@ref0/workspace 0.11.0 → 0.13.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 +68 -15
- package/dist/lint/generic/ast-fields.mjs +32 -0
- package/dist/lint/generic/build-cache-inputs.d.mts +9 -0
- package/dist/lint/generic/build-cache-inputs.mjs +147 -0
- package/dist/lint/generic/effect-gen-wrappers.d.mts +13 -0
- package/dist/lint/generic/effect-gen-wrappers.mjs +100 -0
- package/dist/lint/generic/plugin.d.mts +5 -2
- package/dist/lint/generic/plugin.mjs +15 -2
- package/dist/lint/generic/public-docs.d.mts +12 -0
- package/dist/lint/generic/public-docs.mjs +345 -0
- package/dist/lint/generic/pure-effect-fn.mjs +107 -0
- package/dist/lint/generic/pure-top-level.d.mts +44 -0
- package/dist/lint/generic/pure-top-level.mjs +393 -0
- package/dist/lint/generic/workspace-packages.d.mts +30 -1
- package/dist/lint/generic/workspace-packages.mjs +46 -5
- package/dist/lint/graph.d.mts +6 -2
- package/dist/lint/graph.mjs +2 -2
- package/dist/review-record/review-record.mjs +121 -26
- package/dist/review-record/settings.d.mts +14 -2
- package/dist/review-record/settings.mjs +10 -3
- package/dist/task-sources.d.mts +16 -0
- package/dist/task-sources.mjs +121 -0
- package/dist/types/cache.mjs +2 -2
- package/dist/types/inputs.mjs +23 -16
- package/package.json +10 -2
- package/tsconfig/base.json +20 -0
- package/tsconfig/bundler.json +8 -0
- package/tsconfig/node-next.json +8 -0
|
@@ -47,8 +47,9 @@ import { env } from "node:process";
|
|
|
47
47
|
*
|
|
48
48
|
* A bot's comment doesn't count, and a session counts only from someone who may push to the repo,
|
|
49
49
|
* since anyone may comment once it's public. A pull request whose author may not push needs a
|
|
50
|
-
* session at any tier, as review.md says
|
|
51
|
-
* `
|
|
50
|
+
* session at any tier, as review.md says, unless it's a bot's from a branch the base's `botBranches`
|
|
51
|
+
* names in the repo itself. It reads GitHub with `gh`, and the head's history with `git` from the
|
|
52
|
+
* checkout that holds it, whole.
|
|
52
53
|
*/
|
|
53
54
|
/** Net lines of production source from which a change is large and needs a code quality reviewer. */
|
|
54
55
|
const largeChange = 1e3;
|
|
@@ -139,14 +140,17 @@ const importLine = /^\s*(?:import\b|\}\s*from\b)/;
|
|
|
139
140
|
const fixtures = /\/fixtures\//;
|
|
140
141
|
/**
|
|
141
142
|
* Whether a path is production source, as the review skill counts a large change: one the settings'
|
|
142
|
-
* `productionSource` names, a package's or an app's `src/` unless a repo says
|
|
143
|
-
*
|
|
143
|
+
* `productionSource` names, a package's or an app's `src/` without its tests unless a repo says
|
|
144
|
+
* otherwise, and never a fixture.
|
|
144
145
|
*/
|
|
145
|
-
const isProductionSource = (path, settings = defaults) => matchesAny(settings.productionSource)(path) && !
|
|
146
|
-
/** Whether a path is test code or a fixture, which production source leaves out. */
|
|
146
|
+
const isProductionSource = (path, settings = defaults) => matchesAny(settings.productionSource)(path) && !fixtures.test(path);
|
|
147
|
+
/** Whether a path is test code or a fixture, which production source leaves out by default. */
|
|
147
148
|
const isTestOrFixture = (path, settings) => isTestCode(path, settings) || fixtures.test(path);
|
|
148
|
-
/**
|
|
149
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Whether a change renames test code or a fixture into production source, which counts whole: a
|
|
151
|
+
* file the settings already counted as production, as ref0's test scripts are, counts its edits.
|
|
152
|
+
*/
|
|
153
|
+
const movedIntoProduction = (change, settings) => change.previous_filename !== void 0 && isTestOrFixture(change.previous_filename, settings) && !isProductionSource(change.previous_filename, settings) && isProductionSource(change.filename, settings);
|
|
150
154
|
/**
|
|
151
155
|
* A change's net lines of production source: lines added less lines deleted, and a file moved into
|
|
152
156
|
* it from test code or a fixture whole, as `lines` counts it at the head, since its lines are new
|
|
@@ -230,10 +234,11 @@ const testChangesOf = (changes, settings) => {
|
|
|
230
234
|
lines: files.reduce((sum, file) => sum + file.lines, 0)
|
|
231
235
|
};
|
|
232
236
|
};
|
|
233
|
-
/**
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
+
/**
|
|
238
|
+
* A pull request's changed lines, additions plus deletions, as the tier limits count them, without
|
|
239
|
+
* the generated files the settings' `sizeUncounted` names.
|
|
240
|
+
*/
|
|
241
|
+
const changedLines = (changes, settings = defaults) => changes.filter((change) => !matchesAny(settings.sizeUncounted)(change.filename)).reduce((sum, change) => sum + change.additions + change.deletions, 0);
|
|
237
242
|
/** A patch's hunks, from its first `@@` line, past any header a git diff prints. */
|
|
238
243
|
const hunksOf = (patch) => {
|
|
239
244
|
const hunks = [];
|
|
@@ -345,8 +350,8 @@ const floorOf = (changes, list, net = 0, settings = defaults) => {
|
|
|
345
350
|
const { lowTierLines, highTierLines } = settings;
|
|
346
351
|
const isProduction = (path) => isProductionSource(path, settings);
|
|
347
352
|
const tierAt = list === void 0 ? (path) => isProduction(path) ? "high" : void 0 : tierOf(list);
|
|
348
|
-
const lines = changedLines(changes);
|
|
349
|
-
const counted = changes.flatMap((change) =>
|
|
353
|
+
const lines = changedLines(changes, settings);
|
|
354
|
+
const counted = changes.flatMap((change) => matchesAny(settings.sizeUncounted)(change.filename) ? [] : [change.filename]);
|
|
350
355
|
const reasons = [];
|
|
351
356
|
if (net >= 1e3) reasons.push({
|
|
352
357
|
tier: "high",
|
|
@@ -437,6 +442,70 @@ const linkOf = (token) => {
|
|
|
437
442
|
*/
|
|
438
443
|
const holdsReading = (line) => /\blocal\b/i.test(line) || line.split(/[\s|]+/).some((token) => runLink.test(linkOf(token)));
|
|
439
444
|
/**
|
|
445
|
+
* A batch line's ending, after its case's name: the Coordinator's rule that a case with no local
|
|
446
|
+
* form goes unbenched on a pull request and is read in ci-bench's batch run on main.
|
|
447
|
+
*/
|
|
448
|
+
const batchSkip = ": not run, read in the batch run on main (Coordinator)";
|
|
449
|
+
/** A batch line, whole: a case's name, in backticks or not, as a list item or not, then `batchSkip`. */
|
|
450
|
+
const batchLine = new RegExp(`^(?:[-*+] )?(\`?)([\\w.-]+)\\1${batchSkip.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`);
|
|
451
|
+
/** The case a line leaves to the batch run on main, as `batchLine` reads it, or `undefined`. */
|
|
452
|
+
const batchCaseOf = (line) => batchLine.exec(line.trim())?.[2];
|
|
453
|
+
/** The columns a line is indented by, a tab to the next stop of 4, as CommonMark counts them. */
|
|
454
|
+
const indentOf = (line) => {
|
|
455
|
+
let column = 0;
|
|
456
|
+
for (const char of line) if (char === " ") column += 1;
|
|
457
|
+
else if (char === " ") column += 4 - column % 4;
|
|
458
|
+
else break;
|
|
459
|
+
return column;
|
|
460
|
+
};
|
|
461
|
+
/** A list item's marker, and the spaces after it: its length from the line's indent is its content's. */
|
|
462
|
+
const listMarker = /^(?:[-*+]|\d{1,9}[.)])(?: +|$)/;
|
|
463
|
+
/** Text with its HTML comments and fenced code blocks taken out, as GitHub shows neither as prose. */
|
|
464
|
+
const withoutHidden = (text) => {
|
|
465
|
+
const shown = [];
|
|
466
|
+
let from = 0;
|
|
467
|
+
let at = 0;
|
|
468
|
+
while (at < text.length) {
|
|
469
|
+
fenceOpen.lastIndex = at;
|
|
470
|
+
const fence = at === 0 || text[at - 1] === "\n" ? fenceOpen.exec(text) : null;
|
|
471
|
+
const hidden = fence !== null ? pastFence(text, fenceOpen.lastIndex, fence[1] ?? "```") : text.startsWith("<!--", at) ? text.indexOf("-->", at + 4) : void 0;
|
|
472
|
+
if (hidden === void 0) {
|
|
473
|
+
at += 1;
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
shown.push(text.slice(from, at));
|
|
477
|
+
if (hidden === -1) return shown.join("");
|
|
478
|
+
at = fence !== null ? hidden : hidden + 3;
|
|
479
|
+
from = at;
|
|
480
|
+
}
|
|
481
|
+
shown.push(text.slice(from));
|
|
482
|
+
return shown.join("");
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* The lines of a body's fold that GitHub shows as prose: none inside an HTML comment or a code
|
|
486
|
+
* block, fenced or indented, so an example of a line never reads as the line itself. An indented
|
|
487
|
+
* block is 4 columns past the list item it's in, or past the margin outside any, after a blank line
|
|
488
|
+
* or another of its lines: a list item's own paragraphs, at 2, are prose.
|
|
489
|
+
*/
|
|
490
|
+
const shownLines = (fold) => {
|
|
491
|
+
let content = 0;
|
|
492
|
+
let blank = true;
|
|
493
|
+
let code = false;
|
|
494
|
+
return withoutHidden(fold).split("\n").filter((line) => {
|
|
495
|
+
if (line.trim() === "") {
|
|
496
|
+
blank = true;
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
const indent = indentOf(line);
|
|
500
|
+
code = indent >= content + 4 && (blank || code);
|
|
501
|
+
const marker = code ? null : listMarker.exec(line.trimStart());
|
|
502
|
+
if (marker !== null) content = indent + marker[0].length;
|
|
503
|
+
else if (!code && blank && indent < content) content = 0;
|
|
504
|
+
blank = false;
|
|
505
|
+
return !code;
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
/**
|
|
440
509
|
* Where the body's "Bench and cost" fold opens: a `<details>` tag whose summary reads so, in bold
|
|
441
510
|
* or not. A tag's name ends at `>` or HTML's own whitespace, so `<details-fake>` or a non-breaking
|
|
442
511
|
* space opens no fold.
|
|
@@ -558,20 +627,24 @@ const provenUnchanged = (line, record, lookup) => {
|
|
|
558
627
|
/**
|
|
559
628
|
* The bench cases the base's `benched-paths.txt` ties the changes to, and why the body's "Bench and
|
|
560
629
|
* cost" fold doesn't hold a reading for each: a line there that names the case whole and holds a
|
|
561
|
-
* run's link or the word local,
|
|
562
|
-
*
|
|
630
|
+
* run's link or the word local, a "bundle unchanged" line a run proves, `provenUnchanged`, or the
|
|
631
|
+
* case's batch line, `batchCaseOf`, each of the fold's lines GitHub shows as prose, `shownLines`.
|
|
632
|
+
* `batched` names the cases a batch line carries and no reading does, so the batch run can be
|
|
633
|
+
* checked against what pull requests left to it. A base with no list ties none.
|
|
563
634
|
*/
|
|
564
635
|
const benchReadings = (body, record, settings) => {
|
|
565
636
|
if (record.benched === void 0) return {
|
|
566
637
|
cases: [],
|
|
638
|
+
batched: [],
|
|
567
639
|
errors: []
|
|
568
640
|
};
|
|
569
641
|
const { cases, files } = benchedCases(record.benched, record.changes, settings);
|
|
570
|
-
const lines = benchFold(body)
|
|
642
|
+
const lines = shownLines(benchFold(body));
|
|
571
643
|
const claims = lines.filter((line) => unchangedClaim.test(line));
|
|
572
644
|
const linked = new Set(claims.flatMap(runsOf));
|
|
573
645
|
if (linked.size > 30) return {
|
|
574
646
|
cases,
|
|
647
|
+
batched: [],
|
|
575
648
|
errors: [`Its body's "bundle unchanged" lines link ${linked.size} runs, and review-record reads at most 30: link the one run that benched the set, ci-bench's \`pr\` dispatch.`]
|
|
576
649
|
};
|
|
577
650
|
const runs = /* @__PURE__ */ new Map();
|
|
@@ -581,10 +654,14 @@ const benchReadings = (body, record, settings) => {
|
|
|
581
654
|
};
|
|
582
655
|
const unproven = claims.filter((line) => !provenUnchanged(line, record, lookup));
|
|
583
656
|
const readings = lines.filter((line) => (unchangedClaim.test(line) || holdsReading(line)) && !unproven.includes(line));
|
|
584
|
-
const
|
|
657
|
+
const carried = new Set(lines.flatMap((line) => batchCaseOf(line) ?? []));
|
|
658
|
+
const read = (name) => readings.some((line) => names(line, name));
|
|
659
|
+
const batched = cases.filter((name) => carried.has(name) && !read(name));
|
|
660
|
+
const missing = cases.filter((name) => !carried.has(name) && !read(name));
|
|
585
661
|
return {
|
|
586
662
|
cases,
|
|
587
|
-
|
|
663
|
+
batched,
|
|
664
|
+
errors: [...unproven.map((line) => `Its body's "${line.trim()}" says a bundle is unchanged, and no run it links is ci-bench's on main with a passed "${unchangedJob(unchangedClaim.exec(line)?.[1] ?? "", record.pull ?? 0, record.head)}" job: link the ci-bench run of this pull request that wrote it, \`pr\`'s.`), ...missing.length === 0 ? [] : [`It changes benched paths, ${some(files)}, so its body's "Bench and cost" fold holds a reading for each case ${settings.benchedPaths ?? "the bench list"} ties them to, and holds none for ${some(missing, 5)}. Add a line for each that names the case with its ci-bench run's link, labelled local for a local pass, or as \`<case>${batchSkip}\`, as .agents/repo/review.md says.`]]
|
|
588
665
|
};
|
|
589
666
|
};
|
|
590
667
|
/**
|
|
@@ -729,7 +806,8 @@ const verdict = (record) => {
|
|
|
729
806
|
const { files: tests } = testChangesOf(record.changes, settings);
|
|
730
807
|
const missingBreaks = unbroken(body, record.changes, settings);
|
|
731
808
|
const bench = benchReadings(body, record, settings);
|
|
732
|
-
const
|
|
809
|
+
const batched = bench.batched.length > 0 ? `; batch: ${bench.batched.length} cases, ${some(bench.batched, 10)}` : "";
|
|
810
|
+
const benched = bench.cases.length > 0 ? `, with a bench reading for each of ${bench.cases.length} cases${batched}` : "";
|
|
733
811
|
const lowBreaks = missingBreaks.length > 0 ? [`This low-tier pull request changes test code with no break on record for ${some(missingBreaks)}. Add a "Break:" line to the body for each, naming its file, what you broke in the code and that the test failed, as test-audit's authoring gate asks.`] : [];
|
|
734
812
|
if (tier === "low" && record.outsider !== true) {
|
|
735
813
|
const errors = [...lowBreaks, ...bench.errors];
|
|
@@ -1159,6 +1237,14 @@ const countedComments = (github, repo, pull) => {
|
|
|
1159
1237
|
};
|
|
1160
1238
|
/** The reason a session comment from someone who may not push doesn't count, when there is one. */
|
|
1161
1239
|
const uncountedNote = (record) => record.uncounted === void 0 || record.uncounted.length === 0 ? "" : `: the sessions from ${record.uncounted.join(", ")} don't count, since they may not push to the repo`;
|
|
1240
|
+
/** The jq filter that reads the rest of a pull request's `PullAuthor`, beside its login. */
|
|
1241
|
+
const headFilter = "{type: .user.type, branch: .head.ref, from: (.head.repo.full_name // \"\")} | tojson";
|
|
1242
|
+
/**
|
|
1243
|
+
* Whether a pull request is a bot's from a branch the settings' `botBranches` names, in `repo`
|
|
1244
|
+
* itself and never a fork: only the repo's own workflows open one there, as a release's does, so its
|
|
1245
|
+
* author counts as one who may push. A bot's on any other branch is an outsider's.
|
|
1246
|
+
*/
|
|
1247
|
+
const fromBotBranch = (author, repo, settings) => author.type === "Bot" && author.from.toLowerCase() === repo.toLowerCase() && matchesAny(settings.botBranches)(author.branch);
|
|
1162
1248
|
/** A file at a commit, through GitHub's contents API, or `undefined` when the commit has none. */
|
|
1163
1249
|
const contentsAt = (github, repo, path, ref) => github([
|
|
1164
1250
|
"-H",
|
|
@@ -1174,6 +1260,19 @@ const contentsAt = (github, repo, path, ref) => github([
|
|
|
1174
1260
|
const recordOf = (github, git, repo, pull, base, head) => {
|
|
1175
1261
|
const settings = settingsFrom(contentsAt(github, repo, settingsPath, base));
|
|
1176
1262
|
const isTest = (path) => isTestCode(path, settings);
|
|
1263
|
+
const login = found(github, [
|
|
1264
|
+
`repos/${repo}/pulls/${pull}`,
|
|
1265
|
+
"--jq",
|
|
1266
|
+
".user.login"
|
|
1267
|
+
]).trim();
|
|
1268
|
+
const fromBot = () => settings.botBranches.length > 0 && fromBotBranch({
|
|
1269
|
+
login,
|
|
1270
|
+
...JSON.parse(found(github, [
|
|
1271
|
+
`repos/${repo}/pulls/${pull}`,
|
|
1272
|
+
"--jq",
|
|
1273
|
+
headFilter
|
|
1274
|
+
]))
|
|
1275
|
+
}, repo, settings);
|
|
1177
1276
|
return {
|
|
1178
1277
|
settings,
|
|
1179
1278
|
changedFiles: Number(found(github, [
|
|
@@ -1182,11 +1281,7 @@ const recordOf = (github, git, repo, pull, base, head) => {
|
|
|
1182
1281
|
".changed_files"
|
|
1183
1282
|
])),
|
|
1184
1283
|
...countedComments(github, repo, pull),
|
|
1185
|
-
outsider: !mayPush(github, repo,
|
|
1186
|
-
`repos/${repo}/pulls/${pull}`,
|
|
1187
|
-
"--jq",
|
|
1188
|
-
".user.login"
|
|
1189
|
-
]).trim()),
|
|
1284
|
+
outsider: !mayPush(github, repo, login) && !fromBot(),
|
|
1190
1285
|
body: found(github, [
|
|
1191
1286
|
`repos/${repo}/pulls/${pull}`,
|
|
1192
1287
|
"--jq",
|
|
@@ -1250,4 +1345,4 @@ const branchRecordOf = (git, comments = [], body = "") => {
|
|
|
1250
1345
|
lines: (path) => linesAt(git, head, path)
|
|
1251
1346
|
};
|
|
1252
1347
|
};
|
|
1253
|
-
export { benchRunOf, benchWorkflow, benchedCases, branchRecordOf, changedLines, changesOf, countedComments, coveredBy, floorOf, gh, gitIn, githubFileCap, historyOf, isProductionSource, isTestCode, largeChange, netProductionLines, pullChangesOf, readSession, recordFloor, recordOf, testChangesOf, testRisks, testsOnly, tierOf, tiers, unchangedJob, verdict };
|
|
1348
|
+
export { benchRunOf, benchWorkflow, benchedCases, branchRecordOf, changedLines, changesOf, countedComments, coveredBy, floorOf, fromBotBranch, gh, gitIn, githubFileCap, historyOf, isProductionSource, isTestCode, largeChange, netProductionLines, pullChangesOf, readSession, recordFloor, recordOf, testChangesOf, testRisks, testsOnly, tierOf, tiers, unchangedJob, verdict };
|
|
@@ -13,8 +13,9 @@ export interface Settings {
|
|
|
13
13
|
/** Changed lines up to which a pull request may be medium: past them its floor is high. */
|
|
14
14
|
readonly highTierLines: number;
|
|
15
15
|
/**
|
|
16
|
-
* Production source, as globs, whose net lines count toward a large change.
|
|
17
|
-
*
|
|
16
|
+
* Production source, as globs, whose net lines count toward a large change. The globs name what
|
|
17
|
+
* they leave out, test code among it, with `!` entries, so a repo may count a test script as
|
|
18
|
+
* production when its old gate did. Fixtures are left out whatever the globs name.
|
|
18
19
|
*/
|
|
19
20
|
readonly productionSource: ReadonlyArray<string>;
|
|
20
21
|
/**
|
|
@@ -34,6 +35,17 @@ export interface Settings {
|
|
|
34
35
|
readonly benchedPaths: string | undefined;
|
|
35
36
|
/** Files under a `testing/` folder that a bench case runs all the same, so a change to one owes its readings. */
|
|
36
37
|
readonly benchRuns: ReadonlyArray<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Generated files, as globs, whose lines a pull request's size leaves out, though the
|
|
40
|
+
* always-review list and the test code rules still read them.
|
|
41
|
+
*/
|
|
42
|
+
readonly sizeUncounted: ReadonlyArray<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Head branches, as globs, from which a bot's pull request in the repo itself, never a fork's,
|
|
45
|
+
* counts as one from someone who may push: only the repo's own workflows open one there, as a
|
|
46
|
+
* release's does.
|
|
47
|
+
*/
|
|
48
|
+
readonly botBranches: ReadonlyArray<string>;
|
|
37
49
|
}
|
|
38
50
|
/** `settingsOf`'s settings, which throws on a problem, as the gate does on anything it can't read. */
|
|
39
51
|
export declare const settingsFrom: (text: string | undefined) => Settings;
|
|
@@ -26,7 +26,9 @@ const File = Schema.Struct({
|
|
|
26
26
|
testCode: Schema.optionalKey(Globs),
|
|
27
27
|
testHelpers: Schema.optionalKey(Globs),
|
|
28
28
|
benchedPaths: Schema.optionalKey(Schema.String),
|
|
29
|
-
benchRuns: Schema.optionalKey(Schema.Array(Schema.String))
|
|
29
|
+
benchRuns: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
30
|
+
sizeUncounted: Schema.optionalKey(Globs),
|
|
31
|
+
botBranches: Schema.optionalKey(Globs)
|
|
30
32
|
});
|
|
31
33
|
/** Each setting's value when the file leaves it out: ref-0/git's, where the gate began. */
|
|
32
34
|
const defaults = {
|
|
@@ -62,7 +64,10 @@ const defaults = {
|
|
|
62
64
|
"packages/*/src/*.ts",
|
|
63
65
|
"packages/*/src/*.tsx",
|
|
64
66
|
"apps/*/src/*.ts",
|
|
65
|
-
"apps/*/src/*.tsx"
|
|
67
|
+
"apps/*/src/*.tsx",
|
|
68
|
+
"!*.test.ts",
|
|
69
|
+
"!*.test-d.ts",
|
|
70
|
+
"!*/testing/*"
|
|
66
71
|
],
|
|
67
72
|
testCode: [
|
|
68
73
|
"*.test.ts",
|
|
@@ -71,7 +76,9 @@ const defaults = {
|
|
|
71
76
|
],
|
|
72
77
|
testHelpers: ["*/testing/*"],
|
|
73
78
|
benchedPaths: void 0,
|
|
74
|
-
benchRuns: []
|
|
79
|
+
benchRuns: [],
|
|
80
|
+
sizeUncounted: ["pnpm-lock.yaml"],
|
|
81
|
+
botBranches: []
|
|
75
82
|
};
|
|
76
83
|
const decodeFile = Schema.decodeUnknownResult(Schema.fromJsonString(File), { onExcessProperty: "error" });
|
|
77
84
|
/**
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Workspace } from "./lint/generic/workspace-packages.mjs";
|
|
2
|
+
declare global {
|
|
3
|
+
var ref0WorkspaceTaskSources: Map<string, ReadonlyMap<string, string> | null> | undefined;
|
|
4
|
+
}
|
|
5
|
+
/** A hash of the files under `folders`, from the root, `''` for all of them, but tests unless asked. */
|
|
6
|
+
export declare const sourcesHash: (ids: ReadonlyMap<string, string>, folders: ReadonlyArray<string>, tests: boolean) => string;
|
|
7
|
+
/**
|
|
8
|
+
* The task commands of a workspace: `builtFrom`, a package's build command, from its
|
|
9
|
+
* `vite.config.ts`'s `import.meta.url`, keyed by its folder and the workspace packages it depends
|
|
10
|
+
* on, but their tests; and `readsAll`, a command that reads the whole workspace, such as lint's,
|
|
11
|
+
* keyed by every file.
|
|
12
|
+
*/
|
|
13
|
+
export declare const taskSources: (workspace: Workspace) => {
|
|
14
|
+
builtFrom: (config: string, command: string) => string;
|
|
15
|
+
readsAll: (command: string) => string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { dependedOn, fromRoot, workspacePackages } from "./lint/generic/workspace-packages.mjs";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { env } from "node:process";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
// src/task-sources.ts
|
|
9
|
+
/**
|
|
10
|
+
* A cached task's command with its sources' contents in it, so that Vite Task's key holds them.
|
|
11
|
+
*
|
|
12
|
+
* Vite Task keys a task by its command, arguments, folder and named variables, and keeps the
|
|
13
|
+
* files it read, with their hashes, in the result. The remote tier keeps one result a key, so two
|
|
14
|
+
* branches that build one package from different sources replace each other's result, and the
|
|
15
|
+
* next run on either misses: on 8 Nov a new worktree, at the commit another had just built and
|
|
16
|
+
* uploaded, replayed 3 of 12 builds and no lint, every miss naming a file only another branch had.
|
|
17
|
+
* With the sources' hash in the command, each set of contents has a key of its own, and any
|
|
18
|
+
* checkout at those contents, CI's too, finds it. The files read are still checked on a replay.
|
|
19
|
+
*
|
|
20
|
+
* The hash is of each file's Git object ID, as the checkout holds it: from Git's index, or, for a
|
|
21
|
+
* file changed or added and not ignored, hashed as Git would. Ignored files, such as the
|
|
22
|
+
* compiler's generated bundles, are left out, so two checkouts that differ only there share a key,
|
|
23
|
+
* and the files read still tell them apart. A build's sources are its package's folder and each
|
|
24
|
+
* workspace package it depends on, but their test files, with the lockfile, the workspace file and
|
|
25
|
+
* `tsconfig.base.json`. Lint's are every file.
|
|
26
|
+
*
|
|
27
|
+
* A command that `&&` joins from several takes the hash on each, as web's and overlord's staging
|
|
28
|
+
* builds do, a build and then Wrangler's dry run of its deploy. Vite Task may keep a result for
|
|
29
|
+
* each joined command, as it did for those two before they had the hash, or one for them all, as
|
|
30
|
+
* it does with it, on 9 Nov 2026: either way, every key holds the hash.
|
|
31
|
+
*
|
|
32
|
+
* Only the run that plans the tasks adds it: a task's own processes, which Vite Task marks with
|
|
33
|
+
* `VP_RUN`, load the same config, where the command is never read. Outside Git, the command is
|
|
34
|
+
* left as it is.
|
|
35
|
+
*/
|
|
36
|
+
const git = (root, args, input = "") => execFileSync("git", args, {
|
|
37
|
+
cwd: root,
|
|
38
|
+
encoding: "utf8",
|
|
39
|
+
input,
|
|
40
|
+
maxBuffer: 268435456,
|
|
41
|
+
stdio: [
|
|
42
|
+
"pipe",
|
|
43
|
+
"pipe",
|
|
44
|
+
"ignore"
|
|
45
|
+
]
|
|
46
|
+
});
|
|
47
|
+
/** Each file's Git object ID, from the root, as the checkout holds it, or none outside Git. */
|
|
48
|
+
const listObjects = (root) => {
|
|
49
|
+
try {
|
|
50
|
+
const ids = /* @__PURE__ */ new Map();
|
|
51
|
+
for (const entry of git(root, [
|
|
52
|
+
"ls-files",
|
|
53
|
+
"--stage",
|
|
54
|
+
"-z"
|
|
55
|
+
]).split("\0")) {
|
|
56
|
+
const tab = entry.indexOf(" ");
|
|
57
|
+
if (tab === -1) continue;
|
|
58
|
+
ids.set(entry.slice(tab + 1), entry.slice(0, tab).split(" ")[1] ?? "");
|
|
59
|
+
}
|
|
60
|
+
const changed = git(root, [
|
|
61
|
+
"ls-files",
|
|
62
|
+
"--modified",
|
|
63
|
+
"--others",
|
|
64
|
+
"--exclude-standard",
|
|
65
|
+
"-z"
|
|
66
|
+
]).split("\0").filter((path) => path !== "" && !path.includes("\n"));
|
|
67
|
+
const present = changed.filter((path) => existsSync(join(root, path)));
|
|
68
|
+
for (const path of changed) ids.delete(path);
|
|
69
|
+
const hashed = present.length === 0 ? [] : git(root, ["hash-object", "--stdin-paths"], present.join("\n")).split("\n");
|
|
70
|
+
for (const [index, path] of present.entries()) ids.set(path, hashed[index] ?? "");
|
|
71
|
+
return ids;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const objects = (root) => {
|
|
77
|
+
globalThis.ref0WorkspaceTaskSources ??= /* @__PURE__ */ new Map();
|
|
78
|
+
const known = globalThis.ref0WorkspaceTaskSources.get(root);
|
|
79
|
+
if (known !== void 0) return known;
|
|
80
|
+
const listed = listObjects(root);
|
|
81
|
+
globalThis.ref0WorkspaceTaskSources.set(root, listed);
|
|
82
|
+
return listed;
|
|
83
|
+
};
|
|
84
|
+
/** Every build reads these, as its inputs name them. */
|
|
85
|
+
const shared = /* @__PURE__ */ new Set([
|
|
86
|
+
"pnpm-lock.yaml",
|
|
87
|
+
"pnpm-workspace.yaml",
|
|
88
|
+
"tsconfig.base.json"
|
|
89
|
+
]);
|
|
90
|
+
const testFile = /\.test\.[cm]?[jt]sx?$/u;
|
|
91
|
+
/** A hash of the files under `folders`, from the root, `''` for all of them, but tests unless asked. */
|
|
92
|
+
const sourcesHash = (ids, folders, tests) => {
|
|
93
|
+
const within = (path) => shared.has(path) || folders.some((folder) => folder === "" || path.startsWith(`${folder}/`));
|
|
94
|
+
const entries = [...ids].flatMap(([path, id]) => within(path) && (tests || !testFile.test(path)) ? [`${path}\0${id}`] : []);
|
|
95
|
+
entries.sort();
|
|
96
|
+
return createHash("sha256").update(entries.join("\n")).digest("hex").slice(0, 16);
|
|
97
|
+
};
|
|
98
|
+
const keyed = (root, command, folders, tests) => {
|
|
99
|
+
if (env["VP_RUN"] !== void 0) return command;
|
|
100
|
+
const ids = objects(root);
|
|
101
|
+
if (ids === null) return command;
|
|
102
|
+
const sources = `env REF0_SOURCES=${sourcesHash(ids, folders, tests)}`;
|
|
103
|
+
return command.split(" && ").map((part) => `${sources} ${part}`).join(" && ");
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The task commands of a workspace: `builtFrom`, a package's build command, from its
|
|
107
|
+
* `vite.config.ts`'s `import.meta.url`, keyed by its folder and the workspace packages it depends
|
|
108
|
+
* on, but their tests; and `readsAll`, a command that reads the whole workspace, such as lint's,
|
|
109
|
+
* keyed by every file.
|
|
110
|
+
*/
|
|
111
|
+
const taskSources = (workspace) => ({
|
|
112
|
+
builtFrom: (config, command) => {
|
|
113
|
+
const directory = fromRoot(workspace.root, dirname(fileURLToPath(config)));
|
|
114
|
+
const packages = workspacePackages(workspace);
|
|
115
|
+
const own = [...packages.values()].find((found) => found.directory === directory);
|
|
116
|
+
const dependencies = own === void 0 ? [] : [...dependedOn(own.name, packages).values()];
|
|
117
|
+
return keyed(workspace.root, command, [directory, ...dependencies.map((dependency) => dependency.directory)], false);
|
|
118
|
+
},
|
|
119
|
+
readsAll: (command) => keyed(workspace.root, command, [""], true)
|
|
120
|
+
});
|
|
121
|
+
export { sourcesHash, taskSources };
|
package/dist/types/cache.mjs
CHANGED
|
@@ -15,8 +15,8 @@ import { mkdir, readFile, readdir, rename, stat, unlink, utimes, writeFile } fro
|
|
|
15
15
|
* A project's key hashes the contents of every file its program read, as tsrs's `--listFiles`
|
|
16
16
|
* named them, except the packages under `node_modules/.pnpm/`, which the lockfile pins. It also
|
|
17
17
|
* hashes what decides which files a program reads and how: the lockfile, `pnpm-workspace.yaml`,
|
|
18
|
-
* every `package.json` and `tsconfig*.json` in the workspace and each file a config's
|
|
19
|
-
*
|
|
18
|
+
* every `package.json` and `tsconfig*.json` in the workspace and each file a config's chain of
|
|
19
|
+
* `extends` reaches, the path of every file a project includes, and tsrs's arguments. So an edit to any file
|
|
20
20
|
* a program read moves that project's key, and adding, removing or renaming a project's file moves
|
|
21
21
|
* every key. Contents are hashed rather than dated, since each worktree is a fresh checkout, and
|
|
22
22
|
* every path is from the worktree's root, so two worktrees at the same contents share a key. A
|
package/dist/types/inputs.mjs
CHANGED
|
@@ -37,30 +37,37 @@ const workspaceFiles = (root) => {
|
|
|
37
37
|
return walk("");
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
+
/** The workspace files `file`'s `extends` names, from the root: those outside it, as a package's, aren't. */
|
|
41
|
+
const extendedBy = (root, file) => {
|
|
42
|
+
const text = (() => {
|
|
43
|
+
try {
|
|
44
|
+
return readFileSync(join(root, file), "utf8");
|
|
45
|
+
} catch {
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
return [...(/"extends"\s*:\s*(\[[^\]]*\]|"[^"]*")/.exec(text)?.[1] ?? "").matchAll(/"(\.[^"]*)"/g)].flatMap(([, target = ""]) => {
|
|
50
|
+
const path = relative(root, resolve(root, dirname(file), target));
|
|
51
|
+
return path.startsWith("..") ? [] : [path];
|
|
52
|
+
});
|
|
53
|
+
};
|
|
40
54
|
/**
|
|
41
55
|
* The lockfile, the workspace's settings, every `package.json` and `tsconfig*.json` in `files`,
|
|
42
|
-
* and each workspace file a config's `extends`
|
|
43
|
-
* files a resolver reads and how it reads them.
|
|
56
|
+
* and each workspace file a config's chain of `extends` reaches, from the root, sorted: what
|
|
57
|
+
* decides which files a resolver reads and how it reads them.
|
|
44
58
|
*/
|
|
45
59
|
const manifestInputs = (root, files) => {
|
|
46
60
|
const manifests = files.filter((file) => {
|
|
47
61
|
const name = basename(file);
|
|
48
62
|
return name === "package.json" || /^tsconfig.*\.json$/.test(name);
|
|
49
63
|
});
|
|
50
|
-
const extended =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
})();
|
|
59
|
-
return [...(/"extends"\s*:\s*(\[[^\]]*\]|"[^"]*")/.exec(text)?.[1] ?? "").matchAll(/"(\.[^"]*)"/g)].flatMap(([, target = ""]) => {
|
|
60
|
-
const path = relative(root, resolve(root, dirname(file), target));
|
|
61
|
-
return path.startsWith("..") ? [] : [path];
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
+
const extended = /* @__PURE__ */ new Set();
|
|
65
|
+
const toRead = manifests.filter((file) => basename(file) !== "package.json");
|
|
66
|
+
for (let file = toRead.pop(); file !== void 0; file = toRead.pop()) for (const target of extendedBy(root, file)) {
|
|
67
|
+
if (extended.has(target)) continue;
|
|
68
|
+
extended.add(target);
|
|
69
|
+
toRead.push(target);
|
|
70
|
+
}
|
|
64
71
|
return [.../* @__PURE__ */ new Set([
|
|
65
72
|
"pnpm-lock.yaml",
|
|
66
73
|
"pnpm-workspace.yaml",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ref0/workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "The lint and workspace checks every ref-0 repo shares",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dist",
|
|
16
16
|
"!dist/**/*.test.*",
|
|
17
17
|
"!dist/**/fixtures",
|
|
18
|
+
"tsconfig",
|
|
18
19
|
"README.md",
|
|
19
20
|
"LICENSE"
|
|
20
21
|
],
|
|
@@ -33,10 +34,17 @@
|
|
|
33
34
|
"types": "./dist/lint/graph.d.mts",
|
|
34
35
|
"import": "./dist/lint/graph.mjs"
|
|
35
36
|
},
|
|
37
|
+
"./task-sources": {
|
|
38
|
+
"types": "./dist/task-sources.d.mts",
|
|
39
|
+
"import": "./dist/task-sources.mjs"
|
|
40
|
+
},
|
|
36
41
|
"./review-record": {
|
|
37
42
|
"types": "./dist/review-record/index.d.mts",
|
|
38
43
|
"import": "./dist/review-record/index.mjs"
|
|
39
|
-
}
|
|
44
|
+
},
|
|
45
|
+
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
46
|
+
"./tsconfig/bundler.json": "./tsconfig/bundler.json",
|
|
47
|
+
"./tsconfig/node-next.json": "./tsconfig/node-next.json"
|
|
40
48
|
},
|
|
41
49
|
"publishConfig": {
|
|
42
50
|
"access": "public"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowUnreachableCode": false,
|
|
5
|
+
"allowUnusedLabels": false,
|
|
6
|
+
"exactOptionalPropertyTypes": true,
|
|
7
|
+
"isolatedModules": true,
|
|
8
|
+
"moduleDetection": "force",
|
|
9
|
+
"noFallthroughCasesInSwitch": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noImplicitReturns": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"noUnusedParameters": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"strict": true,
|
|
17
|
+
"target": "ES2023",
|
|
18
|
+
"verbatimModuleSyntax": true
|
|
19
|
+
}
|
|
20
|
+
}
|