Sha256: 9369e029494a8fe2f87f403bbb4b9d3254d6a1daf4f8116852d3f48fdf5a3f82

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

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 --no-save'
    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

6 entries across 6 versions & 1 rubygems

Version Path
license_finder-5.8.0 lib/license_finder/package_managers/npm.rb
license_finder-5.7.1 lib/license_finder/package_managers/npm.rb
license_finder-5.7.0 lib/license_finder/package_managers/npm.rb
license_finder-5.6.2 lib/license_finder/package_managers/npm.rb
license_finder-5.6.1 lib/license_finder/package_managers/npm.rb
license_finder-5.6.0 lib/license_finder/package_managers/npm.rb