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

fix(cli): Don't succeed migration if npm install failed #6595

Merged
merged 2 commits into from
May 17, 2023
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
94 changes: 59 additions & 35 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const plugins = [
const coreVersion = '^5.0.0';
const pluginVersion = '^5.0.0';
const gradleVersion = '8.0.2';
let installFailed = false;

export async function migrateCommand(
config: Config,
Expand Down Expand Up @@ -93,8 +94,6 @@ export async function migrateCommand(
fatal('Variable and Classpath info could not be read.');
}

//*

allDependencies = {
...config.app.package.dependencies,
...config.app.package.devDependencies,
Expand Down Expand Up @@ -164,12 +163,12 @@ export async function migrateCommand(
},
);
} catch (ex) {
console.log(ex);
logger.error(
`${installerType} install failed. Try deleting node_modules folder and running ${c.input(
`${installerType} install --force`,
)} manually.`,
);
installFailed = true;
}

// Update iOS Projects
Expand Down Expand Up @@ -316,39 +315,53 @@ export async function migrateCommand(

rimraf.sync(join(config.android.appDirAbs, 'build'));

await runTask(
'Migrating package from Manifest to build.gradle in Capacitor plugins',
() => {
return patchOldCapacitorPlugins(config);
},
);
if (!installFailed) {
await runTask(
'Migrating package from Manifest to build.gradle in Capacitor plugins',
() => {
return patchOldCapacitorPlugins(config);
},
);
} else {
logger.warn(
'Skipped migrating package from Manifest to build.gradle in Capacitor plugins',
);
}
}

// Run Cap Sync
await runTask(`Running cap sync.`, () => {
return getCommandOutput('npx', ['cap', 'sync']);
});
if (!installFailed) {
// Run Cap Sync
await runTask(`Running cap sync.`, () => {
return getCommandOutput('npx', ['cap', 'sync']);
});
} else {
logger.warn('Skipped Running cap sync.');
}

if (
allDependencies['@capacitor/android'] &&
existsSync(config.android.platformDirAbs)
) {
try {
await runTask(`Upgrading gradle wrapper files`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
} catch (e: any) {
if (e.includes('EACCES')) {
logger.error(
`gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${c.input(
`chmod +x ./${config.android.platformDir}/gradlew`,
)} and ${c.input(
`cd ${config.android.platformDir} && ./gradlew wrapper --distribution-type all --gradle-version ${gradleVersion} --warning-mode all`,
)} to update the files manually`,
);
} else {
logger.error(`gradle wrapper files were not updated`);
if (!installFailed) {
try {
await runTask(`Upgrading gradle wrapper files`, () => {
return updateGradleWrapperFiles(config.android.platformDirAbs);
});
} catch (e: any) {
if (e.includes('EACCES')) {
logger.error(
`gradlew file does not have executable permissions. This can happen if the Android platform was added on a Windows machine. Please run ${c.input(
`chmod +x ./${config.android.platformDir}/gradlew`,
)} and ${c.input(
`cd ${config.android.platformDir} && ./gradlew wrapper --distribution-type all --gradle-version ${gradleVersion} --warning-mode all`,
)} to update the files manually`,
);
} else {
logger.error(`gradle wrapper files were not updated`);
}
}
} else {
logger.warn('Skipped upgrading gradle wrapper files');
}
}

Expand All @@ -357,16 +370,21 @@ export async function migrateCommand(
return writeBreakingChanges();
});

logSuccess(
`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`,
);
if (!installFailed) {
logSuccess(
`Migration to Capacitor ${coreVersion} is complete. Run and test your app!`,
);
} else {
logger.warn(
`Migration to Capacitor ${coreVersion} is incomplete. Check the log messages for more information.`,
);
}
} catch (err) {
fatal(`Failed to migrate: ${err}`);
}
} else {
fatal(`User canceled migration.`);
}
//*/
}

async function checkCapacitorMajorVersion(config: Config): Promise<number> {
Expand Down Expand Up @@ -858,9 +876,15 @@ export async function patchOldCapacitorPlugins(
if (buildGradlePath && manifestPath) {
const gradleContent = readFile(buildGradlePath);
if (!gradleContent?.includes('namespace')) {
logger.warn(
`${p.id} doesn't officially support Capacitor ${coreVersion} yet, doing our best moving it's package to build.gradle so it builds`,
);
if (plugins.includes(p.id)) {
logger.warn(
`You are using an outdated version of ${p.id}, update the plugin to version ${pluginVersion}`,
);
} else {
logger.warn(
`${p.id}@${p.version} doesn't officially support Capacitor ${coreVersion} yet, doing our best moving it's package to build.gradle so it builds`,
);
}
movePackageFromManifestToBuildGradle(manifestPath, buildGradlePath);
}
}
Expand Down