Sha256: 06b9569c9af161302e10a9e09ab20dd077d5bfffd0e187e84d64dc10bcb0c817

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

require 'json'
require 'tempfile'

module LicenseFinder
  class NPM < PackageManager
    def current_packages
      NpmPackage.packages_from_json(npm_json, detected_package_path)
    end

    def self.package_management_command
      'npm'
    end

    def self.prepare_command
      'npm install'
    end

    def possible_package_paths
      [project_path.join('package.json')]
    end

    def prepare
      prep_cmd = "#{NPM.prepare_command}#{production_flag}"
      _stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(prep_cmd) }
      return if status.success?
      log_errors stderr
      raise "Prepare command '#{prep_cmd}' failed" unless @prepare_no_fail
    end

    private

    def npm_json
      command = "#{NPM.package_management_command} list --json --long#{production_flag}"
      stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
      raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?

      JSON.parse(stdout)
    end

    def production_flag
      return '' if @ignored_groups.nil?
      @ignored_groups.include?('devDependencies') ? ' --production' : ''
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
license_finder-5.4.1 lib/license_finder/package_managers/npm.rb
license_finder-5.4.0 lib/license_finder/package_managers/npm.rb
license_finder-5.3.0 lib/license_finder/package_managers/npm.rb
license_finder-5.2.3 lib/license_finder/package_managers/npm.rb
license_finder-5.2.1 lib/license_finder/package_managers/npm.rb
license_finder-5.2.0 lib/license_finder/package_managers/npm.rb
license_finder-5.1.1 lib/license_finder/package_managers/npm.rb
license_finder-5.1.0 lib/license_finder/package_managers/npm.rb
license_finder-5.0.3 lib/license_finder/package_managers/npm.rb
license_finder-5.0.2 lib/license_finder/package_managers/npm.rb