Skip to content

Commit

Permalink
fix(cli): Don't succeed migration if npm install failed (#6595)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed May 17, 2023
1 parent caeeb09 commit 6843d96
Showing 1 changed file with 59 additions and 35 deletions.
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

0 comments on commit 6843d96

Please sign in to comment.