Sha256: 91f3e5c9d9993816ad0444c2c177acf175fcda379070aa1ef8fa0213cb8f5915
Contents?: true
Size: 1.07 KB
Versions: 6
Compression:
Stored size: 1.07 KB
Contents
require 'json' module LicenseFinder class NPM DEPENDENCY_GROUPS = ["dependencies", "devDependencies", "bundleDependencies", "bundledDependencies"] def self.current_packages json = npm_json dependencies = DEPENDENCY_GROUPS.map { |g| (json[g] || {}).values }.flatten(1).reject{ |d| d.is_a?(String) } dependencies.map do |node_module| NpmPackage.new(node_module) end end def self.active? File.exists?(package_path) end private def self.npm_json command = "npm list --json --long" output, success = capture(command) if success json = JSON(output) else json = JSON(output) rescue nil if json $stderr.puts "Command #{command} returned error but parsing succeeded." unless ENV['test_run'] else raise "Command #{command} failed to execute: #{output}" end end json end def self.capture(command) [`#{command}`, $?.success?] end def self.package_path Pathname.new('package.json').expand_path end end end
Version data entries
6 entries across 6 versions & 1 rubygems