Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #204 - Workaround PUP-5985 #205

Merged
merged 1 commit into from
Feb 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions lib/puppet/feature/npm.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require 'puppet/util/feature'
require 'puppet/util/npm'

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
nil
end
!which('npm').nil? && !which('npm').empty?
Puppet::Util::Npm.npm_check
end

Puppet.features.send :meta_def, 'npm?' do
name = :npm
final = @results[name]
@results[name] = Puppet::Util::Npm.npm_check unless final
@results[name]
end
20 changes: 20 additions & 0 deletions lib/puppet/util/npm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Puppet
module Util
class Npm
def self.which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end

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