@antelopejs/tooling-configs 0.2.16 → 0.2.18
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 +101 -52
- package/dist/bin/api-diff.mjs +430 -107
- package/dist/bin/body-check.d.mts +1 -0
- package/dist/bin/body-check.mjs +344 -0
- package/dist/bin/capture.d.mts +1 -0
- package/dist/bin/capture.mjs +559 -0
- package/dist/bin/check-size.mjs +3 -3
- package/dist/bin/checks.mjs +3 -3
- package/dist/bin/comment-proof.mjs +4 -3
- package/dist/bin/garden.mjs +6 -6
- package/dist/bin/ratchet.mjs +316 -10
- package/dist/bin/suppressions.mjs +118 -80
- package/dist/bin/sync.mjs +554 -153
- package/dist/bin/verify.mjs +240 -127
- package/dist/capture/index.d.mts +50 -0
- package/dist/capture/index.mjs +2 -0
- package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
- package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
- package/dist/{ci-workflow-DIsoEgMd.mjs → ci-workflow-ChW4He0r.mjs} +84 -3
- package/dist/{files-2FikHZ9F.mjs → files-DJ0TeaTU.mjs} +11 -5
- package/dist/formal/index.d.mts +40 -0
- package/dist/formal/index.mjs +205 -0
- package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
- package/dist/oxc/anti-slop/index.mjs +869 -21
- package/dist/oxc/fmt.mjs +1 -1
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +736 -4
- package/dist/oxc/lint.d.mts +20 -3
- package/dist/oxc/lint.mjs +34 -10
- package/dist/oxlint-DIV-lLSS.mjs +98 -0
- package/dist/{package-Dtjt_lSa.mjs → package-BRTjkzt5.mjs} +29 -3
- package/dist/proof-stamp-DDDC0J6l.mjs +279 -0
- package/dist/ratchet-BAcLRYuM.mjs +448 -0
- package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
- package/dist/scenes-DZVXkcxS.mjs +104 -0
- package/dist/shared-igPpEDpS.mjs +622 -0
- package/dist/{size-BVgNbLO6.mjs → size-DBatLT-F.mjs} +4 -4
- package/dist/suppression-base-9L8dlMQK.mjs +120 -0
- package/dist/suppression-budget-C0SkPO5R.mjs +535 -0
- package/dist/{suppressions-BJAngUxo.mjs → suppressions-DM60NkvL.mjs} +180 -18
- package/dist/templates-CypDm-j9.mjs +121 -0
- package/dist/typescript-CM0LrVP7.mjs +222 -0
- package/dist/verify/index.d.mts +6 -1
- package/dist/verify/index.mjs +1 -1
- package/package.json +31 -5
- package/dist/kinds-Bzyyi9yk.mjs +0 -25
- package/dist/ratchet-DRdIYwmv.mjs +0 -80
- package/dist/shared-CsXIMK3I.mjs +0 -34
- package/dist/staged-ratchet-CjoRfZaM.mjs +0 -236
- package/dist/suppression-budget-Yyf5_J5l.mjs +0 -283
- package/dist/typescript-C54ONh9m.mjs +0 -433
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { a as formatCeilings, c as parseCeilings, n as MAX_FILE_BYTES, o as isPackRelease, s as isRetired, t as CEILINGS_FILE } from "./ceilings-B7KayYIG.mjs";
|
|
2
|
+
import { n as renamedPaths, t as readCarriedCeilings } from "./renames-L2owF5GD.mjs";
|
|
3
|
+
import { s as toolingVersions } from "./package-BRTjkzt5.mjs";
|
|
4
|
+
import { n as authoredSizes, o as isAgentFile, r as changedFiles, t as LINT_CONFIG } from "./files-DJ0TeaTU.mjs";
|
|
5
|
+
import { t as lintDiagnostics } from "./oxlint-DIV-lLSS.mjs";
|
|
6
|
+
import "./suppression-budget-C0SkPO5R.mjs";
|
|
7
|
+
import { n as sizeFailure } from "./size-DBatLT-F.mjs";
|
|
8
|
+
import { copyFileSync, existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
//#region src/guardrails/adoption.ts
|
|
13
|
+
/**
|
|
14
|
+
* Each rule the preset turned on after repositories recorded their ratchet,
|
|
15
|
+
* with the first pack release that enables it: the release after the
|
|
16
|
+
* `version` in package.json when the rule lands. `ratchet:update` records
|
|
17
|
+
* today's count of a listed rule once, in a repository whose recorded release
|
|
18
|
+
* predates it; a rule not listed here is never adopted.
|
|
19
|
+
*/
|
|
20
|
+
const PACK_NEW_RULES = /* @__PURE__ */ new Map([
|
|
21
|
+
["antelopejs/no-inherited-key-lookup", "0.2.17"],
|
|
22
|
+
["antelopejs/no-presence-only-type-guard", "0.2.17"],
|
|
23
|
+
["antelopejs/require-tsconfig-include", "0.2.18"],
|
|
24
|
+
["typescript/no-unnecessary-type-parameters", "0.2.17"],
|
|
25
|
+
["typescript/no-unsafe-argument", "0.2.17"],
|
|
26
|
+
["typescript/no-unsafe-assignment", "0.2.17"],
|
|
27
|
+
["typescript/no-unsafe-return", "0.2.17"],
|
|
28
|
+
["typescript/use-unknown-in-catch-callback-variable", "0.2.17"]
|
|
29
|
+
]);
|
|
30
|
+
/** The first pack release whose size guard counts a repository's own files under the agent directories; `ratchet:update` records the oversize ones once, in a repository recorded before it. */
|
|
31
|
+
const AGENT_FILES_RELEASE = "0.2.18";
|
|
32
|
+
function parts(release) {
|
|
33
|
+
return release.split(".").map(Number);
|
|
34
|
+
}
|
|
35
|
+
/** Orders two `major.minor.patch` releases. */
|
|
36
|
+
function compareReleases(a, b) {
|
|
37
|
+
const [left, right] = [parts(a), parts(b)];
|
|
38
|
+
for (let index = 0; index < 3; index += 1) if (left[index] !== right[index]) return left[index] - right[index];
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
function latest(releases) {
|
|
42
|
+
let best;
|
|
43
|
+
for (const release of releases) if (release !== void 0 && isPackRelease(release) && (best === void 0 || compareReleases(release, best) > 0)) best = release;
|
|
44
|
+
return best;
|
|
45
|
+
}
|
|
46
|
+
function show(root, revision, path) {
|
|
47
|
+
const result = spawnSync("git", ["show", `${revision}:${path}`], {
|
|
48
|
+
cwd: root,
|
|
49
|
+
encoding: "utf8"
|
|
50
|
+
});
|
|
51
|
+
return result.status === 0 ? result.stdout : void 0;
|
|
52
|
+
}
|
|
53
|
+
const LOCKED = [{
|
|
54
|
+
file: "pnpm-lock.yaml",
|
|
55
|
+
pattern: /^ {6}'@antelopejs\/tooling-configs':\n {8}specifier: [^\n]*\n {8}version: (\d+\.\d+\.\d+)/mu
|
|
56
|
+
}, {
|
|
57
|
+
file: "package-lock.json",
|
|
58
|
+
pattern: /"node_modules\/@antelopejs\/tooling-configs":\s*\{[^{}]*?"version":\s*"(\d+\.\d+\.\d+)"/u
|
|
59
|
+
}];
|
|
60
|
+
/** The pack release the root importer of the pnpm or npm lockfile at `revision` installs. */
|
|
61
|
+
function lockedRelease(root, revision) {
|
|
62
|
+
let release;
|
|
63
|
+
for (const { file, pattern } of LOCKED) {
|
|
64
|
+
const text = show(root, revision, file);
|
|
65
|
+
if (text !== void 0) {
|
|
66
|
+
release = pattern.exec(text)?.[1];
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return latest([release]);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The release a repository adopted the pack-new rules up to: the later of
|
|
74
|
+
* its ratchet's record and the pack its lockfile at `revision` installs. A
|
|
75
|
+
* repository with neither predates every listed rule.
|
|
76
|
+
*/
|
|
77
|
+
function adoptedRelease(root, recorded, revision) {
|
|
78
|
+
return latest([recorded, revision === void 0 ? void 0 : lockedRelease(root, revision)]);
|
|
79
|
+
}
|
|
80
|
+
/** The release that enabled `rule` when it is later than `adopted`, else undefined. */
|
|
81
|
+
function newlyEnabled(rule, adopted) {
|
|
82
|
+
const since = PACK_NEW_RULES.get(rule);
|
|
83
|
+
if (since === void 0) return void 0;
|
|
84
|
+
return adopted === void 0 || compareReleases(since, adopted) > 0 ? since : void 0;
|
|
85
|
+
}
|
|
86
|
+
/** Whether `adopted` predates the release that began counting the repository's own agent files in the size guard. */
|
|
87
|
+
function agentFilesPending(adopted) {
|
|
88
|
+
return adopted === void 0 || compareReleases("0.2.18", adopted) > 0;
|
|
89
|
+
}
|
|
90
|
+
/** The release an update records: the latest of `adopted`, the installed pack and every listed rule's release and the agent files' release, so none is adopted twice. */
|
|
91
|
+
function recordedRelease(adopted) {
|
|
92
|
+
return latest([
|
|
93
|
+
adopted,
|
|
94
|
+
toolingVersions().pack,
|
|
95
|
+
"0.2.18",
|
|
96
|
+
...PACK_NEW_RULES.values()
|
|
97
|
+
]) ?? "0.0.0";
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/guardrails/previous-tree.ts
|
|
101
|
+
function git(root, args, env, input = "") {
|
|
102
|
+
return execFileSync("git", args, {
|
|
103
|
+
cwd: root,
|
|
104
|
+
encoding: "utf8",
|
|
105
|
+
env: {
|
|
106
|
+
...process.env,
|
|
107
|
+
...env
|
|
108
|
+
},
|
|
109
|
+
input,
|
|
110
|
+
maxBuffer: 268435456
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function revisionEntries(root, revision) {
|
|
114
|
+
const entries = /* @__PURE__ */ new Map();
|
|
115
|
+
for (const entry of git(root, [
|
|
116
|
+
"ls-tree",
|
|
117
|
+
"-r",
|
|
118
|
+
"-z",
|
|
119
|
+
revision
|
|
120
|
+
], {}).split("\0")) {
|
|
121
|
+
const tab = entry.indexOf(" ");
|
|
122
|
+
if (tab > 0) entries.set(entry.slice(tab + 1), entry.slice(0, tab));
|
|
123
|
+
}
|
|
124
|
+
return entries;
|
|
125
|
+
}
|
|
126
|
+
/** Links the `node_modules` of the repository root and of each tracked package into `tree`, so the checkout resolves dependencies as the real one does. */
|
|
127
|
+
function linkModules(root, tree, env) {
|
|
128
|
+
const manifests = git(root, [
|
|
129
|
+
"ls-files",
|
|
130
|
+
"-z",
|
|
131
|
+
"--",
|
|
132
|
+
"package.json",
|
|
133
|
+
":(glob)**/package.json"
|
|
134
|
+
], env).split("\0").filter(Boolean);
|
|
135
|
+
for (const manifest of manifests) {
|
|
136
|
+
const directory = dirname(manifest);
|
|
137
|
+
const modules = join(root, directory, "node_modules");
|
|
138
|
+
const target = join(tree, directory, "node_modules");
|
|
139
|
+
if (existsSync(modules) && !existsSync(target)) symlinkSync(modules, target, "dir");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Runs `use` on a checkout of the index in which each of `paths` holds its
|
|
144
|
+
* content at `revision`, or is absent when `revision` does not have it or does
|
|
145
|
+
* not exist, so the files are linted under the staged configuration. The
|
|
146
|
+
* checkout is deleted afterwards. With `wholeIndex`, files the index marks
|
|
147
|
+
* skip-worktree (a sparse checkout) are written too, so the tree is the commit,
|
|
148
|
+
* and an empty `.git` stops ignore-file lookups at the tree, not above `TMPDIR`.
|
|
149
|
+
*/
|
|
150
|
+
function withPreviousTree(root, revision, paths, use, { wholeIndex = false } = {}) {
|
|
151
|
+
const scratch = mkdtempSync(join(tmpdir(), "antelopejs-previous."));
|
|
152
|
+
try {
|
|
153
|
+
const exists = spawnSync("git", [
|
|
154
|
+
"rev-parse",
|
|
155
|
+
"--verify",
|
|
156
|
+
`${revision}^{commit}`
|
|
157
|
+
], {
|
|
158
|
+
cwd: root,
|
|
159
|
+
stdio: "ignore"
|
|
160
|
+
}).status === 0;
|
|
161
|
+
const index = join(scratch, "index");
|
|
162
|
+
copyFileSync(git(root, [
|
|
163
|
+
"rev-parse",
|
|
164
|
+
"--path-format=absolute",
|
|
165
|
+
"--git-path",
|
|
166
|
+
"index"
|
|
167
|
+
], {}).trim(), index);
|
|
168
|
+
const env = { GIT_INDEX_FILE: index };
|
|
169
|
+
const head = exists ? revisionEntries(root, revision) : /* @__PURE__ */ new Map();
|
|
170
|
+
const restored = paths.filter((path) => head.has(path));
|
|
171
|
+
const removed = paths.filter((path) => !head.has(path));
|
|
172
|
+
if (restored.length) git(root, [
|
|
173
|
+
"update-index",
|
|
174
|
+
"-z",
|
|
175
|
+
"--index-info"
|
|
176
|
+
], env, restored.map((path) => `${head.get(path)}\t${path}\0`).join(""));
|
|
177
|
+
if (removed.length) git(root, [
|
|
178
|
+
"update-index",
|
|
179
|
+
"-z",
|
|
180
|
+
"--force-remove",
|
|
181
|
+
"--stdin"
|
|
182
|
+
], env, removed.map((path) => `${path}\0`).join(""));
|
|
183
|
+
const tree = join(scratch, "tree");
|
|
184
|
+
git(root, [
|
|
185
|
+
"checkout-index",
|
|
186
|
+
"-a",
|
|
187
|
+
"-f",
|
|
188
|
+
...wholeIndex ? ["--ignore-skip-worktree-bits"] : [],
|
|
189
|
+
`--prefix=${tree}/`
|
|
190
|
+
], env);
|
|
191
|
+
if (wholeIndex) mkdirSync(join(tree, ".git"), { recursive: true });
|
|
192
|
+
linkModules(root, tree, env);
|
|
193
|
+
return use(tree);
|
|
194
|
+
} finally {
|
|
195
|
+
rmSync(scratch, {
|
|
196
|
+
recursive: true,
|
|
197
|
+
force: true
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/guardrails/ratchet-raises.ts
|
|
203
|
+
function committed(root, revision, path) {
|
|
204
|
+
const result = spawnSync("git", ["show", `${revision}:${path}`], {
|
|
205
|
+
cwd: root,
|
|
206
|
+
encoding: "utf8"
|
|
207
|
+
});
|
|
208
|
+
return result.status === 0 ? result.stdout : void 0;
|
|
209
|
+
}
|
|
210
|
+
function committedSize(root, revision, path) {
|
|
211
|
+
const result = spawnSync("git", [
|
|
212
|
+
"cat-file",
|
|
213
|
+
"-s",
|
|
214
|
+
`${revision}:${path}`
|
|
215
|
+
], {
|
|
216
|
+
cwd: root,
|
|
217
|
+
encoding: "utf8"
|
|
218
|
+
});
|
|
219
|
+
return result.status === 0 ? Number(result.stdout) : void 0;
|
|
220
|
+
}
|
|
221
|
+
function packFailure(base, ceilings) {
|
|
222
|
+
if (base.pack === void 0) return [];
|
|
223
|
+
if (ceilings.pack === void 0) return [`${CEILINGS_FILE}: drops the recorded pack release ${base.pack} the base has.`];
|
|
224
|
+
return compareReleases(ceilings.pack, base.pack) < 0 ? [`${CEILINGS_FILE}: lowers the recorded pack release from ${base.pack} on the base to ${ceilings.pack}.`] : [];
|
|
225
|
+
}
|
|
226
|
+
function notNewlyEnabled(rule, adopted) {
|
|
227
|
+
const since = PACK_NEW_RULES.get(rule);
|
|
228
|
+
return since === void 0 ? `${CEILINGS_FILE}: adds ${rule}, which the pack did not newly enable.` : `${CEILINGS_FILE}: adds ${rule}, which the pack enabled in ${since}, not after this repository's ${adopted ?? since}.`;
|
|
229
|
+
}
|
|
230
|
+
/** The rules' finding counts over the tree at `revision`, linted under the current configuration; the repository's files that differ from `revision` are restored to it. */
|
|
231
|
+
function countsAtRevision(root, revision) {
|
|
232
|
+
return withPreviousTree(root, revision, execFileSync("git", [
|
|
233
|
+
"diff",
|
|
234
|
+
"--cached",
|
|
235
|
+
"--name-only",
|
|
236
|
+
"--no-renames",
|
|
237
|
+
"-z",
|
|
238
|
+
revision
|
|
239
|
+
], {
|
|
240
|
+
cwd: root,
|
|
241
|
+
encoding: "utf8"
|
|
242
|
+
}).split("\0").filter((file) => file && !LINT_CONFIG.test(file)), (tree) => {
|
|
243
|
+
const counts = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const { rule } of lintDiagnostics(tree)) counts.set(rule, (counts.get(rule) ?? 0) + 1);
|
|
245
|
+
return counts;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/** Counts a rule's findings at the base revision, linting it once and only when an adoption asks. */
|
|
249
|
+
function baseCounter(root, revision) {
|
|
250
|
+
let counts;
|
|
251
|
+
return (rule) => {
|
|
252
|
+
counts ??= countsAtRevision(root, revision);
|
|
253
|
+
return counts.get(rule) ?? 0;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function ruleFailures$1(base, ceilings, measured, adopted, countAtBase) {
|
|
257
|
+
const failures = [];
|
|
258
|
+
for (const [rule, limit] of Object.entries(ceilings.rules)) {
|
|
259
|
+
const before = base.rules[rule];
|
|
260
|
+
const count = measured.rules[rule] ?? 0;
|
|
261
|
+
if (before !== void 0) {
|
|
262
|
+
if (limit > before) failures.push(`${CEILINGS_FILE}: raises ${rule} from ${before} on the base to ${limit}.`);
|
|
263
|
+
} else if (newlyEnabled(rule, adopted) === void 0) failures.push(notNewlyEnabled(rule, adopted));
|
|
264
|
+
else if (limit > count) failures.push(`${CEILINGS_FILE}: adds ${rule} at ${limit}, above its ${count} findings.`);
|
|
265
|
+
else {
|
|
266
|
+
const atBase = countAtBase(rule);
|
|
267
|
+
if (limit > atBase) failures.push(`${CEILINGS_FILE}: adds ${rule} at ${limit}, above its ${atBase} findings on the base.`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return failures;
|
|
271
|
+
}
|
|
272
|
+
function oversizeFailures({ root, revision, renames, adopted }, base, ceilings, measured) {
|
|
273
|
+
const failures = [];
|
|
274
|
+
for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) {
|
|
275
|
+
const before = base.oversizeFiles[file] ?? base.oversizeFiles[renames.get(file) ?? file];
|
|
276
|
+
if (before === void 0) {
|
|
277
|
+
const existing = isAgentFile(file) && agentFilesPending(adopted) ? committedSize(root, revision, renames.get(file) ?? file) : void 0;
|
|
278
|
+
if (existing === void 0) failures.push(`${CEILINGS_FILE}: adds an oversize allowance for ${file}.`);
|
|
279
|
+
else if (limit > Math.min(existing, measured.oversizeFiles[file] ?? 0)) failures.push(`${CEILINGS_FILE}: raises the oversize allowance of ${file} from ${existing} bytes on the base to ${limit}.`);
|
|
280
|
+
} else if (limit > before) failures.push(`${CEILINGS_FILE}: raises the oversize allowance of ${file} from ${before} bytes on the base to ${limit}.`);
|
|
281
|
+
}
|
|
282
|
+
return failures;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Fails each ceiling of `ceilings` added or raised against the ratchet file
|
|
286
|
+
* at `revision`, except a rule the pack enabled after the base's adopted
|
|
287
|
+
* release, recorded at no more than its `measured` count and its count in the
|
|
288
|
+
* tree at `revision`, and an oversize
|
|
289
|
+
* agent file that exists at the base, allowed at no more than its size there
|
|
290
|
+
* and its measured size, while the base predates counting those files; and a recorded pack
|
|
291
|
+
* release dropped or lowered. Renamed files keep their allowance. A base with
|
|
292
|
+
* neither a ratchet file nor a suppression budget, a first adoption, passes.
|
|
293
|
+
*/
|
|
294
|
+
function raisedRatchet(root, revision, ceilings, measured) {
|
|
295
|
+
const text = committed(root, revision, CEILINGS_FILE);
|
|
296
|
+
if (text === void 0 && committed(root, revision, "guardrails.suppressions.json") === void 0) return [];
|
|
297
|
+
const base = text === void 0 ? {
|
|
298
|
+
rules: {},
|
|
299
|
+
oversizeFiles: {}
|
|
300
|
+
} : parseCeilings(text, `${revision.slice(0, 12)}:${CEILINGS_FILE}`);
|
|
301
|
+
const adopted = adoptedRelease(root, base.pack, revision);
|
|
302
|
+
const failures = [
|
|
303
|
+
...packFailure(base, ceilings),
|
|
304
|
+
...ruleFailures$1(base, ceilings, measured, adopted, baseCounter(root, revision)),
|
|
305
|
+
...oversizeFailures({
|
|
306
|
+
root,
|
|
307
|
+
revision,
|
|
308
|
+
renames: renamedPaths(root, false, [revision]),
|
|
309
|
+
adopted
|
|
310
|
+
}, base, ceilings, measured)
|
|
311
|
+
];
|
|
312
|
+
return failures.length ? [...failures, "Ceilings only go down: ratchet:update lowers them and records only the rules the pack newly enabled. Fix the code; raising a ceiling needs the operator's approval through the ruleset bypass."] : [];
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/guardrails/ratchet.ts
|
|
316
|
+
function baseline(root, diagnostics) {
|
|
317
|
+
const rules = /* @__PURE__ */ new Map();
|
|
318
|
+
const oversizeFiles = {};
|
|
319
|
+
const sizes = authoredSizes(root);
|
|
320
|
+
for (const diagnostic of diagnostics) if (diagnostic.rule === "eslint/max-lines") {
|
|
321
|
+
const size = sizes.get(diagnostic.file);
|
|
322
|
+
if (size !== void 0) oversizeFiles[diagnostic.file] = size;
|
|
323
|
+
} else rules.set(diagnostic.rule, (rules.get(diagnostic.rule) ?? 0) + 1);
|
|
324
|
+
for (const [file, size] of sizes) if (size > 2e4) oversizeFiles[file] = size;
|
|
325
|
+
return {
|
|
326
|
+
rules: Object.fromEntries(rules),
|
|
327
|
+
oversizeFiles
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function measureBaseline(root, config) {
|
|
331
|
+
return baseline(root, lintDiagnostics(root, config));
|
|
332
|
+
}
|
|
333
|
+
function lowerCeilings(ceilings, current) {
|
|
334
|
+
const lowered = [];
|
|
335
|
+
for (const [rule, limit] of Object.entries(ceilings.rules)) {
|
|
336
|
+
const count = current.rules[rule] ?? 0;
|
|
337
|
+
if (count === 0) delete ceilings.rules[rule];
|
|
338
|
+
else if (count < limit) ceilings.rules[rule] = count;
|
|
339
|
+
if (count < limit) lowered.push(`${rule}: ${limit} -> ${count}`);
|
|
340
|
+
}
|
|
341
|
+
for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) if (current.oversizeFiles[file] === void 0) {
|
|
342
|
+
delete ceilings.oversizeFiles[file];
|
|
343
|
+
lowered.push(`${file}: removed oversize allowance`);
|
|
344
|
+
} else if (current.oversizeFiles[file] < limit) {
|
|
345
|
+
ceilings.oversizeFiles[file] = current.oversizeFiles[file];
|
|
346
|
+
lowered.push(`${file}: ${limit} -> ${current.oversizeFiles[file]} bytes`);
|
|
347
|
+
}
|
|
348
|
+
return lowered;
|
|
349
|
+
}
|
|
350
|
+
/** Records today's count of each rule without a ceiling that the pack enabled after `adopted`, and the size of each oversize agent file without an allowance when the repository predates counting them. */
|
|
351
|
+
function adopt(ceilings, current, adopted) {
|
|
352
|
+
const adoptions = [];
|
|
353
|
+
for (const [rule, count] of Object.entries(current.rules)) {
|
|
354
|
+
if (Object.hasOwn(ceilings.rules, rule)) continue;
|
|
355
|
+
const since = newlyEnabled(rule, adopted);
|
|
356
|
+
if (since === void 0) continue;
|
|
357
|
+
ceilings.rules[rule] = count;
|
|
358
|
+
adoptions.push(`${rule}: ${count}, enabled by the pack in ${since}.`);
|
|
359
|
+
}
|
|
360
|
+
if (agentFilesPending(adopted)) for (const [file, size] of Object.entries(current.oversizeFiles)) {
|
|
361
|
+
if (!isAgentFile(file) || Object.hasOwn(ceilings.oversizeFiles, file)) continue;
|
|
362
|
+
ceilings.oversizeFiles[file] = size;
|
|
363
|
+
adoptions.push(`${file}: ${size} bytes, counted by the size guard from ${AGENT_FILES_RELEASE}.`);
|
|
364
|
+
}
|
|
365
|
+
return adoptions;
|
|
366
|
+
}
|
|
367
|
+
function adoptionHint(rule, ceilings, adopted) {
|
|
368
|
+
const since = Object.hasOwn(ceilings.rules, rule) ? void 0 : newlyEnabled(rule, adopted);
|
|
369
|
+
if (since === void 0) return "";
|
|
370
|
+
return ` The pack enabled this rule in ${since}${adopted === void 0 ? "" : `, after this repository's ${adopted}`}; run ratchet:update to record today's count.`;
|
|
371
|
+
}
|
|
372
|
+
function ruleFailures(ceilings, current, diagnostics, changed, adopted) {
|
|
373
|
+
const failures = [];
|
|
374
|
+
for (const [rule, count] of Object.entries(current.rules)) {
|
|
375
|
+
const limit = ceilings.rules[rule] ?? 0;
|
|
376
|
+
if (count <= limit) continue;
|
|
377
|
+
failures.push(`${rule}: ${count} diagnostics exceeds ceiling ${limit}.${adoptionHint(rule, ceilings, adopted)}`);
|
|
378
|
+
const matches = diagnostics.filter((diagnostic) => diagnostic.rule === rule);
|
|
379
|
+
const inChanged = matches.filter(({ file }) => changed.has(file));
|
|
380
|
+
const shown = inChanged.length > 0 ? inChanged : matches;
|
|
381
|
+
for (const diagnostic of shown) failures.push(` ${diagnostic.location}: ${diagnostic.message}`);
|
|
382
|
+
if (shown.length < matches.length) failures.push(` ...and ${matches.length - shown.length} recorded in files this change does not touch.`);
|
|
383
|
+
}
|
|
384
|
+
return failures;
|
|
385
|
+
}
|
|
386
|
+
function sizeFailures(root, ceilings, current, adopted) {
|
|
387
|
+
const failures = [];
|
|
388
|
+
for (const [file, size] of Object.entries(current.oversizeFiles)) {
|
|
389
|
+
if (ceilings.oversizeFiles[file] !== void 0) continue;
|
|
390
|
+
const hint = isAgentFile(file) && agentFilesPending(adopted) ? ` The size guard counts the repository's own agent files from ${AGENT_FILES_RELEASE}; run ratchet:update to record today's size.` : "";
|
|
391
|
+
failures.push(`${size > 2e4 ? sizeFailure(file, size, MAX_FILE_BYTES) : `${file}: ${size} bytes and an eslint/max-lines diagnostic; this file has no oversize allowance. Split by responsibility into sibling modules, or split tests by behaviour under test, one file per describe.`}${hint}`);
|
|
392
|
+
}
|
|
393
|
+
const sizes = authoredSizes(root, Object.keys(ceilings.oversizeFiles));
|
|
394
|
+
for (const [file, limit] of Object.entries(ceilings.oversizeFiles)) {
|
|
395
|
+
const size = sizes.get(file);
|
|
396
|
+
if (size !== void 0 && size > limit) failures.push(sizeFailure(file, size, limit));
|
|
397
|
+
}
|
|
398
|
+
return failures;
|
|
399
|
+
}
|
|
400
|
+
/** Writes `ceilings`, or deletes the file once no debt is left; a clean repository gets a file only when it adopted a rule. */
|
|
401
|
+
function persist(root, ceilings, create) {
|
|
402
|
+
const path = join(root, CEILINGS_FILE);
|
|
403
|
+
const present = existsSync(path);
|
|
404
|
+
const retired = present && isRetired(ceilings);
|
|
405
|
+
if (retired) unlinkSync(path);
|
|
406
|
+
else if (present || create) writeFileSync(path, formatCeilings(ceilings));
|
|
407
|
+
return {
|
|
408
|
+
retired,
|
|
409
|
+
created: !present && create
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Fails each rule above its ceiling and each file above its allowance. With
|
|
414
|
+
* `update`, first records today's count of each rule the pack enabled after
|
|
415
|
+
* the repository's adopted release (creating the file in a clean
|
|
416
|
+
* repository), then lowers the other ceilings and moves the recorded release
|
|
417
|
+
* forward. With `pullBase`, also fails each entry added or raised against
|
|
418
|
+
* that revision that is not such an adoption.
|
|
419
|
+
*/
|
|
420
|
+
function ratchet(root, update = false, base = "HEAD", pullBase) {
|
|
421
|
+
if (!update && !existsSync(join(root, "guardrails.ratchet.json"))) throw new Error(`${CEILINGS_FILE} is missing. Run antelopejs-sync first.`);
|
|
422
|
+
const carried = readCarriedCeilings(root, false, [base]);
|
|
423
|
+
const ceilings = {
|
|
424
|
+
...carried,
|
|
425
|
+
rules: { ...carried.rules }
|
|
426
|
+
};
|
|
427
|
+
const adopted = adoptedRelease(root, ceilings.pack, pullBase ?? "HEAD");
|
|
428
|
+
const diagnostics = lintDiagnostics(root);
|
|
429
|
+
const current = baseline(root, diagnostics);
|
|
430
|
+
const adoptions = update ? adopt(ceilings, current, adopted) : [];
|
|
431
|
+
const failures = [...ruleFailures(ceilings, current, diagnostics, changedFiles(root), adopted), ...sizeFailures(root, ceilings, current, adopted)];
|
|
432
|
+
const lowered = update ? lowerCeilings(ceilings, current) : [];
|
|
433
|
+
if (update) ceilings.pack = recordedRelease(adopted);
|
|
434
|
+
if (pullBase !== void 0) failures.push(...raisedRatchet(root, pullBase, ceilings, current));
|
|
435
|
+
const { retired, created } = update ? persist(root, ceilings, adoptions.length > 0) : {
|
|
436
|
+
retired: false,
|
|
437
|
+
created: false
|
|
438
|
+
};
|
|
439
|
+
return {
|
|
440
|
+
failures,
|
|
441
|
+
lowered,
|
|
442
|
+
adoptions,
|
|
443
|
+
retired,
|
|
444
|
+
created
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
448
|
+
export { recordedRelease as i, ratchet as n, withPreviousTree as r, measureBaseline as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as readCeilings } from "./ceilings-B7KayYIG.mjs";
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
3
|
//#region src/guardrails/renames.ts
|
|
4
4
|
/**
|
|
@@ -45,7 +45,7 @@ function carryAllowances(ceilings, renames) {
|
|
|
45
45
|
}
|
|
46
46
|
for (const [file, allowance] of moved) oversizeFiles[file] = allowance;
|
|
47
47
|
return {
|
|
48
|
-
|
|
48
|
+
...ceilings,
|
|
49
49
|
oversizeFiles
|
|
50
50
|
};
|
|
51
51
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { i as isObject, l as optNum, n as children, o as list, u as optStr } from "./json-CG2L7YFl.mjs";
|
|
2
|
+
//#region src/capture/scenes.ts
|
|
3
|
+
const KEBAB_CASE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
|
+
const GUIDE_VIEWPORT = {
|
|
5
|
+
width: 1440,
|
|
6
|
+
height: 900
|
|
7
|
+
};
|
|
8
|
+
/** Types the `docs/captures.ts` default export: `export default defineScenes([...])`. */
|
|
9
|
+
function defineScenes(scenes) {
|
|
10
|
+
return scenes;
|
|
11
|
+
}
|
|
12
|
+
function required(value, message) {
|
|
13
|
+
if (value === void 0 || value === "") throw new Error(message);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function parseStep(step, index) {
|
|
17
|
+
const label = `step ${index + 1}`;
|
|
18
|
+
const action = optStr(step, "action");
|
|
19
|
+
if (action === "press") return {
|
|
20
|
+
action,
|
|
21
|
+
key: required(optStr(step, "key"), `${label} needs a key`)
|
|
22
|
+
};
|
|
23
|
+
if (action !== "click" && action !== "fill" && action !== "wait") throw new Error(`${label} has an unknown action ${JSON.stringify(action)}`);
|
|
24
|
+
const selector = required(optStr(step, "selector"), `${label} needs a selector`);
|
|
25
|
+
if (action !== "fill") return {
|
|
26
|
+
action,
|
|
27
|
+
selector
|
|
28
|
+
};
|
|
29
|
+
const value = optStr(step, "value");
|
|
30
|
+
if (value === void 0) throw new Error(`${label} needs a value`);
|
|
31
|
+
return {
|
|
32
|
+
action,
|
|
33
|
+
selector,
|
|
34
|
+
value
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function parseViewport(source) {
|
|
38
|
+
if (!Object.hasOwn(source, "viewport")) return GUIDE_VIEWPORT;
|
|
39
|
+
const { viewport } = source;
|
|
40
|
+
const [width, height] = isObject(viewport) ? [optNum(viewport, "width"), optNum(viewport, "height")] : [void 0, void 0];
|
|
41
|
+
if (width === void 0 || height === void 0 || !Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) throw new Error("viewport needs a positive width and height");
|
|
42
|
+
return {
|
|
43
|
+
width,
|
|
44
|
+
height
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function parseOutput(source, setup) {
|
|
48
|
+
const output = optStr(source, "output");
|
|
49
|
+
if (setup) {
|
|
50
|
+
if (Object.hasOwn(source, "output")) throw new Error("a setup scene takes no output");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (output === void 0 || output === "") throw new Error("a screenshot scene needs an output");
|
|
54
|
+
if (!output.endsWith(".webp")) throw new Error("output must be a .webp path");
|
|
55
|
+
if (output.startsWith("/") || output.split("/").includes("..")) throw new Error("output must stay inside the repository");
|
|
56
|
+
return output;
|
|
57
|
+
}
|
|
58
|
+
function parseScene(entry, position) {
|
|
59
|
+
if (!isObject(entry)) throw new Error(`scene ${position} is not an object`);
|
|
60
|
+
const id = optStr(entry, "id");
|
|
61
|
+
if (id === void 0 || !KEBAB_CASE.test(id)) throw new Error(`scene id ${JSON.stringify(id)} is not kebab-case`);
|
|
62
|
+
try {
|
|
63
|
+
const route = optStr(entry, "route");
|
|
64
|
+
if (route === void 0 || !route.startsWith("/")) throw new Error("route must start with \"/\"");
|
|
65
|
+
const setup = entry.setup === true;
|
|
66
|
+
const scene = {
|
|
67
|
+
id,
|
|
68
|
+
route,
|
|
69
|
+
viewport: parseViewport(entry),
|
|
70
|
+
steps: Object.hasOwn(entry, "steps") ? children(entry, "steps").map(parseStep) : [],
|
|
71
|
+
setup
|
|
72
|
+
};
|
|
73
|
+
const crop = optStr(entry, "crop");
|
|
74
|
+
if (crop !== void 0 && crop !== "") scene.crop = crop;
|
|
75
|
+
const output = parseOutput(entry, setup);
|
|
76
|
+
if (output !== void 0) scene.output = output;
|
|
77
|
+
return scene;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error(`scene ${JSON.stringify(id)}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Validates what `docs/captures.ts` exports, so a mistyped scene fails with its id and field. */
|
|
83
|
+
function parseScenes(raw) {
|
|
84
|
+
if (!Array.isArray(raw)) throw new Error("docs/captures.ts must export an array of scenes");
|
|
85
|
+
const scenes = list(raw, "scenes").map((entry, index) => parseScene(entry, index + 1));
|
|
86
|
+
const ids = /* @__PURE__ */ new Map();
|
|
87
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const scene of scenes) {
|
|
89
|
+
if (ids.has(scene.id)) throw new Error(`scene id ${JSON.stringify(scene.id)} appears twice`);
|
|
90
|
+
ids.set(scene.id, scene);
|
|
91
|
+
if (scene.output === void 0) continue;
|
|
92
|
+
const other = outputs.get(scene.output);
|
|
93
|
+
if (other) throw new Error(`scenes ${JSON.stringify(other.id)} and ${JSON.stringify(scene.id)} both write ${scene.output}`);
|
|
94
|
+
outputs.set(scene.output, scene);
|
|
95
|
+
}
|
|
96
|
+
return scenes;
|
|
97
|
+
}
|
|
98
|
+
/** The scenes a run executes: every setup scene first, then the screenshot scene asked for, or all of them. */
|
|
99
|
+
function selectScenes(scenes, id) {
|
|
100
|
+
if (id !== void 0 && !scenes.some((scene) => scene.id === id)) throw new Error(`no scene ${JSON.stringify(id)}; the scenes are ${scenes.map((scene) => scene.id).sort().join(", ")}`);
|
|
101
|
+
return [...scenes.filter((scene) => scene.setup), ...scenes.filter((scene) => !scene.setup && (id === void 0 || scene.id === id))];
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { parseScenes as n, selectScenes as r, defineScenes as t };
|