mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
align npm resource with info handling
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
parent
fc9764aa36
commit
508a6889d1
1 changed files with 10 additions and 7 deletions
|
@ -13,23 +13,26 @@ class NpmPackage < Vulcano.resource(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def info
|
def info
|
||||||
return @cache if !@cache.nil?
|
return @info unless @info.nil?
|
||||||
|
|
||||||
cmd = vulcano.run_command("npm ls -g --json #{@package_name}")
|
cmd = vulcano.run_command("npm ls -g --json #{@package_name}")
|
||||||
return nil if cmd.exit_status != 0
|
@info = {
|
||||||
pkgs = JSON.parse(cmd.stdout)
|
|
||||||
@cache = {
|
|
||||||
name: @package_name,
|
name: @package_name,
|
||||||
version: pkgs['dependencies'][@package_name]['version'],
|
|
||||||
type: 'npm',
|
type: 'npm',
|
||||||
|
installed: cmd.exit_status != 0,
|
||||||
}
|
}
|
||||||
|
return @info unless @info[:installed]
|
||||||
|
|
||||||
|
pkgs = JSON.parse(cmd.stdout)
|
||||||
|
@info[version] = pkgs['dependencies'][@package_name]['version']
|
||||||
end
|
end
|
||||||
|
|
||||||
def installed?
|
def installed?
|
||||||
!info.nil?
|
info[:installed]
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
info.nil? ? nil : info[:version]
|
info[:version]
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
Loading…
Reference in a new issue