limina 0.1.1 → 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/chunks/{dep-C5gcXDHp.js → dep-DJz9JBTi.js} +119 -10
- package/chunks/dep-mnWOqiGN.js +244 -0
- package/cli.js +1488 -386
- package/flow-renderer-process.js +23 -31
- package/index.js +1 -1
- package/package.json +1 -1
- package/schemas/tsconfig-schema.json +23 -0
- package/chunks/dep-CuMHuWBQ.js +0 -87
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
3
|
import ts from "typescript";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
|
|
@@ -507,10 +507,17 @@ function toRelativePath(rootDir, absolutePath) {
|
|
|
507
507
|
function normalizeSlashes(value) {
|
|
508
508
|
return value.replaceAll("\\", "/");
|
|
509
509
|
}
|
|
510
|
+
function normalizeAbsolutePathIdentity(value) {
|
|
511
|
+
const normalizedPath = normalize(value);
|
|
512
|
+
return normalizedPath.length > 1 && !/^[A-Za-z]:\/$/u.test(normalizedPath) ? normalizedPath.replace(/\/+$/u, "") : normalizedPath;
|
|
513
|
+
}
|
|
510
514
|
function isPathInsideDirectory(filePath, directoryPath) {
|
|
511
|
-
const normalizedFilePath =
|
|
512
|
-
const
|
|
513
|
-
return
|
|
515
|
+
const normalizedFilePath = normalizeComparableAbsolutePath(filePath);
|
|
516
|
+
const relativePath = relative(normalizeComparableAbsolutePath(directoryPath), normalizedFilePath);
|
|
517
|
+
return relativePath.length === 0 || relativePath !== ".." && !relativePath.startsWith("../") && !isAbsolute(relativePath);
|
|
518
|
+
}
|
|
519
|
+
function normalizeComparableAbsolutePath(value) {
|
|
520
|
+
return normalizeAbsolutePathIdentity(isAbsolute(value) ? value : resolve(value));
|
|
514
521
|
}
|
|
515
522
|
|
|
516
523
|
//#endregion
|
|
@@ -798,9 +805,109 @@ function resolveVueProjectExtensionsForChecker(options, packageName) {
|
|
|
798
805
|
return normalizeExtensions([...options.extensions ?? [], ...resolveVueProjectExtensions(options, packageName)]);
|
|
799
806
|
}
|
|
800
807
|
function resolveTypeScriptModuleName(options) {
|
|
808
|
+
return resolveTypeScriptModuleNameDetailed(options)?.resolvedFileName ?? null;
|
|
809
|
+
}
|
|
810
|
+
function resolveTypeScriptModuleNameDetailed(options) {
|
|
801
811
|
const resolved = ts.resolveModuleName(options.specifier, options.containingFile, options.compilerOptions, ts.sys).resolvedModule;
|
|
802
|
-
if (resolved?.resolvedFileName) return
|
|
803
|
-
|
|
812
|
+
if (resolved?.resolvedFileName) return {
|
|
813
|
+
isExternalLibraryImport: resolved.isExternalLibraryImport === true,
|
|
814
|
+
resolvedBy: "typescript",
|
|
815
|
+
resolvedFileName: normalizeAbsolutePath(resolved.resolvedFileName)
|
|
816
|
+
};
|
|
817
|
+
return resolveCheckerExtensionModuleName(options);
|
|
818
|
+
}
|
|
819
|
+
function resolveCheckerExtensionModuleName(options) {
|
|
820
|
+
const typeScriptExtensions = new Set(getTypeScriptCheckerExtensions());
|
|
821
|
+
const checkerOnlyExtensions = options.extensions.filter((extension) => !typeScriptExtensions.has(extension));
|
|
822
|
+
if (checkerOnlyExtensions.length === 0) return null;
|
|
823
|
+
const resolvedFileName = resolveRelativeModuleCandidate({
|
|
824
|
+
containingFile: options.containingFile,
|
|
825
|
+
extensions: checkerOnlyExtensions,
|
|
826
|
+
specifier: options.specifier
|
|
827
|
+
}) ?? resolvePathMappedModuleCandidate({
|
|
828
|
+
compilerOptions: options.compilerOptions,
|
|
829
|
+
extensions: checkerOnlyExtensions,
|
|
830
|
+
specifier: options.specifier
|
|
831
|
+
}) ?? resolvePackageExportModuleCandidate({
|
|
832
|
+
containingFile: options.containingFile,
|
|
833
|
+
extensions: checkerOnlyExtensions,
|
|
834
|
+
specifier: options.specifier
|
|
835
|
+
});
|
|
836
|
+
return resolvedFileName ? {
|
|
837
|
+
isExternalLibraryImport: false,
|
|
838
|
+
resolvedBy: "checker-extension",
|
|
839
|
+
resolvedFileName
|
|
840
|
+
} : null;
|
|
841
|
+
}
|
|
842
|
+
function resolvePackageExportModuleCandidate(options) {
|
|
843
|
+
const specifierParts = parsePackageSpecifier(options.specifier);
|
|
844
|
+
if (!specifierParts) return null;
|
|
845
|
+
const packageDirectory = findPackageDirectoryForImport({
|
|
846
|
+
containingFile: options.containingFile,
|
|
847
|
+
packageName: specifierParts.packageName
|
|
848
|
+
});
|
|
849
|
+
if (!packageDirectory) return null;
|
|
850
|
+
const targets = collectExportTargetsForSubpath(readPackageManifest(packageDirectory)?.exports, specifierParts.subpath);
|
|
851
|
+
for (const target of targets) {
|
|
852
|
+
if (!target.startsWith("./")) continue;
|
|
853
|
+
const targetPath = posix.resolve(packageDirectory, target.slice(2));
|
|
854
|
+
for (const candidatePath of candidatePathsForBasePath(targetPath, options.extensions)) {
|
|
855
|
+
const resolvedPath = resolveExistingFilePath(candidatePath);
|
|
856
|
+
if (resolvedPath) return resolvedPath;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return null;
|
|
860
|
+
}
|
|
861
|
+
function parsePackageSpecifier(specifier) {
|
|
862
|
+
if (specifier.length === 0 || specifier.startsWith(".") || specifier.startsWith("/")) return null;
|
|
863
|
+
const parts = specifier.split("/");
|
|
864
|
+
if (specifier.startsWith("@")) {
|
|
865
|
+
const scope = parts[0];
|
|
866
|
+
const name = parts[1];
|
|
867
|
+
if (!scope || !name) return null;
|
|
868
|
+
return {
|
|
869
|
+
packageName: `${scope}/${name}`,
|
|
870
|
+
subpath: parts.length > 2 ? `./${parts.slice(2).join("/")}` : "."
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
const packageName = parts[0];
|
|
874
|
+
return packageName ? {
|
|
875
|
+
packageName,
|
|
876
|
+
subpath: parts.length > 1 ? `./${parts.slice(1).join("/")}` : "."
|
|
877
|
+
} : null;
|
|
878
|
+
}
|
|
879
|
+
function findPackageDirectoryForImport(options) {
|
|
880
|
+
let currentDir = posix.dirname(options.containingFile);
|
|
881
|
+
for (;;) {
|
|
882
|
+
const packageDirectory = posix.join(currentDir, "node_modules", options.packageName);
|
|
883
|
+
if (existsSync(posix.join(packageDirectory, "package.json"))) return packageDirectory;
|
|
884
|
+
const parentDir = posix.dirname(currentDir);
|
|
885
|
+
if (parentDir === currentDir) return null;
|
|
886
|
+
currentDir = parentDir;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
function readPackageManifest(packageDirectory) {
|
|
890
|
+
try {
|
|
891
|
+
return JSON.parse(readFileSync(posix.join(packageDirectory, "package.json"), "utf8"));
|
|
892
|
+
} catch {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function isRecord(value) {
|
|
897
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
898
|
+
}
|
|
899
|
+
function collectStringTargets(value) {
|
|
900
|
+
if (typeof value === "string") return [value];
|
|
901
|
+
if (Array.isArray(value)) return value.flatMap(collectStringTargets);
|
|
902
|
+
if (isRecord(value)) return Object.values(value).flatMap(collectStringTargets);
|
|
903
|
+
return [];
|
|
904
|
+
}
|
|
905
|
+
function collectExportTargetsForSubpath(exportsField, subpath) {
|
|
906
|
+
if (exportsField === void 0) return subpath === "." ? ["./index"] : [subpath];
|
|
907
|
+
if (typeof exportsField === "string" || Array.isArray(exportsField)) return subpath === "." ? collectStringTargets(exportsField) : [];
|
|
908
|
+
if (!isRecord(exportsField)) return [];
|
|
909
|
+
if (!Object.keys(exportsField).some((key) => key === "." || key.startsWith("./"))) return subpath === "." ? collectStringTargets(exportsField) : [];
|
|
910
|
+
return collectStringTargets(exportsField[subpath]);
|
|
804
911
|
}
|
|
805
912
|
function mergeParsedProjectConfigs(parsedConfigs, extensions) {
|
|
806
913
|
const firstConfig = parsedConfigs[0];
|
|
@@ -834,11 +941,13 @@ function parseCheckerProjectConfigForContext(options) {
|
|
|
834
941
|
return cloneParsedCheckerProjectConfig(parsedConfig);
|
|
835
942
|
}
|
|
836
943
|
function resolveModuleNameWithCheckers(options) {
|
|
944
|
+
return resolveModuleNameWithCheckersDetailed(options)?.resolvedFileName ?? null;
|
|
945
|
+
}
|
|
946
|
+
function resolveModuleNameWithCheckersDetailed(options) {
|
|
837
947
|
const checkerPresets = options.context.checkerPresets.length > 0 ? options.context.checkerPresets : ["tsc"];
|
|
838
948
|
for (const preset of checkerPresets) {
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
const resolved = adapter.resolveModuleName({
|
|
949
|
+
if (!getCheckerAdapter(preset)) continue;
|
|
950
|
+
const resolved = resolveTypeScriptModuleNameDetailed({
|
|
842
951
|
compilerOptions: options.compilerOptions,
|
|
843
952
|
containingFile: options.containingFile,
|
|
844
953
|
extensions: options.context.extensions,
|
|
@@ -4122,4 +4231,4 @@ async function loadConfig(options = {}) {
|
|
|
4122
4231
|
}
|
|
4123
4232
|
|
|
4124
4233
|
//#endregion
|
|
4125
|
-
export {
|
|
4234
|
+
export { isPackageImportSpecifier as A, resolveRelativeModuleCandidate as C, toPosixPath as D, normalizeSlashes as E, uniqueBy as F, uniqueSortedStrings as I, uniqueTrimmedNonEmptySortedStrings as L, isUrlOrDataOrFileSpecifier as M, isVirtualModuleSpecifier as N, toRelativePath as O, posix as P, uniqueValues as R, resolvePathMappedModuleCandidate as S, normalizeAbsolutePath as T, resolveModuleNameWithCheckers as _, formatUnknownValue as a, resolveBaseUrlModuleCandidate as b, clearCheckerProjectConfigCache as c, getBuildCheckerSupportedExtensions as d, getCheckerAdapter as f, resolveCheckerProjectExtensions as g, parseCheckerProjectConfigForContext as h, loadConfig as i, isRelativeSpecifier as j, isBarePackageSpecifier as k, collectMissingCheckerPeerDependencies as l, normalizeExtensions as m, getActiveCheckers as n, isNonEmptyString as o, getCheckerExtensions as p, isAutoCheckerConfigMode as r, isPlainRecord as s, defineConfig as t, formatMissingCheckerPeerDependencies as u, resolveModuleNameWithCheckersDetailed as v, isPathInsideDirectory as w, resolveExistingFilePath as x, candidatePathsForBasePath as y };
|
|
@@ -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 };
|