class Licensed::Sources::PNPM

Public Class Methods

require_matched_dependency_version() click to toggle source

The PNPM source requires matching reviewed or ignored dependencies on both name and version

# File lib/licensed/sources/pnpm.rb, line 9
def self.require_matched_dependency_version
  true
end

Public Instance Methods

enabled?() click to toggle source

Returns true when pnpm is installed and a pnpm-lock.yaml file is found, otherwise false

# File lib/licensed/sources/pnpm.rb, line 15
def enabled?
  return false unless Licensed::Shell.tool_available?("pnpm")
  File.exist?(File.join(config.pwd, "pnpm-lock.yaml"))
end
enumerate_dependencies() click to toggle source
# File lib/licensed/sources/pnpm.rb, line 20
def enumerate_dependencies
  packages.map do |package|
    name_with_version = "#{package["name"]}@#{package["version"]}"
    Dependency.new(
      name: name_with_version,
      version: package["version"],
      path: package["path"],
      metadata: {
        "type"     => PNPM.type,
        "name"     => package["name"],
        "summary"  => package["description"],
        "homepage" => package["homepage"]
      }
    )
  end
end
include_non_production?() click to toggle source

Returns whether to include non production dependencies based on the licensed configuration settings

# File lib/licensed/sources/pnpm.rb, line 53
def include_non_production?
  config.dig("pnpm", "production_only") == false
end
package_metadata_command() click to toggle source

Returns the output from running ‘pnpm licenses list` to get package metadata

# File lib/licensed/sources/pnpm.rb, line 46
def package_metadata_command
  args = %w(--json --long)
  args << "--prod" unless include_non_production?
  Licensed::Shell.execute("pnpm", "licenses", "list", *args, allow_failure: true)
end
packages() click to toggle source

Returns package metadata returned from ‘pnpm licensed list`

# File lib/licensed/sources/pnpm.rb, line 38
def packages
  JSON.parse(package_metadata_command).values.flatten
rescue JSON::ParserError => e
  message = "Licensed was unable to parse the output from 'pnpm licenses list'. JSON Error: #{e.message}"
  raise Licensed::Sources::Source::Error, message
end