Skip to content

Commit 77a1734

Browse files
clydinmgechev
authored andcommitted
fix(@angular/cli): standardize TTY checks
1 parent 6d5454d commit 77a1734

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

packages/angular/cli/models/analytics.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as os from 'os';
1414
import * as ua from 'universal-analytics';
1515
import { v4 as uuidV4 } from 'uuid';
1616
import { getWorkspace, getWorkspaceRaw } from '../utilities/config';
17+
import { isTTY } from '../utilities/tty';
1718

1819
const analyticsDebug = debug('ng:analytics'); // Generate analytics, including settings and users.
1920
const analyticsLogDebug = debug('ng:analytics:log'); // Actual logs of events.
@@ -359,7 +360,7 @@ export function setAnalyticsConfig(level: 'global' | 'local', value: string | bo
359360
*/
360361
export async function promptGlobalAnalytics(force = false) {
361362
analyticsDebug('prompting global analytics.');
362-
if (force || (process.stdout.isTTY && process.stdin.isTTY)) {
363+
if (force || isTTY()) {
363364
const answers = await inquirer.prompt<{ analytics: boolean }>([
364365
{
365366
type: 'confirm',
@@ -407,7 +408,7 @@ export async function promptProjectAnalytics(force = false): Promise<boolean> {
407408
throw new Error(`Could not find a local workspace. Are you in a project?`);
408409
}
409410

410-
if (force || (process.stdout.isTTY && process.stdin.isTTY)) {
411+
if (force || isTTY()) {
411412
const answers = await inquirer.prompt<{ analytics: boolean }>([
412413
{
413414
type: 'confirm',

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from '../utilities/config';
3838
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
3939
import { getPackageManager } from '../utilities/package-manager';
40+
import { isTTY } from '../utilities/tty';
4041
import { isPackageNameSafeForAnalytics } from './analytics';
4142
import { BaseCommandOptions, Command } from './command';
4243
import { Arguments, CommandContext, CommandDescription, Option } from './interface';
@@ -299,7 +300,7 @@ export abstract class SchematicCommand<
299300
return undefined;
300301
});
301302

302-
if (options.interactive !== false && process.stdout.isTTY) {
303+
if (options.interactive !== false && isTTY()) {
303304
workflow.registry.usePromptProvider((definitions: Array<schema.PromptDefinition>) => {
304305
const questions: inquirer.Questions = definitions.map(definition => {
305306
const question: inquirer.Question = {

packages/angular/cli/utilities/tty.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
export function isTTY(): boolean {
9+
const force = process.env['NG_FORCE_TTY'];
10+
if (force !== undefined) {
11+
return !(force === '0' || force.toUpperCase() === 'FALSE');
12+
}
13+
14+
return !!process.stdout.isTTY && !!process.stdin.isTTY;
15+
}

0 commit comments

Comments
 (0)