Module: PackageResolved

Defined in:
lib/spm_version_updates/package_resolved.rb

Overview

Parsing for ‘Package.resolved` files.

Handles both the v1 format (pins nested under ‘“object”`) and the v2+ format (pins at the top level). This is shared between the Xcode-project source mode and the Swift package manifest source mode.

Defined Under Namespace

Classes: MalformedFileError

Class Method Summary collapse

Class Method Details

.pins_from(path) ⇒ Array<Hash>

Extract structured pins from a ‘Package.resolved` file.

Parameters:

  • path (String)

    The path to a ‘Package.resolved` file

Returns:

  • (Array<Hash>)

    pin records with normalized_url, repository_url, version, and revision

Raises:



39
40
41
42
43
# File 'lib/spm_version_updates/package_resolved.rb', line 39

def self.pins_from(path)
  contents = load_contents(path)
  pins = contents["pins"] || contents.dig("object", "pins") || []
  pins.map { |pin| pin_record(pin) }
end

.versions_from(path) ⇒ Hash<String, String>

Extract the resolved version (or revision, when no version is pinned) for every pin in a ‘Package.resolved` file.

Parameters:

  • path (String)

    The path to a ‘Package.resolved` file

Returns:

  • (Hash<String, String>)

    normalized repository URL => version or revision

Raises:



29
30
31
# File 'lib/spm_version_updates/package_resolved.rb', line 29

def self.versions_from(path)
  pins_from(path).to_h { |pin| [pin["normalized_url"], pin["version"] || pin["revision"]] }
end