Skip to content

Improve Usability of replace-scm-with-registry#9966

Open
thePianoKid wants to merge 10 commits into
swiftlang:mainfrom
thePianoKid:improve-replace-scm-usability
Open

Improve Usability of replace-scm-with-registry#9966
thePianoKid wants to merge 10 commits into
swiftlang:mainfrom
thePianoKid:improve-replace-scm-usability

Conversation

@thePianoKid
Copy link
Copy Markdown
Contributor

@thePianoKid thePianoKid commented Apr 20, 2026

Add replaceScmWithRegistry attribute to registries.json. Resolves #9854.

Motivation:

There is a no global option, or at least per repo that could enable the --replace-scm-with-registry option? This is very error prone to have to setup alias scripts to do use correct flag.

Result:

Devs can now transform SCM dependencies to registry ones globally or on a per-project basis by including "replaceScmWithRegistry": true, in .swiftpm/configuration/registries.json

Manual Testing

Make a package like the one in WorkspaceTests.testRegistriesJsonReplaceScmWithRegistryDrivesSwizzle. Make sure that SPM picks up "replaceScmWithRegistry": true,.

Explore other edge cases like not including "replaceScmWithRegistry", passing in an illegal value, etc...

Blocked by #10036

@thePianoKid
Copy link
Copy Markdown
Contributor Author

#9854 suggested that this config be added to https://github.com/apple/swift-configuration.

replaceScmWithRegistry was added to registries.json instead because swift-configuration is separate from SPM, and was built to manage configuration that is passed in at runtime. Adding this configuration option directly to SPM made the most sense to me.

@bripeticca
Copy link
Copy Markdown
Contributor

@swift-ci test

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test windows

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test macOS

Copy link
Copy Markdown
Contributor

@bripeticca bripeticca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, just a couple questions:

  • Have we considered that the use of --replace-scm-with-registry in the CLI in turn populates the registries.json with this value set, or are we treating these as strictly separate concepts where the CLI will override whatever is present in the registries.json?
  • If the latter, will users have to explicitly declare this property in the registries.json themselves?
  • If the CLI option does affect whether the replace scm flag is persisted to the registries.json file, do we write to the registries.json when this happens? Does the RegistryConfiguration encoding work as expected?

let json = #"""
{
"authentication": {},
"replaceScmWithRegistry": "Bob, I don't think this is valid",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

@bripeticca
Copy link
Copy Markdown
Contributor

@swift-ci test windows

Comment on lines +555 to +564
// registries.json acts as a default; an explicit CLI flag overrides.
let effectiveTransformation: WorkspaceConfiguration.SourceControlToRegistryDependencyTransformation = {
if let cliValue = configuration.sourceControlToRegistryDependencyTransformation {
return cliValue
}
if registriesConfiguration.replaceScmWithRegistry == true {
return .swizzle
}
return .disabled
}()
Copy link
Copy Markdown
Contributor Author

@thePianoKid thePianoKid Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, just a couple questions:

--replace-scm-with-registry doesn't write to registries.json. The transformation used is determined by this logic.

CLI takes precedent over what's in registries.json, which takes precedent over the default (which is a .disabled transformation).

Users will have to know to include this new attribute in registries.json. That raises a good question: what's the best way to tell SPM users about this new attribute?

@thePianoKid thePianoKid requested a review from bripeticca April 30, 2026 15:15
}

try container.encode(self.registryAuthentication, forKey: .authentication)
try container.encodeIfPresent(self.security, forKey: .security)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also be encoding replaceScmWithRegistry

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1d11d2a

@thePianoKid thePianoKid requested a review from plemarquand April 30, 2026 21:15
@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test windows

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test mac

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test linux

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test macOS

@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented May 5, 2026

@swift-ci test windows

XCTAssertThrowsError(try self.decoder.decode(RegistryConfiguration.self, from: json))
}

func testDecodeConfigurationWithMissingReplaceScmWithRegistry() throws {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: consider migrating this test suite to Swift Testing, and utilizing the parameterized tests for test implementation that are similar.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that belong in this PR? What if I add a new migration PR and stack it on top of this one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to convert to Swift Testing in this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. I will make a new PR that is blocked by this one.

"""#)

// Case 1: no CLI override → registries.json drives .swizzle.
do {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: consider migrating this test suite to Swift Testing, and utilizing the parameterized tests for test implementation that are similar.

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test self hosted windows

3 similar comments
@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented May 11, 2026

@swift-ci test self hosted windows

@bkhouri
Copy link
Copy Markdown
Contributor

bkhouri commented May 11, 2026

@swift-ci test self hosted windows

@thePianoKid
Copy link
Copy Markdown
Contributor Author

@swift-ci test self hosted windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package Registry improve usability of replace-scm-with-registry

4 participants