diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-04 12:29:07 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-04 18:11:01 -0600 |
| commit | 82710091812b7579e402274e964db7e5077e7509 (patch) | |
| tree | 6131b9de46ede4f6d51db1a7f0c81edecdf2eaef /lib | |
| parent | 3ee6d1113b57f9fdc3b093a75d5c79ef04078b21 (diff) | |
Parse lockfile when available
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/license/finder/ext/composer.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/license/finder/ext/composer.rb b/lib/license/finder/ext/composer.rb index e6b0733..1be4e2b 100644 --- a/lib/license/finder/ext/composer.rb +++ b/lib/license/finder/ext/composer.rb @@ -45,9 +45,12 @@ module LicenseFinder :licenses, '--format=json' ], env: default_env) - return [] unless status.success? + return from_lockfile unless status.success? - JSON.parse(stdout).fetch('dependencies', {}).map do |name, data| + dependencies = JSON.parse(stdout).fetch('dependencies', {}) + return from_lockfile if dependencies.empty? + + dependencies.map do |name, data| data.merge('name' => name) if data.is_a?(Hash) end.compact end @@ -72,5 +75,12 @@ module LicenseFinder ], env: default_env) status.success? ? stdout.split(' ').last : '' end + + def from_lockfile + return [] unless lockfile_path.exist? + + json = JSON.parse(lockfile_path.read) + json.fetch('packages', []) + end end end |
