diff --git a/cli/src/ios/update.ts b/cli/src/ios/update.ts index c15316688..ba934bf50 100644 --- a/cli/src/ios/update.ts +++ b/cli/src/ios/update.ts @@ -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'); @@ -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) { diff --git a/cli/test/update.ios.spm-plugins.spec.ts b/cli/test/update.ios.spm-plugins.spec.ts index f8fda9431..058f7ffba 100644 --- a/cli/test/update.ios.spm-plugins.spec.ts +++ b/cli/test/update.ios.spm-plugins.spec.ts @@ -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)' });