Skip to content

Commit

Permalink
feat(spm): Move CordovaPlugins into the packages dir
Browse files Browse the repository at this point in the history
This helps keep the top level project directory a bit cleaner by hiding
our CordovaPlugins SPM accumulator package inside the packages
directory.
  • Loading branch information
dpogue committed Jan 19, 2025
1 parent 94ef873 commit b258ad9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/SwiftPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
4 changes: 2 additions & 2 deletions templates/project/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
20 changes: 11 additions & 9 deletions tests/spec/unit/SwiftPackage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ 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);
});

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")');
});

Expand All @@ -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")');
});

Expand All @@ -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);
Expand All @@ -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")');
});
Expand Down

0 comments on commit b258ad9

Please sign in to comment.