@antelopejs/tooling-configs 0.2.15 → 0.2.17
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 +88 -48
- package/dist/bin/api-diff.mjs +409 -97
- package/dist/bin/body-check.d.mts +1 -0
- package/dist/bin/body-check.mjs +344 -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 +5 -5
- package/dist/bin/ratchet.mjs +267 -7
- package/dist/bin/suppressions.mjs +118 -80
- package/dist/bin/sync.mjs +490 -35
- package/dist/bin/verify.mjs +48 -26
- package/dist/{ceilings-BSw9p4YB.mjs → ceilings-B7KayYIG.mjs} +11 -3
- package/dist/{checks-BlWDFYio.mjs → checks-CxkSu2E6.mjs} +1 -1
- package/dist/{ci-workflow-C0nT5SnX.mjs → ci-workflow-ChW4He0r.mjs} +103 -3
- package/dist/{files-2FikHZ9F.mjs → files-Bc036sJW.mjs} +2 -2
- package/dist/{json-BqvuCkqr.mjs → json-CG2L7YFl.mjs} +12 -8
- package/dist/oxc/anti-slop/index.mjs +160 -13
- package/dist/oxc/fmt.mjs +1 -1
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +645 -1
- package/dist/oxc/lint.d.mts +11 -3
- package/dist/oxc/lint.mjs +21 -8
- package/dist/oxlint-Bltmk8-6.mjs +94 -0
- package/dist/{package-Dtjt_lSa.mjs → package-DTxLPNDu.mjs} +3 -2
- package/dist/proof-stamp-w-3j47A-.mjs +279 -0
- package/dist/ratchet-DwRj9h4L.mjs +275 -0
- package/dist/{renames-BGO4dWJ8.mjs → renames-L2owF5GD.mjs} +2 -2
- package/dist/shared-CoUt4GUm.mjs +73 -0
- package/dist/{size-BVgNbLO6.mjs → size-DNtWruCO.mjs} +3 -3
- package/dist/suppression-base-DAfCXwjL.mjs +95 -0
- package/dist/{suppression-budget-Yyf5_J5l.mjs → suppression-budget-Bd2GqMYb.mjs} +248 -33
- package/dist/{suppressions-BJAngUxo.mjs → suppressions-BD_f8f7L.mjs} +180 -18
- package/dist/typescript-BmS5BmrS.mjs +222 -0
- package/dist/verify/index.mjs +1 -1
- package/package.json +4 -2
- 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/typescript-C54ONh9m.mjs +0 -433
package/dist/bin/verify.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as
|
|
3
|
-
import { a as
|
|
2
|
+
import { a as VERIFY_KINDS, c as isVerifyKind, l as skillFolder } from "../shared-CoUt4GUm.mjs";
|
|
3
|
+
import { a as isString, f as parseJson, i as isObject, u as optStr } from "../json-CG2L7YFl.mjs";
|
|
4
|
+
import { a as exitIs, c as interrupted, i as exists, r as equal, u as refused } from "../checks-CxkSu2E6.mjs";
|
|
4
5
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
5
|
-
import { o as repositoryRoot } from "../files-
|
|
6
|
-
import { a as skillFolder, i as isVerifyKind, t as VERIFY_KINDS } from "../kinds-Bzyyi9yk.mjs";
|
|
6
|
+
import { o as repositoryRoot } from "../files-Bc036sJW.mjs";
|
|
7
7
|
import { appendFileSync, closeSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { basename, dirname, extname, join, matchesGlob, posix, relative, resolve, sep } from "node:path";
|
|
9
9
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
10
10
|
import { parseArgs } from "node:util";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
|
-
import { homedir, tmpdir } from "node:os";
|
|
13
12
|
import ts from "typescript";
|
|
13
|
+
import { homedir, tmpdir } from "node:os";
|
|
14
14
|
import { randomBytes } from "node:crypto";
|
|
15
15
|
import { createServer } from "node:net";
|
|
16
16
|
//#region src/verify/doors.ts
|
|
@@ -88,7 +88,7 @@ function publicPart(declaration) {
|
|
|
88
88
|
}
|
|
89
89
|
/** Walks the types a set of signatures reaches and prints every declaration of the package among them. */
|
|
90
90
|
var DeclarationWalk = class {
|
|
91
|
-
|
|
91
|
+
declarations = /* @__PURE__ */ new Map();
|
|
92
92
|
seen = /* @__PURE__ */ new Set();
|
|
93
93
|
printer = ts.createPrinter({ removeComments: true });
|
|
94
94
|
checker;
|
|
@@ -97,14 +97,23 @@ var DeclarationWalk = class {
|
|
|
97
97
|
this.checker = checker;
|
|
98
98
|
this.isLocal = isLocal;
|
|
99
99
|
}
|
|
100
|
+
get found() {
|
|
101
|
+
return [...this.declarations.values()];
|
|
102
|
+
}
|
|
100
103
|
signature(signature) {
|
|
104
|
+
for (const parameter of signature.getTypeParameters() ?? []) this.type(parameter);
|
|
101
105
|
for (const parameter of signature.getParameters()) this.type(this.checker.getTypeOfSymbol(parameter));
|
|
102
106
|
this.type(signature.getReturnType());
|
|
103
107
|
}
|
|
104
108
|
record(symbol) {
|
|
105
|
-
if (this.
|
|
109
|
+
if (this.declarations.has(symbol) || (symbol.flags & NAMED) === 0 || !this.isLocal(symbol)) return;
|
|
106
110
|
const texts = (symbol.declarations ?? []).map((declaration) => this.printer.printNode(ts.EmitHint.Unspecified, publicPart(declaration), declaration.getSourceFile()).replace(/\s+/g, " ").replace(/^(?:export )?(?:declare )?/, ""));
|
|
107
|
-
this.
|
|
111
|
+
this.declarations.set(symbol, texts.join(" "));
|
|
112
|
+
for (const declaration of symbol.declarations ?? []) this.generics(declaration);
|
|
113
|
+
}
|
|
114
|
+
generics(declaration) {
|
|
115
|
+
if (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration) || ts.isTypeAliasDeclaration(declaration)) for (const parameter of declaration.typeParameters ?? []) this.type(this.checker.getTypeAtLocation(parameter));
|
|
116
|
+
if (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) for (const clause of declaration.heritageClauses ?? []) for (const base of clause.types) this.type(this.checker.getTypeAtLocation(base));
|
|
108
117
|
}
|
|
109
118
|
members(type) {
|
|
110
119
|
for (const property of this.checker.getPropertiesOfType(type)) this.type(this.checker.getTypeOfSymbol(property));
|
|
@@ -117,11 +126,20 @@ var DeclarationWalk = class {
|
|
|
117
126
|
for (const part of type.types) this.type(part);
|
|
118
127
|
return;
|
|
119
128
|
}
|
|
129
|
+
if (type.flags & ts.TypeFlags.TypeParameter) {
|
|
130
|
+
this.type(type.getConstraint() ?? type);
|
|
131
|
+
this.type(type.getDefault() ?? type);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
120
134
|
if (type.aliasSymbol) this.record(type.aliasSymbol);
|
|
121
135
|
for (const argument of type.aliasTypeArguments ?? []) this.type(argument);
|
|
122
136
|
if (isObjectType$1(type) && isReference(type)) for (const argument of this.checker.getTypeArguments(type)) this.type(argument);
|
|
123
137
|
const symbol = type.getSymbol();
|
|
124
138
|
if (symbol === void 0 || !this.isLocal(symbol)) return;
|
|
139
|
+
for (const declaration of symbol.declarations ?? []) {
|
|
140
|
+
const owner = ts.isEnumMember(declaration) ? this.checker.getSymbolAtLocation(declaration.parent.name) : void 0;
|
|
141
|
+
if (owner) this.record(owner);
|
|
142
|
+
}
|
|
125
143
|
this.record(symbol);
|
|
126
144
|
this.members(type);
|
|
127
145
|
}
|
|
@@ -135,7 +153,7 @@ var DeclarationWalk = class {
|
|
|
135
153
|
function referencedDeclarations(checker, isLocal, signatures) {
|
|
136
154
|
const walk = new DeclarationWalk(checker, isLocal);
|
|
137
155
|
for (const signature of signatures) walk.signature(signature);
|
|
138
|
-
return
|
|
156
|
+
return walk.found.sort((left, right) => left.localeCompare(right));
|
|
139
157
|
}
|
|
140
158
|
//#endregion
|
|
141
159
|
//#region src/verify/surface.ts
|
|
@@ -2263,13 +2281,13 @@ function isPropertyName(node) {
|
|
|
2263
2281
|
return (ts.isPropertyAccessExpression(parent) || ts.isPropertyAssignment(parent) || ts.isMethodDeclaration(parent) || ts.isPropertyDeclaration(parent) || ts.isGetAccessor(parent) || ts.isSetAccessor(parent) || ts.isEnumMember(parent)) && parent.name === node;
|
|
2264
2282
|
}
|
|
2265
2283
|
/**
|
|
2266
|
-
* A binding
|
|
2267
|
-
* declaration, which may move between covered
|
|
2268
|
-
* otherwise, so a variable or class of one file
|
|
2269
|
-
* name in another.
|
|
2284
|
+
* A binding is its name alone when that module declares it as a function
|
|
2285
|
+
* declaration no other covered file declares, which may move between covered
|
|
2286
|
+
* files, and `module#name` otherwise, so a variable or class of one file, or a
|
|
2287
|
+
* function of the same name in another, never reads as it.
|
|
2270
2288
|
*/
|
|
2271
2289
|
function bindingOrigin(covered, module, name) {
|
|
2272
|
-
return covered.
|
|
2290
|
+
return covered.functions.get(module)?.has(name) && !covered.duplicated.has(name) ? name : `${module}#${name}`;
|
|
2273
2291
|
}
|
|
2274
2292
|
function importedBindings(clause, module, covered) {
|
|
2275
2293
|
const named = clause.namedBindings;
|
|
@@ -2281,9 +2299,8 @@ function importedBindings(clause, module, covered) {
|
|
|
2281
2299
|
}
|
|
2282
2300
|
function reexportTexts(statement, module, covered) {
|
|
2283
2301
|
const exported = statement.exportClause;
|
|
2284
|
-
|
|
2285
|
-
if (exported
|
|
2286
|
-
if (ts.isNamespaceExport(exported)) return inside ? [] : [`export * as ${exported.name.text} from ${module}`];
|
|
2302
|
+
if (exported === void 0) return [`export * from ${module}`];
|
|
2303
|
+
if (ts.isNamespaceExport(exported)) return [`export * as ${exported.name.text} from ${module}`];
|
|
2287
2304
|
return exported.elements.flatMap((element) => {
|
|
2288
2305
|
const origin = bindingOrigin(covered, module, (element.propertyName ?? element.name).text);
|
|
2289
2306
|
return origin === element.name.text ? [] : [`export ${origin} as ${element.name.text}`];
|
|
@@ -2311,13 +2328,14 @@ function localExportTexts(statement, bindings, locals) {
|
|
|
2311
2328
|
* what a use refers to. A binding from a covered module is its name alone
|
|
2312
2329
|
* when it is a function declaration, so moving the declaration between
|
|
2313
2330
|
* covered files keeps every use the same; any other binding is keyed by its
|
|
2314
|
-
* module.
|
|
2331
|
+
* module. A side-effect import keeps its order in the file relative to the binding imports before it, and `export *` is an entry like any re-export. Re-exports and
|
|
2315
2332
|
* renamed or imported exports become entries keyed by the origin they export.
|
|
2316
2333
|
*/
|
|
2317
2334
|
function originsOf(path, covered, file, locals) {
|
|
2318
2335
|
const bindings = /* @__PURE__ */ new Map();
|
|
2319
2336
|
const texts = [];
|
|
2320
2337
|
const ordered = [];
|
|
2338
|
+
const earlier = [];
|
|
2321
2339
|
const exports = [];
|
|
2322
2340
|
for (const statement of file.statements) {
|
|
2323
2341
|
if (!(ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement))) continue;
|
|
@@ -2327,9 +2345,10 @@ function originsOf(path, covered, file, locals) {
|
|
|
2327
2345
|
const module = moduleKey(path, specifier.text);
|
|
2328
2346
|
if (ts.isImportDeclaration(statement)) {
|
|
2329
2347
|
if (statement.importClause === void 0) {
|
|
2330
|
-
ordered.push(`import ${module}`);
|
|
2348
|
+
ordered.push(`import ${module} after ${earlier.join(",")}`);
|
|
2331
2349
|
continue;
|
|
2332
2350
|
}
|
|
2351
|
+
earlier.push(module);
|
|
2333
2352
|
for (const [name, origin] of importedBindings(statement.importClause, module, covered)) bindings.set(name, origin);
|
|
2334
2353
|
} else texts.push(...reexportTexts(statement, module, covered));
|
|
2335
2354
|
}
|
|
@@ -2398,17 +2417,18 @@ function declaredNames(name) {
|
|
|
2398
2417
|
function isFunctionDeclaration(statement) {
|
|
2399
2418
|
return ts.isFunctionDeclaration(statement) && Boolean(statement.body) && statement.name !== void 0;
|
|
2400
2419
|
}
|
|
2401
|
-
/** The top-level variables, classes and enums of a script, each keyed by its file and name: what a function moved into another file must not pick up by name. */
|
|
2402
|
-
function localsOf(script) {
|
|
2420
|
+
/** The top-level variables, classes and enums of a script, and its functions that another covered file also declares, each keyed by its file and name: what a function moved into another file must not pick up by name. */
|
|
2421
|
+
function localsOf(script, covered) {
|
|
2403
2422
|
const file = script.path.replace(MODULE_EXTENSION, "");
|
|
2404
2423
|
const names = script.file.statements.flatMap((statement) => {
|
|
2405
2424
|
if (ts.isVariableStatement(statement)) return statement.declarationList.declarations.flatMap((declaration) => declaredNames(declaration.name));
|
|
2406
2425
|
return (ts.isClassDeclaration(statement) || ts.isEnumDeclaration(statement)) && statement.name ? [statement.name.text] : [];
|
|
2407
2426
|
});
|
|
2408
|
-
|
|
2427
|
+
const clashing = [...covered.functions.get(file) ?? []].filter((name) => covered.duplicated.has(name));
|
|
2428
|
+
return new Map([...names, ...clashing].map((name) => [name, `${file}#${name}`]));
|
|
2409
2429
|
}
|
|
2410
2430
|
function scriptItems(script, covered) {
|
|
2411
|
-
const locals = localsOf(script);
|
|
2431
|
+
const locals = localsOf(script, covered);
|
|
2412
2432
|
const origins = originsOf(script.path, covered, script.file, locals);
|
|
2413
2433
|
const inFunctions = new Map([...locals, ...origins.bindings]);
|
|
2414
2434
|
const statements = script.file.statements.filter((statement) => !ts.isImportDeclaration(statement) && !ts.isExportDeclaration(statement)).map((statement) => {
|
|
@@ -2478,9 +2498,12 @@ function emitFingerprint(repo, sha, files) {
|
|
|
2478
2498
|
const source = fileAt(repo, sha, path);
|
|
2479
2499
|
return source === null ? [] : [parsedFile(path, source)];
|
|
2480
2500
|
});
|
|
2501
|
+
const functions = new Map(parsed.map(({ path, scripts }) => [path.replace(MODULE_EXTENSION, ""), new Set(scripts.flatMap(({ file }) => file.statements.filter(isFunctionDeclaration).map(({ name }) => name.text)))]));
|
|
2502
|
+
const declarations = [...functions.values()].flatMap((names) => [...names]);
|
|
2481
2503
|
const covered = {
|
|
2482
2504
|
modules: new Set(files.map((path) => path.replace(MODULE_EXTENSION, ""))),
|
|
2483
|
-
functions
|
|
2505
|
+
functions,
|
|
2506
|
+
duplicated: new Set(declarations.filter((name, index) => declarations.indexOf(name) !== index))
|
|
2484
2507
|
};
|
|
2485
2508
|
for (const { path, scripts, others } of parsed) {
|
|
2486
2509
|
const items = [...scripts.flatMap((script) => scriptItems(script, covered)), ...others];
|
|
@@ -3631,8 +3654,7 @@ function runSeededDoors(workspace) {
|
|
|
3631
3654
|
function runContainmentCheck(workspace, baseRef) {
|
|
3632
3655
|
const results = runContainments(workspace, process.argv[1], baseRef);
|
|
3633
3656
|
for (const result of results) print(`${result.outcome} ${result.kind} ${result.containment}: ${result.detail}${result.run ? ` (evidence ${result.run}, control ${result.controlRun})` : ""}`);
|
|
3634
|
-
|
|
3635
|
-
return results.length > 0 && results.every((result) => result.outcome === "CONTAINED") ? 0 : 1;
|
|
3657
|
+
return results.every((result) => result.outcome === "CONTAINED") ? 0 : 1;
|
|
3636
3658
|
}
|
|
3637
3659
|
const PROOF_COMMANDS = /* @__PURE__ */ new Set([
|
|
3638
3660
|
"seeded",
|
|
@@ -34,14 +34,21 @@ function readCeilings(root) {
|
|
|
34
34
|
if (!existsSync(path)) return EMPTY_CEILINGS;
|
|
35
35
|
return parseCeilings(readFileSync(path, "utf8"), path);
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
37
|
+
/** Whether `value` is a `major.minor.patch` release. */
|
|
38
|
+
function isPackRelease(value) {
|
|
39
|
+
return /^\d+\.\d+\.\d+$/u.test(value);
|
|
40
|
+
}
|
|
41
|
+
/** Parses the ceilings file, rejecting anything but non-negative integer counts and a release for `pack`. */
|
|
38
42
|
function parseCeilings(text, source) {
|
|
39
43
|
const parsed = JSON.parse(text);
|
|
40
44
|
if (parsed === null || Array.isArray(parsed)) throw new Error(`${source}: expected an object with "rules" and "oversizeFiles"`);
|
|
41
|
-
|
|
45
|
+
if (parsed.pack !== void 0 && !isPackRelease(parsed.pack)) throw new Error(`${source}: "pack" must be a release such as "0.2.17"`);
|
|
46
|
+
const ceilings = {
|
|
42
47
|
rules: parseCounts(parsed.rules, `${source}: rules`),
|
|
43
48
|
oversizeFiles: parseCounts(parsed.oversizeFiles, `${source}: oversizeFiles`)
|
|
44
49
|
};
|
|
50
|
+
if (parsed.pack !== void 0) ceilings.pack = parsed.pack;
|
|
51
|
+
return ceilings;
|
|
45
52
|
}
|
|
46
53
|
function parseCounts(value, source) {
|
|
47
54
|
if (value === void 0) return {};
|
|
@@ -59,10 +66,11 @@ function sortedCounts(counts) {
|
|
|
59
66
|
/** Serializes ceilings with sorted keys, so rewriting an unchanged file is a no-op. */
|
|
60
67
|
function formatCeilings(ceilings) {
|
|
61
68
|
const sorted = {
|
|
69
|
+
pack: ceilings.pack,
|
|
62
70
|
rules: sortedCounts(ceilings.rules),
|
|
63
71
|
oversizeFiles: sortedCounts(ceilings.oversizeFiles)
|
|
64
72
|
};
|
|
65
73
|
return `${JSON.stringify(sorted, null, 2)}\n`;
|
|
66
74
|
}
|
|
67
75
|
//#endregion
|
|
68
|
-
export { formatCeilings as a, findGitRoot as i, MAX_FILE_BYTES as n,
|
|
76
|
+
export { formatCeilings as a, parseCeilings as c, findGitRoot as i, readCeilings as l, MAX_FILE_BYTES as n, isPackRelease as o, MEASURE_ENV as r, isRetired as s, CEILINGS_FILE as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { isMap, isPair, isScalar, isSeq, parseDocument, visit } from "yaml";
|
|
3
|
+
import { Scalar, isMap, isPair, isScalar, isSeq, parseDocument, visit } from "yaml";
|
|
4
4
|
//#region src/guardrails/workflow.ts
|
|
5
5
|
const CI_NODE_PATTERN = /^AntelopeJS\/\.github\/\.github\/workflows\/ci-node\.yml@\S+$/;
|
|
6
6
|
const CI_RENOVATE_SYNC_PATTERN = /^AntelopeJS\/\.github\/\.github\/workflows\/ci-renovate-sync\.yml@\S+$/;
|
|
@@ -53,6 +53,51 @@ function ciRenovateSyncCallers(text) {
|
|
|
53
53
|
return callers(text, CI_RENOVATE_SYNC_PATTERN);
|
|
54
54
|
}
|
|
55
55
|
//#endregion
|
|
56
|
+
//#region src/guardrails/workflow-needs.ts
|
|
57
|
+
const NEEDS_REFERENCE = /(?<![\w.'"-])needs(?:\.([A-Za-z_][\w-]*)|\[\s*(['"])([^'"]+)\2\s*\])/g;
|
|
58
|
+
function neededIds(job) {
|
|
59
|
+
const needs = job.get("needs", true);
|
|
60
|
+
return (isSeq(needs) ? needs.items : [needs]).flatMap((entry) => isScalar(entry) ? [String(entry.value)] : []);
|
|
61
|
+
}
|
|
62
|
+
function isText$1(value) {
|
|
63
|
+
return String(value) === value;
|
|
64
|
+
}
|
|
65
|
+
function expressionsOf(job) {
|
|
66
|
+
const expressions = [];
|
|
67
|
+
visit(job, { Scalar(key, node, path) {
|
|
68
|
+
if (key === "key") return;
|
|
69
|
+
const text = node.value;
|
|
70
|
+
if (!isText$1(text)) return;
|
|
71
|
+
const parent = path.at(-1);
|
|
72
|
+
if (isPair(parent) && isScalar(parent.key) && parent.key.value === "if") expressions.push(text);
|
|
73
|
+
else expressions.push(...text.match(/\$\{\{[\s\S]*?\}\}/g) ?? []);
|
|
74
|
+
} });
|
|
75
|
+
return expressions;
|
|
76
|
+
}
|
|
77
|
+
function referencedIds(job) {
|
|
78
|
+
return expressionsOf(job).flatMap((expression) => [...expression.matchAll(NEEDS_REFERENCE)].map(([, dotted, , quoted]) => dotted ?? quoted));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Lists every `needs:` entry naming no job and every `needs.<id>` or `needs['<id>']` read in a job's `if:` or `${{ }}`
|
|
82
|
+
* expressions whose id is not in that job's `needs:`. GitHub evaluates such a read to null, so a gate condition like
|
|
83
|
+
* `needs.checks.result == 'skipped'` silently stops failing once the job it named was renamed.
|
|
84
|
+
*/
|
|
85
|
+
function staleNeeds(document, path) {
|
|
86
|
+
const jobs = document.get("jobs", true);
|
|
87
|
+
if (!isMap(jobs)) return [];
|
|
88
|
+
const ids = new Set(jobs.items.flatMap(({ key }) => isScalar(key) ? [String(key.value)] : []));
|
|
89
|
+
const problems = [];
|
|
90
|
+
for (const { key, value: job } of jobs.items) {
|
|
91
|
+
if (!isScalar(key) || !isMap(job)) continue;
|
|
92
|
+
const name = String(key.value);
|
|
93
|
+
const needed = neededIds(job);
|
|
94
|
+
for (const id of needed) if (!ids.has(id)) problems.push(`${path}: job ${name} needs ${id}, but no job ${id} exists. Replace it with the job id it was renamed to (the ci-node.yml caller is ci), then rerun antelopejs-sync --check.`);
|
|
95
|
+
const listed = `[${needed.join(", ")}]`;
|
|
96
|
+
for (const id of new Set(referencedIds(job))) if (!needed.includes(id)) problems.push(`${path}: job ${name} reads needs.${id}, but ${id} is not in its needs: ${listed}, so the read is always null. Read needs.<id> of a job in that list (the ci-node.yml caller is needs.ci), or add ${id} to needs, then rerun antelopejs-sync --check.`);
|
|
97
|
+
}
|
|
98
|
+
return problems;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
56
101
|
//#region src/guardrails/ci-workflow.ts
|
|
57
102
|
const CI_PATH = ".github/workflows/ci.yml";
|
|
58
103
|
const MUTATION_PATH = ".github/workflows/mutation.yml";
|
|
@@ -155,6 +200,24 @@ function renameNeeds(document, from, to) {
|
|
|
155
200
|
}
|
|
156
201
|
}
|
|
157
202
|
}
|
|
203
|
+
function escapeRegExp(text) {
|
|
204
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
205
|
+
}
|
|
206
|
+
function renameNeedsReferences(text, from, to) {
|
|
207
|
+
const id = escapeRegExp(from);
|
|
208
|
+
const reference = new RegExp(`(?<![\\w.'"-])needs(?:\\.${id}(?![\\w-])|\\[\\s*(['"])${id}\\1\\s*\\])`, "g");
|
|
209
|
+
return text.replace(reference, (_match, quote) => quote === void 0 ? `needs.${to}` : `needs[${quote}${to}${quote}]`);
|
|
210
|
+
}
|
|
211
|
+
function isText(value) {
|
|
212
|
+
return String(value) === value;
|
|
213
|
+
}
|
|
214
|
+
function renameNeedsExpressions(document, from, to) {
|
|
215
|
+
visit(document, { Scalar(key, node, path) {
|
|
216
|
+
if (key === "key" || !isText(node.value)) return;
|
|
217
|
+
const parent = path.at(-1);
|
|
218
|
+
node.value = isPair(parent) && isScalar(parent.key) && parent.key.value === "if" ? renameNeedsReferences(node.value, from, to) : node.value.replace(/\$\{\{[\s\S]*?\}\}/g, (expression) => renameNeedsReferences(expression, from, to));
|
|
219
|
+
} });
|
|
220
|
+
}
|
|
158
221
|
function hasDispatch(document) {
|
|
159
222
|
const trigger = document.get("on", true);
|
|
160
223
|
if (isMap(trigger)) return trigger.has("workflow_dispatch");
|
|
@@ -188,6 +251,38 @@ function skipRenovateSync(document, job) {
|
|
|
188
251
|
else job.set("with", document.createNode({ "renovate-sync": false }));
|
|
189
252
|
return true;
|
|
190
253
|
}
|
|
254
|
+
function lines(text) {
|
|
255
|
+
return text.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
256
|
+
}
|
|
257
|
+
function normalizePath(path) {
|
|
258
|
+
return path.replace(/^(?:\.\/)+/, "").replace(/\/+$/, "");
|
|
259
|
+
}
|
|
260
|
+
function mergedDocsFiles(current, plan) {
|
|
261
|
+
const computed = new Set(plan.docsFiles);
|
|
262
|
+
const kept = current.map(normalizePath).filter((path) => path && !computed.has(path) && plan.exists(path));
|
|
263
|
+
return [.../* @__PURE__ */ new Set([...plan.docsFiles, ...kept])];
|
|
264
|
+
}
|
|
265
|
+
function setDocsFiles(document, job, plan) {
|
|
266
|
+
const inputs = job.get("with", true);
|
|
267
|
+
const current = isMap(inputs) ? inputs.get("docs-files", true) : void 0;
|
|
268
|
+
const existing = isScalar(current) ? lines(String(current.value)) : [];
|
|
269
|
+
const files = mergedDocsFiles(existing, plan);
|
|
270
|
+
if (isScalar(current) && existing.join("\n") === files.join("\n")) return false;
|
|
271
|
+
const value = new Scalar(`${files.join("\n")}\n`);
|
|
272
|
+
value.type = Scalar.BLOCK_LITERAL;
|
|
273
|
+
if (isMap(inputs)) inputs.set("docs-files", value);
|
|
274
|
+
else job.set("with", document.createNode({ "docs-files": value }));
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
function setCallersDocsFiles(document, jobs, callers, plan) {
|
|
278
|
+
let changed = false;
|
|
279
|
+
if (!plan?.docsFiles.length) return false;
|
|
280
|
+
for (const { id } of callers) {
|
|
281
|
+
const job = jobs.get(id, true);
|
|
282
|
+
if (isMap(job)) changed = setDocsFiles(document, job, plan) || changed;
|
|
283
|
+
}
|
|
284
|
+
return changed;
|
|
285
|
+
}
|
|
191
286
|
function canonicalSyncJob() {
|
|
192
287
|
const job = parseDocument(CI_CALLER).getIn(["jobs", RENOVATE_SYNC_JOB_ID], true);
|
|
193
288
|
if (!isMap(job)) throw new Error("CI_CALLER has no renovate-sync job");
|
|
@@ -218,8 +313,10 @@ function assertNoClash(jobs, callerId, hasSyncCaller) {
|
|
|
218
313
|
* dispatchable and read-only, with the Renovate sync it would otherwise run turned off. The write permissions the sync
|
|
219
314
|
* needs to push and dispatch the caller live on a separate job calling ci-renovate-sync.yml, which is added when missing.
|
|
220
315
|
* No `uses:` ref is ever rewritten. A workflow with no caller job is repository-specific CI and is left as it is.
|
|
316
|
+
* When `docsFiles` computes paths, every caller's `docs-files` input lists them first, then keeps its hand-listed paths
|
|
317
|
+
* that still exist, so sync never drops coverage.
|
|
221
318
|
*/
|
|
222
|
-
function ciWorkflow(current, callers, syncCallers) {
|
|
319
|
+
function ciWorkflow(current, callers, syncCallers, docsFiles) {
|
|
223
320
|
if (current === void 0) return CI_CALLER;
|
|
224
321
|
if (!callers.length) return current;
|
|
225
322
|
const document = parseDocument(current);
|
|
@@ -230,7 +327,7 @@ function ciWorkflow(current, callers, syncCallers) {
|
|
|
230
327
|
assertNoClash(jobs, caller.id, syncCallers.length > 0);
|
|
231
328
|
const pair = jobs.items.find(({ key }) => isScalar(key) && key.value === caller.id);
|
|
232
329
|
if (!pair || !isMap(pair.value)) return current;
|
|
233
|
-
let changed =
|
|
330
|
+
let changed = setCallersDocsFiles(document, jobs, callers, docsFiles);
|
|
234
331
|
if (caller.named) {
|
|
235
332
|
pair.value.delete("name");
|
|
236
333
|
changed = true;
|
|
@@ -238,6 +335,7 @@ function ciWorkflow(current, callers, syncCallers) {
|
|
|
238
335
|
if (caller.id !== "ci") {
|
|
239
336
|
if (isScalar(pair.key)) pair.key.value = "ci";
|
|
240
337
|
renameNeeds(document, caller.id, "ci");
|
|
338
|
+
renameNeedsExpressions(document, caller.id, "ci");
|
|
241
339
|
changed = true;
|
|
242
340
|
}
|
|
243
341
|
changed = grant(document, pair.value, { contents: "read" }) || changed;
|
|
@@ -247,6 +345,8 @@ function ciWorkflow(current, callers, syncCallers) {
|
|
|
247
345
|
addDispatch(document);
|
|
248
346
|
changed = true;
|
|
249
347
|
}
|
|
348
|
+
const stale = staleNeeds(document, CI_PATH);
|
|
349
|
+
if (stale.length) throw new Error(stale.join("\n"));
|
|
250
350
|
if (!changed) return current;
|
|
251
351
|
blockOverflowingFlow(document);
|
|
252
352
|
return document.toString({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./ceilings-
|
|
2
|
-
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "./shared-
|
|
1
|
+
import "./ceilings-B7KayYIG.mjs";
|
|
2
|
+
import { n as IGNORE_PATTERNS, t as AGENT_IGNORE_PATTERNS } from "./shared-CoUt4GUm.mjs";
|
|
3
3
|
import { closeSync, existsSync, lstatSync, openSync, readSync } from "node:fs";
|
|
4
4
|
import { dirname, join, matchesGlob, relative, resolve } from "node:path";
|
|
5
5
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
@@ -21,37 +21,41 @@ function list(value, path) {
|
|
|
21
21
|
if (!Array.isArray(value)) throw new DecodeError(`${path}: expected a list`);
|
|
22
22
|
return value;
|
|
23
23
|
}
|
|
24
|
+
/** The field's value when the payload has it as an own key; never one inherited from `Object.prototype`. */
|
|
25
|
+
function field(source, key) {
|
|
26
|
+
return Object.hasOwn(source, key) ? source[key] : void 0;
|
|
27
|
+
}
|
|
24
28
|
function str(source, key) {
|
|
25
|
-
const value = source
|
|
29
|
+
const value = field(source, key);
|
|
26
30
|
if (value === void 0 || !isString(value)) throw new DecodeError(`${key}: expected a string`);
|
|
27
31
|
return value;
|
|
28
32
|
}
|
|
29
33
|
function optStr(source, key) {
|
|
30
|
-
const value = source
|
|
34
|
+
const value = field(source, key);
|
|
31
35
|
return value !== void 0 && isString(value) ? value : void 0;
|
|
32
36
|
}
|
|
33
37
|
function num(source, key) {
|
|
34
|
-
const value = source
|
|
38
|
+
const value = field(source, key);
|
|
35
39
|
if (value === void 0 || !isNumber(value)) throw new DecodeError(`${key}: expected a number`);
|
|
36
40
|
return value;
|
|
37
41
|
}
|
|
38
42
|
function optNum(source, key) {
|
|
39
|
-
const value = source
|
|
43
|
+
const value = field(source, key);
|
|
40
44
|
return value !== void 0 && isNumber(value) ? value : void 0;
|
|
41
45
|
}
|
|
42
46
|
function flag(source, key) {
|
|
43
|
-
return source
|
|
47
|
+
return field(source, key) === true;
|
|
44
48
|
}
|
|
45
49
|
function child(source, key) {
|
|
46
|
-
const value = source
|
|
50
|
+
const value = field(source, key);
|
|
47
51
|
return value === void 0 ? {} : object(value, key);
|
|
48
52
|
}
|
|
49
53
|
function children(source, key) {
|
|
50
|
-
const value = source
|
|
54
|
+
const value = field(source, key);
|
|
51
55
|
return value === void 0 ? [] : list(value, key).map((entry) => object(entry, key));
|
|
52
56
|
}
|
|
53
57
|
function strings(source, key) {
|
|
54
|
-
const value = source
|
|
58
|
+
const value = field(source, key);
|
|
55
59
|
return value === void 0 ? [] : list(value, key).filter((entry) => isString(entry));
|
|
56
60
|
}
|
|
57
61
|
function time(source, key) {
|