@antelopejs/tooling-configs 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/dist/bin/api-diff.mjs +3 -3
- package/dist/bin/body-check.mjs +1 -1
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +2 -890
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/garden.mjs +221 -215
- package/dist/bin/lease.mjs +1 -1
- package/dist/bin/ratchet.mjs +3 -3
- package/dist/bin/suppressions.mjs +3 -3
- package/dist/bin/sync.mjs +477 -40
- package/dist/checks-BFGuy1KI.mjs +1506 -0
- package/dist/oxc/lint.mjs +1 -1
- package/dist/{package-DxxcxOzp.mjs → package-DiaBP7bI.mjs} +50 -26
- package/dist/{proof-stamp-D9yo2dxU.mjs → proof-stamp-BPIdT5ik.mjs} +2 -2
- package/dist/{ratchet--WWa_w2O.mjs → ratchet-BZvlFCWL.mjs} +2 -2
- package/dist/{suppression-base-Drnl6Y7F.mjs → suppression-base-DZgUDXiI.mjs} +2 -2
- package/dist/{suppression-budget-Dvb_IqBo.mjs → suppression-budget-DgYdu6JK.mjs} +1 -1
- package/dist/{suppressions-BroaaGJ_.mjs → suppressions-CQTcKCi1.mjs} +1 -1
- package/dist/{templates-BiXgdsRN.mjs → templates-C6cfOd2H.mjs} +1 -1
- package/dist/{typescript-D7SaSmsl.mjs → typescript-DJzdex32.mjs} +1 -1
- package/dist/{workflow-B0FmthGv.mjs → workflow-CPcNc8KL.mjs} +5 -2
- package/package.json +1 -1
- package/dist/script-steps-CgH2DSsp.mjs +0 -594
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
3
|
import { c as repositoryRoot, r as changedFiles } from "../files-DJ0TeaTU.mjs";
|
|
4
4
|
import { n as unusedDirectives } from "../oxlint-BbpTFFmf.mjs";
|
|
5
|
-
import { c as stagedSuppressions, i as checkSuppressions, l as checkPolicy, s as stagedNames } from "../suppression-budget-
|
|
6
|
-
import { c as suppressionsIn, i as inWorktree } from "../suppressions-
|
|
7
|
-
import { n as suppressionBase, t as raisedCeilings } from "../suppression-base-
|
|
5
|
+
import { c as stagedSuppressions, i as checkSuppressions, l as checkPolicy, s as stagedNames } from "../suppression-budget-DgYdu6JK.mjs";
|
|
6
|
+
import { c as suppressionsIn, i as inWorktree } from "../suppressions-CQTcKCi1.mjs";
|
|
7
|
+
import { n as suppressionBase, t as raisedCeilings } from "../suppression-base-DZgUDXiI.mjs";
|
|
8
8
|
import { readdirSync } from "node:fs";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import { execFileSync, spawnSync } from "node:child_process";
|
package/dist/bin/sync.mjs
CHANGED
|
@@ -1,21 +1,92 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { a as formatCeilings, l as readCeilings, s as isRetired, t as CEILINGS_FILE } from "../ceilings-B7KayYIG.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { t as admits } from "../semver-BDxeEcP_.mjs";
|
|
4
|
+
import { a as managedPackage, c as repositoryTools, d as toolingVersions, f as usesNuxt, l as serializeManifest, n as bootstrapDependencies, o as packageManager, r as bootstrappedManifest, s as parseManifest, t as addedDevDependencies, u as templatePackage } from "../package-DiaBP7bI.mjs";
|
|
5
|
+
import { i as presetConfig, n as SETUP_SCRIPT, r as lefthook, t as PRESET_CONFIGS } from "../templates-C6cfOd2H.mjs";
|
|
5
6
|
import { a as VERIFY_KINDS, c as isVerifyKind, i as SYNCED_SKILL_FILES, l as skillFolder, o as claudeLink, s as claudeLinkTarget, u as planDocsSkills } from "../shared-igPpEDpS.mjs";
|
|
6
7
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
7
|
-
import { c as CI_CONTEXT, f as ciWorkflow, i as hasChecksWorkflow, n as ciNodeCallers, p as placeholderTestScript, r as ciRenovateSyncCallers, s as renovateArtifacts, t as MISSING_CHECKS_WORKFLOW, u as CI_PATH } from "../workflow-
|
|
8
|
+
import { c as CI_CONTEXT, f as ciWorkflow, i as hasChecksWorkflow, n as ciNodeCallers, p as placeholderTestScript, r as ciRenovateSyncCallers, s as renovateArtifacts, t as MISSING_CHECKS_WORKFLOW, u as CI_PATH } from "../workflow-CPcNc8KL.mjs";
|
|
8
9
|
import { a as gitFiles, c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
9
|
-
import { i as recordedRelease, t as measureBaseline } from "../ratchet
|
|
10
|
-
import { n as
|
|
11
|
-
import { n as
|
|
10
|
+
import { i as recordedRelease, t as measureBaseline } from "../ratchet-BZvlFCWL.mjs";
|
|
11
|
+
import { a as stepsOf, i as matchingScripts, n as droppedChecksSteps, o as planDocs, s as workspaceDirectories } from "../checks-BFGuy1KI.mjs";
|
|
12
|
+
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-DgYdu6JK.mjs";
|
|
13
|
+
import { u as typescript } from "../suppressions-CQTcKCi1.mjs";
|
|
12
14
|
import { t as DEFAULT_SHARED } from "../map-DRyYz_Fw.mjs";
|
|
13
15
|
import { createRequire } from "node:module";
|
|
14
16
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
15
17
|
import { basename, dirname, join, posix, resolve } from "node:path";
|
|
16
18
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
19
|
+
import { isMap, isScalar, parseDocument } from "yaml";
|
|
17
20
|
import ts from "typescript";
|
|
18
21
|
import { parseArgs } from "node:util";
|
|
22
|
+
//#region src/guardrails/docs-typescript.ts
|
|
23
|
+
const MARKDOWN = /\.(?:md|mdc)$/i;
|
|
24
|
+
const UNPUBLISHED_FOLDER = "design";
|
|
25
|
+
const UNPUBLISHED_FILE = /grill.*\.md$/;
|
|
26
|
+
const FENCE = /^[\s>]*(`{3,}|~{3,})\s*([^\s[{`]*)(.*)$/;
|
|
27
|
+
const TYPESCRIPT_LANGUAGES = /* @__PURE__ */ new Set([
|
|
28
|
+
"ts",
|
|
29
|
+
"typescript",
|
|
30
|
+
"tsx",
|
|
31
|
+
"mts",
|
|
32
|
+
"cts"
|
|
33
|
+
]);
|
|
34
|
+
const FRAGMENT = "fragment";
|
|
35
|
+
const DOCS_API = /<!--\s*docs-api:/;
|
|
36
|
+
/** Whether one fence opener is a TypeScript fence the docs check typechecks: a TypeScript language not flagged `fragment`. */
|
|
37
|
+
function checkedFence(language, info) {
|
|
38
|
+
if (!TYPESCRIPT_LANGUAGES.has(language.toLowerCase())) return false;
|
|
39
|
+
return !info.replace(/\[[^\]]*\]|\{[^}]*\}/g, " ").split(/\s+/).includes(FRAGMENT);
|
|
40
|
+
}
|
|
41
|
+
/** Whether a Markdown file needs a tsconfig in the docs check: it holds a checked TypeScript fence or a `docs-api` page. */
|
|
42
|
+
function typed(text) {
|
|
43
|
+
if (DOCS_API.test(text)) return true;
|
|
44
|
+
let open;
|
|
45
|
+
for (const line of text.split(/\r?\n/)) {
|
|
46
|
+
const fence = FENCE.exec(line);
|
|
47
|
+
if (!fence) continue;
|
|
48
|
+
const [, marker, language, info] = fence;
|
|
49
|
+
if (open === void 0) {
|
|
50
|
+
open = marker;
|
|
51
|
+
if (checkedFence(language, info)) return true;
|
|
52
|
+
} else if (marker.startsWith(open) && language === "" && info.trim() === "") open = void 0;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
/** The Markdown files a `docs-files` entry selects, as the docs check walks it. */
|
|
57
|
+
function markdownFiles(root, path, base = path) {
|
|
58
|
+
const absolute = join(root, path);
|
|
59
|
+
const stat = statSync(absolute, { throwIfNoEntry: false });
|
|
60
|
+
if (!stat) return [];
|
|
61
|
+
if (!stat.isDirectory()) return MARKDOWN.test(path) ? [path] : [];
|
|
62
|
+
return readdirSync(absolute).flatMap((name) => `${path}/${name}` === `${base}/${UNPUBLISHED_FOLDER}` || UNPUBLISHED_FILE.test(name) ? [] : markdownFiles(root, `${path}/${name}`, base));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The docs files, relative to `root`, that hold TypeScript fences or `docs-api`
|
|
66
|
+
* pages the docs check typechecks, under a CI caller job that lists them in
|
|
67
|
+
* `docs-files` but sets no `docs-typescript-project`.
|
|
68
|
+
*/
|
|
69
|
+
function untypedDocsFiles(root) {
|
|
70
|
+
const path = join(root, CI_PATH);
|
|
71
|
+
if (!existsSync(path)) return [];
|
|
72
|
+
const jobs = parseDocument(readFileSync(path, "utf8")).get("jobs", true);
|
|
73
|
+
if (!isMap(jobs)) return [];
|
|
74
|
+
const found = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const { value: job } of jobs.items) {
|
|
76
|
+
const inputs = isMap(job) ? job.get("with", true) : void 0;
|
|
77
|
+
if (!isMap(inputs)) continue;
|
|
78
|
+
const project = inputs.get("docs-typescript-project", true);
|
|
79
|
+
const files = inputs.get("docs-files", true);
|
|
80
|
+
if (isScalar(project) && String(project.value).trim() || !isScalar(files)) continue;
|
|
81
|
+
for (const entry of String(files.value).split("\n")) {
|
|
82
|
+
const trimmed = entry.trim().replace(/\/+$/, "");
|
|
83
|
+
if (!trimmed) continue;
|
|
84
|
+
for (const file of markdownFiles(root, trimmed)) if (typed(readFileSync(join(root, file), "utf8"))) found.add(file);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return [...found];
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
19
90
|
//#region src/guardrails/agents-block.ts
|
|
20
91
|
const AGENTS_BLOCK_START = "<!-- antelopejs-guardrails:start -->";
|
|
21
92
|
const AGENTS_BLOCK_END = "<!-- antelopejs-guardrails:end -->";
|
|
@@ -185,6 +256,63 @@ function agentsBlock(context) {
|
|
|
185
256
|
].join("\n");
|
|
186
257
|
}
|
|
187
258
|
//#endregion
|
|
259
|
+
//#region src/guardrails/pnpm-workspace.ts
|
|
260
|
+
const PATH = "pnpm-workspace.yaml";
|
|
261
|
+
/** Whether the pinned pnpm reads settings from a `pnpm-workspace.yaml` without `packages`, which pnpm before 10.5 rejects. An unpinned pnpm counts as current. */
|
|
262
|
+
function readsSettings(manifest) {
|
|
263
|
+
const pinned = manifest.packageManager?.split("@")[1];
|
|
264
|
+
return pinned === void 0 || admits(">=10.5.0", pinned);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* `current` with `allowBuilds.lefthook` set to `false` unless the repository already decides it.
|
|
268
|
+
* pnpm 11 fails an install on a dependency build it was not told about, and the synced `prepare` script runs `lefthook install` itself.
|
|
269
|
+
*/
|
|
270
|
+
function withLefthookDecided(current = "") {
|
|
271
|
+
const document = parseDocument(current);
|
|
272
|
+
if (document.errors.length) throw new Error(`${PATH}: ${document.errors.map(({ message }) => message).join("; ")}`);
|
|
273
|
+
if (document.toJS() == null) {
|
|
274
|
+
const kept = current.trimStart();
|
|
275
|
+
return `${kept}${kept === "" || kept.endsWith("\n") ? "" : "\n"}allowBuilds:\n lefthook: false\n`;
|
|
276
|
+
}
|
|
277
|
+
if (!isMap(document.contents)) throw new Error(`${PATH} must contain a YAML mapping.`);
|
|
278
|
+
if (document.get("allowBuilds") == null) document.set("allowBuilds", document.createNode({}));
|
|
279
|
+
const builds = document.get("allowBuilds");
|
|
280
|
+
if (!isMap(builds)) throw new Error(`${PATH}: allowBuilds must be a mapping.`);
|
|
281
|
+
if (builds.get("lefthook") != null) return current;
|
|
282
|
+
document.contents.flow = false;
|
|
283
|
+
builds.flow = false;
|
|
284
|
+
builds.set("lefthook", false);
|
|
285
|
+
return document.toString({
|
|
286
|
+
lineWidth: 0,
|
|
287
|
+
flowCollectionPadding: false
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/** The `pnpm-workspace.yaml` a full-profile pnpm repository needs so pnpm 11 and later install lefthook without `ERR_PNPM_IGNORED_BUILDS`. */
|
|
291
|
+
function pnpmWorkspaceArtifacts(root, manifest, managed) {
|
|
292
|
+
if (!managed || packageManager(manifest) !== "pnpm") return [];
|
|
293
|
+
const file = join(root, PATH);
|
|
294
|
+
const current = existsSync(file) ? readFileSync(file, "utf8") : void 0;
|
|
295
|
+
if (current === void 0 && !readsSettings(manifest)) return [];
|
|
296
|
+
try {
|
|
297
|
+
const content = withLefthookDecided(current);
|
|
298
|
+
return [content === current ? {
|
|
299
|
+
kind: "unchanged",
|
|
300
|
+
path: PATH
|
|
301
|
+
} : {
|
|
302
|
+
kind: "write",
|
|
303
|
+
path: PATH,
|
|
304
|
+
content,
|
|
305
|
+
mode: void 0
|
|
306
|
+
}];
|
|
307
|
+
} catch (error) {
|
|
308
|
+
return [{
|
|
309
|
+
kind: "error",
|
|
310
|
+
path: PATH,
|
|
311
|
+
message: `${error instanceof Error ? error.message : String(error)} Add \`allowBuilds: { lefthook: false }\` to it, then rerun antelopejs-sync.`
|
|
312
|
+
}];
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
//#endregion
|
|
188
316
|
//#region src/guardrails/backend-boundary.ts
|
|
189
317
|
/** Where a DMS frontend layer keeps its backend boundary plugin, relative to the layer. */
|
|
190
318
|
const BACKEND_BOUNDARY_FILE = "build/backend-boundary.ts";
|
|
@@ -1191,10 +1319,13 @@ const MANAGED_ARTIFACTS = [
|
|
|
1191
1319
|
{
|
|
1192
1320
|
path: "package.json",
|
|
1193
1321
|
profiles: ["full", "template"],
|
|
1194
|
-
desired: (current, context) =>
|
|
1195
|
-
content
|
|
1196
|
-
|
|
1197
|
-
|
|
1322
|
+
desired: (current, context) => {
|
|
1323
|
+
const content = context.profile === "full" ? managedPackage(current, context.versions, context) : templatePackage(current, context.versions, context);
|
|
1324
|
+
return {
|
|
1325
|
+
content,
|
|
1326
|
+
notes: droppedChecksSteps(current, content)
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1198
1329
|
},
|
|
1199
1330
|
{
|
|
1200
1331
|
path: ".nvmrc",
|
|
@@ -1338,7 +1469,7 @@ function repositoryContext(root, current, profile, verificationSkill) {
|
|
|
1338
1469
|
versions: toolingVersions(),
|
|
1339
1470
|
tools: repositoryTools(manifest),
|
|
1340
1471
|
typeAware: /\btypeAware["']?\s*:\s*true\b/.test(desiredLint),
|
|
1341
|
-
nuxt:
|
|
1472
|
+
nuxt: usesNuxt(root, manifest),
|
|
1342
1473
|
claude: profile === "full" ? claudeProse(root, current) : "",
|
|
1343
1474
|
baseline: "",
|
|
1344
1475
|
suppressionBudget: adoptedBudget(root, current.get(SUPPRESSIONS_FILE)),
|
|
@@ -1383,7 +1514,11 @@ function syncRepository(root, options = {}) {
|
|
|
1383
1514
|
const writing = planWritingSkills(root, profile, verify.kind);
|
|
1384
1515
|
const actions = [...verify.actions, ...writing.actions];
|
|
1385
1516
|
const context = repositoryContext(root, current, profile, verify.verificationSkill);
|
|
1386
|
-
const standalone = [
|
|
1517
|
+
const standalone = [
|
|
1518
|
+
...backendBoundaryArtifacts(root),
|
|
1519
|
+
...renovateArtifacts(root, manifest, profile === "full" || verify.kind === "template"),
|
|
1520
|
+
...pnpmWorkspaceArtifacts(root, manifest, profile === "full")
|
|
1521
|
+
];
|
|
1387
1522
|
let plan = [...planSync(current, modes, context), ...standalone];
|
|
1388
1523
|
const errors = plan.filter((artifact) => artifact.kind === "error").map(({ message }) => message);
|
|
1389
1524
|
const entryOnly = checkEntryOnlyConfiguration(root);
|
|
@@ -1423,6 +1558,224 @@ function syncRepository(root, options = {}) {
|
|
|
1423
1558
|
};
|
|
1424
1559
|
}
|
|
1425
1560
|
//#endregion
|
|
1561
|
+
//#region src/guardrails/workspace-members.ts
|
|
1562
|
+
/** Each oxlint `options` key, which oxlint reads only from the root config, and the flag that carries it on a member's own oxlint run. */
|
|
1563
|
+
const OPTION_FLAGS = /* @__PURE__ */ new Map([
|
|
1564
|
+
["typeAware", {
|
|
1565
|
+
kind: "switch",
|
|
1566
|
+
flag: "--type-aware"
|
|
1567
|
+
}],
|
|
1568
|
+
["typeCheck", {
|
|
1569
|
+
kind: "switch",
|
|
1570
|
+
flag: "--type-check"
|
|
1571
|
+
}],
|
|
1572
|
+
["denyWarnings", {
|
|
1573
|
+
kind: "switch",
|
|
1574
|
+
flag: "--deny-warnings"
|
|
1575
|
+
}],
|
|
1576
|
+
["maxWarnings", {
|
|
1577
|
+
kind: "count",
|
|
1578
|
+
flag: "--max-warnings"
|
|
1579
|
+
}],
|
|
1580
|
+
["reportUnusedDisableDirectives", {
|
|
1581
|
+
kind: "severity",
|
|
1582
|
+
flag: "--report-unused-disable-directives-severity"
|
|
1583
|
+
}]
|
|
1584
|
+
]);
|
|
1585
|
+
/** The oxlint config names oxlint discovers in a nested directory. */
|
|
1586
|
+
const LINT_CONFIGS = [
|
|
1587
|
+
"oxlint.config.ts",
|
|
1588
|
+
"oxlint.config.mts",
|
|
1589
|
+
"oxlint.config.cts",
|
|
1590
|
+
"oxlint.config.js",
|
|
1591
|
+
"oxlint.config.mjs",
|
|
1592
|
+
"oxlint.config.cjs",
|
|
1593
|
+
".oxlintrc.json",
|
|
1594
|
+
".oxlintrc.jsonc"
|
|
1595
|
+
];
|
|
1596
|
+
/** A command word `oxlint` in a script, not `oxlint-tsgolint` or a path ending in it. */
|
|
1597
|
+
const OXLINT_COMMAND = /(^|[\s;&|(])oxlint(?=$|[\s;&|)])/g;
|
|
1598
|
+
function unwrapped(node) {
|
|
1599
|
+
const compiler = typescript();
|
|
1600
|
+
let current = node;
|
|
1601
|
+
while (compiler.isParenthesizedExpression(current) || compiler.isAsExpression(current) || compiler.isSatisfiesExpression(current)) current = current.expression;
|
|
1602
|
+
return current;
|
|
1603
|
+
}
|
|
1604
|
+
function variableInitializer(source, name) {
|
|
1605
|
+
const compiler = typescript();
|
|
1606
|
+
for (const statement of source.statements) if (compiler.isVariableStatement(statement)) {
|
|
1607
|
+
for (const declaration of statement.declarationList.declarations) if (compiler.isIdentifier(declaration.name) && declaration.name.text === name) return declaration.initializer;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
/** The object literal a config exports: itself, the first argument of `defineConfig(...)`, or a same-file variable holding either. */
|
|
1611
|
+
function configLiteral(source, node, seen = /* @__PURE__ */ new Set()) {
|
|
1612
|
+
const compiler = typescript();
|
|
1613
|
+
if (node === void 0) return void 0;
|
|
1614
|
+
const value = unwrapped(node);
|
|
1615
|
+
if (compiler.isObjectLiteralExpression(value)) return value;
|
|
1616
|
+
if (compiler.isCallExpression(value)) return configLiteral(source, value.arguments[0], seen);
|
|
1617
|
+
if (!compiler.isIdentifier(value) || seen.has(value.text)) return void 0;
|
|
1618
|
+
seen.add(value.text);
|
|
1619
|
+
return configLiteral(source, variableInitializer(source, value.text), seen);
|
|
1620
|
+
}
|
|
1621
|
+
function exportedConfig(path, text) {
|
|
1622
|
+
const compiler = typescript();
|
|
1623
|
+
if (path.endsWith(".json") || path.endsWith(".jsonc")) {
|
|
1624
|
+
const source = compiler.parseJsonText(path, text);
|
|
1625
|
+
const [statement] = source.statements;
|
|
1626
|
+
return statement && configLiteral(source, statement.expression);
|
|
1627
|
+
}
|
|
1628
|
+
const source = compiler.createSourceFile(path, text, compiler.ScriptTarget.Latest, true);
|
|
1629
|
+
return configLiteral(source, source.statements.find((statement) => compiler.isExportAssignment(statement) && !statement.isExportEquals)?.expression);
|
|
1630
|
+
}
|
|
1631
|
+
function propertyName(element) {
|
|
1632
|
+
const compiler = typescript();
|
|
1633
|
+
const name = element.name;
|
|
1634
|
+
return name !== void 0 && (compiler.isIdentifier(name) || compiler.isStringLiteralLike(name)) ? name.text : void 0;
|
|
1635
|
+
}
|
|
1636
|
+
/** The flag that carries one option value, `""` for a switch set to `false`, or undefined when the value has no flag. */
|
|
1637
|
+
function optionFlag(entry, value) {
|
|
1638
|
+
const compiler = typescript();
|
|
1639
|
+
switch (entry.kind) {
|
|
1640
|
+
case "switch":
|
|
1641
|
+
if (value.kind === compiler.SyntaxKind.TrueKeyword) return entry.flag;
|
|
1642
|
+
return value.kind === compiler.SyntaxKind.FalseKeyword ? "" : void 0;
|
|
1643
|
+
case "count": return compiler.isNumericLiteral(value) ? `${entry.flag}=${value.text}` : void 0;
|
|
1644
|
+
case "severity": return compiler.isStringLiteralLike(value) ? `${entry.flag}=${value.text}` : void 0;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
/** The flags an `options` literal stands for, or the keys no flag can carry. */
|
|
1648
|
+
function optionFlags(options) {
|
|
1649
|
+
const compiler = typescript();
|
|
1650
|
+
const literal = unwrapped(options);
|
|
1651
|
+
if (!compiler.isObjectLiteralExpression(literal)) return { unsupported: ["options"] };
|
|
1652
|
+
const flags = [];
|
|
1653
|
+
const unsupported = [];
|
|
1654
|
+
for (const element of literal.properties) {
|
|
1655
|
+
const name = propertyName(element) ?? element.getText();
|
|
1656
|
+
const entry = OPTION_FLAGS.get(name);
|
|
1657
|
+
const flag = entry && compiler.isPropertyAssignment(element) ? optionFlag(entry, unwrapped(element.initializer)) : void 0;
|
|
1658
|
+
if (flag === void 0) unsupported.push(name);
|
|
1659
|
+
else if (flag) flags.push(flag);
|
|
1660
|
+
}
|
|
1661
|
+
return unsupported.length ? { unsupported } : { flags };
|
|
1662
|
+
}
|
|
1663
|
+
/** `text` without `property`, its separating comma and the line it sat on. */
|
|
1664
|
+
function withoutProperty(text, config, property) {
|
|
1665
|
+
const elements = config.properties;
|
|
1666
|
+
const index = elements.indexOf(property);
|
|
1667
|
+
const next = elements[index + 1];
|
|
1668
|
+
const previous = elements[index - 1];
|
|
1669
|
+
if (next) return text.slice(0, property.getFullStart()) + text.slice(next.getFullStart());
|
|
1670
|
+
if (previous) return text.slice(0, previous.end) + text.slice(property.end);
|
|
1671
|
+
return text.slice(0, config.getStart()) + "{}" + text.slice(config.end);
|
|
1672
|
+
}
|
|
1673
|
+
/** The config without its root-only `options`, and the flags that keep the member's own run the same. */
|
|
1674
|
+
function moveOptions(path, text) {
|
|
1675
|
+
const config = exportedConfig(path, text);
|
|
1676
|
+
const options = config?.properties.find((element) => propertyName(element) === "options");
|
|
1677
|
+
if (config === void 0 || options === void 0) return { kind: "none" };
|
|
1678
|
+
if (!typescript().isPropertyAssignment(options)) return {
|
|
1679
|
+
kind: "unsupported",
|
|
1680
|
+
keys: ["options"]
|
|
1681
|
+
};
|
|
1682
|
+
const result = optionFlags(options.initializer);
|
|
1683
|
+
if ("unsupported" in result) return {
|
|
1684
|
+
kind: "unsupported",
|
|
1685
|
+
keys: result.unsupported
|
|
1686
|
+
};
|
|
1687
|
+
return {
|
|
1688
|
+
kind: "moved",
|
|
1689
|
+
text: withoutProperty(text, config, options),
|
|
1690
|
+
flags: result.flags
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
/** A shell separator that ends one command of a script. */
|
|
1694
|
+
const COMMAND_END = /&&|\|\||[;|]/;
|
|
1695
|
+
/** `script` with `flags` after each `oxlint` command word, skipping a flag that command already passes. */
|
|
1696
|
+
function withFlags(script, flags) {
|
|
1697
|
+
return script.replace(OXLINT_COMMAND, (match, before, offset) => {
|
|
1698
|
+
const rest = script.slice(offset + match.length);
|
|
1699
|
+
const command = rest.split(COMMAND_END)[0] ?? rest;
|
|
1700
|
+
const missing = flags.filter((flag) => !command.includes(flag.split("=")[0] ?? flag));
|
|
1701
|
+
return missing.length ? `${before}oxlint ${missing.join(" ")}` : match;
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
const ALIGNED_TOOLS = [
|
|
1705
|
+
"@antelopejs/tooling-configs",
|
|
1706
|
+
"oxlint",
|
|
1707
|
+
"oxlint-tsgolint",
|
|
1708
|
+
"oxfmt",
|
|
1709
|
+
"knip",
|
|
1710
|
+
"lefthook"
|
|
1711
|
+
];
|
|
1712
|
+
/** The range each pack tool resolves to at the root: the one it declares, else the one `--init` and sync add. A protocol or path spec stays root-only, since a member would resolve it elsewhere. */
|
|
1713
|
+
function rootRanges(root, versions) {
|
|
1714
|
+
const ranges = /* @__PURE__ */ new Map([
|
|
1715
|
+
["@antelopejs/tooling-configs", `^${versions.pack}`],
|
|
1716
|
+
["oxlint", versions.oxlint],
|
|
1717
|
+
["oxlint-tsgolint", versions.tsgolint],
|
|
1718
|
+
["oxfmt", versions.oxfmt],
|
|
1719
|
+
["knip", versions.knip],
|
|
1720
|
+
["lefthook", versions.lefthook]
|
|
1721
|
+
]);
|
|
1722
|
+
for (const field of [root.dependencies, root.devDependencies]) for (const [name, range] of Object.entries(field ?? {})) if (ranges.has(name)) ranges.set(name, range);
|
|
1723
|
+
for (const [name, range] of ranges) if (/[:/]/.test(range)) ranges.delete(name);
|
|
1724
|
+
return ranges;
|
|
1725
|
+
}
|
|
1726
|
+
/** Sets each pack tool the member declares to the root's range, so the workspace installs one copy of the pack; returns whether it changed one. */
|
|
1727
|
+
function alignRanges(member, ranges) {
|
|
1728
|
+
let changed = false;
|
|
1729
|
+
for (const field of [member.dependencies, member.devDependencies]) for (const name of ALIGNED_TOOLS) {
|
|
1730
|
+
const declared = field && Object.hasOwn(field, name) ? field[name] : void 0;
|
|
1731
|
+
const wanted = ranges.get(name);
|
|
1732
|
+
if (!field || declared === void 0 || wanted === void 0 || declared === wanted || declared.includes(":")) continue;
|
|
1733
|
+
field[name] = wanted;
|
|
1734
|
+
changed = true;
|
|
1735
|
+
}
|
|
1736
|
+
return changed;
|
|
1737
|
+
}
|
|
1738
|
+
function alignMember(root, directory, ranges, result) {
|
|
1739
|
+
const manifestPath = join(root, directory, "package.json");
|
|
1740
|
+
const current = readFileSync(manifestPath, "utf8");
|
|
1741
|
+
const member = parseManifest(current);
|
|
1742
|
+
let changed = alignRanges(member, ranges);
|
|
1743
|
+
for (const name of LINT_CONFIGS) {
|
|
1744
|
+
const relative = `${directory}/${name}`;
|
|
1745
|
+
const path = join(root, relative);
|
|
1746
|
+
if (!existsSync(path)) continue;
|
|
1747
|
+
const move = moveOptions(relative, readFileSync(path, "utf8"));
|
|
1748
|
+
if (move.kind === "unsupported") result.failures.push(`${relative} sets oxlint options that oxlint reads only from the root config and that no command-line flag carries (${move.keys.join(", ")}). Move them to the root config or remove them, then rerun antelopejs-sync --init.`);
|
|
1749
|
+
if (move.kind !== "moved") continue;
|
|
1750
|
+
writeFileSync(path, move.text);
|
|
1751
|
+
result.paths.push(relative);
|
|
1752
|
+
for (const [script, command] of Object.entries(member.scripts ?? {})) {
|
|
1753
|
+
const flagged = withFlags(command, move.flags);
|
|
1754
|
+
if (flagged === command || !member.scripts) continue;
|
|
1755
|
+
member.scripts[script] = flagged;
|
|
1756
|
+
changed = true;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
if (!changed) return;
|
|
1760
|
+
writeFileSync(manifestPath, serializeManifest(member, current));
|
|
1761
|
+
result.paths.push(`${directory}/package.json`);
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* Prepares each workspace member for the root's lint and install: the pack
|
|
1765
|
+
* tools it declares move to the root's ranges, and the `options` of its oxlint
|
|
1766
|
+
* config, which oxlint accepts only in the root config, move to the same flags
|
|
1767
|
+
* on the member's `oxlint` scripts.
|
|
1768
|
+
*/
|
|
1769
|
+
function alignWorkspaceMembers(root, manifest, versions) {
|
|
1770
|
+
const ranges = rootRanges(manifest, versions);
|
|
1771
|
+
const result = {
|
|
1772
|
+
paths: [],
|
|
1773
|
+
failures: []
|
|
1774
|
+
};
|
|
1775
|
+
for (const directory of workspaceDirectories(root)) alignMember(root, directory, ranges, result);
|
|
1776
|
+
return result;
|
|
1777
|
+
}
|
|
1778
|
+
//#endregion
|
|
1426
1779
|
//#region src/guardrails/init.ts
|
|
1427
1780
|
/** The `gh` arguments that turn `delete_branch_on_merge` on; `gh` fills `{owner}/{repo}` from the git remote. */
|
|
1428
1781
|
const ENABLE_ARGS = [
|
|
@@ -1480,66 +1833,148 @@ function ensureBranchCleanup(root) {
|
|
|
1480
1833
|
reason: failureText(write)
|
|
1481
1834
|
} : { kind: "enabled" };
|
|
1482
1835
|
}
|
|
1483
|
-
/** Runs
|
|
1484
|
-
function
|
|
1485
|
-
const
|
|
1836
|
+
/** Runs `manager` with `args` quietly; returns its output only when it failed. */
|
|
1837
|
+
function run(root, manager, args) {
|
|
1838
|
+
const command = [manager, ...args].join(" ");
|
|
1839
|
+
const result = spawnSync(manager, args, {
|
|
1486
1840
|
cwd: root,
|
|
1487
1841
|
encoding: "utf8"
|
|
1488
1842
|
});
|
|
1489
|
-
if (result.error) return `${
|
|
1843
|
+
if (result.error) return `${command} failed: ${result.error.message}`;
|
|
1490
1844
|
if (result.status === 0) return void 0;
|
|
1491
|
-
return `${
|
|
1845
|
+
return `${command} failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd();
|
|
1846
|
+
}
|
|
1847
|
+
function install(root, manager) {
|
|
1848
|
+
return run(root, manager, ["install"]);
|
|
1492
1849
|
}
|
|
1493
1850
|
function resolveOxfmt(root) {
|
|
1494
1851
|
const require = createRequire(join(root, "package.json"));
|
|
1495
1852
|
return join(dirname(require.resolve("oxfmt/package.json")), "bin/oxfmt");
|
|
1496
1853
|
}
|
|
1497
|
-
/** Formats
|
|
1498
|
-
function
|
|
1854
|
+
/** Formats the repository with its installed oxfmt, as its `format` script does, so `format:check` passes on the keys init and sync append out of order and on source the repository never formatted. */
|
|
1855
|
+
function formatRepository(root) {
|
|
1499
1856
|
let binary;
|
|
1500
1857
|
try {
|
|
1501
1858
|
binary = resolveOxfmt(root);
|
|
1502
1859
|
} catch {
|
|
1503
|
-
return
|
|
1860
|
+
return {
|
|
1861
|
+
rewritten: [],
|
|
1862
|
+
failure: "oxfmt is not installed in this repository, so it is not formatted."
|
|
1863
|
+
};
|
|
1504
1864
|
}
|
|
1505
|
-
const
|
|
1865
|
+
const oxfmt = (flags) => spawnSync(process.execPath, [
|
|
1506
1866
|
binary,
|
|
1867
|
+
...flags,
|
|
1507
1868
|
"--no-error-on-unmatched-pattern",
|
|
1508
|
-
"
|
|
1869
|
+
"."
|
|
1509
1870
|
], {
|
|
1510
1871
|
cwd: root,
|
|
1511
1872
|
encoding: "utf8"
|
|
1512
1873
|
});
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1874
|
+
const rewritten = oxfmt(["--list-different"]).stdout.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
1875
|
+
const result = oxfmt([]);
|
|
1876
|
+
if (result.error) return {
|
|
1877
|
+
rewritten: [],
|
|
1878
|
+
failure: `oxfmt failed: ${result.error.message}`
|
|
1879
|
+
};
|
|
1880
|
+
if (result.status === 0) return {
|
|
1881
|
+
rewritten,
|
|
1882
|
+
failure: void 0
|
|
1883
|
+
};
|
|
1884
|
+
return {
|
|
1885
|
+
rewritten: [],
|
|
1886
|
+
failure: `oxfmt failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd()
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
/** The tsconfig `--init` writes for a Node repository with none, so the synced `typecheck` checks its JavaScript and TypeScript under Node's module rules. */
|
|
1890
|
+
const NODE_TSCONFIG = `{
|
|
1891
|
+
"compilerOptions": {
|
|
1892
|
+
"target": "ES2024",
|
|
1893
|
+
"module": "NodeNext",
|
|
1894
|
+
"moduleResolution": "NodeNext",
|
|
1895
|
+
"allowJs": true,
|
|
1896
|
+
"checkJs": true,
|
|
1897
|
+
"noEmit": true,
|
|
1898
|
+
"types": ["node"]
|
|
1899
|
+
}
|
|
1516
1900
|
}
|
|
1901
|
+
`;
|
|
1902
|
+
const NPM_LOCKFILE = "package-lock.json";
|
|
1517
1903
|
/**
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
*
|
|
1521
|
-
*
|
|
1522
|
-
* Every step is idempotent, so a second run changes nothing.
|
|
1904
|
+
* The file steps before the first install: `node_modules` ignored, the pnpm version the pack's CI runs pinned when
|
|
1905
|
+
* `packageManager` is unset, the bootstrap devDependencies, a tsconfig for a Node repository without one or its own
|
|
1906
|
+
* `typecheck`, the pack's oxfmt config when there is none, each workspace member on the root's tool ranges with its
|
|
1907
|
+
* oxlint `options` moved to flags, and npm's lockfile replaced by a pnpm lockfile holding the versions it resolved.
|
|
1523
1908
|
*/
|
|
1524
|
-
function
|
|
1909
|
+
function bootstrap(root) {
|
|
1525
1910
|
const path = join(root, "package.json");
|
|
1526
1911
|
if (!existsSync(path)) throw new Error("package.json is missing. antelopejs-sync --init needs a repository that already has one.");
|
|
1527
1912
|
const current = readFileSync(path, "utf8");
|
|
1528
1913
|
const manifest = parseManifest(current);
|
|
1529
1914
|
const manager = packageManager(manifest);
|
|
1915
|
+
const versions = toolingVersions();
|
|
1530
1916
|
const paths = [];
|
|
1531
1917
|
if (ensureGitignore(root)) paths.push(".gitignore");
|
|
1532
|
-
const
|
|
1533
|
-
|
|
1534
|
-
|
|
1918
|
+
const nodeProject = !existsSync(join(root, "tsconfig.json")) && manifest.scripts?.typecheck === void 0 && !usesNuxt(root, manifest);
|
|
1919
|
+
const next = bootstrappedManifest(current, bootstrapDependencies(manifest, versions, nodeProject), versions.packageManager);
|
|
1920
|
+
if (next !== current) {
|
|
1921
|
+
writeFileSync(path, next);
|
|
1535
1922
|
paths.push("package.json");
|
|
1536
1923
|
}
|
|
1537
|
-
|
|
1924
|
+
if (nodeProject) {
|
|
1925
|
+
writeFileSync(join(root, "tsconfig.json"), NODE_TSCONFIG);
|
|
1926
|
+
paths.push("tsconfig.json");
|
|
1927
|
+
}
|
|
1928
|
+
const fmt = PRESET_CONFIGS[1];
|
|
1929
|
+
if (![fmt.path, ...fmt.legacy].some((file) => existsSync(join(root, file)))) {
|
|
1930
|
+
writeFileSync(join(root, fmt.path), presetConfig(void 0, fmt, repositoryTools(manifest)));
|
|
1931
|
+
paths.push(fmt.path);
|
|
1932
|
+
}
|
|
1933
|
+
const members = alignWorkspaceMembers(root, manifest, versions);
|
|
1934
|
+
paths.push(...members.paths);
|
|
1935
|
+
if (members.failures.length) return {
|
|
1936
|
+
manager,
|
|
1937
|
+
paths,
|
|
1938
|
+
removed: [],
|
|
1939
|
+
failure: members.failures.join("\n")
|
|
1940
|
+
};
|
|
1941
|
+
const npmLock = manager === "pnpm" && existsSync(join(root, NPM_LOCKFILE));
|
|
1942
|
+
const imported = npmLock && !existsSync(join(root, "pnpm-lock.yaml")) ? run(root, manager, ["import"]) : void 0;
|
|
1943
|
+
if (imported !== void 0) return {
|
|
1944
|
+
manager,
|
|
1945
|
+
paths,
|
|
1946
|
+
removed: [],
|
|
1947
|
+
failure: imported
|
|
1948
|
+
};
|
|
1949
|
+
if (npmLock) unlinkSync(join(root, NPM_LOCKFILE));
|
|
1950
|
+
return {
|
|
1951
|
+
manager,
|
|
1952
|
+
paths,
|
|
1953
|
+
removed: npmLock ? [NPM_LOCKFILE] : [],
|
|
1954
|
+
failure: install(root, manager)
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Onboards a repository in one run: the bootstrap file steps and an install, the repository formatted by oxfmt before
|
|
1959
|
+
* sync measures its lint and size baseline, a full-profile sync, a second install when sync added devDependencies, a
|
|
1960
|
+
* second oxfmt pass over what sync wrote, and `delete_branch_on_merge` on GitHub, which runs whatever the file steps
|
|
1961
|
+
* did. Every step is idempotent, so a second run changes nothing.
|
|
1962
|
+
*/
|
|
1963
|
+
function initRepository(root, options = {}) {
|
|
1964
|
+
const { manager, paths, removed, failure: installed } = bootstrap(root);
|
|
1965
|
+
const format = () => {
|
|
1966
|
+
const formatted = formatRepository(root);
|
|
1967
|
+
for (const file of formatted.rewritten) if (!paths.includes(file)) paths.push(file);
|
|
1968
|
+
return formatted.failure;
|
|
1969
|
+
};
|
|
1970
|
+
const first = installed ?? (existsSync(join(root, PRESET_CONFIGS[1].path)) ? format() : void 0);
|
|
1538
1971
|
if (first !== void 0) return {
|
|
1539
1972
|
paths,
|
|
1973
|
+
removed,
|
|
1540
1974
|
failure: first,
|
|
1541
1975
|
sync: void 0,
|
|
1542
|
-
branchCleanup: ensureBranchCleanup(root)
|
|
1976
|
+
branchCleanup: ensureBranchCleanup(root),
|
|
1977
|
+
untypedDocs: []
|
|
1543
1978
|
};
|
|
1544
1979
|
const sync = syncRepository(root, {
|
|
1545
1980
|
profile: "full",
|
|
@@ -1548,15 +1983,15 @@ function initRepository(root, options = {}) {
|
|
|
1548
1983
|
let failure;
|
|
1549
1984
|
if (!sync.errors.length) {
|
|
1550
1985
|
failure = sync.dependenciesAdded ? install(root, manager) : void 0;
|
|
1551
|
-
|
|
1552
|
-
failure ??= formatManifest(root);
|
|
1553
|
-
if (readFileSync(path, "utf8") !== unformatted && !paths.includes("package.json")) paths.push("package.json");
|
|
1986
|
+
failure ??= format();
|
|
1554
1987
|
}
|
|
1555
1988
|
return {
|
|
1556
1989
|
paths,
|
|
1990
|
+
removed,
|
|
1557
1991
|
failure,
|
|
1558
1992
|
sync,
|
|
1559
|
-
branchCleanup: ensureBranchCleanup(root)
|
|
1993
|
+
branchCleanup: ensureBranchCleanup(root),
|
|
1994
|
+
untypedDocs: sync.errors.length ? [] : untypedDocsFiles(root)
|
|
1560
1995
|
};
|
|
1561
1996
|
}
|
|
1562
1997
|
//#endregion
|
|
@@ -1576,10 +2011,12 @@ function init(verify) {
|
|
|
1576
2011
|
const result = initRepository(repositoryRoot(), { verify });
|
|
1577
2012
|
const reportedBySync = result.sync && !result.sync.errors.length ? result.sync.paths : [];
|
|
1578
2013
|
for (const path of result.paths) if (!reportedBySync.includes(path)) process.stdout.write(`Updated: ${path}\n`);
|
|
2014
|
+
for (const path of result.removed) process.stdout.write(`Removed: ${path}\n`);
|
|
1579
2015
|
const synced = result.sync ? printSync(result.sync, {
|
|
1580
2016
|
check: false,
|
|
1581
2017
|
installed: true
|
|
1582
2018
|
}) : 0;
|
|
2019
|
+
if (result.untypedDocs.length) process.stdout.write(`Note: ${result.untypedDocs.join(", ")} hold TypeScript fences or docs-api pages the docs check typechecks. Set docs-typescript-project in ${CI_PATH} to a tsconfig whose program resolves their imports, or mark illustrative fences \`fragment\`. Without it the check uses the root tsconfig.json and fails when there is none.\n`);
|
|
1583
2020
|
if (result.failure !== void 0) process.stderr.write(`${result.failure}\n`);
|
|
1584
2021
|
const failed = synced !== 0 || result.failure !== void 0;
|
|
1585
2022
|
if (failed) process.stderr.write("Fix the errors above, then rerun antelopejs-sync --init.\n");
|