Skip to content

Commit f1db498

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 exit gracefully. ``` The specified command ("completion") is invalid. For a list of available options, run "ng help". Did you mean "analytics"? ``` Closes angular#23518
1 parent 62b8568 commit f1db498

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/angular/cli/lib/init.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { VERSION } from '../src/utilities/version';
2424
*/
2525
let forceExit = false;
2626

27-
(async () => {
27+
(async (): Promise<typeof import('./cli').default | null> => {
2828
/**
2929
* Disable Browserslist old data warning as otherwise with every release we'd need to update this dependency
3030
* which is cumbersome considering we pin versions and the warning is not user actionable.
@@ -42,6 +42,8 @@ let forceExit = false;
4242
}
4343

4444
let cli;
45+
const rawCommandName = process.argv[2];
46+
4547
try {
4648
// No error implies a projectLocalCli, which will load whatever
4749
// version of ng-cli you have installed in a local package.json
@@ -68,6 +70,11 @@ let forceExit = false;
6870
// Ensure older versions of the CLI fully exit
6971
if (major(localVersion) < 14) {
7072
forceExit = true;
73+
74+
// Versions prior to 14 didn't implemenent completion command.
75+
if (rawCommandName === 'completion') {
76+
return null;
77+
}
7178
}
7279

7380
let isGlobalGreater = false;
@@ -78,7 +85,6 @@ let forceExit = false;
7885
console.error('Version mismatch check skipped. Unable to compare local version: ' + error);
7986
}
8087

81-
const rawCommandName = process.argv[2];
8288
// When using the completion command, don't show the warning as otherwise this will break completion.
8389
if (isGlobalGreater && rawCommandName !== 'completion') {
8490
// If using the update command and the global version is greater, use the newer update command
@@ -114,14 +120,12 @@ let forceExit = false;
114120

115121
return cli;
116122
})()
117-
.then((cli) => {
118-
return cli({
123+
.then((cli) =>
124+
cli?.({
119125
cliArgs: process.argv.slice(2),
120-
inputStream: process.stdin,
121-
outputStream: process.stdout,
122-
});
123-
})
124-
.then((exitCode: number) => {
126+
}),
127+
)
128+
.then((exitCode = 0) => {
125129
if (forceExit) {
126130
process.exit(exitCode);
127131
}

0 commit comments

Comments
 (0)