Skip to content

Commit

Permalink
Added --npm_options option to customize npm behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Malott committed May 11, 2021
1 parent 6fdf9d2 commit b8457a6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/license_finder/cli/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def license_finder_config
:gradle_include_groups,
:maven_include_groups,
:maven_options,
:npm_options,
:pip_requirements_path,
:python_version,
:rebar_command,
Expand Down
1 change: 1 addition & 0 deletions lib/license_finder/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Main < Base
Defaults to 'gradlew' / 'gradlew.bat' if the wrapper is present, otherwise to 'gradle'."
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.'
class_option :maven_options, desc: 'Maven options to append to command. Defaults to empty.'
class_option :npm_options, desc: 'npm options to append to command. Defaults to empty.'
class_option :pip_requirements_path, desc: 'Path to python requirements file. Defaults to requirements.txt.'
class_option :python_version, desc: 'Python version to invoke pip with. Valid versions: 2 or 3. Default: 2'
class_option :rebar_command, desc: "Command to use when fetching rebar packages. Only meaningful if used with a Erlang/rebar project. Defaults to 'rebar'."
Expand Down
5 changes: 5 additions & 0 deletions lib/license_finder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def maven_options
get(:maven_options)
end

def npm_options
get(:npm_options)
end


def pip_requirements_path
get(:pip_requirements_path)
end
Expand Down
1 change: 1 addition & 0 deletions lib/license_finder/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def options # rubocop:disable Metrics/AbcSize
gradle_include_groups: config.gradle_include_groups,
maven_include_groups: config.maven_include_groups,
maven_options: config.maven_options,
npm_options: config.npm_options,
pip_requirements_path: config.pip_requirements_path,
python_version: config.python_version,
rebar_command: config.rebar_command,
Expand Down
7 changes: 7 additions & 0 deletions lib/license_finder/package_managers/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

module LicenseFinder
class NPM < PackageManager
def initialize(options = {})
super
@npm_options = options[:npm_options]
end


def current_packages
NpmPackage.packages_from_json(npm_json, detected_package_path)
end
Expand Down Expand Up @@ -35,6 +41,7 @@ def prepare

def npm_json
command = "#{package_management_command} list --json --long#{production_flag}"
command += " #{@npm_options}" unless @npm_options.nil?
stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
# we can try and continue if we got an exit status 1 - unmet peer dependency
raise "Command '#{command}' failed to execute: #{stderr}" if !status.success? && status.exitstatus != 1
Expand Down
1 change: 1 addition & 0 deletions spec/lib/license_finder/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module LicenseFinder
gradle_include_groups: nil,
maven_include_groups: nil,
maven_options: nil,
npm_options: nil,
pip_requirements_path: nil,
python_version: nil,
rebar_command: configuration.rebar_command,
Expand Down

0 comments on commit b8457a6

Please sign in to comment.