limina 0.0.6 → 0.1.2
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/LICENSE.md +105 -30
- package/README.md +18 -11
- package/README.zh-CN.md +17 -10
- package/bin/limina.js +2 -1
- package/chunks/{dep-Ce6cDHmw.js → dep-DJz9JBTi.js} +649 -1316
- package/chunks/dep-mnWOqiGN.js +244 -0
- package/cli.js +34575 -7481
- package/flow-renderer-process.js +101 -0
- package/index.d.ts +680 -163
- package/index.js +2 -3
- package/package.json +11 -12
- package/schemas/tsconfig-schema.json +54 -0
- package/chunks/dep-COZNKoxO.js +0 -15582
- package/config.d.ts +0 -683
- package/config.js +0 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
//#region src/flow/render-model.ts
|
|
2
|
+
const ANSI_RESET = "\x1B[0m";
|
|
3
|
+
const ANSI_GREEN = "\x1B[32m";
|
|
4
|
+
const ANSI_RED = "\x1B[31m";
|
|
5
|
+
const ANSI_YELLOW = "\x1B[33m";
|
|
6
|
+
const DEFAULT_TERMINAL_COLUMNS$1 = 80;
|
|
7
|
+
const TERMINAL_FRAME_MARGIN_LINES = 1;
|
|
8
|
+
const TERMINAL_FRAME_CONTEXT_LINES = 6;
|
|
9
|
+
const OMITTED_LINES_MARKER = "│ ...";
|
|
10
|
+
const ANSI_ESCAPE = String.fromCodePoint(27);
|
|
11
|
+
const ANSI_PATTERN = new RegExp(String.raw`${ANSI_ESCAPE}\[[\d:;<=>?]*[\u0020-\u002F]*[\u0040-\u007E]`, "gu");
|
|
12
|
+
const SPINNER_FRAMES = [
|
|
13
|
+
"⠋",
|
|
14
|
+
"⠙",
|
|
15
|
+
"⠹",
|
|
16
|
+
"⠸",
|
|
17
|
+
"⠼",
|
|
18
|
+
"⠴",
|
|
19
|
+
"⠦",
|
|
20
|
+
"⠧",
|
|
21
|
+
"⠇",
|
|
22
|
+
"⠏"
|
|
23
|
+
];
|
|
24
|
+
const SPINNER_INTERVAL_MS = 80;
|
|
25
|
+
const FLOW_SYMBOL_BY_STATUS = {
|
|
26
|
+
fail: "✕",
|
|
27
|
+
info: "│",
|
|
28
|
+
pass: "◆",
|
|
29
|
+
planned: "◇",
|
|
30
|
+
skip: "◇",
|
|
31
|
+
start: "◇",
|
|
32
|
+
warn: "▲"
|
|
33
|
+
};
|
|
34
|
+
function colorInteractiveSymbol(status, symbol) {
|
|
35
|
+
if (status === "pass") return `${ANSI_GREEN}${symbol}${ANSI_RESET}`;
|
|
36
|
+
if (status === "fail") return `${ANSI_RED}${symbol}${ANSI_RESET}`;
|
|
37
|
+
if (status === "warn") return `${ANSI_YELLOW}${symbol}${ANSI_RESET}`;
|
|
38
|
+
return symbol;
|
|
39
|
+
}
|
|
40
|
+
function formatElapsedTime(milliseconds) {
|
|
41
|
+
if (milliseconds < 1e3) return `${Math.round(milliseconds)}ms`;
|
|
42
|
+
return `${(milliseconds / 1e3).toFixed(2)}s`;
|
|
43
|
+
}
|
|
44
|
+
function formatMessageWithElapsed(message, elapsedTimeMs) {
|
|
45
|
+
return typeof elapsedTimeMs === "number" ? `${message} (${formatElapsedTime(elapsedTimeMs)})` : message;
|
|
46
|
+
}
|
|
47
|
+
function indentMessage(message, depth) {
|
|
48
|
+
if (depth <= 0) return message;
|
|
49
|
+
return `${" ".repeat(depth)}${message}`;
|
|
50
|
+
}
|
|
51
|
+
function formatInteractiveLine(status, message, depth, spinnerFrameIndex) {
|
|
52
|
+
const renderedMessage = indentMessage(message, depth);
|
|
53
|
+
return `${colorInteractiveSymbol(status, status === "start" ? SPINNER_FRAMES[spinnerFrameIndex % SPINNER_FRAMES.length] : FLOW_SYMBOL_BY_STATUS[status])} ${renderedMessage}`;
|
|
54
|
+
}
|
|
55
|
+
function toTreeFlowStatus(status) {
|
|
56
|
+
switch (status) {
|
|
57
|
+
case "failed": return "fail";
|
|
58
|
+
case "passed": return "pass";
|
|
59
|
+
case "planned": return "planned";
|
|
60
|
+
case "running": return "start";
|
|
61
|
+
case "skipped": return "skip";
|
|
62
|
+
}
|
|
63
|
+
throw new Error(`Unsupported flow tree node status: ${status}`);
|
|
64
|
+
}
|
|
65
|
+
function isTreeNodeTerminal(node) {
|
|
66
|
+
return node.status === "failed" || node.status === "passed" || node.status === "skipped";
|
|
67
|
+
}
|
|
68
|
+
function areTreeNodeDescendantsTerminal(node) {
|
|
69
|
+
return node.children.every((child) => isTreeNodeTerminal(child) && areTreeNodeDescendantsTerminal(child));
|
|
70
|
+
}
|
|
71
|
+
function renderTreeNodeLine(node, spinnerFrameIndex) {
|
|
72
|
+
const elapsedTimeMs = isTreeNodeTerminal(node) && areTreeNodeDescendantsTerminal(node) ? node.elapsedTimeMs : void 0;
|
|
73
|
+
return formatInteractiveLine(toTreeFlowStatus(node.status), formatMessageWithElapsed(node.message, elapsedTimeMs), node.depth, spinnerFrameIndex);
|
|
74
|
+
}
|
|
75
|
+
function renderTreeNodeLines(node, spinnerFrameIndex) {
|
|
76
|
+
return [renderTreeNodeLine(node, spinnerFrameIndex), ...node.children.flatMap((child) => renderTreeNodeLines(child, spinnerFrameIndex))];
|
|
77
|
+
}
|
|
78
|
+
function renderCompactTreeNodeLines(node, spinnerFrameIndex) {
|
|
79
|
+
return [renderTreeNodeLine(node, spinnerFrameIndex), ...node.children.map((child) => renderTreeNodeLine(child, spinnerFrameIndex))];
|
|
80
|
+
}
|
|
81
|
+
function renderSnapshotLines(snapshot, spinnerFrameIndex) {
|
|
82
|
+
const lines = snapshot.entries.flatMap((entry) => {
|
|
83
|
+
if (entry.kind === "line") return [entry.line];
|
|
84
|
+
if (entry.kind === "flow-line") return [formatInteractiveLine(entry.status, formatMessageWithElapsed(entry.message, entry.elapsedTimeMs), entry.depth, spinnerFrameIndex)];
|
|
85
|
+
return snapshot.treeRoots.flatMap((root) => renderTreeNodeLines(root, spinnerFrameIndex));
|
|
86
|
+
});
|
|
87
|
+
return snapshot.outroMessage ? [...lines, `└ ${snapshot.outroMessage}`] : lines;
|
|
88
|
+
}
|
|
89
|
+
function renderCompactSnapshotLines(snapshot, spinnerFrameIndex) {
|
|
90
|
+
const flowLineDepths = snapshot.entries.filter((entry) => entry.kind === "flow-line").map((entry) => entry.depth);
|
|
91
|
+
const maxCompactFlowLineDepth = flowLineDepths.length > 0 ? Math.min(...flowLineDepths) + 1 : Number.POSITIVE_INFINITY;
|
|
92
|
+
const lines = snapshot.entries.flatMap((entry) => {
|
|
93
|
+
if (entry.kind === "line") return [entry.line];
|
|
94
|
+
if (entry.kind === "flow-line") {
|
|
95
|
+
if (entry.depth > maxCompactFlowLineDepth) return [];
|
|
96
|
+
return [formatInteractiveLine(entry.status, formatMessageWithElapsed(entry.message, entry.elapsedTimeMs), entry.depth, spinnerFrameIndex)];
|
|
97
|
+
}
|
|
98
|
+
return snapshot.treeRoots.flatMap((root) => renderCompactTreeNodeLines(root, spinnerFrameIndex));
|
|
99
|
+
});
|
|
100
|
+
return snapshot.outroMessage ? [...lines, `└ ${snapshot.outroMessage}`] : lines;
|
|
101
|
+
}
|
|
102
|
+
function stripControlSequences(text) {
|
|
103
|
+
return text.replaceAll(ANSI_PATTERN, "").replaceAll("\r", "");
|
|
104
|
+
}
|
|
105
|
+
function countRenderedTerminalRows(line, columns) {
|
|
106
|
+
const text = stripControlSequences(line);
|
|
107
|
+
let column = 0;
|
|
108
|
+
let rows = 1;
|
|
109
|
+
for (const char of text) {
|
|
110
|
+
if (char === "\n") {
|
|
111
|
+
rows += 1;
|
|
112
|
+
column = 0;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
column += 1;
|
|
116
|
+
if (column >= columns) {
|
|
117
|
+
rows += 1;
|
|
118
|
+
column = 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return rows;
|
|
122
|
+
}
|
|
123
|
+
function countRenderedRows(lines, dimensions) {
|
|
124
|
+
const columns = Math.max(1, dimensions.columns ?? DEFAULT_TERMINAL_COLUMNS$1);
|
|
125
|
+
return lines.reduce((sum, line) => sum + countRenderedTerminalRows(line, columns), 0);
|
|
126
|
+
}
|
|
127
|
+
function fitsRenderedLines(lines, dimensions, options = {}) {
|
|
128
|
+
if (dimensions.rows === void 0) return true;
|
|
129
|
+
const contextLines = options.reserveContext && dimensions.rows > TERMINAL_FRAME_CONTEXT_LINES * 2 ? TERMINAL_FRAME_CONTEXT_LINES : 0;
|
|
130
|
+
const lineLimit = Math.max(1, dimensions.rows - TERMINAL_FRAME_MARGIN_LINES - contextLines);
|
|
131
|
+
return countRenderedRows(lines, dimensions) <= lineLimit;
|
|
132
|
+
}
|
|
133
|
+
function fitRenderedLinesToTerminal(lines, dimensions, options = {}) {
|
|
134
|
+
if (fitsRenderedLines(lines, dimensions) && !options.omittedLines) return lines;
|
|
135
|
+
if (dimensions.rows === void 0) return options.omittedLines ? addOmittedLinesMarker(lines) : lines;
|
|
136
|
+
const lineLimit = Math.max(1, dimensions.rows - TERMINAL_FRAME_MARGIN_LINES);
|
|
137
|
+
const columns = Math.max(1, dimensions.columns ?? DEFAULT_TERMINAL_COLUMNS$1);
|
|
138
|
+
const lastLine = lines.at(-1);
|
|
139
|
+
const shouldPreserveOutro = lastLine?.startsWith("└ ") ?? false;
|
|
140
|
+
const bodyLineCount = lines.length - (shouldPreserveOutro ? 1 : 0);
|
|
141
|
+
const bodyLines = lines.slice(0, bodyLineCount);
|
|
142
|
+
const ellipsisRows = countRenderedTerminalRows(OMITTED_LINES_MARKER, columns);
|
|
143
|
+
const reservedRows = shouldPreserveOutro && lastLine ? countRenderedTerminalRows(lastLine, columns) : 0;
|
|
144
|
+
const availableBodyRows = Math.max(0, lineLimit - reservedRows);
|
|
145
|
+
const bodyRows = countRenderedRows(bodyLines, { columns });
|
|
146
|
+
const shouldShowOmissionMarker = (options.omittedLines === true || bodyRows > availableBodyRows) && availableBodyRows >= ellipsisRows;
|
|
147
|
+
const fittedLines = [];
|
|
148
|
+
let remainingRows = availableBodyRows;
|
|
149
|
+
if (shouldShowOmissionMarker) remainingRows -= ellipsisRows;
|
|
150
|
+
for (let index = 0; index < bodyLineCount && remainingRows > 0; index++) {
|
|
151
|
+
const line = lines[index];
|
|
152
|
+
const rowCount = countRenderedTerminalRows(line, columns);
|
|
153
|
+
if (rowCount > remainingRows) break;
|
|
154
|
+
fittedLines.push(line);
|
|
155
|
+
remainingRows -= rowCount;
|
|
156
|
+
}
|
|
157
|
+
if (shouldShowOmissionMarker) fittedLines.push(OMITTED_LINES_MARKER);
|
|
158
|
+
if (shouldPreserveOutro && lastLine && reservedRows <= lineLimit) fittedLines.push(lastLine);
|
|
159
|
+
if (fittedLines.length > 0) return fittedLines;
|
|
160
|
+
return lines.slice(0, 1);
|
|
161
|
+
}
|
|
162
|
+
function addOmittedLinesMarker(lines) {
|
|
163
|
+
if (lines.includes(OMITTED_LINES_MARKER)) return lines;
|
|
164
|
+
const lastLine = lines.at(-1);
|
|
165
|
+
if (lastLine?.startsWith("└ ")) return [
|
|
166
|
+
...lines.slice(0, -1),
|
|
167
|
+
OMITTED_LINES_MARKER,
|
|
168
|
+
lastLine
|
|
169
|
+
];
|
|
170
|
+
return [...lines, OMITTED_LINES_MARKER];
|
|
171
|
+
}
|
|
172
|
+
function renderSnapshotLinesForTerminal(snapshot, spinnerFrameIndex, dimensions) {
|
|
173
|
+
const shouldPreferCompact = snapshot.compactMode === "check-flow" && snapshot.outroMessage !== void 0;
|
|
174
|
+
const fullLines = renderSnapshotLines(snapshot, spinnerFrameIndex);
|
|
175
|
+
if (!shouldPreferCompact && fitsRenderedLines(fullLines, dimensions, { reserveContext: true })) return fullLines;
|
|
176
|
+
const compactLines = renderCompactSnapshotLines(snapshot, spinnerFrameIndex);
|
|
177
|
+
return fitRenderedLinesToTerminal(compactLines, dimensions, { omittedLines: compactLines.length < fullLines.length });
|
|
178
|
+
}
|
|
179
|
+
function hasRunningSnapshotWork(snapshot) {
|
|
180
|
+
const hasRunningTreeNode = (node) => node.status === "running" || node.children.some(hasRunningTreeNode);
|
|
181
|
+
return snapshot.entries.some((entry) => entry.kind === "flow-line" && entry.status === "start") || snapshot.treeRoots.some(hasRunningTreeNode);
|
|
182
|
+
}
|
|
183
|
+
function toWritableText(chunk) {
|
|
184
|
+
if (chunk instanceof Uint8Array) return Buffer.from(chunk).toString();
|
|
185
|
+
return chunk;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/flow/terminal-frame.ts
|
|
190
|
+
const DEFAULT_TERMINAL_COLUMNS = 80;
|
|
191
|
+
var TerminalFrameTracker = class {
|
|
192
|
+
#column = 0;
|
|
193
|
+
#lineCount = 0;
|
|
194
|
+
#getColumns;
|
|
195
|
+
constructor(getColumns) {
|
|
196
|
+
this.#getColumns = getColumns;
|
|
197
|
+
}
|
|
198
|
+
get lineCount() {
|
|
199
|
+
return this.#lineCount;
|
|
200
|
+
}
|
|
201
|
+
record(chunk) {
|
|
202
|
+
const text = stripControlSequences(toWritableText(chunk));
|
|
203
|
+
const columns = Math.max(1, this.#getColumns());
|
|
204
|
+
for (const char of text) {
|
|
205
|
+
if (char === "\n") {
|
|
206
|
+
this.#lineCount += 1;
|
|
207
|
+
this.#column = 0;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
this.#column += 1;
|
|
211
|
+
if (this.#column >= columns) {
|
|
212
|
+
this.#lineCount += 1;
|
|
213
|
+
this.#column = 0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
reset() {
|
|
218
|
+
this.#lineCount = 0;
|
|
219
|
+
this.#column = 0;
|
|
220
|
+
}
|
|
221
|
+
setLineCount(lineCount) {
|
|
222
|
+
this.#lineCount = Math.max(0, lineCount);
|
|
223
|
+
this.#column = 0;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
function patchWriteStream(stream, onWrite) {
|
|
227
|
+
if (typeof stream?.write !== "function") return;
|
|
228
|
+
const originalWrite = stream.write;
|
|
229
|
+
const patchedWrite = (...args) => {
|
|
230
|
+
onWrite(args[0]);
|
|
231
|
+
return writeWithFlowArgs(originalWrite, args);
|
|
232
|
+
};
|
|
233
|
+
stream.write = patchedWrite;
|
|
234
|
+
return () => {
|
|
235
|
+
stream.write = originalWrite;
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function writeWithFlowArgs(write, args) {
|
|
239
|
+
if (typeof args[1] === "string") return write(args[0], args[1], args[2]);
|
|
240
|
+
return write(args[0], args[1]);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { SPINNER_FRAMES as a, formatMessageWithElapsed as c, toTreeFlowStatus as d, toWritableText as f, writeWithFlowArgs as i, hasRunningSnapshotWork as l, TerminalFrameTracker as n, SPINNER_INTERVAL_MS as o, patchWriteStream as r, formatInteractiveLine as s, DEFAULT_TERMINAL_COLUMNS as t, renderSnapshotLinesForTerminal as u };
|