Install npm_from_source failing with custom version
jmreicha opened this issue · 5 comments
jmreicha commented
Found a new issue. This one has to do with customizing the version of npm to install. Here are the actions I am taking:
node.default['nodejs']['npm']['install_method'] = 'source'
node.default['nodejs']['npm']['version'] = '1.4.21'
include_recipe "nodejs::npm_from_source"
And here is the chef-client output that is failing. I will investigate more when I have a chance but just wanted to make sure it's not something silly that I am missing.
================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/me-retaliator/recipes/default.rb
================================================================================
ArgumentError
-------------
wrong number of arguments (2 for 1)
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/nodejs/libraries/nodejs_helper.rb:10:in `npm_dist'
/tmp/kitchen/cache/cookbooks/nodejs/recipes/npm_from_source.rb:25:in `from_file'
/tmp/kitchen/cache/cookbooks/me-retaliator/recipes/default.rb:8:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/nodejs/libraries/nodejs_helper.rb:
3: def npm_dist
4: if node['nodejs']['npm']['url']
5: return { 'url' => node['nodejs']['npm']['url'] }
6: else
7:
8: require 'open-uri'
9: require 'json'
10>> result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}", :max_nesting => false
).read)
11: ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
12: Chef::Log.debug("Npm dist #{ret}")
13: return ret
14: end
15: end
16:
17: def install_not_needed?
18: cmd = Mixlib::ShellOut.new("#{node['nodejs']['node_bin']} --version")
19: version = cmd.run_command.stdout.chomp
guilhem commented
What chef version are you using?
If latest, json parser was changed. It may be linked.
If it is, I have to revert PR quickly
jmreicha commented
so far I have tried 11.12.8
and 11.14.2
and can reproduce the issue with both.
jmreicha commented
Quick update. Changing the code to the following seems to work, not sure what it breaks but I figured I'd post it so you can take a look.
from
require 'open-uri'
require 'json'
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}", :max_nesting => false).read)
ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
Chef::Log.debug("Npm dist #{ret}")
return ret
to
require 'open-uri'
require 'json'
uri = URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read
result = JSON.parse(uri)
ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
Chef::Log.debug("Npm dist #{ret}")
return ret
jmreicha commented
Got it, thanks!