@antelopejs/tooling-configs 0.5.0 → 0.5.2
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 +68 -31
- package/dist/bin/api-diff.mjs +3 -3
- package/dist/bin/body-check.mjs +2 -2
- package/dist/bin/checks.mjs +157 -7
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/garden.mjs +7 -2
- package/dist/bin/lease.mjs +48 -11
- package/dist/bin/ratchet.mjs +2 -2
- package/dist/bin/suppressions.mjs +1 -1
- package/dist/bin/sync.mjs +200 -484
- package/dist/bin/verify.mjs +211 -54
- package/dist/oxc/anti-slop/index.mjs +106 -366
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +279 -10
- package/dist/oxc/lint.d.mts +6 -0
- package/dist/oxc/lint.mjs +4 -2
- package/dist/{oxlint-DIV-lLSS.mjs → oxlint-BbpTFFmf.mjs} +7 -2
- package/dist/{package-Dn7VTFUW.mjs → package-DxxcxOzp.mjs} +28 -2
- package/dist/{proof-stamp-DLWpPwQE.mjs → proof-stamp-D9yo2dxU.mjs} +1 -1
- package/dist/{ratchet-BTiPMqam.mjs → ratchet--WWa_w2O.mjs} +3 -2
- package/dist/script-steps-CgH2DSsp.mjs +594 -0
- package/dist/{templates-lJBZFskp.mjs → templates-BiXgdsRN.mjs} +1 -1
- package/dist/{typescript-BBbry7uU.mjs → typescript-D7SaSmsl.mjs} +1 -1
- package/dist/{ci-workflow-COJUT12b.mjs → workflow-B0FmthGv.mjs} +107 -107
- package/package.json +3 -2
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
import { o as parseManifest } from "./package-DxxcxOzp.mjs";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
5
|
+
//#region src/guardrails/markdown-table.ts
|
|
6
|
+
/** The lines of a Markdown table whose first row is the header, columns padded as oxfmt leaves them. */
|
|
7
|
+
function tableLines(table) {
|
|
8
|
+
const widths = table[0].map((_, column) => Math.max(3, ...table.map((row) => row[column].length)));
|
|
9
|
+
const line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column])).join(" | ")} |`;
|
|
10
|
+
return [
|
|
11
|
+
line(table[0]),
|
|
12
|
+
line(widths.map((width) => "-".repeat(width))),
|
|
13
|
+
...table.slice(1).map(line)
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/guardrails/docs-modules.ts
|
|
18
|
+
const DMS_MODULES_START = "<!-- antelopejs-dms-modules:start -->";
|
|
19
|
+
const DMS_MODULES_END = "<!-- antelopejs-dms-modules:end -->";
|
|
20
|
+
const ORGANIZATION = "https://github.com/AntelopeJS";
|
|
21
|
+
/** The AntelopeJS DMS modules in display order. Every README holding the markers lists exactly these. */
|
|
22
|
+
const DMS_MODULES = [
|
|
23
|
+
{
|
|
24
|
+
repo: "dms-builder",
|
|
25
|
+
row: "Edit pages, tables and data sources by clicking, as TypeScript that compiles"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
repo: "dms-ai",
|
|
29
|
+
row: "An assistant chat in the dashboard, on your own Claude Code or Codex"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
repo: "dms-database",
|
|
33
|
+
row: "Schemas, relation diagrams, a data browser and a query console"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
repo: "dms-api",
|
|
37
|
+
row: "API health, request logs, per-route statistics and a request tester"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
repo: "dms-automation",
|
|
41
|
+
row: "Node-graph automations on schedules, webhooks and DMS events, with a trace for every run"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
repo: "dms-mailing",
|
|
45
|
+
row: "E-mail templates in a block editor, versions, a send log and delivery metrics"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
repo: "dms-lang",
|
|
49
|
+
row: "Translation coverage, a translation matrix and a translation queue"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
repo: "dms-media",
|
|
53
|
+
row: "A media library with folders, per-folder permissions, image sizes and light editing"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
repo: "dms-saas",
|
|
57
|
+
row: "Self-service sign-up, plans that gate features, and Stripe billing"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
repo: "dms-marketing",
|
|
61
|
+
row: "Traffic, conversion funnels with A/B splits and click heatmaps, without cookies"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
repo: "dms-frontend",
|
|
65
|
+
row: "The `ajs dms` CLI, the Vue renderer and the SDK every frontend module builds on"
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
/** The generated block, formatted as oxfmt leaves it. */
|
|
69
|
+
function modulesBlock() {
|
|
70
|
+
return [
|
|
71
|
+
DMS_MODULES_START,
|
|
72
|
+
"",
|
|
73
|
+
...tableLines([["Module", "What it adds"], ...DMS_MODULES.map(({ repo, row }) => [`[\`${repo}\`](${ORGANIZATION}/${repo})`, row])]),
|
|
74
|
+
"",
|
|
75
|
+
DMS_MODULES_END,
|
|
76
|
+
""
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
/** The README with the block between its markers rewritten. A README without markers comes back as it is. */
|
|
80
|
+
function placeModulesBlock(current) {
|
|
81
|
+
const start = current.indexOf(DMS_MODULES_START);
|
|
82
|
+
const end = current.indexOf(DMS_MODULES_END);
|
|
83
|
+
const starts = current.split(DMS_MODULES_START).length - 1;
|
|
84
|
+
const ends = current.split(DMS_MODULES_END).length - 1;
|
|
85
|
+
if (starts === 0 && ends === 0) return current;
|
|
86
|
+
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.");
|
|
87
|
+
return `${current.slice(0, start)}${modulesBlock()}${current.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/guardrails/docs-compat.ts
|
|
91
|
+
const DOCS_COMPAT_START = "<!-- antelopejs-docs-compat:start -->";
|
|
92
|
+
const DOCS_COMPAT_END = "<!-- antelopejs-docs-compat:end -->";
|
|
93
|
+
const DOCS_NODE_START = "<!-- antelopejs-docs-node:start -->";
|
|
94
|
+
const DOCS_NODE_END = "<!-- antelopejs-docs-node:end -->";
|
|
95
|
+
const LOCKFILE = "pnpm-lock.yaml";
|
|
96
|
+
const REQUIREMENTS_HEADING = /^##\s+Requirements\s*$/i;
|
|
97
|
+
const SCOPE = "@antelopejs/";
|
|
98
|
+
const UNRESOLVED = "—";
|
|
99
|
+
const WORKSPACE = "workspace";
|
|
100
|
+
const LEGACY_MARKER = /^<!--\s*docs-compat:\s*\.\/package\.json#\w+\s*-->\s*$/;
|
|
101
|
+
const COMPATIBILITY_HEADING = /^##\s+Compatibility\s*$/i;
|
|
102
|
+
const RESOLVED_SECTIONS = [
|
|
103
|
+
"dependencies",
|
|
104
|
+
"optionalDependencies",
|
|
105
|
+
"devDependencies"
|
|
106
|
+
];
|
|
107
|
+
/** The generated block, rows sorted by package name, formatted as oxfmt leaves it. */
|
|
108
|
+
function compatBlock(rows) {
|
|
109
|
+
const sorted = [...rows].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
110
|
+
return [
|
|
111
|
+
DOCS_COMPAT_START,
|
|
112
|
+
"",
|
|
113
|
+
...tableLines([[
|
|
114
|
+
"Package",
|
|
115
|
+
"Supported",
|
|
116
|
+
"Tested with"
|
|
117
|
+
], ...sorted.map(({ name, supported, tested }) => [
|
|
118
|
+
`\`${name}\``,
|
|
119
|
+
`\`${supported.replaceAll("|", "\\|")}\``,
|
|
120
|
+
tested === void 0 ? UNRESOLVED : `\`${tested}\``
|
|
121
|
+
])]),
|
|
122
|
+
"",
|
|
123
|
+
DOCS_COMPAT_END,
|
|
124
|
+
""
|
|
125
|
+
].join("\n");
|
|
126
|
+
}
|
|
127
|
+
function legacySpanEnd(lines, marker) {
|
|
128
|
+
let index = marker + 1;
|
|
129
|
+
while (index < lines.length && !lines[index].trim()) index++;
|
|
130
|
+
while (index < lines.length && lines[index].trimStart().startsWith("|")) index++;
|
|
131
|
+
while (index < lines.length && !lines[index].trim()) index++;
|
|
132
|
+
return index;
|
|
133
|
+
}
|
|
134
|
+
function replaceLegacyTables(lines, block) {
|
|
135
|
+
const placed = [];
|
|
136
|
+
let replaced = false;
|
|
137
|
+
for (let index = 0; index < lines.length;) {
|
|
138
|
+
if (!LEGACY_MARKER.test(lines[index])) {
|
|
139
|
+
placed.push(lines[index]);
|
|
140
|
+
index++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (!replaced) placed.push(...block.split("\n"));
|
|
144
|
+
replaced = true;
|
|
145
|
+
index = legacySpanEnd(lines, index);
|
|
146
|
+
}
|
|
147
|
+
return replaced ? placed : void 0;
|
|
148
|
+
}
|
|
149
|
+
function finalNewline(text) {
|
|
150
|
+
return text.endsWith("\n") ? text : `${text}\n`;
|
|
151
|
+
}
|
|
152
|
+
/** The README with the block in place: replacing the markers, a legacy `docs-compat` table, or under `## Compatibility`. */
|
|
153
|
+
function placeCompatBlock(current, block) {
|
|
154
|
+
const text = current ?? "";
|
|
155
|
+
const start = text.indexOf(DOCS_COMPAT_START);
|
|
156
|
+
const end = text.indexOf(DOCS_COMPAT_END);
|
|
157
|
+
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-compat markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
158
|
+
if (start !== -1) return `${text.slice(0, start)}${block}${text.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
159
|
+
const lines = text.split("\n");
|
|
160
|
+
const legacy = replaceLegacyTables(lines, block);
|
|
161
|
+
if (legacy) return finalNewline(legacy.join("\n"));
|
|
162
|
+
const heading = lines.findIndex((line) => COMPATIBILITY_HEADING.test(line));
|
|
163
|
+
if (heading !== -1) {
|
|
164
|
+
let rest = heading + 1;
|
|
165
|
+
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
166
|
+
return finalNewline([
|
|
167
|
+
...lines.slice(0, heading + 1),
|
|
168
|
+
"",
|
|
169
|
+
...block.split("\n"),
|
|
170
|
+
...lines.slice(rest)
|
|
171
|
+
].join("\n"));
|
|
172
|
+
}
|
|
173
|
+
const before = text.trimEnd();
|
|
174
|
+
return `${before}${before ? "\n\n" : ""}## Compatibility\n\n${block}`;
|
|
175
|
+
}
|
|
176
|
+
/** The generated Node prerequisite block for an `engines.node` range, formatted as oxfmt leaves it. */
|
|
177
|
+
function nodeBlock(range) {
|
|
178
|
+
return `${DOCS_NODE_START}\n\nThis package requires Node.js \`${range}\`.\n${DOCS_NODE_END}\n`;
|
|
179
|
+
}
|
|
180
|
+
/** The README with the Node block in place: between its markers, under `## Requirements`, or in a new `## Requirements` section at the end. */
|
|
181
|
+
function placeNodeBlock(current, block) {
|
|
182
|
+
const start = current.indexOf(DOCS_NODE_START);
|
|
183
|
+
const end = current.indexOf(DOCS_NODE_END);
|
|
184
|
+
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-node markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
185
|
+
if (start !== -1) return `${current.slice(0, start)}${block}${current.slice(end + 33).replace(/^\r?\n/, "")}`;
|
|
186
|
+
const lines = current.split("\n");
|
|
187
|
+
const heading = lines.findIndex((line) => REQUIREMENTS_HEADING.test(line));
|
|
188
|
+
if (heading !== -1) {
|
|
189
|
+
let rest = heading + 1;
|
|
190
|
+
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
191
|
+
return finalNewline([
|
|
192
|
+
...lines.slice(0, heading + 1),
|
|
193
|
+
"",
|
|
194
|
+
...block.trimEnd().split("\n"),
|
|
195
|
+
...rest < lines.length ? ["", ...lines.slice(rest)] : []
|
|
196
|
+
].join("\n"));
|
|
197
|
+
}
|
|
198
|
+
return `${current.trimEnd()}\n\n## Requirements\n\n${block}`;
|
|
199
|
+
}
|
|
200
|
+
function relative$1(directory, name) {
|
|
201
|
+
return directory ? `${directory}/${name}` : name;
|
|
202
|
+
}
|
|
203
|
+
function isDirectory(root, path) {
|
|
204
|
+
return statSync(join(root, path), { throwIfNoEntry: false })?.isDirectory() === true;
|
|
205
|
+
}
|
|
206
|
+
function subdirectories(root, directory) {
|
|
207
|
+
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));
|
|
208
|
+
}
|
|
209
|
+
function descendants(root, directory) {
|
|
210
|
+
return subdirectories(root, directory).flatMap((child) => [child, ...descendants(root, child)]);
|
|
211
|
+
}
|
|
212
|
+
function globExpression(pattern) {
|
|
213
|
+
const source = pattern.split("/").map((segment) => segment === "**" ? "(?:.*)" : segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("*", "[^/]*").replaceAll("?", "[^/]")).join("/").replaceAll("(?:.*)/", "(?:.*/)?");
|
|
214
|
+
return new RegExp(`^${source}$`);
|
|
215
|
+
}
|
|
216
|
+
function expand(root, pattern) {
|
|
217
|
+
let directories = [""];
|
|
218
|
+
for (const segment of pattern.split("/")) if (segment === "**") directories = directories.flatMap((directory) => [directory, ...descendants(root, directory)]);
|
|
219
|
+
else if (/[*?]/.test(segment)) {
|
|
220
|
+
const expression = globExpression(segment);
|
|
221
|
+
directories = directories.flatMap((directory) => subdirectories(root, directory).filter((child) => expression.test(child.slice(child.lastIndexOf("/") + 1))));
|
|
222
|
+
} else directories = directories.map((directory) => relative$1(directory, segment)).filter((directory) => isDirectory(root, directory));
|
|
223
|
+
return directories;
|
|
224
|
+
}
|
|
225
|
+
function normalizePattern(pattern) {
|
|
226
|
+
return pattern.replace(/^(?:\.\/)+/, "").replace(/\/+$/, "").replace(/^\.$/, "");
|
|
227
|
+
}
|
|
228
|
+
function scalarItems(document, path) {
|
|
229
|
+
const node = document.getIn(path, true);
|
|
230
|
+
return isSeq(node) ? node.items.flatMap((item) => isScalar(item) ? [String(item.value)] : []) : [];
|
|
231
|
+
}
|
|
232
|
+
/** pnpm-workspace.yaml `packages`, else package.json `workspaces` as an array or as `{ packages }`; JSON parses as YAML. */
|
|
233
|
+
function workspacePatterns(root) {
|
|
234
|
+
const pnpm = join(root, "pnpm-workspace.yaml");
|
|
235
|
+
if (existsSync(pnpm)) return scalarItems(parseDocument(readFileSync(pnpm, "utf8")), ["packages"]);
|
|
236
|
+
const manifest = parseDocument(readFileSync(join(root, "package.json"), "utf8"));
|
|
237
|
+
return scalarItems(manifest, isMap(manifest.get("workspaces", true)) ? ["workspaces", "packages"] : ["workspaces"]);
|
|
238
|
+
}
|
|
239
|
+
/** The workspace package directories, relative to `root` and sorted, that `pnpm-workspace.yaml` or package.json `workspaces` list. */
|
|
240
|
+
function workspaceDirectories(root) {
|
|
241
|
+
const patterns = workspacePatterns(root);
|
|
242
|
+
const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => globExpression(normalizePattern(pattern.slice(1))));
|
|
243
|
+
const found = /* @__PURE__ */ new Set();
|
|
244
|
+
for (const pattern of patterns.filter((item) => !item.startsWith("!"))) {
|
|
245
|
+
const normalized = normalizePattern(pattern);
|
|
246
|
+
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);
|
|
247
|
+
}
|
|
248
|
+
return [...found].sort();
|
|
249
|
+
}
|
|
250
|
+
function declaredRanges(manifest) {
|
|
251
|
+
const ranges = /* @__PURE__ */ new Map();
|
|
252
|
+
for (const field of [
|
|
253
|
+
manifest.optionalDependencies,
|
|
254
|
+
manifest.dependencies,
|
|
255
|
+
manifest.peerDependencies
|
|
256
|
+
]) for (const [name, range] of Object.entries(field ?? {})) if (name.startsWith(SCOPE)) ranges.set(name, range);
|
|
257
|
+
return ranges;
|
|
258
|
+
}
|
|
259
|
+
function readManifest(root, directory) {
|
|
260
|
+
return parseManifest(readFileSync(join(root, directory, "package.json"), "utf8"));
|
|
261
|
+
}
|
|
262
|
+
/** 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. */
|
|
263
|
+
function resolvedVersion({ document, importer }, name) {
|
|
264
|
+
for (const section of RESOLVED_SECTIONS) {
|
|
265
|
+
const entry = document.getIn([
|
|
266
|
+
"importers",
|
|
267
|
+
importer,
|
|
268
|
+
section,
|
|
269
|
+
name
|
|
270
|
+
], true);
|
|
271
|
+
const version = isMap(entry) ? entry.get("version", true) : entry;
|
|
272
|
+
if (!isScalar(version)) continue;
|
|
273
|
+
const resolved = String(version.value).split("(")[0];
|
|
274
|
+
return resolved.startsWith("link:") ? WORKSPACE : resolved;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const UNSHARED_NPMRC = /^\s*shared-workspace-lockfile\s*=\s*false\s*(?:[#;].*)?$/m;
|
|
278
|
+
/** Whether the workspace keeps one root lockfile, or `shared-workspace-lockfile=false` gives each package its own. */
|
|
279
|
+
function sharesLockfile(root) {
|
|
280
|
+
const npmrc = join(root, ".npmrc");
|
|
281
|
+
if (existsSync(npmrc) && UNSHARED_NPMRC.test(readFileSync(npmrc, "utf8"))) return false;
|
|
282
|
+
const workspace = join(root, "pnpm-workspace.yaml");
|
|
283
|
+
return !(existsSync(workspace) && parseDocument(readFileSync(workspace, "utf8")).get("sharedWorkspaceLockfile") === false);
|
|
284
|
+
}
|
|
285
|
+
/** The lockfile path of a package, relative to the root. A shared lockfile is the root's, indexed by the package directory. */
|
|
286
|
+
function lockPath(shared, directory) {
|
|
287
|
+
return shared ? LOCKFILE : relative$1(directory, LOCKFILE);
|
|
288
|
+
}
|
|
289
|
+
function readLock(root, shared, directory, documents) {
|
|
290
|
+
const path = join(root, lockPath(shared, directory));
|
|
291
|
+
if (!documents.has(path) && existsSync(path)) documents.set(path, parseDocument(readFileSync(path, "utf8")));
|
|
292
|
+
const document = documents.get(path);
|
|
293
|
+
return document && {
|
|
294
|
+
document,
|
|
295
|
+
importer: shared ? directory || "." : "."
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/** Adds one package's `docs-files` lines and, when it needs one, its README with the generated blocks. */
|
|
299
|
+
function planPackage(root, plan, lock, standard, { directory, ranges, published, node }) {
|
|
300
|
+
const readme = relative$1(directory, "README.md");
|
|
301
|
+
const docs = relative$1(directory, "docs");
|
|
302
|
+
if (!published) return;
|
|
303
|
+
if (ranges.size > 0 || existsSync(join(root, readme))) plan.docsFiles.push(readme);
|
|
304
|
+
if (isDirectory(root, docs)) plan.docsFiles.push(docs);
|
|
305
|
+
const current = existsSync(join(root, readme)) ? readFileSync(join(root, readme), "utf8") : void 0;
|
|
306
|
+
const nodeRange = standard && current !== void 0 ? node : void 0;
|
|
307
|
+
if (ranges.size === 0 && current === void 0) return;
|
|
308
|
+
const rows = [...ranges].map(([name, supported]) => ({
|
|
309
|
+
name,
|
|
310
|
+
supported,
|
|
311
|
+
tested: lock && resolvedVersion(lock, name)
|
|
312
|
+
}));
|
|
313
|
+
try {
|
|
314
|
+
const withRequirements = nodeRange !== void 0 && current !== void 0 ? placeNodeBlock(current, nodeBlock(nodeRange)) : current;
|
|
315
|
+
plan.readmes.push({
|
|
316
|
+
path: readme,
|
|
317
|
+
current,
|
|
318
|
+
content: placeModulesBlock(rows.length > 0 ? placeCompatBlock(withRequirements, compatBlock(rows)) : withRequirements ?? "")
|
|
319
|
+
});
|
|
320
|
+
} catch (error) {
|
|
321
|
+
plan.errors.push(`${readme}: ${error instanceof Error ? error.message : String(error)}`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Plans the docs-compat block of the root and of every workspace package that is not private and declares an
|
|
326
|
+
* `@antelopejs/*` peer, runtime or optional dependency, and the `docs-files` lines covering the root and every workspace
|
|
327
|
+
* package that is not private.
|
|
328
|
+
* 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.
|
|
329
|
+
*/
|
|
330
|
+
function planDocs(root, manager) {
|
|
331
|
+
const rootManifest = readManifest(root, "");
|
|
332
|
+
const packages = ["", ...workspaceDirectories(root)].map((directory) => {
|
|
333
|
+
const manifest = directory ? readManifest(root, directory) : rootManifest;
|
|
334
|
+
return {
|
|
335
|
+
directory,
|
|
336
|
+
published: !directory || !manifest.private,
|
|
337
|
+
node: manifest.engines?.node,
|
|
338
|
+
ranges: manifest.private ? /* @__PURE__ */ new Map() : declaredRanges(manifest)
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
const qualifying = packages.filter(({ ranges }) => ranges.size > 0);
|
|
342
|
+
const plan = {
|
|
343
|
+
readmes: [],
|
|
344
|
+
docsFiles: [],
|
|
345
|
+
errors: [],
|
|
346
|
+
exists: (path) => existsSync(join(root, path))
|
|
347
|
+
};
|
|
348
|
+
const shared = sharesLockfile(root);
|
|
349
|
+
const documents = /* @__PURE__ */ new Map();
|
|
350
|
+
const locks = new Map(qualifying.map(({ directory }) => [directory, manager === "pnpm" ? readLock(root, shared, directory, documents) : void 0]));
|
|
351
|
+
const missing = manager === "pnpm" ? qualifying.filter(({ directory }) => !locks.get(directory)) : [];
|
|
352
|
+
if (missing.length) {
|
|
353
|
+
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.`);
|
|
354
|
+
return plan;
|
|
355
|
+
}
|
|
356
|
+
const standard = rootManifest.antelopeJs?.docs?.standard === true;
|
|
357
|
+
for (const item of packages) planPackage(root, plan, locks.get(item.directory), standard, item);
|
|
358
|
+
return plan;
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/guardrails/script-steps.ts
|
|
362
|
+
const SEPARATORS = /&&|\|\||[;|\n]|(?<![>&])&(?!&)/u;
|
|
363
|
+
const ENV_ASSIGNMENT = /^[A-Za-z_]\w*=/u;
|
|
364
|
+
const TSC_COMMAND = /(?:^|[\\/])tsc(?:\.js)?$/u;
|
|
365
|
+
const MANAGERS = /* @__PURE__ */ new Set([
|
|
366
|
+
"pnpm",
|
|
367
|
+
"npm",
|
|
368
|
+
"yarn",
|
|
369
|
+
"bun"
|
|
370
|
+
]);
|
|
371
|
+
const NPM_BUILTINS = /* @__PURE__ */ new Set([
|
|
372
|
+
"test",
|
|
373
|
+
"start",
|
|
374
|
+
"stop",
|
|
375
|
+
"restart"
|
|
376
|
+
]);
|
|
377
|
+
const WRAPPERS = /* @__PURE__ */ new Set([
|
|
378
|
+
"cross-env",
|
|
379
|
+
"cross-env-shell",
|
|
380
|
+
"env",
|
|
381
|
+
"corepack"
|
|
382
|
+
]);
|
|
383
|
+
const EXEC_RUNNERS = /* @__PURE__ */ new Set([
|
|
384
|
+
"npx",
|
|
385
|
+
"bunx",
|
|
386
|
+
"pnpx"
|
|
387
|
+
]);
|
|
388
|
+
const EXEC_VERBS = /* @__PURE__ */ new Set([
|
|
389
|
+
"exec",
|
|
390
|
+
"x",
|
|
391
|
+
"dlx"
|
|
392
|
+
]);
|
|
393
|
+
const RUN_ALL = /* @__PURE__ */ new Set([
|
|
394
|
+
"run-s",
|
|
395
|
+
"run-p",
|
|
396
|
+
"npm-run-all",
|
|
397
|
+
"npm-run-all2"
|
|
398
|
+
]);
|
|
399
|
+
const RUN_ALL_VALUED = /* @__PURE__ */ new Set(["--max-parallel", "--npm-path"]);
|
|
400
|
+
const EXEC_VALUED = /* @__PURE__ */ new Set([
|
|
401
|
+
"-p",
|
|
402
|
+
"--package",
|
|
403
|
+
"-c",
|
|
404
|
+
"--call"
|
|
405
|
+
]);
|
|
406
|
+
const DIR_OPTIONS = /* @__PURE__ */ new Set([
|
|
407
|
+
"--dir",
|
|
408
|
+
"-C",
|
|
409
|
+
"--prefix",
|
|
410
|
+
"--cwd"
|
|
411
|
+
]);
|
|
412
|
+
const SELECT_OPTIONS = /* @__PURE__ */ new Set([
|
|
413
|
+
"--filter",
|
|
414
|
+
"-F",
|
|
415
|
+
"--filter-prod",
|
|
416
|
+
"--workspace"
|
|
417
|
+
]);
|
|
418
|
+
/** Manager options that take their value as the next word and point at no package. */
|
|
419
|
+
const OTHER_VALUED = [
|
|
420
|
+
"--workspace-concurrency",
|
|
421
|
+
"--reporter",
|
|
422
|
+
"--loglevel",
|
|
423
|
+
"--test-pattern",
|
|
424
|
+
"--changed-files-ignore-pattern",
|
|
425
|
+
"--resume-from"
|
|
426
|
+
];
|
|
427
|
+
const MANAGER_VALUED = /* @__PURE__ */ new Set([
|
|
428
|
+
...DIR_OPTIONS,
|
|
429
|
+
...SELECT_OPTIONS,
|
|
430
|
+
...OTHER_VALUED
|
|
431
|
+
]);
|
|
432
|
+
const TARGET_FLAGS = /* @__PURE__ */ new Set([
|
|
433
|
+
"-r",
|
|
434
|
+
"--recursive",
|
|
435
|
+
"--workspaces",
|
|
436
|
+
"-ws"
|
|
437
|
+
]);
|
|
438
|
+
/** The package an option points at; npm's `-w` selects only where `valued` lists it, since pnpm's `-w` is the workspace root. */
|
|
439
|
+
function target(name, value, valued) {
|
|
440
|
+
if (TARGET_FLAGS.has(name)) return { kind: "all" };
|
|
441
|
+
if (value === void 0) return void 0;
|
|
442
|
+
if (DIR_OPTIONS.has(name)) return {
|
|
443
|
+
kind: "dir",
|
|
444
|
+
path: value
|
|
445
|
+
};
|
|
446
|
+
if (SELECT_OPTIONS.has(name) || name === "-w" && valued.has(name)) return {
|
|
447
|
+
kind: "select",
|
|
448
|
+
selector: value
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function words(segment) {
|
|
452
|
+
return segment.replace(/[()]/gu, " ").split(/\s+/u).map((word) => word.replace(/^["']|["']$/gu, "")).filter(Boolean);
|
|
453
|
+
}
|
|
454
|
+
/** The simple commands of a script: `&&`, `||`, `;`, `|`, `&`, newlines and parentheses all end one. */
|
|
455
|
+
function lines(script) {
|
|
456
|
+
return script.split(SEPARATORS).map(words).filter((list) => list.length > 0);
|
|
457
|
+
}
|
|
458
|
+
/** Skips the options from `from`, and the values of those that take one; `targets` are the packages they point at. */
|
|
459
|
+
function skipOptions(args, from, valued) {
|
|
460
|
+
let index = from;
|
|
461
|
+
const targets = [];
|
|
462
|
+
while (index < args.length && args[index].startsWith("-")) {
|
|
463
|
+
const [name, ...inline] = args[index].split("=");
|
|
464
|
+
const separate = valued.has(name) && inline.length === 0;
|
|
465
|
+
const pointed = target(name, separate ? args[index + 1] : inline.length ? inline.join("=") : void 0, valued);
|
|
466
|
+
if (pointed) targets.push(pointed);
|
|
467
|
+
index += separate ? 2 : 1;
|
|
468
|
+
}
|
|
469
|
+
return {
|
|
470
|
+
index,
|
|
471
|
+
targets
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function isTsc(word) {
|
|
475
|
+
return TSC_COMMAND.test(word);
|
|
476
|
+
}
|
|
477
|
+
/** `tsc`, a path to it, or `node` running one. */
|
|
478
|
+
function programSteps(line) {
|
|
479
|
+
const [head, ...rest] = line;
|
|
480
|
+
if (head === void 0) return [];
|
|
481
|
+
if (isTsc(head)) return [{
|
|
482
|
+
kind: "tsc",
|
|
483
|
+
args: rest,
|
|
484
|
+
targets: []
|
|
485
|
+
}];
|
|
486
|
+
if (head !== "node") return [];
|
|
487
|
+
if (rest[0] === "--run" && rest[1] !== void 0) return [{
|
|
488
|
+
kind: "script",
|
|
489
|
+
names: [rest[1]],
|
|
490
|
+
targets: []
|
|
491
|
+
}];
|
|
492
|
+
const at = rest.findIndex((word) => !word.startsWith("-"));
|
|
493
|
+
return at !== -1 && isTsc(rest[at]) ? [{
|
|
494
|
+
kind: "tsc",
|
|
495
|
+
args: rest.slice(at + 1),
|
|
496
|
+
targets: []
|
|
497
|
+
}] : [];
|
|
498
|
+
}
|
|
499
|
+
/** What `npx`, `pnpm exec` and `npm exec` run: the command after the options and the packages they name. */
|
|
500
|
+
function execSteps(args) {
|
|
501
|
+
return programSteps(args.slice(skipOptions(args, 0, EXEC_VALUED).index));
|
|
502
|
+
}
|
|
503
|
+
/** The steps with `targets` added, for a command the manager runs in other packages. */
|
|
504
|
+
function pointedAt(steps, targets) {
|
|
505
|
+
return steps.map((step) => step.kind === "cd" ? step : {
|
|
506
|
+
...step,
|
|
507
|
+
targets: [...targets, ...step.targets]
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/** The packages npm options after the script name point at, up to `--`: npm reads its options anywhere on the line. */
|
|
511
|
+
function trailingTargets(args, from, valued) {
|
|
512
|
+
const targets = [];
|
|
513
|
+
for (let index = from; index < args.length && args[index] !== "--"; index++) if (args[index].startsWith("-")) {
|
|
514
|
+
const found = skipOptions(args, index, valued);
|
|
515
|
+
targets.push(...found.targets);
|
|
516
|
+
index = found.index - 1;
|
|
517
|
+
}
|
|
518
|
+
return targets;
|
|
519
|
+
}
|
|
520
|
+
function managerSteps(manager, args) {
|
|
521
|
+
const valued = new Set(MANAGER_VALUED);
|
|
522
|
+
if (manager === "npm") valued.add("-w");
|
|
523
|
+
const first = skipOptions(args, 0, valued);
|
|
524
|
+
const verb = args[first.index];
|
|
525
|
+
if (verb === void 0) return [];
|
|
526
|
+
if (EXEC_VERBS.has(verb)) return pointedAt(execSteps(args.slice(first.index + 1)), first.targets);
|
|
527
|
+
if (isTsc(verb)) return pointedAt(programSteps(args.slice(first.index)), first.targets);
|
|
528
|
+
const run = verb === "run" || verb === "run-script";
|
|
529
|
+
const second = run ? skipOptions(args, first.index + 1, valued) : {
|
|
530
|
+
index: first.index,
|
|
531
|
+
targets: []
|
|
532
|
+
};
|
|
533
|
+
const name = args[second.index];
|
|
534
|
+
if (name === void 0 || !run && manager === "npm" && !NPM_BUILTINS.has(verb)) return [];
|
|
535
|
+
const trailing = manager === "npm" ? trailingTargets(args, second.index + 1, valued) : [];
|
|
536
|
+
return [{
|
|
537
|
+
kind: "script",
|
|
538
|
+
names: [name],
|
|
539
|
+
targets: [
|
|
540
|
+
...first.targets,
|
|
541
|
+
...second.targets,
|
|
542
|
+
...trailing
|
|
543
|
+
]
|
|
544
|
+
}];
|
|
545
|
+
}
|
|
546
|
+
function runAllSteps(args) {
|
|
547
|
+
const names = [];
|
|
548
|
+
for (let index = 0; index < args.length && args[index] !== "--"; index++) if (!args[index].startsWith("-")) names.push(args[index]);
|
|
549
|
+
else if (RUN_ALL_VALUED.has(args[index])) index++;
|
|
550
|
+
return names.length === 0 ? [] : [{
|
|
551
|
+
kind: "script",
|
|
552
|
+
names,
|
|
553
|
+
targets: []
|
|
554
|
+
}];
|
|
555
|
+
}
|
|
556
|
+
/** The line without its leading environment assignments and wrappers (`cross-env A=1`, `env`, `corepack`). */
|
|
557
|
+
function unwrapped(line) {
|
|
558
|
+
let index = 0;
|
|
559
|
+
let wrapped = false;
|
|
560
|
+
while (index < line.length) {
|
|
561
|
+
const word = line[index];
|
|
562
|
+
if (WRAPPERS.has(word)) wrapped = true;
|
|
563
|
+
else if (!ENV_ASSIGNMENT.test(word) && !(wrapped && word.startsWith("-"))) break;
|
|
564
|
+
index++;
|
|
565
|
+
}
|
|
566
|
+
return line.slice(index);
|
|
567
|
+
}
|
|
568
|
+
function lineSteps(line) {
|
|
569
|
+
const [head, ...args] = unwrapped(line);
|
|
570
|
+
if (head === void 0) return [];
|
|
571
|
+
if (head === "cd") return [{
|
|
572
|
+
kind: "cd",
|
|
573
|
+
path: args[0] ?? "~"
|
|
574
|
+
}];
|
|
575
|
+
if (RUN_ALL.has(head)) return runAllSteps(args);
|
|
576
|
+
if (MANAGERS.has(head)) return managerSteps(head, args);
|
|
577
|
+
if (EXEC_RUNNERS.has(head)) return execSteps(args);
|
|
578
|
+
return programSteps([head, ...args]);
|
|
579
|
+
}
|
|
580
|
+
/** The scripts and `tsc` runs a script's command lines start. */
|
|
581
|
+
function stepsOf(script) {
|
|
582
|
+
return lines(script).flatMap(lineSteps);
|
|
583
|
+
}
|
|
584
|
+
/** The script names a `run-s` pattern list selects among `available`. */
|
|
585
|
+
function matchingScripts(names, available) {
|
|
586
|
+
const all = [...available];
|
|
587
|
+
return names.flatMap((name) => {
|
|
588
|
+
if (!name.includes("*")) return [name];
|
|
589
|
+
const pattern = new RegExp(`^${name.split("**").map((part) => part.split("*").map((piece) => piece.replace(/[.+?^${}()|[\]\\]/gu, "\\$&")).join("[^:]*")).join(".*")}$`, "u");
|
|
590
|
+
return all.filter((script) => pattern.test(script));
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
//#endregion
|
|
594
|
+
export { workspaceDirectories as i, stepsOf as n, planDocs as r, matchingScripts as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as parseManifest } from "./package-DxxcxOzp.mjs";
|
|
2
2
|
import { u as trackedManifests } from "./files-DJ0TeaTU.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|