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): show error if npm install on migration failed #5904

Merged
merged 3 commits into from
Sep 13, 2022
Merged
Changes from 1 commit
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
45 changes: 29 additions & 16 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { writeFileSync, readFileSync, existsSync } from '@ionic/utils-fs';
import { join } from 'path';
import rimraf from 'rimraf';

import c from '../colors';
import { runTask } from '../common';
import type { Config } from '../definitions';
import { fatal } from '../errors';
import { logger, logPrompt, logSuccess } from '../log';
import { deleteFolderRecursive } from '../util/fs';
import { getCommandOutput } from '../util/subprocess';
import { runCommand, getCommandOutput } from '../util/subprocess';
import { extractTemplate } from '../util/template';
import { readXML } from '../util/xml';

Expand Down Expand Up @@ -105,16 +106,32 @@ export async function migrateCommand(config: Config): Promise<void> {
typeof npmInstallConfirm === 'string' &&
npmInstallConfirm.toLowerCase() === 'y';

await runTask(`Installing Latest NPM Modules.`, () => {
return installLatestNPMLibs(runNpmInstall, config);
});
try {
await runTask(`Installing Latest NPM Modules.`, () => {
return installLatestNPMLibs(runNpmInstall, config);
});
} catch (ex) {
logger.error(
`npm install failed. Try deleting node_modules folder and running ${c.input(
'npm install --force',
)} manually.`,
);
}

await runTask(
`Migrating @capacitor/storage to @capacitor/preferences.`,
() => {
return migrateStoragePluginToPreferences(runNpmInstall);
},
);
try {
await runTask(
`Migrating @capacitor/storage to @capacitor/preferences.`,
() => {
return migrateStoragePluginToPreferences(runNpmInstall);
},
);
} catch (ex) {
logger.error(
`@capacitor/preferences failed to install. Try deleting node_modules folder and running ${c.input(
'npm install @capacitor/preferences --force',
)} manually.`,
);
}

if (
allDependencies['@capacitor/ios'] &&
Expand Down Expand Up @@ -376,9 +393,8 @@ async function installLatestNPMLibs(runInstall: boolean, config: Config) {
});

if (runInstall) {
rimraf.sync(join(config.app.rootDir, 'package-lock.json'));
rimraf.sync(join(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
await getCommandOutput('npm', ['i']);
await runCommand('npm', ['i']);
} else {
logger.info(
`Please run an install command with your package manager of choice. (ex: yarn install)`,
Expand All @@ -393,10 +409,7 @@ async function migrateStoragePluginToPreferences(runInstall: boolean) {
);
if (runInstall) {
await getCommandOutput('npm', ['uninstall', '@capacitor/storage']);
await getCommandOutput('npm', [
'i',
`@capacitor/preferences@${pluginVersion}`,
]);
await runCommand('npm', ['i', `@capacitor/preferences@${pluginVersion}`]);
} else {
logger.info(
`Please manually uninstall @capacitor/storage and replace it with @capacitor/preferences@${pluginVersion}`,
Expand Down