Skip to content

Commit e7bf105

Browse files
clydinvikerman
authored andcommitted
fix(@angular/cli): skip project analytics prompt when using update
The prompt will cause the workspace configuration file to be updated which can result in an unclean repository. Fixes #16012
1 parent 8820093 commit e7bf105

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

packages/angular/cli/models/command-runner.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,19 @@ export interface CommandMapOptions {
6464
* Create the analytics instance.
6565
* @private
6666
*/
67-
async function _createAnalytics(workspace: boolean): Promise<analytics.Analytics> {
67+
async function _createAnalytics(workspace: boolean, skipPrompt = false): Promise<analytics.Analytics> {
6868
let config = await getGlobalAnalytics();
6969
// If in workspace and global analytics is enabled, defer to workspace level
7070
if (workspace && config) {
71+
const skipAnalytics =
72+
skipPrompt ||
73+
(process.env['NG_CLI_ANALYTICS'] &&
74+
(process.env['NG_CLI_ANALYTICS'].toLowerCase() === 'false' ||
75+
process.env['NG_CLI_ANALYTICS'] === '0'));
7176
// TODO: This should honor the `no-interactive` option.
7277
// It is currently not an `ng` option but rather only an option for specific commands.
7378
// The concept of `ng`-wide options are needed to cleanly handle this.
74-
if (!(await hasWorkspaceAnalyticsConfiguration())) {
79+
if (!skipAnalytics && !(await hasWorkspaceAnalyticsConfiguration())) {
7580
await promptProjectAnalytics();
7681
}
7782
config = await getWorkspaceAnalytics();
@@ -231,7 +236,9 @@ export async function runCommand(
231236
return map;
232237
});
233238

234-
const analytics = options.analytics || await _createAnalytics(!!workspace.configFile);
239+
const analytics =
240+
options.analytics ||
241+
(await _createAnalytics(!!workspace.configFile, description.name === 'update'));
235242
const context = { workspace, analytics };
236243
const command = new description.impl(context, description, logger);
237244

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { execWithEnv, killAllProcesses, waitForAnyProcessOutputToMatch } from '../../utils/process';
2+
import { expectToFail } from '../../utils/utils';
3+
4+
export default async function() {
5+
try {
6+
// Execute a command with TTY force enabled
7+
const execution = execWithEnv('ng', ['version'], {
8+
...process.env,
9+
NG_FORCE_TTY: '1',
10+
NG_CLI_ANALYTICS: 'ci',
11+
});
12+
13+
// Check if the prompt is shown
14+
await waitForAnyProcessOutputToMatch(/Would you like to share anonymous usage data/);
15+
} finally {
16+
killAllProcesses();
17+
}
18+
19+
try {
20+
// Execute a command with TTY force enabled
21+
const execution = execWithEnv('ng', ['version'], {
22+
...process.env,
23+
NG_FORCE_TTY: '1',
24+
NG_CLI_ANALYTICS: 'false',
25+
});
26+
27+
// Check if the prompt is shown
28+
await expectToFail(() =>
29+
waitForAnyProcessOutputToMatch(/Would you like to share anonymous usage data/, 5),
30+
);
31+
} finally {
32+
killAllProcesses();
33+
}
34+
35+
// Should not show a prompt when using update
36+
try {
37+
// Execute a command with TTY force enabled
38+
const execution = execWithEnv('ng', ['update'], {
39+
...process.env,
40+
NG_FORCE_TTY: '1',
41+
NG_CLI_ANALYTICS: 'ci',
42+
});
43+
44+
// Check if the prompt is shown
45+
await expectToFail(() =>
46+
waitForAnyProcessOutputToMatch(/Would you like to share anonymous usage data/, 5),
47+
);
48+
} finally {
49+
killAllProcesses();
50+
}
51+
}

0 commit comments

Comments
 (0)