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, dependabot_versions = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dependabot/npm_and_yarn/version_selector.rb', line 30

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

  # Return an empty hash if no engine versions are specified
  return {} if engine_versions.nil?

  versions = {}

  if Dependabot::Experiments.enabled?(:enable_engine_version_detection)
    engine_versions.each do |engine, value|
      next unless engine.to_s.match(name)

      versions[name] = ConstraintHelper.find_highest_version_from_constraint_expression(
        value, dependabot_versions
      )
    end
  else
    versions = engine_versions.select do |engine, value|
      engine.to_s.match(name) && valid_extracted_version?(value)
    end
  end

  versions
end

#valid_extracted_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/dependabot/npm_and_yarn/version_selector.rb', line 56

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