Skip to content

Commit 22955f2

Browse files
committed
fix(@angular/cli): do not collect analytics when running in non TTY mode
Prior to this change we collected analytics when config was not present and the CLI was running in non TTY mode. (cherry picked from commit 61fab64)
1 parent 6280741 commit 22955f2

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

packages/angular/cli/src/analytics/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export async function getAnalyticsUserId(
184184
}
185185
}
186186

187-
return globalConfig || randomUUID();
187+
return globalConfig;
188188
}
189189

190190
function analyticsConfigValueToHumanFormat(value: unknown): 'enabled' | 'disabled' | 'not set' {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import assert from 'node:assert';
2+
import { readFile } from '../../../utils/fs';
3+
import { ng } from '../../../utils/process';
4+
5+
export default async function () {
6+
await ng('analytics', 'enable');
7+
assert.ok(JSON.parse(await readFile('angular.json')).cli.analytics);
8+
9+
await ng('analytics', 'disable');
10+
assert.strictEqual(JSON.parse(await readFile('angular.json')).cli.analytics, false);
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { execAndWaitForOutputToMatch } from '../../../utils/process';
2+
import { updateJsonFile } from '../../../utils/project';
3+
4+
export default async function () {
5+
// Should be disabled by default.
6+
await configureTest(undefined /** analytics */);
7+
await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: disabled/, {
8+
NG_FORCE_TTY: '0', // Disable prompts
9+
});
10+
11+
await configureTest('1dba0835-38a3-4957-bf34-9974e2df0df3' /** analytics */);
12+
await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: enabled/, {
13+
NG_FORCE_TTY: '0', // Disable prompts
14+
});
15+
16+
await configureTest(false /** analytics */);
17+
await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: disabled/, {
18+
NG_FORCE_TTY: '0', // Disable prompts
19+
});
20+
}
21+
22+
async function configureTest(analytics: false | string | undefined): Promise<void> {
23+
await updateJsonFile('angular.json', (config) => {
24+
config.cli ??= {};
25+
config.cli.analytics = analytics;
26+
});
27+
}

tests/legacy-cli/e2e/tests/misc/ask-analytics-command.ts renamed to tests/legacy-cli/e2e/tests/commands/analytics/ask-analytics-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { execWithEnv } from '../../utils/process';
2-
import { mockHome } from '../../utils/utils';
1+
import { execWithEnv } from '../../../utils/process';
2+
import { mockHome } from '../../../utils/utils';
33

44
const ANALYTICS_PROMPT = /Would you like to share pseudonymous usage data/;
55

0 commit comments

Comments
 (0)