Class: Dependabot::NpmAndYarn::PackageManager

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/npm_and_yarn/package_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(package_json, lockfiles:) ⇒ PackageManager

Returns a new instance of PackageManager.



9
10
11
12
13
# File 'lib/dependabot/npm_and_yarn/package_manager.rb', line 9

def initialize(package_json, lockfiles:)
  @package_json = package_json
  @lockfiles = lockfiles
  @package_manager = package_json.fetch("packageManager", nil)
end

Instance Method Details

#setup(name) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dependabot/npm_and_yarn/package_manager.rb', line 15

def setup(name)
  return unless @package_manager.nil? || @package_manager.start_with?("#{name}@")

  version = requested_version(name)

  if version
    raise_if_unsupported!(name, version)

    install(name, version)
  else
    version = guessed_version(name)

    if version
      raise_if_unsupported!(name, version.to_s)

      install(name, version) if name == "pnpm"
    end
  end

  version
end