Skip to content

fix(@angular/cli): handle cases were having completion enabled but running in an older CLI workspace #23520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { VERSION } from '../src/utilities/version';
*/
let forceExit = false;

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

let cli;
const rawCommandName = process.argv[2];

try {
// No error implies a projectLocalCli, which will load whatever
// version of ng-cli you have installed in a local package.json
Expand All @@ -68,6 +70,11 @@ let forceExit = false;
// Ensure older versions of the CLI fully exit
if (major(localVersion) < 14) {
forceExit = true;

// Versions prior to 14 didn't implement completion command.
if (rawCommandName === 'completion') {
return null;
}
}

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

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

return cli;
})()
.then((cli) => {
return cli({
.then((cli) =>
cli?.({
cliArgs: process.argv.slice(2),
inputStream: process.stdin,
outputStream: process.stdout,
});
})
.then((exitCode: number) => {
}),
)
.then((exitCode = 0) => {
if (forceExit) {
process.exit(exitCode);
}
Expand Down