Skip to content

Commit b8457a6

Browse files
author
Alexander-Malott
committed
Added --npm_options option to customize npm behavior.
1 parent 6fdf9d2 commit b8457a6

6 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/license_finder/cli/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def license_finder_config
4242
:gradle_include_groups,
4343
:maven_include_groups,
4444
:maven_options,
45+
:npm_options,
4546
:pip_requirements_path,
4647
:python_version,
4748
:rebar_command,

lib/license_finder/cli/main.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Main < Base
3030
Defaults to 'gradlew' / 'gradlew.bat' if the wrapper is present, otherwise to 'gradle'."
3131
class_option :maven_include_groups, desc: 'Whether dependency name should include group id. Only meaningful if used with a Java/maven project. Defaults to false.'
3232
class_option :maven_options, desc: 'Maven options to append to command. Defaults to empty.'
33+
class_option :npm_options, desc: 'npm options to append to command. Defaults to empty.'
3334
class_option :pip_requirements_path, desc: 'Path to python requirements file. Defaults to requirements.txt.'
3435
class_option :python_version, desc: 'Python version to invoke pip with. Valid versions: 2 or 3. Default: 2'
3536
class_option :rebar_command, desc: "Command to use when fetching rebar packages. Only meaningful if used with a Erlang/rebar project. Defaults to 'rebar'."

lib/license_finder/configuration.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def maven_options
9393
get(:maven_options)
9494
end
9595

96+
def npm_options
97+
get(:npm_options)
98+
end
99+
100+
96101
def pip_requirements_path
97102
get(:pip_requirements_path)
98103
end

lib/license_finder/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def options # rubocop:disable Metrics/AbcSize
9999
gradle_include_groups: config.gradle_include_groups,
100100
maven_include_groups: config.maven_include_groups,
101101
maven_options: config.maven_options,
102+
npm_options: config.npm_options,
102103
pip_requirements_path: config.pip_requirements_path,
103104
python_version: config.python_version,
104105
rebar_command: config.rebar_command,

lib/license_finder/package_managers/npm.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
module LicenseFinder
77
class NPM < PackageManager
8+
def initialize(options = {})
9+
super
10+
@npm_options = options[:npm_options]
11+
end
12+
13+
814
def current_packages
915
NpmPackage.packages_from_json(npm_json, detected_package_path)
1016
end
@@ -35,6 +41,7 @@ def prepare
3541

3642
def npm_json
3743
command = "#{package_management_command} list --json --long#{production_flag}"
44+
command += " #{@npm_options}" unless @npm_options.nil?
3845
stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
3946
# we can try and continue if we got an exit status 1 - unmet peer dependency
4047
raise "Command '#{command}' failed to execute: #{stderr}" if !status.success? && status.exitstatus != 1

spec/lib/license_finder/core_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module LicenseFinder
4040
gradle_include_groups: nil,
4141
maven_include_groups: nil,
4242
maven_options: nil,
43+
npm_options: nil,
4344
pip_requirements_path: nil,
4445
python_version: nil,
4546
rebar_command: configuration.rebar_command,

0 commit comments

Comments
 (0)