From b62809b91f1289092933f284f81509cb0d1240cb Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 20 Jan 2025 22:16:49 -0800 Subject: [PATCH] [WIP] feat(spm): Support linked cordova-ios TODO: Unit tests --- lib/SwiftPackage.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/SwiftPackage.js b/lib/SwiftPackage.js index 0e73008fe..593c60912 100644 --- a/lib/SwiftPackage.js +++ b/lib/SwiftPackage.js @@ -21,6 +21,8 @@ const fs = require('node:fs'); const path = require('node:path'); const CordovaError = require('cordova-common').CordovaError; +const ROOT = path.join(__dirname, '..'); + class SwiftPackage { constructor (projectRoot) { this.root = projectRoot; @@ -49,8 +51,10 @@ package.targets.first?.dependencies.append(.product(name: "${plugin.id}", packag const pkgSwiftPath = path.join(this.root, 'packages', plugin.id, 'Package.swift'); const pkg_fd = fs.openSync(pkgSwiftPath, 'r+'); - const cordovaPath = path.relative(pluginPath, path.join(this.root, 'packages', 'cordova-ios')); - // TODO: Detect if cordova-ios was linked and use that path + let cordovaPath = path.relative(pluginPath, path.join(this.root, 'packages', 'cordova-ios')); + if (!fs.existsSync(cordovaPath)) { + cordovaPath = path.relative(pluginPath, ROOT); + } let packageContent = fs.readFileSync(pkg_fd, 'utf8'); packageContent = packageContent.replace(/package\(.+cordova-ios.+\)/gm, `package(name: "cordova-ios", path: "${cordovaPath.replaceAll(path.sep, path.posix.sep)}")`);