Skip to content

Commit cbf7c02

Browse files
committed
fix(@angular/cli): handle cases were having completion enabled but running in an older CLI workspace
Previously when having completion enabled and the current workspaces has an older version of the Angular CLI installed in the terminal the below errors is show. This is because the older versions of the CLI do not implement this command. Now we favor the global version if it's greater than the local version of the CLI. ``` The specified command ("completion") is invalid. For a list of available options, run "ng help". Did you mean "analytics"? ``` Closes angular#23518
1 parent 325990f commit cbf7c02

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/angular/cli/lib/init.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ let forceExit = false;
7979
}
8080

8181
const rawCommandName = process.argv[2];
82-
// When using the completion command, don't show the warning as otherwise this will break completion.
83-
if (isGlobalGreater && rawCommandName !== 'completion') {
84-
// If using the update command and the global version is greater, use the newer update command
85-
// This allows improvements in update to be used in older versions that do not have bootstrapping
82+
if (isGlobalGreater) {
83+
// If using the update/completion command and the global version is greater. Use the global version.
84+
// - update: This allows improvements in update to be used in older versions that do not have bootstrapping.
85+
// - completion: This allows improvements to the completion command and handles the case where older local
86+
// versions of the CLI don't have this command.
8687
if (
87-
rawCommandName === 'update' &&
88-
cli.VERSION &&
89-
cli.VERSION.major - globalVersion.major <= 1
88+
rawCommandName === 'completion' ||
89+
(rawCommandName === 'update' && cli.VERSION && cli.VERSION.major - globalVersion.major <= 1)
9090
) {
9191
cli = await import('./cli');
9292
} else if (await isWarningEnabled('versionMismatch')) {

0 commit comments

Comments
 (0)