Class: Licensed::Sources::PNPM
- Defined in:
- lib/licensed/sources/pnpm.rb
Instance Attribute Summary
Attributes inherited from Source
Class Method Summary collapse
-
.require_matched_dependency_version ⇒ Object
The PNPM source requires matching reviewed or ignored dependencies on both name and version.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Returns true when pnpm is installed and a pnpm-lock.yaml file is found, otherwise false.
- #enumerate_dependencies ⇒ Object
-
#include_non_production? ⇒ Boolean
Returns whether to include non production dependencies based on the licensed configuration settings.
-
#package_metadata_command ⇒ Object
Returns the output from running ‘pnpm licenses list` to get package metadata.
-
#packages ⇒ Object
Returns package metadata returned from ‘pnpm licensed list`.
Methods inherited from Source
#dependencies, full_type, #ignored?, inherited, #initialize, register_source, #source_config, type, type_and_version
Constructor Details
This class inherits a constructor from Licensed::Sources::Source
Class Method Details
.require_matched_dependency_version ⇒ Object
The PNPM source requires matching reviewed or ignored dependencies on both name and version
9 10 11 |
# File 'lib/licensed/sources/pnpm.rb', line 9 def self.require_matched_dependency_version true end |
Instance Method Details
#enabled? ⇒ Boolean
Returns true when pnpm is installed and a pnpm-lock.yaml file is found, otherwise false
15 16 17 18 |
# 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 ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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? ⇒ Boolean
Returns whether to include non production dependencies based on the licensed configuration settings
53 54 55 |
# File 'lib/licensed/sources/pnpm.rb', line 53 def include_non_production? config.dig("pnpm", "production_only") == false end |
#package_metadata_command ⇒ Object
Returns the output from running ‘pnpm licenses list` to get package metadata
46 47 48 49 50 |
# File 'lib/licensed/sources/pnpm.rb', line 46 def args = %w(--json --long) args << "--prod" unless include_non_production? Licensed::Shell.execute("pnpm", "licenses", "list", *args, allow_failure: true) end |
#packages ⇒ Object
Returns package metadata returned from ‘pnpm licensed list`
38 39 40 41 42 43 |
# File 'lib/licensed/sources/pnpm.rb', line 38 def packages JSON.parse().values.flatten rescue JSON::ParserError => e = "Licensed was unable to parse the output from 'pnpm licenses list'. JSON Error: #{e.}" raise Licensed::Sources::Source::Error, end |