Skip to content

Commit c7a2a2f

Browse files
committed
feat(@angular/cli): add flags to the process title
Closes #8772 Fixes #6888 Special thanks to @tomastrajan for original PR.
1 parent ec3fa80 commit c7a2a2f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

packages/angular/cli/bin/ng

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
// Provide a title to the process in `ps`.
55
// Due to an obscure Mac bug, do not start this title with any symbol.
6-
process.title = 'ng';
6+
try {
7+
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
8+
} catch(_) {
9+
// If an error happened above, use the most basic title.
10+
process.title = 'ng';
11+
}
712

13+
// Some older versions of Node do not support let or const.
814
var version = process.version.substr(1).split('.');
915
if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) {
1016
process.stderr.write(
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { execAndWaitForOutputToMatch, execWithEnv, killAllProcesses } from '../../utils/process';
2+
3+
4+
export default async function() {
5+
try {
6+
await execAndWaitForOutputToMatch('ng', ['build', '--watch'], /./);
7+
8+
const output = await execWithEnv('ps', [], { COLUMNS: '200' });
9+
10+
if (!output.stdout.match(/ng build --/)) {
11+
throw new Error('Title of the process was not properly set.');
12+
}
13+
} finally {
14+
await killAllProcesses();
15+
}
16+
}

tests/legacy-cli/e2e/utils/process.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SpawnOptions } from "child_process";
12
import * as child_process from 'child_process';
23
import { terminal } from '@angular-devkit/core';
34
import { Observable, concat, defer, EMPTY, from} from 'rxjs';
@@ -11,6 +12,7 @@ const treeKill = require('tree-kill');
1112
interface ExecOptions {
1213
silent?: boolean;
1314
waitForMatch?: RegExp;
15+
env?: { [varname: string]: string };
1416
}
1517

1618

@@ -26,6 +28,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc
2628
let stdout = '';
2729
let stderr = '';
2830
const cwd = process.cwd();
31+
const env = options.env;
2932
console.log(
3033
`==========================================================================================`
3134
);
@@ -41,7 +44,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc
4144

4245
console.log(terminal.blue(`Running \`${cmd} ${args.map(x => `"${x}"`).join(' ')}\`${flags}...`));
4346
console.log(terminal.blue(`CWD: ${cwd}`));
44-
const spawnOptions: any = {cwd};
47+
const spawnOptions: SpawnOptions = {cwd, env};
4548

4649
if (process.platform.startsWith('win')) {
4750
args.unshift('/c', cmd);
@@ -146,6 +149,10 @@ export function silentExec(cmd: string, ...args: string[]) {
146149
return _exec({ silent: true }, cmd, args);
147150
}
148151

152+
export function execWithEnv(cmd: string, args: string[], env: { [varname: string]: string }) {
153+
return _exec({ env }, cmd, args);
154+
}
155+
149156
export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
150157
if (cmd === 'ng' && args[0] === 'serve') {
151158
// Accept matches up to 20 times after the initial match.

0 commit comments

Comments
 (0)