@visulima/pail 2.1.16 → 2.1.18
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/CHANGELOG.md +24 -0
- package/dist/index.browser.cjs +19 -1
- package/dist/index.browser.mjs +14 -1
- package/dist/index.server.cjs +442 -5
- package/dist/index.server.mjs +437 -5
- package/dist/packem_shared/CallerProcessor-CyJFdYGN.mjs +58 -0
- package/dist/packem_shared/CallerProcessor-DYrXv6Fp.cjs +60 -0
- package/dist/packem_shared/JsonFileReporter-BHaRQMnS.cjs +135 -0
- package/dist/packem_shared/JsonFileReporter-CdHau53i.mjs +133 -0
- package/dist/packem_shared/JsonReporter-C05lFJhj.mjs +20 -0
- package/dist/packem_shared/JsonReporter-DCd8dbfQ.mjs +32 -0
- package/dist/packem_shared/JsonReporter-DDubAhfJ.cjs +22 -0
- package/dist/packem_shared/JsonReporter-HXYHZuWz.cjs +34 -0
- package/dist/packem_shared/MessageFormatterProcessor-CFyi7GWt.mjs +53 -0
- package/dist/packem_shared/MessageFormatterProcessor-D_txQ9nO.cjs +55 -0
- package/dist/packem_shared/PrettyReporter-Bx3QLZrW.mjs +162 -0
- package/dist/packem_shared/PrettyReporter-LWDDriJ1.cjs +200 -0
- package/dist/packem_shared/PrettyReporter-XC0Ix5SW.mjs +192 -0
- package/dist/packem_shared/PrettyReporter-mFCjMb0i.cjs +168 -0
- package/dist/packem_shared/RedactProcessor-CfNkF2lC.mjs +26 -0
- package/dist/packem_shared/RedactProcessor-DWE5iqAQ.cjs +26 -0
- package/dist/packem_shared/SimpleReporter-CuNgsGVB.mjs +178 -0
- package/dist/packem_shared/SimpleReporter-DabZGkIs.cjs +186 -0
- package/dist/packem_shared/abstract-json-reporter-CG0EXqip.mjs +55 -0
- package/dist/packem_shared/abstract-json-reporter-D4MiU6B-.cjs +57 -0
- package/dist/packem_shared/abstract-pretty-reporter-BR_6_JVa.cjs +49 -0
- package/dist/packem_shared/abstract-pretty-reporter-izJgxoMv.mjs +46 -0
- package/dist/packem_shared/constants-BYYZ5WNW.mjs +114 -0
- package/dist/packem_shared/constants-DHfYGxxG.cjs +118 -0
- package/dist/packem_shared/format-label-CQCvMzlF.cjs +622 -0
- package/dist/packem_shared/format-label-DYMZf3Bg.mjs +610 -0
- package/dist/packem_shared/get-longest-label-CM8kLFWH.mjs +11 -0
- package/dist/packem_shared/get-longest-label-CQ7lRhgD.cjs +13 -0
- package/dist/packem_shared/pail.browser-B3Bi2uPA.cjs +387 -0
- package/dist/packem_shared/pail.browser-DZLrCtc5.mjs +384 -0
- package/dist/packem_shared/write-console-log-Cu0-IDN-.cjs +18 -0
- package/dist/packem_shared/write-console-log-Tptfzg9D.mjs +16 -0
- package/dist/packem_shared/write-stream-BBAF33Zm.mjs +8 -0
- package/dist/packem_shared/write-stream-CkNf2Ju8.cjs +10 -0
- package/dist/processor.browser.cjs +11 -1
- package/dist/processor.browser.mjs +2 -1
- package/dist/processor.server.cjs +13 -1
- package/dist/processor.server.mjs +3 -1
- package/dist/reporter.browser.cjs +11 -1
- package/dist/reporter.browser.mjs +2 -1
- package/dist/reporter.server.cjs +15 -1
- package/dist/reporter.server.mjs +4 -1
- package/package.json +14 -14
- package/dist/packem_shared/CallerProcessor-BBHkvRgS.mjs +0 -1
- package/dist/packem_shared/CallerProcessor-CLoY9R76.cjs +0 -1
- package/dist/packem_shared/JsonFileReporter-CLEMnuGI.cjs +0 -2
- package/dist/packem_shared/JsonFileReporter-lr0s7r9B.mjs +0 -4
- package/dist/packem_shared/JsonReporter-CiQkPCv4.cjs +0 -2
- package/dist/packem_shared/JsonReporter-CjvkrXUp.cjs +0 -1
- package/dist/packem_shared/JsonReporter-DInAbLuf.mjs +0 -1
- package/dist/packem_shared/JsonReporter-J50eZjl2.mjs +0 -2
- package/dist/packem_shared/MessageFormatterProcessor-CCRIUIdT.cjs +0 -1
- package/dist/packem_shared/MessageFormatterProcessor-D_XajTuK.mjs +0 -1
- package/dist/packem_shared/PrettyReporter-1SleqVaI.mjs +0 -13
- package/dist/packem_shared/PrettyReporter-C_AJrNOj.mjs +0 -5
- package/dist/packem_shared/PrettyReporter-CldK9UpN.cjs +0 -13
- package/dist/packem_shared/PrettyReporter-CuJWFD0k.cjs +0 -5
- package/dist/packem_shared/RedactProcessor-BVZtatWJ.cjs +0 -1
- package/dist/packem_shared/RedactProcessor-CxKTN42V.mjs +0 -3
- package/dist/packem_shared/SimpleReporter-Cy_0ZeXQ.cjs +0 -11
- package/dist/packem_shared/SimpleReporter-DzUWU5Gu.mjs +0 -11
- package/dist/packem_shared/abstract-json-reporter-29d4dwOH.mjs +0 -1
- package/dist/packem_shared/abstract-json-reporter-Z6bVrpPK.cjs +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-CZb4ET-0.cjs +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-DgXRHEj-.mjs +0 -1
- package/dist/packem_shared/constants-BFrKdBPm.cjs +0 -1
- package/dist/packem_shared/constants-BMS51p6Y.mjs +0 -1
- package/dist/packem_shared/format-label-B0BaeOry.cjs +0 -8
- package/dist/packem_shared/format-label-ECls2QEw.mjs +0 -8
- package/dist/packem_shared/get-longest-label-4ISUsE2q.mjs +0 -1
- package/dist/packem_shared/get-longest-label-DXpzhu5N.cjs +0 -1
- package/dist/packem_shared/pail.browser-D7k9K5zt.mjs +0 -1
- package/dist/packem_shared/pail.browser-tTEE0Aky.cjs +0 -1
- package/dist/packem_shared/write-console-log-3G15muTS.cjs +0 -1
- package/dist/packem_shared/write-console-log-BP95fgQZ.mjs +0 -1
- package/dist/packem_shared/write-stream-Bgxqp0HI.cjs +0 -1
- package/dist/packem_shared/write-stream-C17GXSxA.mjs +0 -1
package/dist/index.server.mjs
CHANGED
|
@@ -1,5 +1,437 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { stdout, stderr, env } from 'node:process';
|
|
2
|
+
import { t as terminalSize, w as wrapAnsi } from './packem_shared/format-label-DYMZf3Bg.mjs';
|
|
3
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
4
|
+
import { a as PailBrowserImpl } from './packem_shared/pail.browser-DZLrCtc5.mjs';
|
|
5
|
+
import { inspect } from '@visulima/inspector';
|
|
6
|
+
import { E as EMPTY_SYMBOL } from './packem_shared/constants-BYYZ5WNW.mjs';
|
|
7
|
+
import { w as writeStream } from './packem_shared/write-stream-BBAF33Zm.mjs';
|
|
8
|
+
import MessageFormatterProcessor from './packem_shared/MessageFormatterProcessor-CFyi7GWt.mjs';
|
|
9
|
+
import { PrettyReporter } from './packem_shared/PrettyReporter-XC0Ix5SW.mjs';
|
|
10
|
+
|
|
11
|
+
var __defProp$5 = Object.defineProperty;
|
|
12
|
+
var __name$5 = (target, value) => __defProp$5(target, "name", { value, configurable: true });
|
|
13
|
+
class InteractiveManager {
|
|
14
|
+
static {
|
|
15
|
+
__name$5(this, "InteractiveManager");
|
|
16
|
+
}
|
|
17
|
+
#stream;
|
|
18
|
+
#isActive = false;
|
|
19
|
+
#isSuspended = false;
|
|
20
|
+
#lastLength = 0;
|
|
21
|
+
#outside = 0;
|
|
22
|
+
constructor(stdout, stderr) {
|
|
23
|
+
this.#stream = {
|
|
24
|
+
stderr,
|
|
25
|
+
stdout
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Last printed rows count
|
|
30
|
+
*/
|
|
31
|
+
get lastLength() {
|
|
32
|
+
return this.#lastLength;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Rows count outside editable area
|
|
36
|
+
*/
|
|
37
|
+
get outside() {
|
|
38
|
+
return this.#outside;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hook activity status
|
|
42
|
+
*/
|
|
43
|
+
get isHooked() {
|
|
44
|
+
return this.#isActive;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Suspend status for active hooks
|
|
48
|
+
*/
|
|
49
|
+
get isSuspended() {
|
|
50
|
+
return this.#isSuspended;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Removes from the bottom of output up the specified count of lines
|
|
54
|
+
*
|
|
55
|
+
* @param stream - Stream to remove lines from
|
|
56
|
+
* @param count - lines count to remove
|
|
57
|
+
*/
|
|
58
|
+
erase(stream, count = this.#lastLength) {
|
|
59
|
+
if (this.#stream[stream] === undefined) {
|
|
60
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
61
|
+
}
|
|
62
|
+
this.#stream[stream].erase(count);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Hook stdout and stderr streams
|
|
66
|
+
* @returns Success status
|
|
67
|
+
*/
|
|
68
|
+
hook() {
|
|
69
|
+
if (!this.#isActive) {
|
|
70
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
71
|
+
this._clear(true);
|
|
72
|
+
}
|
|
73
|
+
return this.#isActive;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resume suspend hooks
|
|
77
|
+
*
|
|
78
|
+
* @param stream - Stream to resume
|
|
79
|
+
* @param eraseRowCount - erase output rows count
|
|
80
|
+
*/
|
|
81
|
+
resume(stream, eraseRowCount) {
|
|
82
|
+
if (this.#isSuspended) {
|
|
83
|
+
this.#isSuspended = false;
|
|
84
|
+
if (eraseRowCount) {
|
|
85
|
+
this.erase(stream, eraseRowCount);
|
|
86
|
+
}
|
|
87
|
+
this.#lastLength = 0;
|
|
88
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Suspend active hooks for external output
|
|
93
|
+
*
|
|
94
|
+
* @param stream - Stream to suspend
|
|
95
|
+
* @param erase - erase output
|
|
96
|
+
*/
|
|
97
|
+
suspend(stream, erase = true) {
|
|
98
|
+
if (!this.#isSuspended) {
|
|
99
|
+
this.#isSuspended = true;
|
|
100
|
+
if (erase) {
|
|
101
|
+
this.erase(stream);
|
|
102
|
+
}
|
|
103
|
+
Object.values(this.#stream).forEach((hook) => hook.renew());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Unhooks both stdout and stderr streams and print their story of logs
|
|
108
|
+
*
|
|
109
|
+
* @param separateHistory - If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
110
|
+
*
|
|
111
|
+
* @returns Success status
|
|
112
|
+
*/
|
|
113
|
+
unhook(separateHistory = true) {
|
|
114
|
+
if (this.#isActive) {
|
|
115
|
+
Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));
|
|
116
|
+
this._clear();
|
|
117
|
+
}
|
|
118
|
+
return !this.#isActive;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Update output
|
|
122
|
+
*
|
|
123
|
+
* @param stream - Stream to write to
|
|
124
|
+
* @param rows - Text lines to write to standard output
|
|
125
|
+
* @param from - Index of the line starting from which the contents of the terminal are being overwritten
|
|
126
|
+
*/
|
|
127
|
+
update(stream, rows, from = 0) {
|
|
128
|
+
if (rows.length > 0) {
|
|
129
|
+
if (this.#stream[stream] === undefined) {
|
|
130
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
131
|
+
}
|
|
132
|
+
const hook = this.#stream[stream];
|
|
133
|
+
const { columns: width, rows: height } = terminalSize();
|
|
134
|
+
const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));
|
|
135
|
+
const actualLength = this.lastLength - position;
|
|
136
|
+
const outside = Math.max(actualLength - height, this.outside);
|
|
137
|
+
let output = rows.reduce(
|
|
138
|
+
(accumulator, row) => [
|
|
139
|
+
...accumulator,
|
|
140
|
+
wrapAnsi(row, width, {
|
|
141
|
+
hard: true,
|
|
142
|
+
trim: false,
|
|
143
|
+
wordWrap: true
|
|
144
|
+
})
|
|
145
|
+
],
|
|
146
|
+
[]
|
|
147
|
+
);
|
|
148
|
+
if (height <= actualLength) {
|
|
149
|
+
hook.erase(height);
|
|
150
|
+
if (position < outside) {
|
|
151
|
+
output = output.slice(outside - position + 1);
|
|
152
|
+
}
|
|
153
|
+
} else if (actualLength) {
|
|
154
|
+
hook.erase(actualLength);
|
|
155
|
+
}
|
|
156
|
+
hook.write(output.join("\n") + "\n");
|
|
157
|
+
this.#lastLength = outside ? outside + output.length + 1 : output.length;
|
|
158
|
+
this.#outside = Math.max(this.lastLength - height, this.outside);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_clear(status = false) {
|
|
162
|
+
this.#isActive = status;
|
|
163
|
+
this.#lastLength = 0;
|
|
164
|
+
this.#outside = 0;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
var __defProp$4 = Object.defineProperty;
|
|
169
|
+
var __name$4 = (target, value) => __defProp$4(target, "name", { value, configurable: true });
|
|
170
|
+
const ESC = "\x1B[";
|
|
171
|
+
const eraseScreen = ESC + "2J";
|
|
172
|
+
const eraseLine = ESC + "2K";
|
|
173
|
+
const cursorLeft = ESC + "G";
|
|
174
|
+
const cursorUp = /* @__PURE__ */ __name$4((count = 1) => ESC + count + "A", "cursorUp");
|
|
175
|
+
const clearTerminal = process.platform === "win32" ? `${eraseScreen}${ESC}0f` : (
|
|
176
|
+
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
177
|
+
// 2. Erases the whole screen including scrollback buffer
|
|
178
|
+
// 3. Moves cursor to the top-left position
|
|
179
|
+
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
180
|
+
`${eraseScreen}${ESC}3J${ESC}H`
|
|
181
|
+
);
|
|
182
|
+
const cursorHide = ESC + "?25l";
|
|
183
|
+
const cursorShow = ESC + "?25h";
|
|
184
|
+
const eraseLines = /* @__PURE__ */ __name$4((count) => {
|
|
185
|
+
let clear = "";
|
|
186
|
+
for (let index = 0; index < count; index++) {
|
|
187
|
+
clear += eraseLine + (index < count - 1 ? cursorUp() : "");
|
|
188
|
+
}
|
|
189
|
+
if (count) {
|
|
190
|
+
clear += cursorLeft;
|
|
191
|
+
}
|
|
192
|
+
return clear;
|
|
193
|
+
}, "eraseLines");
|
|
194
|
+
|
|
195
|
+
var __defProp$3 = Object.defineProperty;
|
|
196
|
+
var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
|
|
197
|
+
class InteractiveStreamHook {
|
|
198
|
+
static {
|
|
199
|
+
__name$3(this, "InteractiveStreamHook");
|
|
200
|
+
}
|
|
201
|
+
static DRAIN = true;
|
|
202
|
+
#decoder = new StringDecoder();
|
|
203
|
+
#history = [];
|
|
204
|
+
#method;
|
|
205
|
+
#stream;
|
|
206
|
+
constructor(stream) {
|
|
207
|
+
this.#method = stream.write;
|
|
208
|
+
this.#stream = stream;
|
|
209
|
+
}
|
|
210
|
+
active() {
|
|
211
|
+
this.write(cursorHide);
|
|
212
|
+
this.#stream.write = (data, ...arguments_) => {
|
|
213
|
+
const callback = arguments_.at(-1);
|
|
214
|
+
this.#history.push(
|
|
215
|
+
this.#decoder.write(
|
|
216
|
+
typeof data === "string" ? Buffer.from(data, typeof arguments_[0] === "string" ? arguments_[0] : undefined) : Buffer.from(data)
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
if (typeof callback === "function") {
|
|
220
|
+
callback();
|
|
221
|
+
}
|
|
222
|
+
return InteractiveStreamHook.DRAIN;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
erase(count) {
|
|
226
|
+
if (count > 0) {
|
|
227
|
+
this.write(eraseLines(count + 1));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
inactive(separateHistory = false) {
|
|
231
|
+
if (this.#history.length > 0) {
|
|
232
|
+
if (separateHistory) {
|
|
233
|
+
this.write("\n");
|
|
234
|
+
}
|
|
235
|
+
this.#history.forEach((element) => {
|
|
236
|
+
this.write(element);
|
|
237
|
+
});
|
|
238
|
+
this.#history = [];
|
|
239
|
+
}
|
|
240
|
+
this.renew();
|
|
241
|
+
}
|
|
242
|
+
renew() {
|
|
243
|
+
this.#stream.write = this.#method;
|
|
244
|
+
this.write(cursorShow);
|
|
245
|
+
}
|
|
246
|
+
write(message) {
|
|
247
|
+
this.#method.apply(this.#stream, [message]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
var __defProp$2 = Object.defineProperty;
|
|
252
|
+
var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
|
|
253
|
+
class RawReporter {
|
|
254
|
+
static {
|
|
255
|
+
__name$2(this, "RawReporter");
|
|
256
|
+
}
|
|
257
|
+
#stdout;
|
|
258
|
+
#stderr;
|
|
259
|
+
#interactiveManager;
|
|
260
|
+
#interactive = false;
|
|
261
|
+
#inspectOptions;
|
|
262
|
+
constructor(inspectOptions = {}) {
|
|
263
|
+
this.#stdout = stdout;
|
|
264
|
+
this.#stderr = stderr;
|
|
265
|
+
this.#inspectOptions = inspectOptions;
|
|
266
|
+
}
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
268
|
+
setStdout(stdout_) {
|
|
269
|
+
this.#stdout = stdout_;
|
|
270
|
+
}
|
|
271
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
272
|
+
setStderr(stderr_) {
|
|
273
|
+
this.#stderr = stderr_;
|
|
274
|
+
}
|
|
275
|
+
setInteractiveManager(manager) {
|
|
276
|
+
this.#interactiveManager = manager;
|
|
277
|
+
}
|
|
278
|
+
setIsInteractive(interactive) {
|
|
279
|
+
this.#interactive = interactive;
|
|
280
|
+
}
|
|
281
|
+
log(meta) {
|
|
282
|
+
const { context, groups, message, type } = meta;
|
|
283
|
+
const items = [];
|
|
284
|
+
if (message !== EMPTY_SYMBOL) {
|
|
285
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
286
|
+
items.push(formattedMessage);
|
|
287
|
+
}
|
|
288
|
+
if (context) {
|
|
289
|
+
items.push(
|
|
290
|
+
...context.map((value) => {
|
|
291
|
+
if (typeof value === "object") {
|
|
292
|
+
return " " + inspect(value, this.#inspectOptions);
|
|
293
|
+
}
|
|
294
|
+
return " " + value;
|
|
295
|
+
})
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
const streamType = ["error", "trace", "warn"].includes(type.level) ? "stderr" : "stdout";
|
|
299
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
300
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
301
|
+
if (this.#interactive && this.#interactiveManager !== undefined && stream.isTTY) {
|
|
302
|
+
this.#interactiveManager.update(streamType, (groupSpaces + items.join("")).split("\n"), 0);
|
|
303
|
+
} else {
|
|
304
|
+
writeStream(groupSpaces + items.join(""), stream);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
var __defProp$1 = Object.defineProperty;
|
|
310
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
311
|
+
class PailServerImpl extends PailBrowserImpl {
|
|
312
|
+
constructor(options) {
|
|
313
|
+
const { interactive, rawReporter, reporters, stderr, stdout, ...rest } = options;
|
|
314
|
+
super(rest);
|
|
315
|
+
this.options = options;
|
|
316
|
+
this.interactive = interactive ?? false;
|
|
317
|
+
this.stdout = stdout;
|
|
318
|
+
this.stderr = stderr;
|
|
319
|
+
if (this.interactive) {
|
|
320
|
+
this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(reporters)) {
|
|
323
|
+
this.registerReporters(reporters);
|
|
324
|
+
}
|
|
325
|
+
this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter());
|
|
326
|
+
}
|
|
327
|
+
static {
|
|
328
|
+
__name$1(this, "PailServerImpl");
|
|
329
|
+
}
|
|
330
|
+
stdout;
|
|
331
|
+
stderr;
|
|
332
|
+
interactiveManager;
|
|
333
|
+
interactive;
|
|
334
|
+
// @ts-expect-error - this returns a different type
|
|
335
|
+
scope(...name) {
|
|
336
|
+
if (name.length === 0) {
|
|
337
|
+
throw new Error("No scope name was defined.");
|
|
338
|
+
}
|
|
339
|
+
this.scopeName = name.flat();
|
|
340
|
+
return this;
|
|
341
|
+
}
|
|
342
|
+
getInteractiveManager() {
|
|
343
|
+
return this.interactiveManager;
|
|
344
|
+
}
|
|
345
|
+
wrapStd() {
|
|
346
|
+
this._wrapStream(this.stdout, "log");
|
|
347
|
+
this._wrapStream(this.stderr, "log");
|
|
348
|
+
}
|
|
349
|
+
restoreStd() {
|
|
350
|
+
this._restoreStream(this.stdout);
|
|
351
|
+
this._restoreStream(this.stderr);
|
|
352
|
+
}
|
|
353
|
+
wrapAll() {
|
|
354
|
+
this.wrapConsole();
|
|
355
|
+
this.wrapStd();
|
|
356
|
+
}
|
|
357
|
+
restoreAll() {
|
|
358
|
+
this.restoreConsole();
|
|
359
|
+
this.restoreStd();
|
|
360
|
+
}
|
|
361
|
+
clear() {
|
|
362
|
+
this.stdout.write(clearTerminal);
|
|
363
|
+
this.stderr.write(clearTerminal);
|
|
364
|
+
}
|
|
365
|
+
extendReporter(reporter) {
|
|
366
|
+
if (typeof reporter.setStdout === "function") {
|
|
367
|
+
reporter.setStdout(this.stdout);
|
|
368
|
+
}
|
|
369
|
+
if (typeof reporter.setStderr === "function") {
|
|
370
|
+
reporter.setStderr(this.stderr);
|
|
371
|
+
}
|
|
372
|
+
if (typeof reporter.setLoggerTypes === "function") {
|
|
373
|
+
reporter.setLoggerTypes(this.types);
|
|
374
|
+
}
|
|
375
|
+
if (typeof reporter.setStringify === "function") {
|
|
376
|
+
reporter.setStringify(this.stringify);
|
|
377
|
+
}
|
|
378
|
+
if (typeof reporter.setIsInteractive === "function") {
|
|
379
|
+
reporter.setIsInteractive(this.interactive);
|
|
380
|
+
}
|
|
381
|
+
if (this.interactive && typeof reporter.setInteractiveManager === "function") {
|
|
382
|
+
reporter.setInteractiveManager(this.interactiveManager);
|
|
383
|
+
}
|
|
384
|
+
return reporter;
|
|
385
|
+
}
|
|
386
|
+
_wrapStream(stream, type) {
|
|
387
|
+
if (!stream) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (!stream.__write) {
|
|
391
|
+
stream.__write = stream.write;
|
|
392
|
+
}
|
|
393
|
+
stream.write = (data) => {
|
|
394
|
+
this[type].log(String(data).trim());
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
// eslint-disable-next-line class-methods-use-this
|
|
398
|
+
_restoreStream(stream) {
|
|
399
|
+
if (!stream) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (stream.__write) {
|
|
403
|
+
stream.write = stream.__write;
|
|
404
|
+
delete stream.__write;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
const PailServer = PailServerImpl;
|
|
409
|
+
|
|
410
|
+
var __defProp = Object.defineProperty;
|
|
411
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
412
|
+
const _getDefaultLogLevel = /* @__PURE__ */ __name(() => {
|
|
413
|
+
if (env.NODE_ENV === "debug" || env.DEBUG !== undefined) {
|
|
414
|
+
return "debug";
|
|
415
|
+
}
|
|
416
|
+
if (env.NODE_ENV === "test") {
|
|
417
|
+
return "warning";
|
|
418
|
+
}
|
|
419
|
+
return "informational";
|
|
420
|
+
}, "_getDefaultLogLevel");
|
|
421
|
+
const createPail = /* @__PURE__ */ __name((options) => {
|
|
422
|
+
let logLevel = _getDefaultLogLevel();
|
|
423
|
+
if (env.PAIL_LOG_LEVEL !== undefined) {
|
|
424
|
+
logLevel = env.PAIL_LOG_LEVEL;
|
|
425
|
+
}
|
|
426
|
+
return new PailServer({
|
|
427
|
+
logLevel,
|
|
428
|
+
processors: [new MessageFormatterProcessor()],
|
|
429
|
+
reporters: [new PrettyReporter()],
|
|
430
|
+
stderr,
|
|
431
|
+
stdout,
|
|
432
|
+
...options
|
|
433
|
+
});
|
|
434
|
+
}, "createPail");
|
|
435
|
+
const pail = createPail();
|
|
436
|
+
|
|
437
|
+
export { createPail, pail };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp$1 = Object.defineProperty;
|
|
2
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
3
|
+
const getCallerFilename = /* @__PURE__ */ __name$1(() => {
|
|
4
|
+
const errorStack = Error.prepareStackTrace;
|
|
5
|
+
try {
|
|
6
|
+
let result = [];
|
|
7
|
+
Error.prepareStackTrace = (_error, stack) => {
|
|
8
|
+
const callSitesWithoutCurrent = stack.slice(1);
|
|
9
|
+
result = callSitesWithoutCurrent;
|
|
10
|
+
return callSitesWithoutCurrent;
|
|
11
|
+
};
|
|
12
|
+
const callers = result.reduce((accumulator, x) => {
|
|
13
|
+
if (x.isNative() || x.getFileName()?.includes("pail/dist")) {
|
|
14
|
+
return accumulator;
|
|
15
|
+
}
|
|
16
|
+
accumulator.push({
|
|
17
|
+
columnNumber: x.getColumnNumber(),
|
|
18
|
+
fileName: x.getFileName(),
|
|
19
|
+
lineNumber: x.getLineNumber()
|
|
20
|
+
});
|
|
21
|
+
return accumulator;
|
|
22
|
+
}, []);
|
|
23
|
+
const firstExternalFilePath = callers[0];
|
|
24
|
+
if (firstExternalFilePath) {
|
|
25
|
+
return {
|
|
26
|
+
columnNumber: firstExternalFilePath.columnNumber ?? undefined,
|
|
27
|
+
fileName: firstExternalFilePath.fileName,
|
|
28
|
+
lineNumber: firstExternalFilePath.lineNumber ?? undefined
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
fileName: "anonymous",
|
|
33
|
+
lineNumber: undefined
|
|
34
|
+
};
|
|
35
|
+
} finally {
|
|
36
|
+
Error.prepareStackTrace = errorStack;
|
|
37
|
+
}
|
|
38
|
+
}, "getCallerFilename");
|
|
39
|
+
|
|
40
|
+
var __defProp = Object.defineProperty;
|
|
41
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
42
|
+
class CallerProcessor {
|
|
43
|
+
static {
|
|
44
|
+
__name(this, "CallerProcessor");
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line class-methods-use-this
|
|
47
|
+
process(meta) {
|
|
48
|
+
const { columnNumber, fileName, lineNumber } = getCallerFilename();
|
|
49
|
+
meta.file = {
|
|
50
|
+
column: columnNumber,
|
|
51
|
+
line: lineNumber,
|
|
52
|
+
name: fileName
|
|
53
|
+
};
|
|
54
|
+
return meta;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { CallerProcessor as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp$1 = Object.defineProperty;
|
|
4
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
5
|
+
const getCallerFilename = /* @__PURE__ */ __name$1(() => {
|
|
6
|
+
const errorStack = Error.prepareStackTrace;
|
|
7
|
+
try {
|
|
8
|
+
let result = [];
|
|
9
|
+
Error.prepareStackTrace = (_error, stack) => {
|
|
10
|
+
const callSitesWithoutCurrent = stack.slice(1);
|
|
11
|
+
result = callSitesWithoutCurrent;
|
|
12
|
+
return callSitesWithoutCurrent;
|
|
13
|
+
};
|
|
14
|
+
const callers = result.reduce((accumulator, x) => {
|
|
15
|
+
if (x.isNative() || x.getFileName()?.includes("pail/dist")) {
|
|
16
|
+
return accumulator;
|
|
17
|
+
}
|
|
18
|
+
accumulator.push({
|
|
19
|
+
columnNumber: x.getColumnNumber(),
|
|
20
|
+
fileName: x.getFileName(),
|
|
21
|
+
lineNumber: x.getLineNumber()
|
|
22
|
+
});
|
|
23
|
+
return accumulator;
|
|
24
|
+
}, []);
|
|
25
|
+
const firstExternalFilePath = callers[0];
|
|
26
|
+
if (firstExternalFilePath) {
|
|
27
|
+
return {
|
|
28
|
+
columnNumber: firstExternalFilePath.columnNumber ?? undefined,
|
|
29
|
+
fileName: firstExternalFilePath.fileName,
|
|
30
|
+
lineNumber: firstExternalFilePath.lineNumber ?? undefined
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
fileName: "anonymous",
|
|
35
|
+
lineNumber: undefined
|
|
36
|
+
};
|
|
37
|
+
} finally {
|
|
38
|
+
Error.prepareStackTrace = errorStack;
|
|
39
|
+
}
|
|
40
|
+
}, "getCallerFilename");
|
|
41
|
+
|
|
42
|
+
var __defProp = Object.defineProperty;
|
|
43
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
44
|
+
class CallerProcessor {
|
|
45
|
+
static {
|
|
46
|
+
__name(this, "CallerProcessor");
|
|
47
|
+
}
|
|
48
|
+
// eslint-disable-next-line class-methods-use-this
|
|
49
|
+
process(meta) {
|
|
50
|
+
const { columnNumber, fileName, lineNumber } = getCallerFilename();
|
|
51
|
+
meta.file = {
|
|
52
|
+
column: columnNumber,
|
|
53
|
+
line: lineNumber,
|
|
54
|
+
name: fileName
|
|
55
|
+
};
|
|
56
|
+
return meta;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = CallerProcessor;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const abstractJsonReporter = require('./abstract-json-reporter-D4MiU6B-.cjs');
|
|
6
|
+
|
|
7
|
+
var __defProp$2 = Object.defineProperty;
|
|
8
|
+
var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
|
|
9
|
+
class SafeStreamHandler {
|
|
10
|
+
static {
|
|
11
|
+
__name$2(this, "SafeStreamHandler");
|
|
12
|
+
}
|
|
13
|
+
#ready = true;
|
|
14
|
+
#stream;
|
|
15
|
+
#name;
|
|
16
|
+
constructor(stream, name) {
|
|
17
|
+
this.#stream = stream;
|
|
18
|
+
this.#name = name;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Writes `message` to the instance's internal stream
|
|
22
|
+
* @param message Message to write
|
|
23
|
+
*/
|
|
24
|
+
write(message) {
|
|
25
|
+
this.writeStream(message);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Calls `end` on this instance's internal stream
|
|
29
|
+
*/
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
end(...arguments_) {
|
|
32
|
+
this.#stream.end(...arguments_);
|
|
33
|
+
}
|
|
34
|
+
get isReady() {
|
|
35
|
+
return this.#ready;
|
|
36
|
+
}
|
|
37
|
+
writeStream(message) {
|
|
38
|
+
if (!this.#ready) {
|
|
39
|
+
console.warn("Stream busy: " + this.#name + '. Write will be dropped: "' + message + '"');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.#ready = false;
|
|
43
|
+
this.#stream.on("error", (error) => {
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
this.#stream.on("drain", () => {
|
|
47
|
+
this.#ready = true;
|
|
48
|
+
});
|
|
49
|
+
this.#stream.on("finish", () => {
|
|
50
|
+
this.#ready = true;
|
|
51
|
+
});
|
|
52
|
+
this.#ready = this.#stream.write(message, () => {
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var __defProp$1 = Object.defineProperty;
|
|
58
|
+
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
59
|
+
class RotatingFileStream {
|
|
60
|
+
static {
|
|
61
|
+
__name$1(this, "RotatingFileStream");
|
|
62
|
+
}
|
|
63
|
+
#filePath;
|
|
64
|
+
#immediate;
|
|
65
|
+
#stream;
|
|
66
|
+
#options;
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
|
|
68
|
+
#createRfsStream;
|
|
69
|
+
constructor(filePath, writeImmediately = false, options = {}) {
|
|
70
|
+
this.#filePath = filePath;
|
|
71
|
+
this.#immediate = writeImmediately;
|
|
72
|
+
this.#options = options;
|
|
73
|
+
if (!this.#immediate) {
|
|
74
|
+
try {
|
|
75
|
+
this.#createRfsStream = require("rotating-file-stream").createStream;
|
|
76
|
+
} catch {
|
|
77
|
+
throw new Error("The 'rotating-file-stream' package is missing. Make sure to install the 'rotating-file-stream' package.");
|
|
78
|
+
}
|
|
79
|
+
this.#stream = this.#createRfsStream(this.#filePath, options);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Writes `message` to the instance's internal #stream
|
|
84
|
+
* @param message Message to write
|
|
85
|
+
*/
|
|
86
|
+
write(message) {
|
|
87
|
+
let fileStream = this.#stream;
|
|
88
|
+
if (this.#immediate) {
|
|
89
|
+
fileStream = this.#createRfsStream(this.#filePath, this.#options);
|
|
90
|
+
}
|
|
91
|
+
const stream = new SafeStreamHandler(fileStream, this.#filePath);
|
|
92
|
+
stream.write(message);
|
|
93
|
+
if (this.#immediate) {
|
|
94
|
+
stream.end();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Ends the instance's internal #stream
|
|
99
|
+
*
|
|
100
|
+
* When `immediate` is not `true`, a call to `write` after calling this method
|
|
101
|
+
* will throw an error.
|
|
102
|
+
*/
|
|
103
|
+
end() {
|
|
104
|
+
if (this.#stream !== undefined) {
|
|
105
|
+
this.#stream.end();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var __defProp = Object.defineProperty;
|
|
111
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
112
|
+
class JsonFileReporter extends abstractJsonReporter.AbstractJsonReporter {
|
|
113
|
+
static {
|
|
114
|
+
__name(this, "JsonFileReporter");
|
|
115
|
+
}
|
|
116
|
+
stream;
|
|
117
|
+
constructor(options) {
|
|
118
|
+
super();
|
|
119
|
+
const { filePath, writeImmediately = false, ...rfsOptions } = options;
|
|
120
|
+
this.stream = new RotatingFileStream(filePath, writeImmediately, {
|
|
121
|
+
compress: "gzip",
|
|
122
|
+
// compress rotated files
|
|
123
|
+
interval: "1d",
|
|
124
|
+
// rotate daily
|
|
125
|
+
size: "10M",
|
|
126
|
+
// rotate every 10 MegaBytes written,
|
|
127
|
+
...rfsOptions
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
_log(message) {
|
|
131
|
+
this.stream.write(message + "\n");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.JsonFileReporter = JsonFileReporter;
|