@reliverse/relinka 1.6.0 → 2.2.7
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 +198 -345
- package/dist/mod.d.ts +49 -0
- package/dist/mod.js +182 -0
- package/package.json +17 -38
- package/LICENSE +0 -21
- package/bin/alias.d.ts +0 -8
- package/bin/alias.js +0 -8
- package/bin/impl.d.ts +0 -50
- package/bin/impl.js +0 -605
- package/bin/mod.d.ts +0 -3
- package/bin/mod.js +0 -14
- package/bin/setup.d.ts +0 -144
- package/bin/setup.js +0 -90
- package/bin/types.d.ts +0 -2
- package/bin/types.js +0 -0
package/dist/mod.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { re } from "@reliverse/relico";
|
|
2
|
+
const textEncoder = new TextEncoder();
|
|
3
|
+
const LOG_COLORS = {
|
|
4
|
+
log: re.white,
|
|
5
|
+
error: re.red,
|
|
6
|
+
fatal: re.red,
|
|
7
|
+
warn: re.yellow,
|
|
8
|
+
info: re.blue,
|
|
9
|
+
success: re.green,
|
|
10
|
+
debug: re.gray,
|
|
11
|
+
box: re.white
|
|
12
|
+
};
|
|
13
|
+
const LOG_SYMBOLS = {
|
|
14
|
+
log: "\u2502 ",
|
|
15
|
+
error: "\u2716 ",
|
|
16
|
+
fatal: "\u2620 ",
|
|
17
|
+
warn: "\u26A0 ",
|
|
18
|
+
info: "\u25A0 ",
|
|
19
|
+
success: "\u2713 ",
|
|
20
|
+
debug: "\u2731 ",
|
|
21
|
+
box: ""
|
|
22
|
+
};
|
|
23
|
+
let writeLock = Promise.resolve();
|
|
24
|
+
const formatMessage = (...args) => {
|
|
25
|
+
const len = args.length;
|
|
26
|
+
if (len === 0) return "";
|
|
27
|
+
if (len === 1) return String(args[0]);
|
|
28
|
+
return args.map(String).join(" ");
|
|
29
|
+
};
|
|
30
|
+
const createPrefixedMessage = (level, message) => {
|
|
31
|
+
const symbol = LOG_SYMBOLS[level];
|
|
32
|
+
if (symbol === "") return message;
|
|
33
|
+
return symbol + message;
|
|
34
|
+
};
|
|
35
|
+
const formatBox = (message) => {
|
|
36
|
+
const lines = message.split("\n");
|
|
37
|
+
const lineCount = lines.length;
|
|
38
|
+
if (lineCount === 0) {
|
|
39
|
+
return "\u250C\u2500\u2500\u2510\n\u2502 \u2502\n\u2514\u2500\u2500\u2518\n";
|
|
40
|
+
}
|
|
41
|
+
let maxWidth = 0;
|
|
42
|
+
for (let i = 0; i < lineCount; i++) {
|
|
43
|
+
const line = lines[i];
|
|
44
|
+
if (line === void 0) continue;
|
|
45
|
+
const len = line.length;
|
|
46
|
+
if (len > maxWidth) maxWidth = len;
|
|
47
|
+
}
|
|
48
|
+
const padding = 2;
|
|
49
|
+
const width = maxWidth + padding * 2;
|
|
50
|
+
const horizontal = "\u2500".repeat(width);
|
|
51
|
+
const top = `\u250C${horizontal}\u2510
|
|
52
|
+
`;
|
|
53
|
+
const bottom = `\u2514${horizontal}\u2518
|
|
54
|
+
`;
|
|
55
|
+
const leftPadding = " ".repeat(padding);
|
|
56
|
+
const rightPadding = " ".repeat(padding);
|
|
57
|
+
if (maxWidth === 0) {
|
|
58
|
+
return `${top}\u2502${" ".repeat(width)}\u2502
|
|
59
|
+
${bottom}`;
|
|
60
|
+
}
|
|
61
|
+
let content = "";
|
|
62
|
+
for (let i = 0; i < lineCount; i++) {
|
|
63
|
+
const line = lines[i];
|
|
64
|
+
if (line === void 0) continue;
|
|
65
|
+
const padded = line.padEnd(maxWidth);
|
|
66
|
+
content += `\u2502${leftPadding}${padded}${rightPadding}\u2502
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
return `${top}${content}${bottom}`;
|
|
70
|
+
};
|
|
71
|
+
const writeAsync = async (text, isError = false) => {
|
|
72
|
+
const encoded = textEncoder.encode(`${text}
|
|
73
|
+
`);
|
|
74
|
+
const stream = isError ? Bun.stderr : Bun.stdout;
|
|
75
|
+
writeLock = writeLock.then(async () => {
|
|
76
|
+
await Bun.write(stream, encoded);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const writeSync = (text, isError = false) => {
|
|
80
|
+
const encoded = textEncoder.encode(`${text}
|
|
81
|
+
`);
|
|
82
|
+
(isError ? process.stderr : process.stdout).write(encoded);
|
|
83
|
+
};
|
|
84
|
+
const writeColoredAsync = (text, color, isError = false) => {
|
|
85
|
+
const coloredText = color(text);
|
|
86
|
+
return writeAsync(coloredText, isError);
|
|
87
|
+
};
|
|
88
|
+
const writeColoredSync = (text, color, isError = false) => {
|
|
89
|
+
const coloredText = color(text);
|
|
90
|
+
writeSync(coloredText, isError);
|
|
91
|
+
};
|
|
92
|
+
function createLogMethod(level, isAsync, isError = false) {
|
|
93
|
+
const color = LOG_COLORS[level];
|
|
94
|
+
const isBox = level === "box";
|
|
95
|
+
if (isAsync) {
|
|
96
|
+
return (...args) => {
|
|
97
|
+
const message = formatMessage(...args);
|
|
98
|
+
const formattedMessage = isBox ? formatBox(message) : createPrefixedMessage(level, message);
|
|
99
|
+
return writeColoredAsync(formattedMessage, color, isError);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return (...args) => {
|
|
103
|
+
const message = formatMessage(...args);
|
|
104
|
+
const formattedMessage = isBox ? formatBox(message) : createPrefixedMessage(level, message);
|
|
105
|
+
writeColoredSync(formattedMessage, color, isError);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function createRawMethod(isAsync) {
|
|
109
|
+
if (isAsync) {
|
|
110
|
+
return (...args) => {
|
|
111
|
+
const message = formatMessage(...args);
|
|
112
|
+
return writeAsync(message);
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return (...args) => {
|
|
116
|
+
const message = formatMessage(...args);
|
|
117
|
+
writeSync(message);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const createCallableLogger = (methods) => {
|
|
121
|
+
const callable = ((level, ...args) => {
|
|
122
|
+
const method = methods[level];
|
|
123
|
+
if (method) {
|
|
124
|
+
method(...args);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
methods.log(...args);
|
|
128
|
+
});
|
|
129
|
+
callable.log = methods.log;
|
|
130
|
+
callable.error = methods.error;
|
|
131
|
+
callable.fatal = methods.fatal;
|
|
132
|
+
callable.warn = methods.warn;
|
|
133
|
+
callable.info = methods.info;
|
|
134
|
+
callable.success = methods.success;
|
|
135
|
+
callable.debug = methods.debug;
|
|
136
|
+
callable.box = methods.box;
|
|
137
|
+
callable.raw = methods.raw;
|
|
138
|
+
return callable;
|
|
139
|
+
};
|
|
140
|
+
const createCallableLoggerAsync = (methods) => {
|
|
141
|
+
const callable = ((level, ...args) => {
|
|
142
|
+
const method = methods[level];
|
|
143
|
+
if (method) {
|
|
144
|
+
return method(...args);
|
|
145
|
+
}
|
|
146
|
+
return methods.log(...args);
|
|
147
|
+
});
|
|
148
|
+
callable.log = methods.log;
|
|
149
|
+
callable.error = methods.error;
|
|
150
|
+
callable.fatal = methods.fatal;
|
|
151
|
+
callable.warn = methods.warn;
|
|
152
|
+
callable.info = methods.info;
|
|
153
|
+
callable.success = methods.success;
|
|
154
|
+
callable.debug = methods.debug;
|
|
155
|
+
callable.box = methods.box;
|
|
156
|
+
callable.raw = methods.raw;
|
|
157
|
+
return callable;
|
|
158
|
+
};
|
|
159
|
+
const loggerMethods = {
|
|
160
|
+
log: createLogMethod("log", false),
|
|
161
|
+
error: createLogMethod("error", false, true),
|
|
162
|
+
fatal: createLogMethod("fatal", false, true),
|
|
163
|
+
warn: createLogMethod("warn", false),
|
|
164
|
+
info: createLogMethod("info", false),
|
|
165
|
+
success: createLogMethod("success", false),
|
|
166
|
+
debug: createLogMethod("debug", false),
|
|
167
|
+
box: createLogMethod("box", false),
|
|
168
|
+
raw: createRawMethod(false)
|
|
169
|
+
};
|
|
170
|
+
const relinkaMethods = {
|
|
171
|
+
log: createLogMethod("log", true),
|
|
172
|
+
error: createLogMethod("error", true, true),
|
|
173
|
+
fatal: createLogMethod("fatal", true, true),
|
|
174
|
+
warn: createLogMethod("warn", true),
|
|
175
|
+
info: createLogMethod("info", true),
|
|
176
|
+
success: createLogMethod("success", true),
|
|
177
|
+
debug: createLogMethod("debug", true),
|
|
178
|
+
box: createLogMethod("box", true),
|
|
179
|
+
raw: createRawMethod(true)
|
|
180
|
+
};
|
|
181
|
+
export const logger = createCallableLogger(loggerMethods);
|
|
182
|
+
export const relinka = createCallableLoggerAsync(relinkaMethods);
|
package/package.json
CHANGED
|
@@ -1,45 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"dependencies": {
|
|
3
|
-
"@reliverse/pathkit": "^1.3.4",
|
|
4
|
-
"@reliverse/relico": "^1.3.8",
|
|
5
|
-
"@reliverse/relifso": "^1.4.5",
|
|
6
|
-
"c12": "^3.2.0"
|
|
7
|
-
},
|
|
8
|
-
"description": "@reliverse/relinka is a modern, minimal logging library that actually feels right. It's not just pretty output — it's a system: smart formatting, file-safe logging, runtime config support, and a fatal mode built for developers who care about correctness.",
|
|
9
|
-
"homepage": "https://docs.reliverse.org/cli",
|
|
10
|
-
"license": "MIT",
|
|
11
2
|
"name": "@reliverse/relinka",
|
|
3
|
+
"version": "2.2.7",
|
|
4
|
+
"private": false,
|
|
12
5
|
"type": "module",
|
|
13
|
-
"
|
|
14
|
-
"keywords": [
|
|
15
|
-
"logger",
|
|
16
|
-
"consola",
|
|
17
|
-
"console",
|
|
18
|
-
"elegant",
|
|
19
|
-
"clack",
|
|
20
|
-
"cli",
|
|
21
|
-
"error",
|
|
22
|
-
"format",
|
|
23
|
-
"prompt",
|
|
24
|
-
"reliverse",
|
|
25
|
-
"reporter",
|
|
26
|
-
"stacktrace",
|
|
27
|
-
"unified",
|
|
28
|
-
"universal"
|
|
29
|
-
],
|
|
30
|
-
"devDependencies": {},
|
|
6
|
+
"description": "@reliverse/relinka is a modern and lightweight logging library.",
|
|
31
7
|
"exports": {
|
|
32
|
-
".":
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/mod.d.ts",
|
|
10
|
+
"default": "./dist/mod.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@reliverse/relico": "2.2.7"
|
|
33
15
|
},
|
|
34
|
-
"files": [
|
|
35
|
-
"bin",
|
|
36
|
-
"package.json",
|
|
37
|
-
"README.md",
|
|
38
|
-
"LICENSE"
|
|
39
|
-
],
|
|
40
|
-
"main": "./bin/mod.js",
|
|
41
|
-
"module": "./bin/mod.js",
|
|
42
16
|
"publishConfig": {
|
|
43
17
|
"access": "public"
|
|
44
|
-
}
|
|
45
|
-
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"package.json"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Nazar Kornienko (blefnk), Reliverse
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/bin/alias.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Alias exports for the relinka logger
|
|
3
|
-
* Provides convenient aliases for common logging needs
|
|
4
|
-
*/
|
|
5
|
-
import { relinka } from "./impl.js";
|
|
6
|
-
export { relinka as log, relinka as logger };
|
|
7
|
-
export declare function message(msg: string, ...args: unknown[]): void;
|
|
8
|
-
export declare function step(msg: string, ...args: unknown[]): void;
|
package/bin/alias.js
DELETED
package/bin/impl.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type LogLevel, type RelinkaConfig, type RelinkaConfigOptions, type RelinkaFunction } from "./setup";
|
|
2
|
-
/** Promise resolved once the user's config (if any) is merged. */
|
|
3
|
-
export declare const loadRelinkaConfig: Promise<RelinkaConfig>;
|
|
4
|
-
/**
|
|
5
|
-
* Enhanced relinkaConfig function that accepts options
|
|
6
|
-
*/
|
|
7
|
-
export declare function relinkaConfig(options?: RelinkaConfigOptions): Promise<RelinkaConfig>;
|
|
8
|
-
/**
|
|
9
|
-
* Shuts down the logger, flushing all buffers and clearing timers.
|
|
10
|
-
* As Relinka user - call this at the end of your program to prevent hanging.
|
|
11
|
-
*/
|
|
12
|
-
export declare function relinkaShutdown(): Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* Flushes all log buffers to disk. Used before process exit or on demand.
|
|
15
|
-
*/
|
|
16
|
-
export declare function flushAllLogBuffers(): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* If something truly impossible happened, log + throw.
|
|
19
|
-
*/
|
|
20
|
-
export declare function shouldNeverHappen(message: string, ...args: unknown[]): never;
|
|
21
|
-
/**
|
|
22
|
-
* Truncates a string to a specified length, adding "…" if truncated.
|
|
23
|
-
*/
|
|
24
|
-
export declare function truncateString(msg: string, maxLength?: number): string;
|
|
25
|
-
/**
|
|
26
|
-
* Exhaustiveness check. If we land here, we missed a union case.
|
|
27
|
-
*/
|
|
28
|
-
export declare function casesHandled(unexpectedCase: never): never;
|
|
29
|
-
/**
|
|
30
|
-
* Logs a message synchronously using the current config.
|
|
31
|
-
* If type === "fatal", logs a fatal error and throws (never returns).
|
|
32
|
-
*
|
|
33
|
-
* Can be used in two ways:
|
|
34
|
-
* - relinka("level", message, ...args) - traditional syntax
|
|
35
|
-
* - relinka.level(message, ...args) - method syntax
|
|
36
|
-
*/
|
|
37
|
-
export declare const relinka: RelinkaFunction;
|
|
38
|
-
/**
|
|
39
|
-
* Logs a message asynchronously, waiting for the config to be fully loaded.
|
|
40
|
-
* If type === "fatal", logs a fatal error and throws (never returns).
|
|
41
|
-
*/
|
|
42
|
-
export declare function relinkaAsync(type: LogLevel, message: string, ...args: unknown[]): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Type helper for user config files.
|
|
45
|
-
*/
|
|
46
|
-
export declare function defineConfig(config: Partial<RelinkaConfig>): Partial<RelinkaConfig>;
|
|
47
|
-
/**
|
|
48
|
-
* Simple box formatting function
|
|
49
|
-
*/
|
|
50
|
-
export declare function formatBox(text: string): string;
|