-
Notifications
You must be signed in to change notification settings - Fork 336
/
npm.rb
49 lines (37 loc) · 1.17 KB
/
npm.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
require 'json'
require 'tempfile'
module LicenseFinder
class NPM < PackageManager
def current_packages
NpmPackage.packages_from_json(npm_json, detected_package_path)
end
def self.package_management_command
'npm'
end
def self.prepare_command
'npm install --no-save'
end
def possible_package_paths
[project_path.join('package.json')]
end
def prepare
prep_cmd = "#{NPM.prepare_command}#{production_flag}"
_stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(prep_cmd) }
return if status.success?
log_errors stderr
raise "Prepare command '#{prep_cmd}' failed" unless @prepare_no_fail
end
private
def npm_json
command = "#{NPM.package_management_command} list --json --long#{production_flag}"
stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
JSON.parse(stdout)
end
def production_flag
return '' if @ignored_groups.nil?
@ignored_groups.include?('devDependencies') ? ' --production' : ''
end
end
end