Skip to content

Commit

Permalink
Supports Yarn v2 and Yarn v3
Browse files Browse the repository at this point in the history
This pull request enables user to use yarn berry (aka yarn v2 and yarn v3) as their package manager, and fixed ionic-team#4483
  • Loading branch information
Losses authored Jul 19, 2022
1 parent 866d8fc commit 4ce456d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/@ionic/cli/src/lib/utils/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,30 @@ export async function pkgManagerArgs(npmClient: NpmClient, options: PkgManagerOp
}
}

const installerExec: string = '';
const installerArgs: string[] = [];

switch (npmClient) {
case 'npm':
installerExec = 'npm';
vocab = { run: 'run', install: 'i', bareInstall: 'i', uninstall: 'uninstall', dedupe: 'dedupe', rebuild: 'rebuild', global: '-g', save: '--save', saveDev: '-D', saveExact: '-E', nonInteractive: '', lockFileOnly: '--package-lock-only' };
break;
case 'yarn':
installerExec = 'yarn';
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'install', global: '', save: '', saveDev: '--dev', saveExact: '--exact', nonInteractive: '--non-interactive', lockFileOnly: '' };
if (options.global) { // yarn installs packages globally under the 'global' prefix, instead of having a flag
installerArgs.push('global');
}
break;
case 'yarn-berry':
installerExec = 'yarn';
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'install', global: '', save: '', saveDev: '--dev', saveExact: '--exact', nonInteractive: '', lockFileOnly: '' };
if (options.global) { // yarn installs packages globally under the 'global' prefix, instead of having a flag
installerArgs.push('global');
}
break;
case 'pnpm':
installerExec = 'pnpm';
vocab = { run: 'run', install: 'add', bareInstall: 'install', uninstall: 'remove', dedupe: '', rebuild: 'rebuild', global: '--global', save: '', saveDev: '--save-dev', saveExact: '--save-exact', nonInteractive: '', lockFileOnly: '--lockfile-only' };
break;
default:
Expand Down Expand Up @@ -171,7 +182,7 @@ export async function pkgManagerArgs(npmClient: NpmClient, options: PkgManagerOp
installerArgs.push('--json');
}

return [npmClient, ...installerArgs];
return [installerExec, ...installerArgs];
}

/**
Expand Down

0 comments on commit 4ce456d

Please sign in to comment.