diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/language/node.rb | 31 | ||||
| -rw-r--r-- | Library/Homebrew/test/language/node_spec.rb | 35 |
2 files changed, 41 insertions, 25 deletions
diff --git a/Library/Homebrew/language/node.rb b/Library/Homebrew/language/node.rb index 01d41041b..eaadc54fc 100644 --- a/Library/Homebrew/language/node.rb +++ b/Library/Homebrew/language/node.rb @@ -1,7 +1,7 @@ module Language module Node def self.npm_cache_config - "cache=#{HOMEBREW_CACHE}/npm_cache\n" + "cache=#{HOMEBREW_CACHE}/npm_cache" end def self.pack_for_installation @@ -10,19 +10,18 @@ module Language # fed to `npm install` only symlinks are created linking back to that # directory, consequently breaking that assumption. We require a tarball # because npm install creates a "real" installation when fed a tarball. - output = Utils.popen_read("npm pack").chomp - raise "npm failed to pack #{Dir.pwd}" unless $CHILD_STATUS.exitstatus.zero? - output + pack_cmd = "npm pack --ignore-scripts" + output = Utils.popen_read(pack_cmd) + if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty? + raise "npm failed to pack #{Dir.pwd}" + end + output.lines.last.chomp end def self.setup_npm_environment - npmrc = Pathname.new("#{ENV["HOME"]}/.npmrc") - # only run setup_npm_environment once per formula - return if npmrc.exist? - # explicitly set npm's cache path to HOMEBREW_CACHE/npm_cache to fix - # issues caused by overriding $HOME (long build times, high disk usage) - # https://github.com/Homebrew/brew/pull/37#issuecomment-208840366 - npmrc.write npm_cache_config + # guard that this is only run once + return if @env_set + @env_set = true # explicitly use our npm and node-gyp executables instead of the user # managed ones in HOMEBREW_PREFIX/lib/node_modules which might be broken begin @@ -42,8 +41,10 @@ module Language # npm install args for global style module format installed into libexec %W[ - --verbose + -ddd --global + --build-from-source + --#{npm_cache_config} --prefix=#{libexec} #{Dir.pwd}/#{pack} ] @@ -52,7 +53,11 @@ module Language def self.local_npm_install_args setup_npm_environment # npm install args for local style module format - ["--verbose"] + %W[ + -ddd + --build-from-source + --#{npm_cache_config} + ] end end end diff --git a/Library/Homebrew/test/language/node_spec.rb b/Library/Homebrew/test/language/node_spec.rb index b2114bc4f..5ddbde944 100644 --- a/Library/Homebrew/test/language/node_spec.rb +++ b/Library/Homebrew/test/language/node_spec.rb @@ -2,45 +2,56 @@ 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 + it "calls prepend_path when node formula exists only during the first call" 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 + subject.instance_variable_set(:@env_set, false) + expect(subject.setup_npm_environment).to be_nil + + expect(subject.instance_variable_get(:@env_set)).to eq(true) + expect(ENV).not_to receive(:prepend_path) + expect(subject.setup_npm_environment).to be_nil 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) + it "does not call prepend_path when node formula does not exist" do 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 --ignore-scripts" it "raises error with non zero exitstatus" do + allow(Utils).to receive(:popen_read).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(Utils).to receive(:popen_read).with(npm_pack_cmd).and_return("") + allow_any_instance_of(Process::Status).to receive(:exitstatus).and_return(0) + allow_any_instance_of(nil::NilClass).to receive(:exitstatus).and_return(0) 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(Utils).to receive(:popen_read).with("npm pack").and_return("pack") + allow(Utils).to receive(:popen_read).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") + 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("--verbose") + expect(resp).to include("-ddd", "--build-from-source", "--cache=#{HOMEBREW_CACHE}/npm_cache") end end |
