@antelopejs/tooling-configs 0.5.1 → 0.5.3
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 +21 -9
- package/dist/bin/api-diff.mjs +3 -3
- package/dist/bin/body-check.mjs +2 -2
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +2 -774
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/garden.mjs +221 -215
- package/dist/bin/lease.mjs +1 -1
- package/dist/bin/ratchet.mjs +4 -4
- package/dist/bin/suppressions.mjs +4 -4
- package/dist/bin/sync.mjs +624 -557
- package/dist/checks-BFGuy1KI.mjs +1506 -0
- package/dist/oxc/lint.mjs +1 -1
- package/dist/{oxlint-DIV-lLSS.mjs → oxlint-BbpTFFmf.mjs} +7 -2
- package/dist/{package-Dn7VTFUW.mjs → package-DiaBP7bI.mjs} +65 -15
- package/dist/{proof-stamp-DLWpPwQE.mjs → proof-stamp-BPIdT5ik.mjs} +2 -2
- package/dist/{ratchet-ClfblHNJ.mjs → ratchet-BZvlFCWL.mjs} +3 -3
- package/dist/{suppression-base-Drnl6Y7F.mjs → suppression-base-DZgUDXiI.mjs} +2 -2
- package/dist/{suppression-budget-Dvb_IqBo.mjs → suppression-budget-DgYdu6JK.mjs} +1 -1
- package/dist/{suppressions-BroaaGJ_.mjs → suppressions-CQTcKCi1.mjs} +1 -1
- package/dist/{templates-lJBZFskp.mjs → templates-C6cfOd2H.mjs} +1 -1
- package/dist/{typescript-BBbry7uU.mjs → typescript-DJzdex32.mjs} +1 -1
- package/dist/{ci-workflow-COJUT12b.mjs → workflow-CPcNc8KL.mjs} +112 -109
- package/package.json +3 -2
package/dist/bin/checks.mjs
CHANGED
|
@@ -1,780 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as CEILINGS_FILE } from "../ceilings-B7KayYIG.mjs";
|
|
3
|
-
import { a as parseManifest, i as packageManager } from "../package-Dn7VTFUW.mjs";
|
|
4
2
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { t as
|
|
7
|
-
import { createRequire } from "node:module";
|
|
8
|
-
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
-
import { basename, dirname, join, posix, relative, resolve, sep } from "node:path";
|
|
10
|
-
import { spawn } from "node:child_process";
|
|
11
|
-
import { isMap, isScalar, isSeq, parseAllDocuments, parseDocument } from "yaml";
|
|
12
|
-
import { createHash } from "node:crypto";
|
|
13
|
-
import { tmpdir } from "node:os";
|
|
3
|
+
import { c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
4
|
+
import { r as runChecks, t as CHECKS_SKIP_ENV } from "../checks-BFGuy1KI.mjs";
|
|
14
5
|
import { parseArgs } from "node:util";
|
|
15
|
-
//#region src/guardrails/run-command.ts
|
|
16
|
-
const KILL_GRACE_MS = 5e3;
|
|
17
|
-
function stopGroup(child, signal) {
|
|
18
|
-
if (child.pid === void 0 || child.exitCode !== null) return;
|
|
19
|
-
try {
|
|
20
|
-
if (process.platform === "win32") child.kill(signal);
|
|
21
|
-
else process.kill(-child.pid, signal);
|
|
22
|
-
} catch {
|
|
23
|
-
child.kill(signal);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Runs `command` in its own process group and collects stdout and stderr together. When `signal` aborts, the group
|
|
28
|
-
* gets SIGTERM, then SIGKILL after a grace period, so a step's own children stop with it. On Windows the command runs
|
|
29
|
-
* through a shell, so `npm` and `pnpm` resolve to their `.cmd` shims, unless `shell` is `false`: pass that for an
|
|
30
|
-
* executable path and arguments that a shell must not split, such as paths with spaces.
|
|
31
|
-
*/
|
|
32
|
-
function runCommand(command, args, options) {
|
|
33
|
-
const { cwd, env = process.env, signal, shell = process.platform === "win32" } = options;
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
const child = spawn(command, args, {
|
|
36
|
-
cwd,
|
|
37
|
-
env,
|
|
38
|
-
shell,
|
|
39
|
-
detached: process.platform !== "win32",
|
|
40
|
-
stdio: [
|
|
41
|
-
"ignore",
|
|
42
|
-
"pipe",
|
|
43
|
-
"pipe"
|
|
44
|
-
]
|
|
45
|
-
});
|
|
46
|
-
const chunks = [];
|
|
47
|
-
const stdout = [];
|
|
48
|
-
child.stdout.on("data", (chunk) => {
|
|
49
|
-
chunks.push(chunk);
|
|
50
|
-
stdout.push(chunk);
|
|
51
|
-
});
|
|
52
|
-
child.stderr.on("data", (chunk) => chunks.push(chunk));
|
|
53
|
-
const interrupt = () => {
|
|
54
|
-
stopGroup(child, "SIGTERM");
|
|
55
|
-
setTimeout(() => stopGroup(child, "SIGKILL"), KILL_GRACE_MS).unref();
|
|
56
|
-
};
|
|
57
|
-
if (signal?.aborted) interrupt();
|
|
58
|
-
else signal?.addEventListener("abort", interrupt, { once: true });
|
|
59
|
-
child.once("error", (error) => {
|
|
60
|
-
signal?.removeEventListener("abort", interrupt);
|
|
61
|
-
resolve({
|
|
62
|
-
status: null,
|
|
63
|
-
stdout: "",
|
|
64
|
-
output: `${error.message}\n`
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
child.once("close", (code, killed) => {
|
|
68
|
-
signal?.removeEventListener("abort", interrupt);
|
|
69
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
70
|
-
resolve({
|
|
71
|
-
status: code,
|
|
72
|
-
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
73
|
-
output: `${text}${killed ? `Terminated by ${killed}\n` : ""}`
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/guardrails/git-identity.ts
|
|
80
|
-
/** Config scopes stored inside the repository, which every checkout and agent sharing it commits under. */
|
|
81
|
-
const SHARED_SCOPES = /* @__PURE__ */ new Set(["local", "worktree"]);
|
|
82
|
-
/** Whether `root` is a git checkout, a `.git` folder or a linked worktree's `.git` file. */
|
|
83
|
-
function isGitCheckout(root) {
|
|
84
|
-
return existsSync(join(root, ".git"));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Fails when the repository's own git config, its `.git/config` shared by every worktree or a worktree's
|
|
88
|
-
* `config.worktree`, sets `user.name` or `user.email`: whoever commits in any checkout of it then signs as that identity.
|
|
89
|
-
* Global, system and command-line settings pass. Returns what failed, naming each file and value, empty when it passed.
|
|
90
|
-
*/
|
|
91
|
-
async function checkGitIdentity(root, signal) {
|
|
92
|
-
const result = await runCommand("git", [
|
|
93
|
-
"config",
|
|
94
|
-
"--show-scope",
|
|
95
|
-
"--show-origin",
|
|
96
|
-
"--get-regexp",
|
|
97
|
-
String.raw`^user\.(name|email)$`
|
|
98
|
-
], {
|
|
99
|
-
cwd: root,
|
|
100
|
-
signal,
|
|
101
|
-
shell: false
|
|
102
|
-
});
|
|
103
|
-
if (result.status === 1) return "";
|
|
104
|
-
if (result.status !== 0) return result.output;
|
|
105
|
-
const shared = result.stdout.split("\n").filter((line) => SHARED_SCOPES.has(line.split(" ")[0] ?? ""));
|
|
106
|
-
if (!shared.length) return "";
|
|
107
|
-
return `The repository's git config sets a commit identity, so every checkout and agent sharing it commits as that identity:\n${shared.map((line) => ` ${line.split(" ").slice(1).join(" ")}\n`).join("")}Remove it with git config --local --unset-all user.name and git config --local --unset-all user.email (--worktree for a config.worktree), and set an identity with --global or per command with git -c.\n`;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
//#region src/guardrails/services.ts
|
|
111
|
-
/** The compose file the shared CI starts through its `services-compose-file` input, relative to the repository root. */
|
|
112
|
-
const COMPOSE_FILE = ".github/compose.yml";
|
|
113
|
-
function shortPort(text) {
|
|
114
|
-
const parts = text.replace(/\/\w+$/, "").split(":");
|
|
115
|
-
return parts.length < 2 ? void 0 : wholePort(parts.at(-2));
|
|
116
|
-
}
|
|
117
|
-
function wholePort(text) {
|
|
118
|
-
return text !== void 0 && /^\d+$/.test(text) ? Number(text) : void 0;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* The host ports the compose file publishes, or `undefined` when a service publishes none or one this cannot read
|
|
122
|
-
* (a range, an interpolation, a container-only port), since such a service cannot be probed.
|
|
123
|
-
*/
|
|
124
|
-
function publishedPorts(text) {
|
|
125
|
-
const services = parseDocument(text).get("services");
|
|
126
|
-
if (!isMap(services) || services.items.length === 0) return void 0;
|
|
127
|
-
const ports = [];
|
|
128
|
-
for (const { value } of services.items) {
|
|
129
|
-
const entries = isMap(value) ? value.get("ports") : void 0;
|
|
130
|
-
if (!isSeq(entries) || entries.items.length === 0) return void 0;
|
|
131
|
-
for (const entry of entries.items) {
|
|
132
|
-
const published = isMap(entry) ? entry.get("published") : void 0;
|
|
133
|
-
const port = isScalar(entry) ? shortPort(String(entry.value)) : wholePort(published === void 0 ? void 0 : String(published));
|
|
134
|
-
if (port === void 0) return void 0;
|
|
135
|
-
ports.push(port);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return ports;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* The environment compose runs in. A project named by `COMPOSE_PROJECT_NAME` or by the compose file's own `name:` is
|
|
142
|
-
* kept; otherwise the project is named after the repository root, since compose would name every repository's project
|
|
143
|
-
* `github` after the compose file's directory and a run could adopt or remove another checkout's containers.
|
|
144
|
-
*/
|
|
145
|
-
function composeEnv(root) {
|
|
146
|
-
if (process.env.COMPOSE_PROJECT_NAME) return process.env;
|
|
147
|
-
if (parseDocument(readFileSync(join(root, COMPOSE_FILE), "utf8")).has("name")) return process.env;
|
|
148
|
-
const slug = basename(root).toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[^a-z0-9]+/, "");
|
|
149
|
-
const digest = createHash("sha256").update(root).digest("hex").slice(0, 8);
|
|
150
|
-
return {
|
|
151
|
-
...process.env,
|
|
152
|
-
COMPOSE_PROJECT_NAME: `${slug || "repo"}-${digest}`
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
async function compose(root, args, signal) {
|
|
156
|
-
const result = await runCommand("docker", [
|
|
157
|
-
"compose",
|
|
158
|
-
"-f",
|
|
159
|
-
COMPOSE_FILE,
|
|
160
|
-
...args
|
|
161
|
-
], {
|
|
162
|
-
cwd: root,
|
|
163
|
-
env: composeEnv(root),
|
|
164
|
-
signal
|
|
165
|
-
});
|
|
166
|
-
if (result.status === 0) return {
|
|
167
|
-
failure: "",
|
|
168
|
-
stdout: result.stdout
|
|
169
|
-
};
|
|
170
|
-
const outcome = result.status === null ? "did not finish" : `exited with status ${result.status}`;
|
|
171
|
-
return {
|
|
172
|
-
failure: `${result.output}docker compose -f ${COMPOSE_FILE} ${args.join(" ")}: ${outcome}\n`,
|
|
173
|
-
stdout: result.stdout
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Decides whether the checks start the services of `.github/compose.yml`: not when the file is absent or every port
|
|
178
|
-
* it publishes already accepts connections, and fail at once when Docker Compose cannot run, because the
|
|
179
|
-
* tests that need those services would wait for them forever.
|
|
180
|
-
*/
|
|
181
|
-
async function planServices(root) {
|
|
182
|
-
if (!existsSync(join(root, COMPOSE_FILE))) return { kind: "none" };
|
|
183
|
-
const ports = publishedPorts(readFileSync(join(root, COMPOSE_FILE), "utf8"));
|
|
184
|
-
if (ports && (await Promise.all(ports.map(accepting))).every(Boolean)) return { kind: "none" };
|
|
185
|
-
const probe = await compose(root, ["version"]);
|
|
186
|
-
if (!probe.failure) return { kind: "start" };
|
|
187
|
-
return {
|
|
188
|
-
kind: "unavailable",
|
|
189
|
-
output: `Docker Compose is not available, so the services in ${COMPOSE_FILE} cannot start and the tests that need them would hang. Start Docker, start the services yourself, or pass --no-services.\n${probe.failure}`
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Runs `docker compose up -d --wait` on the compose file, stopping it when `signal` aborts. `failure` is empty on
|
|
194
|
-
* success; `owned` is true when the project had no container before, so the run may remove it afterwards without
|
|
195
|
-
* taking a stack the developer started.
|
|
196
|
-
*/
|
|
197
|
-
async function startServices(root, signal) {
|
|
198
|
-
const before = await compose(root, [
|
|
199
|
-
"ps",
|
|
200
|
-
"--all",
|
|
201
|
-
"--quiet"
|
|
202
|
-
], signal);
|
|
203
|
-
if (before.failure) return {
|
|
204
|
-
failure: before.failure,
|
|
205
|
-
owned: false
|
|
206
|
-
};
|
|
207
|
-
const owned = before.stdout.trim() === "";
|
|
208
|
-
return {
|
|
209
|
-
failure: (await compose(root, [
|
|
210
|
-
"up",
|
|
211
|
-
"-d",
|
|
212
|
-
"--wait"
|
|
213
|
-
], signal)).failure,
|
|
214
|
-
owned
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
/** Runs `docker compose down -v` on the compose file; returns the failure output, empty on success. */
|
|
218
|
-
async function stopServices(root) {
|
|
219
|
-
return (await compose(root, ["down", "-v"])).failure;
|
|
220
|
-
}
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region src/guardrails/verify-layers.ts
|
|
223
|
-
const SKILLS_FOLDER = ".agents/skills";
|
|
224
|
-
const LAYER_PREFIX = "verify-";
|
|
225
|
-
const TSCONFIG = "tsconfig.json";
|
|
226
|
-
/** Folders of a layer that are not the layer's own code: verify builds its playground with the playground's own tsconfig. */
|
|
227
|
-
const NOT_LAYER_CODE = /* @__PURE__ */ new Set(["node_modules", "dist"]);
|
|
228
|
-
const LAYER_PLAYGROUND = "playground";
|
|
229
|
-
const VERIFY_CONFIG = "verify.config.ts";
|
|
230
|
-
/**
|
|
231
|
-
* Options the generated config sets over the layer's: nothing is emitted, and each declaration or build-cache option the
|
|
232
|
-
* layer may inherit is unset with `null`, so no `.tsbuildinfo` is written, no option is left needing `declaration` or
|
|
233
|
-
* `composite`, and the declaration checks of files that are never emitted are not run.
|
|
234
|
-
*/
|
|
235
|
-
const NO_OUTPUT = {
|
|
236
|
-
noEmit: true,
|
|
237
|
-
declaration: null,
|
|
238
|
-
composite: null,
|
|
239
|
-
incremental: null,
|
|
240
|
-
tsBuildInfoFile: null,
|
|
241
|
-
declarationDir: null,
|
|
242
|
-
declarationMap: null,
|
|
243
|
-
emitDeclarationOnly: null,
|
|
244
|
-
isolatedDeclarations: null
|
|
245
|
-
};
|
|
246
|
-
/** The verify layers of a repository, relative to its root: each `.agents/skills/verify-*` folder that holds a `tsconfig.json` or a `verify.config.ts`. */
|
|
247
|
-
function verifyLayers(root) {
|
|
248
|
-
const skills = join(root, SKILLS_FOLDER);
|
|
249
|
-
if (!existsSync(skills)) return [];
|
|
250
|
-
return readdirSync(skills, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.startsWith(LAYER_PREFIX) && [TSCONFIG, VERIFY_CONFIG].some((file) => existsSync(join(skills, entry.name, file)))).map((entry) => `${SKILLS_FOLDER}/${entry.name}`).sort();
|
|
251
|
-
}
|
|
252
|
-
/** Whether a file the layer's tsconfig includes is the layer's own code, not its playground, a dependency or a build output. */
|
|
253
|
-
function isLayerCode(layer, file) {
|
|
254
|
-
const segments = relative(layer, file).split(sep);
|
|
255
|
-
return segments[0] !== LAYER_PLAYGROUND && !segments.some((segment) => NOT_LAYER_CODE.has(segment));
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* The repository's own `tsc` entry, run with Node so no shell parses its path. It is found through the `bin.tsc` field of
|
|
259
|
-
* `typescript/package.json`, a subpath every TypeScript version exports, because TypeScript 7 declares an `exports` map that
|
|
260
|
-
* leaves `typescript/bin/tsc` out.
|
|
261
|
-
*/
|
|
262
|
-
function compilerOf(root) {
|
|
263
|
-
try {
|
|
264
|
-
const manifestPath = createRequire(join(root, "package.json")).resolve("typescript/package.json");
|
|
265
|
-
const tsc = parseManifest(readFileSync(manifestPath, "utf8")).bin?.tsc;
|
|
266
|
-
return tsc === void 0 ? void 0 : join(dirname(manifestPath), tsc);
|
|
267
|
-
} catch {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
async function typecheckLayer(root, compiler, layer, signal) {
|
|
272
|
-
const configPath = join(root, layer, TSCONFIG);
|
|
273
|
-
if (!existsSync(configPath)) return `${layer}: has a verify.config.ts and no tsconfig.json. Add a tsconfig.json that includes its TypeScript files; antelopejs-sync writes one for the shared kinds.\n`;
|
|
274
|
-
const ts = (await import("typescript")).default;
|
|
275
|
-
const parsed = ts.getParsedCommandLineOfConfigFile(configPath, void 0, {
|
|
276
|
-
...ts.sys,
|
|
277
|
-
onUnRecoverableConfigFileDiagnostic: () => void 0
|
|
278
|
-
});
|
|
279
|
-
if (parsed === void 0) return `${layer}/${TSCONFIG}: could not read it.\n`;
|
|
280
|
-
const verifyConfig = join(root, layer, VERIFY_CONFIG);
|
|
281
|
-
if (existsSync(verifyConfig) && !parsed.fileNames.some((file) => resolve(file) === verifyConfig)) return `${layer}/${TSCONFIG}: does not include ${VERIFY_CONFIG}, so it is never type-checked. Add it to the tsconfig's "include" or "files".\n`;
|
|
282
|
-
const files = parsed.fileNames.filter((file) => isLayerCode(join(root, layer), resolve(file)));
|
|
283
|
-
if (files.length === 0) return "";
|
|
284
|
-
const folder = mkdtempSync(join(tmpdir(), "antelopejs-verify-types-"));
|
|
285
|
-
try {
|
|
286
|
-
const generated = join(folder, TSCONFIG);
|
|
287
|
-
writeFileSync(generated, JSON.stringify({
|
|
288
|
-
extends: configPath,
|
|
289
|
-
compilerOptions: {
|
|
290
|
-
...NO_OUTPUT,
|
|
291
|
-
typeRoots: ts.getEffectiveTypeRoots(parsed.options, ts.sys)
|
|
292
|
-
},
|
|
293
|
-
files,
|
|
294
|
-
include: []
|
|
295
|
-
}));
|
|
296
|
-
const result = await runCommand(process.execPath, [
|
|
297
|
-
compiler,
|
|
298
|
-
"-p",
|
|
299
|
-
generated,
|
|
300
|
-
"--pretty",
|
|
301
|
-
"false"
|
|
302
|
-
], {
|
|
303
|
-
cwd: root,
|
|
304
|
-
env: {
|
|
305
|
-
...process.env,
|
|
306
|
-
CI: "1"
|
|
307
|
-
},
|
|
308
|
-
signal,
|
|
309
|
-
shell: false
|
|
310
|
-
});
|
|
311
|
-
return result.status === 0 ? "" : result.output;
|
|
312
|
-
} finally {
|
|
313
|
-
rmSync(folder, {
|
|
314
|
-
recursive: true,
|
|
315
|
-
force: true
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Type-checks the own code of each verify layer with the repository's own TypeScript. The files are those the layer's
|
|
321
|
-
* `tsconfig.json` includes, minus its `playground` folder, which verify compiles with the playground's own config after
|
|
322
|
-
* installing it, and any `node_modules` or `dist` folder. A config generated in the system temp folder extends the layer's,
|
|
323
|
-
* lists those files, turns off emit and unsets the emit and build-cache options in `NO_OUTPUT`, so nothing is written in the
|
|
324
|
-
* repository and no package is fetched. A layer whose `tsconfig.json` does not include its `verify.config.ts` fails. Returns the compiler output of the layers that fail, empty when all pass.
|
|
325
|
-
*/
|
|
326
|
-
async function typecheckLayers(root, signal) {
|
|
327
|
-
const layers = verifyLayers(root);
|
|
328
|
-
if (layers.length === 0) return "";
|
|
329
|
-
const compiler = compilerOf(root);
|
|
330
|
-
if (compiler === void 0) return "TypeScript is not installed in the repository root: run the package manager's install first.\n";
|
|
331
|
-
return (await Promise.all(layers.map((layer) => typecheckLayer(root, compiler, layer, signal)))).join("");
|
|
332
|
-
}
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/guardrails/verify-lockfiles.ts
|
|
335
|
-
/** The folder a repository's playground lives in; verify installs a fixture project from it. */
|
|
336
|
-
const PLAYGROUND = "playground";
|
|
337
|
-
const PNPM_LOCK$1 = "pnpm-lock.yaml";
|
|
338
|
-
const NPM_LOCK = "package-lock.json";
|
|
339
|
-
const MANIFEST = "package.json";
|
|
340
|
-
const PNPM_WORKSPACE = "pnpm-workspace.yaml";
|
|
341
|
-
/** Lockfiles this check does not compare, which still mean a folder is locked. */
|
|
342
|
-
const OTHER_LOCKS = [
|
|
343
|
-
"npm-shrinkwrap.json",
|
|
344
|
-
"yarn.lock",
|
|
345
|
-
"bun.lock",
|
|
346
|
-
"bun.lockb"
|
|
347
|
-
];
|
|
348
|
-
/** The manifest fields both package managers record as a project's direct dependencies. */
|
|
349
|
-
const DIRECT_FIELDS = [
|
|
350
|
-
"dependencies",
|
|
351
|
-
"devDependencies",
|
|
352
|
-
"optionalDependencies"
|
|
353
|
-
];
|
|
354
|
-
/** A lockfile or manifest this check cannot read as a version it knows. */
|
|
355
|
-
var Unreadable = class extends Error {};
|
|
356
|
-
/** Parses a JSON or YAML file whose top level is a mapping; throws `Unreadable` otherwise. */
|
|
357
|
-
function readMapping(path) {
|
|
358
|
-
const document = parseDocument(readFileSync(path, "utf8"), {
|
|
359
|
-
schema: "failsafe",
|
|
360
|
-
uniqueKeys: false
|
|
361
|
-
});
|
|
362
|
-
const { contents } = document;
|
|
363
|
-
if (document.errors.length > 0 || !isMap(contents)) throw new Unreadable(path);
|
|
364
|
-
return contents;
|
|
365
|
-
}
|
|
366
|
-
/** The mapping under `key`; `undefined` when absent or not a mapping. */
|
|
367
|
-
function mapping(map, key) {
|
|
368
|
-
const value = map?.get(key, true);
|
|
369
|
-
return isMap(value) ? value : void 0;
|
|
370
|
-
}
|
|
371
|
-
/** The source text of the scalar under `key`; `undefined` when absent or not a scalar. */
|
|
372
|
-
function scalar(map, key) {
|
|
373
|
-
const value = map?.get(key, true);
|
|
374
|
-
return isScalar(value) ? String(value.value) : void 0;
|
|
375
|
-
}
|
|
376
|
-
/** The scalar keys of a mapping, in order; none when it is absent. */
|
|
377
|
-
function keys(map) {
|
|
378
|
-
return (map?.items ?? []).flatMap((pair) => isScalar(pair.key) ? [String(pair.key.value)] : []);
|
|
379
|
-
}
|
|
380
|
-
/** Reads a project's direct dependencies, with `specifierOf` reading the specifier of one name from its field. */
|
|
381
|
-
function directOf(node, specifierOf) {
|
|
382
|
-
const direct = /* @__PURE__ */ new Map();
|
|
383
|
-
for (const field of DIRECT_FIELDS) {
|
|
384
|
-
const entries = mapping(node, field);
|
|
385
|
-
for (const name of keys(entries)) {
|
|
386
|
-
const specifier = specifierOf(entries, name);
|
|
387
|
-
if (specifier === void 0) throw new Unreadable(name);
|
|
388
|
-
direct.set(name, /* @__PURE__ */ new Set([...direct.get(name) ?? [], specifier]));
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return direct;
|
|
392
|
-
}
|
|
393
|
-
/** A `package.json` or a `package-lock.json` root entry, where each name maps to its specifier. */
|
|
394
|
-
function declared(node) {
|
|
395
|
-
return directOf(node, scalar);
|
|
396
|
-
}
|
|
397
|
-
/** A `pnpm-lock.yaml` importer, where each name maps to its `specifier` and resolved `version`. */
|
|
398
|
-
function pnpmLocked(node) {
|
|
399
|
-
return directOf(node, (field, name) => scalar(mapping(field, name), "specifier"));
|
|
400
|
-
}
|
|
401
|
-
function listed(specifiers) {
|
|
402
|
-
return specifiers === void 0 ? "none" : [...specifiers].map((specifier) => `"${specifier}"`).join(" or ");
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* The names whose specifiers differ between a manifest and what its lockfile records, in either direction. A name counts as
|
|
406
|
-
* present whichever of the three fields records it, and matches when the two sides share a specifier. A name the lockfile
|
|
407
|
-
* records and the manifest declares only as a peer passes, since the package manager may or may not install peers. `skip`
|
|
408
|
-
* names the manifest entries the lockfile may leave out or record with another specifier.
|
|
409
|
-
*/
|
|
410
|
-
function differences(manifest, locked, skip) {
|
|
411
|
-
const wanted = declared(manifest);
|
|
412
|
-
const peers = new Set(keys(mapping(manifest, "peerDependencies")));
|
|
413
|
-
const line = (name) => `"${name}": package.json asks for ${listed(wanted.get(name))}, the lockfile has ${listed(locked.get(name))}.`;
|
|
414
|
-
const stale = [...wanted].filter(([name, specifiers]) => ![...locked.get(name) ?? []].some((specifier) => specifiers.has(specifier)) && !skip(name, specifiers)).map(([name]) => line(name));
|
|
415
|
-
const extra = [...locked.keys()].filter((name) => !wanted.has(name) && !peers.has(name)).map(line);
|
|
416
|
-
return [...stale, ...extra].sort();
|
|
417
|
-
}
|
|
418
|
-
/** Every package name an override selector such as `foo`, `@scope/foo@^1` or `bar@1>foo@2` mentions, its target among them. */
|
|
419
|
-
function overrideNames(selector) {
|
|
420
|
-
return selector.split(">").flatMap((segment) => /^(?:@[^/@]+\/)?[^@]+/u.exec(segment) ?? []);
|
|
421
|
-
}
|
|
422
|
-
function pnpmDifferences(path) {
|
|
423
|
-
const lockfile = readMapping(join(path, PNPM_LOCK$1));
|
|
424
|
-
if (Number(scalar(lockfile, "lockfileVersion") ?? "0") < 6) throw new Unreadable(path);
|
|
425
|
-
const overridden = new Set(keys(mapping(lockfile, "overrides")).flatMap(overrideNames));
|
|
426
|
-
const linksLeftOut = scalar(mapping(lockfile, "settings"), "excludeLinksFromLockfile") === "true";
|
|
427
|
-
const skip = (name, specifiers) => overridden.has(name) || linksLeftOut && [...specifiers].every((specifier) => specifier.startsWith("link:"));
|
|
428
|
-
const importers = mapping(lockfile, "importers");
|
|
429
|
-
return (importers ? keys(importers) : ["."]).flatMap((importer) => {
|
|
430
|
-
const manifest = join(path, importer, MANIFEST);
|
|
431
|
-
if (!existsSync(manifest)) return [];
|
|
432
|
-
const node = importers ? mapping(importers, importer) : lockfile;
|
|
433
|
-
return differences(readMapping(manifest), pnpmLocked(node), skip).map((line) => `importer "${importer}" ${line}`);
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
function npmDifferences(path) {
|
|
437
|
-
const lockfile = readMapping(join(path, NPM_LOCK));
|
|
438
|
-
const rootEntry = mapping(mapping(lockfile, "packages"), "");
|
|
439
|
-
if (Number(scalar(lockfile, "lockfileVersion") ?? "0") < 2 || rootEntry === void 0) throw new Unreadable(path);
|
|
440
|
-
const manifest = join(path, MANIFEST);
|
|
441
|
-
if (!existsSync(manifest)) return [];
|
|
442
|
-
return differences(readMapping(manifest), declared(rootEntry), () => false);
|
|
443
|
-
}
|
|
444
|
-
function lockfileIn(path) {
|
|
445
|
-
if (existsSync(join(path, PNPM_LOCK$1))) return PNPM_LOCK$1;
|
|
446
|
-
if (existsSync(join(path, NPM_LOCK))) return NPM_LOCK;
|
|
447
|
-
return OTHER_LOCKS.some((name) => existsSync(join(path, name))) ? "other" : void 0;
|
|
448
|
-
}
|
|
449
|
-
/** Each folder at or under `folder`, `node_modules` and `dist` aside, that holds a lockfile. */
|
|
450
|
-
function lockedFolders(root, folder) {
|
|
451
|
-
const path = join(root, folder);
|
|
452
|
-
if (!existsSync(path)) return [];
|
|
453
|
-
const lockfile = lockfileIn(path);
|
|
454
|
-
return [...lockfile === void 0 ? [] : [{
|
|
455
|
-
folder,
|
|
456
|
-
lockfile
|
|
457
|
-
}], ...readdirSync(path, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist").flatMap((entry) => lockedFolders(root, `${folder}/${entry.name}`))];
|
|
458
|
-
}
|
|
459
|
-
/** Whether a `package.json` declares a direct dependency; `false` when it is missing or cannot be read, so this check cannot tell. */
|
|
460
|
-
function hasDependencies(path) {
|
|
461
|
-
try {
|
|
462
|
-
if (!existsSync(path)) return false;
|
|
463
|
-
const manifest = readMapping(path);
|
|
464
|
-
return DIRECT_FIELDS.some((field) => keys(mapping(manifest, field)).length > 0);
|
|
465
|
-
} catch (error) {
|
|
466
|
-
if (error instanceof Unreadable) return false;
|
|
467
|
-
throw error;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* The folders this check reads, when a layer exists: each folder under a layer, `node_modules` and `dist` aside, and the
|
|
472
|
-
* root `playground`, that holds a lockfile; and each layer's `playground` and the root `playground`, the folders verify
|
|
473
|
-
* installs from, when its `package.json` has dependencies and it holds no lockfile.
|
|
474
|
-
*/
|
|
475
|
-
function verifyInstallFolders(root) {
|
|
476
|
-
const layers = verifyLayers(root);
|
|
477
|
-
if (layers.length === 0) return [];
|
|
478
|
-
const playgrounds = [...layers.map((layer) => `${layer}/${PLAYGROUND}`), PLAYGROUND];
|
|
479
|
-
const rootPlayground = lockfileIn(join(root, PLAYGROUND));
|
|
480
|
-
return [
|
|
481
|
-
...layers.flatMap((layer) => lockedFolders(root, layer)),
|
|
482
|
-
...rootPlayground === void 0 ? [] : [{
|
|
483
|
-
folder: PLAYGROUND,
|
|
484
|
-
lockfile: rootPlayground
|
|
485
|
-
}],
|
|
486
|
-
...playgrounds.filter((folder) => lockfileIn(join(root, folder)) === void 0 && hasDependencies(join(root, folder, MANIFEST))).map((folder) => ({
|
|
487
|
-
folder,
|
|
488
|
-
lockfile: void 0
|
|
489
|
-
}))
|
|
490
|
-
];
|
|
491
|
-
}
|
|
492
|
-
/** The folders above `folder`, nearest first, up to the repository root. */
|
|
493
|
-
function ancestors(folder) {
|
|
494
|
-
const parent = posix.dirname(folder);
|
|
495
|
-
return parent === folder ? [] : [parent, ...ancestors(parent)];
|
|
496
|
-
}
|
|
497
|
-
/** Whether a manifest declares workspaces, or cannot be read and so might. */
|
|
498
|
-
function declaresWorkspaces(path) {
|
|
499
|
-
try {
|
|
500
|
-
return existsSync(path) && readMapping(path).has("workspaces");
|
|
501
|
-
} catch (error) {
|
|
502
|
-
if (error instanceof Unreadable) return true;
|
|
503
|
-
throw error;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* Whether a folder above `folder` holds a workspace that may list it, a `pnpm-workspace.yaml` or a `package.json` with
|
|
508
|
-
* `workspaces`: its membership then follows patterns this check does not evaluate, and that workspace's lockfile may hold it.
|
|
509
|
-
*/
|
|
510
|
-
function inWorkspace(root, folder) {
|
|
511
|
-
return ancestors(folder).some((above) => existsSync(join(root, above, PNPM_WORKSPACE)) || declaresWorkspaces(join(root, above, MANIFEST)));
|
|
512
|
-
}
|
|
513
|
-
function fixCommand(root, folder, lockfile) {
|
|
514
|
-
if (lockfile === NPM_LOCK) return `npm install --package-lock-only --prefix ${folder}`;
|
|
515
|
-
return existsSync(join(root, folder, PNPM_WORKSPACE)) ? `pnpm install --dir ${folder} --lockfile-only` : `pnpm install --dir ${folder} --ignore-workspace --lockfile-only`;
|
|
516
|
-
}
|
|
517
|
-
function unlocked(root, folder) {
|
|
518
|
-
if (inWorkspace(root, folder)) return "";
|
|
519
|
-
const manager = ancestors(folder).some((above) => existsSync(join(root, above, NPM_LOCK))) ? NPM_LOCK : PNPM_LOCK$1;
|
|
520
|
-
return `${folder}/${MANIFEST} has dependencies and no lockfile: run \`${fixCommand(root, folder, manager)}\`.\n`;
|
|
521
|
-
}
|
|
522
|
-
function checkFolder(root, { folder, lockfile }) {
|
|
523
|
-
if (lockfile === "other") return "";
|
|
524
|
-
try {
|
|
525
|
-
if (lockfile === void 0) return unlocked(root, folder);
|
|
526
|
-
const path = join(root, folder);
|
|
527
|
-
const found = lockfile === PNPM_LOCK$1 ? pnpmDifferences(path) : npmDifferences(path);
|
|
528
|
-
return found.length === 0 ? "" : `${folder}/${lockfile} does not match ${folder}/${MANIFEST}: run \`${fixCommand(root, folder, lockfile)}\`.\n${found.map((line) => ` ${line}\n`).join("")}`;
|
|
529
|
-
} catch (error) {
|
|
530
|
-
if (error instanceof Unreadable) return `${folder}/${lockfile ?? MANIFEST}: could not read it, or a ${MANIFEST} it locks, as a version this check knows.\n`;
|
|
531
|
-
throw error;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Compares, in code, the direct dependencies each lockfile records with the `package.json` files it locks, and fails on a
|
|
536
|
-
* difference in either direction. A `pnpm-lock.yaml` is compared importer by importer, for each importer it lists that has a
|
|
537
|
-
* `package.json` on disk; a `package-lock.json` by its root entry. Only `dependencies`, `devDependencies` and
|
|
538
|
-
* `optionalDependencies` are compared, by name and specifier: a name counts as present whichever of the three fields records
|
|
539
|
-
* it, and specifiers such as `catalog:` or `workspace:^` compare as written. A name the lockfile records that `package.json`
|
|
540
|
-
* declares only in `peerDependencies` passes. A `package.json` name that an override selector in the `pnpm-lock.yaml`
|
|
541
|
-
* mentions, or a `link:` one the lockfile leaves out under `excludeLinksFromLockfile`, is not compared. A missing lockfile fails only in a layer's
|
|
542
|
-
* `playground` or the root `playground` whose `package.json` has dependencies, unless a folder above it holds a workspace.
|
|
543
|
-
*
|
|
544
|
-
* It spawns no package manager, writes no file and fetches nothing. It does not check workspace membership, overrides,
|
|
545
|
-
* settings, catalogs, `.npmrc` or user configuration, resolved versions, integrity hashes, transitive entries, npm workspace
|
|
546
|
-
* members, or `yarn.lock` and `bun.lock`: verify's own frozen install still rejects a lockfile stale there. Returns what
|
|
547
|
-
* failed, empty when every lockfile matches.
|
|
548
|
-
*/
|
|
549
|
-
function checkLockfiles(root) {
|
|
550
|
-
return verifyInstallFolders(root).map((install) => checkFolder(root, install)).join("");
|
|
551
|
-
}
|
|
552
|
-
//#endregion
|
|
553
|
-
//#region src/guardrails/singleton-packages.ts
|
|
554
|
-
const PNPM_LOCK = "pnpm-lock.yaml";
|
|
555
|
-
/** Packages one process must load once: every AntelopeJS interface package shares one runtime with its peers. */
|
|
556
|
-
const SINGLETON = /^@antelopejs\/interface-/u;
|
|
557
|
-
/** The fields of a lockfile package entry that point at the copy each dependency resolves to. */
|
|
558
|
-
const PACKAGE_FIELDS = ["dependencies", "optionalDependencies"];
|
|
559
|
-
/** How to move every importer onto one copy while pnpm keeps every other locked version, which `pnpm dedupe` does not. */
|
|
560
|
-
const REPAIR = " Set the direct specifier that locks the older copy to the newer version, run `pnpm install --lockfile-only`, then restore the specifier.\n";
|
|
561
|
-
/** A `name@version` key or a resolved version without its peer suffix, `(peer@1)`, which names no other copy. */
|
|
562
|
-
function withoutPeers(reference) {
|
|
563
|
-
const open = reference.indexOf("(");
|
|
564
|
-
return open === -1 ? reference : reference.slice(0, open);
|
|
565
|
-
}
|
|
566
|
-
/** The name and version of a `packages` key: `@scope/name@1.0.0` in version 9, `/@scope/name@1.0.0` in version 6. */
|
|
567
|
-
function packageKey(key) {
|
|
568
|
-
const match = /^\/?((?:@[^/@]+\/)?[^@]+)@(.+)$/u.exec(withoutPeers(key));
|
|
569
|
-
return match?.[1] && match[2] ? {
|
|
570
|
-
name: match[1],
|
|
571
|
-
version: match[2]
|
|
572
|
-
} : void 0;
|
|
573
|
-
}
|
|
574
|
-
/** Records `by` as a puller of the copy a dependency resolves to: `version`, or the `name@version` an `npm:` alias resolves to. */
|
|
575
|
-
function pull(copies, name, version, by) {
|
|
576
|
-
if (version === void 0) return;
|
|
577
|
-
const alias = packageKey(version);
|
|
578
|
-
const target = alias && copies.has(alias.name) ? alias : {
|
|
579
|
-
name,
|
|
580
|
-
version: withoutPeers(version)
|
|
581
|
-
};
|
|
582
|
-
copies.get(target.name)?.get(target.version)?.add(by);
|
|
583
|
-
}
|
|
584
|
-
function addPullers(copies, node, fields, by) {
|
|
585
|
-
for (const field of fields) {
|
|
586
|
-
const entries = mapping(node, field);
|
|
587
|
-
for (const name of keys(entries)) pull(copies, name, scalar(entries, name) ?? scalar(mapping(entries, name), "version"), by);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
/** Each document of a lockfile: pnpm 11 writes its config dependencies, installed apart from the project, as a document before the project's. */
|
|
591
|
-
function lockfileDocuments(path) {
|
|
592
|
-
return parseAllDocuments(readFileSync(path, "utf8"), {
|
|
593
|
-
schema: "failsafe",
|
|
594
|
-
uniqueKeys: false
|
|
595
|
-
}).map((document) => {
|
|
596
|
-
const { contents } = document;
|
|
597
|
-
if (document.errors.length > 0 || !isMap(contents) || !(Number.parseFloat(scalar(contents, "lockfileVersion") ?? "") >= 6)) throw new Unreadable(path);
|
|
598
|
-
return contents;
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
function documentCopies(lockfile) {
|
|
602
|
-
const copies = /* @__PURE__ */ new Map();
|
|
603
|
-
const packages = mapping(lockfile, "packages");
|
|
604
|
-
for (const parsed of keys(packages).map(packageKey)) if (parsed && SINGLETON.test(parsed.name)) copies.set(parsed.name, (copies.get(parsed.name) ?? /* @__PURE__ */ new Map()).set(parsed.version, /* @__PURE__ */ new Set()));
|
|
605
|
-
const importers = mapping(lockfile, "importers");
|
|
606
|
-
for (const importer of importers ? keys(importers) : ["."]) addPullers(copies, importers ? mapping(importers, importer) : lockfile, DIRECT_FIELDS, `importer "${importer}"`);
|
|
607
|
-
const resolved = mapping(lockfile, "snapshots") ?? packages;
|
|
608
|
-
for (const key of keys(resolved)) addPullers(copies, mapping(resolved, key), PACKAGE_FIELDS, withoutPeers(key.replace(/^\//u, "")));
|
|
609
|
-
return copies;
|
|
610
|
-
}
|
|
611
|
-
function report(file, copies) {
|
|
612
|
-
return [...copies].filter(([, versions]) => versions.size > 1).map(([name, versions]) => `${file} resolves "${name}" at ${versions.size} versions, and an interface package must load once:\n${[...versions].map(([version, by]) => ` ${version}, pulled by ${[...by].join(", ") || "nothing"}\n`).join("")}${REPAIR}`).join("");
|
|
613
|
-
}
|
|
614
|
-
/** The `pnpm-lock.yaml` files on disk in the repository, tracked or not yet added, outside what `.gitignore` leaves out. */
|
|
615
|
-
function pnpmLockfiles(root) {
|
|
616
|
-
return gitFiles(root).filter((file) => (file === PNPM_LOCK || file.endsWith(`/${PNPM_LOCK}`)) && existsSync(join(root, file)));
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Fails when a `pnpm-lock.yaml` of the repository resolves an AntelopeJS interface package, any `@antelopejs/interface-*`,
|
|
620
|
-
* at more than one version: each copy carries its own runtime, so two copies in one process break the contract between
|
|
621
|
-
* modules, or throw on a runtime protocol mismatch. Names, for each version, the importers and packages that pull it.
|
|
622
|
-
* Reads the lockfiles only: it spawns no package manager, writes no file and fetches nothing. Returns what failed, empty
|
|
623
|
-
* when every interface package resolves once.
|
|
624
|
-
*/
|
|
625
|
-
function checkSingletonPackages(root) {
|
|
626
|
-
return pnpmLockfiles(root).map((file) => {
|
|
627
|
-
try {
|
|
628
|
-
return lockfileDocuments(join(root, file)).map((document) => report(file, documentCopies(document))).join("");
|
|
629
|
-
} catch (error) {
|
|
630
|
-
if (error instanceof Unreadable) return `${file}: could not read it as a lockfile version this check knows.\n`;
|
|
631
|
-
throw error;
|
|
632
|
-
}
|
|
633
|
-
}).join("");
|
|
634
|
-
}
|
|
635
|
-
//#endregion
|
|
636
|
-
//#region src/guardrails/checks.ts
|
|
637
|
-
const CHECK_STEPS = [
|
|
638
|
-
"typecheck",
|
|
639
|
-
"lint",
|
|
640
|
-
"format:check",
|
|
641
|
-
"knip",
|
|
642
|
-
"test",
|
|
643
|
-
"size",
|
|
644
|
-
"ratchet",
|
|
645
|
-
"suppressions",
|
|
646
|
-
"sync:check",
|
|
647
|
-
"verify:types",
|
|
648
|
-
"verify:lockfiles",
|
|
649
|
-
"lockfile:singletons",
|
|
650
|
-
"git:identity"
|
|
651
|
-
];
|
|
652
|
-
/** Steps `antelopejs-checks` runs itself, no package.json script behind them: each returns what failed, empty when it passed. */
|
|
653
|
-
const OWN_STEPS = /* @__PURE__ */ new Map([
|
|
654
|
-
["verify:types", typecheckLayers],
|
|
655
|
-
["verify:lockfiles", (root) => Promise.resolve(checkLockfiles(root))],
|
|
656
|
-
["lockfile:singletons", (root) => Promise.resolve(checkSingletonPackages(root))],
|
|
657
|
-
["git:identity", checkGitIdentity]
|
|
658
|
-
]);
|
|
659
|
-
function hasWork(root, step) {
|
|
660
|
-
if (step === "ratchet") return existsSync(join(root, CEILINGS_FILE));
|
|
661
|
-
if (step === "verify:types") return verifyLayers(root).length > 0;
|
|
662
|
-
if (step === "verify:lockfiles") return verifyInstallFolders(root).length > 0;
|
|
663
|
-
if (step === "lockfile:singletons") return pnpmLockfiles(root).length > 0;
|
|
664
|
-
if (step === "git:identity") return isGitCheckout(root);
|
|
665
|
-
return true;
|
|
666
|
-
}
|
|
667
|
-
/** The step that runs after the others, never beside them: tests often hold time limits that CPU contention would break. */
|
|
668
|
-
const RUNS_ALONE = "test";
|
|
669
|
-
/** The environment variable naming, comma-separated, the steps `runChecks` leaves to another CI job. */
|
|
670
|
-
const CHECKS_SKIP_ENV = "ANTELOPEJS_CHECKS_SKIP";
|
|
671
|
-
function skippedNames(setting) {
|
|
672
|
-
return setting.split(",").map((name) => name.trim()).filter(Boolean);
|
|
673
|
-
}
|
|
674
|
-
async function runSteps(root, manifest, steps, signal) {
|
|
675
|
-
const manager = packageManager(manifest);
|
|
676
|
-
const runStep = async (step) => {
|
|
677
|
-
if (signal?.aborted) return [];
|
|
678
|
-
const own = OWN_STEPS.get(step);
|
|
679
|
-
if (own) {
|
|
680
|
-
const failure = await own(root, signal);
|
|
681
|
-
return failure ? [`[${step}]\n${failure}`] : [];
|
|
682
|
-
}
|
|
683
|
-
if (!manifest.scripts?.[step]) return [`[${step}] Missing package.json script "${step}". Run antelopejs-sync.\n`];
|
|
684
|
-
const result = await runCommand(manager, ["run", step], {
|
|
685
|
-
cwd: root,
|
|
686
|
-
env: {
|
|
687
|
-
...process.env,
|
|
688
|
-
CI: "1"
|
|
689
|
-
},
|
|
690
|
-
signal
|
|
691
|
-
});
|
|
692
|
-
return result.status === 0 ? [] : [`[${step}]\n${result.output}`];
|
|
693
|
-
};
|
|
694
|
-
const failures = /* @__PURE__ */ new Map();
|
|
695
|
-
await Promise.all(steps.filter((step) => step !== RUNS_ALONE).map(async (step) => failures.set(step, await runStep(step))));
|
|
696
|
-
if (steps.includes(RUNS_ALONE)) failures.set(RUNS_ALONE, await runStep(RUNS_ALONE));
|
|
697
|
-
return steps.flatMap((step) => failures.get(step) ?? []);
|
|
698
|
-
}
|
|
699
|
-
/** The optional package script run once before the steps, to build what several steps read, such as a workspace package's `dist`. */
|
|
700
|
-
const PREPARE = "checks:prepare";
|
|
701
|
-
/** Runs `checks:prepare` when the manifest has it: the run's result when it failed or `signal` aborted it, else undefined. */
|
|
702
|
-
async function prepare(root, manifest, signal) {
|
|
703
|
-
if (!manifest.scripts?.[PREPARE]) return void 0;
|
|
704
|
-
const result = await runCommand(packageManager(manifest), ["run", PREPARE], {
|
|
705
|
-
cwd: root,
|
|
706
|
-
env: {
|
|
707
|
-
...process.env,
|
|
708
|
-
CI: "1"
|
|
709
|
-
},
|
|
710
|
-
signal
|
|
711
|
-
});
|
|
712
|
-
const failure = result.status === 0 ? "" : `[${PREPARE}]\n${result.output}`;
|
|
713
|
-
if (signal?.aborted) return {
|
|
714
|
-
failed: failure ? 1 : 0,
|
|
715
|
-
interrupted: true,
|
|
716
|
-
output: `${failure}Checks interrupted by ${String(signal.reason)}.\n`
|
|
717
|
-
};
|
|
718
|
-
if (failure) return {
|
|
719
|
-
failed: 1,
|
|
720
|
-
interrupted: false,
|
|
721
|
-
output: `${failure}Checks: 0 passed, 1 failed.\n`
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
function summary(failures, passed, skipped) {
|
|
725
|
-
return `${failures.join("\n")}Checks: ${passed} passed, ${failures.length} failed${skipped ? `, ${skipped} skipped` : ""}.\n`;
|
|
726
|
-
}
|
|
727
|
-
/**
|
|
728
|
-
* Runs the `checks:prepare` package script first when it exists and a step will run, and stops there if it fails.
|
|
729
|
-
* Then runs every check step except `test` at the same time, then `test` alone, and reports only what failed, each step's
|
|
730
|
-
* output buffered and listed in step order whichever step finishes first. `skipSetting` is the comma-separated value of
|
|
731
|
-
* `ANTELOPEJS_CHECKS_SKIP`: the steps it names are not run and are counted as skipped, never as passed, and a name that
|
|
732
|
-
* is not a step fails the run before any step starts so a typo cannot skip nothing. Unless `services` is false, the
|
|
733
|
-
* services of `.github/compose.yml` are started before the steps when `test` runs, and removed after them if the run created them, also when a step fails or
|
|
734
|
-
* `signal` aborts the run; an aborted run stops every running step and reports `interrupted`.
|
|
735
|
-
*/
|
|
736
|
-
async function runChecks(root, options = {}) {
|
|
737
|
-
const { skipSetting = "", services = true, signal } = options;
|
|
738
|
-
const requested = skippedNames(skipSetting);
|
|
739
|
-
const unknown = requested.filter((name) => !CHECK_STEPS.includes(name));
|
|
740
|
-
if (unknown.length) return {
|
|
741
|
-
failed: 1,
|
|
742
|
-
interrupted: false,
|
|
743
|
-
output: `[${CHECKS_SKIP_ENV}]\nUnknown step ${unknown.map((name) => `"${name}"`).join(", ")}. Valid steps: ${CHECK_STEPS.join(", ")}.\nChecks: 0 passed, 1 failed.\n`
|
|
744
|
-
};
|
|
745
|
-
const present = CHECK_STEPS.filter((step) => hasWork(root, step));
|
|
746
|
-
const steps = present.filter((step) => !requested.includes(step));
|
|
747
|
-
const skipped = present.length - steps.length;
|
|
748
|
-
const manifest = parseManifest(readFileSync(join(root, "package.json"), "utf8"));
|
|
749
|
-
const plan = services && steps.includes("test") ? await planServices(root) : { kind: "none" };
|
|
750
|
-
if (plan.kind === "unavailable") return {
|
|
751
|
-
failed: 1,
|
|
752
|
-
interrupted: false,
|
|
753
|
-
output: `[services]\n${plan.output}Checks: 0 passed, 1 failed.\n`
|
|
754
|
-
};
|
|
755
|
-
const unprepared = steps.length ? await prepare(root, manifest, signal) : void 0;
|
|
756
|
-
if (unprepared) return unprepared;
|
|
757
|
-
const started = plan.kind === "start" ? await startServices(root, signal) : {
|
|
758
|
-
failure: "",
|
|
759
|
-
owned: false
|
|
760
|
-
};
|
|
761
|
-
let failures = [];
|
|
762
|
-
let stopped = "";
|
|
763
|
-
try {
|
|
764
|
-
failures = started.failure ? [`[services]\n${started.failure}`] : await runSteps(root, manifest, steps, signal);
|
|
765
|
-
} finally {
|
|
766
|
-
if (started.owned) stopped = await stopServices(root);
|
|
767
|
-
}
|
|
768
|
-
const passed = started.failure ? 0 : steps.length - failures.length;
|
|
769
|
-
if (stopped) failures.push(`[services]\n${stopped}`);
|
|
770
|
-
const interrupted = signal?.aborted ?? false;
|
|
771
|
-
return {
|
|
772
|
-
failed: failures.length,
|
|
773
|
-
interrupted,
|
|
774
|
-
output: interrupted ? `${failures.join("\n")}Checks interrupted by ${String(signal?.reason)}.\n` : summary(failures, passed, skipped)
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
//#endregion
|
|
778
6
|
//#region src/bin/checks.ts
|
|
779
7
|
const SIGNAL_EXIT = /* @__PURE__ */ new Map([
|
|
780
8
|
["SIGHUP", 129],
|