@antelopejs/tooling-configs 0.2.2 → 0.2.4
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 +9 -3
- package/dist/bin/api-diff.mjs +413 -33
- package/dist/bin/check-size.mjs +2 -2
- package/dist/bin/checks.mjs +2 -1
- package/dist/bin/comment-proof.mjs +7 -3
- package/dist/bin/ratchet.mjs +10 -5
- package/dist/bin/sync.mjs +96 -6
- package/dist/files-CaMy-5ne.mjs +382 -0
- package/dist/oxc/fmt.mjs +1 -1
- package/dist/oxc/lint.mjs +4 -3
- package/dist/{ratchet-B2_QUucT.mjs → ratchet-Bz4Rl3_r.mjs} +7 -6
- package/dist/renames-BGO4dWJ8.mjs +59 -0
- package/dist/{shared-NC0T8ykm.mjs → shared-CsXIMK3I.mjs} +4 -2
- package/dist/{size-D7JJp_W4.mjs → size-DYVe2pXo.mjs} +4 -3
- package/dist/typescript-BlNlyAhQ.mjs +169 -0
- package/package.json +1 -1
- package/dist/files-DAD5OtfV.mjs +0 -129
- package/dist/typescript-CHOlkIXa.mjs +0 -202
package/dist/bin/ratchet.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { s as readCeilings, t as CEILINGS_FILE } from "../ceilings-BSw9p4YB.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { n as renamedPaths } from "../renames-BGO4dWJ8.mjs";
|
|
4
|
+
import { a as resolveRevision, h as runCli, i as repositoryRoot, r as repositoryPath } from "../files-CaMy-5ne.mjs";
|
|
5
|
+
import { n as ratchet, r as lintDiagnostics } from "../ratchet-Bz4Rl3_r.mjs";
|
|
5
6
|
import { resolve } from "node:path";
|
|
6
7
|
import { execFileSync } from "node:child_process";
|
|
7
8
|
import { parseArgs } from "node:util";
|
|
@@ -18,6 +19,7 @@ function stagedRatchet(root, files) {
|
|
|
18
19
|
encoding: "utf8"
|
|
19
20
|
}).split("\0").filter(Boolean);
|
|
20
21
|
if (!targets.length) return [];
|
|
22
|
+
const renames = renamedPaths(root, true);
|
|
21
23
|
const additions = /* @__PURE__ */ new Map();
|
|
22
24
|
for (const file of targets) {
|
|
23
25
|
const diff = execFileSync("git", [
|
|
@@ -26,8 +28,9 @@ function stagedRatchet(root, files) {
|
|
|
26
28
|
"--no-ext-diff",
|
|
27
29
|
"--no-color",
|
|
28
30
|
"--unified=0",
|
|
31
|
+
"--find-renames",
|
|
29
32
|
"--",
|
|
30
|
-
file
|
|
33
|
+
...[renames.get(file), file].filter((path) => path !== void 0)
|
|
31
34
|
], {
|
|
32
35
|
cwd: root,
|
|
33
36
|
encoding: "utf8"
|
|
@@ -46,18 +49,20 @@ runCli(() => {
|
|
|
46
49
|
const { values, positionals } = parseArgs({
|
|
47
50
|
options: {
|
|
48
51
|
update: { type: "boolean" },
|
|
49
|
-
staged: { type: "boolean" }
|
|
52
|
+
staged: { type: "boolean" },
|
|
53
|
+
base: { type: "string" }
|
|
50
54
|
},
|
|
51
55
|
allowPositionals: true
|
|
52
56
|
});
|
|
53
57
|
const root = repositoryRoot();
|
|
58
|
+
if (values.base !== void 0 && values.staged) throw new Error("--base cannot be combined with --staged.");
|
|
54
59
|
if (values.update && values.staged) throw new Error("--staged cannot be combined with --update.");
|
|
55
60
|
if (positionals.length && !values.staged) throw new Error("File arguments require --staged.");
|
|
56
61
|
const result = values.staged ? {
|
|
57
62
|
failures: stagedRatchet(root, positionals.length ? positionals.map((file) => repositoryPath(root, resolve(file))) : void 0),
|
|
58
63
|
lowered: [],
|
|
59
64
|
retired: false
|
|
60
|
-
} : ratchet(root, values.update);
|
|
65
|
+
} : ratchet(root, values.update, values.base === void 0 ? void 0 : resolveRevision(root, values.base));
|
|
61
66
|
if (result.retired) process.stdout.write(`Deleted ${CEILINGS_FILE}: no debt left. Run antelopejs-sync.\n`);
|
|
62
67
|
for (const message of result.lowered) process.stdout.write(`Lowered ${message}\n`);
|
|
63
68
|
for (const message of result.failures) process.stderr.write(`${message}\n`);
|
package/dist/bin/sync.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { a as formatCeilings, o as isRetired, s as readCeilings, t as CEILINGS_FILE } from "../ceilings-BSw9p4YB.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { h as runCli, i as repositoryRoot } from "../files-CaMy-5ne.mjs";
|
|
4
4
|
import { a as repositoryTools, i as parseManifest, n as managedPackage, o as toolingVersions, r as packageManager, t as execCommand } from "../package-Ckd7e4tA.mjs";
|
|
5
|
-
import { t as measureBaseline } from "../ratchet-
|
|
5
|
+
import { t as measureBaseline } from "../ratchet-Bz4Rl3_r.mjs";
|
|
6
6
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { execFileSync } from "node:child_process";
|
|
8
9
|
import { parseArgs } from "node:util";
|
|
9
10
|
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
10
11
|
//#region src/guardrails/agents-block.ts
|
|
@@ -12,7 +13,11 @@ const AGENTS_BLOCK_START = "<!-- antelopejs-guardrails:start -->";
|
|
|
12
13
|
const AGENTS_BLOCK_END = "<!-- antelopejs-guardrails:end -->";
|
|
13
14
|
const COMMENTS = `### Comments
|
|
14
15
|
|
|
15
|
-
Say it in code. A constraint belongs in a type, a lint rule, or a test. A public item's contract belongs in TSDoc (\`/** */\`) on that item. The only other comments are lint directives that name their rules, \`@ts-expect-error <reason>\`, \`SAFETY: <reason>\` above a type assertion, \`/*!\` license headers, and bundler or formatter directives
|
|
16
|
+
Say it in code. A constraint belongs in a type, a lint rule, or a test. A public item's contract belongs in TSDoc (\`/** */\`) on that item. The only other comments are lint directives that name their rules, \`@ts-expect-error <reason>\`, \`SAFETY: <reason>\` above a type assertion, \`/*!\` license headers, and bundler or formatter directives.
|
|
17
|
+
|
|
18
|
+
Before suppressing a type rule, try inference or a type derived from its owner with \`Parameters\`, \`ReturnType\`, or indexed access. A private alias can still appear in a published declaration. Keep a suppression only after checking the published contract and the unchecked boundary it protects.
|
|
19
|
+
|
|
20
|
+
Check each directive reason against the current line and its callers. Returning a value is not the same as awaiting and discarding it. A reason must describe what the code does now.`;
|
|
16
21
|
const TESTS = `### Tests
|
|
17
22
|
|
|
18
23
|
Hold every test you write or keep to this checklist:
|
|
@@ -22,7 +27,13 @@ Hold every test you write or keep to this checklist:
|
|
|
22
27
|
- An invariant over many files is a lint rule, not a test.`;
|
|
23
28
|
const CLEANUP_PROOF = `### Cleanup proof
|
|
24
29
|
|
|
25
|
-
A behaviour-preserving cleanup PR shows \`antelopejs-api-diff <base-ref>\` passing. Published declarations stay unchanged. A comment-only PR shows \`antelopejs-comment-proof <base-ref>\` passing instead of a verifier. Both compare committed HEAD
|
|
30
|
+
A behaviour-preserving cleanup PR shows \`antelopejs-api-diff <base-ref>\` passing. Published declarations and built runtime exports stay unchanged; pass \`--allow-added <glob>\` (repeatable, e.g. \`'**/internal/**'\`) to let added entries under that glob pass when their module is \`@internal\`, and copy its "Added (allowed)" list. A comment-only PR shows \`antelopejs-comment-proof <base-ref>\` passing instead of a verifier. Both compare committed HEAD.
|
|
31
|
+
|
|
32
|
+
Copy counts from the proof's base and HEAD table. Never type counts by hand. Keep the command and the committed head beside the copied output. Directive lines are not individual suppressed rules.
|
|
33
|
+
|
|
34
|
+
Pass \`--probe <file.cjs>\` to api-diff when changing receivers, positional calls, or modules that no published entry reaches. The same captured script runs against both worktree roots, supplied as \`argv[2]\`, and prints JSON observations. Matching metadata alone does not prove those behaviours.
|
|
35
|
+
|
|
36
|
+
An entry-only rule exempts only its own module. Add a second module entry rather than exempting another importer. A no-upward rule must reject peers in the same tier as well as higher tiers. Probe the rank decision with an import, not just a reading of the configuration.`;
|
|
26
37
|
const SHARED_RULES = [
|
|
27
38
|
["Formatting", "oxfmt"],
|
|
28
39
|
["Lint findings are errors; no rule warns", "oxlint preset"],
|
|
@@ -32,14 +43,19 @@ const SHARED_RULES = [
|
|
|
32
43
|
["No assertion that restates a constant", "`antelopejs/no-constant-value-assertion`"],
|
|
33
44
|
["No test whose only check is \"is a function\"", "`antelopejs/no-typeof-function-only-test`"],
|
|
34
45
|
["Params ≤ 5, function ≤ 120 lines, file ≤ 500 lines, depth ≤ 4, complexity ≤ 20", "`eslint/max-*`, `eslint/complexity`"],
|
|
35
|
-
["Cleanup preserves
|
|
36
|
-
["Comment-only changes preserve JavaScript emit", "`antelopejs-comment-proof <base-ref>`"]
|
|
46
|
+
["Cleanup preserves declarations and built runtime export metadata", "`antelopejs-api-diff <base-ref>`"],
|
|
47
|
+
["Comment-only changes preserve JavaScript emit", "`antelopejs-comment-proof <base-ref>`"],
|
|
48
|
+
["PR-body counts come from tracked code files", "api-diff and comment-proof tables"],
|
|
49
|
+
["Receiver, positional and unpublished-module behaviour", "`antelopejs-api-diff <base-ref> --probe <file.cjs>`"],
|
|
50
|
+
["Type suppressions and directive reasons are justified", "review; no tool"],
|
|
51
|
+
["No-upward rules reject same-tier peers", "review and import probes"]
|
|
37
52
|
];
|
|
38
53
|
const FULL_RULES = [
|
|
39
54
|
["Files ≤ 20,000 bytes, tests included", "`antelopejs-check-size` (pre-commit)"],
|
|
40
55
|
["Types check", "`tsc` (pre-push)"],
|
|
41
56
|
["No dead files, exports, or dependencies", "knip"],
|
|
42
57
|
["Managed files match the pack", "`antelopejs-sync --check`"],
|
|
58
|
+
["Entry-only rules exempt no tracked outsider", "`antelopejs-sync --check`"],
|
|
43
59
|
["A test names the wrong implementation it catches", "review; no tool"]
|
|
44
60
|
];
|
|
45
61
|
/** Pads each column the way oxfmt does, so formatting AGENTS.md never reports sync drift. */
|
|
@@ -258,6 +274,76 @@ function hasChecksWorkflow(root) {
|
|
|
258
274
|
return false;
|
|
259
275
|
}
|
|
260
276
|
//#endregion
|
|
277
|
+
//#region src/guardrails/entry-only.ts
|
|
278
|
+
const LOAD_RULES = `
|
|
279
|
+
const advisories = [];
|
|
280
|
+
const rules = [];
|
|
281
|
+
const SUPPORTED = { from: ["pathNot"], to: ["path", "pathNot"] };
|
|
282
|
+
function patterns(value) {
|
|
283
|
+
if (value === undefined) return [];
|
|
284
|
+
const list = Array.isArray(value) ? value : [value];
|
|
285
|
+
if (list.some(pattern => typeof pattern !== "string")) return null;
|
|
286
|
+
try { list.forEach(pattern => new RegExp(pattern)); } catch { return null; }
|
|
287
|
+
return list;
|
|
288
|
+
}
|
|
289
|
+
function problem(rule) {
|
|
290
|
+
if (!rule.from || typeof rule.from !== "object" || !rule.to || typeof rule.to !== "object")
|
|
291
|
+
return "Warning: entry-only rule " + rule.name + " has no from and to selectors, so its exemptions cannot be checked.";
|
|
292
|
+
const unsupported = [
|
|
293
|
+
...(rule.severity === "error" ? [] : ["severity " + String(rule.severity)]),
|
|
294
|
+
...Object.keys(rule.from).filter(key => !SUPPORTED.from.includes(key)).map(key => "from." + key),
|
|
295
|
+
...Object.keys(rule.to).filter(key => !SUPPORTED.to.includes(key)).map(key => "to." + key),
|
|
296
|
+
];
|
|
297
|
+
if (unsupported.length)
|
|
298
|
+
return "Note: entry-only rule " + rule.name + " skipped, because its selectors are not supported (" + unsupported.join(", ") + "); only error rules built from from.pathNot and to.path or to.pathNot patterns are checked.";
|
|
299
|
+
if (rule.to.path === undefined)
|
|
300
|
+
return "Warning: entry-only rule " + rule.name + " has no to.path, so there is no module to exempt against.";
|
|
301
|
+
if (patterns(rule.from.pathNot) === null || !patterns(rule.to.path)?.length || patterns(rule.to.pathNot) === null)
|
|
302
|
+
return "Warning: entry-only rule " + rule.name + " has selectors that are not valid regular expression strings, so its exemptions cannot be checked.";
|
|
303
|
+
return undefined;
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const forbidden = require(process.cwd()+"/.dependency-cruiser.cjs").forbidden;
|
|
307
|
+
if (!Array.isArray(forbidden)) advisories.push("Warning: .dependency-cruiser.cjs has no forbidden rule array, so entry-only exemptions are not checked.");
|
|
308
|
+
else for (const rule of forbidden) {
|
|
309
|
+
if (!rule || typeof rule.name !== "string" || !rule.name.endsWith("-entry-only")) continue;
|
|
310
|
+
const advisory = problem(rule);
|
|
311
|
+
if (advisory === undefined) rules.push({ name: rule.name, exempt: patterns(rule.from.pathNot), domain: patterns(rule.to.path) });
|
|
312
|
+
else advisories.push(advisory);
|
|
313
|
+
}
|
|
314
|
+
} catch (error) {
|
|
315
|
+
advisories.push("Warning: .dependency-cruiser.cjs could not be loaded, so entry-only exemptions are not checked (" + String(error && error.message) + ").");
|
|
316
|
+
}
|
|
317
|
+
process.stdout.write(JSON.stringify({ rules, advisories }));
|
|
318
|
+
`;
|
|
319
|
+
function matcher(patterns) {
|
|
320
|
+
return patterns.map((pattern) => new RegExp(pattern));
|
|
321
|
+
}
|
|
322
|
+
/** Rejects tracked importers exempted from another module's entry-only boundary. A rule it cannot interpret yields a printed note or warning in `advisories` and never a failure. */
|
|
323
|
+
function checkEntryOnlyConfiguration(root) {
|
|
324
|
+
if (!existsSync(join(root, ".dependency-cruiser.cjs"))) return {
|
|
325
|
+
errors: [],
|
|
326
|
+
advisories: []
|
|
327
|
+
};
|
|
328
|
+
const { rules, advisories } = JSON.parse(execFileSync(process.execPath, ["-e", LOAD_RULES], {
|
|
329
|
+
cwd: root,
|
|
330
|
+
encoding: "utf8",
|
|
331
|
+
timeout: 1e4
|
|
332
|
+
}));
|
|
333
|
+
const paths = execFileSync("git", ["ls-files", "-z"], {
|
|
334
|
+
cwd: root,
|
|
335
|
+
encoding: "utf8"
|
|
336
|
+
}).split("\0").filter(Boolean);
|
|
337
|
+
return {
|
|
338
|
+
errors: rules.flatMap((rule) => {
|
|
339
|
+
const domain = matcher(rule.domain);
|
|
340
|
+
const exemption = matcher(rule.exempt);
|
|
341
|
+
return paths.filter((path) => exemption.some((pattern) => pattern.test(path)) && !domain.some((pattern) => pattern.test(path))).map((path) => `${rule.name} exempts ${path} outside its module; give the module a second entry instead`);
|
|
342
|
+
}),
|
|
343
|
+
advisories
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
//#endregion
|
|
261
347
|
//#region src/guardrails/sync.ts
|
|
262
348
|
const LEGACY_COMMENT_INSTRUCTION = "- Explain non-obvious constraints and decisions in comments; avoid restating the code. Document public contracts with TSDoc.";
|
|
263
349
|
const RETIRED_RATCHET = `${CEILINGS_FILE} has no debt left. Run ratchet:update to delete it, then run antelopejs-sync.`;
|
|
@@ -463,6 +549,8 @@ function syncRepository(root, options = {}) {
|
|
|
463
549
|
const context = repositoryContext(root, current, profile);
|
|
464
550
|
let plan = planSync(current, modes, context);
|
|
465
551
|
const errors = plan.filter((artifact) => artifact.kind === "error").map(({ message }) => message);
|
|
552
|
+
const entryOnly = checkEntryOnlyConfiguration(root);
|
|
553
|
+
errors.push(...entryOnly.errors);
|
|
466
554
|
const notes = plan.flatMap((artifact) => artifact.kind === "migrated" ? artifact.notes : []);
|
|
467
555
|
(options.check ? errors : notes).push(...repositoryNotices(root, context));
|
|
468
556
|
if (!errors.length && profile === "full" && !options.check && !current.has("guardrails.ratchet.json") && manifest.scripts?.["sync:check"] === void 0) {
|
|
@@ -483,6 +571,7 @@ function syncRepository(root, options = {}) {
|
|
|
483
571
|
paths: errors.length ? [] : writes.map(({ path }) => path),
|
|
484
572
|
errors,
|
|
485
573
|
notes,
|
|
574
|
+
advisories: entryOnly.advisories,
|
|
486
575
|
dependenciesAdded
|
|
487
576
|
};
|
|
488
577
|
}
|
|
@@ -502,6 +591,7 @@ runCli(() => {
|
|
|
502
591
|
profile: values.profile
|
|
503
592
|
});
|
|
504
593
|
for (const note of result.notes) process.stdout.write(`Note: ${values.check || result.errors.length ? "Planned migration. " : ""}${note}\n`);
|
|
594
|
+
for (const advisory of result.advisories) process.stdout.write(`${advisory}\n`);
|
|
505
595
|
for (const error of result.errors) process.stderr.write(`${error}\n`);
|
|
506
596
|
if (result.errors.length) return 1;
|
|
507
597
|
for (const path of result.paths) process.stdout.write(`${values.check ? "Drift" : "Updated"}: ${path}${values.check ? "; run antelopejs-sync" : ""}\n`);
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import "./ceilings-BSw9p4YB.mjs";
|
|
2
|
+
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "./shared-CsXIMK3I.mjs";
|
|
3
|
+
import { closeSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, rmSync, symlinkSync } from "node:fs";
|
|
4
|
+
import { dirname, join, matchesGlob, relative, resolve } from "node:path";
|
|
5
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
//#region src/guardrails/cli.ts
|
|
8
|
+
function runCli(main) {
|
|
9
|
+
try {
|
|
10
|
+
process.exitCode = main();
|
|
11
|
+
} catch (error) {
|
|
12
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
13
|
+
process.exitCode = 1;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/guardrails/added-entries.ts
|
|
18
|
+
function createAddedPolicy(globs) {
|
|
19
|
+
return {
|
|
20
|
+
globs,
|
|
21
|
+
verdicts: /* @__PURE__ */ new Map(),
|
|
22
|
+
allowed: /* @__PURE__ */ new Map(),
|
|
23
|
+
problems: /* @__PURE__ */ new Set()
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function entryKey(directory, subpath) {
|
|
27
|
+
return `${directory}\0${subpath}`;
|
|
28
|
+
}
|
|
29
|
+
function allowedByGlob(policy, subpath) {
|
|
30
|
+
return policy.globs.some((glob) => matchesGlob(subpath, glob));
|
|
31
|
+
}
|
|
32
|
+
/** Substitutes each export star in order with its capture, as the published target pattern did. */
|
|
33
|
+
function fillStars(pattern, captures, format = (capture) => capture) {
|
|
34
|
+
let index = 0;
|
|
35
|
+
return pattern.replaceAll("*", () => format(captures[index++] ?? captures[0] ?? ""));
|
|
36
|
+
}
|
|
37
|
+
const INTERNAL_TAG = /@internal\b/u;
|
|
38
|
+
const MODULE_TAG = /@(?:packageDocumentation|module|fileoverview)\b/u;
|
|
39
|
+
function exportedLocalNames(compiler, source) {
|
|
40
|
+
const names = /* @__PURE__ */ new Set();
|
|
41
|
+
for (const statement of source.statements) {
|
|
42
|
+
if (compiler.isExportDeclaration(statement) && statement.moduleSpecifier === void 0 && statement.exportClause !== void 0 && compiler.isNamedExports(statement.exportClause)) for (const element of statement.exportClause.elements) names.add((element.propertyName ?? element.name).text);
|
|
43
|
+
if (compiler.isExportAssignment(statement) && compiler.isIdentifier(statement.expression)) names.add(statement.expression.text);
|
|
44
|
+
}
|
|
45
|
+
return names;
|
|
46
|
+
}
|
|
47
|
+
function declaredNames(compiler, statement) {
|
|
48
|
+
if (compiler.isVariableStatement(statement)) return statement.declarationList.declarations.flatMap((declaration) => compiler.isIdentifier(declaration.name) ? [declaration.name.text] : []);
|
|
49
|
+
if ((compiler.isFunctionDeclaration(statement) || compiler.isClassDeclaration(statement) || compiler.isInterfaceDeclaration(statement) || compiler.isTypeAliasDeclaration(statement) || compiler.isEnumDeclaration(statement) || compiler.isModuleDeclaration(statement)) && statement.name !== void 0 && compiler.isIdentifier(statement.name)) return [statement.name.text];
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
function isExportedDeclaration(compiler, statement, locals) {
|
|
53
|
+
if (compiler.isExportAssignment(statement)) return !compiler.isIdentifier(statement.expression);
|
|
54
|
+
if ((compiler.canHaveModifiers(statement) ? compiler.getModifiers(statement) : void 0)?.some((modifier) => modifier.kind === compiler.SyntaxKind.ExportKeyword)) return true;
|
|
55
|
+
return declaredNames(compiler, statement).some((name) => locals.has(name));
|
|
56
|
+
}
|
|
57
|
+
function hasInternalTag(compiler, statement) {
|
|
58
|
+
return compiler.getJSDocTags(statement).some((tag) => tag.tagName.text === "internal");
|
|
59
|
+
}
|
|
60
|
+
/** Whether a module's text carries `@internal` on the module (with `@packageDocumentation`, `@module` or `@fileoverview`) or on every exported declaration. */
|
|
61
|
+
function isInternalModule(compiler, text) {
|
|
62
|
+
const source = compiler.createSourceFile("module.ts", text, compiler.ScriptTarget.Latest, true);
|
|
63
|
+
if ((compiler.getLeadingCommentRanges(text, 0) ?? []).map((range) => text.slice(range.pos, range.end)).some((comment) => comment.startsWith("/**") && INTERNAL_TAG.test(comment) && MODULE_TAG.test(comment))) return true;
|
|
64
|
+
const locals = exportedLocalNames(compiler, source);
|
|
65
|
+
const exported = source.statements.filter((statement) => isExportedDeclaration(compiler, statement, locals));
|
|
66
|
+
return exported.length > 0 && exported.every((statement) => hasInternalTag(compiler, statement));
|
|
67
|
+
}
|
|
68
|
+
/** Records why an allowed added entry is not internal, or `undefined` when its module is. */
|
|
69
|
+
function recordVerdict(policy, compiler, entry) {
|
|
70
|
+
const internal = isInternalModule(compiler, readFileSync(entry.module, "utf8"));
|
|
71
|
+
policy.verdicts.set(entryKey(entry.directory, entry.subpath), internal ? void 0 : `${entry.label}: added entry ./${entry.subpath} is allowed by --allow-added but is not marked @internal. Add a leading "/** @internal @packageDocumentation */" comment to the file, or tag every exported declaration with "/** @internal */".`);
|
|
72
|
+
}
|
|
73
|
+
/** Lets matching, `@internal` additions through by removing them from the head output; returns how many files were removed. */
|
|
74
|
+
function applyAllowance(policy, base, head, remove) {
|
|
75
|
+
const existing = new Set(base.map(({ path }) => path));
|
|
76
|
+
let removed = 0;
|
|
77
|
+
for (const entry of head) {
|
|
78
|
+
if (existing.has(entry.path) || !allowedByGlob(policy, entry.subpath)) continue;
|
|
79
|
+
const key = entryKey(entry.directory, entry.subpath);
|
|
80
|
+
const problem = policy.verdicts.has(key) ? policy.verdicts.get(key) : `${entry.directory}: added entry ./${entry.subpath} has no emitted declaration, so @internal cannot be verified.`;
|
|
81
|
+
if (problem !== void 0) {
|
|
82
|
+
policy.problems.add(problem);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
remove(entry.path);
|
|
86
|
+
removed += 1;
|
|
87
|
+
policy.allowed.set(key, {
|
|
88
|
+
directory: entry.directory,
|
|
89
|
+
subpath: entry.subpath
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return removed;
|
|
93
|
+
}
|
|
94
|
+
/** The "Added (allowed)" list with its count, or the problems that kept additions from passing. */
|
|
95
|
+
function describeAllowance(policy) {
|
|
96
|
+
const lines = [...policy.allowed.values()].map(({ directory, subpath }) => ` ${directory}: ./${subpath}\n`).sort();
|
|
97
|
+
return `Added (allowed): ${lines.length}\n${lines.join("")}${[...policy.problems].map((problem) => `Not internal: ${problem}\n`).join("")}`;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/guardrails/revisions.ts
|
|
101
|
+
function trackedManifests(root) {
|
|
102
|
+
return execFileSync("git", ["ls-files", "-z"], {
|
|
103
|
+
cwd: root,
|
|
104
|
+
encoding: "utf8"
|
|
105
|
+
}).split("\0").filter((file) => file === "package.json" || file.endsWith("/package.json"));
|
|
106
|
+
}
|
|
107
|
+
const DIRECTORY_LINK = process.platform === "win32" ? "junction" : "dir";
|
|
108
|
+
function linkDependencies(root, worktree) {
|
|
109
|
+
const directories = /* @__PURE__ */ new Set([".", ...trackedManifests(root).map(dirname)]);
|
|
110
|
+
for (const directory of directories) {
|
|
111
|
+
const source = join(root, directory, "node_modules");
|
|
112
|
+
const target = join(worktree, directory, "node_modules");
|
|
113
|
+
if (existsSync(source) && existsSync(dirname(target)) && !existsSync(target)) symlinkSync(source, target, DIRECTORY_LINK);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Compares isolated committed revisions and removes both worktrees even when compilation fails; a policy lets matching `@internal` additions through. */
|
|
117
|
+
function compareRevisions(root, baseRef, label, emit, policy) {
|
|
118
|
+
const temporary = mkdtempSync(join(tmpdir(), "antelope-proof-"));
|
|
119
|
+
const worktrees = [];
|
|
120
|
+
const results = [];
|
|
121
|
+
try {
|
|
122
|
+
for (const [side, ref] of [["base", baseRef], ["head", "HEAD"]]) {
|
|
123
|
+
const revision = execFileSync("git", [
|
|
124
|
+
"rev-parse",
|
|
125
|
+
"--verify",
|
|
126
|
+
"--end-of-options",
|
|
127
|
+
`${ref}^{commit}`
|
|
128
|
+
], {
|
|
129
|
+
cwd: root,
|
|
130
|
+
encoding: "utf8",
|
|
131
|
+
stdio: [
|
|
132
|
+
"ignore",
|
|
133
|
+
"pipe",
|
|
134
|
+
"pipe"
|
|
135
|
+
]
|
|
136
|
+
}).trim();
|
|
137
|
+
const worktree = join(temporary, "worktrees", side);
|
|
138
|
+
execFileSync("git", [
|
|
139
|
+
"worktree",
|
|
140
|
+
"add",
|
|
141
|
+
"--quiet",
|
|
142
|
+
"--detach",
|
|
143
|
+
worktree,
|
|
144
|
+
revision
|
|
145
|
+
], {
|
|
146
|
+
cwd: root,
|
|
147
|
+
stdio: [
|
|
148
|
+
"ignore",
|
|
149
|
+
"pipe",
|
|
150
|
+
"pipe"
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
worktrees.push(worktree);
|
|
154
|
+
linkDependencies(root, worktree);
|
|
155
|
+
const output = join(temporary, side);
|
|
156
|
+
mkdirSync(output, { recursive: true });
|
|
157
|
+
results.push(emit(worktree, output, join(temporary, "emit", side)));
|
|
158
|
+
}
|
|
159
|
+
const allowedAdditions = policy === void 0 ? 0 : applyAllowance(policy, results[0].published ?? [], results[1].published ?? [], (path) => rmSync(join(temporary, "head", path), { force: true }));
|
|
160
|
+
const diff = spawnSync("git", [
|
|
161
|
+
"diff",
|
|
162
|
+
"--no-index",
|
|
163
|
+
"--no-color",
|
|
164
|
+
"--no-renames",
|
|
165
|
+
"--no-ext-diff",
|
|
166
|
+
"--no-textconv",
|
|
167
|
+
"--",
|
|
168
|
+
"base",
|
|
169
|
+
"head"
|
|
170
|
+
], {
|
|
171
|
+
cwd: temporary,
|
|
172
|
+
encoding: "utf8",
|
|
173
|
+
maxBuffer: 67108864
|
|
174
|
+
});
|
|
175
|
+
if (diff.error) throw diff.error;
|
|
176
|
+
if (diff.status !== 0 && diff.status !== 1) throw new Error(diff.stderr || "Could not compare revision outputs.");
|
|
177
|
+
const packages = new Set(results.flatMap((result) => result.packages)).size;
|
|
178
|
+
return {
|
|
179
|
+
different: diff.status === 1,
|
|
180
|
+
output: diff.status === 1 ? `${label}: differences against ${baseRef} (committed HEAD).\n${diff.stdout}` : `${label}: ${packages} packages, ${results[1].entries - allowedAdditions} entries unchanged against ${baseRef} (committed HEAD).\n`
|
|
181
|
+
};
|
|
182
|
+
} finally {
|
|
183
|
+
for (const worktree of worktrees.reverse()) execFileSync("git", [
|
|
184
|
+
"worktree",
|
|
185
|
+
"remove",
|
|
186
|
+
"--force",
|
|
187
|
+
worktree
|
|
188
|
+
], {
|
|
189
|
+
cwd: root,
|
|
190
|
+
stdio: "pipe"
|
|
191
|
+
});
|
|
192
|
+
rmSync(temporary, {
|
|
193
|
+
recursive: true,
|
|
194
|
+
force: true
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const COUNTS = [
|
|
199
|
+
["oxlint-disable / eslint-disable directive lines", /^\s*(?:\/\/|\/\*|\*)\s*(?:oxlint|eslint)-disable\b/u],
|
|
200
|
+
["SAFETY: lines", /^\s*(?:\/\/|\/\*|\*)\s*SAFETY:/u],
|
|
201
|
+
["@ts-expect-error lines", /^\s*(?:\/\/|\/\*|\*)\s*@ts-expect-error\b/u]
|
|
202
|
+
];
|
|
203
|
+
const CODE_PATHSPECS = [
|
|
204
|
+
"*.ts",
|
|
205
|
+
"*.tsx",
|
|
206
|
+
"*.mts",
|
|
207
|
+
"*.cts",
|
|
208
|
+
"*.js",
|
|
209
|
+
"*.jsx",
|
|
210
|
+
"*.mjs",
|
|
211
|
+
"*.cjs",
|
|
212
|
+
"*.vue"
|
|
213
|
+
];
|
|
214
|
+
function countsAt(root, ref) {
|
|
215
|
+
const result = spawnSync("git", [
|
|
216
|
+
"grep",
|
|
217
|
+
"-h",
|
|
218
|
+
"-I",
|
|
219
|
+
"-E",
|
|
220
|
+
"-e",
|
|
221
|
+
"(oxlint|eslint)-disable|SAFETY:|@ts-expect-error",
|
|
222
|
+
ref,
|
|
223
|
+
"--",
|
|
224
|
+
...CODE_PATHSPECS
|
|
225
|
+
], {
|
|
226
|
+
cwd: root,
|
|
227
|
+
encoding: "utf8",
|
|
228
|
+
maxBuffer: 67108864
|
|
229
|
+
});
|
|
230
|
+
if (result.error) throw result.error;
|
|
231
|
+
if (result.status !== 0 && result.status !== 1) throw new Error(result.stderr);
|
|
232
|
+
const lines = result.stdout.split("\n");
|
|
233
|
+
return COUNTS.map(([, pattern]) => lines.filter((line) => pattern.test(line)).length);
|
|
234
|
+
}
|
|
235
|
+
/** Counts directive, `SAFETY:` and `@ts-expect-error` lines in every tracked code file at the base and at committed HEAD, so a PR body copies them instead of typing them. */
|
|
236
|
+
function revisionCounts(root, baseRef) {
|
|
237
|
+
const base = countsAt(root, baseRef);
|
|
238
|
+
const head = countsAt(root, "HEAD");
|
|
239
|
+
return `\nCounts in tracked code files (${baseRef} and committed HEAD).\n| Lines | base | HEAD |\n| --- | ---: | ---: |\n${COUNTS.map(([label], index) => `| ${label} | ${base[index]} | ${head[index]} |`).join("\n")}\n`;
|
|
240
|
+
}
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/guardrails/files.ts
|
|
243
|
+
const SIZE_EXCLUSIONS = [
|
|
244
|
+
{
|
|
245
|
+
kind: "generated",
|
|
246
|
+
patterns: [
|
|
247
|
+
...IGNORE_PATTERNS,
|
|
248
|
+
...AGENT_IGNORE_PATTERNS,
|
|
249
|
+
"**/*.generated.*",
|
|
250
|
+
"**/generated/**",
|
|
251
|
+
"**/__snapshots__/**"
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
kind: "fixtures",
|
|
256
|
+
patterns: ["**/fixtures/**", "**/__fixtures__/**"]
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
kind: "data",
|
|
260
|
+
patterns: [
|
|
261
|
+
"**/locales/**/*.json",
|
|
262
|
+
"**/i18n/**/*.json",
|
|
263
|
+
"**/blocks.json",
|
|
264
|
+
"**/schema.json",
|
|
265
|
+
"**/evals/**/cases.json"
|
|
266
|
+
]
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
kind: "lockfiles",
|
|
270
|
+
patterns: [
|
|
271
|
+
"**/{pnpm-lock.yaml,package-lock.json,npm-shrinkwrap.json,yarn.lock,bun.lock,bun.lockb,Cargo.lock,poetry.lock,uv.lock,Gemfile.lock,composer.lock,go.sum}",
|
|
272
|
+
"**/*.lock",
|
|
273
|
+
"**/*.lockb"
|
|
274
|
+
]
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
kind: "documentation",
|
|
278
|
+
patterns: ["**/CHANGELOG.md", "**/*.{md,mdx,markdown,MD}"]
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
kind: "assets",
|
|
282
|
+
patterns: ["**/*.{png,jpg,jpeg,gif,webp,avif,ico,svg,bmp,tiff,pdf,mp3,wav,ogg,flac,mp4,webm,mov,avi,woff,woff2,ttf,otf,eot,zip,gz,tgz,bz2,xz,7z,tar,rar,wasm,bin,exe,dll,so,dylib,db,sqlite,sqlite3,icns}"]
|
|
283
|
+
}
|
|
284
|
+
];
|
|
285
|
+
function gitFiles(root) {
|
|
286
|
+
return [...new Set(execFileSync("git", [
|
|
287
|
+
"ls-files",
|
|
288
|
+
"--cached",
|
|
289
|
+
"--others",
|
|
290
|
+
"--exclude-standard",
|
|
291
|
+
"-z"
|
|
292
|
+
], {
|
|
293
|
+
cwd: root,
|
|
294
|
+
encoding: "utf8"
|
|
295
|
+
}).split("\0").filter(Boolean))];
|
|
296
|
+
}
|
|
297
|
+
function repositoryRoot(cwd = process.cwd()) {
|
|
298
|
+
return execFileSync("git", ["rev-parse", "--show-toplevel"], {
|
|
299
|
+
cwd,
|
|
300
|
+
encoding: "utf8"
|
|
301
|
+
}).trim();
|
|
302
|
+
}
|
|
303
|
+
/** Resolves a user-supplied revision to a commit id, so it can never read as an option. */
|
|
304
|
+
function resolveRevision(root, revision) {
|
|
305
|
+
return execFileSync("git", [
|
|
306
|
+
"rev-parse",
|
|
307
|
+
"--verify",
|
|
308
|
+
"--end-of-options",
|
|
309
|
+
`${revision}^{commit}`
|
|
310
|
+
], {
|
|
311
|
+
cwd: root,
|
|
312
|
+
encoding: "utf8",
|
|
313
|
+
stdio: [
|
|
314
|
+
"ignore",
|
|
315
|
+
"pipe",
|
|
316
|
+
"pipe"
|
|
317
|
+
]
|
|
318
|
+
}).trim();
|
|
319
|
+
}
|
|
320
|
+
function repositoryPath(root, file) {
|
|
321
|
+
return relative(root, resolve(root, file)).split("\\").join("/");
|
|
322
|
+
}
|
|
323
|
+
function fileBytes(root, file, staged = false) {
|
|
324
|
+
if (staged) {
|
|
325
|
+
const result = spawnSync("git", [
|
|
326
|
+
"cat-file",
|
|
327
|
+
"-s",
|
|
328
|
+
`:${file}`
|
|
329
|
+
], {
|
|
330
|
+
cwd: root,
|
|
331
|
+
encoding: "utf8"
|
|
332
|
+
});
|
|
333
|
+
if (result.error) throw result.error;
|
|
334
|
+
return result.status === 0 ? Number(result.stdout.trim()) : void 0;
|
|
335
|
+
}
|
|
336
|
+
const path = join(root, file);
|
|
337
|
+
if (!existsSync(path)) return void 0;
|
|
338
|
+
const stat = lstatSync(path);
|
|
339
|
+
return stat.isFile() ? stat.size : void 0;
|
|
340
|
+
}
|
|
341
|
+
/** A package root is the directory of a tracked manifest outside every `src` directory; its top-level `build` and `output` are generated output. */
|
|
342
|
+
function packageOutputPatterns(root) {
|
|
343
|
+
return trackedManifests(root).flatMap((manifest) => {
|
|
344
|
+
const directory = dirname(manifest);
|
|
345
|
+
if (directory === "." || directory.split("/").includes("src")) return [];
|
|
346
|
+
return [`${directory}/build/**`, `${directory}/output/**`];
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
/** `path.matchesGlob` never lets `*` or `**` cross a segment starting with a dot, so each path is also tried with those dots removed. */
|
|
350
|
+
function isExcluded(file, packageOutputs) {
|
|
351
|
+
const undotted = file.replace(/(^|\/)\./gu, "$1");
|
|
352
|
+
const matches = (pattern) => matchesGlob(file, pattern) || matchesGlob(undotted, pattern);
|
|
353
|
+
return SIZE_EXCLUSIONS.some(({ patterns }) => patterns.some(matches)) || packageOutputs.some(matches);
|
|
354
|
+
}
|
|
355
|
+
function isBinary(root, file, staged) {
|
|
356
|
+
if (staged) return execFileSync("git", ["show", `:${file}`], {
|
|
357
|
+
cwd: root,
|
|
358
|
+
maxBuffer: fileBytes(root, file, true)
|
|
359
|
+
}).subarray(0, 8e3).includes(0);
|
|
360
|
+
const descriptor = openSync(join(root, file), "r");
|
|
361
|
+
try {
|
|
362
|
+
const prefix = Buffer.alloc(8e3);
|
|
363
|
+
const length = readSync(descriptor, prefix, 0, prefix.length, 0);
|
|
364
|
+
return prefix.subarray(0, length).includes(0);
|
|
365
|
+
} finally {
|
|
366
|
+
closeSync(descriptor);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function authoredSizes(root, files = gitFiles(root), staged = false) {
|
|
370
|
+
const sizes = /* @__PURE__ */ new Map();
|
|
371
|
+
const packageOutputs = packageOutputPatterns(root);
|
|
372
|
+
for (const input of files) {
|
|
373
|
+
const file = repositoryPath(root, input);
|
|
374
|
+
if (isExcluded(file, packageOutputs)) continue;
|
|
375
|
+
const size = fileBytes(root, file, staged);
|
|
376
|
+
if (size !== void 0 && size > 2e4 && isBinary(root, file, staged)) continue;
|
|
377
|
+
if (size !== void 0) sizes.set(file, size);
|
|
378
|
+
}
|
|
379
|
+
return sizes;
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
export { resolveRevision as a, revisionCounts as c, createAddedPolicy as d, describeAllowance as f, runCli as h, repositoryRoot as i, trackedManifests as l, recordVerdict as m, gitFiles as n, DIRECTORY_LINK as o, fillStars as p, repositoryPath as r, compareRevisions as s, authoredSizes as t, allowedByGlob as u };
|
package/dist/oxc/fmt.mjs
CHANGED
package/dist/oxc/lint.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { i as findGitRoot
|
|
1
|
+
import { i as findGitRoot } from "../ceilings-BSw9p4YB.mjs";
|
|
2
|
+
import { t as readCarriedCeilings } from "../renames-BGO4dWJ8.mjs";
|
|
2
3
|
import { n as TEST_FILE_GLOBS, t as ASSERTION_FUNCTION_NAMES } from "../shared-WC0z3y9F.mjs";
|
|
3
|
-
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "../shared-
|
|
4
|
+
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "../shared-CsXIMK3I.mjs";
|
|
4
5
|
import { defineConfig } from "oxlint";
|
|
5
6
|
//#region src/oxc/lint.ts
|
|
6
7
|
/**
|
|
@@ -179,7 +180,7 @@ function importSortingPreset() {
|
|
|
179
180
|
/** Overrides run after rules, including test-specific rules; measurement bypasses all ceilings. */
|
|
180
181
|
function ratchetOverrides() {
|
|
181
182
|
if (process.env["ANTELOPEJS_RATCHET_MEASURE"] !== void 0) return [];
|
|
182
|
-
const ceilings =
|
|
183
|
+
const ceilings = readCarriedCeilings(findGitRoot());
|
|
183
184
|
const rules = Object.fromEntries(Object.keys(ceilings.rules).map((rule) => [rule, "off"]));
|
|
184
185
|
return [...Object.keys(ceilings.oversizeFiles).map((path) => ({
|
|
185
186
|
files: [path.replaceAll(/([*?[\]{}])/gu, "\\$1")],
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { a as formatCeilings, n as MAX_FILE_BYTES, o as isRetired, r as MEASURE_ENV,
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
1
|
+
import { a as formatCeilings, n as MAX_FILE_BYTES, o as isRetired, r as MEASURE_ENV, t as CEILINGS_FILE } from "./ceilings-BSw9p4YB.mjs";
|
|
2
|
+
import { t as readCarriedCeilings } from "./renames-BGO4dWJ8.mjs";
|
|
3
|
+
import { n as gitFiles, r as repositoryPath, t as authoredSizes } from "./files-CaMy-5ne.mjs";
|
|
4
|
+
import { n as sizeFailure } from "./size-DYVe2pXo.mjs";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import { existsSync, mkdtempSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
7
|
import { basename, dirname, join } from "node:path";
|
|
@@ -50,7 +51,7 @@ function lintDiagnostics(root, config, files) {
|
|
|
50
51
|
writeFileSync(path, config ?? "");
|
|
51
52
|
args.push("--config", path, "--ignore-pattern", `${basename(temporary)}/**`);
|
|
52
53
|
}
|
|
53
|
-
if (files) args.push("--", ...files);
|
|
54
|
+
if (files) args.push("--no-error-on-unmatched-pattern", "--", ...files);
|
|
54
55
|
const result = spawnSync(process.execPath, args, {
|
|
55
56
|
cwd: root,
|
|
56
57
|
encoding: "utf8",
|
|
@@ -137,9 +138,9 @@ function lowerCeilings(ceilings, current) {
|
|
|
137
138
|
}
|
|
138
139
|
return lowered;
|
|
139
140
|
}
|
|
140
|
-
function ratchet(root, update = false) {
|
|
141
|
+
function ratchet(root, update = false, base = "HEAD") {
|
|
141
142
|
if (!existsSync(join(root, "guardrails.ratchet.json"))) throw new Error(`${CEILINGS_FILE} is missing. Run antelopejs-sync first.`);
|
|
142
|
-
const ceilings =
|
|
143
|
+
const ceilings = readCarriedCeilings(root, false, [base]);
|
|
143
144
|
const diagnostics = lintDiagnostics(root);
|
|
144
145
|
const current = baseline(root, diagnostics);
|
|
145
146
|
const changed = changedFiles(root);
|