summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-05-19 11:42:07 -0600
committermo khan <mo.khan@gmail.com>2020-05-19 11:42:07 -0600
commit0f1db0d60c61a6db1c5389fc0ddb2d984789b330 (patch)
tree0a93685e673cf43b8c61ad9e251a1722f5460796
parentea84a8f5badf153744486c51a75b1f492763fdfd (diff)
Add --allow-root option to install step
-rw-r--r--lib/license/finder/ext.rb1
-rw-r--r--lib/license/finder/ext/bower.rb55
-rw-r--r--spec/integration/js/bower_spec.rb4
3 files changed, 58 insertions, 2 deletions
diff --git a/lib/license/finder/ext.rb b/lib/license/finder/ext.rb
index 3d8a463..3c56c7a 100644
--- a/lib/license/finder/ext.rb
+++ b/lib/license/finder/ext.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require 'license/finder/ext/bower'
require 'license/finder/ext/go_modules'
require 'license/finder/ext/gradle'
require 'license/finder/ext/license'
diff --git a/lib/license/finder/ext/bower.rb b/lib/license/finder/ext/bower.rb
new file mode 100644
index 0000000..3c6ba6f
--- /dev/null
+++ b/lib/license/finder/ext/bower.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module LicenseFinder
+ class Bower < PackageManager
+ def prepare
+ shell.execute([:bower, :install, '--allow-root'])
+ end
+
+ def current_packages
+ bower_output.map do |bower_module|
+ map_from(bower_module)
+ end
+ end
+
+ def possible_package_paths
+ [project_path.join('bower.json')]
+ end
+
+ private
+
+ def bower_output
+ stdout, _stderr, status = Dir.chdir(project_path) do
+ shell.execute([:bower, :list, '--json', '-l', 'action', '--allow-root'])
+ end
+ return [] unless status.success?
+
+ json = JSON.parse(stdout)
+ json.fetch('dependencies', {}).values
+ end
+
+ def map_from(bower_module)
+ spec = bower_module.fetch('pkgMeta', {})
+
+ if spec.empty?
+ endpoint = bower_module.fetch('endpoint', {})
+ Package.new(
+ endpoint['name'],
+ endpoint['target'],
+ install_path: bower_module['canonicalDir'],
+ )
+ else
+ Package.new(
+ spec['name'],
+ spec['version'],
+ summary: spec['description'],
+ description: spec['readme'],
+ homepage: spec['homepage'],
+ spec_licenses: Package.license_names_from_standard_spec(spec),
+ install_path: bower_module['canonicalDir'],
+ )
+ end
+ end
+ end
+end
+
diff --git a/spec/integration/js/bower_spec.rb b/spec/integration/js/bower_spec.rb
index 68ab12d..b72f256 100644
--- a/spec/integration/js/bower_spec.rb
+++ b/spec/integration/js/bower_spec.rb
@@ -10,9 +10,9 @@ RSpec.describe "bower" do
specify { expect(subject).to match_schema(version: '2.0') }
specify { expect(subject.dependency_names).to match_array(['cli', 'jquery', 'masonry-layout', 'stimulus.umd']) }
- specify { expect(subject.licenses_for('cli')).to match_array(['Artistic-2.0']) }
+ specify { expect(subject.licenses_for('cli')).to match_array(['Apache-2.0', 'BSD-3-Clause', 'ISC', 'MIT']) }
specify { expect(subject.licenses_for('jquery')).to match_array(['MIT']) }
specify { expect(subject.licenses_for('masonry-layout')).to match_array(['MIT']) }
- specify { expect(subject.licenses_for('stimulus.umd')).to match_array(['MIT']) }
+ specify { expect(subject.licenses_for('stimulus.umd')).to match_array(['unknown']) }
end
end