Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function updatePluginFiles(config: Config, plugins: Plugin[], deployment:
const iosPlatformVersion = await getCapacitorPackageVersion(config, config.ios.name);
const majorCapVersion = major(iosPlatformVersion);
const capacitorPackagePath = await resolveCapacitorPackagePath(config);
const packageOptions = config.app.extConfig.experimental?.ios?.spm?.packageOptions ?? {};
await Promise.all(
validSPMPackages.map(async (plugin) => {
const packageSwiftPath = join(plugin.rootPath, 'Package.swift');
Expand All @@ -85,7 +86,12 @@ async function updatePluginFiles(config: Config, plugins: Plugin[], deployment:

// The plugin has to resolve to the same package identity as the app, or SPM ends up with
// two packages that both vend a Capacitor product.
let rewritten = rewriteCapacitorDependency(content, capacitorPackagePath, plugin.rootPath);
// With `symlink: true` the app package reaches the plugin through a symlink, and SwiftPM
// resolves the plugin's relative paths from the symlink's location without following it.
const fromDir = packageOptions[plugin.id]?.symlink
? join(config.ios.nativeProjectDirAbs, 'CapApp-SPM', 'symlinks', plugin.name)
: plugin.rootPath;
let rewritten = rewriteCapacitorDependency(content, capacitorPackagePath, fromDir);
rewritten = patchPackageSwiftDeploymentTarget(rewritten, config.ios.minVersion).content;

if (rewritten !== content) {
Expand Down
15 changes: 15 additions & 0 deletions cli/test/update.ios.spm-plugins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ let package = Package(
expect(content).toContain('platforms: [.iOS(.v16)]');
});

it('resolves the Capacitor path from the symlink folder for a plugin with packageOptions.symlink', async () => {
const manifests = await makeSpmApp(tmpDir.path, '16.0', { app: '.iOS(.v16)' });
await writeJSON(join(tmpDir.path, 'capacitor.config.json'), {
appId: 'com.example.app',
appName: 'App',
webDir: 'www',
experimental: { ios: { spm: { packageOptions: { '@capacitor/app': { symlink: true } } } } },
});

await updateIOS(await loadAppConfig(tmpDir.path), false);

const content = await readFile(manifests.app, 'utf-8');
expect(content).toContain('.package(name: "capacitor-ios", path: "../../../../../node_modules/@capacitor/ios")');
});

it('leaves a plugin that already declares a target at or above the Capacitor minimum alone', async () => {
const manifests = await makeSpmApp(tmpDir.path, '18.0', { app: '.iOS(.v17)' });

Expand Down
Loading