summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-04-23 12:53:19 -0600
committermo khan <mo.khan@gmail.com>2020-05-04 18:20:33 -0600
commitc9915861e3db35719bf33aeed7eb4bbf82298267 (patch)
treefa912674be3b7898bb9e7622286baff980e8e908 /lib
parent6bd70e9995e70af4fd12e0c6fa55cf0340e22ba9 (diff)
Add tests for js npm projects
* Add tests for js projects with npm-lock.json file * Add specs for project that does not have a package-lock.json * Fix typo in loading fixture file content not path * Remove dev dependencies for expected js test reports * Add spec for using different engine * Add latest nodejs LTS * Cleanup files after install and disable NPM update checks * Install a .curlrc to remove progress meter * Export LOG_LEVEL=debug in dev mode * Update fixture files * Update to latest patch level of nodejs, php, python, ruby * Add CHANGELOG entry * Move prepare_javascript from bash to ruby
Diffstat (limited to 'lib')
-rw-r--r--lib/license/finder/ext.rb2
-rw-r--r--lib/license/finder/ext/npm.rb36
-rw-r--r--lib/license/finder/ext/yarn.rb9
-rw-r--r--lib/license/management/version.rb2
4 files changed, 48 insertions, 1 deletions
diff --git a/lib/license/finder/ext.rb b/lib/license/finder/ext.rb
index 70620be..3d8a463 100644
--- a/lib/license/finder/ext.rb
+++ b/lib/license/finder/ext.rb
@@ -4,11 +4,13 @@ require 'license/finder/ext/go_modules'
require 'license/finder/ext/gradle'
require 'license/finder/ext/license'
require 'license/finder/ext/maven'
+require 'license/finder/ext/npm'
require 'license/finder/ext/nuget'
require 'license/finder/ext/package_manager'
require 'license/finder/ext/pip'
require 'license/finder/ext/pipenv'
require 'license/finder/ext/shared_helpers'
+require 'license/finder/ext/yarn'
# Apply patch to the JsonReport found in the `license_finder` gem.
LicenseFinder::JsonReport.prepend(License::Management::Report)
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
diff --git a/lib/license/finder/ext/yarn.rb b/lib/license/finder/ext/yarn.rb
new file mode 100644
index 0000000..cc2c029
--- /dev/null
+++ b/lib/license/finder/ext/yarn.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module LicenseFinder
+ class Yarn
+ def prepare_command
+ 'yarn install --ignore-engines --ignore-scripts'
+ end
+ end
+end
diff --git a/lib/license/management/version.rb b/lib/license/management/version.rb
index 64d34f7..cfb570e 100644
--- a/lib/license/management/version.rb
+++ b/lib/license/management/version.rb
@@ -2,6 +2,6 @@
module License
module Management
- VERSION = '3.7.5'
+ VERSION = '3.7.6'
end
end