@@ -2,12 +2,13 @@ import { writeFileSync, readFileSync, existsSync } from '@ionic/utils-fs';
22import { join } from 'path' ;
33import rimraf from 'rimraf' ;
44
5+ import c from '../colors' ;
56import { runTask } from '../common' ;
67import type { Config } from '../definitions' ;
78import { fatal } from '../errors' ;
89import { logger , logPrompt , logSuccess } from '../log' ;
910import { deleteFolderRecursive } from '../util/fs' ;
10- import { getCommandOutput } from '../util/subprocess' ;
11+ import { runCommand , getCommandOutput } from '../util/subprocess' ;
1112import { extractTemplate } from '../util/template' ;
1213import { readXML } from '../util/xml' ;
1314
@@ -105,16 +106,32 @@ export async function migrateCommand(config: Config): Promise<void> {
105106 typeof npmInstallConfirm === 'string' &&
106107 npmInstallConfirm . toLowerCase ( ) === 'y' ;
107108
108- await runTask ( `Installing Latest NPM Modules.` , ( ) => {
109- return installLatestNPMLibs ( runNpmInstall , config ) ;
110- } ) ;
109+ try {
110+ await runTask ( `Installing Latest NPM Modules.` , ( ) => {
111+ return installLatestNPMLibs ( runNpmInstall , config ) ;
112+ } ) ;
113+ } catch ( ex ) {
114+ logger . error (
115+ `npm install failed. Try deleting node_modules folder and running ${ c . input (
116+ 'npm install --force' ,
117+ ) } manually.`,
118+ ) ;
119+ }
111120
112- await runTask (
113- `Migrating @capacitor/storage to @capacitor/preferences.` ,
114- ( ) => {
115- return migrateStoragePluginToPreferences ( runNpmInstall ) ;
116- } ,
117- ) ;
121+ try {
122+ await runTask (
123+ `Migrating @capacitor/storage to @capacitor/preferences.` ,
124+ ( ) => {
125+ return migrateStoragePluginToPreferences ( runNpmInstall ) ;
126+ } ,
127+ ) ;
128+ } catch ( ex ) {
129+ logger . error (
130+ `@capacitor/preferences failed to install. Try deleting node_modules folder and running ${ c . input (
131+ 'npm install @capacitor/preferences --force' ,
132+ ) } manually.`,
133+ ) ;
134+ }
118135
119136 if (
120137 allDependencies [ '@capacitor/ios' ] &&
@@ -376,9 +393,8 @@ async function installLatestNPMLibs(runInstall: boolean, config: Config) {
376393 } ) ;
377394
378395 if ( runInstall ) {
379- rimraf . sync ( join ( config . app . rootDir , 'package-lock.json' ) ) ;
380396 rimraf . sync ( join ( config . app . rootDir , 'node_modules/@capacitor/!(cli)' ) ) ;
381- await getCommandOutput ( 'npm' , [ 'i' ] ) ;
397+ await runCommand ( 'npm' , [ 'i' ] ) ;
382398 } else {
383399 logger . info (
384400 `Please run an install command with your package manager of choice. (ex: yarn install)` ,
@@ -393,10 +409,7 @@ async function migrateStoragePluginToPreferences(runInstall: boolean) {
393409 ) ;
394410 if ( runInstall ) {
395411 await getCommandOutput ( 'npm' , [ 'uninstall' , '@capacitor/storage' ] ) ;
396- await getCommandOutput ( 'npm' , [
397- 'i' ,
398- `@capacitor/preferences@${ pluginVersion } ` ,
399- ] ) ;
412+ await runCommand ( 'npm' , [ 'i' , `@capacitor/preferences@${ pluginVersion } ` ] ) ;
400413 } else {
401414 logger . info (
402415 `Please manually uninstall @capacitor/storage and replace it with @capacitor/preferences@${ pluginVersion } ` ,
0 commit comments