rslog 1.2.10 → 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/README.md +1 -1
- package/dist/color.d.ts +8 -0
- package/dist/constants.d.ts +48 -0
- package/dist/createLogger.d.ts +2 -0
- package/dist/gradient.d.ts +1 -0
- package/dist/index.cjs +18 -6
- package/dist/index.d.ts +4 -75
- package/dist/index.js +27 -15
- package/dist/types.d.ts +19 -0
- package/dist/utils.d.ts +2 -0
- package/package.json +10 -11
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ Rslog provides both CommonJS and ESModule output and supports Node.js >= 14.
|
|
|
142
142
|
|
|
143
143
|
## Credits
|
|
144
144
|
|
|
145
|
-
Rslog is built with [
|
|
145
|
+
Rslog is built with [Rslib](https://github.com/web-infra-dev/rslib).
|
|
146
146
|
|
|
147
147
|
The color implementation of Rslog are modified from [alexeyraspopov/picocolors](https://github.com/alexeyraspopov/picocolors).
|
|
148
148
|
|
package/dist/color.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ColorFn = (input: string | number | null | undefined) => string;
|
|
2
|
+
export declare const bold: ColorFn;
|
|
3
|
+
export declare const red: ColorFn;
|
|
4
|
+
export declare const green: ColorFn;
|
|
5
|
+
export declare const yellow: ColorFn;
|
|
6
|
+
export declare const magenta: ColorFn;
|
|
7
|
+
export declare const cyan: ColorFn;
|
|
8
|
+
export declare const gray: ColorFn;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare let LOG_LEVEL: {
|
|
2
|
+
readonly silent: -1;
|
|
3
|
+
readonly error: 0;
|
|
4
|
+
readonly warn: 1;
|
|
5
|
+
readonly info: 2;
|
|
6
|
+
readonly log: 2;
|
|
7
|
+
readonly verbose: 3;
|
|
8
|
+
};
|
|
9
|
+
export declare let LOG_TYPES: {
|
|
10
|
+
error: {
|
|
11
|
+
label: string;
|
|
12
|
+
level: "error";
|
|
13
|
+
color: import("./color.js").ColorFn;
|
|
14
|
+
};
|
|
15
|
+
warn: {
|
|
16
|
+
label: string;
|
|
17
|
+
level: "warn";
|
|
18
|
+
color: import("./color.js").ColorFn;
|
|
19
|
+
};
|
|
20
|
+
info: {
|
|
21
|
+
label: string;
|
|
22
|
+
level: "info";
|
|
23
|
+
color: import("./color.js").ColorFn;
|
|
24
|
+
};
|
|
25
|
+
start: {
|
|
26
|
+
label: string;
|
|
27
|
+
level: "info";
|
|
28
|
+
color: import("./color.js").ColorFn;
|
|
29
|
+
};
|
|
30
|
+
ready: {
|
|
31
|
+
label: string;
|
|
32
|
+
level: "info";
|
|
33
|
+
color: import("./color.js").ColorFn;
|
|
34
|
+
};
|
|
35
|
+
success: {
|
|
36
|
+
label: string;
|
|
37
|
+
level: "info";
|
|
38
|
+
color: import("./color.js").ColorFn;
|
|
39
|
+
};
|
|
40
|
+
log: {
|
|
41
|
+
level: "info";
|
|
42
|
+
};
|
|
43
|
+
debug: {
|
|
44
|
+
label: string;
|
|
45
|
+
level: "verbose";
|
|
46
|
+
color: import("./color.js").ColorFn;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare let gradient: (message: string) => string;
|
package/dist/index.cjs
CHANGED
|
@@ -99,6 +99,8 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
99
99
|
if ('TEAMCITY_VERSION' in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
100
100
|
if ('truecolor' === env.COLORTERM) return 3;
|
|
101
101
|
if ('xterm-kitty' === env.TERM) return 3;
|
|
102
|
+
if ('xterm-ghostty' === env.TERM) return 3;
|
|
103
|
+
if ('wezterm' === env.TERM) return 3;
|
|
102
104
|
if ('TERM_PROGRAM' in env) {
|
|
103
105
|
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
104
106
|
switch(env.TERM_PROGRAM){
|
|
@@ -233,6 +235,14 @@ let LOG_TYPES = {
|
|
|
233
235
|
color: magenta
|
|
234
236
|
}
|
|
235
237
|
};
|
|
238
|
+
const normalizeErrorMessage = (err)=>{
|
|
239
|
+
if (err.stack) {
|
|
240
|
+
let [name, ...rest] = err.stack.split('\n');
|
|
241
|
+
if (name.startsWith('Error: ')) name = name.slice(7);
|
|
242
|
+
return `${name}\n${gray(rest.join('\n'))}`;
|
|
243
|
+
}
|
|
244
|
+
return err.message;
|
|
245
|
+
};
|
|
236
246
|
let createLogger = (options = {})=>{
|
|
237
247
|
let maxLevel = options.level || 'info';
|
|
238
248
|
let log = (type, message, ...args)=>{
|
|
@@ -245,12 +255,14 @@ let createLogger = (options = {})=>{
|
|
|
245
255
|
label = (logType.label || '').padEnd(7);
|
|
246
256
|
label = bold(logType.color ? logType.color(label) : label);
|
|
247
257
|
}
|
|
248
|
-
if (message instanceof Error)
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
if (message instanceof Error) {
|
|
259
|
+
text += normalizeErrorMessage(message);
|
|
260
|
+
const { cause } = message;
|
|
261
|
+
if (cause) {
|
|
262
|
+
text += yellow('\n [cause]: ');
|
|
263
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
264
|
+
}
|
|
265
|
+
} else if ('error' === logType.level && 'string' == typeof message) {
|
|
254
266
|
let lines = message.split('\n');
|
|
255
267
|
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
256
268
|
} else text = `${message}`;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,75 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare let createLogger: (options?: Options) => Logger;
|
|
7
|
-
|
|
8
|
-
declare let LOG_TYPES: {
|
|
9
|
-
error: {
|
|
10
|
-
label: string;
|
|
11
|
-
level: "error";
|
|
12
|
-
color: ColorFn;
|
|
13
|
-
};
|
|
14
|
-
warn: {
|
|
15
|
-
label: string;
|
|
16
|
-
level: "warn";
|
|
17
|
-
color: ColorFn;
|
|
18
|
-
};
|
|
19
|
-
info: {
|
|
20
|
-
label: string;
|
|
21
|
-
level: "info";
|
|
22
|
-
color: ColorFn;
|
|
23
|
-
};
|
|
24
|
-
start: {
|
|
25
|
-
label: string;
|
|
26
|
-
level: "info";
|
|
27
|
-
color: ColorFn;
|
|
28
|
-
};
|
|
29
|
-
ready: {
|
|
30
|
-
label: string;
|
|
31
|
-
level: "info";
|
|
32
|
-
color: ColorFn;
|
|
33
|
-
};
|
|
34
|
-
success: {
|
|
35
|
-
label: string;
|
|
36
|
-
level: "info";
|
|
37
|
-
color: ColorFn;
|
|
38
|
-
};
|
|
39
|
-
log: {
|
|
40
|
-
level: "info";
|
|
41
|
-
};
|
|
42
|
-
debug: {
|
|
43
|
-
label: string;
|
|
44
|
-
level: "verbose";
|
|
45
|
-
color: ColorFn;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export declare type LogFunction = (message?: LogMessage, ...args: any[]) => void;
|
|
50
|
-
|
|
51
|
-
export declare type Logger = Record<LogMethods, LogFunction> & {
|
|
52
|
-
greet: (message: string) => void;
|
|
53
|
-
level: LogLevel;
|
|
54
|
-
override: (customLogger: Partial<Record<LogMethods, LogFunction>>) => void;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export declare let logger: Logger_2;
|
|
58
|
-
|
|
59
|
-
export declare type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'log' | 'verbose';
|
|
60
|
-
|
|
61
|
-
export declare type LogMessage = unknown;
|
|
62
|
-
|
|
63
|
-
declare type LogMethods = keyof typeof LOG_TYPES;
|
|
64
|
-
|
|
65
|
-
export declare interface LogType {
|
|
66
|
-
label?: string;
|
|
67
|
-
level: LogLevel;
|
|
68
|
-
color?: ColorFn_2;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export declare interface Options {
|
|
72
|
-
level?: LogLevel;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export { }
|
|
1
|
+
import { createLogger } from './createLogger.js';
|
|
2
|
+
export { createLogger };
|
|
3
|
+
export declare let logger: import("./types.js").Logger;
|
|
4
|
+
export type { Options, Logger, LogType, LogLevel, LogMessage, LogFunction, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args :
|
|
1
|
+
import node_process from "node:process";
|
|
2
|
+
import node_os from "node:os";
|
|
3
|
+
import node_tty from "node:tty";
|
|
4
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
5
5
|
const prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--';
|
|
6
6
|
const position = argv.indexOf(prefix + flag);
|
|
7
7
|
const terminatorPosition = argv.indexOf('--');
|
|
8
8
|
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
9
9
|
}
|
|
10
|
-
const { env } =
|
|
10
|
+
const { env } = node_process;
|
|
11
11
|
let flagForceColor;
|
|
12
12
|
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) flagForceColor = 0;
|
|
13
13
|
else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) flagForceColor = 1;
|
|
@@ -47,8 +47,8 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
47
47
|
if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
|
|
48
48
|
const min = forceColor || 0;
|
|
49
49
|
if ('dumb' === env.TERM) return min;
|
|
50
|
-
if ('win32' ===
|
|
51
|
-
const osRelease =
|
|
50
|
+
if ('win32' === node_process.platform) {
|
|
51
|
+
const osRelease = node_os.release().split('.');
|
|
52
52
|
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
53
53
|
return 1;
|
|
54
54
|
}
|
|
@@ -70,6 +70,8 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
|
70
70
|
if ('TEAMCITY_VERSION' in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
71
71
|
if ('truecolor' === env.COLORTERM) return 3;
|
|
72
72
|
if ('xterm-kitty' === env.TERM) return 3;
|
|
73
|
+
if ('xterm-ghostty' === env.TERM) return 3;
|
|
74
|
+
if ('wezterm' === env.TERM) return 3;
|
|
73
75
|
if ('TERM_PROGRAM' in env) {
|
|
74
76
|
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
75
77
|
switch(env.TERM_PROGRAM){
|
|
@@ -93,10 +95,10 @@ function createSupportsColor(stream, options = {}) {
|
|
|
93
95
|
}
|
|
94
96
|
const supportsColor = {
|
|
95
97
|
stdout: createSupportsColor({
|
|
96
|
-
isTTY:
|
|
98
|
+
isTTY: node_tty.isatty(1)
|
|
97
99
|
}),
|
|
98
100
|
stderr: createSupportsColor({
|
|
99
|
-
isTTY:
|
|
101
|
+
isTTY: node_tty.isatty(2)
|
|
100
102
|
})
|
|
101
103
|
};
|
|
102
104
|
const supports_color = supportsColor;
|
|
@@ -204,6 +206,14 @@ let LOG_TYPES = {
|
|
|
204
206
|
color: magenta
|
|
205
207
|
}
|
|
206
208
|
};
|
|
209
|
+
const normalizeErrorMessage = (err)=>{
|
|
210
|
+
if (err.stack) {
|
|
211
|
+
let [name, ...rest] = err.stack.split('\n');
|
|
212
|
+
if (name.startsWith('Error: ')) name = name.slice(7);
|
|
213
|
+
return `${name}\n${gray(rest.join('\n'))}`;
|
|
214
|
+
}
|
|
215
|
+
return err.message;
|
|
216
|
+
};
|
|
207
217
|
let createLogger = (options = {})=>{
|
|
208
218
|
let maxLevel = options.level || 'info';
|
|
209
219
|
let log = (type, message, ...args)=>{
|
|
@@ -216,12 +226,14 @@ let createLogger = (options = {})=>{
|
|
|
216
226
|
label = (logType.label || '').padEnd(7);
|
|
217
227
|
label = bold(logType.color ? logType.color(label) : label);
|
|
218
228
|
}
|
|
219
|
-
if (message instanceof Error)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
229
|
+
if (message instanceof Error) {
|
|
230
|
+
text += normalizeErrorMessage(message);
|
|
231
|
+
const { cause } = message;
|
|
232
|
+
if (cause) {
|
|
233
|
+
text += yellow('\n [cause]: ');
|
|
234
|
+
text += cause instanceof Error ? normalizeErrorMessage(cause) : String(cause);
|
|
235
|
+
}
|
|
236
|
+
} else if ('error' === logType.level && 'string' == typeof message) {
|
|
225
237
|
let lines = message.split('\n');
|
|
226
238
|
text = lines.map((line)=>isErrorStackMessage(line) ? gray(line) : line).join('\n');
|
|
227
239
|
} else text = `${message}`;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ColorFn } from './color.js';
|
|
2
|
+
import type { LOG_TYPES } from './constants.js';
|
|
3
|
+
export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'log' | 'verbose';
|
|
4
|
+
export type LogMessage = unknown;
|
|
5
|
+
export interface LogType {
|
|
6
|
+
label?: string;
|
|
7
|
+
level: LogLevel;
|
|
8
|
+
color?: ColorFn;
|
|
9
|
+
}
|
|
10
|
+
export type LogFunction = (message?: LogMessage, ...args: any[]) => void;
|
|
11
|
+
export interface Options {
|
|
12
|
+
level?: LogLevel;
|
|
13
|
+
}
|
|
14
|
+
export type LogMethods = keyof typeof LOG_TYPES;
|
|
15
|
+
export type Logger = Record<LogMethods, LogFunction> & {
|
|
16
|
+
greet: (message: string) => void;
|
|
17
|
+
level: LogLevel;
|
|
18
|
+
override: (customLogger: Partial<Record<LogMethods, LogFunction>>) => void;
|
|
19
|
+
};
|
package/dist/utils.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rslog",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rspack-contrib/rslog.git"
|
|
@@ -24,20 +24,19 @@
|
|
|
24
24
|
"bump": "npx bumpp",
|
|
25
25
|
"dev": "rslib build --watch",
|
|
26
26
|
"prepare": "rslib build",
|
|
27
|
-
"preview": "
|
|
27
|
+
"preview": "node ./preview/index.ts",
|
|
28
28
|
"test": "rstest"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"typescript": "~5.8.3"
|
|
31
|
+
"@rslib/core": "^0.15.1",
|
|
32
|
+
"@rstest/core": "^0.5.2",
|
|
33
|
+
"@types/node": "^22.18.11",
|
|
34
|
+
"prettier": "~3.6.2",
|
|
35
|
+
"strip-ansi": "^7.1.2",
|
|
36
|
+
"supports-color": "^10.2.2",
|
|
37
|
+
"typescript": "~5.9.3"
|
|
39
38
|
},
|
|
40
|
-
"packageManager": "pnpm@10.
|
|
39
|
+
"packageManager": "pnpm@10.18.3",
|
|
41
40
|
"publishConfig": {
|
|
42
41
|
"access": "public",
|
|
43
42
|
"registry": "https://registry.npmjs.org/"
|