From eda96def48e11533cd0a3353c96b7eac9a881e1e Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 15 Nov 2022 13:57:20 +0000 Subject: [PATCH] fix(@angular/cli): use global version of the CLI when running `ng new` In some cases orphan `node_modules` would cause the non global CLI to be used to generate a new workspace. Closes #14603 (cherry picked from commit 412cb3e61f7f0c05004a76d2955fdf65451eac88) --- packages/angular/cli/lib/init.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/angular/cli/lib/init.ts b/packages/angular/cli/lib/init.ts index 0ec6c94c071a..feed3a56d901 100644 --- a/packages/angular/cli/lib/init.ts +++ b/packages/angular/cli/lib/init.ts @@ -33,17 +33,21 @@ let forceExit = false; * See: https://github.com/browserslist/browserslist/blob/819c4337456996d19db6ba953014579329e9c6e1/node.js#L324 */ process.env.BROWSERSLIST_IGNORE_OLD_DATA = '1'; + const rawCommandName = process.argv[2]; /** * Disable CLI version mismatch checks and forces usage of the invoked CLI * instead of invoking the local installed version. + * + * When running `ng new` always favor the global version. As in some + * cases orphan `node_modules` would cause the non global CLI to be used. + * @see: https://github.com/angular/angular-cli/issues/14603 */ - if (disableVersionCheck) { + if (disableVersionCheck || rawCommandName === 'new') { return (await import('./cli')).default; } let cli; - const rawCommandName = process.argv[2]; try { // No error implies a projectLocalCli, which will load whatever