bivium 0.6.2 → 0.7.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 +26 -22
- package/cli.js +573 -273
- package/docs/api.md +5 -1
- package/docs/ci.md +4 -2
- package/docs/cli.md +69 -8
- package/docs/config.md +13 -10
- package/docs/how-it-works.md +18 -3
- package/docs/recipes.md +6 -4
- package/docs/tuning.md +35 -29
- package/index.d.ts +14 -26
- package/package.json +1 -1
- package/shared.js +189 -40
package/shared.js
CHANGED
|
@@ -8,7 +8,7 @@ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
|
8
8
|
import { isAbsolute, join } from "node:path";
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
|
-
var version = "0.
|
|
11
|
+
var version = "0.7.0";
|
|
12
12
|
|
|
13
13
|
// src/env.ts
|
|
14
14
|
function githubOutputPath() {
|
|
@@ -17,9 +17,25 @@ function githubOutputPath() {
|
|
|
17
17
|
function nowMs() {
|
|
18
18
|
return Date.now();
|
|
19
19
|
}
|
|
20
|
+
function environment() {
|
|
21
|
+
return process.env;
|
|
22
|
+
}
|
|
23
|
+
var AGENT_ENV = [
|
|
24
|
+
"AGENT",
|
|
25
|
+
"AI_AGENT",
|
|
26
|
+
"CLAUDECODE",
|
|
27
|
+
"CODEX_CI",
|
|
28
|
+
"CODEX_THREAD_ID"
|
|
29
|
+
];
|
|
30
|
+
function agentVariable(env) {
|
|
31
|
+
return AGENT_ENV.find((name) => {
|
|
32
|
+
const value = env[name];
|
|
33
|
+
return value !== undefined && value !== "" && value !== "0";
|
|
34
|
+
});
|
|
35
|
+
}
|
|
20
36
|
|
|
21
37
|
// src/cache.ts
|
|
22
|
-
var SCANNER_VERSION =
|
|
38
|
+
var SCANNER_VERSION = 9;
|
|
23
39
|
var MAGIC = "bivium-extractions";
|
|
24
40
|
var FILE = "extractions.json";
|
|
25
41
|
function isHeader(value) {
|
|
@@ -1375,7 +1391,7 @@ function createResolver({
|
|
|
1375
1391
|
const found = probe(posix.join(svelteKitRoot(fromDir), "static", rest));
|
|
1376
1392
|
return found.length > 0 ? { files: found } : undefined;
|
|
1377
1393
|
}
|
|
1378
|
-
const found = probe(posix.join(fromDir, bare));
|
|
1394
|
+
const found = probe(posix.join(fromDir, bare).replace(/(.)\/+$/, "$1"));
|
|
1379
1395
|
return found.length > 0 ? { files: found } : undefined;
|
|
1380
1396
|
};
|
|
1381
1397
|
const resolveBare = (scope, bare) => {
|
|
@@ -2933,6 +2949,19 @@ function addPattern(deps, pattern, kind) {
|
|
|
2933
2949
|
deps.patternKinds ??= new Map;
|
|
2934
2950
|
deps.patternKinds.set(pattern, kind);
|
|
2935
2951
|
}
|
|
2952
|
+
function addCause(deps, cause) {
|
|
2953
|
+
if (!deps.unknown.includes(cause))
|
|
2954
|
+
deps.unknown.push(cause);
|
|
2955
|
+
}
|
|
2956
|
+
function addPages(deps, pages) {
|
|
2957
|
+
for (const page of pages) {
|
|
2958
|
+
if (!deps.files.has(page)) {
|
|
2959
|
+
deps.pages ??= new Set;
|
|
2960
|
+
deps.pages.add(page);
|
|
2961
|
+
}
|
|
2962
|
+
deps.files.add(page);
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2936
2965
|
var NON_LITERAL_GOTO = "non-literal goto(";
|
|
2937
2966
|
var HERMETIC_CAUSES = new Set([
|
|
2938
2967
|
UNDECLARED_READS,
|
|
@@ -3047,28 +3076,22 @@ function graphFrom(files, extractions, { config, packages, tsconfigs }) {
|
|
|
3047
3076
|
(erased ? typed : valued).add(node);
|
|
3048
3077
|
};
|
|
3049
3078
|
if (resolved === undefined) {
|
|
3050
|
-
|
|
3051
|
-
if (!deps.unknown.includes(cause))
|
|
3052
|
-
deps.unknown.push(cause);
|
|
3079
|
+
addCause(deps, `unresolved "${specifier}"`);
|
|
3053
3080
|
} else if ("pkg" in resolved) {
|
|
3054
3081
|
add(`pkg:${resolved.pkg}`);
|
|
3055
3082
|
external.add(`pkg:${resolved.pkg}`);
|
|
3056
3083
|
} else {
|
|
3057
3084
|
if (type !== true && !declaration && JS_SPECIFIER.test(specifier.replace(QUERY, "")) && resolved.files.every((file) => DECLARATION.test(file))) {
|
|
3058
|
-
|
|
3059
|
-
if (!deps.unknown.includes(cause))
|
|
3060
|
-
deps.unknown.push(cause);
|
|
3085
|
+
addCause(deps, `only declarations for "${specifier}"`);
|
|
3061
3086
|
}
|
|
3062
|
-
|
|
3087
|
+
const nodes = resolved.files.flatMap((file) => {
|
|
3063
3088
|
const barrel = names && named.get(file);
|
|
3064
|
-
if (!barrel || !names)
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
}
|
|
3071
|
-
}
|
|
3089
|
+
if (!barrel || !names)
|
|
3090
|
+
return [file];
|
|
3091
|
+
return names.map((name) => barrel.has(name) ? `${file}#${name}` : file);
|
|
3092
|
+
});
|
|
3093
|
+
for (const node of nodes)
|
|
3094
|
+
add(node);
|
|
3072
3095
|
}
|
|
3073
3096
|
}
|
|
3074
3097
|
for (const node of typed) {
|
|
@@ -3085,25 +3108,18 @@ function graphFrom(files, extractions, { config, packages, tsconfigs }) {
|
|
|
3085
3108
|
if (suite) {
|
|
3086
3109
|
for (const argument of found.gotos) {
|
|
3087
3110
|
const url = gotoUrl(argument);
|
|
3088
|
-
if (url === undefined) {
|
|
3089
|
-
|
|
3090
|
-
deps.unknown.push(`${NON_LITERAL_GOTO}${argument})`);
|
|
3091
|
-
}
|
|
3092
|
-
} else if (url !== "about:blank") {
|
|
3093
|
-
const mapped = mapUrl(suite, url.replace(QUERY, ""));
|
|
3094
|
-
if (mapped === undefined)
|
|
3095
|
-
deps.unknown.push(`goto("${url}")`);
|
|
3096
|
-
else if (exists.has(mapped[0] ?? "")) {
|
|
3097
|
-
for (const page of mapped.filter((file) => exists.has(file))) {
|
|
3098
|
-
if (!deps.files.has(page)) {
|
|
3099
|
-
deps.pages ??= new Set;
|
|
3100
|
-
deps.pages.add(page);
|
|
3101
|
-
}
|
|
3102
|
-
deps.files.add(page);
|
|
3103
|
-
}
|
|
3104
|
-
} else
|
|
3105
|
-
deps.unknown.push(`missing fixture "${url}"`);
|
|
3111
|
+
if (url === undefined && found.dependsOn.length === 0) {
|
|
3112
|
+
deps.unknown.push(`${NON_LITERAL_GOTO}${argument})`);
|
|
3106
3113
|
}
|
|
3114
|
+
if (url === undefined || url === "about:blank")
|
|
3115
|
+
continue;
|
|
3116
|
+
const mapped = mapUrl(suite, url.replace(QUERY, ""));
|
|
3117
|
+
if (mapped === undefined)
|
|
3118
|
+
deps.unknown.push(`goto("${url}")`);
|
|
3119
|
+
else if (exists.has(mapped[0] ?? "")) {
|
|
3120
|
+
addPages(deps, mapped.filter((file) => exists.has(file)));
|
|
3121
|
+
} else
|
|
3122
|
+
deps.unknown.push(`missing fixture "${url}"`);
|
|
3107
3123
|
}
|
|
3108
3124
|
}
|
|
3109
3125
|
for (const glob of found.dependsOn) {
|
|
@@ -4284,9 +4300,142 @@ function planTests(graph, changed, config, {
|
|
|
4284
4300
|
// src/settings.ts
|
|
4285
4301
|
import { posix as posix5 } from "node:path";
|
|
4286
4302
|
|
|
4287
|
-
// src/
|
|
4288
|
-
|
|
4289
|
-
|
|
4303
|
+
// src/terminal.ts
|
|
4304
|
+
var asIs = (text) => text;
|
|
4305
|
+
var PLAIN = {
|
|
4306
|
+
good: asIs,
|
|
4307
|
+
warn: asIs,
|
|
4308
|
+
bad: asIs,
|
|
4309
|
+
dim: asIs,
|
|
4310
|
+
bold: asIs,
|
|
4311
|
+
faint: asIs
|
|
4312
|
+
};
|
|
4313
|
+
function createPaint() {
|
|
4314
|
+
const wrap = (code) => (text) => text === "" ? text : `\x1B[${code}m${text}\x1B[39m`;
|
|
4315
|
+
return {
|
|
4316
|
+
good: wrap(32),
|
|
4317
|
+
warn: wrap(33),
|
|
4318
|
+
bad: wrap(31),
|
|
4319
|
+
dim: wrap(90),
|
|
4320
|
+
bold: (text) => text === "" ? text : `\x1B[1m${text}\x1B[22m`,
|
|
4321
|
+
faint: (text) => text === "" ? text : `\x1B[2m${text}\x1B[22m`
|
|
4322
|
+
};
|
|
4323
|
+
}
|
|
4324
|
+
function wantsColor(forced, terminal, env, agent) {
|
|
4325
|
+
if (forced !== undefined)
|
|
4326
|
+
return forced;
|
|
4327
|
+
if ((env.NO_COLOR ?? "") !== "")
|
|
4328
|
+
return false;
|
|
4329
|
+
const force = env.FORCE_COLOR;
|
|
4330
|
+
if (force !== undefined && force !== "")
|
|
4331
|
+
return force !== "0";
|
|
4332
|
+
return terminal && !agent;
|
|
4333
|
+
}
|
|
4334
|
+
var SEPARATOR = " · ";
|
|
4335
|
+
var branch = (index, count) => index === count - 1 ? "└ " : "├ ";
|
|
4336
|
+
var NOTE_INDENT = " ";
|
|
4337
|
+
function closingLine(paint, what, detail) {
|
|
4338
|
+
return `${paint.good("✓")} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR}${detail}`)}`;
|
|
4339
|
+
}
|
|
4340
|
+
function failLine(paint, what, detail) {
|
|
4341
|
+
return `${paint.bad("✗")} ${what}${detail === undefined ? "" : paint.dim(`${SEPARATOR}${detail}`)}`;
|
|
4342
|
+
}
|
|
4343
|
+
function truncateWords(text, max) {
|
|
4344
|
+
if ([...text].length <= max)
|
|
4345
|
+
return text;
|
|
4346
|
+
const cut = [...text].slice(0, max - 1).join("");
|
|
4347
|
+
const space = cut.lastIndexOf(" ");
|
|
4348
|
+
return `${(space > max / 2 ? cut.slice(0, space) : cut).replace(/[\s,;:]+$/, "")}…`;
|
|
4349
|
+
}
|
|
4350
|
+
var HASH_TAIL = /[-.][^-./]+\.\w+$/;
|
|
4351
|
+
var WORD_END = /(?<=[-_.])/;
|
|
4352
|
+
var width = (text) => [...text].length;
|
|
4353
|
+
function truncatePath(path, max) {
|
|
4354
|
+
if (width(path) <= max)
|
|
4355
|
+
return path;
|
|
4356
|
+
const parts = path.split("/");
|
|
4357
|
+
const name = parts.pop() ?? path;
|
|
4358
|
+
for (let keep = parts.length - 1;keep >= 0; keep--) {
|
|
4359
|
+
const candidate = `…/${[...parts.slice(parts.length - keep), name].join("/")}`;
|
|
4360
|
+
if (width(candidate) <= max)
|
|
4361
|
+
return candidate;
|
|
4362
|
+
}
|
|
4363
|
+
const prefix = parts.length > 0 ? "…/" : "";
|
|
4364
|
+
const tail = HASH_TAIL.exec(name)?.[0] ?? "";
|
|
4365
|
+
const stem = name.slice(0, name.length - tail.length);
|
|
4366
|
+
const room = max - width(prefix) - width(tail) - 1;
|
|
4367
|
+
if (room < 4)
|
|
4368
|
+
return `${prefix}…${[...name].slice(-(max - width(prefix) - 1)).join("")}`;
|
|
4369
|
+
const words = stem.split(WORD_END);
|
|
4370
|
+
const first = words[0] ?? "";
|
|
4371
|
+
let end = "";
|
|
4372
|
+
for (let i = words.length - 1;i > 0; i--) {
|
|
4373
|
+
const word = words[i] ?? "";
|
|
4374
|
+
if (width(first) + 1 + width(word + end) > room)
|
|
4375
|
+
break;
|
|
4376
|
+
end = word + end;
|
|
4377
|
+
}
|
|
4378
|
+
return end === "" ? `${prefix}${[...stem].slice(0, room).join("")}…${tail}` : `${prefix}${first}…${end}${tail}`;
|
|
4379
|
+
}
|
|
4380
|
+
var ESCAPE = /\x1b\[[0-9;]*m/g;
|
|
4381
|
+
var textWidth = (text) => typeof Bun === "undefined" ? [...text.replace(ESCAPE, "")].length : Bun.stringWidth(text);
|
|
4382
|
+
var MEASURE = 80;
|
|
4383
|
+
var RULE = "\x00rule";
|
|
4384
|
+
function aligned(table, rightColumns = [], paintRule = asIs, indent = " ") {
|
|
4385
|
+
const blank = (cell) => cell === "" || cell === RULE;
|
|
4386
|
+
const used = new Set(table.flatMap((row) => row.flatMap((cell, i) => blank(cell) ? [] : [i])));
|
|
4387
|
+
const keep = (row) => row.filter((_, i) => used.has(i));
|
|
4388
|
+
const rows = table.map(keep);
|
|
4389
|
+
const right = [...used].sort((a, b) => a - b).flatMap((column, i) => rightColumns.includes(column) ? [i] : []);
|
|
4390
|
+
const cellWidth = (cell) => cell === RULE ? 0 : textWidth(cell);
|
|
4391
|
+
const widths = [];
|
|
4392
|
+
for (const row of rows) {
|
|
4393
|
+
for (const [i, cell] of row.entries()) {
|
|
4394
|
+
if (i === row.length - 1 && !right.includes(i))
|
|
4395
|
+
continue;
|
|
4396
|
+
widths[i] = Math.max(widths[i] ?? 0, cellWidth(cell));
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
const pad = (cell, i) => " ".repeat(Math.max(0, (widths[i] ?? 0) - cellWidth(cell)));
|
|
4400
|
+
const columnsWidth = (from, to) => widths.slice(from, to).reduce((sum, w) => sum + w + 2, 0);
|
|
4401
|
+
return rows.map((row) => {
|
|
4402
|
+
const first = row.indexOf(RULE);
|
|
4403
|
+
if (first !== -1) {
|
|
4404
|
+
const last = row.lastIndexOf(RULE);
|
|
4405
|
+
const line = "─".repeat(columnsWidth(first, last + 1) - 2);
|
|
4406
|
+
return `${indent}${" ".repeat(columnsWidth(0, first))}${paintRule(line)}`;
|
|
4407
|
+
}
|
|
4408
|
+
return `${indent}${row.map((cell, i) => right.includes(i) ? pad(cell, i) + cell : i === row.length - 1 ? cell : cell + pad(cell, i)).join(" ")}`.trimEnd();
|
|
4409
|
+
});
|
|
4410
|
+
}
|
|
4411
|
+
var headerRow = (paint, cells) => cells.map((cell) => paint.faint(cell));
|
|
4412
|
+
var plural = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
|
|
4413
|
+
var SILENT = { step: () => {}, clear: () => {} };
|
|
4414
|
+
var BAR_WIDTH = 20;
|
|
4415
|
+
var CLEAR_LINE = "\r\x1B[2K";
|
|
4416
|
+
function createProgress(write, paint, nowMs) {
|
|
4417
|
+
const startMs = nowMs();
|
|
4418
|
+
let text = "";
|
|
4419
|
+
let doneRatio = 0;
|
|
4420
|
+
const render = () => {
|
|
4421
|
+
const done = Math.round(Math.min(1, Math.max(0, doneRatio)) * BAR_WIDTH);
|
|
4422
|
+
const bar = paint.good("━".repeat(done)) + paint.dim("─".repeat(BAR_WIDTH - done));
|
|
4423
|
+
const seconds = Math.floor((nowMs() - startMs) / 1000);
|
|
4424
|
+
write(`${CLEAR_LINE}${bar} ${text}${paint.dim(` · ${seconds} s`)}`);
|
|
4425
|
+
};
|
|
4426
|
+
const timer = setInterval(render, 1000);
|
|
4427
|
+
timer.unref();
|
|
4428
|
+
return {
|
|
4429
|
+
step(next, ratio) {
|
|
4430
|
+
text = next;
|
|
4431
|
+
doneRatio = ratio;
|
|
4432
|
+
render();
|
|
4433
|
+
},
|
|
4434
|
+
clear() {
|
|
4435
|
+
clearInterval(timer);
|
|
4436
|
+
write(CLEAR_LINE);
|
|
4437
|
+
}
|
|
4438
|
+
};
|
|
4290
4439
|
}
|
|
4291
4440
|
|
|
4292
4441
|
// src/tsconfig.ts
|
|
@@ -4816,4 +4965,4 @@ async function plan2(options = {}) {
|
|
|
4816
4965
|
};
|
|
4817
4966
|
}
|
|
4818
4967
|
|
|
4819
|
-
export { version, githubOutputPath, BiviumError2, didYouMean, globToRegExp, defineConfig2, inRoot, sorted, QUERY, UNDECLARED_READS, RELATIVE, aliasPath, createResolver, SCANNED, formatOf, extract, stringsOf, finish, gotoPage, walksByTypes, importersOf, affectedBy, formatSelection, orphanOf, plural, computePlan, prepare, plan2 };
|
|
4968
|
+
export { version, githubOutputPath, nowMs, environment, agentVariable, BiviumError2, didYouMean, globToRegExp, defineConfig2, inRoot, sorted, QUERY, UNDECLARED_READS, RELATIVE, aliasPath, createResolver, SCANNED, formatOf, extract, stringsOf, finish, gotoPage, walksByTypes, importersOf, affectedBy, formatSelection, orphanOf, PLAIN, createPaint, wantsColor, SEPARATOR, branch, NOTE_INDENT, closingLine, failLine, truncateWords, truncatePath, textWidth, MEASURE, RULE, aligned, headerRow, plural, SILENT, createProgress, computePlan, prepare, plan2 };
|