diff options
Diffstat (limited to 'lib/license/finder/ext/npm.rb')
| -rw-r--r-- | lib/license/finder/ext/npm.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/license/finder/ext/npm.rb b/lib/license/finder/ext/npm.rb new file mode 100644 index 0000000..75c0855 --- /dev/null +++ b/lib/license/finder/ext/npm.rb @@ -0,0 +1,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 |
