From b258ad969762b0d823190da0d96c84ed8132feba Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 18 Jan 2025 19:13:01 -0800 Subject: [PATCH] feat(spm): Move CordovaPlugins into the packages dir This helps keep the top level project directory a bit cleaner by hiding our CordovaPlugins SPM accumulator package inside the packages directory. --- lib/SwiftPackage.js | 2 +- .../project/App.xcodeproj/project.pbxproj | 4 ++-- .../cordova-ios-plugins}/Package.swift | 0 .../CordovaPlugins/CordovaPlugins.swift | 0 tests/spec/unit/SwiftPackage.spec.js | 20 ++++++++++--------- 5 files changed, 14 insertions(+), 12 deletions(-) rename templates/project/{CordovaPlugins => packages/cordova-ios-plugins}/Package.swift (100%) rename templates/project/{CordovaPlugins => packages/cordova-ios-plugins}/Sources/CordovaPlugins/CordovaPlugins.swift (100%) diff --git a/lib/SwiftPackage.js b/lib/SwiftPackage.js index 7f0223b7f..f58624a8c 100644 --- a/lib/SwiftPackage.js +++ b/lib/SwiftPackage.js @@ -24,7 +24,7 @@ const CordovaError = require('cordova-common').CordovaError; class SwiftPackage { constructor (projectRoot) { this.root = projectRoot; - this.path = path.join(this.root, 'CordovaPlugins', 'Package.swift'); + this.path = path.join(this.root, 'packages', 'cordova-ios-plugins', 'Package.swift'); if (!fs.existsSync(this.path)) { throw new CordovaError('Package.swift is not found.'); diff --git a/templates/project/App.xcodeproj/project.pbxproj b/templates/project/App.xcodeproj/project.pbxproj index 7c208a829..29ec0061f 100755 --- a/templates/project/App.xcodeproj/project.pbxproj +++ b/templates/project/App.xcodeproj/project.pbxproj @@ -529,9 +529,9 @@ isa = XCLocalSwiftPackageReference; relativePath = "../../../cordova-ios"; }; - 90D82ABB2CF19AEA001383CF /* XCLocalSwiftPackageReference "CordovaPlugins" */ = { + 90D82ABB2CF19AEA001383CF /* XCLocalSwiftPackageReference "packages/cordova-ios-plugins" */ = { isa = XCLocalSwiftPackageReference; - relativePath = CordovaPlugins; + relativePath = "packages/cordova-ios-plugins"; }; /* End XCLocalSwiftPackageReference section */ diff --git a/templates/project/CordovaPlugins/Package.swift b/templates/project/packages/cordova-ios-plugins/Package.swift similarity index 100% rename from templates/project/CordovaPlugins/Package.swift rename to templates/project/packages/cordova-ios-plugins/Package.swift diff --git a/templates/project/CordovaPlugins/Sources/CordovaPlugins/CordovaPlugins.swift b/templates/project/packages/cordova-ios-plugins/Sources/CordovaPlugins/CordovaPlugins.swift similarity index 100% rename from templates/project/CordovaPlugins/Sources/CordovaPlugins/CordovaPlugins.swift rename to templates/project/packages/cordova-ios-plugins/Sources/CordovaPlugins/CordovaPlugins.swift diff --git a/tests/spec/unit/SwiftPackage.spec.js b/tests/spec/unit/SwiftPackage.spec.js index 016969e81..b64d570a7 100644 --- a/tests/spec/unit/SwiftPackage.spec.js +++ b/tests/spec/unit/SwiftPackage.spec.js @@ -51,8 +51,8 @@ describe('SwiftPackage', () => { let pkg; beforeEach(() => { - fs.mkdirSync(path.join(tmpDir.name, 'CordovaPlugins')); - fs.writeFileSync(path.join(tmpDir.name, 'CordovaPlugins', 'Package.swift'), fixturePackage, 'utf8'); + fs.mkdirSync(path.join(tmpDir.name, 'packages', 'cordova-ios-plugins'), { recursive: true }); + fs.writeFileSync(path.join(tmpDir.name, 'packages', 'cordova-ios-plugins', 'Package.swift'), fixturePackage, 'utf8'); pkg = new SwiftPackage(tmpDir.name); }); @@ -60,9 +60,9 @@ describe('SwiftPackage', () => { it('should add plugin references to the package file', () => { pkg.addPlugin(my_plugin); - const pkgPath = path.join(tmpDir.name, 'CordovaPlugins', 'Package.swift'); + const pkgPath = path.join(tmpDir.name, 'packages', 'cordova-ios-plugins', 'Package.swift'); const content = fs.readFileSync(pkgPath, 'utf8'); - expect(content).toContain('.package(name: "my-plugin", path: "../packages/my-plugin")'); + expect(content).toContain('.package(name: "my-plugin", path: "../my-plugin")'); expect(content).toContain('.product(name: "my-plugin", package: "my-plugin")'); }); @@ -75,11 +75,11 @@ describe('SwiftPackage', () => { it('should add plugin references to the package file when linked', () => { pkg.addPlugin(my_plugin, { link: true }); - const pkgPath = path.join(tmpDir.name, 'CordovaPlugins', 'Package.swift'); + const pkgPath = path.join(tmpDir.name, 'packages', 'cordova-ios-plugins', 'Package.swift'); const content = fs.readFileSync(pkgPath, 'utf8'); expect(content).toContain('.package(name: "my-plugin", path: "'); - expect(content).not.toContain('.package(name: "my-plugin", path: "../packages/my-plugin")'); + expect(content).not.toContain('.package(name: "my-plugin", path: "../my-plugin")'); expect(content).toContain('.product(name: "my-plugin", package: "my-plugin")'); }); @@ -98,8 +98,8 @@ describe('SwiftPackage', () => { let pkg; beforeEach(() => { - fs.mkdirSync(path.join(tmpDir.name, 'CordovaPlugins')); - const pkgPath = path.join(tmpDir.name, 'CordovaPlugins', 'Package.swift'); + fs.mkdirSync(path.join(tmpDir.name, 'packages', 'cordova-ios-plugins'), { recursive: true }); + const pkgPath = path.join(tmpDir.name, 'packages', 'cordova-ios-plugins', 'Package.swift'); fs.writeFileSync(pkgPath, fixturePackage, 'utf8'); pkg = new SwiftPackage(tmpDir.name); @@ -109,7 +109,9 @@ describe('SwiftPackage', () => { it('should remove plugin references to the package file', () => { pkg.removePlugin(my_plugin); - const content = fs.readFileSync(path.join(tmpDir.name, 'CordovaPlugins', 'Package.swift'), 'utf8'); + const pkgPath = path.join(tmpDir.name, 'packages', 'cordova-ios-plugins', 'Package.swift'); + const content = fs.readFileSync(pkgPath, 'utf8'); + expect(content).not.toContain('.package(name: "my-plugin"'); expect(content).not.toContain('.product(name: "my-plugin", package: "my-plugin")'); });