Skip to content

fix(cli): fix name collisions in swift-package-manager - #8739

Merged
markemer merged 6 commits into
mainfrom
OSSS-155
Nov 24, 2026
Merged

markemer merged 6 commits into
mainfrom
OSSS-155

Conversation

@markemer

@markemer markemer commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

Closes #8734 by changing capacitor to capacitor-ios in all places the cli fixes things

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Platforms Affected

  • Android
  • iOS
  • Web

Notes / Comments

Claude helped on this one, to find some of the weird corner cases and to fix the tests.

@markemer markemer changed the title [WIP]: Fix Capcitor SPM replacements fix(cli): fix name collisions when something has the implicit name capacitor as a package Nov 20, 2026
@markemer
markemer marked this pull request as ready for review November 20, 2026 19:51
@markemer markemer changed the title fix(cli): fix name collisions when something has the implicit name capacitor as a package fix(cli): fix name collisions in swift-package-manager Nov 20, 2026

@theproducer theproducer left a comment

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.

With this change,

content = content.replace(`apache`, `ionic-team`).replaceAll(`cordova-ios`, SOURCE_PACKAGE_IDENTITY);

might rewrite apache/cordova-ios.git to ionic-team/capacitor-ios.git which will obviously won't work.

Comment on lines +133 to +141
for (const name of previousNames) {
if (remainingNames.has(name)) {
continue;
}
rewritten = rewritten.replace(
new RegExp(`(package:\\s*)"${escapeRegExp(name)}"`, 'gi'),
`$1"${SOURCE_PACKAGE_IDENTITY}"`,
);
}

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.

This could edit text inside comments and strings, not sure if that's intended or not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question. I think it's unlikely that these will be in comments? So we're probably ok?

Swift Package Manager accepts either name for a dependency in
.product(package:): the name: it was given, or the identity it
gets from the end of its path or URL. The old code recorded only
one name per dependency, so I replaced packageReferenceName
with packageReferenceNames, which returns both. This has two effects:

- Other dependencies keep their products. When the code checks which
names still belong to other dependencies, it now records both names,
and it skips the Capacitor entries themselves. So
`.package(name: "SentryCapacitor", path: "../../@sentry/capacitor")
protects package: "capacitor", and Sentry’s products are no longer renamed to capacitor-ios.

A second bug is fixed too. When collecting Capacitor’s old names, the code now takes both.
Before this, a plugin with .package(name: "CapacitorSwiftPM", url: ".../capacitor-swift-pm.git")
would have kept .product(..., package: "capacitor-swift-pm"), which no longer resolves.
@markemer
markemer requested review from theproducer and a balanced review from Copilot November 23, 2026 15:44

This comment was marked as low quality.

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

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.

Overall me and Claude tested and seems to be working fine with different combination of plugin Package.swift files.

Leaving a few non-blocker comments.

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 usually consider this kind of template changes to be in a new major as a "breaking change". I personally don't mind this because it's in a file that gets regenerated by the CLI when doing cap sync anyway, but just wanna highlight it to make sure we're "okay" with it.

const SOURCE_PACKAGE_URL = 'https://github.com/ionic-team/capacitor';
export const SOURCE_PACKAGE_IDENTITY = 'capacitor';
const SOURCE_PACKAGE_NAME = new RegExp(`name:\\s*"${SOURCE_PACKAGE_IDENTITY}"`);
export const SOURCE_PACKAGE_IDENTITY = 'capacitor-ios';

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.

Unrelated to this PR specifically: we should tweak the docs entry with this new identity https://github.com/ionic-team/capacitor-docs/blob/f5de151948208d132c1a76f5eee3f2cd44d45a27/docs/main/updating/9-0.md#capacitor-builds-from-node_modules

I suppose this can be done in ionic-team/capacitor-docs#639

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I'll do it in ionic-team/capacitor-docs#639, but good catch.

@markemer
markemer merged commit 82b01fd into main Nov 24, 2026
6 checks passed
@markemer
markemer deleted the OSSS-155 branch November 24, 2026 15:53
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.

bug(cli, ios): 9.0.0-rc.0 local core package identity "capacitor" clashes with plugins in a folder named capacitor (e.g. @sentry/capacitor)

4 participants