Skip to content

Commit

Permalink
Fixes #202 - Implement a feature check for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
imriz committed Feb 28, 2016
1 parent 39a910d commit 595bebb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/puppet/feature/npm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'puppet/util/feature'

Puppet.features.add(:npm) do

def self.which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end

!self.which('npm').nil? && !self.which('npm').empty?

end
2 changes: 2 additions & 0 deletions lib/puppet/provider/package/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Puppet::Type.type(:package).provide :npm, :parent => Puppet::Provider::Package do
desc 'npm is the package manager for Node.js. This provider only handles global packages.'

confine :feature => :npm

has_feature :versionable

if Puppet::Util::Package.versioncmp(Puppet.version, '3.0') >= 0
Expand Down

0 comments on commit 595bebb

Please sign in to comment.