Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): migrate command updates #7795

Merged
merged 4 commits into from
Dec 16, 2024
Merged
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
84 changes: 38 additions & 46 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync, readFileSync, existsSync } from 'fs-extra';
import { join } from 'path';
import rimraf from 'rimraf';
import { coerce, gt, gte, lt } from 'semver';
import { coerce, gte, lt } from 'semver';

import { getAndroidPlugins } from '../android/common';
import c from '../colors';
Expand Down Expand Up @@ -44,9 +44,9 @@
'@capacitor/text-zoom',
'@capacitor/toast',
];
const coreVersion = '^6.0.0';
const pluginVersion = '^6.0.0';
const gradleVersion = '8.2.1';
const coreVersion = 'next';
const pluginVersion = 'next';
const gradleVersion = '8.11.1';
let installFailed = false;

export async function migrateCommand(config: Config, noprompt: boolean, packagemanager: string): Promise<void> {
Expand All @@ -55,14 +55,14 @@
}

const capMajor = await checkCapacitorMajorVersion(config);
if (capMajor < 5) {
fatal('Migrate can only be used on capacitor 5 and above, please use the CLI in Capacitor 5 to upgrade to 5 first');
if (capMajor < 6) {
fatal('Migrate can only be used on Capacitor 6, please use the CLI in Capacitor 6 to upgrade to 6 first');
}

const jdkMajor = await checkJDKMajorVersion();

if (jdkMajor < 17) {
logger.warn('Capacitor 6 requires JDK 17 or higher. Some steps may fail.');
if (jdkMajor < 21) {
logger.warn('Capacitor 7 requires JDK 21 or higher. Some steps may fail.');
}

const variablesAndClasspaths:
Expand All @@ -89,7 +89,7 @@

const { migrateconfirm } = noprompt
? { migrateconfirm: 'y' }
: await logPrompt(`Capacitor 6 sets a deployment target of iOS 13 and Android 14 (SDK 34). \n`, {
: await logPrompt(`Capacitor 7 sets a deployment target of iOS 14 and Android 15 (SDK 35). \n`, {
type: 'text',
name: 'migrateconfirm',
message: `Are you sure you want to migrate? (Y/n)`,
Expand Down Expand Up @@ -147,9 +147,19 @@
// Update iOS Projects
if (allDependencies['@capacitor/ios'] && existsSync(config.ios.platformDirAbs)) {
// ios template changes
// Remove NSLocationAlwaysUsageDescription
await runTask(`Migrating Info.plist by removing NSLocationAlwaysUsageDescription key.`, () => {
return removeKey(join(config.ios.nativeTargetDirAbs, 'Info.plist'), 'NSLocationAlwaysUsageDescription');
// Set deployment target to 14.0
await runTask(`Migrating deployment target to 14.0.`, () => {
return updateFile(
config,
join(config.ios.nativeXcodeProjDirAbs, 'project.pbxproj'),
'IPHONEOS_DEPLOYMENT_TARGET = ',
';',
'14.0',
);
});
// Update Podfile to 14.0
await runTask(`Migrating Podfile to 14.0.`, () => {
return updateFile(config, join(config.ios.nativeProjectDirAbs, 'Podfile'), `platform :ios, '`, `'`, '14.0');
});
}

Expand All @@ -166,8 +176,12 @@
join(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'),
);

if (!installFailed && gt(gradleVersion, gradleWrapperVersion)) {
if (!installFailed && gte(gradleVersion, gradleWrapperVersion)) {
try {
await runTask(`Upgrading gradle wrapper`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
// Run twice as first time it only updates the wrapper properties file
await runTask(`Upgrading gradle wrapper files`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
Expand All @@ -191,28 +205,6 @@
return updateBuildGradle(join(config.android.platformDirAbs, 'build.gradle'), variablesAndClasspaths);
});

// Replace deprecated compileSdkVersion
await runTask('Replacing deprecated compileSdkVersion from build.gradle', () => {
return (async (): Promise<void> => {
const buildGradleFilename = join(config.android.platformDirAbs, 'app', 'build.gradle');
const buildGradleText = readFile(buildGradleFilename);

if (!buildGradleText) {
logger.error(`Could not read ${buildGradleFilename}. Check its permissions and if it exists.`);
return;
}
const compileSdk = `compileSdkVersion rootProject.ext.compileSdkVersion`;
if (buildGradleText.includes(compileSdk)) {
const buildGradleReplaced = buildGradleText.replace(
compileSdk,
`compileSdk rootProject.ext.compileSdkVersion`,
);

writeFileSync(buildGradleFilename, buildGradleReplaced, 'utf-8');
}
})();
});

// Variables gradle
await runTask(`Migrating variables.gradle file.`, () => {
return (async (): Promise<void> => {
Expand Down Expand Up @@ -261,11 +253,11 @@
}
}
const pluginVariables: { [key: string]: string } = {
firebaseMessagingVersion: '23.3.1',
playServicesLocationVersion: '21.1.0',
androidxBrowserVersion: '1.7.0',
androidxMaterialVersion: '1.10.0',
androidxExifInterfaceVersion: '1.3.6',
firebaseMessagingVersion: '24.1.0',
playServicesLocationVersion: '21.3.0',
androidxBrowserVersion: '1.8.0',
androidxMaterialVersion: '1.12.0',
androidxExifInterfaceVersion: '1.3.7',
androidxCoreKTXVersion: '1.12.0',
googleMapsPlayServicesVersion: '18.2.0',
googleMapsUtilsVersion: '3.8.2',
Expand Down Expand Up @@ -360,11 +352,11 @@

async function writeBreakingChanges() {
const breaking = [
'@capacitor/camera',
'@capacitor/filesystem',
'@capacitor/geolocation',
'@capacitor/google-maps',
'@capacitor/local-notifications',
'@capacitor/app',
'@capacitor/device',
'@capacitor/haptics',
'@capacitor/splash-screen',
'@capacitor/statusbar',
];
const broken = [];
for (const lib of breaking) {
Expand All @@ -374,7 +366,7 @@
}
if (broken.length > 0) {
logger.info(
`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/6-0#plugins for breaking changes in these plugins that you use: ${broken.join(
`IMPORTANT: Review https://capacitorjs.com/docs/next/updating/7-0#plugins for breaking changes in these plugins that you use: ${broken.join(
', ',
)}.`,
);
Expand Down Expand Up @@ -637,7 +629,7 @@
);
}

async function removeKey(filename: string, key: string) {

Check warning on line 632 in cli/src/tasks/migrate.ts

View workflow job for this annotation

GitHub Actions / lint

'removeKey' is defined but never used
const txt = readFile(filename);
if (!txt) {
return;
Expand Down
Loading