blob: 75c0855969f67109247656d4eb1527764552e8d0 (
plain)
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
|
# frozen_string_literal: true
module LicenseFinder
class NPM
def current_packages
NpmPackage.packages_from_json(npm_json, detected_package_path)
end
def prepare_command
lockfile? ? 'npm ci' : 'npm install --no-save'
end
def possible_package_paths
[project_path.join('package.json')]
end
def prepare
Dir.chdir(project_path) do
shell.execute("#{prepare_command} --production")
end
end
private
def lockfile?
File.exist?(project_path.join('package-lock.json'))
end
def npm_json
stdout, _stderr, status = Dir.chdir(project_path) do
shell.execute("npm list --json --long --production")
end
status.success? ? JSON.parse(stdout) : {}
end
end
end
|