Class: Package::Audit::Npm::YarnLockParser

Inherits:
Object
  • Object
show all
Defined in:
lib/package/audit/npm/yarn_lock_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(yarn_lock_path) ⇒ YarnLockParser

Returns a new instance of YarnLockParser.



7
8
9
10
# File 'lib/package/audit/npm/yarn_lock_parser.rb', line 7

def initialize(yarn_lock_path)
  @yarn_lock_file = File.read(yarn_lock_path)
  @yarn_lock_path = yarn_lock_path
end

Instance Method Details

#fetch(default_deps, dev_deps) ⇒ Object

rubocop:disable Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/package/audit/npm/yarn_lock_parser.rb', line 12

def fetch(default_deps, dev_deps) # rubocop:disable Metrics/MethodLength
  pkgs = []
  default_deps.merge(dev_deps).each do |dep_name, expected_version|
    pkg_block = fetch_package_block(dep_name, expected_version)
    version = fetch_package_version(dep_name, pkg_block)
    pks = Package.new(dep_name.to_s, version, 'node')
    pks.update groups: if dev_deps.key?(dep_name)
                         [Enum::Group::DEV]
                       else
                         [Enum::Group::DEFAULT, Enum::Group::DEV]
                       end
    pkgs << pks
  end
  pkgs
end