Skip to content

Commit d788263

Browse files
committed
fix(@angular/cli): ensure full process exit with older local CLI versions
Angular CLI versions prior to v14 may not exit correctly if not forcibly exited via `process.exit`. When the local CLI version is less than v14, the CLI will now use `process.exit` to ensure the process exits with these older CLI versions. Fixes #23289
1 parent edc6afb commit d788263

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

packages/angular/cli/lib/init.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ import 'symbol-observable';
1010
// symbol polyfill must go first
1111
import { promises as fs } from 'fs';
1212
import * as path from 'path';
13-
import { SemVer } from 'semver';
13+
import { SemVer, major } from 'semver';
1414
import { colors } from '../src/utilities/color';
1515
import { isWarningEnabled } from '../src/utilities/config';
1616
import { disableVersionCheck } from '../src/utilities/environment-options';
1717
import { VERSION } from '../src/utilities/version';
1818

19+
/**
20+
* Angular CLI versions prior to v14 may not exit correctly if not forcibly exited
21+
* via `process.exit()`. When bootstrapping, `forceExit` will be set to `true`
22+
* if the local CLI version is less than v14 to prevent the CLI from hanging on
23+
* exit in those cases.
24+
*/
25+
let forceExit = false;
26+
1927
(async () => {
2028
/**
2129
* Disable Browserslist old data warning as otherwise with every release we'd need to update this dependency
@@ -57,6 +65,11 @@ import { VERSION } from '../src/utilities/version';
5765
}
5866
}
5967

68+
// Ensure older versions of the CLI fully exit
69+
if (major(localVersion) < 14) {
70+
forceExit = true;
71+
}
72+
6073
let isGlobalGreater = false;
6174
try {
6275
isGlobalGreater = !!localVersion && globalVersion.compare(localVersion) > 0;
@@ -107,6 +120,9 @@ import { VERSION } from '../src/utilities/version';
107120
});
108121
})
109122
.then((exitCode: number) => {
123+
if (forceExit) {
124+
process.exit(exitCode);
125+
}
110126
process.exitCode = exitCode;
111127
})
112128
.catch((err: Error) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createProjectFromAsset } from '../../utils/assets';
2+
import { moveFile, replaceInFile } from '../../utils/fs';
3+
import { setRegistry } from '../../utils/packages';
4+
import { noSilentNg } from '../../utils/process';
5+
import { useCIChrome } from '../../utils/project';
6+
import { expectToFail } from '../../utils/utils';
7+
8+
/**
9+
* @fileoverview This tests that using the latest version of the CLI globally does not cause older (< 14)
10+
* versions of the CLI to never exit after completing certain commands.
11+
* This test will timeout in a failure condition.
12+
*/
13+
14+
export default async function () {
15+
try {
16+
// We need to use the public registry because in the local NPM server we don't have
17+
// older versions @angular/cli packages which would cause `npm install` during `ng update` to fail.
18+
await setRegistry(false);
19+
await createProjectFromAsset('12.0-project', true);
20+
21+
// A missing stylesheet error will trigger the stuck process issue with v12 when building
22+
await moveFile('src/styles.css', 'src/styles.scss');
23+
await expectToFail(() => noSilentNg('build'));
24+
25+
// Setup a SCSS global stylesheet
26+
// Simulates issue https://github.com/angular/angular-cli/issues/23289
27+
await replaceInFile('angular.json', /styles\.css/g, 'styles.scss');
28+
29+
await useCIChrome();
30+
await noSilentNg('test', '--watch=false');
31+
} finally {
32+
await setRegistry(true);
33+
}
34+
}

0 commit comments

Comments
 (0)