Skip to content

Commit 889c254

Browse files
hanslalexeagle
authored andcommitted
fix(@angular-devkit/core): remove static initialization using process object
It does not work in a browser.
1 parent d9166b0 commit 889c254

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

packages/angular_devkit/core/src/terminal/caps.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ function _getColorLevel(stream: Socket): 0 | 1 | 2 | 3 {
152152

153153

154154
function _getRows() {
155-
return process.stdout.rows || null;
155+
return typeof process == 'object' && process.stdout.rows || null;
156156
}
157157
function _getColumns() {
158-
return process.stdout.columns || null;
158+
return typeof process == 'object' && process.stdout.columns || null;
159159
}
160160

161161

@@ -189,8 +189,3 @@ export function getCapabilities(
189189

190190
return maybeCaps;
191191
}
192-
193-
194-
export const stdin = getCapabilities(process.stdin as Socket);
195-
export const stdout = getCapabilities(process.stdout);
196-
export const stderr = getCapabilities(process.stderr);

packages/angular_devkit/core/src/terminal/text.ts

+29-26
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,34 @@
88
import * as caps from './caps';
99
import { colors } from './colors';
1010

11-
export const reset = caps.stdout.colors ? colors.reset : (x: string) => x;
12-
export const bold = caps.stdout.colors ? colors.bold : (x: string) => x;
13-
export const dim = caps.stdout.colors ? colors.dim : (x: string) => x;
14-
export const italic = caps.stdout.colors ? colors.italic : (x: string) => x;
15-
export const underline = caps.stdout.colors ? colors.underline : (x: string) => x;
16-
export const inverse = caps.stdout.colors ? colors.inverse : (x: string) => x;
17-
export const hidden = caps.stdout.colors ? colors.hidden : (x: string) => x;
18-
export const strikethrough = caps.stdout.colors ? colors.strikethrough : (x: string) => x;
11+
const stdout = typeof process == 'object'
12+
? caps.getCapabilities(process.stdout) : { colors: false };
1913

20-
export const black = caps.stdout.colors ? colors.black : (x: string) => x;
21-
export const red = caps.stdout.colors ? colors.red : (x: string) => x;
22-
export const green = caps.stdout.colors ? colors.green : (x: string) => x;
23-
export const yellow = caps.stdout.colors ? colors.yellow : (x: string) => x;
24-
export const blue = caps.stdout.colors ? colors.blue : (x: string) => x;
25-
export const magenta = caps.stdout.colors ? colors.magenta : (x: string) => x;
26-
export const cyan = caps.stdout.colors ? colors.cyan : (x: string) => x;
27-
export const white = caps.stdout.colors ? colors.white : (x: string) => x;
28-
export const grey = caps.stdout.colors ? colors.gray : (x: string) => x;
29-
export const gray = caps.stdout.colors ? colors.gray : (x: string) => x;
14+
export const reset = stdout.colors ? colors.reset : (x: string) => x;
15+
export const bold = stdout.colors ? colors.bold : (x: string) => x;
16+
export const dim = stdout.colors ? colors.dim : (x: string) => x;
17+
export const italic = stdout.colors ? colors.italic : (x: string) => x;
18+
export const underline = stdout.colors ? colors.underline : (x: string) => x;
19+
export const inverse = stdout.colors ? colors.inverse : (x: string) => x;
20+
export const hidden = stdout.colors ? colors.hidden : (x: string) => x;
21+
export const strikethrough = stdout.colors ? colors.strikethrough : (x: string) => x;
3022

31-
export const bgBlack = caps.stdout.colors ? colors.bgBlack : (x: string) => x;
32-
export const bgRed = caps.stdout.colors ? colors.bgRed : (x: string) => x;
33-
export const bgGreen = caps.stdout.colors ? colors.bgGreen : (x: string) => x;
34-
export const bgYellow = caps.stdout.colors ? colors.bgYellow : (x: string) => x;
35-
export const bgBlue = caps.stdout.colors ? colors.bgBlue : (x: string) => x;
36-
export const bgMagenta = caps.stdout.colors ? colors.bgMagenta : (x: string) => x;
37-
export const bgCyan = caps.stdout.colors ? colors.bgCyan : (x: string) => x;
38-
export const bgWhite = caps.stdout.colors ? colors.bgWhite : (x: string) => x;
23+
export const black = stdout.colors ? colors.black : (x: string) => x;
24+
export const red = stdout.colors ? colors.red : (x: string) => x;
25+
export const green = stdout.colors ? colors.green : (x: string) => x;
26+
export const yellow = stdout.colors ? colors.yellow : (x: string) => x;
27+
export const blue = stdout.colors ? colors.blue : (x: string) => x;
28+
export const magenta = stdout.colors ? colors.magenta : (x: string) => x;
29+
export const cyan = stdout.colors ? colors.cyan : (x: string) => x;
30+
export const white = stdout.colors ? colors.white : (x: string) => x;
31+
export const grey = stdout.colors ? colors.gray : (x: string) => x;
32+
export const gray = stdout.colors ? colors.gray : (x: string) => x;
33+
34+
export const bgBlack = stdout.colors ? colors.bgBlack : (x: string) => x;
35+
export const bgRed = stdout.colors ? colors.bgRed : (x: string) => x;
36+
export const bgGreen = stdout.colors ? colors.bgGreen : (x: string) => x;
37+
export const bgYellow = stdout.colors ? colors.bgYellow : (x: string) => x;
38+
export const bgBlue = stdout.colors ? colors.bgBlue : (x: string) => x;
39+
export const bgMagenta = stdout.colors ? colors.bgMagenta : (x: string) => x;
40+
export const bgCyan = stdout.colors ? colors.bgCyan : (x: string) => x;
41+
export const bgWhite = stdout.colors ? colors.bgWhite : (x: string) => x;

0 commit comments

Comments
 (0)