Class: LicenseFinder::PNPM
Constant Summary
collapse
- SHELL_COMMAND =
'pnpm licenses list --json --long'
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, #command_exists?, #current_packages_with_relations, #detected_package_path, id, #installed?, #project_root?
Constructor Details
#initialize(options = {}) ⇒ PNPM
Returns a new instance of PNPM.
8
9
10
11
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 8
def initialize(options = {})
super
@pnpm_options = options[:pnpm_options]
end
|
Class Method Details
.takes_priority_over ⇒ Object
19
20
21
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 19
def self.takes_priority_over
NPM
end
|
Instance Method Details
#current_packages ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 23
def current_packages
raise 'The minimum PNPM version is not met, requires 7.17.0 or later' unless supported_pnpm?
cmd = PNPM::SHELL_COMMAND.to_s
cmd += ' --no-color'
cmd += ' --recursive' unless project_has_workspaces == false
cmd += " --dir #{project_path}" unless project_path.nil?
cmd += " #{@pnpm_options}" unless @pnpm_options.nil?
stdout, stderr, status = Cmd.run(cmd)
raise "Command '#{cmd}' failed to execute: #{stderr}" unless status.success?
json_objects = JSON.parse(stdout)
get_pnpm_packages(json_objects)
end
|
#get_pnpm_packages(json_objects) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 41
def get_pnpm_packages(json_objects)
packages = []
incompatible_packages = []
json_objects.map do |_, value|
value.each do |pkg|
name = pkg['name']
if pkg['version']
version = pkg['version']
elsif pkg['versions']
version = pkg['versions'][0]
end
license = pkg['license']
homepage = pkg['vendorUrl']
author = pkg['vendorName']
module_path = pkg['path']
package = PNPMPackage.new(
name,
version,
spec_licenses: [license],
homepage: homepage,
authors: author,
install_path: module_path
)
packages << package
end
end
packages + incompatible_packages.uniq
end
|
#package_management_command ⇒ Object
75
76
77
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 75
def package_management_command
'pnpm'
end
|
#possible_package_paths ⇒ Object
15
16
17
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 15
def possible_package_paths
[project_path.join('pnpm-lock.yaml')]
end
|
#prepare ⇒ Object
83
84
85
86
87
88
89
90
91
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 83
def prepare
prep_cmd = "#{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
|
#prepare_command ⇒ Object
79
80
81
|
# File 'lib/license_finder/package_managers/pnpm.rb', line 79
def prepare_command
'pnpm install --no-lockfile --ignore-scripts'
end
|