@visulima/pail 3.0.3 → 3.2.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/CHANGELOG.md +47 -0
- package/LICENSE.md +18 -391
- package/README.md +578 -0
- package/dist/index.browser.d.ts +4 -3
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +19 -74
- package/dist/index.server.js +535 -5
- package/dist/interactive/index.d.ts +28 -0
- package/dist/interactive/index.js +2 -0
- package/dist/object-tree.d.ts +17 -0
- package/dist/object-tree.js +89 -0
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/{abstract-json-reporter-wUti0B3k.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +3 -3
- package/dist/packem_shared/{abstract-pretty-reporter-MOYolfGR.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/{pail.browser-Bs2ng_Qj.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
- package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
- package/dist/packem_shared/{types-RidvA4RN.d.ts → types-D3ycu8-x.d.ts} +2 -29
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/processor/caller/caller-processor.d.ts +2 -1
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/message-formatter-processor.d.ts +2 -1
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +19 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +2 -1
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +76 -0
- package/dist/progress-bar.js +404 -0
- package/dist/reporter/file/json-file-reporter.d.ts +3 -2
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +13 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/json/index.browser.d.ts +3 -2
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -2
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/pretty/index.browser.d.ts +3 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +3 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +3 -2
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/spinner.d.ts +154 -0
- package/dist/spinner.js +2150 -0
- package/package.json +69 -3
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-APmxUrnh.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-DqvZRRR6.js +0 -33
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/getBarChar-mKDZW32R.js +0 -1
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare class InteractiveStreamHook {
|
|
2
|
+
#private;
|
|
3
|
+
static readonly DRAIN = true;
|
|
4
|
+
constructor(stream: NodeJS.WriteStream);
|
|
5
|
+
active(): void;
|
|
6
|
+
erase(count: number): void;
|
|
7
|
+
inactive(separateHistory?: boolean): void;
|
|
8
|
+
renew(): void;
|
|
9
|
+
write(message: string): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type StreamType = "stderr" | "stdout";
|
|
13
|
+
declare class InteractiveManager {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook);
|
|
16
|
+
get lastLength(): number;
|
|
17
|
+
get outside(): number;
|
|
18
|
+
get isHooked(): boolean;
|
|
19
|
+
get isSuspended(): boolean;
|
|
20
|
+
erase(stream: StreamType, count?: number): void;
|
|
21
|
+
hook(): boolean;
|
|
22
|
+
resume(stream: StreamType, eraseRowCount?: number): void;
|
|
23
|
+
suspend(stream: StreamType, erase?: boolean): void;
|
|
24
|
+
unhook(separateHistory?: boolean): boolean;
|
|
25
|
+
update(stream: StreamType, rows: string[], from?: number): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { InteractiveManager, InteractiveStreamHook };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type TreeRenderFunction = (node: unknown) => string | undefined;
|
|
2
|
+
type TreeSortFunction = (a: string, b: string) => number;
|
|
3
|
+
interface ObjectTreeOptions {
|
|
4
|
+
breakCircularWith?: string | null | undefined;
|
|
5
|
+
joined?: boolean;
|
|
6
|
+
keyNeighbour?: string;
|
|
7
|
+
keyNoNeighbour?: string;
|
|
8
|
+
renderFn?: TreeRenderFunction;
|
|
9
|
+
separator?: string;
|
|
10
|
+
sortFn?: TreeSortFunction | undefined;
|
|
11
|
+
spacerNeighbour?: string;
|
|
12
|
+
spacerNoNeighbour?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const renderObjectTree: (tree: Record<string, unknown> | unknown[], options?: ObjectTreeOptions) => string | string[];
|
|
15
|
+
|
|
16
|
+
export { renderObjectTree as default, renderObjectTree };
|
|
17
|
+
export type { ObjectTreeOptions, TreeRenderFunction, TreeSortFunction };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const buildContext = (options) => {
|
|
2
|
+
const context = {
|
|
3
|
+
breakCircularWith: " (circular ref.)",
|
|
4
|
+
joined: true,
|
|
5
|
+
keyNeighbour: "├─ ",
|
|
6
|
+
keyNoNeighbour: "└─ ",
|
|
7
|
+
renderFn: (node) => {
|
|
8
|
+
if (["boolean", "number", "string"].includes(typeof node)) {
|
|
9
|
+
return String(node);
|
|
10
|
+
}
|
|
11
|
+
return void 0;
|
|
12
|
+
},
|
|
13
|
+
separator: ": ",
|
|
14
|
+
sortFn: void 0,
|
|
15
|
+
spacerNeighbour: "│ ",
|
|
16
|
+
spacerNoNeighbour: " ",
|
|
17
|
+
...options
|
|
18
|
+
};
|
|
19
|
+
if (typeof context.joined !== "boolean") {
|
|
20
|
+
throw new TypeError('Option "joined" must be a boolean');
|
|
21
|
+
}
|
|
22
|
+
if (typeof context.spacerNoNeighbour !== "string") {
|
|
23
|
+
throw new TypeError('Option "spacerNoNeighbour" must be a string');
|
|
24
|
+
}
|
|
25
|
+
if (typeof context.spacerNeighbour !== "string") {
|
|
26
|
+
throw new TypeError('Option "spacerNeighbour" must be a string');
|
|
27
|
+
}
|
|
28
|
+
if (typeof context.keyNoNeighbour !== "string") {
|
|
29
|
+
throw new TypeError('Option "keyNoNeighbour" must be a string');
|
|
30
|
+
}
|
|
31
|
+
if (typeof context.keyNeighbour !== "string") {
|
|
32
|
+
throw new TypeError('Option "keyNeighbour" must be a string');
|
|
33
|
+
}
|
|
34
|
+
if (typeof context.separator !== "string") {
|
|
35
|
+
throw new TypeError('Option "separator" must be a string');
|
|
36
|
+
}
|
|
37
|
+
if (typeof context.renderFn !== "function") {
|
|
38
|
+
throw new TypeError('Option "renderFn" must be a function');
|
|
39
|
+
}
|
|
40
|
+
if (context.sortFn !== void 0 && typeof context.sortFn !== "function") {
|
|
41
|
+
throw new TypeError('Option "sortFn" must be a function or undefined');
|
|
42
|
+
}
|
|
43
|
+
if (context.breakCircularWith !== null && typeof context.breakCircularWith !== "string") {
|
|
44
|
+
throw new TypeError('Option "breakCircularWith" must be a string or null');
|
|
45
|
+
}
|
|
46
|
+
return context;
|
|
47
|
+
};
|
|
48
|
+
const renderObjectTree = (tree, options) => {
|
|
49
|
+
const context = buildContext(options);
|
|
50
|
+
const result = [];
|
|
51
|
+
const rootRendered = context.renderFn(tree);
|
|
52
|
+
if (rootRendered !== void 0) {
|
|
53
|
+
result.push(String(rootRendered));
|
|
54
|
+
}
|
|
55
|
+
const sort = (input) => {
|
|
56
|
+
if (context.sortFn === void 0) {
|
|
57
|
+
return input;
|
|
58
|
+
}
|
|
59
|
+
return input.toSorted((a, b) => context?.sortFn?.(b, a) ?? 0);
|
|
60
|
+
};
|
|
61
|
+
const neighbours = [];
|
|
62
|
+
const keys = sort(Object.keys(tree)).map((k) => [k]);
|
|
63
|
+
const lookup = [tree];
|
|
64
|
+
while (keys.length > 0) {
|
|
65
|
+
const key = keys.pop() ?? [];
|
|
66
|
+
const node = lookup[key.length - 1][key[key.length - 1] ?? ""];
|
|
67
|
+
const isCircular = context.breakCircularWith !== null && lookup.slice(0, key.length).includes(node);
|
|
68
|
+
neighbours[key.length - 1] = keys.length > 0 && (keys[keys.length - 1]?.length ?? 0) === key.length;
|
|
69
|
+
const indent = neighbours.slice(0, key.length - 1).map((n) => {
|
|
70
|
+
if (n) {
|
|
71
|
+
return context.spacerNeighbour;
|
|
72
|
+
}
|
|
73
|
+
return context.spacerNoNeighbour;
|
|
74
|
+
}).join("");
|
|
75
|
+
const connector = neighbours[key.length - 1] ? context.keyNeighbour : context.keyNoNeighbour;
|
|
76
|
+
const keyName = key[key.length - 1];
|
|
77
|
+
const nodeRendered = context.renderFn(node);
|
|
78
|
+
const value = nodeRendered === void 0 ? "" : `${context.separator}${nodeRendered}`;
|
|
79
|
+
const circular = isCircular ? context.breakCircularWith : "";
|
|
80
|
+
result.push(`${indent}${connector}${keyName}${value}${circular}`);
|
|
81
|
+
if (node !== null && typeof node === "object" && !Array.isArray(node) && !isCircular) {
|
|
82
|
+
keys.push(...sort(Object.keys(node)).map((k) => [...key, k]));
|
|
83
|
+
lookup[key.length] = node;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return context.joined === true ? result.join("\n") : result;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { renderObjectTree as default, renderObjectTree };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
|
|
2
|
+
|
|
3
|
+
function isPlainObject(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const ErrorProto = Object.create(
|
|
12
|
+
{},
|
|
13
|
+
{
|
|
14
|
+
cause: {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
value: void 0,
|
|
17
|
+
writable: true
|
|
18
|
+
},
|
|
19
|
+
code: {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
value: void 0,
|
|
22
|
+
writable: true
|
|
23
|
+
},
|
|
24
|
+
errors: {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
value: void 0,
|
|
27
|
+
writable: true
|
|
28
|
+
},
|
|
29
|
+
message: {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
value: void 0,
|
|
32
|
+
writable: true
|
|
33
|
+
},
|
|
34
|
+
name: {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
value: void 0,
|
|
37
|
+
writable: true
|
|
38
|
+
},
|
|
39
|
+
stack: {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
value: void 0,
|
|
42
|
+
writable: true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
47
|
+
const toJSON = (from) => {
|
|
48
|
+
toJsonWasCalled.add(from);
|
|
49
|
+
const json = from.toJSON();
|
|
50
|
+
toJsonWasCalled.delete(from);
|
|
51
|
+
return json;
|
|
52
|
+
};
|
|
53
|
+
const serializeValue = (value, seen, depth, options) => {
|
|
54
|
+
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
55
|
+
return "[object Buffer]";
|
|
56
|
+
}
|
|
57
|
+
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
58
|
+
return "[object Stream]";
|
|
59
|
+
}
|
|
60
|
+
if (value instanceof Error) {
|
|
61
|
+
if (seen.includes(value)) {
|
|
62
|
+
return "[Circular]";
|
|
63
|
+
}
|
|
64
|
+
depth += 1;
|
|
65
|
+
return _serialize(value, options, seen, depth);
|
|
66
|
+
}
|
|
67
|
+
if (options.useToJSON && typeof value.toJSON === "function") {
|
|
68
|
+
return value.toJSON();
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "object" && value instanceof Date) {
|
|
71
|
+
return value.toISOString();
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === "function") {
|
|
74
|
+
return `[Function: ${value.name || "anonymous"}]`;
|
|
75
|
+
}
|
|
76
|
+
if (isPlainObject(value)) {
|
|
77
|
+
depth += 1;
|
|
78
|
+
if (options.maxDepth && depth >= options.maxDepth) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
const plainObject = {};
|
|
82
|
+
for (const key in value) {
|
|
83
|
+
plainObject[key] = serializeValue(value[key], seen, depth, options);
|
|
84
|
+
}
|
|
85
|
+
return plainObject;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
return value;
|
|
89
|
+
} catch {
|
|
90
|
+
return "[Not Available]";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const _serialize = (error, options, seen, depth) => {
|
|
94
|
+
seen.push(error);
|
|
95
|
+
if (options.maxDepth === 0) {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
if (options.useToJSON && typeof error.toJSON === "function" && !toJsonWasCalled.has(error)) {
|
|
99
|
+
return toJSON(error);
|
|
100
|
+
}
|
|
101
|
+
const protoError = Object.create(ErrorProto);
|
|
102
|
+
protoError.name = Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name;
|
|
103
|
+
protoError.message = error.message;
|
|
104
|
+
protoError.stack = error.stack;
|
|
105
|
+
if (Array.isArray(error.errors)) {
|
|
106
|
+
const aggregateErrors = [];
|
|
107
|
+
for (const aggregateError of error.errors) {
|
|
108
|
+
if (!(aggregateError instanceof Error)) {
|
|
109
|
+
throw new TypeError("All errors in the 'errors' property must be instances of Error");
|
|
110
|
+
}
|
|
111
|
+
if (seen.includes(aggregateError)) {
|
|
112
|
+
protoError.errors = [];
|
|
113
|
+
return protoError;
|
|
114
|
+
}
|
|
115
|
+
aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
|
|
116
|
+
}
|
|
117
|
+
protoError.errors = aggregateErrors;
|
|
118
|
+
}
|
|
119
|
+
if (error.cause instanceof Error && !seen.includes(error.cause)) {
|
|
120
|
+
protoError.cause = _serialize(error.cause, options, seen, depth);
|
|
121
|
+
}
|
|
122
|
+
for (const key in error) {
|
|
123
|
+
if (protoError[key] === void 0) {
|
|
124
|
+
const value = error[key];
|
|
125
|
+
protoError[key] = serializeValue(value, seen, depth, options);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(options.exclude) && options.exclude.length > 0) {
|
|
129
|
+
for (const key of options.exclude) {
|
|
130
|
+
try {
|
|
131
|
+
delete protoError[key];
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return protoError;
|
|
137
|
+
};
|
|
138
|
+
const serialize = (error, options = {}) => _serialize(
|
|
139
|
+
error,
|
|
140
|
+
{
|
|
141
|
+
exclude: options.exclude ?? [],
|
|
142
|
+
maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
|
|
143
|
+
useToJSON: options.useToJSON ?? false
|
|
144
|
+
},
|
|
145
|
+
[],
|
|
146
|
+
0
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
class AbstractJsonReporter {
|
|
150
|
+
/** Custom stringify function for object serialization */
|
|
151
|
+
stringify;
|
|
152
|
+
/** Error serialization options */
|
|
153
|
+
errorOptions;
|
|
154
|
+
/**
|
|
155
|
+
* Creates a new AbstractJsonReporter instance.
|
|
156
|
+
* @param options Configuration options for JSON formatting and error handling
|
|
157
|
+
*/
|
|
158
|
+
constructor(options = {}) {
|
|
159
|
+
this.errorOptions = options.error ?? {};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets a custom stringify function for object serialization.
|
|
163
|
+
* @param function_ The stringify function to use for serialization
|
|
164
|
+
*/
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
166
|
+
setStringify(function_) {
|
|
167
|
+
this.stringify = function_;
|
|
168
|
+
}
|
|
169
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
170
|
+
log(meta) {
|
|
171
|
+
const { context, error, file, message, type, ...rest } = meta;
|
|
172
|
+
if (rest.label) {
|
|
173
|
+
rest.label = rest.label.trim();
|
|
174
|
+
}
|
|
175
|
+
if (file) {
|
|
176
|
+
rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
|
|
177
|
+
}
|
|
178
|
+
if (message === EMPTY_SYMBOL) {
|
|
179
|
+
rest.message = void 0;
|
|
180
|
+
} else {
|
|
181
|
+
rest.message = message;
|
|
182
|
+
}
|
|
183
|
+
if (error) {
|
|
184
|
+
rest.error = serialize(error, this.errorOptions);
|
|
185
|
+
}
|
|
186
|
+
if (context) {
|
|
187
|
+
const newContext = [];
|
|
188
|
+
for (const item of context) {
|
|
189
|
+
if (item === EMPTY_SYMBOL) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (item instanceof Error) {
|
|
193
|
+
newContext.push(serialize(item, this.errorOptions));
|
|
194
|
+
} else {
|
|
195
|
+
newContext.push(item);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
rest.context = newContext;
|
|
199
|
+
}
|
|
200
|
+
this._log(this.stringify(rest), type.level);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { AbstractJsonReporter };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { t as terminalSize, w as wordWrap, W as WrapMode } from './index-DqKWykfa.js';
|
|
2
|
+
|
|
3
|
+
class InteractiveManager {
|
|
4
|
+
#stream;
|
|
5
|
+
#isActive = false;
|
|
6
|
+
#isSuspended = false;
|
|
7
|
+
#lastLength = 0;
|
|
8
|
+
#outside = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new InteractiveManager with the given stream hooks.
|
|
11
|
+
* @param stdout Hook for stdout stream
|
|
12
|
+
* @param stderr Hook for stderr stream
|
|
13
|
+
*/
|
|
14
|
+
constructor(stdout, stderr) {
|
|
15
|
+
this.#stream = {
|
|
16
|
+
stderr,
|
|
17
|
+
stdout
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Last printed rows count.
|
|
22
|
+
*
|
|
23
|
+
* Tracks the number of rows that were last written to the terminal.
|
|
24
|
+
* Used internally for managing cursor positioning and output updates.
|
|
25
|
+
*/
|
|
26
|
+
get lastLength() {
|
|
27
|
+
return this.#lastLength;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Rows count outside editable area.
|
|
31
|
+
*
|
|
32
|
+
* Tracks the number of rows that extend beyond the current terminal height.
|
|
33
|
+
* Used for managing scrolling and ensuring all output remains visible.
|
|
34
|
+
*/
|
|
35
|
+
get outside() {
|
|
36
|
+
return this.#outside;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook activity status.
|
|
40
|
+
*
|
|
41
|
+
* Indicates whether the interactive hooks are currently active.
|
|
42
|
+
* When true, streams are being intercepted for interactive output.
|
|
43
|
+
*/
|
|
44
|
+
get isHooked() {
|
|
45
|
+
return this.#isActive;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Suspend status for active hooks.
|
|
49
|
+
*
|
|
50
|
+
* Indicates whether interactive mode is temporarily suspended.
|
|
51
|
+
* When suspended, external output can be written without interference.
|
|
52
|
+
*/
|
|
53
|
+
get isSuspended() {
|
|
54
|
+
return this.#isSuspended;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Removes lines from the terminal output.
|
|
58
|
+
*
|
|
59
|
+
* Erases the specified number of lines from the bottom of the output,
|
|
60
|
+
* moving the cursor up and clearing the lines. Useful for removing
|
|
61
|
+
* previous interactive output before displaying new content.
|
|
62
|
+
* @param stream The stream to erase lines from ("stdout" or "stderr")
|
|
63
|
+
* @param count Number of lines to remove (defaults to lastLength)
|
|
64
|
+
* @throws {TypeError} If the specified stream is not available
|
|
65
|
+
*/
|
|
66
|
+
erase(stream, count = this.#lastLength) {
|
|
67
|
+
if (this.#stream[stream] === void 0) {
|
|
68
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
69
|
+
}
|
|
70
|
+
this.#stream[stream].erase(count);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Hook stdout and stderr streams.
|
|
74
|
+
* @returns Success status
|
|
75
|
+
*/
|
|
76
|
+
hook() {
|
|
77
|
+
if (!this.#isActive) {
|
|
78
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
79
|
+
this.#clear(true);
|
|
80
|
+
}
|
|
81
|
+
return this.#isActive;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resume suspend hooks.
|
|
85
|
+
* @param stream Stream to resume
|
|
86
|
+
* @param eraseRowCount erase output rows count
|
|
87
|
+
*/
|
|
88
|
+
resume(stream, eraseRowCount) {
|
|
89
|
+
if (this.#isSuspended) {
|
|
90
|
+
this.#isSuspended = false;
|
|
91
|
+
if (eraseRowCount) {
|
|
92
|
+
this.erase(stream, eraseRowCount);
|
|
93
|
+
}
|
|
94
|
+
this.#lastLength = 0;
|
|
95
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Suspend active hooks for external output.
|
|
100
|
+
* @param stream Stream to suspend
|
|
101
|
+
* @param erase erase output
|
|
102
|
+
*/
|
|
103
|
+
suspend(stream, erase = true) {
|
|
104
|
+
if (!this.#isSuspended) {
|
|
105
|
+
this.#isSuspended = true;
|
|
106
|
+
if (erase) {
|
|
107
|
+
this.erase(stream);
|
|
108
|
+
}
|
|
109
|
+
Object.values(this.#stream).forEach((hook) => hook.renew());
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Unhooks both stdout and stderr streams and print their story of logs.
|
|
114
|
+
* @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
115
|
+
* @returns Success status
|
|
116
|
+
*/
|
|
117
|
+
unhook(separateHistory = true) {
|
|
118
|
+
if (this.#isActive) {
|
|
119
|
+
Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));
|
|
120
|
+
this.#clear();
|
|
121
|
+
}
|
|
122
|
+
return !this.#isActive;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Update output.
|
|
126
|
+
* @param stream Stream to write to
|
|
127
|
+
* @param rows Text lines to write to standard output
|
|
128
|
+
* @param from Index of the line starting from which the contents of the terminal are being overwritten
|
|
129
|
+
*/
|
|
130
|
+
update(stream, rows, from = 0) {
|
|
131
|
+
if (rows.length > 0) {
|
|
132
|
+
if (this.#stream[stream] === void 0) {
|
|
133
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
134
|
+
}
|
|
135
|
+
const hook = this.#stream[stream];
|
|
136
|
+
const { columns: width, rows: height } = terminalSize();
|
|
137
|
+
const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));
|
|
138
|
+
const actualLength = this.lastLength - position;
|
|
139
|
+
const outside = Math.max(actualLength - height, this.outside);
|
|
140
|
+
let output = rows.reduce(
|
|
141
|
+
(accumulator, row) => [
|
|
142
|
+
...accumulator,
|
|
143
|
+
wordWrap(row, {
|
|
144
|
+
trim: false,
|
|
145
|
+
width,
|
|
146
|
+
wrapMode: WrapMode.STRICT_WIDTH
|
|
147
|
+
})
|
|
148
|
+
],
|
|
149
|
+
[]
|
|
150
|
+
);
|
|
151
|
+
if (height <= actualLength) {
|
|
152
|
+
hook.erase(height);
|
|
153
|
+
if (position < outside) {
|
|
154
|
+
output = output.slice(outside - position + 1);
|
|
155
|
+
}
|
|
156
|
+
} else if (actualLength) {
|
|
157
|
+
hook.erase(actualLength);
|
|
158
|
+
}
|
|
159
|
+
hook.write(`${output.join("\n")}
|
|
160
|
+
`);
|
|
161
|
+
this.#lastLength = outside ? outside + output.length + 1 : output.length;
|
|
162
|
+
this.#outside = Math.max(this.lastLength - height, this.outside);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
#clear(status = false) {
|
|
166
|
+
this.#isActive = status;
|
|
167
|
+
this.#lastLength = 0;
|
|
168
|
+
this.#outside = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { InteractiveManager as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export { I as default } from './interactive-stream-hook-DG4BtN12.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
stdout,
|
|
9
|
+
stderr
|
|
10
|
+
} = __cjs_getProcess;
|
|
11
|
+
import { w as writeStream } from './write-stream-BG8fhcs3.js';
|
|
12
|
+
import { AbstractJsonReporter } from './AbstractJsonReporter-intFdT_A.js';
|
|
13
|
+
|
|
14
|
+
class JsonReporter extends AbstractJsonReporter {
|
|
15
|
+
/** Standard output stream */
|
|
16
|
+
#stdout;
|
|
17
|
+
/** Standard error stream */
|
|
18
|
+
#stderr;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Server JSON Reporter instance.
|
|
21
|
+
* @param options Configuration options for JSON formatting
|
|
22
|
+
*/
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
super(options);
|
|
25
|
+
this.#stdout = stdout;
|
|
26
|
+
this.#stderr = stderr;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sets the stdout stream for the reporter.
|
|
30
|
+
* @param stdout_ The writable stream to use for stdout output
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
33
|
+
setStdout(stdout_) {
|
|
34
|
+
this.#stdout = stdout_;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sets the stderr stream for the reporter.
|
|
38
|
+
* @param stderr_ The writable stream to use for stderr output
|
|
39
|
+
*/
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
41
|
+
setStderr(stderr_) {
|
|
42
|
+
this.#stderr = stderr_;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Outputs the JSON message to the appropriate stream.
|
|
46
|
+
*
|
|
47
|
+
* Routes error and warning level messages to stderr, others to stdout.
|
|
48
|
+
* @param message The JSON-formatted log message
|
|
49
|
+
* @param logLevel The log level determining which stream to use
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
53
|
+
_log(message, logLevel) {
|
|
54
|
+
const stream = ["error", "warn"].includes(logLevel) ? this.#stderr : this.#stdout;
|
|
55
|
+
writeStream(`${message}
|
|
56
|
+
`, stream);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { JsonReporter as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AbstractJsonReporter } from './AbstractJsonReporter-intFdT_A.js';
|
|
2
|
+
import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-DBmRYXpj.js';
|
|
3
|
+
|
|
4
|
+
class JsonReporter extends AbstractJsonReporter {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new Browser JSON Reporter instance.
|
|
7
|
+
* @param options Configuration options for JSON formatting
|
|
8
|
+
*/
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
super(options);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Outputs the JSON message to the browser console.
|
|
14
|
+
*
|
|
15
|
+
* Uses the appropriate console method based on the log level
|
|
16
|
+
* (console.log, console.error, console.warn, etc.).
|
|
17
|
+
* @param message The JSON-formatted log message
|
|
18
|
+
* @param logLevel The log level determining which console method to use
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line class-methods-use-this, no-underscore-dangle
|
|
22
|
+
_log(message, logLevel) {
|
|
23
|
+
const consoleLogFunction = writeConsoleLogBasedOnLevel(logLevel);
|
|
24
|
+
consoleLogFunction(message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { JsonReporter as default };
|