@jsenv/humanize 1.2.7 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/js/vendors.js +295 -0
- package/dist/node/jsenv_humanize_node.js +7 -281
- package/package.json +4 -6
- package/src/_tests/js_value/biginit.test.js +0 -1
- package/src/_tests/log/logger.test.mjs +0 -1
- package/src/log/dynamic_log.js +2 -4
- package/src/log/task_log.js +1 -1
- package/src/.jsenv/jsenv_tests_output.txt +0 -30
- /package/src/_tests/log/{log_long.test.mjs → log_long.test_manual.mjs} +0 -0
- /package/src/_tests/log/{log_modified.test.mjs → log_modified.test_manual.mjs} +0 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import tty from "node:tty";
|
|
4
|
+
|
|
5
|
+
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
|
|
6
|
+
/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
|
|
7
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
|
|
8
|
+
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
9
|
+
const position = argv.indexOf(prefix + flag);
|
|
10
|
+
const terminatorPosition = argv.indexOf('--');
|
|
11
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const {env} = process;
|
|
15
|
+
|
|
16
|
+
let flagForceColor;
|
|
17
|
+
if (
|
|
18
|
+
hasFlag('no-color')
|
|
19
|
+
|| hasFlag('no-colors')
|
|
20
|
+
|| hasFlag('color=false')
|
|
21
|
+
|| hasFlag('color=never')
|
|
22
|
+
) {
|
|
23
|
+
flagForceColor = 0;
|
|
24
|
+
} else if (
|
|
25
|
+
hasFlag('color')
|
|
26
|
+
|| hasFlag('colors')
|
|
27
|
+
|| hasFlag('color=true')
|
|
28
|
+
|| hasFlag('color=always')
|
|
29
|
+
) {
|
|
30
|
+
flagForceColor = 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function envForceColor() {
|
|
34
|
+
if (!('FORCE_COLOR' in env)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (env.FORCE_COLOR === 'true') {
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (env.FORCE_COLOR === 'false') {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (env.FORCE_COLOR.length === 0) {
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
51
|
+
|
|
52
|
+
if (![0, 1, 2, 3].includes(level)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return level;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function translateLevel(level) {
|
|
60
|
+
if (level === 0) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
level,
|
|
66
|
+
hasBasic: true,
|
|
67
|
+
has256: level >= 2,
|
|
68
|
+
has16m: level >= 3,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
73
|
+
const noFlagForceColor = envForceColor();
|
|
74
|
+
if (noFlagForceColor !== undefined) {
|
|
75
|
+
flagForceColor = noFlagForceColor;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
79
|
+
|
|
80
|
+
if (forceColor === 0) {
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (sniffFlags) {
|
|
85
|
+
if (hasFlag('color=16m')
|
|
86
|
+
|| hasFlag('color=full')
|
|
87
|
+
|| hasFlag('color=truecolor')) {
|
|
88
|
+
return 3;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (hasFlag('color=256')) {
|
|
92
|
+
return 2;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Check for Azure DevOps pipelines.
|
|
97
|
+
// Has to be above the `!streamIsTTY` check.
|
|
98
|
+
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const min = forceColor || 0;
|
|
107
|
+
|
|
108
|
+
if (env.TERM === 'dumb') {
|
|
109
|
+
return min;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (process.platform === 'win32') {
|
|
113
|
+
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
114
|
+
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
115
|
+
const osRelease = os.release().split('.');
|
|
116
|
+
if (
|
|
117
|
+
Number(osRelease[0]) >= 10
|
|
118
|
+
&& Number(osRelease[2]) >= 10_586
|
|
119
|
+
) {
|
|
120
|
+
return Number(osRelease[2]) >= 14_931 ? 3 : 2;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if ('CI' in env) {
|
|
127
|
+
if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
|
|
128
|
+
return 3;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return min;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
139
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (env.COLORTERM === 'truecolor') {
|
|
143
|
+
return 3;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (env.TERM === 'xterm-kitty') {
|
|
147
|
+
return 3;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if ('TERM_PROGRAM' in env) {
|
|
151
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
152
|
+
|
|
153
|
+
switch (env.TERM_PROGRAM) {
|
|
154
|
+
case 'iTerm.app': {
|
|
155
|
+
return version >= 3 ? 3 : 2;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
case 'Apple_Terminal': {
|
|
159
|
+
return 2;
|
|
160
|
+
}
|
|
161
|
+
// No default
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
166
|
+
return 2;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if ('COLORTERM' in env) {
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return min;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function createSupportsColor(stream, options = {}) {
|
|
181
|
+
const level = _supportsColor(stream, {
|
|
182
|
+
streamIsTTY: stream && stream.isTTY,
|
|
183
|
+
...options,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return translateLevel(level);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
({
|
|
190
|
+
stdout: createSupportsColor({isTTY: tty.isatty(1)}),
|
|
191
|
+
stderr: createSupportsColor({isTTY: tty.isatty(2)}),
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
function isUnicodeSupported() {
|
|
195
|
+
const {env} = process;
|
|
196
|
+
const {TERM, TERM_PROGRAM} = env;
|
|
197
|
+
|
|
198
|
+
if (process.platform !== 'win32') {
|
|
199
|
+
return TERM !== 'linux'; // Linux console (kernel)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return Boolean(env.WT_SESSION) // Windows Terminal
|
|
203
|
+
|| Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
|
204
|
+
|| env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
|
205
|
+
|| TERM_PROGRAM === 'Terminus-Sublime'
|
|
206
|
+
|| TERM_PROGRAM === 'vscode'
|
|
207
|
+
|| TERM === 'xterm-256color'
|
|
208
|
+
|| TERM === 'alacritty'
|
|
209
|
+
|| TERM === 'rxvt-unicode'
|
|
210
|
+
|| TERM === 'rxvt-unicode-256color'
|
|
211
|
+
|| env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
|
|
215
|
+
|
|
216
|
+
const isBrowser = globalThis.window?.document !== undefined;
|
|
217
|
+
|
|
218
|
+
globalThis.process?.versions?.node !== undefined;
|
|
219
|
+
|
|
220
|
+
globalThis.process?.versions?.bun !== undefined;
|
|
221
|
+
|
|
222
|
+
globalThis.Deno?.version?.deno !== undefined;
|
|
223
|
+
|
|
224
|
+
globalThis.process?.versions?.electron !== undefined;
|
|
225
|
+
|
|
226
|
+
globalThis.navigator?.userAgent?.includes('jsdom') === true;
|
|
227
|
+
|
|
228
|
+
typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
|
|
229
|
+
|
|
230
|
+
typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
231
|
+
|
|
232
|
+
typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
|
|
233
|
+
|
|
234
|
+
typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
|
|
235
|
+
|
|
236
|
+
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
|
|
237
|
+
const platform = globalThis.navigator?.userAgentData?.platform;
|
|
238
|
+
|
|
239
|
+
platform === 'macOS'
|
|
240
|
+
|| globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|
|
241
|
+
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true
|
|
242
|
+
|| globalThis.process?.platform === 'darwin';
|
|
243
|
+
|
|
244
|
+
platform === 'Windows'
|
|
245
|
+
|| globalThis.navigator?.platform === 'Win32'
|
|
246
|
+
|| globalThis.process?.platform === 'win32';
|
|
247
|
+
|
|
248
|
+
platform === 'Linux'
|
|
249
|
+
|| globalThis.navigator?.platform?.startsWith('Linux') === true
|
|
250
|
+
|| globalThis.navigator?.userAgent?.includes(' Linux ') === true
|
|
251
|
+
|| globalThis.process?.platform === 'linux';
|
|
252
|
+
|
|
253
|
+
platform === 'Android'
|
|
254
|
+
|| globalThis.navigator?.platform === 'Android'
|
|
255
|
+
|| globalThis.navigator?.userAgent?.includes(' Android ') === true
|
|
256
|
+
|| globalThis.process?.platform === 'android';
|
|
257
|
+
|
|
258
|
+
const ESC = '\u001B[';
|
|
259
|
+
|
|
260
|
+
!isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
261
|
+
const isWindows = !isBrowser && process.platform === 'win32';
|
|
262
|
+
|
|
263
|
+
isBrowser ? () => {
|
|
264
|
+
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
|
|
265
|
+
} : process.cwd;
|
|
266
|
+
|
|
267
|
+
const cursorUp = (count = 1) => ESC + count + 'A';
|
|
268
|
+
|
|
269
|
+
const cursorLeft = ESC + 'G';
|
|
270
|
+
|
|
271
|
+
const eraseLines = count => {
|
|
272
|
+
let clear = '';
|
|
273
|
+
|
|
274
|
+
for (let i = 0; i < count; i++) {
|
|
275
|
+
clear += eraseLine + (i < count - 1 ? cursorUp() : '');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (count) {
|
|
279
|
+
clear += cursorLeft;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return clear;
|
|
283
|
+
};
|
|
284
|
+
const eraseLine = ESC + '2K';
|
|
285
|
+
const eraseScreen = ESC + '2J';
|
|
286
|
+
|
|
287
|
+
const clearTerminal = isWindows
|
|
288
|
+
? `${eraseScreen}${ESC}0f`
|
|
289
|
+
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
290
|
+
// 2. Erases the whole screen including scrollback buffer
|
|
291
|
+
// 3. Moves cursor to the top-left position
|
|
292
|
+
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
293
|
+
: `${eraseScreen}${ESC}3J${ESC}H`;
|
|
294
|
+
|
|
295
|
+
export { clearTerminal, createSupportsColor, eraseLines, isUnicodeSupported };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import tty from "node:tty";
|
|
1
|
+
import { createSupportsColor, isUnicodeSupported, clearTerminal, eraseLines } from "./js/vendors.js";
|
|
4
2
|
import stringWidth from "string-width";
|
|
3
|
+
import "node:process";
|
|
4
|
+
import "node:os";
|
|
5
|
+
import "node:tty";
|
|
5
6
|
|
|
6
7
|
const createDetailedMessage = (message, details = {}) => {
|
|
7
8
|
let string = `${message}`;
|
|
@@ -21,183 +22,6 @@ ${
|
|
|
21
22
|
return string;
|
|
22
23
|
};
|
|
23
24
|
|
|
24
|
-
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
|
|
25
|
-
/// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
|
|
26
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
|
|
27
|
-
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
28
|
-
const position = argv.indexOf(prefix + flag);
|
|
29
|
-
const terminatorPosition = argv.indexOf('--');
|
|
30
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const {env} = process$1;
|
|
34
|
-
|
|
35
|
-
let flagForceColor;
|
|
36
|
-
if (
|
|
37
|
-
hasFlag('no-color')
|
|
38
|
-
|| hasFlag('no-colors')
|
|
39
|
-
|| hasFlag('color=false')
|
|
40
|
-
|| hasFlag('color=never')
|
|
41
|
-
) {
|
|
42
|
-
flagForceColor = 0;
|
|
43
|
-
} else if (
|
|
44
|
-
hasFlag('color')
|
|
45
|
-
|| hasFlag('colors')
|
|
46
|
-
|| hasFlag('color=true')
|
|
47
|
-
|| hasFlag('color=always')
|
|
48
|
-
) {
|
|
49
|
-
flagForceColor = 1;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function envForceColor() {
|
|
53
|
-
if ('FORCE_COLOR' in env) {
|
|
54
|
-
if (env.FORCE_COLOR === 'true') {
|
|
55
|
-
return 1;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (env.FORCE_COLOR === 'false') {
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function translateLevel(level) {
|
|
67
|
-
if (level === 0) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
level,
|
|
73
|
-
hasBasic: true,
|
|
74
|
-
has256: level >= 2,
|
|
75
|
-
has16m: level >= 3,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
80
|
-
const noFlagForceColor = envForceColor();
|
|
81
|
-
if (noFlagForceColor !== undefined) {
|
|
82
|
-
flagForceColor = noFlagForceColor;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
86
|
-
|
|
87
|
-
if (forceColor === 0) {
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (sniffFlags) {
|
|
92
|
-
if (hasFlag('color=16m')
|
|
93
|
-
|| hasFlag('color=full')
|
|
94
|
-
|| hasFlag('color=truecolor')) {
|
|
95
|
-
return 3;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (hasFlag('color=256')) {
|
|
99
|
-
return 2;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Check for Azure DevOps pipelines.
|
|
104
|
-
// Has to be above the `!streamIsTTY` check.
|
|
105
|
-
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
|
|
106
|
-
return 1;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
110
|
-
return 0;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const min = forceColor || 0;
|
|
114
|
-
|
|
115
|
-
if (env.TERM === 'dumb') {
|
|
116
|
-
return min;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (process$1.platform === 'win32') {
|
|
120
|
-
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
121
|
-
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
122
|
-
const osRelease = os.release().split('.');
|
|
123
|
-
if (
|
|
124
|
-
Number(osRelease[0]) >= 10
|
|
125
|
-
&& Number(osRelease[2]) >= 10_586
|
|
126
|
-
) {
|
|
127
|
-
return Number(osRelease[2]) >= 14_931 ? 3 : 2;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return 1;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if ('CI' in env) {
|
|
134
|
-
if ('GITHUB_ACTIONS' in env || 'GITEA_ACTIONS' in env) {
|
|
135
|
-
return 3;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
139
|
-
return 1;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return min;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if ('TEAMCITY_VERSION' in env) {
|
|
146
|
-
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (env.COLORTERM === 'truecolor') {
|
|
150
|
-
return 3;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (env.TERM === 'xterm-kitty') {
|
|
154
|
-
return 3;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if ('TERM_PROGRAM' in env) {
|
|
158
|
-
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
159
|
-
|
|
160
|
-
switch (env.TERM_PROGRAM) {
|
|
161
|
-
case 'iTerm.app': {
|
|
162
|
-
return version >= 3 ? 3 : 2;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
case 'Apple_Terminal': {
|
|
166
|
-
return 2;
|
|
167
|
-
}
|
|
168
|
-
// No default
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (/-256(color)?$/i.test(env.TERM)) {
|
|
173
|
-
return 2;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
177
|
-
return 1;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if ('COLORTERM' in env) {
|
|
181
|
-
return 1;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return min;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function createSupportsColor(stream, options = {}) {
|
|
188
|
-
const level = _supportsColor(stream, {
|
|
189
|
-
streamIsTTY: stream && stream.isTTY,
|
|
190
|
-
...options,
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
return translateLevel(level);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
({
|
|
197
|
-
stdout: createSupportsColor({isTTY: tty.isatty(1)}),
|
|
198
|
-
stderr: createSupportsColor({isTTY: tty.isatty(2)}),
|
|
199
|
-
});
|
|
200
|
-
|
|
201
25
|
// https://github.com/Marak/colors.js/blob/master/lib/styles.js
|
|
202
26
|
// https://stackoverflow.com/a/75985833/2634179
|
|
203
27
|
const RESET = "\x1b[0m";
|
|
@@ -259,21 +83,6 @@ const ANSI = createAnsi({
|
|
|
259
83
|
process.env.GITHUB_WORKFLOW,
|
|
260
84
|
});
|
|
261
85
|
|
|
262
|
-
function isUnicodeSupported() {
|
|
263
|
-
if (process$1.platform !== 'win32') {
|
|
264
|
-
return process$1.env.TERM !== 'linux'; // Linux console (kernel)
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return Boolean(process$1.env.WT_SESSION) // Windows Terminal
|
|
268
|
-
|| Boolean(process$1.env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
|
|
269
|
-
|| process$1.env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
|
|
270
|
-
|| process$1.env.TERM_PROGRAM === 'Terminus-Sublime'
|
|
271
|
-
|| process$1.env.TERM_PROGRAM === 'vscode'
|
|
272
|
-
|| process$1.env.TERM === 'xterm-256color'
|
|
273
|
-
|| process$1.env.TERM === 'alacritty'
|
|
274
|
-
|| process$1.env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
|
|
275
|
-
}
|
|
276
|
-
|
|
277
86
|
// see also https://github.com/sindresorhus/figures
|
|
278
87
|
|
|
279
88
|
const createUnicode = ({ supported, ANSI }) => {
|
|
@@ -1576,87 +1385,6 @@ const error = (...args) => console.error(...args);
|
|
|
1576
1385
|
|
|
1577
1386
|
const errorDisabled = () => {};
|
|
1578
1387
|
|
|
1579
|
-
/* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
|
|
1580
|
-
|
|
1581
|
-
const isBrowser = globalThis.window?.document !== undefined;
|
|
1582
|
-
|
|
1583
|
-
globalThis.process?.versions?.node !== undefined;
|
|
1584
|
-
|
|
1585
|
-
globalThis.process?.versions?.bun !== undefined;
|
|
1586
|
-
|
|
1587
|
-
globalThis.Deno?.version?.deno !== undefined;
|
|
1588
|
-
|
|
1589
|
-
globalThis.process?.versions?.electron !== undefined;
|
|
1590
|
-
|
|
1591
|
-
globalThis.navigator?.userAgent?.includes('jsdom') === true;
|
|
1592
|
-
|
|
1593
|
-
typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
|
|
1594
|
-
|
|
1595
|
-
typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
|
|
1596
|
-
|
|
1597
|
-
typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
|
|
1598
|
-
|
|
1599
|
-
typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
|
|
1600
|
-
|
|
1601
|
-
// Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
|
|
1602
|
-
const platform = globalThis.navigator?.userAgentData?.platform;
|
|
1603
|
-
|
|
1604
|
-
platform === 'macOS'
|
|
1605
|
-
|| globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
|
|
1606
|
-
|| globalThis.navigator?.userAgent?.includes(' Mac ') === true
|
|
1607
|
-
|| globalThis.process?.platform === 'darwin';
|
|
1608
|
-
|
|
1609
|
-
platform === 'Windows'
|
|
1610
|
-
|| globalThis.navigator?.platform === 'Win32'
|
|
1611
|
-
|| globalThis.process?.platform === 'win32';
|
|
1612
|
-
|
|
1613
|
-
platform === 'Linux'
|
|
1614
|
-
|| globalThis.navigator?.platform?.startsWith('Linux') === true
|
|
1615
|
-
|| globalThis.navigator?.userAgent?.includes(' Linux ') === true
|
|
1616
|
-
|| globalThis.process?.platform === 'linux';
|
|
1617
|
-
|
|
1618
|
-
platform === 'Android'
|
|
1619
|
-
|| globalThis.navigator?.platform === 'Android'
|
|
1620
|
-
|| globalThis.navigator?.userAgent?.includes(' Android ') === true
|
|
1621
|
-
|| globalThis.process?.platform === 'android';
|
|
1622
|
-
|
|
1623
|
-
const ESC = '\u001B[';
|
|
1624
|
-
|
|
1625
|
-
!isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
|
|
1626
|
-
const isWindows = !isBrowser && process$1.platform === 'win32';
|
|
1627
|
-
|
|
1628
|
-
isBrowser ? () => {
|
|
1629
|
-
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
|
|
1630
|
-
} : process$1.cwd;
|
|
1631
|
-
|
|
1632
|
-
const cursorUp = (count = 1) => ESC + count + 'A';
|
|
1633
|
-
|
|
1634
|
-
const cursorLeft = ESC + 'G';
|
|
1635
|
-
|
|
1636
|
-
const eraseLines = count => {
|
|
1637
|
-
let clear = '';
|
|
1638
|
-
|
|
1639
|
-
for (let i = 0; i < count; i++) {
|
|
1640
|
-
clear += eraseLine + (i < count - 1 ? cursorUp() : '');
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
if (count) {
|
|
1644
|
-
clear += cursorLeft;
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
return clear;
|
|
1648
|
-
};
|
|
1649
|
-
const eraseLine = ESC + '2K';
|
|
1650
|
-
const eraseScreen = ESC + '2J';
|
|
1651
|
-
|
|
1652
|
-
const clearTerminal = isWindows
|
|
1653
|
-
? `${eraseScreen}${ESC}0f`
|
|
1654
|
-
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
1655
|
-
// 2. Erases the whole screen including scrollback buffer
|
|
1656
|
-
// 3. Moves cursor to the top-left position
|
|
1657
|
-
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
1658
|
-
: `${eraseScreen}${ESC}3J${ESC}H`;
|
|
1659
|
-
|
|
1660
1388
|
/*
|
|
1661
1389
|
* see also https://github.com/vadimdemedes/ink
|
|
1662
1390
|
*/
|
|
@@ -1818,15 +1546,13 @@ const createDynamicLog = ({
|
|
|
1818
1546
|
// is that node.js will later throw error if stream gets closed
|
|
1819
1547
|
// while something listening data on it
|
|
1820
1548
|
const spyStreamOutput = (stream, callback) => {
|
|
1821
|
-
const originalWrite = stream.write;
|
|
1822
|
-
|
|
1823
1549
|
let output = "";
|
|
1824
1550
|
let installed = true;
|
|
1825
|
-
|
|
1551
|
+
const originalWrite = stream.write;
|
|
1826
1552
|
stream.write = function (...args /* chunk, encoding, callback */) {
|
|
1827
1553
|
output += args;
|
|
1828
1554
|
callback(output);
|
|
1829
|
-
return originalWrite.call(
|
|
1555
|
+
return originalWrite.call(this, ...args);
|
|
1830
1556
|
};
|
|
1831
1557
|
|
|
1832
1558
|
const uninstall = () => {
|
|
@@ -1926,7 +1652,7 @@ const createTaskLog = (
|
|
|
1926
1652
|
fail: () => {},
|
|
1927
1653
|
};
|
|
1928
1654
|
}
|
|
1929
|
-
if (animated && process.env.
|
|
1655
|
+
if (animated && process.env.CAPTURING_SIDE_EFFECTS) {
|
|
1930
1656
|
animated = false;
|
|
1931
1657
|
}
|
|
1932
1658
|
const startMs = Date.now();
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/humanize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Generate messages meant to read by humans",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/jsenv/core",
|
|
9
|
-
"directory": "packages/independent/humanize"
|
|
9
|
+
"directory": "packages/independent/tooling/humanize"
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
@@ -33,9 +33,7 @@
|
|
|
33
33
|
"/src/"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"dev": "node ./scripts/dev.mjs",
|
|
37
36
|
"build": "node ./scripts/build.mjs",
|
|
38
|
-
"test": "node ./scripts/test.mjs",
|
|
39
37
|
"prepublishOnly": "npm run build"
|
|
40
38
|
},
|
|
41
39
|
"dependencies": {
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
"ansi-escapes": "7.0.0"
|
|
44
42
|
},
|
|
45
43
|
"devDependencies": {
|
|
46
|
-
"is-unicode-supported": "2.
|
|
47
|
-
"supports-color": "
|
|
44
|
+
"is-unicode-supported": "2.1.0",
|
|
45
|
+
"supports-color": "10.0.0"
|
|
48
46
|
}
|
|
49
47
|
}
|
package/src/log/dynamic_log.js
CHANGED
|
@@ -161,15 +161,13 @@ export const createDynamicLog = ({
|
|
|
161
161
|
// is that node.js will later throw error if stream gets closed
|
|
162
162
|
// while something listening data on it
|
|
163
163
|
const spyStreamOutput = (stream, callback) => {
|
|
164
|
-
const originalWrite = stream.write;
|
|
165
|
-
|
|
166
164
|
let output = "";
|
|
167
165
|
let installed = true;
|
|
168
|
-
|
|
166
|
+
const originalWrite = stream.write;
|
|
169
167
|
stream.write = function (...args /* chunk, encoding, callback */) {
|
|
170
168
|
output += args;
|
|
171
169
|
callback(output);
|
|
172
|
-
return originalWrite.call(
|
|
170
|
+
return originalWrite.call(this, ...args);
|
|
173
171
|
};
|
|
174
172
|
|
|
175
173
|
const uninstall = () => {
|
package/src/log/task_log.js
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
------------ 23 executions ready ------------
|
|
2
|
-
directory: /Users/damien.maillard/dev/perso/jsenv-core/packages/independent/humanize/src
|
|
3
|
-
---------------------------------------------
|
|
4
|
-
✔ 01/23 _tests/byte/file_size.test.js [node/0.03s] (1 completed)
|
|
5
|
-
✔ 02/23 _tests/byte/memory.test.js [node/0.03s] (2 completed)
|
|
6
|
-
✔ 03/23 _tests/content_frame/content_frame.test.js [node/0.2s] (3 completed)
|
|
7
|
-
✔ 04/23 _tests/js_value/_inspect.test.html [chromium/0.6s] (4 completed)
|
|
8
|
-
✔ 05/23 _tests/js_value/_inspect.test.html [firefox/0.2s] (5 completed)
|
|
9
|
-
✔ 06/23 _tests/js_value/_inspect.test.html [webkit/0.6s] (6 completed)
|
|
10
|
-
✔ 07/23 _tests/js_value/array.test.js [node/0.03s] (7 completed)
|
|
11
|
-
✔ 08/23 _tests/js_value/biginit.test.js [node/0.03s] (8 completed)
|
|
12
|
-
✔ 09/23 _tests/js_value/boolean.test.js [node/0.04s] (9 completed)
|
|
13
|
-
✔ 10/23 _tests/js_value/date.test.js [node/0.03s] (10 completed)
|
|
14
|
-
✔ 11/23 _tests/js_value/error.test.js [node/0.04s] (11 completed)
|
|
15
|
-
✔ 12/23 _tests/js_value/function.test.js [node/0.04s] (12 completed)
|
|
16
|
-
✔ 13/23 _tests/js_value/instance.test.js [node/0.08s] (13 completed)
|
|
17
|
-
✔ 14/23 _tests/js_value/null.test.js [node/0.04s] (14 completed)
|
|
18
|
-
✔ 15/23 _tests/js_value/number.test.js [node/0.07s] (15 completed)
|
|
19
|
-
✔ 16/23 _tests/js_value/object.test.js [node/0.05s] (16 completed)
|
|
20
|
-
✔ 17/23 _tests/js_value/regexp.test.js [node/0.05s] (17 completed)
|
|
21
|
-
✔ 18/23 _tests/js_value/string.test.js [node/0.04s] (18 completed)
|
|
22
|
-
✔ 19/23 _tests/js_value/symbol.test.js [node/0.05s] (19 completed)
|
|
23
|
-
✔ 20/23 _tests/js_value/undefined.test.js [node/0.03s] (20 completed)
|
|
24
|
-
✔ 21/23 _tests/time/decimals.test.js [node/0.03s] (21 completed)
|
|
25
|
-
✔ 22/23 _tests/time/duration.test.js [node/0.03s] (22 completed)
|
|
26
|
-
✔ 23/23 _tests/time/ellapsed.test.js [node/0.07s] (all completed)
|
|
27
|
-
------------ 23 executions done -------------
|
|
28
|
-
status: all completed
|
|
29
|
-
duration: 2.8s (setup: 0.4s, execution: 2.6s, teardown: 0.2s)
|
|
30
|
-
---------------------------------------------
|
|
File without changes
|
|
File without changes
|