Skip to content

fix(@angular/cli): ensure full process exit with older local CLI versions #23298

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
Jun 7, 2022
Merged
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion packages/angular/cli/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import 'symbol-observable';
// symbol polyfill must go first
import { promises as fs } from 'fs';
import * as path from 'path';
import { SemVer } from 'semver';
import { SemVer, major } from 'semver';
import { colors } from '../src/utilities/color';
import { isWarningEnabled } from '../src/utilities/config';
import { disableVersionCheck } from '../src/utilities/environment-options';
import { VERSION } from '../src/utilities/version';

/**
* Angular CLI versions prior to v14 may not exit correctly if not forcibly exited
* via `process.exit()`. When bootstrapping, `forceExit` will be set to `true`
* if the local CLI version is less than v14 to prevent the CLI from hanging on
* exit in those cases.
*/
let forceExit = false;

(async () => {
/**
* Disable Browserslist old data warning as otherwise with every release we'd need to update this dependency
Expand Down Expand Up @@ -57,6 +65,11 @@ import { VERSION } from '../src/utilities/version';
}
}

// Ensure older versions of the CLI fully exit
if (major(localVersion) < 14) {
forceExit = true;
}

let isGlobalGreater = false;
try {
isGlobalGreater = !!localVersion && globalVersion.compare(localVersion) > 0;
Expand Down Expand Up @@ -107,6 +120,9 @@ import { VERSION } from '../src/utilities/version';
});
})
.then((exitCode: number) => {
if (forceExit) {
process.exit(exitCode);
}
process.exitCode = exitCode;
})
.catch((err: Error) => {
Expand Down
34 changes: 34 additions & 0 deletions tests/legacy-cli/e2e/tests/misc/cli-exit-interop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { createProjectFromAsset } from '../../utils/assets';
import { moveFile, replaceInFile } from '../../utils/fs';
import { setRegistry } from '../../utils/packages';
import { noSilentNg } from '../../utils/process';
import { useCIChrome } from '../../utils/project';
import { expectToFail } from '../../utils/utils';

/**
* @fileoverview This tests that using the latest version of the CLI globally does not cause older (< 14)
* versions of the CLI to never exit after completing certain commands.
* This test will timeout in a failure condition.
*/

export default async function () {
try {
// We need to use the public registry because in the local NPM server we don't have
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
await setRegistry(false);
await createProjectFromAsset('12.0-project', true);

// A missing stylesheet error will trigger the stuck process issue with v12 when building
await moveFile('src/styles.css', 'src/styles.scss');
await expectToFail(() => noSilentNg('build'));

// Setup a SCSS global stylesheet
// Simulates issue https://github.com/angular/angular-cli/issues/23289
await replaceInFile('angular.json', /styles\.css/g, 'styles.scss');

await useCIChrome();
await noSilentNg('test', '--watch=false');
} finally {
await setRegistry(true);
}
}