bivium 0.9.0 → 0.11.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/README.md +10 -6
- package/cli.js +51 -2192
- package/compute.js +4 -3
- package/config.js +3 -2
- package/docs/api.md +3 -0
- package/docs/ci.md +138 -4
- package/docs/cli.md +101 -3
- package/docs/config.md +115 -0
- package/docs/how-it-works.md +129 -0
- package/docs/tuning.md +24 -1
- package/errors.js +2 -1
- package/index.d.ts +62 -0
- package/package.json +1 -1
- package/shared-1erx1bv8.js +26 -0
- package/shared-6n8bazs5.js +103 -0
- package/shared-8kbmg99n.js +164 -0
- package/shared-9e8vfbjs.js +475 -0
- package/shared-9xwazb0f.js +1047 -0
- package/shared-apgq7xbk.js +13 -0
- package/shared-b9dpffxv.js +30 -0
- package/shared-dyz928f5.js +68 -0
- package/shared-graedbt1.js +12 -0
- package/shared-jee85qxj.js +149 -0
- package/shared-jp8yw63q.js +4 -0
- package/shared-k2ahcc61.js +68 -0
- package/shared-mpjk8met.js +320 -0
- package/shared-nyb7n090.js +655 -0
- package/shared-p3qfqmwd.js +40 -0
- package/{shared-550cvwt2.js → shared-qaqjsxsk.js} +42 -5
- package/shared-vaqyv5nn.js +19 -0
- package/{shared-07rt4zr7.js → shared-wxem8d5w.js} +2162 -1363
- package/shared-211m8fjt.js +0 -69
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fanIn2,
|
|
3
|
+
graphReport2,
|
|
4
|
+
formatGraph2
|
|
5
|
+
} from "./shared-8kbmg99n.js";
|
|
6
|
+
import"./shared-qaqjsxsk.js";
|
|
7
|
+
import"./shared-p3qfqmwd.js";
|
|
8
|
+
import"./shared-mpjk8met.js";
|
|
9
|
+
export {
|
|
10
|
+
fanIn2 as fanIn,
|
|
11
|
+
formatGraph2 as formatGraph,
|
|
12
|
+
graphReport2 as graphReport
|
|
13
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
textWidth2,
|
|
3
|
+
MEASURE2
|
|
4
|
+
} from "./shared-mpjk8met.js";
|
|
5
|
+
|
|
6
|
+
// src/human.ts
|
|
7
|
+
function duration(ms) {
|
|
8
|
+
if (ms < 999.5)
|
|
9
|
+
return `${Math.round(ms)} ms`;
|
|
10
|
+
const s = ms / 1000;
|
|
11
|
+
return `${s < 999.5 ? s.toPrecision(3) : Math.round(s)} s`;
|
|
12
|
+
}
|
|
13
|
+
function wrapped(text, first, hang) {
|
|
14
|
+
const lines = [];
|
|
15
|
+
let line = first;
|
|
16
|
+
let empty = true;
|
|
17
|
+
for (const word of text.split(" ")) {
|
|
18
|
+
if (!empty && textWidth2(line) + 1 + textWidth2(word) > MEASURE2) {
|
|
19
|
+
lines.push(line);
|
|
20
|
+
line = hang + word;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
line += empty ? word : ` ${word}`;
|
|
24
|
+
empty = false;
|
|
25
|
+
}
|
|
26
|
+
lines.push(line);
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { duration, wrapped };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PLAIN2,
|
|
3
|
+
createPaint2,
|
|
4
|
+
wantsColor2,
|
|
5
|
+
isDumb2,
|
|
6
|
+
isAgent2,
|
|
7
|
+
UNICODE_GLYPHS2,
|
|
8
|
+
ASCII_GLYPHS2,
|
|
9
|
+
markOf2,
|
|
10
|
+
wantsAscii2,
|
|
11
|
+
hideCursor2,
|
|
12
|
+
showCursor2,
|
|
13
|
+
cursorHidden2,
|
|
14
|
+
MISSING2,
|
|
15
|
+
SEPARATOR2,
|
|
16
|
+
branch2,
|
|
17
|
+
NOTE_INDENT2,
|
|
18
|
+
closingLine2,
|
|
19
|
+
failLine2,
|
|
20
|
+
keyHints2,
|
|
21
|
+
nearest2,
|
|
22
|
+
truncateWords2,
|
|
23
|
+
truncatePath2,
|
|
24
|
+
textWidth2,
|
|
25
|
+
MEASURE2,
|
|
26
|
+
fitTerminal2,
|
|
27
|
+
fitWidth2,
|
|
28
|
+
RULE2,
|
|
29
|
+
aligned2,
|
|
30
|
+
headerRow2,
|
|
31
|
+
plural2,
|
|
32
|
+
SILENT2,
|
|
33
|
+
createProgress2
|
|
34
|
+
} from "./shared-mpjk8met.js";
|
|
35
|
+
export {
|
|
36
|
+
ASCII_GLYPHS2 as ASCII_GLYPHS,
|
|
37
|
+
MEASURE2 as MEASURE,
|
|
38
|
+
MISSING2 as MISSING,
|
|
39
|
+
NOTE_INDENT2 as NOTE_INDENT,
|
|
40
|
+
PLAIN2 as PLAIN,
|
|
41
|
+
RULE2 as RULE,
|
|
42
|
+
SEPARATOR2 as SEPARATOR,
|
|
43
|
+
SILENT2 as SILENT,
|
|
44
|
+
UNICODE_GLYPHS2 as UNICODE_GLYPHS,
|
|
45
|
+
aligned2 as aligned,
|
|
46
|
+
branch2 as branch,
|
|
47
|
+
closingLine2 as closingLine,
|
|
48
|
+
createPaint2 as createPaint,
|
|
49
|
+
createProgress2 as createProgress,
|
|
50
|
+
cursorHidden2 as cursorHidden,
|
|
51
|
+
failLine2 as failLine,
|
|
52
|
+
fitTerminal2 as fitTerminal,
|
|
53
|
+
fitWidth2 as fitWidth,
|
|
54
|
+
headerRow2 as headerRow,
|
|
55
|
+
hideCursor2 as hideCursor,
|
|
56
|
+
isAgent2 as isAgent,
|
|
57
|
+
isDumb2 as isDumb,
|
|
58
|
+
keyHints2 as keyHints,
|
|
59
|
+
markOf2 as markOf,
|
|
60
|
+
nearest2 as nearest,
|
|
61
|
+
plural2 as plural,
|
|
62
|
+
showCursor2 as showCursor,
|
|
63
|
+
textWidth2 as textWidth,
|
|
64
|
+
truncatePath2 as truncatePath,
|
|
65
|
+
truncateWords2 as truncateWords,
|
|
66
|
+
wantsAscii2 as wantsAscii,
|
|
67
|
+
wantsColor2 as wantsColor
|
|
68
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PLAIN2,
|
|
3
|
+
createPaint2,
|
|
4
|
+
wantsColor2,
|
|
5
|
+
isAgent2
|
|
6
|
+
} from "./shared-mpjk8met.js";
|
|
7
|
+
import {
|
|
8
|
+
BiviumError2,
|
|
9
|
+
didYouMean2
|
|
10
|
+
} from "./shared-p3qfqmwd.js";
|
|
11
|
+
|
|
12
|
+
// src/args.ts
|
|
13
|
+
var VALUED = new Set([
|
|
14
|
+
"--config",
|
|
15
|
+
"--cwd",
|
|
16
|
+
"--suite",
|
|
17
|
+
"--base",
|
|
18
|
+
"--format",
|
|
19
|
+
"--max-unknown",
|
|
20
|
+
"--top"
|
|
21
|
+
]);
|
|
22
|
+
var COMMON = ["--config", "--cwd", "--no-cache", "--color", "--no-color"];
|
|
23
|
+
var FLAGS2 = {
|
|
24
|
+
plan: [...COMMON, "--json", "--github", "--list"],
|
|
25
|
+
run: [...COMMON, "--suite"],
|
|
26
|
+
why: [...COMMON, "--base", "--json", "--format", "--all"],
|
|
27
|
+
check: [...COMMON, "--base", "--max-unknown", "--json", "--all"],
|
|
28
|
+
graph: [...COMMON, "--suite", "--top", "--json"]
|
|
29
|
+
};
|
|
30
|
+
var POSITIONAL = {
|
|
31
|
+
plan: 1,
|
|
32
|
+
run: 1,
|
|
33
|
+
why: 2,
|
|
34
|
+
check: 0,
|
|
35
|
+
graph: 0
|
|
36
|
+
};
|
|
37
|
+
function colorAsked(argv) {
|
|
38
|
+
let forced;
|
|
39
|
+
for (const arg of argv) {
|
|
40
|
+
if (arg === "--color" || arg === "--color=true")
|
|
41
|
+
forced = true;
|
|
42
|
+
if (arg === "--no-color" || arg === "--no-color=true")
|
|
43
|
+
forced = false;
|
|
44
|
+
}
|
|
45
|
+
return forced;
|
|
46
|
+
}
|
|
47
|
+
function outFor2(io, argv, startMs) {
|
|
48
|
+
const agent = isAgent2(io.env);
|
|
49
|
+
const forced = colorAsked(argv);
|
|
50
|
+
return {
|
|
51
|
+
io,
|
|
52
|
+
paint: wantsColor2(forced, io.stdout, io.env, agent) ? createPaint2() : PLAIN2,
|
|
53
|
+
errorPaint: wantsColor2(forced, io.stderr, io.env, agent) ? createPaint2() : PLAIN2,
|
|
54
|
+
agent,
|
|
55
|
+
startMs
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var SCHEMA_VERSION = 1;
|
|
59
|
+
function usageError2(code, message) {
|
|
60
|
+
return new BiviumError2(code, message);
|
|
61
|
+
}
|
|
62
|
+
function unknownOption(command, flag) {
|
|
63
|
+
const known = FLAGS2[command] ?? [];
|
|
64
|
+
const others = Object.keys(FLAGS2).filter((other) => other !== command && FLAGS2[other]?.includes(flag));
|
|
65
|
+
const hint = others.length > 0 ? ` (${others.join(" and ")} ${others.length === 1 ? "takes" : "take"} it)` : didYouMean2(flag, known);
|
|
66
|
+
return usageError2("BV_UNKNOWN_OPTION", `bivium ${command}: unknown option ${flag}${hint}`);
|
|
67
|
+
}
|
|
68
|
+
function parseArgs2(command, argv) {
|
|
69
|
+
const known = FLAGS2[command] ?? [];
|
|
70
|
+
const flags = new Map;
|
|
71
|
+
const positional = [];
|
|
72
|
+
for (let i = 0;i < argv.length; i++) {
|
|
73
|
+
const arg = argv[i];
|
|
74
|
+
if (arg === undefined)
|
|
75
|
+
continue;
|
|
76
|
+
if (!arg.startsWith("-") || arg === "-") {
|
|
77
|
+
positional.push(arg);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const equals = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
81
|
+
const flag = equals === -1 ? arg : arg.slice(0, equals);
|
|
82
|
+
if (!known.includes(flag))
|
|
83
|
+
throw unknownOption(command, flag);
|
|
84
|
+
if (!VALUED.has(flag)) {
|
|
85
|
+
const on = equals === -1 ? "true" : arg.slice(equals + 1);
|
|
86
|
+
if (on !== "true" && on !== "false") {
|
|
87
|
+
throw usageError2("BV_BAD_OPTION_VALUE", `bivium ${command}: ${flag} is a switch: give it alone, or as ${flag}=true or ${flag}=false`);
|
|
88
|
+
}
|
|
89
|
+
if (on === "true")
|
|
90
|
+
flags.set(flag, "");
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const value = equals === -1 ? argv[++i] : arg.slice(equals + 1);
|
|
94
|
+
if (value === undefined || value === "" || value.startsWith("--")) {
|
|
95
|
+
throw usageError2("BV_BAD_OPTION_VALUE", `bivium: ${flag} needs a value`);
|
|
96
|
+
}
|
|
97
|
+
flags.set(flag, value);
|
|
98
|
+
}
|
|
99
|
+
if (positional.length > (POSITIONAL[command] ?? 0)) {
|
|
100
|
+
throw usageError2("BV_UNEXPECTED_ARGUMENT", `bivium ${command}: unexpected ${positional.at(-1)}`);
|
|
101
|
+
}
|
|
102
|
+
return { flags, positional };
|
|
103
|
+
}
|
|
104
|
+
function json2(value) {
|
|
105
|
+
return JSON.stringify({ schemaVersion: SCHEMA_VERSION, ...value }, null, 2);
|
|
106
|
+
}
|
|
107
|
+
function commandAt2(argv) {
|
|
108
|
+
for (let i = 0;i < argv.length; i++) {
|
|
109
|
+
const arg = argv[i];
|
|
110
|
+
if (arg === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
if (!arg.startsWith("-"))
|
|
113
|
+
return i;
|
|
114
|
+
if (VALUED.has(arg))
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
return -1;
|
|
118
|
+
}
|
|
119
|
+
var COMMANDS2 = Object.keys(FLAGS2);
|
|
120
|
+
var EVERY_FLAG2 = [
|
|
121
|
+
...new Set([...Object.values(FLAGS2).flat(), "--help", "--version"])
|
|
122
|
+
];
|
|
123
|
+
function unknownFlag2(argv) {
|
|
124
|
+
for (let i = 0;i < argv.length; i++) {
|
|
125
|
+
const arg = argv[i];
|
|
126
|
+
if (arg === undefined || !arg.startsWith("-") || arg === "-")
|
|
127
|
+
continue;
|
|
128
|
+
const equals = arg.startsWith("--") ? arg.indexOf("=") : -1;
|
|
129
|
+
const flag = equals === -1 ? arg : arg.slice(0, equals);
|
|
130
|
+
if (!EVERY_FLAG2.includes(flag))
|
|
131
|
+
return flag;
|
|
132
|
+
if (VALUED.has(arg))
|
|
133
|
+
i++;
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
function wantsJson(argv) {
|
|
138
|
+
return argv.some((arg, i) => arg === "--json" || arg === "--json=true" || arg === "--format=json" || arg === "--format" && argv[i + 1] === "json");
|
|
139
|
+
}
|
|
140
|
+
function fail2(argv, error) {
|
|
141
|
+
console.error(error.message);
|
|
142
|
+
if (wantsJson(argv)) {
|
|
143
|
+
const { kind, code, message } = error;
|
|
144
|
+
console.log(json2({ error: { kind, code, message } }));
|
|
145
|
+
}
|
|
146
|
+
return 2;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { FLAGS2, outFor2, usageError2, parseArgs2, json2, commandAt2, COMMANDS2, EVERY_FLAG2, unknownFlag2, fail2 };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SEPARATOR2
|
|
3
|
+
} from "./shared-mpjk8met.js";
|
|
4
|
+
import {
|
|
5
|
+
version
|
|
6
|
+
} from "./shared-jp8yw63q.js";
|
|
7
|
+
|
|
8
|
+
// src/help.ts
|
|
9
|
+
var row = (p, name, does, preset) => ` ${name.padEnd(21)}${does}${preset === undefined ? "" : p.dim(`${SEPARATOR2}${preset}`)}`;
|
|
10
|
+
var example = (p, intent, command) => ` ${p.dim(`# ${intent}`)}
|
|
11
|
+
${command}`;
|
|
12
|
+
function usage(p) {
|
|
13
|
+
return `${p.bold("bivium")} ${version}${p.dim(`${SEPARATOR2}run only the tests your change can reach`)}
|
|
14
|
+
|
|
15
|
+
${p.bold("Usage")}
|
|
16
|
+
bivium <command> [arguments] [options]
|
|
17
|
+
|
|
18
|
+
${p.bold("Commands")}
|
|
19
|
+
${row(p, "plan [base]", "the tests a change can affect, per suite")}
|
|
20
|
+
${row(p, "run [base]", "run a suite's selected tests")}
|
|
21
|
+
${row(p, "why <test> [file]", "the chain from a change, or a file, to a test")}
|
|
22
|
+
${row(p, "check", "what the graph can't read, and dead globs")}
|
|
23
|
+
${row(p, "graph", "each file's test fan-in, and the graph")}
|
|
24
|
+
|
|
25
|
+
base defaults to the config's base, else the upstream default branch.
|
|
26
|
+
Options go before or after the command, as --flag value or --flag=value.
|
|
27
|
+
A path is repo-relative, relative to the current directory, or absolute.
|
|
28
|
+
|
|
29
|
+
${p.bold("Options")}
|
|
30
|
+
${row(p, "--config <file>", "the config file", "bivium.config.{ts,mts,mjs,js,json}")}
|
|
31
|
+
${row(p, "--cwd <dir>", "the repository", "the current directory")}
|
|
32
|
+
${row(p, "--no-cache", "read every file; skip the extraction cache")}
|
|
33
|
+
${row(p, "--json", "plan, why, check, graph: print JSON")}
|
|
34
|
+
${row(p, "--color, --no-color", "force color on or off", "on in a terminal")}
|
|
35
|
+
${row(p, "-h, --help", "this help")}
|
|
36
|
+
${row(p, "-v, --version", "the version")}
|
|
37
|
+
|
|
38
|
+
${p.bold(" plan")}
|
|
39
|
+
${row(p, "--list", "the files, as when piped, on a terminal too")}
|
|
40
|
+
${row(p, "--github", "also write each suite's selection to $GITHUB_OUTPUT")}
|
|
41
|
+
${p.bold(" run")}
|
|
42
|
+
${row(p, "--suite <name>", "the suite to run", "the first")}
|
|
43
|
+
${p.bold(" why")}
|
|
44
|
+
${row(p, "--base <ref>", "the base ref", "as for plan")}
|
|
45
|
+
${row(p, "--format <f>", "tree, chain, source or json", "tree")}
|
|
46
|
+
${row(p, "--all", "every change's chain, not only the shortest")}
|
|
47
|
+
${p.bold(" check")}
|
|
48
|
+
${row(p, "--base <ref>", "the base ref", "HEAD")}
|
|
49
|
+
${row(p, "--all", "every file, and each fix whole")}
|
|
50
|
+
${row(p, "--max-unknown <n>", "fail past n unknown files that reach a test")}
|
|
51
|
+
${p.bold(" graph")}
|
|
52
|
+
${row(p, "--suite <name>", "only this suite", "every suite")}
|
|
53
|
+
${row(p, "--top <n>", "files to list per suite", "10")}
|
|
54
|
+
|
|
55
|
+
${p.bold("Examples")}
|
|
56
|
+
${example(p, "the tests this branch needs, as data", "bivium plan origin/main --json")}
|
|
57
|
+
${example(p, "how a change to a file reaches a test", "bivium why tests/Button.test.ts src/Button.svelte --format chain")}
|
|
58
|
+
${example(p, "fail CI when a file bivium can't follow reaches a test", "bivium check --max-unknown 0")}
|
|
59
|
+
|
|
60
|
+
${p.bold("For agents")}
|
|
61
|
+
Run with --json; read ok and summary. Exit 0 done, 1 check found
|
|
62
|
+
problems, 2 a usage, config or git error; run exits with its command's,
|
|
63
|
+
or 130 on Ctrl-C. With --json, an error is JSON too: error.kind (usage,
|
|
64
|
+
config, git or other), error.code and error.message.`;
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
usage
|
|
68
|
+
};
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// src/terminal.ts
|
|
2
|
+
var asIs = (text) => text;
|
|
3
|
+
var PLAIN2 = {
|
|
4
|
+
good: asIs,
|
|
5
|
+
warn: asIs,
|
|
6
|
+
bad: asIs,
|
|
7
|
+
dim: asIs,
|
|
8
|
+
bold: asIs,
|
|
9
|
+
faint: asIs
|
|
10
|
+
};
|
|
11
|
+
function createPaint2() {
|
|
12
|
+
const wrap = (code) => (text) => text === "" ? text : `\x1B[${code}m${text}\x1B[39m`;
|
|
13
|
+
return {
|
|
14
|
+
good: wrap(32),
|
|
15
|
+
warn: wrap(33),
|
|
16
|
+
bad: wrap(31),
|
|
17
|
+
dim: wrap(90),
|
|
18
|
+
bold: (text) => text === "" ? text : `\x1B[1m${text}\x1B[22m`,
|
|
19
|
+
faint: (text) => text === "" ? text : `\x1B[2m${text}\x1B[22m`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function wantsColor2(forced, terminal, env, agent) {
|
|
23
|
+
if (forced !== undefined)
|
|
24
|
+
return forced;
|
|
25
|
+
if ((env.NO_COLOR ?? "") !== "")
|
|
26
|
+
return false;
|
|
27
|
+
const force = env.FORCE_COLOR;
|
|
28
|
+
if (force !== undefined && force !== "")
|
|
29
|
+
return force !== "0";
|
|
30
|
+
return terminal && !agent && !isDumb2(env);
|
|
31
|
+
}
|
|
32
|
+
var isDumb2 = (env) => env.TERM === "dumb";
|
|
33
|
+
var AGENT_ENV = [
|
|
34
|
+
"AGENT",
|
|
35
|
+
"AI_AGENT",
|
|
36
|
+
"CLAUDECODE",
|
|
37
|
+
"CODEX_CI",
|
|
38
|
+
"CODEX_THREAD_ID"
|
|
39
|
+
];
|
|
40
|
+
var agentVariableOf = (env) => AGENT_ENV.find((name) => {
|
|
41
|
+
const value = env[name];
|
|
42
|
+
return value !== undefined && value !== "" && value !== "0";
|
|
43
|
+
});
|
|
44
|
+
var isAgent2 = (env) => agentVariableOf(env) !== undefined;
|
|
45
|
+
var UNICODE_GLYPHS2 = {
|
|
46
|
+
done: "✓",
|
|
47
|
+
failed: "✗",
|
|
48
|
+
skipped: "-",
|
|
49
|
+
pending: "○",
|
|
50
|
+
spinner: ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
|
|
51
|
+
pointer: "›",
|
|
52
|
+
picked: "●",
|
|
53
|
+
unpicked: "○",
|
|
54
|
+
up: "↑",
|
|
55
|
+
down: "↓",
|
|
56
|
+
upDown: "↑↓",
|
|
57
|
+
leftRight: "←→",
|
|
58
|
+
barDone: "━",
|
|
59
|
+
barTodo: "─"
|
|
60
|
+
};
|
|
61
|
+
var ASCII_GLYPHS2 = {
|
|
62
|
+
done: "+",
|
|
63
|
+
failed: "x",
|
|
64
|
+
skipped: "-",
|
|
65
|
+
pending: ".",
|
|
66
|
+
spinner: [">"],
|
|
67
|
+
pointer: ">",
|
|
68
|
+
picked: "[x]",
|
|
69
|
+
unpicked: "[ ]",
|
|
70
|
+
up: "^",
|
|
71
|
+
down: "v",
|
|
72
|
+
upDown: "up/down",
|
|
73
|
+
leftRight: "left/right",
|
|
74
|
+
barDone: "=",
|
|
75
|
+
barTodo: "-"
|
|
76
|
+
};
|
|
77
|
+
var markOf2 = (glyphs, mark) => glyphs[mark] ?? UNICODE_GLYPHS2[mark];
|
|
78
|
+
function wantsAscii2(env) {
|
|
79
|
+
if (isDumb2(env))
|
|
80
|
+
return true;
|
|
81
|
+
const locale = env.LC_ALL || env.LC_CTYPE || env.LANG;
|
|
82
|
+
return locale !== undefined && locale !== "" && !/utf-?8/i.test(locale);
|
|
83
|
+
}
|
|
84
|
+
var HIDE_CURSOR = "\x1B[?25l";
|
|
85
|
+
var SHOW_CURSOR = "\x1B[?25h";
|
|
86
|
+
var cursor = { hidden: false };
|
|
87
|
+
function hideCursor2() {
|
|
88
|
+
cursor.hidden = true;
|
|
89
|
+
return HIDE_CURSOR;
|
|
90
|
+
}
|
|
91
|
+
function showCursor2() {
|
|
92
|
+
cursor.hidden = false;
|
|
93
|
+
return SHOW_CURSOR;
|
|
94
|
+
}
|
|
95
|
+
var cursorHidden2 = () => cursor.hidden;
|
|
96
|
+
var MISSING2 = "n/a";
|
|
97
|
+
var SEPARATOR2 = " · ";
|
|
98
|
+
var branch2 = (index, count) => index === count - 1 ? "└ " : "├ ";
|
|
99
|
+
var NOTE_INDENT2 = " ";
|
|
100
|
+
function closingLine2(paint, what, detail, glyphs = UNICODE_GLYPHS2) {
|
|
101
|
+
return `${paint.good(glyphs.done)} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR2}${detail}`)}`;
|
|
102
|
+
}
|
|
103
|
+
function failLine2(paint, what, detail, glyphs = UNICODE_GLYPHS2) {
|
|
104
|
+
return `${paint.bad(glyphs.failed)} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR2}${detail}`)}`;
|
|
105
|
+
}
|
|
106
|
+
var keyHints2 = (paint, keys) => paint.faint(keys.map((k) => `${k.key} ${k.does}`).join(SEPARATOR2));
|
|
107
|
+
function distance(a, b) {
|
|
108
|
+
const width = b.length + 1;
|
|
109
|
+
const cells = new Uint32Array((a.length + 1) * width);
|
|
110
|
+
const d = (i, j) => cells[i * width + j] ?? 0;
|
|
111
|
+
for (let i = 0;i <= a.length; i++)
|
|
112
|
+
cells[i * width] = i;
|
|
113
|
+
for (let j = 0;j <= b.length; j++)
|
|
114
|
+
cells[j] = j;
|
|
115
|
+
for (let i = 1;i <= a.length; i++) {
|
|
116
|
+
for (let j = 1;j <= b.length; j++) {
|
|
117
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
118
|
+
let best = Math.min(d(i - 1, j) + 1, d(i, j - 1) + 1, d(i - 1, j - 1) + cost);
|
|
119
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
120
|
+
best = Math.min(best, d(i - 2, j - 2) + 1);
|
|
121
|
+
}
|
|
122
|
+
cells[i * width + j] = best;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return d(a.length, b.length);
|
|
126
|
+
}
|
|
127
|
+
function shareLetter(a, b) {
|
|
128
|
+
const letters = new Set(a.replace(/^-+/, "").toLowerCase());
|
|
129
|
+
for (const c of b.replace(/^-+/, "").toLowerCase()) {
|
|
130
|
+
if (letters.has(c))
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
function nearest2(input, candidates) {
|
|
136
|
+
const most = Math.max(1, Math.floor(input.length / 3));
|
|
137
|
+
let best;
|
|
138
|
+
let bestDistance = most + 1;
|
|
139
|
+
for (const candidate of candidates) {
|
|
140
|
+
const d = distance(input, candidate);
|
|
141
|
+
if (d < bestDistance && shareLetter(input, candidate)) {
|
|
142
|
+
best = candidate;
|
|
143
|
+
bestDistance = d;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return best;
|
|
147
|
+
}
|
|
148
|
+
function truncateWords2(text, max) {
|
|
149
|
+
if ([...text].length <= max)
|
|
150
|
+
return text;
|
|
151
|
+
const cut = [...text].slice(0, max - 1).join("");
|
|
152
|
+
const space = cut.lastIndexOf(" ");
|
|
153
|
+
return `${(space > max / 2 ? cut.slice(0, space) : cut).replace(/[\s,;:]+$/, "")}…`;
|
|
154
|
+
}
|
|
155
|
+
var HASH_TAIL = /[-.][^-./]+\.\w+$/;
|
|
156
|
+
var WORD_END = /(?<=[-_.])/;
|
|
157
|
+
var width = (text) => [...text].length;
|
|
158
|
+
function truncatePath2(path, max) {
|
|
159
|
+
if (width(path) <= max)
|
|
160
|
+
return path;
|
|
161
|
+
const parts = path.split("/");
|
|
162
|
+
const name = parts.pop() ?? path;
|
|
163
|
+
for (let keep = parts.length - 1;keep >= 0; keep--) {
|
|
164
|
+
const candidate = `…/${[...parts.slice(parts.length - keep), name].join("/")}`;
|
|
165
|
+
if (width(candidate) <= max)
|
|
166
|
+
return candidate;
|
|
167
|
+
}
|
|
168
|
+
const prefix = parts.length > 0 ? "…/" : "";
|
|
169
|
+
const tail = HASH_TAIL.exec(name)?.[0] ?? "";
|
|
170
|
+
const stem = name.slice(0, name.length - tail.length);
|
|
171
|
+
const room = max - width(prefix) - width(tail) - 1;
|
|
172
|
+
if (room < 4)
|
|
173
|
+
return `${prefix}…${[...name].slice(-(max - width(prefix) - 1)).join("")}`;
|
|
174
|
+
const words = stem.split(WORD_END);
|
|
175
|
+
const first = words[0] ?? "";
|
|
176
|
+
let end = "";
|
|
177
|
+
for (let i = words.length - 1;i > 0; i--) {
|
|
178
|
+
const word = words[i] ?? "";
|
|
179
|
+
if (width(first) + 1 + width(word + end) > room)
|
|
180
|
+
break;
|
|
181
|
+
end = word + end;
|
|
182
|
+
}
|
|
183
|
+
return end === "" ? `${prefix}${[...stem].slice(0, room).join("")}…${tail}` : `${prefix}${first}…${end}${tail}`;
|
|
184
|
+
}
|
|
185
|
+
var ESCAPE = /\x1b\[[0-9;]*m/g;
|
|
186
|
+
var LEADING_ESCAPE = /^\x1b\[[0-9;]*m/;
|
|
187
|
+
var textWidth2 = (text) => typeof Bun === "undefined" ? [...text.replace(ESCAPE, "")].length : Bun.stringWidth(text);
|
|
188
|
+
var MEASURE2 = 80;
|
|
189
|
+
function hangOf(line) {
|
|
190
|
+
const plain = line.replace(ESCAPE, "");
|
|
191
|
+
const lead = /^ */.exec(plain)?.[0].length ?? 0;
|
|
192
|
+
const gap = /^ *\S.*? {2,}(?=\S)/.exec(plain);
|
|
193
|
+
return gap ? textWidth2(gap[0]) : lead;
|
|
194
|
+
}
|
|
195
|
+
function splitAt(line, columns) {
|
|
196
|
+
let seen = 0;
|
|
197
|
+
let i = 0;
|
|
198
|
+
while (i < line.length && seen < columns) {
|
|
199
|
+
const escape = LEADING_ESCAPE.exec(line.slice(i));
|
|
200
|
+
if (escape) {
|
|
201
|
+
i += escape[0].length;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const ch = String.fromCodePoint(line.codePointAt(i) ?? 32);
|
|
205
|
+
seen += textWidth2(ch);
|
|
206
|
+
i += ch.length;
|
|
207
|
+
}
|
|
208
|
+
return [line.slice(0, i), line.slice(i)];
|
|
209
|
+
}
|
|
210
|
+
var fitTerminal2 = (text, terminal, columns) => terminal ? fitWidth2(text, Math.min(MEASURE2, columns || MEASURE2)) : text;
|
|
211
|
+
function wordsOf(text) {
|
|
212
|
+
const words = [];
|
|
213
|
+
for (const word of text.split(/ +/)) {
|
|
214
|
+
const last = words.at(-1);
|
|
215
|
+
if (last !== undefined && last.replace(ESCAPE, "") === "·") {
|
|
216
|
+
words[words.length - 1] = `${last} ${word}`;
|
|
217
|
+
} else if (word !== "")
|
|
218
|
+
words.push(word);
|
|
219
|
+
}
|
|
220
|
+
return words;
|
|
221
|
+
}
|
|
222
|
+
function wrapWords(words, room, breakWords) {
|
|
223
|
+
const lines = [];
|
|
224
|
+
let current = "";
|
|
225
|
+
for (const word of words) {
|
|
226
|
+
const pieces = [];
|
|
227
|
+
let rest = word;
|
|
228
|
+
while (breakWords && textWidth2(rest) > room) {
|
|
229
|
+
const [piece, after] = splitAt(rest, room);
|
|
230
|
+
pieces.push(piece);
|
|
231
|
+
rest = after;
|
|
232
|
+
}
|
|
233
|
+
pieces.push(rest);
|
|
234
|
+
for (const piece of pieces) {
|
|
235
|
+
const next = current === "" ? piece : `${current} ${piece}`;
|
|
236
|
+
if (current !== "" && textWidth2(next) > room) {
|
|
237
|
+
lines.push(current);
|
|
238
|
+
current = piece;
|
|
239
|
+
} else {
|
|
240
|
+
current = next;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (current !== "")
|
|
245
|
+
lines.push(current);
|
|
246
|
+
return lines;
|
|
247
|
+
}
|
|
248
|
+
function fitWidth2(text, width) {
|
|
249
|
+
return text.split(`
|
|
250
|
+
`).flatMap((line) => {
|
|
251
|
+
if (textWidth2(line) <= width)
|
|
252
|
+
return [line];
|
|
253
|
+
let hang = hangOf(line);
|
|
254
|
+
if (hang > width / 2)
|
|
255
|
+
hang = /^ */.exec(line.replace(ESCAPE, ""))?.[0].length ?? 0;
|
|
256
|
+
const [head, rest] = splitAt(line, hang);
|
|
257
|
+
const room = Math.max(1, width - hang);
|
|
258
|
+
return wrapWords(wordsOf(rest), room, false).map((part, k) => (k === 0 ? head : " ".repeat(hang)) + part);
|
|
259
|
+
}).join(`
|
|
260
|
+
`);
|
|
261
|
+
}
|
|
262
|
+
var RULE2 = "\x00rule";
|
|
263
|
+
function aligned2(table, rightColumns = [], paintRule = asIs, indent = " ") {
|
|
264
|
+
const blank = (cell) => cell === "" || cell === RULE2;
|
|
265
|
+
const used = new Set(table.flatMap((row) => row.flatMap((cell, i) => blank(cell) ? [] : [i])));
|
|
266
|
+
const keep = (row) => row.filter((_, i) => used.has(i));
|
|
267
|
+
const rows = table.map(keep);
|
|
268
|
+
const right = [...used].sort((a, b) => a - b).flatMap((column, i) => rightColumns.includes(column) ? [i] : []);
|
|
269
|
+
const cellWidth = (cell) => cell === RULE2 ? 0 : textWidth2(cell);
|
|
270
|
+
const widths = [];
|
|
271
|
+
for (const row of rows) {
|
|
272
|
+
for (const [i, cell] of row.entries()) {
|
|
273
|
+
if (i === row.length - 1 && !right.includes(i))
|
|
274
|
+
continue;
|
|
275
|
+
widths[i] = Math.max(widths[i] ?? 0, cellWidth(cell));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const pad = (cell, i) => " ".repeat(Math.max(0, (widths[i] ?? 0) - cellWidth(cell)));
|
|
279
|
+
const columnsWidth = (from, to) => widths.slice(from, to).reduce((sum, w) => sum + w + 2, 0);
|
|
280
|
+
return rows.map((row) => {
|
|
281
|
+
const first = row.indexOf(RULE2);
|
|
282
|
+
if (first !== -1) {
|
|
283
|
+
const last = row.lastIndexOf(RULE2);
|
|
284
|
+
const line = "─".repeat(columnsWidth(first, last + 1) - 2);
|
|
285
|
+
return `${indent}${" ".repeat(columnsWidth(0, first))}${paintRule(line)}`;
|
|
286
|
+
}
|
|
287
|
+
return `${indent}${row.map((cell, i) => right.includes(i) ? pad(cell, i) + cell : i === row.length - 1 ? cell : cell + pad(cell, i)).join(" ")}`.trimEnd();
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
var headerRow2 = (paint, cells) => cells.map((cell) => paint.faint(cell));
|
|
291
|
+
var plural2 = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
|
|
292
|
+
var SILENT2 = { step: () => {}, clear: () => {} };
|
|
293
|
+
var BAR_WIDTH = 20;
|
|
294
|
+
var CLEAR_LINE = "\r\x1B[2K";
|
|
295
|
+
function createProgress2(write, paint, nowMs, glyphs = UNICODE_GLYPHS2) {
|
|
296
|
+
const startMs = nowMs();
|
|
297
|
+
let text = "";
|
|
298
|
+
let doneRatio = 0;
|
|
299
|
+
const render = () => {
|
|
300
|
+
const done = Math.round(Math.min(1, Math.max(0, doneRatio)) * BAR_WIDTH);
|
|
301
|
+
const bar = paint.good(markOf2(glyphs, "barDone").repeat(done)) + paint.dim(markOf2(glyphs, "barTodo").repeat(BAR_WIDTH - done));
|
|
302
|
+
const seconds = Math.floor((nowMs() - startMs) / 1000);
|
|
303
|
+
write(`${CLEAR_LINE}${bar} ${text}${paint.dim(` · ${seconds} s`)}`);
|
|
304
|
+
};
|
|
305
|
+
const timer = setInterval(render, 1000);
|
|
306
|
+
timer.unref();
|
|
307
|
+
return {
|
|
308
|
+
step(next, ratio) {
|
|
309
|
+
text = next;
|
|
310
|
+
doneRatio = ratio;
|
|
311
|
+
render();
|
|
312
|
+
},
|
|
313
|
+
clear() {
|
|
314
|
+
clearInterval(timer);
|
|
315
|
+
write(CLEAR_LINE);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export { PLAIN2, createPaint2, wantsColor2, isDumb2, isAgent2, UNICODE_GLYPHS2, ASCII_GLYPHS2, markOf2, wantsAscii2, hideCursor2, showCursor2, cursorHidden2, MISSING2, SEPARATOR2, branch2, NOTE_INDENT2, closingLine2, failLine2, keyHints2, nearest2, truncateWords2, truncatePath2, textWidth2, MEASURE2, fitTerminal2, fitWidth2, RULE2, aligned2, headerRow2, plural2, SILENT2, createProgress2 };
|