Christian Moritz 466fe9841a language/node: npm pack ignore prepublish scripts
This tells npm pack to don't run prepublish scripts at all.
I think this is the best default because:
* most modules don't have a prepublish script at all and aren't affected
  by this change
* most prepublish scripts are calling devDeps, which would fail in our
  case, because (dev)Deps aren't installed at npm pack time until #2820
  gets resolved
* we favor npm registry tarball for formula downloads, which are already
  prepublished, so we would in the best case needlessly run prepublish
  a second time and in the worst case it would fail (because a clean
  step is required before running prepublish a second time in a row)
* This change does the right thing for >99% of all the packages and
  would only affect packages with prepublish scripts downloaded from a
  non-npm registry tarball (like github tarballs) and with a prepublish
  script wich does no't require any devDep (unlike for cross platform)
2017-06-29 20:29:25 +02:00

57 lines
2.1 KiB
Ruby

require "language/node"
describe Language::Node do
describe "#setup_npm_environment" do
it "does nothing when npmrc exists" do
expect(subject.setup_npm_environment).to be_nil
end
it "calls prepend_path when node formula exists and npmrc does not exist" do
node = formula "node" do
url "node-test"
end
stub_formula_loader(node)
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false)
expect(ENV).to receive(:prepend_path)
subject.setup_npm_environment
end
it "does not call prepend_path when node formula does not exist but npmrc exists" do
allow_any_instance_of(Pathname).to receive(:exist?).and_return(false)
expect(subject.setup_npm_environment).to be_nil
end
end
describe "#std_npm_install_args" do
npm_install_arg = "libexec"
npm_pack_cmd = "npm pack -ddd --ignore-scripts"
it "raises error with non zero exitstatus" do
allow(Language::Node).to receive(:`).with(npm_pack_cmd).and_return("error msg")
allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(42)
allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(42)
expect { subject.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}")
end
it "raises error with empty npm pack output" do
allow(Language::Node).to receive(:`).with(npm_pack_cmd).and_return("")
expect { subject.std_npm_install_args(npm_install_arg) }.to \
raise_error("npm failed to pack #{Dir.pwd}")
end
it "does not raise error with a zero exitstatus" do
allow(Language::Node).to receive(:`).with(npm_pack_cmd).and_return("pack.tgz")
allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0)
allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(0)
resp = subject.std_npm_install_args(npm_install_arg)
expect(resp).to include("--prefix=#{npm_install_arg}", "#{Dir.pwd}/pack.tgz")
end
end
specify "#local_npm_install_args" do
resp = subject.local_npm_install_args
expect(resp).to include("-ddd", "--build-from-source")
end
end