Skip to content

Commit

Permalink
fix(@angular/cli): do not collect analytics when running in non TTY mode
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
alan-agius4 committed Oct 14, 2022
1 parent 6280741 commit 22955f2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/angular/cli/src/analytics/analytics.ts
Expand Up @@ -184,7 +184,7 @@ export async function getAnalyticsUserId(
}
}

return globalConfig || randomUUID();
return globalConfig;
}

function analyticsConfigValueToHumanFormat(value: unknown): 'enabled' | 'disabled' | 'not set' {
Expand Down
@@ -0,0 +1,11 @@
import assert from 'node:assert';
import { readFile } from '../../../utils/fs';
import { ng } from '../../../utils/process';

export default async function () {
await ng('analytics', 'enable');
assert.ok(JSON.parse(await readFile('angular.json')).cli.analytics);

await ng('analytics', 'disable');
assert.strictEqual(JSON.parse(await readFile('angular.json')).cli.analytics, false);
}
27 changes: 27 additions & 0 deletions tests/legacy-cli/e2e/tests/commands/analytics/analytics-info.ts
@@ -0,0 +1,27 @@
import { execAndWaitForOutputToMatch } from '../../../utils/process';
import { updateJsonFile } from '../../../utils/project';

export default async function () {
// Should be disabled by default.
await configureTest(undefined /** analytics */);
await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: disabled/, {
NG_FORCE_TTY: '0', // Disable prompts
});

await configureTest('1dba0835-38a3-4957-bf34-9974e2df0df3' /** analytics */);
await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: enabled/, {
NG_FORCE_TTY: '0', // Disable prompts
});

await configureTest(false /** analytics */);
await execAndWaitForOutputToMatch('ng', ['analytics', 'info'], /Effective status: disabled/, {
NG_FORCE_TTY: '0', // Disable prompts
});
}

async function configureTest(analytics: false | string | undefined): Promise<void> {
await updateJsonFile('angular.json', (config) => {
config.cli ??= {};
config.cli.analytics = analytics;
});
}
@@ -1,5 +1,5 @@
import { execWithEnv } from '../../utils/process';
import { mockHome } from '../../utils/utils';
import { execWithEnv } from '../../../utils/process';
import { mockHome } from '../../../utils/utils';

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

Expand Down

0 comments on commit 22955f2

Please sign in to comment.