Skip to content

feat(@angular/cli): add flags to the process title #11920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/angular/cli/bin/ng
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

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

// Some older versions of Node do not support let or const.
var version = process.version.substr(1).split('.');
if (Number(version[0]) < 8 || (Number(version[0]) === 8 && Number(version[1]) < 9)) {
process.stderr.write(
Expand Down
16 changes: 16 additions & 0 deletions tests/legacy-cli/e2e/tests/misc/title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { execAndWaitForOutputToMatch, execWithEnv, killAllProcesses } from '../../utils/process';


export default async function() {
try {
await execAndWaitForOutputToMatch('ng', ['build', '--watch'], /./);

const output = await execWithEnv('ps', ['x'], { COLUMNS: '200' });

if (!output.stdout.match(/ng build --watch/)) {
throw new Error('Title of the process was not properly set.');
}
} finally {
await killAllProcesses();
}
}
9 changes: 8 additions & 1 deletion tests/legacy-cli/e2e/utils/process.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SpawnOptions } from "child_process";
import * as child_process from 'child_process';
import { terminal } from '@angular-devkit/core';
import { Observable, concat, defer, EMPTY, from} from 'rxjs';
Expand All @@ -11,6 +12,7 @@ const treeKill = require('tree-kill');
interface ExecOptions {
silent?: boolean;
waitForMatch?: RegExp;
env?: { [varname: string]: string };
}


Expand All @@ -26,6 +28,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc
let stdout = '';
let stderr = '';
const cwd = process.cwd();
const env = options.env;
console.log(
`==========================================================================================`
);
Expand All @@ -41,7 +44,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc

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

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

export function execWithEnv(cmd: string, args: string[], env: { [varname: string]: string }) {
return _exec({ env }, cmd, args);
}

export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
if (cmd === 'ng' && args[0] === 'serve') {
// Accept matches up to 20 times after the initial match.
Expand Down