Class: Dependabot::NpmAndYarn::VersionSelector

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/npm_and_yarn/version_selector.rb

Constant Summary collapse

NODE_ENGINE_SUPPORTED_REGEX =

For limited testing, allowing only specific versions defined in engines in package.json such as “20.8.7”, “8.1.2”, “8.21.2”,

/^\d+(?:\.\d+)*$/

Instance Method Summary collapse

Instance Method Details

#setup(manifest_json, name) ⇒ Object



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

def setup(manifest_json, name)
  engine_versions = manifest_json["engines"]

  if engine_versions.nil?
    Dependabot.logger.info("No info (engines) found")
    return {}
  end

  # logs entries for analysis purposes
  log = engine_versions.select do |engine, _value|
    engine.to_s.match(name)
  end
  Dependabot.logger.info("Found engine info #{log}") unless log.empty?

  # Only keep matching specs versions i.e. "20.21.2", "7.1.2",
  # Additional specs can be added later
  engine_versions.delete_if { |_key, value| !valid_extracted_version?(value) }
  version = engine_versions.select { |engine, _value| engine.to_s.match(name) }

  version
end

#valid_extracted_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/dependabot/npm_and_yarn/version_selector.rb', line 40

def valid_extracted_version?(version)
  version.match?(NODE_ENGINE_SUPPORTED_REGEX)
end