You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2026/09/23 13:28:31 UTC

(cordova-ios) branch master updated: Replace plugin variables with their actual values (#1724)

This is an automated email from the ASF dual-hosted git repository.

GitToTheHub pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new 97254540 Replace plugin variables with their actual values (#1724)
97254540 is described below

commit 972545409e3c9d302956eac7d937f2dc2f013680
Author: Maxim Chemerisuk <ch...@gmail.com>
AuthorDate: Wed Sep 23 16:28:25 2026 +0300

    Replace plugin variables with their actual values (#1724)
    
    In cordova-ios v8 framework added ability to use Swift Package Manager to manage plugin dependencies. After trying to switch to this new capability I noticed that there is no way to use plugin variables specified from CLI or default preference values from plugin.xml in Package.swift. At the same time there is logic that replaces plugin variables in plugin.xml, and this is really helpful for plugin authors.
---
 lib/SwiftPackage.js                                          |  5 +++++
 tests/spec/SwiftPackage.spec.js                              | 12 ++++++++++++
 .../org.test.plugins.swiftpackageplugin/Package.swift        |  3 ++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/SwiftPackage.js b/lib/SwiftPackage.js
index 4c5468a1..19fbdda8 100644
--- a/lib/SwiftPackage.js
+++ b/lib/SwiftPackage.js
@@ -78,6 +78,11 @@ package.targets.first?.dependencies.append(.product(name: "${plugin.id}", packag
             // exclusions.
             packageContent = packageContent.replace(/package\(.+cordova-ios.+\)/gm, `package(name: "cordova-ios", path: "${cordovaPath.replaceAll(path.sep, path.posix.sep)}")`);
 
+            // Replace plugin variables with their actual values
+            for (const [varName, varValue] of Object.entries(opts.variables ?? {})) {
+                packageContent = packageContent.replaceAll(`$${varName}`, varValue);
+            }
+
             fs.ftruncateSync(pkg_fd);
             fs.writeSync(pkg_fd, packageContent, 0, 'utf8');
             fs.closeSync(pkg_fd);
diff --git a/tests/spec/SwiftPackage.spec.js b/tests/spec/SwiftPackage.spec.js
index b8621068..32dc647b 100644
--- a/tests/spec/SwiftPackage.spec.js
+++ b/tests/spec/SwiftPackage.spec.js
@@ -144,6 +144,18 @@ describe('SwiftPackage', () => {
             expect(content).toContain('.product(name: "my-plugin", package: "my-plugin")');
         });
 
+        it('should replace plugin variables in the package file', () => {
+            pkg.addPlugin(my_plugin, {
+                variables: {
+                    SDK_VERSION: '0.0.1'
+                }
+            });
+
+            const pkgPath = path.join(tmpDir.name, 'packages', 'my-plugin', 'Package.swift');
+            const content = fs.readFileSync(pkgPath, 'utf8');
+            expect(content).toContain('.package(url: "https://github.com/apache/sdk.git", exact: "0.0.1")');
+        });
+
         it('should copy the plugin into the packages directory', () => {
             pkg.addPlugin(my_plugin);
 
diff --git a/tests/spec/fixtures/org.test.plugins.swiftpackageplugin/Package.swift b/tests/spec/fixtures/org.test.plugins.swiftpackageplugin/Package.swift
index 7efae140..5212ed53 100644
--- a/tests/spec/fixtures/org.test.plugins.swiftpackageplugin/Package.swift
+++ b/tests/spec/fixtures/org.test.plugins.swiftpackageplugin/Package.swift
@@ -31,7 +31,8 @@ let package = Package(
         .library(name: "PackagePlugin", targets: ["PackagePlugin"])
     ],
     dependencies: [
-        .package(url: "https://github.com/apache/cordova-ios.git", branch: "master")
+        .package(url: "https://github.com/apache/cordova-ios.git", branch: "master"),
+        .package(url: "https://github.com/apache/sdk.git", exact: "$SDK_VERSION")
     ],
     targets: [
         .target(


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org