@antelopejs/tooling-configs 0.5.3 → 0.5.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 +1 -1
- package/dist/bin/api-diff.mjs +3 -3
- package/dist/bin/body-check.mjs +1 -1
- package/dist/bin/checks.mjs +1 -1
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/ratchet.mjs +1 -1
- package/dist/bin/sync.mjs +197 -51
- package/dist/{checks-BFGuy1KI.mjs → checks-CyMCnYb4.mjs} +884 -884
- package/dist/oxc/lint.mjs +1 -1
- package/dist/{package-DiaBP7bI.mjs → package-CORwvwTw.mjs} +14 -7
- package/dist/{proof-stamp-BPIdT5ik.mjs → proof-stamp-C56iYgHa.mjs} +1 -1
- package/dist/{ratchet-BZvlFCWL.mjs → ratchet-Al0XZtOz.mjs} +1 -1
- package/dist/{templates-C6cfOd2H.mjs → templates-DaatyItc.mjs} +1 -1
- package/dist/{typescript-DJzdex32.mjs → typescript-Cw1JH8mk.mjs} +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as CEILINGS_FILE } from "./ceilings-B7KayYIG.mjs";
|
|
2
|
-
import { o as packageManager, s as parseManifest } from "./package-
|
|
2
|
+
import { o as packageManager, s as parseManifest } from "./package-CORwvwTw.mjs";
|
|
3
3
|
import { a as gitFiles } from "./files-DJ0TeaTU.mjs";
|
|
4
4
|
import { t as accepting } from "./ports-DGP6bPJy.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
@@ -11,981 +11,981 @@ import ts from "typescript";
|
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
12
|
import { tmpdir } from "node:os";
|
|
13
13
|
import { minimatch } from "minimatch";
|
|
14
|
-
//#region src/guardrails/
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Runs `command` in its own process group and collects stdout and stderr together. When `signal` aborts, the group
|
|
27
|
-
* gets SIGTERM, then SIGKILL after a grace period, so a step's own children stop with it. On Windows the command runs
|
|
28
|
-
* through a shell, so `npm` and `pnpm` resolve to their `.cmd` shims, unless `shell` is `false`: pass that for an
|
|
29
|
-
* executable path and arguments that a shell must not split, such as paths with spaces.
|
|
30
|
-
*/
|
|
31
|
-
function runCommand(command, args, options) {
|
|
32
|
-
const { cwd, env = process.env, signal, shell = process.platform === "win32" } = options;
|
|
33
|
-
return new Promise((resolve) => {
|
|
34
|
-
const child = spawn(command, args, {
|
|
35
|
-
cwd,
|
|
36
|
-
env,
|
|
37
|
-
shell,
|
|
38
|
-
detached: process.platform !== "win32",
|
|
39
|
-
stdio: [
|
|
40
|
-
"ignore",
|
|
41
|
-
"pipe",
|
|
42
|
-
"pipe"
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
const chunks = [];
|
|
46
|
-
const stdout = [];
|
|
47
|
-
child.stdout.on("data", (chunk) => {
|
|
48
|
-
chunks.push(chunk);
|
|
49
|
-
stdout.push(chunk);
|
|
50
|
-
});
|
|
51
|
-
child.stderr.on("data", (chunk) => chunks.push(chunk));
|
|
52
|
-
const interrupt = () => {
|
|
53
|
-
stopGroup(child, "SIGTERM");
|
|
54
|
-
setTimeout(() => stopGroup(child, "SIGKILL"), KILL_GRACE_MS).unref();
|
|
55
|
-
};
|
|
56
|
-
if (signal?.aborted) interrupt();
|
|
57
|
-
else signal?.addEventListener("abort", interrupt, { once: true });
|
|
58
|
-
child.once("error", (error) => {
|
|
59
|
-
signal?.removeEventListener("abort", interrupt);
|
|
60
|
-
resolve({
|
|
61
|
-
status: null,
|
|
62
|
-
stdout: "",
|
|
63
|
-
output: `${error.message}\n`
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
child.once("close", (code, killed) => {
|
|
67
|
-
signal?.removeEventListener("abort", interrupt);
|
|
68
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
69
|
-
resolve({
|
|
70
|
-
status: code,
|
|
71
|
-
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
72
|
-
output: `${text}${killed ? `Terminated by ${killed}\n` : ""}`
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
14
|
+
//#region src/guardrails/markdown-table.ts
|
|
15
|
+
/** The lines of a Markdown table whose first row is the header, columns padded as oxfmt leaves them. */
|
|
16
|
+
function tableLines(table) {
|
|
17
|
+
const widths = table[0].map((_, column) => Math.max(3, ...table.map((row) => row[column].length)));
|
|
18
|
+
const line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column])).join(" | ")} |`;
|
|
19
|
+
return [
|
|
20
|
+
line(table[0]),
|
|
21
|
+
line(widths.map((width) => "-".repeat(width))),
|
|
22
|
+
...table.slice(1).map(line)
|
|
23
|
+
];
|
|
76
24
|
}
|
|
77
25
|
//#endregion
|
|
78
|
-
//#region src/guardrails/
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
26
|
+
//#region src/guardrails/docs-modules.ts
|
|
27
|
+
const DMS_MODULES_START = "<!-- antelopejs-dms-modules:start -->";
|
|
28
|
+
const DMS_MODULES_END = "<!-- antelopejs-dms-modules:end -->";
|
|
29
|
+
const ORGANIZATION = "https://github.com/AntelopeJS";
|
|
30
|
+
/** The AntelopeJS DMS modules in display order. Every README holding the markers lists exactly these. */
|
|
31
|
+
const DMS_MODULES = [
|
|
32
|
+
{
|
|
33
|
+
repo: "dms-builder",
|
|
34
|
+
row: "Edit pages, tables and data sources by clicking, as TypeScript that compiles"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
repo: "dms-ai",
|
|
38
|
+
row: "An assistant chat in the dashboard, on your own Claude Code or Codex"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
repo: "dms-database",
|
|
42
|
+
row: "Schemas, relation diagrams, a data browser and a query console"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
repo: "dms-api",
|
|
46
|
+
row: "API health, request logs, per-route statistics and a request tester"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
repo: "dms-automation",
|
|
50
|
+
row: "Node-graph automations on schedules, webhooks and DMS events, with a trace for every run"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
repo: "dms-mailing",
|
|
54
|
+
row: "E-mail templates in a block editor, versions, a send log and delivery metrics"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
repo: "dms-lang",
|
|
58
|
+
row: "Translation coverage, a translation matrix and a translation queue"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
repo: "dms-media",
|
|
62
|
+
row: "A media library with folders, per-folder permissions, image sizes and light editing"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
repo: "dms-saas",
|
|
66
|
+
row: "Self-service sign-up, plans that gate features, and Stripe billing"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
repo: "dms-marketing",
|
|
70
|
+
row: "Traffic, conversion funnels with A/B splits and click heatmaps, without cookies"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
repo: "dms-frontend",
|
|
74
|
+
row: "The `ajs dms` CLI, the Vue renderer and the SDK every frontend module builds on"
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
/** The generated block, formatted as oxfmt leaves it. */
|
|
78
|
+
function modulesBlock() {
|
|
79
|
+
return [
|
|
80
|
+
DMS_MODULES_START,
|
|
81
|
+
"",
|
|
82
|
+
...tableLines([["Module", "What it adds"], ...DMS_MODULES.map(({ repo, row }) => [`[\`${repo}\`](${ORGANIZATION}/${repo})`, row])]),
|
|
83
|
+
"",
|
|
84
|
+
DMS_MODULES_END,
|
|
85
|
+
""
|
|
86
|
+
].join("\n");
|
|
84
87
|
}
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
"--show-origin",
|
|
95
|
-
"--get-regexp",
|
|
96
|
-
String.raw`^user\.(name|email)$`
|
|
97
|
-
], {
|
|
98
|
-
cwd: root,
|
|
99
|
-
signal,
|
|
100
|
-
shell: false
|
|
101
|
-
});
|
|
102
|
-
if (result.status === 1) return "";
|
|
103
|
-
if (result.status !== 0) return result.output;
|
|
104
|
-
const shared = result.stdout.split("\n").filter((line) => SHARED_SCOPES.has(line.split(" ")[0] ?? ""));
|
|
105
|
-
if (!shared.length) return "";
|
|
106
|
-
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`;
|
|
88
|
+
/** The README with the block between its markers rewritten. A README without markers comes back as it is. */
|
|
89
|
+
function placeModulesBlock(current) {
|
|
90
|
+
const start = current.indexOf(DMS_MODULES_START);
|
|
91
|
+
const end = current.indexOf(DMS_MODULES_END);
|
|
92
|
+
const starts = current.split(DMS_MODULES_START).length - 1;
|
|
93
|
+
const ends = current.split(DMS_MODULES_END).length - 1;
|
|
94
|
+
if (starts === 0 && ends === 0) return current;
|
|
95
|
+
if (starts !== 1 || ends !== 1 || end < start) throw new Error("invalid antelopejs-dms-modules markers: a README holds exactly one start marker followed by one end marker. Repair or delete them, then rerun antelopejs-sync.");
|
|
96
|
+
return `${current.slice(0, start)}${modulesBlock()}${current.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
107
97
|
}
|
|
108
98
|
//#endregion
|
|
109
|
-
//#region src/guardrails/
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
//#region src/guardrails/docs-compat.ts
|
|
100
|
+
const DOCS_COMPAT_START = "<!-- antelopejs-docs-compat:start -->";
|
|
101
|
+
const DOCS_COMPAT_END = "<!-- antelopejs-docs-compat:end -->";
|
|
102
|
+
const DOCS_NODE_START = "<!-- antelopejs-docs-node:start -->";
|
|
103
|
+
const DOCS_NODE_END = "<!-- antelopejs-docs-node:end -->";
|
|
104
|
+
const LOCKFILE = "pnpm-lock.yaml";
|
|
105
|
+
const REQUIREMENTS_HEADING = /^##\s+Requirements\s*$/i;
|
|
106
|
+
const SCOPE = "@antelopejs/";
|
|
107
|
+
const UNRESOLVED = "—";
|
|
108
|
+
const WORKSPACE = "workspace";
|
|
109
|
+
const LEGACY_MARKER = /^<!--\s*docs-compat:\s*\.\/package\.json#\w+\s*-->\s*$/;
|
|
110
|
+
const COMPATIBILITY_HEADING = /^##\s+Compatibility\s*$/i;
|
|
111
|
+
const RESOLVED_SECTIONS = [
|
|
112
|
+
"dependencies",
|
|
113
|
+
"optionalDependencies",
|
|
114
|
+
"devDependencies"
|
|
115
|
+
];
|
|
116
|
+
/** The generated block, rows sorted by package name, formatted as oxfmt leaves it. */
|
|
117
|
+
function compatBlock(rows) {
|
|
118
|
+
const sorted = [...rows].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
119
|
+
return [
|
|
120
|
+
DOCS_COMPAT_START,
|
|
121
|
+
"",
|
|
122
|
+
...tableLines([[
|
|
123
|
+
"Package",
|
|
124
|
+
"Supported",
|
|
125
|
+
"Tested with"
|
|
126
|
+
], ...sorted.map(({ name, supported, tested }) => [
|
|
127
|
+
`\`${name}\``,
|
|
128
|
+
`\`${supported.replaceAll("|", "\\|")}\``,
|
|
129
|
+
tested === void 0 ? UNRESOLVED : `\`${tested}\``
|
|
130
|
+
])]),
|
|
131
|
+
"",
|
|
132
|
+
DOCS_COMPAT_END,
|
|
133
|
+
""
|
|
134
|
+
].join("\n");
|
|
115
135
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
136
|
+
function legacySpanEnd(lines, marker) {
|
|
137
|
+
let index = marker + 1;
|
|
138
|
+
while (index < lines.length && !lines[index].trim()) index++;
|
|
139
|
+
while (index < lines.length && lines[index].trimStart().startsWith("|")) index++;
|
|
140
|
+
while (index < lines.length && !lines[index].trim()) index++;
|
|
141
|
+
return index;
|
|
118
142
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
for (const { value } of services.items) {
|
|
128
|
-
const entries = isMap(value) ? value.get("ports") : void 0;
|
|
129
|
-
if (!isSeq(entries) || entries.items.length === 0) return void 0;
|
|
130
|
-
for (const entry of entries.items) {
|
|
131
|
-
const published = isMap(entry) ? entry.get("published") : void 0;
|
|
132
|
-
const port = isScalar(entry) ? shortPort(String(entry.value)) : wholePort(published === void 0 ? void 0 : String(published));
|
|
133
|
-
if (port === void 0) return void 0;
|
|
134
|
-
ports.push(port);
|
|
143
|
+
function replaceLegacyTables(lines, block) {
|
|
144
|
+
const placed = [];
|
|
145
|
+
let replaced = false;
|
|
146
|
+
for (let index = 0; index < lines.length;) {
|
|
147
|
+
if (!LEGACY_MARKER.test(lines[index])) {
|
|
148
|
+
placed.push(lines[index]);
|
|
149
|
+
index++;
|
|
150
|
+
continue;
|
|
135
151
|
}
|
|
152
|
+
if (!replaced) placed.push(...block.split("\n"));
|
|
153
|
+
replaced = true;
|
|
154
|
+
index = legacySpanEnd(lines, index);
|
|
136
155
|
}
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* The environment compose runs in. A project named by `COMPOSE_PROJECT_NAME` or by the compose file's own `name:` is
|
|
141
|
-
* kept; otherwise the project is named after the repository root, since compose would name every repository's project
|
|
142
|
-
* `github` after the compose file's directory and a run could adopt or remove another checkout's containers.
|
|
143
|
-
*/
|
|
144
|
-
function composeEnv(root) {
|
|
145
|
-
if (process.env.COMPOSE_PROJECT_NAME) return process.env;
|
|
146
|
-
if (parseDocument(readFileSync(join(root, COMPOSE_FILE), "utf8")).has("name")) return process.env;
|
|
147
|
-
const slug = basename(root).toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[^a-z0-9]+/, "");
|
|
148
|
-
const digest = createHash("sha256").update(root).digest("hex").slice(0, 8);
|
|
149
|
-
return {
|
|
150
|
-
...process.env,
|
|
151
|
-
COMPOSE_PROJECT_NAME: `${slug || "repo"}-${digest}`
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
async function compose(root, args, signal) {
|
|
155
|
-
const result = await runCommand("docker", [
|
|
156
|
-
"compose",
|
|
157
|
-
"-f",
|
|
158
|
-
COMPOSE_FILE,
|
|
159
|
-
...args
|
|
160
|
-
], {
|
|
161
|
-
cwd: root,
|
|
162
|
-
env: composeEnv(root),
|
|
163
|
-
signal
|
|
164
|
-
});
|
|
165
|
-
if (result.status === 0) return {
|
|
166
|
-
failure: "",
|
|
167
|
-
stdout: result.stdout
|
|
168
|
-
};
|
|
169
|
-
const outcome = result.status === null ? "did not finish" : `exited with status ${result.status}`;
|
|
170
|
-
return {
|
|
171
|
-
failure: `${result.output}docker compose -f ${COMPOSE_FILE} ${args.join(" ")}: ${outcome}\n`,
|
|
172
|
-
stdout: result.stdout
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Decides whether the checks start the services of `.github/compose.yml`: not when the file is absent or every port
|
|
177
|
-
* it publishes already accepts connections, and fail at once when Docker Compose cannot run, because the
|
|
178
|
-
* tests that need those services would wait for them forever.
|
|
179
|
-
*/
|
|
180
|
-
async function planServices(root) {
|
|
181
|
-
if (!existsSync(join(root, COMPOSE_FILE))) return { kind: "none" };
|
|
182
|
-
const ports = publishedPorts(readFileSync(join(root, COMPOSE_FILE), "utf8"));
|
|
183
|
-
if (ports && (await Promise.all(ports.map(accepting))).every(Boolean)) return { kind: "none" };
|
|
184
|
-
const probe = await compose(root, ["version"]);
|
|
185
|
-
if (!probe.failure) return { kind: "start" };
|
|
186
|
-
return {
|
|
187
|
-
kind: "unavailable",
|
|
188
|
-
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}`
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Runs `docker compose up -d --wait` on the compose file, stopping it when `signal` aborts. `failure` is empty on
|
|
193
|
-
* success; `owned` is true when the project had no container before, so the run may remove it afterwards without
|
|
194
|
-
* taking a stack the developer started.
|
|
195
|
-
*/
|
|
196
|
-
async function startServices(root, signal) {
|
|
197
|
-
const before = await compose(root, [
|
|
198
|
-
"ps",
|
|
199
|
-
"--all",
|
|
200
|
-
"--quiet"
|
|
201
|
-
], signal);
|
|
202
|
-
if (before.failure) return {
|
|
203
|
-
failure: before.failure,
|
|
204
|
-
owned: false
|
|
205
|
-
};
|
|
206
|
-
const owned = before.stdout.trim() === "";
|
|
207
|
-
return {
|
|
208
|
-
failure: (await compose(root, [
|
|
209
|
-
"up",
|
|
210
|
-
"-d",
|
|
211
|
-
"--wait"
|
|
212
|
-
], signal)).failure,
|
|
213
|
-
owned
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
/** Runs `docker compose down -v` on the compose file; returns the failure output, empty on success. */
|
|
217
|
-
async function stopServices(root) {
|
|
218
|
-
return (await compose(root, ["down", "-v"])).failure;
|
|
219
|
-
}
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/guardrails/verify-layers.ts
|
|
222
|
-
const SKILLS_FOLDER = ".agents/skills";
|
|
223
|
-
const LAYER_PREFIX = "verify-";
|
|
224
|
-
const TSCONFIG = "tsconfig.json";
|
|
225
|
-
/** Folders of a layer that are not the layer's own code: verify builds its playground with the playground's own tsconfig. */
|
|
226
|
-
const NOT_LAYER_CODE = /* @__PURE__ */ new Set(["node_modules", "dist"]);
|
|
227
|
-
const LAYER_PLAYGROUND = "playground";
|
|
228
|
-
const VERIFY_CONFIG = "verify.config.ts";
|
|
229
|
-
/**
|
|
230
|
-
* Options the generated config sets over the layer's: nothing is emitted, and each declaration or build-cache option the
|
|
231
|
-
* layer may inherit is unset with `null`, so no `.tsbuildinfo` is written, no option is left needing `declaration` or
|
|
232
|
-
* `composite`, and the declaration checks of files that are never emitted are not run.
|
|
233
|
-
*/
|
|
234
|
-
const NO_OUTPUT = {
|
|
235
|
-
noEmit: true,
|
|
236
|
-
declaration: null,
|
|
237
|
-
composite: null,
|
|
238
|
-
incremental: null,
|
|
239
|
-
tsBuildInfoFile: null,
|
|
240
|
-
declarationDir: null,
|
|
241
|
-
declarationMap: null,
|
|
242
|
-
emitDeclarationOnly: null,
|
|
243
|
-
isolatedDeclarations: null
|
|
244
|
-
};
|
|
245
|
-
/** 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`. */
|
|
246
|
-
function verifyLayers(root) {
|
|
247
|
-
const skills = join(root, SKILLS_FOLDER);
|
|
248
|
-
if (!existsSync(skills)) return [];
|
|
249
|
-
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();
|
|
156
|
+
return replaced ? placed : void 0;
|
|
250
157
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const segments = relative(layer, file).split(sep);
|
|
254
|
-
return segments[0] !== LAYER_PLAYGROUND && !segments.some((segment) => NOT_LAYER_CODE.has(segment));
|
|
158
|
+
function finalNewline(text) {
|
|
159
|
+
return text.endsWith("\n") ? text : `${text}\n`;
|
|
255
160
|
}
|
|
256
|
-
/**
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
161
|
+
/** The README with the block in place: replacing the markers, a legacy `docs-compat` table, or under `## Compatibility`. */
|
|
162
|
+
function placeCompatBlock(current, block) {
|
|
163
|
+
const text = current ?? "";
|
|
164
|
+
const start = text.indexOf(DOCS_COMPAT_START);
|
|
165
|
+
const end = text.indexOf(DOCS_COMPAT_END);
|
|
166
|
+
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-compat markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
167
|
+
if (start !== -1) return `${text.slice(0, start)}${block}${text.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
168
|
+
const lines = text.split("\n");
|
|
169
|
+
const legacy = replaceLegacyTables(lines, block);
|
|
170
|
+
if (legacy) return finalNewline(legacy.join("\n"));
|
|
171
|
+
const heading = lines.findIndex((line) => COMPATIBILITY_HEADING.test(line));
|
|
172
|
+
if (heading !== -1) {
|
|
173
|
+
let rest = heading + 1;
|
|
174
|
+
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
175
|
+
return finalNewline([
|
|
176
|
+
...lines.slice(0, heading + 1),
|
|
177
|
+
"",
|
|
178
|
+
...block.split("\n"),
|
|
179
|
+
...lines.slice(rest)
|
|
180
|
+
].join("\n"));
|
|
268
181
|
}
|
|
182
|
+
const before = text.trimEnd();
|
|
183
|
+
return `${before}${before ? "\n\n" : ""}## Compatibility\n\n${block}`;
|
|
269
184
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
},
|
|
292
|
-
files,
|
|
293
|
-
include: []
|
|
294
|
-
}));
|
|
295
|
-
const result = await runCommand(process.execPath, [
|
|
296
|
-
compiler,
|
|
297
|
-
"-p",
|
|
298
|
-
generated,
|
|
299
|
-
"--pretty",
|
|
300
|
-
"false"
|
|
301
|
-
], {
|
|
302
|
-
cwd: root,
|
|
303
|
-
env: {
|
|
304
|
-
...process.env,
|
|
305
|
-
CI: "1"
|
|
306
|
-
},
|
|
307
|
-
signal,
|
|
308
|
-
shell: false
|
|
309
|
-
});
|
|
310
|
-
return result.status === 0 ? "" : result.output;
|
|
311
|
-
} finally {
|
|
312
|
-
rmSync(folder, {
|
|
313
|
-
recursive: true,
|
|
314
|
-
force: true
|
|
315
|
-
});
|
|
185
|
+
/** The generated Node prerequisite block for an `engines.node` range, formatted as oxfmt leaves it. */
|
|
186
|
+
function nodeBlock(range) {
|
|
187
|
+
return `${DOCS_NODE_START}\n\nThis package requires Node.js \`${range}\`.\n${DOCS_NODE_END}\n`;
|
|
188
|
+
}
|
|
189
|
+
/** The README with the Node block in place: between its markers, under `## Requirements`, or in a new `## Requirements` section at the end. */
|
|
190
|
+
function placeNodeBlock(current, block) {
|
|
191
|
+
const start = current.indexOf(DOCS_NODE_START);
|
|
192
|
+
const end = current.indexOf(DOCS_NODE_END);
|
|
193
|
+
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-node markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
194
|
+
if (start !== -1) return `${current.slice(0, start)}${block}${current.slice(end + 33).replace(/^\r?\n/, "")}`;
|
|
195
|
+
const lines = current.split("\n");
|
|
196
|
+
const heading = lines.findIndex((line) => REQUIREMENTS_HEADING.test(line));
|
|
197
|
+
if (heading !== -1) {
|
|
198
|
+
let rest = heading + 1;
|
|
199
|
+
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
200
|
+
return finalNewline([
|
|
201
|
+
...lines.slice(0, heading + 1),
|
|
202
|
+
"",
|
|
203
|
+
...block.trimEnd().split("\n"),
|
|
204
|
+
...rest < lines.length ? ["", ...lines.slice(rest)] : []
|
|
205
|
+
].join("\n"));
|
|
316
206
|
}
|
|
207
|
+
return `${current.trimEnd()}\n\n## Requirements\n\n${block}`;
|
|
317
208
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
* `tsconfig.json` includes, minus its `playground` folder, which verify compiles with the playground's own config after
|
|
321
|
-
* installing it, and any `node_modules` or `dist` folder. A config generated in the system temp folder extends the layer's,
|
|
322
|
-
* lists those files, turns off emit and unsets the emit and build-cache options in `NO_OUTPUT`, so nothing is written in the
|
|
323
|
-
* 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.
|
|
324
|
-
*/
|
|
325
|
-
async function typecheckLayers(root, signal) {
|
|
326
|
-
const layers = verifyLayers(root);
|
|
327
|
-
if (layers.length === 0) return "";
|
|
328
|
-
const compiler = compilerOf(root);
|
|
329
|
-
if (compiler === void 0) return "TypeScript is not installed in the repository root: run the package manager's install first.\n";
|
|
330
|
-
return (await Promise.all(layers.map((layer) => typecheckLayer(root, compiler, layer, signal)))).join("");
|
|
209
|
+
function relative$1(directory, name) {
|
|
210
|
+
return directory ? `${directory}/${name}` : name;
|
|
331
211
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
/** The folder a repository's playground lives in; verify installs a fixture project from it. */
|
|
335
|
-
const PLAYGROUND = "playground";
|
|
336
|
-
const PNPM_LOCK$1 = "pnpm-lock.yaml";
|
|
337
|
-
const NPM_LOCK = "package-lock.json";
|
|
338
|
-
const MANIFEST = "package.json";
|
|
339
|
-
const PNPM_WORKSPACE = "pnpm-workspace.yaml";
|
|
340
|
-
/** Lockfiles this check does not compare, which still mean a folder is locked. */
|
|
341
|
-
const OTHER_LOCKS = [
|
|
342
|
-
"npm-shrinkwrap.json",
|
|
343
|
-
"yarn.lock",
|
|
344
|
-
"bun.lock",
|
|
345
|
-
"bun.lockb"
|
|
346
|
-
];
|
|
347
|
-
/** The manifest fields both package managers record as a project's direct dependencies. */
|
|
348
|
-
const DIRECT_FIELDS = [
|
|
349
|
-
"dependencies",
|
|
350
|
-
"devDependencies",
|
|
351
|
-
"optionalDependencies"
|
|
352
|
-
];
|
|
353
|
-
/** A lockfile or manifest this check cannot read as a version it knows. */
|
|
354
|
-
var Unreadable = class extends Error {};
|
|
355
|
-
/** Parses a JSON or YAML file whose top level is a mapping; throws `Unreadable` otherwise. */
|
|
356
|
-
function readMapping(path) {
|
|
357
|
-
const document = parseDocument(readFileSync(path, "utf8"), {
|
|
358
|
-
schema: "failsafe",
|
|
359
|
-
uniqueKeys: false
|
|
360
|
-
});
|
|
361
|
-
const { contents } = document;
|
|
362
|
-
if (document.errors.length > 0 || !isMap(contents)) throw new Unreadable(path);
|
|
363
|
-
return contents;
|
|
212
|
+
function isDirectory(root, path) {
|
|
213
|
+
return statSync(join(root, path), { throwIfNoEntry: false })?.isDirectory() === true;
|
|
364
214
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const value = map?.get(key, true);
|
|
368
|
-
return isMap(value) ? value : void 0;
|
|
215
|
+
function subdirectories(root, directory) {
|
|
216
|
+
return readdirSync(join(root, directory), { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "node_modules" && !entry.name.startsWith(".")).map((entry) => relative$1(directory, entry.name));
|
|
369
217
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const value = map?.get(key, true);
|
|
373
|
-
return isScalar(value) ? String(value.value) : void 0;
|
|
218
|
+
function descendants(root, directory) {
|
|
219
|
+
return subdirectories(root, directory).flatMap((child) => [child, ...descendants(root, child)]);
|
|
374
220
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return
|
|
221
|
+
function globExpression(pattern) {
|
|
222
|
+
const source = pattern.split("/").map((segment) => segment === "**" ? "(?:.*)" : segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("*", "[^/]*").replaceAll("?", "[^/]")).join("/").replaceAll("(?:.*)/", "(?:.*/)?");
|
|
223
|
+
return new RegExp(`^${source}$`);
|
|
378
224
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
direct.set(name, /* @__PURE__ */ new Set([...direct.get(name) ?? [], specifier]));
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return direct;
|
|
225
|
+
function expand(root, pattern) {
|
|
226
|
+
let directories = [""];
|
|
227
|
+
for (const segment of pattern.split("/")) if (segment === "**") directories = directories.flatMap((directory) => [directory, ...descendants(root, directory)]);
|
|
228
|
+
else if (/[*?]/.test(segment)) {
|
|
229
|
+
const expression = globExpression(segment);
|
|
230
|
+
directories = directories.flatMap((directory) => subdirectories(root, directory).filter((child) => expression.test(child.slice(child.lastIndexOf("/") + 1))));
|
|
231
|
+
} else directories = directories.map((directory) => relative$1(directory, segment)).filter((directory) => isDirectory(root, directory));
|
|
232
|
+
return directories;
|
|
391
233
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
return directOf(node, scalar);
|
|
234
|
+
function normalizePattern(pattern) {
|
|
235
|
+
return pattern.replace(/^(?:\.\/)+/, "").replace(/\/+$/, "").replace(/^\.$/, "");
|
|
395
236
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return
|
|
237
|
+
function scalarItems(document, path) {
|
|
238
|
+
const node = document.getIn(path, true);
|
|
239
|
+
return isSeq(node) ? node.items.flatMap((item) => isScalar(item) ? [String(item.value)] : []) : [];
|
|
399
240
|
}
|
|
400
|
-
|
|
401
|
-
|
|
241
|
+
/** pnpm-workspace.yaml `packages`, else package.json `workspaces` as an array or as `{ packages }`; JSON parses as YAML. */
|
|
242
|
+
function workspacePatterns(root) {
|
|
243
|
+
const pnpm = join(root, "pnpm-workspace.yaml");
|
|
244
|
+
if (existsSync(pnpm)) return scalarItems(parseDocument(readFileSync(pnpm, "utf8")), ["packages"]);
|
|
245
|
+
const manifest = parseDocument(readFileSync(join(root, "package.json"), "utf8"));
|
|
246
|
+
return scalarItems(manifest, isMap(manifest.get("workspaces", true)) ? ["workspaces", "packages"] : ["workspaces"]);
|
|
402
247
|
}
|
|
403
|
-
/**
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const stale = [...wanted].filter(([name, specifiers]) => ![...locked.get(name) ?? []].some((specifier) => specifiers.has(specifier)) && !skip(name, specifiers)).map(([name]) => line(name));
|
|
414
|
-
const extra = [...locked.keys()].filter((name) => !wanted.has(name) && !peers.has(name)).map(line);
|
|
415
|
-
return [...stale, ...extra].sort();
|
|
248
|
+
/** The workspace package directories, relative to `root` and sorted, that `pnpm-workspace.yaml` or package.json `workspaces` list. */
|
|
249
|
+
function workspaceDirectories(root) {
|
|
250
|
+
const patterns = workspacePatterns(root);
|
|
251
|
+
const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => globExpression(normalizePattern(pattern.slice(1))));
|
|
252
|
+
const found = /* @__PURE__ */ new Set();
|
|
253
|
+
for (const pattern of patterns.filter((item) => !item.startsWith("!"))) {
|
|
254
|
+
const normalized = normalizePattern(pattern);
|
|
255
|
+
for (const directory of normalized ? expand(root, normalized) : [""]) if (directory && !excluded.some((expression) => expression.test(directory)) && existsSync(join(root, directory, "package.json"))) found.add(directory);
|
|
256
|
+
}
|
|
257
|
+
return [...found].sort();
|
|
416
258
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
259
|
+
function declaredRanges(manifest) {
|
|
260
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
261
|
+
for (const field of [
|
|
262
|
+
manifest.optionalDependencies,
|
|
263
|
+
manifest.dependencies,
|
|
264
|
+
manifest.peerDependencies
|
|
265
|
+
]) for (const [name, range] of Object.entries(field ?? {})) if (name.startsWith(SCOPE)) ranges.set(name, range);
|
|
266
|
+
return ranges;
|
|
420
267
|
}
|
|
421
|
-
function
|
|
422
|
-
|
|
423
|
-
if (Number(scalar(lockfile, "lockfileVersion") ?? "0") < 6) throw new Unreadable(path);
|
|
424
|
-
const overridden = new Set(keys(mapping(lockfile, "overrides")).flatMap(overrideNames));
|
|
425
|
-
const linksLeftOut = scalar(mapping(lockfile, "settings"), "excludeLinksFromLockfile") === "true";
|
|
426
|
-
const skip = (name, specifiers) => overridden.has(name) || linksLeftOut && [...specifiers].every((specifier) => specifier.startsWith("link:"));
|
|
427
|
-
const importers = mapping(lockfile, "importers");
|
|
428
|
-
return (importers ? keys(importers) : ["."]).flatMap((importer) => {
|
|
429
|
-
const manifest = join(path, importer, MANIFEST);
|
|
430
|
-
if (!existsSync(manifest)) return [];
|
|
431
|
-
const node = importers ? mapping(importers, importer) : lockfile;
|
|
432
|
-
return differences(readMapping(manifest), pnpmLocked(node), skip).map((line) => `importer "${importer}" ${line}`);
|
|
433
|
-
});
|
|
268
|
+
function readManifest(root, directory) {
|
|
269
|
+
return parseManifest(readFileSync(join(root, directory, "package.json"), "utf8"));
|
|
434
270
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
271
|
+
/** The version the lockfile resolves for a dependency; a `link:` resolves to `workspace`, so a release that bumps the linked package leaves this README unchanged. */
|
|
272
|
+
function resolvedVersion({ document, importer }, name) {
|
|
273
|
+
for (const section of RESOLVED_SECTIONS) {
|
|
274
|
+
const entry = document.getIn([
|
|
275
|
+
"importers",
|
|
276
|
+
importer,
|
|
277
|
+
section,
|
|
278
|
+
name
|
|
279
|
+
], true);
|
|
280
|
+
const version = isMap(entry) ? entry.get("version", true) : entry;
|
|
281
|
+
if (!isScalar(version)) continue;
|
|
282
|
+
const resolved = String(version.value).split("(")[0];
|
|
283
|
+
return resolved.startsWith("link:") ? WORKSPACE : resolved;
|
|
284
|
+
}
|
|
442
285
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
286
|
+
const UNSHARED_NPMRC = /^\s*shared-workspace-lockfile\s*=\s*false\s*(?:[#;].*)?$/m;
|
|
287
|
+
/** Whether the workspace keeps one root lockfile, or `shared-workspace-lockfile=false` gives each package its own. */
|
|
288
|
+
function sharesLockfile(root) {
|
|
289
|
+
const npmrc = join(root, ".npmrc");
|
|
290
|
+
if (existsSync(npmrc) && UNSHARED_NPMRC.test(readFileSync(npmrc, "utf8"))) return false;
|
|
291
|
+
const workspace = join(root, "pnpm-workspace.yaml");
|
|
292
|
+
return !(existsSync(workspace) && parseDocument(readFileSync(workspace, "utf8")).get("sharedWorkspaceLockfile") === false);
|
|
447
293
|
}
|
|
448
|
-
/**
|
|
449
|
-
function
|
|
450
|
-
|
|
451
|
-
if (!existsSync(path)) return [];
|
|
452
|
-
const lockfile = lockfileIn(path);
|
|
453
|
-
return [...lockfile === void 0 ? [] : [{
|
|
454
|
-
folder,
|
|
455
|
-
lockfile
|
|
456
|
-
}], ...readdirSync(path, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist").flatMap((entry) => lockedFolders(root, `${folder}/${entry.name}`))];
|
|
294
|
+
/** The lockfile path of a package, relative to the root. A shared lockfile is the root's, indexed by the package directory. */
|
|
295
|
+
function lockPath(shared, directory) {
|
|
296
|
+
return shared ? LOCKFILE : relative$1(directory, LOCKFILE);
|
|
457
297
|
}
|
|
458
|
-
|
|
459
|
-
|
|
298
|
+
function readLock(root, shared, directory, documents) {
|
|
299
|
+
const path = join(root, lockPath(shared, directory));
|
|
300
|
+
if (!documents.has(path) && existsSync(path)) documents.set(path, parseDocument(readFileSync(path, "utf8")));
|
|
301
|
+
const document = documents.get(path);
|
|
302
|
+
return document && {
|
|
303
|
+
document,
|
|
304
|
+
importer: shared ? directory || "." : "."
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/** Adds one package's `docs-files` lines and, when it needs one, its README with the generated blocks. */
|
|
308
|
+
function planPackage(root, plan, lock, standard, { directory, ranges, published, node }) {
|
|
309
|
+
const readme = relative$1(directory, "README.md");
|
|
310
|
+
const docs = relative$1(directory, "docs");
|
|
311
|
+
if (!published) return;
|
|
312
|
+
if (ranges.size > 0 || existsSync(join(root, readme))) plan.docsFiles.push(readme);
|
|
313
|
+
if (isDirectory(root, docs)) plan.docsFiles.push(docs);
|
|
314
|
+
const current = existsSync(join(root, readme)) ? readFileSync(join(root, readme), "utf8") : void 0;
|
|
315
|
+
const nodeRange = standard && current !== void 0 ? node : void 0;
|
|
316
|
+
if (ranges.size === 0 && current === void 0) return;
|
|
317
|
+
const rows = [...ranges].map(([name, supported]) => ({
|
|
318
|
+
name,
|
|
319
|
+
supported,
|
|
320
|
+
tested: lock && resolvedVersion(lock, name)
|
|
321
|
+
}));
|
|
322
|
+
try {
|
|
323
|
+
const withRequirements = nodeRange !== void 0 && current !== void 0 ? placeNodeBlock(current, nodeBlock(nodeRange)) : current;
|
|
324
|
+
plan.readmes.push({
|
|
325
|
+
path: readme,
|
|
326
|
+
current,
|
|
327
|
+
content: placeModulesBlock(rows.length > 0 ? placeCompatBlock(withRequirements, compatBlock(rows)) : withRequirements ?? "")
|
|
328
|
+
});
|
|
329
|
+
} catch (error) {
|
|
330
|
+
plan.errors.push(`${readme}: ${error instanceof Error ? error.message : String(error)}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Plans the docs-compat block of the root and of every workspace package that is not private and declares an
|
|
335
|
+
* `@antelopejs/*` peer, runtime or optional dependency, and the `docs-files` lines covering the root and every workspace
|
|
336
|
+
* package that is not private.
|
|
337
|
+
* Tested with comes from pnpm-lock.yaml, each package's own when `shared-workspace-lockfile=false`, and is `workspace` for a `link:` dependency; other package managers get a dash.
|
|
338
|
+
*/
|
|
339
|
+
function planDocs(root, manager) {
|
|
340
|
+
const rootManifest = readManifest(root, "");
|
|
341
|
+
const packages = ["", ...workspaceDirectories(root)].map((directory) => {
|
|
342
|
+
const manifest = directory ? readManifest(root, directory) : rootManifest;
|
|
343
|
+
return {
|
|
344
|
+
directory,
|
|
345
|
+
published: !directory || !manifest.private,
|
|
346
|
+
node: manifest.engines?.node,
|
|
347
|
+
ranges: manifest.private ? /* @__PURE__ */ new Map() : declaredRanges(manifest)
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
const qualifying = packages.filter(({ ranges }) => ranges.size > 0);
|
|
351
|
+
const plan = {
|
|
352
|
+
readmes: [],
|
|
353
|
+
docsFiles: [],
|
|
354
|
+
errors: [],
|
|
355
|
+
exists: (path) => existsSync(join(root, path))
|
|
356
|
+
};
|
|
357
|
+
const shared = sharesLockfile(root);
|
|
358
|
+
const documents = /* @__PURE__ */ new Map();
|
|
359
|
+
const locks = new Map(qualifying.map(({ directory }) => [directory, manager === "pnpm" ? readLock(root, shared, directory, documents) : void 0]));
|
|
360
|
+
const missing = manager === "pnpm" ? qualifying.filter(({ directory }) => !locks.get(directory)) : [];
|
|
361
|
+
if (missing.length) {
|
|
362
|
+
for (const path of new Set(missing.map(({ directory }) => lockPath(shared, directory)))) plan.errors.push(`${path} is missing, and the docs-compat block reads Tested with from it: run pnpm install, then rerun antelopejs-sync.`);
|
|
363
|
+
return plan;
|
|
364
|
+
}
|
|
365
|
+
const standard = rootManifest.antelopeJs?.docs?.standard === true;
|
|
366
|
+
for (const item of packages) planPackage(root, plan, locks.get(item.directory), standard, item);
|
|
367
|
+
return plan;
|
|
368
|
+
}
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/guardrails/run-command.ts
|
|
371
|
+
const KILL_GRACE_MS = 5e3;
|
|
372
|
+
function stopGroup(child, signal) {
|
|
373
|
+
if (child.pid === void 0 || child.exitCode !== null) return;
|
|
460
374
|
try {
|
|
461
|
-
if (
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (error instanceof Unreadable) return false;
|
|
466
|
-
throw error;
|
|
375
|
+
if (process.platform === "win32") child.kill(signal);
|
|
376
|
+
else process.kill(-child.pid, signal);
|
|
377
|
+
} catch {
|
|
378
|
+
child.kill(signal);
|
|
467
379
|
}
|
|
468
380
|
}
|
|
469
381
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
382
|
+
* Runs `command` in its own process group and collects stdout and stderr together. When `signal` aborts, the group
|
|
383
|
+
* gets SIGTERM, then SIGKILL after a grace period, so a step's own children stop with it. On Windows the command runs
|
|
384
|
+
* through a shell, so `npm` and `pnpm` resolve to their `.cmd` shims, unless `shell` is `false`: pass that for an
|
|
385
|
+
* executable path and arguments that a shell must not split, such as paths with spaces.
|
|
473
386
|
*/
|
|
474
|
-
function
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
387
|
+
function runCommand(command, args, options) {
|
|
388
|
+
const { cwd, env = process.env, signal, shell = process.platform === "win32" } = options;
|
|
389
|
+
return new Promise((resolve) => {
|
|
390
|
+
const child = spawn(command, args, {
|
|
391
|
+
cwd,
|
|
392
|
+
env,
|
|
393
|
+
shell,
|
|
394
|
+
detached: process.platform !== "win32",
|
|
395
|
+
stdio: [
|
|
396
|
+
"ignore",
|
|
397
|
+
"pipe",
|
|
398
|
+
"pipe"
|
|
399
|
+
]
|
|
400
|
+
});
|
|
401
|
+
const chunks = [];
|
|
402
|
+
const stdout = [];
|
|
403
|
+
child.stdout.on("data", (chunk) => {
|
|
404
|
+
chunks.push(chunk);
|
|
405
|
+
stdout.push(chunk);
|
|
406
|
+
});
|
|
407
|
+
child.stderr.on("data", (chunk) => chunks.push(chunk));
|
|
408
|
+
const interrupt = () => {
|
|
409
|
+
stopGroup(child, "SIGTERM");
|
|
410
|
+
setTimeout(() => stopGroup(child, "SIGKILL"), KILL_GRACE_MS).unref();
|
|
411
|
+
};
|
|
412
|
+
if (signal?.aborted) interrupt();
|
|
413
|
+
else signal?.addEventListener("abort", interrupt, { once: true });
|
|
414
|
+
child.once("error", (error) => {
|
|
415
|
+
signal?.removeEventListener("abort", interrupt);
|
|
416
|
+
resolve({
|
|
417
|
+
status: null,
|
|
418
|
+
stdout: "",
|
|
419
|
+
output: `${error.message}\n`
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
child.once("close", (code, killed) => {
|
|
423
|
+
signal?.removeEventListener("abort", interrupt);
|
|
424
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
425
|
+
resolve({
|
|
426
|
+
status: code,
|
|
427
|
+
stdout: Buffer.concat(stdout).toString("utf8"),
|
|
428
|
+
output: `${text}${killed ? `Terminated by ${killed}\n` : ""}`
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
});
|
|
495
432
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region src/guardrails/git-identity.ts
|
|
435
|
+
/** Config scopes stored inside the repository, which every checkout and agent sharing it commits under. */
|
|
436
|
+
const SHARED_SCOPES = /* @__PURE__ */ new Set(["local", "worktree"]);
|
|
437
|
+
/** Whether `root` is a git checkout, a `.git` folder or a linked worktree's `.git` file. */
|
|
438
|
+
function isGitCheckout(root) {
|
|
439
|
+
return existsSync(join(root, ".git"));
|
|
504
440
|
}
|
|
505
441
|
/**
|
|
506
|
-
*
|
|
507
|
-
* `
|
|
442
|
+
* Fails when the repository's own git config, its `.git/config` shared by every worktree or a worktree's
|
|
443
|
+
* `config.worktree`, sets `user.name` or `user.email`: whoever commits in any checkout of it then signs as that identity.
|
|
444
|
+
* Global, system and command-line settings pass. Returns what failed, naming each file and value, empty when it passed.
|
|
508
445
|
*/
|
|
509
|
-
function
|
|
510
|
-
|
|
446
|
+
async function checkGitIdentity(root, signal) {
|
|
447
|
+
const result = await runCommand("git", [
|
|
448
|
+
"config",
|
|
449
|
+
"--show-scope",
|
|
450
|
+
"--show-origin",
|
|
451
|
+
"--get-regexp",
|
|
452
|
+
String.raw`^user\.(name|email)$`
|
|
453
|
+
], {
|
|
454
|
+
cwd: root,
|
|
455
|
+
signal,
|
|
456
|
+
shell: false
|
|
457
|
+
});
|
|
458
|
+
if (result.status === 1) return "";
|
|
459
|
+
if (result.status !== 0) return result.output;
|
|
460
|
+
const shared = result.stdout.split("\n").filter((line) => SHARED_SCOPES.has(line.split(" ")[0] ?? ""));
|
|
461
|
+
if (!shared.length) return "";
|
|
462
|
+
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`;
|
|
511
463
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
464
|
+
//#endregion
|
|
465
|
+
//#region src/guardrails/services.ts
|
|
466
|
+
/** The compose file the shared CI starts through its `services-compose-file` input, relative to the repository root. */
|
|
467
|
+
const COMPOSE_FILE = ".github/compose.yml";
|
|
468
|
+
function shortPort(text) {
|
|
469
|
+
const parts = text.replace(/\/\w+$/, "").split(":");
|
|
470
|
+
return parts.length < 2 ? void 0 : wholePort(parts.at(-2));
|
|
515
471
|
}
|
|
516
|
-
function
|
|
517
|
-
|
|
518
|
-
const manager = ancestors(folder).some((above) => existsSync(join(root, above, NPM_LOCK))) ? NPM_LOCK : PNPM_LOCK$1;
|
|
519
|
-
return `${folder}/${MANIFEST} has dependencies and no lockfile: run \`${fixCommand(root, folder, manager)}\`.\n`;
|
|
472
|
+
function wholePort(text) {
|
|
473
|
+
return text !== void 0 && /^\d+$/.test(text) ? Number(text) : void 0;
|
|
520
474
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
475
|
+
/**
|
|
476
|
+
* The host ports the compose file publishes, or `undefined` when a service publishes none or one this cannot read
|
|
477
|
+
* (a range, an interpolation, a container-only port), since such a service cannot be probed.
|
|
478
|
+
*/
|
|
479
|
+
function publishedPorts(text) {
|
|
480
|
+
const services = parseDocument(text).get("services");
|
|
481
|
+
if (!isMap(services) || services.items.length === 0) return void 0;
|
|
482
|
+
const ports = [];
|
|
483
|
+
for (const { value } of services.items) {
|
|
484
|
+
const entries = isMap(value) ? value.get("ports") : void 0;
|
|
485
|
+
if (!isSeq(entries) || entries.items.length === 0) return void 0;
|
|
486
|
+
for (const entry of entries.items) {
|
|
487
|
+
const published = isMap(entry) ? entry.get("published") : void 0;
|
|
488
|
+
const port = isScalar(entry) ? shortPort(String(entry.value)) : wholePort(published === void 0 ? void 0 : String(published));
|
|
489
|
+
if (port === void 0) return void 0;
|
|
490
|
+
ports.push(port);
|
|
491
|
+
}
|
|
531
492
|
}
|
|
493
|
+
return ports;
|
|
532
494
|
}
|
|
533
495
|
/**
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
* `
|
|
537
|
-
* `optionalDependencies` are compared, by name and specifier: a name counts as present whichever of the three fields records
|
|
538
|
-
* it, and specifiers such as `catalog:` or `workspace:^` compare as written. A name the lockfile records that `package.json`
|
|
539
|
-
* declares only in `peerDependencies` passes. A `package.json` name that an override selector in the `pnpm-lock.yaml`
|
|
540
|
-
* mentions, or a `link:` one the lockfile leaves out under `excludeLinksFromLockfile`, is not compared. A missing lockfile fails only in a layer's
|
|
541
|
-
* `playground` or the root `playground` whose `package.json` has dependencies, unless a folder above it holds a workspace.
|
|
542
|
-
*
|
|
543
|
-
* It spawns no package manager, writes no file and fetches nothing. It does not check workspace membership, overrides,
|
|
544
|
-
* settings, catalogs, `.npmrc` or user configuration, resolved versions, integrity hashes, transitive entries, npm workspace
|
|
545
|
-
* members, or `yarn.lock` and `bun.lock`: verify's own frozen install still rejects a lockfile stale there. Returns what
|
|
546
|
-
* failed, empty when every lockfile matches.
|
|
496
|
+
* The environment compose runs in. A project named by `COMPOSE_PROJECT_NAME` or by the compose file's own `name:` is
|
|
497
|
+
* kept; otherwise the project is named after the repository root, since compose would name every repository's project
|
|
498
|
+
* `github` after the compose file's directory and a run could adopt or remove another checkout's containers.
|
|
547
499
|
*/
|
|
548
|
-
function
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const PACKAGE_FIELDS = ["dependencies", "optionalDependencies"];
|
|
558
|
-
/** How to move every importer onto one copy while pnpm keeps every other locked version, which `pnpm dedupe` does not. */
|
|
559
|
-
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";
|
|
560
|
-
/** A `name@version` key or a resolved version without its peer suffix, `(peer@1)`, which names no other copy. */
|
|
561
|
-
function withoutPeers(reference) {
|
|
562
|
-
const open = reference.indexOf("(");
|
|
563
|
-
return open === -1 ? reference : reference.slice(0, open);
|
|
500
|
+
function composeEnv(root) {
|
|
501
|
+
if (process.env.COMPOSE_PROJECT_NAME) return process.env;
|
|
502
|
+
if (parseDocument(readFileSync(join(root, COMPOSE_FILE), "utf8")).has("name")) return process.env;
|
|
503
|
+
const slug = basename(root).toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[^a-z0-9]+/, "");
|
|
504
|
+
const digest = createHash("sha256").update(root).digest("hex").slice(0, 8);
|
|
505
|
+
return {
|
|
506
|
+
...process.env,
|
|
507
|
+
COMPOSE_PROJECT_NAME: `${slug || "repo"}-${digest}`
|
|
508
|
+
};
|
|
564
509
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
510
|
+
async function compose(root, args, signal) {
|
|
511
|
+
const result = await runCommand("docker", [
|
|
512
|
+
"compose",
|
|
513
|
+
"-f",
|
|
514
|
+
COMPOSE_FILE,
|
|
515
|
+
...args
|
|
516
|
+
], {
|
|
517
|
+
cwd: root,
|
|
518
|
+
env: composeEnv(root),
|
|
519
|
+
signal
|
|
520
|
+
});
|
|
521
|
+
if (result.status === 0) return {
|
|
522
|
+
failure: "",
|
|
523
|
+
stdout: result.stdout
|
|
524
|
+
};
|
|
525
|
+
const outcome = result.status === null ? "did not finish" : `exited with status ${result.status}`;
|
|
526
|
+
return {
|
|
527
|
+
failure: `${result.output}docker compose -f ${COMPOSE_FILE} ${args.join(" ")}: ${outcome}\n`,
|
|
528
|
+
stdout: result.stdout
|
|
529
|
+
};
|
|
572
530
|
}
|
|
573
|
-
/**
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
531
|
+
/**
|
|
532
|
+
* Decides whether the checks start the services of `.github/compose.yml`: not when the file is absent or every port
|
|
533
|
+
* it publishes already accepts connections, and fail at once when Docker Compose cannot run, because the
|
|
534
|
+
* tests that need those services would wait for them forever.
|
|
535
|
+
*/
|
|
536
|
+
async function planServices(root) {
|
|
537
|
+
if (!existsSync(join(root, COMPOSE_FILE))) return { kind: "none" };
|
|
538
|
+
const ports = publishedPorts(readFileSync(join(root, COMPOSE_FILE), "utf8"));
|
|
539
|
+
if (ports && (await Promise.all(ports.map(accepting))).every(Boolean)) return { kind: "none" };
|
|
540
|
+
const probe = await compose(root, ["version"]);
|
|
541
|
+
if (!probe.failure) return { kind: "start" };
|
|
542
|
+
return {
|
|
543
|
+
kind: "unavailable",
|
|
544
|
+
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}`
|
|
580
545
|
};
|
|
581
|
-
copies.get(target.name)?.get(target.version)?.add(by);
|
|
582
|
-
}
|
|
583
|
-
function addPullers(copies, node, fields, by) {
|
|
584
|
-
for (const field of fields) {
|
|
585
|
-
const entries = mapping(node, field);
|
|
586
|
-
for (const name of keys(entries)) pull(copies, name, scalar(entries, name) ?? scalar(mapping(entries, name), "version"), by);
|
|
587
|
-
}
|
|
588
546
|
}
|
|
589
|
-
/**
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Runs `docker compose up -d --wait` on the compose file, stopping it when `signal` aborts. `failure` is empty on
|
|
549
|
+
* success; `owned` is true when the project had no container before, so the run may remove it afterwards without
|
|
550
|
+
* taking a stack the developer started.
|
|
551
|
+
*/
|
|
552
|
+
async function startServices(root, signal) {
|
|
553
|
+
const before = await compose(root, [
|
|
554
|
+
"ps",
|
|
555
|
+
"--all",
|
|
556
|
+
"--quiet"
|
|
557
|
+
], signal);
|
|
558
|
+
if (before.failure) return {
|
|
559
|
+
failure: before.failure,
|
|
560
|
+
owned: false
|
|
561
|
+
};
|
|
562
|
+
const owned = before.stdout.trim() === "";
|
|
563
|
+
return {
|
|
564
|
+
failure: (await compose(root, [
|
|
565
|
+
"up",
|
|
566
|
+
"-d",
|
|
567
|
+
"--wait"
|
|
568
|
+
], signal)).failure,
|
|
569
|
+
owned
|
|
570
|
+
};
|
|
599
571
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
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()));
|
|
604
|
-
const importers = mapping(lockfile, "importers");
|
|
605
|
-
for (const importer of importers ? keys(importers) : ["."]) addPullers(copies, importers ? mapping(importers, importer) : lockfile, DIRECT_FIELDS, `importer "${importer}"`);
|
|
606
|
-
const resolved = mapping(lockfile, "snapshots") ?? packages;
|
|
607
|
-
for (const key of keys(resolved)) addPullers(copies, mapping(resolved, key), PACKAGE_FIELDS, withoutPeers(key.replace(/^\//u, "")));
|
|
608
|
-
return copies;
|
|
572
|
+
/** Runs `docker compose down -v` on the compose file; returns the failure output, empty on success. */
|
|
573
|
+
async function stopServices(root) {
|
|
574
|
+
return (await compose(root, ["down", "-v"])).failure;
|
|
609
575
|
}
|
|
610
|
-
|
|
611
|
-
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region src/guardrails/verify-layers.ts
|
|
578
|
+
const SKILLS_FOLDER = ".agents/skills";
|
|
579
|
+
const LAYER_PREFIX = "verify-";
|
|
580
|
+
const TSCONFIG = "tsconfig.json";
|
|
581
|
+
/** Folders of a layer that are not the layer's own code: verify builds its playground with the playground's own tsconfig. */
|
|
582
|
+
const NOT_LAYER_CODE = /* @__PURE__ */ new Set(["node_modules", "dist"]);
|
|
583
|
+
const LAYER_PLAYGROUND = "playground";
|
|
584
|
+
const VERIFY_CONFIG = "verify.config.ts";
|
|
585
|
+
/**
|
|
586
|
+
* Options the generated config sets over the layer's: nothing is emitted, and each declaration or build-cache option the
|
|
587
|
+
* layer may inherit is unset with `null`, so no `.tsbuildinfo` is written, no option is left needing `declaration` or
|
|
588
|
+
* `composite`, and the declaration checks of files that are never emitted are not run.
|
|
589
|
+
*/
|
|
590
|
+
const NO_OUTPUT = {
|
|
591
|
+
noEmit: true,
|
|
592
|
+
declaration: null,
|
|
593
|
+
composite: null,
|
|
594
|
+
incremental: null,
|
|
595
|
+
tsBuildInfoFile: null,
|
|
596
|
+
declarationDir: null,
|
|
597
|
+
declarationMap: null,
|
|
598
|
+
emitDeclarationOnly: null,
|
|
599
|
+
isolatedDeclarations: null
|
|
600
|
+
};
|
|
601
|
+
/** 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`. */
|
|
602
|
+
function verifyLayers(root) {
|
|
603
|
+
const skills = join(root, SKILLS_FOLDER);
|
|
604
|
+
if (!existsSync(skills)) return [];
|
|
605
|
+
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();
|
|
612
606
|
}
|
|
613
|
-
/**
|
|
614
|
-
function
|
|
615
|
-
|
|
607
|
+
/** Whether a file the layer's tsconfig includes is the layer's own code, not its playground, a dependency or a build output. */
|
|
608
|
+
function isLayerCode(layer, file) {
|
|
609
|
+
const segments = relative(layer, file).split(sep);
|
|
610
|
+
return segments[0] !== LAYER_PLAYGROUND && !segments.some((segment) => NOT_LAYER_CODE.has(segment));
|
|
616
611
|
}
|
|
617
612
|
/**
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
* Reads the lockfiles only: it spawns no package manager, writes no file and fetches nothing. Returns what failed, empty
|
|
622
|
-
* when every interface package resolves once.
|
|
613
|
+
* The repository's own `tsc` entry, run with Node so no shell parses its path. It is found through the `bin.tsc` field of
|
|
614
|
+
* `typescript/package.json`, a subpath every TypeScript version exports, because TypeScript 7 declares an `exports` map that
|
|
615
|
+
* leaves `typescript/bin/tsc` out.
|
|
623
616
|
*/
|
|
624
|
-
function
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
}).join("");
|
|
633
|
-
}
|
|
634
|
-
//#endregion
|
|
635
|
-
//#region src/guardrails/markdown-table.ts
|
|
636
|
-
/** The lines of a Markdown table whose first row is the header, columns padded as oxfmt leaves them. */
|
|
637
|
-
function tableLines(table) {
|
|
638
|
-
const widths = table[0].map((_, column) => Math.max(3, ...table.map((row) => row[column].length)));
|
|
639
|
-
const line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column])).join(" | ")} |`;
|
|
640
|
-
return [
|
|
641
|
-
line(table[0]),
|
|
642
|
-
line(widths.map((width) => "-".repeat(width))),
|
|
643
|
-
...table.slice(1).map(line)
|
|
644
|
-
];
|
|
617
|
+
function compilerOf(root) {
|
|
618
|
+
try {
|
|
619
|
+
const manifestPath = createRequire(join(root, "package.json")).resolve("typescript/package.json");
|
|
620
|
+
const tsc = parseManifest(readFileSync(manifestPath, "utf8")).bin?.tsc;
|
|
621
|
+
return tsc === void 0 ? void 0 : join(dirname(manifestPath), tsc);
|
|
622
|
+
} catch {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
645
625
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
const
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
},
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
},
|
|
693
|
-
{
|
|
694
|
-
repo: "dms-frontend",
|
|
695
|
-
row: "The `ajs dms` CLI, the Vue renderer and the SDK every frontend module builds on"
|
|
626
|
+
async function typecheckLayer(root, compiler, layer, signal) {
|
|
627
|
+
const configPath = join(root, layer, TSCONFIG);
|
|
628
|
+
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`;
|
|
629
|
+
const ts = (await import("typescript")).default;
|
|
630
|
+
const parsed = ts.getParsedCommandLineOfConfigFile(configPath, void 0, {
|
|
631
|
+
...ts.sys,
|
|
632
|
+
onUnRecoverableConfigFileDiagnostic: () => void 0
|
|
633
|
+
});
|
|
634
|
+
if (parsed === void 0) return `${layer}/${TSCONFIG}: could not read it.\n`;
|
|
635
|
+
const verifyConfig = join(root, layer, VERIFY_CONFIG);
|
|
636
|
+
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`;
|
|
637
|
+
const files = parsed.fileNames.filter((file) => isLayerCode(join(root, layer), resolve(file)));
|
|
638
|
+
if (files.length === 0) return "";
|
|
639
|
+
const folder = mkdtempSync(join(tmpdir(), "antelopejs-verify-types-"));
|
|
640
|
+
try {
|
|
641
|
+
const generated = join(folder, TSCONFIG);
|
|
642
|
+
writeFileSync(generated, JSON.stringify({
|
|
643
|
+
extends: configPath,
|
|
644
|
+
compilerOptions: {
|
|
645
|
+
...NO_OUTPUT,
|
|
646
|
+
typeRoots: ts.getEffectiveTypeRoots(parsed.options, ts.sys)
|
|
647
|
+
},
|
|
648
|
+
files,
|
|
649
|
+
include: []
|
|
650
|
+
}));
|
|
651
|
+
const result = await runCommand(process.execPath, [
|
|
652
|
+
compiler,
|
|
653
|
+
"-p",
|
|
654
|
+
generated,
|
|
655
|
+
"--pretty",
|
|
656
|
+
"false"
|
|
657
|
+
], {
|
|
658
|
+
cwd: root,
|
|
659
|
+
env: {
|
|
660
|
+
...process.env,
|
|
661
|
+
CI: "1"
|
|
662
|
+
},
|
|
663
|
+
signal,
|
|
664
|
+
shell: false
|
|
665
|
+
});
|
|
666
|
+
return result.status === 0 ? "" : result.output;
|
|
667
|
+
} finally {
|
|
668
|
+
rmSync(folder, {
|
|
669
|
+
recursive: true,
|
|
670
|
+
force: true
|
|
671
|
+
});
|
|
696
672
|
}
|
|
697
|
-
];
|
|
698
|
-
/** The generated block, formatted as oxfmt leaves it. */
|
|
699
|
-
function modulesBlock() {
|
|
700
|
-
return [
|
|
701
|
-
DMS_MODULES_START,
|
|
702
|
-
"",
|
|
703
|
-
...tableLines([["Module", "What it adds"], ...DMS_MODULES.map(({ repo, row }) => [`[\`${repo}\`](${ORGANIZATION}/${repo})`, row])]),
|
|
704
|
-
"",
|
|
705
|
-
DMS_MODULES_END,
|
|
706
|
-
""
|
|
707
|
-
].join("\n");
|
|
708
673
|
}
|
|
709
|
-
/**
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
674
|
+
/**
|
|
675
|
+
* Type-checks the own code of each verify layer with the repository's own TypeScript. The files are those the layer's
|
|
676
|
+
* `tsconfig.json` includes, minus its `playground` folder, which verify compiles with the playground's own config after
|
|
677
|
+
* installing it, and any `node_modules` or `dist` folder. A config generated in the system temp folder extends the layer's,
|
|
678
|
+
* lists those files, turns off emit and unsets the emit and build-cache options in `NO_OUTPUT`, so nothing is written in the
|
|
679
|
+
* 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.
|
|
680
|
+
*/
|
|
681
|
+
async function typecheckLayers(root, signal) {
|
|
682
|
+
const layers = verifyLayers(root);
|
|
683
|
+
if (layers.length === 0) return "";
|
|
684
|
+
const compiler = compilerOf(root);
|
|
685
|
+
if (compiler === void 0) return "TypeScript is not installed in the repository root: run the package manager's install first.\n";
|
|
686
|
+
return (await Promise.all(layers.map((layer) => typecheckLayer(root, compiler, layer, signal)))).join("");
|
|
718
687
|
}
|
|
719
688
|
//#endregion
|
|
720
|
-
//#region src/guardrails/
|
|
721
|
-
|
|
722
|
-
const
|
|
723
|
-
const
|
|
724
|
-
const
|
|
725
|
-
const
|
|
726
|
-
const
|
|
727
|
-
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
689
|
+
//#region src/guardrails/verify-lockfiles.ts
|
|
690
|
+
/** The folder a repository's playground lives in; verify installs a fixture project from it. */
|
|
691
|
+
const PLAYGROUND = "playground";
|
|
692
|
+
const PNPM_LOCK$1 = "pnpm-lock.yaml";
|
|
693
|
+
const NPM_LOCK = "package-lock.json";
|
|
694
|
+
const MANIFEST = "package.json";
|
|
695
|
+
const PNPM_WORKSPACE = "pnpm-workspace.yaml";
|
|
696
|
+
/** Lockfiles this check does not compare, which still mean a folder is locked. */
|
|
697
|
+
const OTHER_LOCKS = [
|
|
698
|
+
"npm-shrinkwrap.json",
|
|
699
|
+
"yarn.lock",
|
|
700
|
+
"bun.lock",
|
|
701
|
+
"bun.lockb"
|
|
702
|
+
];
|
|
703
|
+
/** The manifest fields both package managers record as a project's direct dependencies. */
|
|
704
|
+
const DIRECT_FIELDS = [
|
|
733
705
|
"dependencies",
|
|
734
|
-
"
|
|
735
|
-
"
|
|
706
|
+
"devDependencies",
|
|
707
|
+
"optionalDependencies"
|
|
736
708
|
];
|
|
737
|
-
/**
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
"",
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
`\`${name}\``,
|
|
749
|
-
`\`${supported.replaceAll("|", "\\|")}\``,
|
|
750
|
-
tested === void 0 ? UNRESOLVED : `\`${tested}\``
|
|
751
|
-
])]),
|
|
752
|
-
"",
|
|
753
|
-
DOCS_COMPAT_END,
|
|
754
|
-
""
|
|
755
|
-
].join("\n");
|
|
709
|
+
/** A lockfile or manifest this check cannot read as a version it knows. */
|
|
710
|
+
var Unreadable = class extends Error {};
|
|
711
|
+
/** Parses a JSON or YAML file whose top level is a mapping; throws `Unreadable` otherwise. */
|
|
712
|
+
function readMapping(path) {
|
|
713
|
+
const document = parseDocument(readFileSync(path, "utf8"), {
|
|
714
|
+
schema: "failsafe",
|
|
715
|
+
uniqueKeys: false
|
|
716
|
+
});
|
|
717
|
+
const { contents } = document;
|
|
718
|
+
if (document.errors.length > 0 || !isMap(contents)) throw new Unreadable(path);
|
|
719
|
+
return contents;
|
|
756
720
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
while (index < lines.length && !lines[index].trim()) index++;
|
|
762
|
-
return index;
|
|
721
|
+
/** The mapping under `key`; `undefined` when absent or not a mapping. */
|
|
722
|
+
function mapping(map, key) {
|
|
723
|
+
const value = map?.get(key, true);
|
|
724
|
+
return isMap(value) ? value : void 0;
|
|
763
725
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
726
|
+
/** The source text of the scalar under `key`; `undefined` when absent or not a scalar. */
|
|
727
|
+
function scalar(map, key) {
|
|
728
|
+
const value = map?.get(key, true);
|
|
729
|
+
return isScalar(value) ? String(value.value) : void 0;
|
|
730
|
+
}
|
|
731
|
+
/** The scalar keys of a mapping, in order; none when it is absent. */
|
|
732
|
+
function keys(map) {
|
|
733
|
+
return (map?.items ?? []).flatMap((pair) => isScalar(pair.key) ? [String(pair.key.value)] : []);
|
|
734
|
+
}
|
|
735
|
+
/** Reads a project's direct dependencies, with `specifierOf` reading the specifier of one name from its field. */
|
|
736
|
+
function directOf(node, specifierOf) {
|
|
737
|
+
const direct = /* @__PURE__ */ new Map();
|
|
738
|
+
for (const field of DIRECT_FIELDS) {
|
|
739
|
+
const entries = mapping(node, field);
|
|
740
|
+
for (const name of keys(entries)) {
|
|
741
|
+
const specifier = specifierOf(entries, name);
|
|
742
|
+
if (specifier === void 0) throw new Unreadable(name);
|
|
743
|
+
direct.set(name, /* @__PURE__ */ new Set([...direct.get(name) ?? [], specifier]));
|
|
772
744
|
}
|
|
773
|
-
if (!replaced) placed.push(...block.split("\n"));
|
|
774
|
-
replaced = true;
|
|
775
|
-
index = legacySpanEnd(lines, index);
|
|
776
745
|
}
|
|
777
|
-
return
|
|
746
|
+
return direct;
|
|
778
747
|
}
|
|
779
|
-
|
|
780
|
-
|
|
748
|
+
/** A `package.json` or a `package-lock.json` root entry, where each name maps to its specifier. */
|
|
749
|
+
function declared(node) {
|
|
750
|
+
return directOf(node, scalar);
|
|
781
751
|
}
|
|
782
|
-
/**
|
|
783
|
-
function
|
|
784
|
-
|
|
785
|
-
const start = text.indexOf(DOCS_COMPAT_START);
|
|
786
|
-
const end = text.indexOf(DOCS_COMPAT_END);
|
|
787
|
-
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-compat markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
788
|
-
if (start !== -1) return `${text.slice(0, start)}${block}${text.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
789
|
-
const lines = text.split("\n");
|
|
790
|
-
const legacy = replaceLegacyTables(lines, block);
|
|
791
|
-
if (legacy) return finalNewline(legacy.join("\n"));
|
|
792
|
-
const heading = lines.findIndex((line) => COMPATIBILITY_HEADING.test(line));
|
|
793
|
-
if (heading !== -1) {
|
|
794
|
-
let rest = heading + 1;
|
|
795
|
-
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
796
|
-
return finalNewline([
|
|
797
|
-
...lines.slice(0, heading + 1),
|
|
798
|
-
"",
|
|
799
|
-
...block.split("\n"),
|
|
800
|
-
...lines.slice(rest)
|
|
801
|
-
].join("\n"));
|
|
802
|
-
}
|
|
803
|
-
const before = text.trimEnd();
|
|
804
|
-
return `${before}${before ? "\n\n" : ""}## Compatibility\n\n${block}`;
|
|
752
|
+
/** A `pnpm-lock.yaml` importer, where each name maps to its `specifier` and resolved `version`. */
|
|
753
|
+
function pnpmLocked(node) {
|
|
754
|
+
return directOf(node, (field, name) => scalar(mapping(field, name), "specifier"));
|
|
805
755
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
return `${DOCS_NODE_START}\n\nThis package requires Node.js \`${range}\`.\n${DOCS_NODE_END}\n`;
|
|
756
|
+
function listed(specifiers) {
|
|
757
|
+
return specifiers === void 0 ? "none" : [...specifiers].map((specifier) => `"${specifier}"`).join(" or ");
|
|
809
758
|
}
|
|
810
|
-
/**
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
"",
|
|
824
|
-
...block.trimEnd().split("\n"),
|
|
825
|
-
...rest < lines.length ? ["", ...lines.slice(rest)] : []
|
|
826
|
-
].join("\n"));
|
|
827
|
-
}
|
|
828
|
-
return `${current.trimEnd()}\n\n## Requirements\n\n${block}`;
|
|
759
|
+
/**
|
|
760
|
+
* The names whose specifiers differ between a manifest and what its lockfile records, in either direction. A name counts as
|
|
761
|
+
* present whichever of the three fields records it, and matches when the two sides share a specifier. A name the lockfile
|
|
762
|
+
* records and the manifest declares only as a peer passes, since the package manager may or may not install peers. `skip`
|
|
763
|
+
* names the manifest entries the lockfile may leave out or record with another specifier.
|
|
764
|
+
*/
|
|
765
|
+
function differences(manifest, locked, skip) {
|
|
766
|
+
const wanted = declared(manifest);
|
|
767
|
+
const peers = new Set(keys(mapping(manifest, "peerDependencies")));
|
|
768
|
+
const line = (name) => `"${name}": package.json asks for ${listed(wanted.get(name))}, the lockfile has ${listed(locked.get(name))}.`;
|
|
769
|
+
const stale = [...wanted].filter(([name, specifiers]) => ![...locked.get(name) ?? []].some((specifier) => specifiers.has(specifier)) && !skip(name, specifiers)).map(([name]) => line(name));
|
|
770
|
+
const extra = [...locked.keys()].filter((name) => !wanted.has(name) && !peers.has(name)).map(line);
|
|
771
|
+
return [...stale, ...extra].sort();
|
|
829
772
|
}
|
|
830
|
-
|
|
831
|
-
|
|
773
|
+
/** Every package name an override selector such as `foo`, `@scope/foo@^1` or `bar@1>foo@2` mentions, its target among them. */
|
|
774
|
+
function overrideNames(selector) {
|
|
775
|
+
return selector.split(">").flatMap((segment) => /^(?:@[^/@]+\/)?[^@]+/u.exec(segment) ?? []);
|
|
832
776
|
}
|
|
833
|
-
function
|
|
834
|
-
|
|
777
|
+
function pnpmDifferences(path) {
|
|
778
|
+
const lockfile = readMapping(join(path, PNPM_LOCK$1));
|
|
779
|
+
if (Number(scalar(lockfile, "lockfileVersion") ?? "0") < 6) throw new Unreadable(path);
|
|
780
|
+
const overridden = new Set(keys(mapping(lockfile, "overrides")).flatMap(overrideNames));
|
|
781
|
+
const linksLeftOut = scalar(mapping(lockfile, "settings"), "excludeLinksFromLockfile") === "true";
|
|
782
|
+
const skip = (name, specifiers) => overridden.has(name) || linksLeftOut && [...specifiers].every((specifier) => specifier.startsWith("link:"));
|
|
783
|
+
const importers = mapping(lockfile, "importers");
|
|
784
|
+
return (importers ? keys(importers) : ["."]).flatMap((importer) => {
|
|
785
|
+
const manifest = join(path, importer, MANIFEST);
|
|
786
|
+
if (!existsSync(manifest)) return [];
|
|
787
|
+
const node = importers ? mapping(importers, importer) : lockfile;
|
|
788
|
+
return differences(readMapping(manifest), pnpmLocked(node), skip).map((line) => `importer "${importer}" ${line}`);
|
|
789
|
+
});
|
|
835
790
|
}
|
|
836
|
-
function
|
|
837
|
-
|
|
791
|
+
function npmDifferences(path) {
|
|
792
|
+
const lockfile = readMapping(join(path, NPM_LOCK));
|
|
793
|
+
const rootEntry = mapping(mapping(lockfile, "packages"), "");
|
|
794
|
+
if (Number(scalar(lockfile, "lockfileVersion") ?? "0") < 2 || rootEntry === void 0) throw new Unreadable(path);
|
|
795
|
+
const manifest = join(path, MANIFEST);
|
|
796
|
+
if (!existsSync(manifest)) return [];
|
|
797
|
+
return differences(readMapping(manifest), declared(rootEntry), () => false);
|
|
838
798
|
}
|
|
839
|
-
function
|
|
840
|
-
|
|
799
|
+
function lockfileIn(path) {
|
|
800
|
+
if (existsSync(join(path, PNPM_LOCK$1))) return PNPM_LOCK$1;
|
|
801
|
+
if (existsSync(join(path, NPM_LOCK))) return NPM_LOCK;
|
|
802
|
+
return OTHER_LOCKS.some((name) => existsSync(join(path, name))) ? "other" : void 0;
|
|
803
|
+
}
|
|
804
|
+
/** Each folder at or under `folder`, `node_modules` and `dist` aside, that holds a lockfile. */
|
|
805
|
+
function lockedFolders(root, folder) {
|
|
806
|
+
const path = join(root, folder);
|
|
807
|
+
if (!existsSync(path)) return [];
|
|
808
|
+
const lockfile = lockfileIn(path);
|
|
809
|
+
return [...lockfile === void 0 ? [] : [{
|
|
810
|
+
folder,
|
|
811
|
+
lockfile
|
|
812
|
+
}], ...readdirSync(path, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist").flatMap((entry) => lockedFolders(root, `${folder}/${entry.name}`))];
|
|
813
|
+
}
|
|
814
|
+
/** Whether a `package.json` declares a direct dependency; `false` when it is missing or cannot be read, so this check cannot tell. */
|
|
815
|
+
function hasDependencies(path) {
|
|
816
|
+
try {
|
|
817
|
+
if (!existsSync(path)) return false;
|
|
818
|
+
const manifest = readMapping(path);
|
|
819
|
+
return DIRECT_FIELDS.some((field) => keys(mapping(manifest, field)).length > 0);
|
|
820
|
+
} catch (error) {
|
|
821
|
+
if (error instanceof Unreadable) return false;
|
|
822
|
+
throw error;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* The folders this check reads, when a layer exists: each folder under a layer, `node_modules` and `dist` aside, and the
|
|
827
|
+
* root `playground`, that holds a lockfile; and each layer's `playground` and the root `playground`, the folders verify
|
|
828
|
+
* installs from, when its `package.json` has dependencies and it holds no lockfile.
|
|
829
|
+
*/
|
|
830
|
+
function verifyInstallFolders(root) {
|
|
831
|
+
const layers = verifyLayers(root);
|
|
832
|
+
if (layers.length === 0) return [];
|
|
833
|
+
const playgrounds = [...layers.map((layer) => `${layer}/${PLAYGROUND}`), PLAYGROUND];
|
|
834
|
+
const rootPlayground = lockfileIn(join(root, PLAYGROUND));
|
|
835
|
+
return [
|
|
836
|
+
...layers.flatMap((layer) => lockedFolders(root, layer)),
|
|
837
|
+
...rootPlayground === void 0 ? [] : [{
|
|
838
|
+
folder: PLAYGROUND,
|
|
839
|
+
lockfile: rootPlayground
|
|
840
|
+
}],
|
|
841
|
+
...playgrounds.filter((folder) => lockfileIn(join(root, folder)) === void 0 && hasDependencies(join(root, folder, MANIFEST))).map((folder) => ({
|
|
842
|
+
folder,
|
|
843
|
+
lockfile: void 0
|
|
844
|
+
}))
|
|
845
|
+
];
|
|
841
846
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
847
|
+
/** The folders above `folder`, nearest first, up to the repository root. */
|
|
848
|
+
function ancestors(folder) {
|
|
849
|
+
const parent = posix.dirname(folder);
|
|
850
|
+
return parent === folder ? [] : [parent, ...ancestors(parent)];
|
|
845
851
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
852
|
+
/** Whether a manifest declares workspaces, or cannot be read and so might. */
|
|
853
|
+
function declaresWorkspaces(path) {
|
|
854
|
+
try {
|
|
855
|
+
return existsSync(path) && readMapping(path).has("workspaces");
|
|
856
|
+
} catch (error) {
|
|
857
|
+
if (error instanceof Unreadable) return true;
|
|
858
|
+
throw error;
|
|
859
|
+
}
|
|
854
860
|
}
|
|
855
|
-
|
|
856
|
-
|
|
861
|
+
/**
|
|
862
|
+
* Whether a folder above `folder` holds a workspace that may list it, a `pnpm-workspace.yaml` or a `package.json` with
|
|
863
|
+
* `workspaces`: its membership then follows patterns this check does not evaluate, and that workspace's lockfile may hold it.
|
|
864
|
+
*/
|
|
865
|
+
function inWorkspace(root, folder) {
|
|
866
|
+
return ancestors(folder).some((above) => existsSync(join(root, above, PNPM_WORKSPACE)) || declaresWorkspaces(join(root, above, MANIFEST)));
|
|
857
867
|
}
|
|
858
|
-
function
|
|
859
|
-
|
|
860
|
-
return
|
|
868
|
+
function fixCommand(root, folder, lockfile) {
|
|
869
|
+
if (lockfile === NPM_LOCK) return `npm install --package-lock-only --prefix ${folder}`;
|
|
870
|
+
return existsSync(join(root, folder, PNPM_WORKSPACE)) ? `pnpm install --dir ${folder} --lockfile-only` : `pnpm install --dir ${folder} --ignore-workspace --lockfile-only`;
|
|
861
871
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
const
|
|
865
|
-
|
|
866
|
-
const manifest = parseDocument(readFileSync(join(root, "package.json"), "utf8"));
|
|
867
|
-
return scalarItems(manifest, isMap(manifest.get("workspaces", true)) ? ["workspaces", "packages"] : ["workspaces"]);
|
|
872
|
+
function unlocked(root, folder) {
|
|
873
|
+
if (inWorkspace(root, folder)) return "";
|
|
874
|
+
const manager = ancestors(folder).some((above) => existsSync(join(root, above, NPM_LOCK))) ? NPM_LOCK : PNPM_LOCK$1;
|
|
875
|
+
return `${folder}/${MANIFEST} has dependencies and no lockfile: run \`${fixCommand(root, folder, manager)}\`.\n`;
|
|
868
876
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
+
function checkFolder(root, { folder, lockfile }) {
|
|
878
|
+
if (lockfile === "other") return "";
|
|
879
|
+
try {
|
|
880
|
+
if (lockfile === void 0) return unlocked(root, folder);
|
|
881
|
+
const path = join(root, folder);
|
|
882
|
+
const found = lockfile === PNPM_LOCK$1 ? pnpmDifferences(path) : npmDifferences(path);
|
|
883
|
+
return found.length === 0 ? "" : `${folder}/${lockfile} does not match ${folder}/${MANIFEST}: run \`${fixCommand(root, folder, lockfile)}\`.\n${found.map((line) => ` ${line}\n`).join("")}`;
|
|
884
|
+
} catch (error) {
|
|
885
|
+
if (error instanceof Unreadable) return `${folder}/${lockfile ?? MANIFEST}: could not read it, or a ${MANIFEST} it locks, as a version this check knows.\n`;
|
|
886
|
+
throw error;
|
|
877
887
|
}
|
|
878
|
-
return [...found].sort();
|
|
879
888
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
889
|
+
/**
|
|
890
|
+
* Compares, in code, the direct dependencies each lockfile records with the `package.json` files it locks, and fails on a
|
|
891
|
+
* difference in either direction. A `pnpm-lock.yaml` is compared importer by importer, for each importer it lists that has a
|
|
892
|
+
* `package.json` on disk; a `package-lock.json` by its root entry. Only `dependencies`, `devDependencies` and
|
|
893
|
+
* `optionalDependencies` are compared, by name and specifier: a name counts as present whichever of the three fields records
|
|
894
|
+
* it, and specifiers such as `catalog:` or `workspace:^` compare as written. A name the lockfile records that `package.json`
|
|
895
|
+
* declares only in `peerDependencies` passes. A `package.json` name that an override selector in the `pnpm-lock.yaml`
|
|
896
|
+
* mentions, or a `link:` one the lockfile leaves out under `excludeLinksFromLockfile`, is not compared. A missing lockfile fails only in a layer's
|
|
897
|
+
* `playground` or the root `playground` whose `package.json` has dependencies, unless a folder above it holds a workspace.
|
|
898
|
+
*
|
|
899
|
+
* It spawns no package manager, writes no file and fetches nothing. It does not check workspace membership, overrides,
|
|
900
|
+
* settings, catalogs, `.npmrc` or user configuration, resolved versions, integrity hashes, transitive entries, npm workspace
|
|
901
|
+
* members, or `yarn.lock` and `bun.lock`: verify's own frozen install still rejects a lockfile stale there. Returns what
|
|
902
|
+
* failed, empty when every lockfile matches.
|
|
903
|
+
*/
|
|
904
|
+
function checkLockfiles(root) {
|
|
905
|
+
return verifyInstallFolders(root).map((install) => checkFolder(root, install)).join("");
|
|
888
906
|
}
|
|
889
|
-
|
|
890
|
-
|
|
907
|
+
//#endregion
|
|
908
|
+
//#region src/guardrails/singleton-packages.ts
|
|
909
|
+
const PNPM_LOCK = "pnpm-lock.yaml";
|
|
910
|
+
/** Packages one process must load once: every AntelopeJS interface package shares one runtime with its peers. */
|
|
911
|
+
const SINGLETON = /^@antelopejs\/interface-/u;
|
|
912
|
+
/** The fields of a lockfile package entry that point at the copy each dependency resolves to. */
|
|
913
|
+
const PACKAGE_FIELDS = ["dependencies", "optionalDependencies"];
|
|
914
|
+
/** How to move every importer onto one copy while pnpm keeps every other locked version, which `pnpm dedupe` does not. */
|
|
915
|
+
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";
|
|
916
|
+
/** A `name@version` key or a resolved version without its peer suffix, `(peer@1)`, which names no other copy. */
|
|
917
|
+
function withoutPeers(reference) {
|
|
918
|
+
const open = reference.indexOf("(");
|
|
919
|
+
return open === -1 ? reference : reference.slice(0, open);
|
|
891
920
|
}
|
|
892
|
-
/** The
|
|
893
|
-
function
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
921
|
+
/** The name and version of a `packages` key: `@scope/name@1.0.0` in version 9, `/@scope/name@1.0.0` in version 6. */
|
|
922
|
+
function packageKey(key) {
|
|
923
|
+
const match = /^\/?((?:@[^/@]+\/)?[^@]+)@(.+)$/u.exec(withoutPeers(key));
|
|
924
|
+
return match?.[1] && match[2] ? {
|
|
925
|
+
name: match[1],
|
|
926
|
+
version: match[2]
|
|
927
|
+
} : void 0;
|
|
928
|
+
}
|
|
929
|
+
/** Records `by` as a puller of the copy a dependency resolves to: `version`, or the `name@version` an `npm:` alias resolves to. */
|
|
930
|
+
function pull(copies, name, version, by) {
|
|
931
|
+
if (version === void 0) return;
|
|
932
|
+
const alias = packageKey(version);
|
|
933
|
+
const target = alias && copies.has(alias.name) ? alias : {
|
|
934
|
+
name,
|
|
935
|
+
version: withoutPeers(version)
|
|
936
|
+
};
|
|
937
|
+
copies.get(target.name)?.get(target.version)?.add(by);
|
|
938
|
+
}
|
|
939
|
+
function addPullers(copies, node, fields, by) {
|
|
940
|
+
for (const field of fields) {
|
|
941
|
+
const entries = mapping(node, field);
|
|
942
|
+
for (const name of keys(entries)) pull(copies, name, scalar(entries, name) ?? scalar(mapping(entries, name), "version"), by);
|
|
905
943
|
}
|
|
906
944
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
945
|
+
/** Each document of a lockfile: pnpm 11 writes its config dependencies, installed apart from the project, as a document before the project's. */
|
|
946
|
+
function lockfileDocuments(path) {
|
|
947
|
+
return parseAllDocuments(readFileSync(path, "utf8"), {
|
|
948
|
+
schema: "failsafe",
|
|
949
|
+
uniqueKeys: false
|
|
950
|
+
}).map((document) => {
|
|
951
|
+
const { contents } = document;
|
|
952
|
+
if (document.errors.length > 0 || !isMap(contents) || !(Number.parseFloat(scalar(contents, "lockfileVersion") ?? "") >= 6)) throw new Unreadable(path);
|
|
953
|
+
return contents;
|
|
954
|
+
});
|
|
914
955
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
956
|
+
function documentCopies(lockfile) {
|
|
957
|
+
const copies = /* @__PURE__ */ new Map();
|
|
958
|
+
const packages = mapping(lockfile, "packages");
|
|
959
|
+
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()));
|
|
960
|
+
const importers = mapping(lockfile, "importers");
|
|
961
|
+
for (const importer of importers ? keys(importers) : ["."]) addPullers(copies, importers ? mapping(importers, importer) : lockfile, DIRECT_FIELDS, `importer "${importer}"`);
|
|
962
|
+
const resolved = mapping(lockfile, "snapshots") ?? packages;
|
|
963
|
+
for (const key of keys(resolved)) addPullers(copies, mapping(resolved, key), PACKAGE_FIELDS, withoutPeers(key.replace(/^\//u, "")));
|
|
964
|
+
return copies;
|
|
918
965
|
}
|
|
919
|
-
function
|
|
920
|
-
|
|
921
|
-
if (!documents.has(path) && existsSync(path)) documents.set(path, parseDocument(readFileSync(path, "utf8")));
|
|
922
|
-
const document = documents.get(path);
|
|
923
|
-
return document && {
|
|
924
|
-
document,
|
|
925
|
-
importer: shared ? directory || "." : "."
|
|
926
|
-
};
|
|
966
|
+
function report(file, copies) {
|
|
967
|
+
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("");
|
|
927
968
|
}
|
|
928
|
-
/**
|
|
929
|
-
function
|
|
930
|
-
|
|
931
|
-
const docs = relative$1(directory, "docs");
|
|
932
|
-
if (!published) return;
|
|
933
|
-
if (ranges.size > 0 || existsSync(join(root, readme))) plan.docsFiles.push(readme);
|
|
934
|
-
if (isDirectory(root, docs)) plan.docsFiles.push(docs);
|
|
935
|
-
const current = existsSync(join(root, readme)) ? readFileSync(join(root, readme), "utf8") : void 0;
|
|
936
|
-
const nodeRange = standard && current !== void 0 ? node : void 0;
|
|
937
|
-
if (ranges.size === 0 && current === void 0) return;
|
|
938
|
-
const rows = [...ranges].map(([name, supported]) => ({
|
|
939
|
-
name,
|
|
940
|
-
supported,
|
|
941
|
-
tested: lock && resolvedVersion(lock, name)
|
|
942
|
-
}));
|
|
943
|
-
try {
|
|
944
|
-
const withRequirements = nodeRange !== void 0 && current !== void 0 ? placeNodeBlock(current, nodeBlock(nodeRange)) : current;
|
|
945
|
-
plan.readmes.push({
|
|
946
|
-
path: readme,
|
|
947
|
-
current,
|
|
948
|
-
content: placeModulesBlock(rows.length > 0 ? placeCompatBlock(withRequirements, compatBlock(rows)) : withRequirements ?? "")
|
|
949
|
-
});
|
|
950
|
-
} catch (error) {
|
|
951
|
-
plan.errors.push(`${readme}: ${error instanceof Error ? error.message : String(error)}`);
|
|
952
|
-
}
|
|
969
|
+
/** The `pnpm-lock.yaml` files on disk in the repository, tracked or not yet added, outside what `.gitignore` leaves out. */
|
|
970
|
+
function pnpmLockfiles(root) {
|
|
971
|
+
return gitFiles(root).filter((file) => (file === PNPM_LOCK || file.endsWith(`/${PNPM_LOCK}`)) && existsSync(join(root, file)));
|
|
953
972
|
}
|
|
954
973
|
/**
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
*
|
|
958
|
-
*
|
|
974
|
+
* Fails when a `pnpm-lock.yaml` of the repository resolves an AntelopeJS interface package, any `@antelopejs/interface-*`,
|
|
975
|
+
* at more than one version: each copy carries its own runtime, so two copies in one process break the contract between
|
|
976
|
+
* modules, or throw on a runtime protocol mismatch. Names, for each version, the importers and packages that pull it.
|
|
977
|
+
* Reads the lockfiles only: it spawns no package manager, writes no file and fetches nothing. Returns what failed, empty
|
|
978
|
+
* when every interface package resolves once.
|
|
959
979
|
*/
|
|
960
|
-
function
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
};
|
|
970
|
-
});
|
|
971
|
-
const qualifying = packages.filter(({ ranges }) => ranges.size > 0);
|
|
972
|
-
const plan = {
|
|
973
|
-
readmes: [],
|
|
974
|
-
docsFiles: [],
|
|
975
|
-
errors: [],
|
|
976
|
-
exists: (path) => existsSync(join(root, path))
|
|
977
|
-
};
|
|
978
|
-
const shared = sharesLockfile(root);
|
|
979
|
-
const documents = /* @__PURE__ */ new Map();
|
|
980
|
-
const locks = new Map(qualifying.map(({ directory }) => [directory, manager === "pnpm" ? readLock(root, shared, directory, documents) : void 0]));
|
|
981
|
-
const missing = manager === "pnpm" ? qualifying.filter(({ directory }) => !locks.get(directory)) : [];
|
|
982
|
-
if (missing.length) {
|
|
983
|
-
for (const path of new Set(missing.map(({ directory }) => lockPath(shared, directory)))) plan.errors.push(`${path} is missing, and the docs-compat block reads Tested with from it: run pnpm install, then rerun antelopejs-sync.`);
|
|
984
|
-
return plan;
|
|
985
|
-
}
|
|
986
|
-
const standard = rootManifest.antelopeJs?.docs?.standard === true;
|
|
987
|
-
for (const item of packages) planPackage(root, plan, locks.get(item.directory), standard, item);
|
|
988
|
-
return plan;
|
|
980
|
+
function checkSingletonPackages(root) {
|
|
981
|
+
return pnpmLockfiles(root).map((file) => {
|
|
982
|
+
try {
|
|
983
|
+
return lockfileDocuments(join(root, file)).map((document) => report(file, documentCopies(document))).join("");
|
|
984
|
+
} catch (error) {
|
|
985
|
+
if (error instanceof Unreadable) return `${file}: could not read it as a lockfile version this check knows.\n`;
|
|
986
|
+
throw error;
|
|
987
|
+
}
|
|
988
|
+
}).join("");
|
|
989
989
|
}
|
|
990
990
|
//#endregion
|
|
991
991
|
//#region src/guardrails/script-steps.ts
|
|
@@ -1503,4 +1503,4 @@ async function runChecks(root, options = {}) {
|
|
|
1503
1503
|
};
|
|
1504
1504
|
}
|
|
1505
1505
|
//#endregion
|
|
1506
|
-
export { stepsOf as a, matchingScripts as i, droppedChecksSteps as n, planDocs as o, runChecks as r, workspaceDirectories as s, CHECKS_SKIP_ENV as t };
|
|
1506
|
+
export { stepsOf as a, workspacePatterns as c, matchingScripts as i, droppedChecksSteps as n, planDocs as o, runChecks as r, workspaceDirectories as s, CHECKS_SKIP_ENV as t };
|