Module: Dependabot::Composer::Helpers

Defined in:
lib/dependabot/composer/helpers.rb

Constant Summary collapse

COMPOSER_V2_NAME_REGEX =

From composers json-schema: getcomposer.org/schema.json

%r{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$}.freeze
PLATFORM_PACKAGE_REGEX =
/
  ^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*
  |composer-(?:plugin|runtime)-api)$
/x.freeze

Class Method Summary collapse

Class Method Details

.composer_version(composer_json, parsed_lockfile = nil) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dependabot/composer/helpers.rb', line 16

def self.composer_version(composer_json, parsed_lockfile = nil)
  if parsed_lockfile && parsed_lockfile["plugin-api-version"]
    version = Composer::Version.new(parsed_lockfile["plugin-api-version"])
    return version.canonical_segments.first == 1 ? "v1" : "v2"
  else
    return "v1" if composer_json["name"] && composer_json["name"] !~ COMPOSER_V2_NAME_REGEX
    return "v1" if invalid_v2_requirement?(composer_json)
  end

  "v2"
end