Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import type { CommandRunner } from './install-scripts';
import { logger } from './log';
import { declaresOtherPackageManager } from './package-manager';
import { migratePackageSwift } from './package-swift';
import { runCommand } from './subprocess';

const coreVersion = '9.0.0-beta.0';
Expand Down Expand Up @@ -99,6 +100,7 @@ const prettierJavaVersion = '^2.7.7';
const prettierVersion = '^3.6.2';
const rimrafVersion = '^6.1.0';
const rollupVersion = '^4.53.2';
const rollupNodeResolveVersion = '^16.0.3';
const typesNodeVersion = '^24.10.1';
const typeScriptVersion = '^5.9.3';
const iOSVersion = '16';
Expand Down Expand Up @@ -190,6 +192,7 @@ export const run = async (): Promise<void> => {
updateIfOlder(pluginJSON, 'swiftlint', ionicSwiftlintVersion);
updateIfOlder(pluginJSON, 'rimraf', rimrafVersion);
updateIfOlder(pluginJSON, 'rollup', rollupVersion);
updateIfOlder(pluginJSON, '@rollup/plugin-node-resolve', rollupNodeResolveVersion);
updateIfOlder(pluginJSON, 'typescript', typeScriptVersion);
updateIfOlder(pluginJSON, '@types/node', typesNodeVersion);
let prettierUpdatedFromV2 = false;
Expand Down Expand Up @@ -324,6 +327,16 @@ export const run = async (): Promise<void> => {

// gradle.properties
await updateGradleProperties(join(androidDir, 'gradle.properties'));

// AGP first, since the wrapper task below runs on the new Gradle, which can't load AGP 8
const variablesAndClasspaths = {
variables: variables,
'com.android.tools.build:gradle': AGPVersion,
'com.google.gms:google-services': gmsVersion,
};
await updateBuildGradle(buildGradle, variablesAndClasspaths);
await shipProguardRules(dir, pluginJSON.capacitor.android.src, buildGradle);

const gradleWrapperPath = join(androidDir, 'gradle', 'wrapper', 'gradle-wrapper.properties');

const gradleWrapperVersion = getGradleWrapperVersion(gradleWrapperPath);
Expand Down Expand Up @@ -355,14 +368,6 @@ export const run = async (): Promise<void> => {
},
);
}

const variablesAndClasspaths = {
variables: variables,
'com.android.tools.build:gradle': AGPVersion,
'com.google.gms:google-services': gmsVersion,
};
await updateBuildGradle(buildGradle, variablesAndClasspaths);
await shipProguardRules(dir, pluginJSON.capacitor.android.src, buildGradle);
}
}

Expand All @@ -378,14 +383,9 @@ export const run = async (): Promise<void> => {
);
const packageSwift = join(dir, 'Package.swift');
await updateFile(join(iosDir, 'Podfile'), `platform :ios, '`, `'`, `${iOSVersion}.0`);
await updateFile(packageSwift, '[.iOS(.v', ')],', iOSVersion);
let packageSwiftText = readFileSync(packageSwift, 'utf-8');
packageSwiftText = packageSwiftText.replace(
/^[ \t]*\.product\(name:\s*"Cordova",\s*package:\s*"capacitor-swift-pm"\),?\n?/m,
'',
);
packageSwiftText = packageSwiftText.replaceAll('capacitor-swift-pm', 'capacitor');
writeFileSync(packageSwift, packageSwiftText, { encoding: 'utf-8' });
writeFileSync(packageSwift, migratePackageSwift(readFileSync(packageSwift, 'utf-8'), iOSVersion), {
encoding: 'utf-8',
});
await updateFile(
packageSwift,
'.package(url: "https://github.com/ionic-team/capacitor.git",',
Expand Down
76 changes: 76 additions & 0 deletions src/package-swift.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';

import { migratePackageSwift } from './package-swift.ts';

describe('migratePackageSwift', () => {
it('raises the iOS platform and removes Cordova when it is the last product', () => {
const before = `let package = Package(
name: "Plugin",
platforms: [.iOS(.v15)],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
],
targets: [
.target(
name: "Plugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
])
]
)`;
const after = `let package = Package(
name: "Plugin",
platforms: [.iOS(.v16)],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor.git", from: "8.0.0")
],
targets: [
.target(
name: "Plugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor")
])
]
)`;
assert.equal(migratePackageSwift(before, '16'), after);
});

it('keeps a newer iOS platform and unwraps only the Capacitor .upToNextMajor', () => {
const before = `let package = Package(
name: "Plugin",
platforms: [.iOS(.v17)],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", .upToNextMajor(from: "8.0.0")),
.package(url: "https://github.com/AzureAD/microsoft-authentication-library-for-objc.git", .upToNextMajor(from: "1.9.0"))
],
targets: [
.target(
name: "Plugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm"),
.product(name: "MSAL", package: "microsoft-authentication-library-for-objc")
])
]
)`;
const after = `let package = Package(
name: "Plugin",
platforms: [.iOS(.v17)],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor.git", from: "8.0.0"),
.package(url: "https://github.com/AzureAD/microsoft-authentication-library-for-objc.git", .upToNextMajor(from: "1.9.0"))
],
targets: [
.target(
name: "Plugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor"),
.product(name: "MSAL", package: "microsoft-authentication-library-for-objc")
])
]
)`;
assert.equal(migratePackageSwift(before, '16'), after);
});
});
14 changes: 14 additions & 0 deletions src/package-swift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function migratePackageSwift(text: string, iOSVersion: string): string {
text = text.replace(/\[\.iOS\(\.v(\d+)\)\]/, (platforms, version) =>
Number(version) < Number(iOSVersion) ? `[.iOS(.v${iOSVersion})]` : platforms,
);
// when Cordova is the last product, the comma before it has to go too
text = text.replace(/,\n[ \t]*\.product\(name:\s*"Cordova",\s*package:\s*"capacitor-swift-pm"\)(?=\s*\])/, '');
text = text.replace(/^[ \t]*\.product\(name:\s*"Cordova",\s*package:\s*"capacitor-swift-pm"\),?\n?/m, '');
text = text.replaceAll('capacitor-swift-pm', 'capacitor');
// the version is replaced up to the first ")", so unwrap .upToNextMajor(from:) first
return text.replace(
/(\.package\(url: "https:\/\/github\.com\/ionic-team\/capacitor\.git",\s*)\.upToNextMajor\((from:\s*"[^"]*")\)/,
'$1$2',
);
}
Loading