Skip to content

Commit f4670fc

Browse files
alan-agius4clydin
authored andcommittedMay 21, 2024
fix(@angular/cli): eliminate prompts during ng version command
This update removes the analytics and completion prompts that appear when executing the `ng version` command, ensuring a smoother and uninterrupted user experience. Closes #27668 (cherry picked from commit 3619505)
1 parent d034c1b commit f4670fc

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed
 

‎packages/angular/cli/src/command-builder/command-module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
176176

177177
const userId = await getAnalyticsUserId(
178178
this.context,
179-
// Don't prompt for `ng update` and `ng analytics` commands.
180-
['update', 'analytics'].includes(this.commandName),
179+
// Don't prompt on `ng update`, 'ng version' or `ng analytics`.
180+
['version', 'update', 'analytics'].includes(this.commandName),
181181
);
182182

183183
return userId ? new AnalyticsCollector(this.context, userId) : undefined;

‎packages/angular/cli/src/utilities/completion.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ async function shouldPromptForAutocompletionSetup(
130130
return forceAutocomplete;
131131
}
132132

133-
// Don't prompt on `ng update` or `ng completion`.
134-
if (command === 'update' || command === 'completion') {
133+
// Don't prompt on `ng update`, 'ng version' or `ng completion`.
134+
if (['version', 'update', 'completion'].includes(command)) {
135135
return false;
136136
}
137137

‎tests/legacy-cli/e2e/tests/commands/analytics/ask-analytics-command.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default async function () {
88
await mockHome(async () => {
99
const { stdout } = await execWithEnv(
1010
'ng',
11-
['version'],
11+
['config'],
1212
{
1313
...process.env,
1414
NG_FORCE_TTY: '1',
@@ -24,7 +24,7 @@ export default async function () {
2424

2525
// CLI should skip analytics prompt with `NG_CLI_ANALYTICS=false`.
2626
await mockHome(async () => {
27-
const { stdout } = await execWithEnv('ng', ['version'], {
27+
const { stdout } = await execWithEnv('ng', ['config'], {
2828
...process.env,
2929
NG_FORCE_TTY: '1',
3030
NG_CLI_ANALYTICS: 'false',

‎tests/legacy-cli/e2e/tests/commands/completion/completion-prompt.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default async function () {
4242

4343
const { stdout } = await execWithEnv(
4444
'ng',
45-
['version'],
45+
['config'],
4646
{
4747
...DEFAULT_ENV,
4848
SHELL: '/bin/bash',
@@ -74,7 +74,7 @@ export default async function () {
7474

7575
const { stdout } = await execWithEnv(
7676
'ng',
77-
['version'],
77+
['config'],
7878
{
7979
...DEFAULT_ENV,
8080
SHELL: '/bin/bash',
@@ -112,7 +112,7 @@ export default async function () {
112112

113113
const { stdout: stdout1 } = await execWithEnv(
114114
'ng',
115-
['version'],
115+
['config'],
116116
{
117117
...DEFAULT_ENV,
118118
SHELL: '/bin/bash',
@@ -136,7 +136,7 @@ export default async function () {
136136
// User modifies their configuration and removes `ng completion`.
137137
await fs.writeFile(bashrc, '# Some new commands...');
138138

139-
const { stdout: stdout2 } = await execWithEnv('ng', ['version'], {
139+
const { stdout: stdout2 } = await execWithEnv('ng', ['config'], {
140140
...DEFAULT_ENV,
141141
SHELL: '/bin/bash',
142142
HOME: home,
@@ -165,7 +165,7 @@ export default async function () {
165165

166166
const { stdout: stdout1 } = await execWithEnv(
167167
'ng',
168-
['version'],
168+
['config'],
169169
{
170170
...DEFAULT_ENV,
171171
SHELL: '/bin/bash',
@@ -178,7 +178,7 @@ export default async function () {
178178
throw new Error('First execution did not prompt for autocompletion setup.');
179179
}
180180

181-
const { stdout: stdout2 } = await execWithEnv('ng', ['version'], {
181+
const { stdout: stdout2 } = await execWithEnv('ng', ['config'], {
182182
...DEFAULT_ENV,
183183
SHELL: '/bin/bash',
184184
HOME: home,
@@ -211,7 +211,7 @@ export default async function () {
211211

212212
const err = await execAndCaptureError(
213213
'ng',
214-
['version'],
214+
['config'],
215215
{
216216
...DEFAULT_ENV,
217217
SHELL: '/bin/bash',
@@ -231,7 +231,7 @@ export default async function () {
231231

232232
const { stdout: stdout2 } = await execWithEnv(
233233
'ng',
234-
['version'],
234+
['config'],
235235
{
236236
...DEFAULT_ENV,
237237
SHELL: '/bin/bash',
@@ -283,7 +283,7 @@ export default async function () {
283283

284284
// Does *not* prompt user for CI executions.
285285
{
286-
const { stdout } = await execWithEnv('ng', ['version'], {
286+
const { stdout } = await execWithEnv('ng', ['config'], {
287287
...DEFAULT_ENV,
288288
CI: 'true',
289289
NG_FORCE_TTY: undefined,
@@ -296,7 +296,7 @@ export default async function () {
296296

297297
// Does *not* prompt user for non-TTY executions.
298298
{
299-
const { stdout } = await execWithEnv('ng', ['version'], {
299+
const { stdout } = await execWithEnv('ng', ['config'], {
300300
...DEFAULT_ENV,
301301
NG_FORCE_TTY: 'false',
302302
});
@@ -308,7 +308,7 @@ export default async function () {
308308

309309
// Does *not* prompt user for executions without a `$HOME`.
310310
{
311-
const { stdout } = await execWithEnv('ng', ['version'], {
311+
const { stdout } = await execWithEnv('ng', ['config'], {
312312
...DEFAULT_ENV,
313313
HOME: undefined,
314314
});
@@ -323,7 +323,7 @@ export default async function () {
323323

324324
// Does *not* prompt user for executions without a `$SHELL`.
325325
{
326-
const { stdout } = await execWithEnv('ng', ['version'], {
326+
const { stdout } = await execWithEnv('ng', ['config'], {
327327
...DEFAULT_ENV,
328328
SHELL: undefined,
329329
});
@@ -338,7 +338,7 @@ export default async function () {
338338

339339
// Does *not* prompt user for executions from unknown shells.
340340
{
341-
const { stdout } = await execWithEnv('ng', ['version'], {
341+
const { stdout } = await execWithEnv('ng', ['config'], {
342342
...DEFAULT_ENV,
343343
SHELL: '/usr/bin/unknown',
344344
});
@@ -364,7 +364,7 @@ source <(ng completion script)
364364
`.trim(),
365365
);
366366

367-
const { stdout } = await execWithEnv('ng', ['version'], {
367+
const { stdout } = await execWithEnv('ng', ['config'], {
368368
...DEFAULT_ENV,
369369
SHELL: '/bin/bash',
370370
HOME: home,
@@ -383,7 +383,7 @@ source <(ng completion script)
383383
const bashrc = path.join(home, '.bashrc');
384384
await fs.writeFile(bashrc, `# Other content...`);
385385

386-
await execAndWaitForOutputToMatch('ng', ['version'], AUTOCOMPLETION_PROMPT, {
386+
await execAndWaitForOutputToMatch('ng', ['config'], AUTOCOMPLETION_PROMPT, {
387387
...DEFAULT_ENV,
388388
SHELL: '/bin/bash',
389389
HOME: home,
@@ -411,7 +411,7 @@ source <(ng completion script)
411411
const localCliBinary = path.join(localCliDir, 'ng');
412412
const pathDirs = process.env['PATH']!.split(':');
413413
const pathEnvVar = [...pathDirs, localCliDir].join(':');
414-
const { stdout } = await execWithEnv(localCliBinary, ['version'], {
414+
const { stdout } = await execWithEnv(localCliBinary, ['config'], {
415415
...DEFAULT_ENV,
416416
SHELL: '/bin/bash',
417417
HOME: home,
@@ -437,7 +437,7 @@ async function windowsTests(): Promise<void> {
437437
const bashrc = path.join(home, '.bashrc');
438438
await fs.writeFile(bashrc, `# Other content...`);
439439

440-
const { stdout } = await execWithEnv('ng', ['version'], { ...env });
440+
const { stdout } = await execWithEnv('ng', ['config'], { ...env });
441441

442442
if (AUTOCOMPLETION_PROMPT.test(stdout)) {
443443
throw new Error(

0 commit comments

Comments
 (0)
Please sign in to comment.