@antelopejs/tooling-configs 0.5.1 → 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 +16 -6
- package/dist/bin/api-diff.mjs +3 -3
- package/dist/bin/body-check.mjs +2 -2
- package/dist/bin/checks.mjs +121 -5
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/garden.mjs +1 -1
- package/dist/bin/ratchet.mjs +2 -2
- package/dist/bin/suppressions.mjs +1 -1
- package/dist/bin/sync.mjs +180 -550
- package/dist/oxc/lint.mjs +1 -1
- 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-ClfblHNJ.mjs → ratchet--WWa_w2O.mjs} +2 -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
package/dist/bin/sync.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
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 { a as
|
|
4
|
-
import { i as presetConfig, n as SETUP_SCRIPT, r as lefthook, t as PRESET_CONFIGS } from "../templates-
|
|
3
|
+
import { a as packageManager, c as templatePackage, i as managedPackage, l as toolingVersions, n as bootstrapDependencies, o as parseManifest, s as repositoryTools, t as addedDevDependencies, u as withDevDependencies } from "../package-DxxcxOzp.mjs";
|
|
4
|
+
import { i as presetConfig, n as SETUP_SCRIPT, r as lefthook, t as PRESET_CONFIGS } from "../templates-BiXgdsRN.mjs";
|
|
5
5
|
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
6
|
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-B0FmthGv.mjs";
|
|
7
8
|
import { a as gitFiles, c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
8
|
-
import { i as recordedRelease, t as measureBaseline } from "../ratchet
|
|
9
|
-
import { a as ciWorkflow, c as ciNodeCallers, l as ciRenovateSyncCallers, o as placeholderTestScript, p as renovateArtifacts, r as CI_PATH, s as MISSING_CHECKS_WORKFLOW, u as hasChecksWorkflow } from "../ci-workflow-COJUT12b.mjs";
|
|
9
|
+
import { i as recordedRelease, t as measureBaseline } from "../ratchet--WWa_w2O.mjs";
|
|
10
10
|
import { n as SUPPRESSIONS_FILE, r as adoptedBudget } from "../suppression-budget-Dvb_IqBo.mjs";
|
|
11
|
+
import { n as stepsOf, r as planDocs, t as matchingScripts } from "../script-steps-CgH2DSsp.mjs";
|
|
11
12
|
import { t as DEFAULT_SHARED } from "../map-DRyYz_Fw.mjs";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
12
14
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
13
15
|
import { basename, dirname, join, posix, resolve } from "node:path";
|
|
14
|
-
import { execFileSync } from "node:child_process";
|
|
15
|
-
import { isMap, isScalar, isSeq, parseDocument } from "yaml";
|
|
16
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
16
17
|
import ts from "typescript";
|
|
17
18
|
import { parseArgs } from "node:util";
|
|
18
19
|
//#region src/guardrails/agents-block.ts
|
|
@@ -426,363 +427,6 @@ function checkEntryOnlyConfiguration(root) {
|
|
|
426
427
|
};
|
|
427
428
|
}
|
|
428
429
|
//#endregion
|
|
429
|
-
//#region src/guardrails/markdown-table.ts
|
|
430
|
-
/** The lines of a Markdown table whose first row is the header, columns padded as oxfmt leaves them. */
|
|
431
|
-
function tableLines(table) {
|
|
432
|
-
const widths = table[0].map((_, column) => Math.max(3, ...table.map((row) => row[column].length)));
|
|
433
|
-
const line = (cells) => `| ${cells.map((cell, column) => cell.padEnd(widths[column])).join(" | ")} |`;
|
|
434
|
-
return [
|
|
435
|
-
line(table[0]),
|
|
436
|
-
line(widths.map((width) => "-".repeat(width))),
|
|
437
|
-
...table.slice(1).map(line)
|
|
438
|
-
];
|
|
439
|
-
}
|
|
440
|
-
//#endregion
|
|
441
|
-
//#region src/guardrails/docs-modules.ts
|
|
442
|
-
const DMS_MODULES_START = "<!-- antelopejs-dms-modules:start -->";
|
|
443
|
-
const DMS_MODULES_END = "<!-- antelopejs-dms-modules:end -->";
|
|
444
|
-
const ORGANIZATION = "https://github.com/AntelopeJS";
|
|
445
|
-
/** The AntelopeJS DMS modules in display order. Every README holding the markers lists exactly these. */
|
|
446
|
-
const DMS_MODULES = [
|
|
447
|
-
{
|
|
448
|
-
repo: "dms-builder",
|
|
449
|
-
row: "Edit pages, tables and data sources by clicking, as TypeScript that compiles"
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
repo: "dms-ai",
|
|
453
|
-
row: "An assistant chat in the dashboard, on your own Claude Code or Codex"
|
|
454
|
-
},
|
|
455
|
-
{
|
|
456
|
-
repo: "dms-database",
|
|
457
|
-
row: "Schemas, relation diagrams, a data browser and a query console"
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
repo: "dms-api",
|
|
461
|
-
row: "API health, request logs, per-route statistics and a request tester"
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
repo: "dms-automation",
|
|
465
|
-
row: "Node-graph automations on schedules, webhooks and DMS events, with a trace for every run"
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
repo: "dms-mailing",
|
|
469
|
-
row: "E-mail templates in a block editor, versions, a send log and delivery metrics"
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
repo: "dms-lang",
|
|
473
|
-
row: "Translation coverage, a translation matrix and a translation queue"
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
repo: "dms-media",
|
|
477
|
-
row: "A media library with folders, per-folder permissions, image sizes and light editing"
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
repo: "dms-saas",
|
|
481
|
-
row: "Self-service sign-up, plans that gate features, and Stripe billing"
|
|
482
|
-
},
|
|
483
|
-
{
|
|
484
|
-
repo: "dms-marketing",
|
|
485
|
-
row: "Traffic, conversion funnels with A/B splits and click heatmaps, without cookies"
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
repo: "dms-frontend",
|
|
489
|
-
row: "The `ajs dms` CLI, the Vue renderer and the SDK every frontend module builds on"
|
|
490
|
-
}
|
|
491
|
-
];
|
|
492
|
-
/** The generated block, formatted as oxfmt leaves it. */
|
|
493
|
-
function modulesBlock() {
|
|
494
|
-
return [
|
|
495
|
-
DMS_MODULES_START,
|
|
496
|
-
"",
|
|
497
|
-
...tableLines([["Module", "What it adds"], ...DMS_MODULES.map(({ repo, row }) => [`[\`${repo}\`](${ORGANIZATION}/${repo})`, row])]),
|
|
498
|
-
"",
|
|
499
|
-
DMS_MODULES_END,
|
|
500
|
-
""
|
|
501
|
-
].join("\n");
|
|
502
|
-
}
|
|
503
|
-
/** The README with the block between its markers rewritten. A README without markers comes back as it is. */
|
|
504
|
-
function placeModulesBlock(current) {
|
|
505
|
-
const start = current.indexOf(DMS_MODULES_START);
|
|
506
|
-
const end = current.indexOf(DMS_MODULES_END);
|
|
507
|
-
const starts = current.split(DMS_MODULES_START).length - 1;
|
|
508
|
-
const ends = current.split(DMS_MODULES_END).length - 1;
|
|
509
|
-
if (starts === 0 && ends === 0) return current;
|
|
510
|
-
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.");
|
|
511
|
-
return `${current.slice(0, start)}${modulesBlock()}${current.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
512
|
-
}
|
|
513
|
-
//#endregion
|
|
514
|
-
//#region src/guardrails/docs-compat.ts
|
|
515
|
-
const DOCS_COMPAT_START = "<!-- antelopejs-docs-compat:start -->";
|
|
516
|
-
const DOCS_COMPAT_END = "<!-- antelopejs-docs-compat:end -->";
|
|
517
|
-
const DOCS_NODE_START = "<!-- antelopejs-docs-node:start -->";
|
|
518
|
-
const DOCS_NODE_END = "<!-- antelopejs-docs-node:end -->";
|
|
519
|
-
const LOCKFILE = "pnpm-lock.yaml";
|
|
520
|
-
const REQUIREMENTS_HEADING = /^##\s+Requirements\s*$/i;
|
|
521
|
-
const SCOPE = "@antelopejs/";
|
|
522
|
-
const UNRESOLVED = "—";
|
|
523
|
-
const LEGACY_MARKER = /^<!--\s*docs-compat:\s*\.\/package\.json#\w+\s*-->\s*$/;
|
|
524
|
-
const COMPATIBILITY_HEADING = /^##\s+Compatibility\s*$/i;
|
|
525
|
-
const RESOLVED_SECTIONS = [
|
|
526
|
-
"dependencies",
|
|
527
|
-
"optionalDependencies",
|
|
528
|
-
"devDependencies"
|
|
529
|
-
];
|
|
530
|
-
/** The generated block, rows sorted by package name, formatted as oxfmt leaves it. */
|
|
531
|
-
function compatBlock(rows) {
|
|
532
|
-
const sorted = [...rows].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
533
|
-
return [
|
|
534
|
-
DOCS_COMPAT_START,
|
|
535
|
-
"",
|
|
536
|
-
...tableLines([[
|
|
537
|
-
"Package",
|
|
538
|
-
"Supported",
|
|
539
|
-
"Tested with"
|
|
540
|
-
], ...sorted.map(({ name, supported, tested }) => [
|
|
541
|
-
`\`${name}\``,
|
|
542
|
-
`\`${supported.replaceAll("|", "\\|")}\``,
|
|
543
|
-
tested === void 0 ? UNRESOLVED : `\`${tested}\``
|
|
544
|
-
])]),
|
|
545
|
-
"",
|
|
546
|
-
DOCS_COMPAT_END,
|
|
547
|
-
""
|
|
548
|
-
].join("\n");
|
|
549
|
-
}
|
|
550
|
-
function legacySpanEnd(lines, marker) {
|
|
551
|
-
let index = marker + 1;
|
|
552
|
-
while (index < lines.length && !lines[index].trim()) index++;
|
|
553
|
-
while (index < lines.length && lines[index].trimStart().startsWith("|")) index++;
|
|
554
|
-
while (index < lines.length && !lines[index].trim()) index++;
|
|
555
|
-
return index;
|
|
556
|
-
}
|
|
557
|
-
function replaceLegacyTables(lines, block) {
|
|
558
|
-
const placed = [];
|
|
559
|
-
let replaced = false;
|
|
560
|
-
for (let index = 0; index < lines.length;) {
|
|
561
|
-
if (!LEGACY_MARKER.test(lines[index])) {
|
|
562
|
-
placed.push(lines[index]);
|
|
563
|
-
index++;
|
|
564
|
-
continue;
|
|
565
|
-
}
|
|
566
|
-
if (!replaced) placed.push(...block.split("\n"));
|
|
567
|
-
replaced = true;
|
|
568
|
-
index = legacySpanEnd(lines, index);
|
|
569
|
-
}
|
|
570
|
-
return replaced ? placed : void 0;
|
|
571
|
-
}
|
|
572
|
-
function finalNewline(text) {
|
|
573
|
-
return text.endsWith("\n") ? text : `${text}\n`;
|
|
574
|
-
}
|
|
575
|
-
/** The README with the block in place: replacing the markers, a legacy `docs-compat` table, or under `## Compatibility`. */
|
|
576
|
-
function placeCompatBlock(current, block) {
|
|
577
|
-
const text = current ?? "";
|
|
578
|
-
const start = text.indexOf(DOCS_COMPAT_START);
|
|
579
|
-
const end = text.indexOf(DOCS_COMPAT_END);
|
|
580
|
-
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-compat markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
581
|
-
if (start !== -1) return `${text.slice(0, start)}${block}${text.slice(end + 35).replace(/^\r?\n/, "")}`;
|
|
582
|
-
const lines = text.split("\n");
|
|
583
|
-
const legacy = replaceLegacyTables(lines, block);
|
|
584
|
-
if (legacy) return finalNewline(legacy.join("\n"));
|
|
585
|
-
const heading = lines.findIndex((line) => COMPATIBILITY_HEADING.test(line));
|
|
586
|
-
if (heading !== -1) {
|
|
587
|
-
let rest = heading + 1;
|
|
588
|
-
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
589
|
-
return finalNewline([
|
|
590
|
-
...lines.slice(0, heading + 1),
|
|
591
|
-
"",
|
|
592
|
-
...block.split("\n"),
|
|
593
|
-
...lines.slice(rest)
|
|
594
|
-
].join("\n"));
|
|
595
|
-
}
|
|
596
|
-
const before = text.trimEnd();
|
|
597
|
-
return `${before}${before ? "\n\n" : ""}## Compatibility\n\n${block}`;
|
|
598
|
-
}
|
|
599
|
-
/** The generated Node prerequisite block for an `engines.node` range, formatted as oxfmt leaves it. */
|
|
600
|
-
function nodeBlock(range) {
|
|
601
|
-
return `${DOCS_NODE_START}\n\nThis package requires Node.js \`${range}\`.\n${DOCS_NODE_END}\n`;
|
|
602
|
-
}
|
|
603
|
-
/** The README with the Node block in place: between its markers, under `## Requirements`, or in a new `## Requirements` section at the end. */
|
|
604
|
-
function placeNodeBlock(current, block) {
|
|
605
|
-
const start = current.indexOf(DOCS_NODE_START);
|
|
606
|
-
const end = current.indexOf(DOCS_NODE_END);
|
|
607
|
-
if (start === -1 !== (end === -1) || end < start) throw new Error("incomplete antelopejs-docs-node markers. Repair or delete them, then rerun antelopejs-sync.");
|
|
608
|
-
if (start !== -1) return `${current.slice(0, start)}${block}${current.slice(end + 33).replace(/^\r?\n/, "")}`;
|
|
609
|
-
const lines = current.split("\n");
|
|
610
|
-
const heading = lines.findIndex((line) => REQUIREMENTS_HEADING.test(line));
|
|
611
|
-
if (heading !== -1) {
|
|
612
|
-
let rest = heading + 1;
|
|
613
|
-
while (rest < lines.length && !lines[rest].trim()) rest++;
|
|
614
|
-
return finalNewline([
|
|
615
|
-
...lines.slice(0, heading + 1),
|
|
616
|
-
"",
|
|
617
|
-
...block.trimEnd().split("\n"),
|
|
618
|
-
...rest < lines.length ? ["", ...lines.slice(rest)] : []
|
|
619
|
-
].join("\n"));
|
|
620
|
-
}
|
|
621
|
-
return `${current.trimEnd()}\n\n## Requirements\n\n${block}`;
|
|
622
|
-
}
|
|
623
|
-
function relative$1(directory, name) {
|
|
624
|
-
return directory ? `${directory}/${name}` : name;
|
|
625
|
-
}
|
|
626
|
-
function isDirectory(root, path) {
|
|
627
|
-
return statSync(join(root, path), { throwIfNoEntry: false })?.isDirectory() === true;
|
|
628
|
-
}
|
|
629
|
-
function subdirectories(root, directory) {
|
|
630
|
-
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));
|
|
631
|
-
}
|
|
632
|
-
function descendants(root, directory) {
|
|
633
|
-
return subdirectories(root, directory).flatMap((child) => [child, ...descendants(root, child)]);
|
|
634
|
-
}
|
|
635
|
-
function globExpression(pattern) {
|
|
636
|
-
const source = pattern.split("/").map((segment) => segment === "**" ? "(?:.*)" : segment.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("*", "[^/]*").replaceAll("?", "[^/]")).join("/").replaceAll("(?:.*)/", "(?:.*/)?");
|
|
637
|
-
return new RegExp(`^${source}$`);
|
|
638
|
-
}
|
|
639
|
-
function expand(root, pattern) {
|
|
640
|
-
let directories = [""];
|
|
641
|
-
for (const segment of pattern.split("/")) if (segment === "**") directories = directories.flatMap((directory) => [directory, ...descendants(root, directory)]);
|
|
642
|
-
else if (/[*?]/.test(segment)) {
|
|
643
|
-
const expression = globExpression(segment);
|
|
644
|
-
directories = directories.flatMap((directory) => subdirectories(root, directory).filter((child) => expression.test(child.slice(child.lastIndexOf("/") + 1))));
|
|
645
|
-
} else directories = directories.map((directory) => relative$1(directory, segment)).filter((directory) => isDirectory(root, directory));
|
|
646
|
-
return directories;
|
|
647
|
-
}
|
|
648
|
-
function normalizePattern(pattern) {
|
|
649
|
-
return pattern.replace(/^(?:\.\/)+/, "").replace(/\/+$/, "").replace(/^\.$/, "");
|
|
650
|
-
}
|
|
651
|
-
function scalarItems(document, path) {
|
|
652
|
-
const node = document.getIn(path, true);
|
|
653
|
-
return isSeq(node) ? node.items.flatMap((item) => isScalar(item) ? [String(item.value)] : []) : [];
|
|
654
|
-
}
|
|
655
|
-
/** pnpm-workspace.yaml `packages`, else package.json `workspaces` as an array or as `{ packages }`; JSON parses as YAML. */
|
|
656
|
-
function workspacePatterns(root) {
|
|
657
|
-
const pnpm = join(root, "pnpm-workspace.yaml");
|
|
658
|
-
if (existsSync(pnpm)) return scalarItems(parseDocument(readFileSync(pnpm, "utf8")), ["packages"]);
|
|
659
|
-
const manifest = parseDocument(readFileSync(join(root, "package.json"), "utf8"));
|
|
660
|
-
return scalarItems(manifest, isMap(manifest.get("workspaces", true)) ? ["workspaces", "packages"] : ["workspaces"]);
|
|
661
|
-
}
|
|
662
|
-
function workspaceDirectories(root) {
|
|
663
|
-
const patterns = workspacePatterns(root);
|
|
664
|
-
const excluded = patterns.filter((pattern) => pattern.startsWith("!")).map((pattern) => globExpression(normalizePattern(pattern.slice(1))));
|
|
665
|
-
const found = /* @__PURE__ */ new Set();
|
|
666
|
-
for (const pattern of patterns.filter((item) => !item.startsWith("!"))) {
|
|
667
|
-
const normalized = normalizePattern(pattern);
|
|
668
|
-
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);
|
|
669
|
-
}
|
|
670
|
-
return [...found].sort();
|
|
671
|
-
}
|
|
672
|
-
function declaredRanges(manifest) {
|
|
673
|
-
const ranges = /* @__PURE__ */ new Map();
|
|
674
|
-
for (const field of [
|
|
675
|
-
manifest.optionalDependencies,
|
|
676
|
-
manifest.dependencies,
|
|
677
|
-
manifest.peerDependencies
|
|
678
|
-
]) for (const [name, range] of Object.entries(field ?? {})) if (name.startsWith(SCOPE)) ranges.set(name, range);
|
|
679
|
-
return ranges;
|
|
680
|
-
}
|
|
681
|
-
function readManifest(root, directory) {
|
|
682
|
-
return parseManifest(readFileSync(join(root, directory, "package.json"), "utf8"));
|
|
683
|
-
}
|
|
684
|
-
function linkedVersion(root, directory, link) {
|
|
685
|
-
const target = join(root, directory, link);
|
|
686
|
-
return existsSync(join(target, "package.json")) ? parseManifest(readFileSync(join(target, "package.json"), "utf8")).version : void 0;
|
|
687
|
-
}
|
|
688
|
-
function resolvedVersion(root, { document, importer }, directory, name) {
|
|
689
|
-
for (const section of RESOLVED_SECTIONS) {
|
|
690
|
-
const entry = document.getIn([
|
|
691
|
-
"importers",
|
|
692
|
-
importer,
|
|
693
|
-
section,
|
|
694
|
-
name
|
|
695
|
-
], true);
|
|
696
|
-
const version = isMap(entry) ? entry.get("version", true) : entry;
|
|
697
|
-
if (!isScalar(version)) continue;
|
|
698
|
-
const resolved = String(version.value).split("(")[0];
|
|
699
|
-
return resolved.startsWith("link:") ? linkedVersion(root, directory, resolved.slice(5)) : resolved;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
const UNSHARED_NPMRC = /^\s*shared-workspace-lockfile\s*=\s*false\s*(?:[#;].*)?$/m;
|
|
703
|
-
/** Whether the workspace keeps one root lockfile, or `shared-workspace-lockfile=false` gives each package its own. */
|
|
704
|
-
function sharesLockfile(root) {
|
|
705
|
-
const npmrc = join(root, ".npmrc");
|
|
706
|
-
if (existsSync(npmrc) && UNSHARED_NPMRC.test(readFileSync(npmrc, "utf8"))) return false;
|
|
707
|
-
const workspace = join(root, "pnpm-workspace.yaml");
|
|
708
|
-
return !(existsSync(workspace) && parseDocument(readFileSync(workspace, "utf8")).get("sharedWorkspaceLockfile") === false);
|
|
709
|
-
}
|
|
710
|
-
/** The lockfile path of a package, relative to the root. A shared lockfile is the root's, indexed by the package directory. */
|
|
711
|
-
function lockPath(shared, directory) {
|
|
712
|
-
return shared ? LOCKFILE : relative$1(directory, LOCKFILE);
|
|
713
|
-
}
|
|
714
|
-
function readLock(root, shared, directory, documents) {
|
|
715
|
-
const path = join(root, lockPath(shared, directory));
|
|
716
|
-
if (!documents.has(path) && existsSync(path)) documents.set(path, parseDocument(readFileSync(path, "utf8")));
|
|
717
|
-
const document = documents.get(path);
|
|
718
|
-
return document && {
|
|
719
|
-
document,
|
|
720
|
-
importer: shared ? directory || "." : "."
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
/** Adds one package's `docs-files` lines and, when it needs one, its README with the generated blocks. */
|
|
724
|
-
function planPackage(root, plan, lock, standard, { directory, ranges, published, node }) {
|
|
725
|
-
const readme = relative$1(directory, "README.md");
|
|
726
|
-
const docs = relative$1(directory, "docs");
|
|
727
|
-
if (!published) return;
|
|
728
|
-
if (ranges.size > 0 || existsSync(join(root, readme))) plan.docsFiles.push(readme);
|
|
729
|
-
if (isDirectory(root, docs)) plan.docsFiles.push(docs);
|
|
730
|
-
const current = existsSync(join(root, readme)) ? readFileSync(join(root, readme), "utf8") : void 0;
|
|
731
|
-
const nodeRange = standard && current !== void 0 ? node : void 0;
|
|
732
|
-
if (ranges.size === 0 && current === void 0) return;
|
|
733
|
-
const rows = [...ranges].map(([name, supported]) => ({
|
|
734
|
-
name,
|
|
735
|
-
supported,
|
|
736
|
-
tested: lock && resolvedVersion(root, lock, directory, name)
|
|
737
|
-
}));
|
|
738
|
-
try {
|
|
739
|
-
const withRequirements = nodeRange !== void 0 && current !== void 0 ? placeNodeBlock(current, nodeBlock(nodeRange)) : current;
|
|
740
|
-
plan.readmes.push({
|
|
741
|
-
path: readme,
|
|
742
|
-
current,
|
|
743
|
-
content: placeModulesBlock(rows.length > 0 ? placeCompatBlock(withRequirements, compatBlock(rows)) : withRequirements ?? "")
|
|
744
|
-
});
|
|
745
|
-
} catch (error) {
|
|
746
|
-
plan.errors.push(`${readme}: ${error instanceof Error ? error.message : String(error)}`);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Plans the docs-compat block of the root and of every workspace package that is not private and declares an
|
|
751
|
-
* `@antelopejs/*` peer, runtime or optional dependency, and the `docs-files` lines covering the root and every workspace
|
|
752
|
-
* package that is not private.
|
|
753
|
-
* Tested with comes from pnpm-lock.yaml, each package's own when `shared-workspace-lockfile=false`; other package managers get a dash.
|
|
754
|
-
*/
|
|
755
|
-
function planDocs(root, manager) {
|
|
756
|
-
const rootManifest = readManifest(root, "");
|
|
757
|
-
const packages = ["", ...workspaceDirectories(root)].map((directory) => {
|
|
758
|
-
const manifest = directory ? readManifest(root, directory) : rootManifest;
|
|
759
|
-
return {
|
|
760
|
-
directory,
|
|
761
|
-
published: !directory || !manifest.private,
|
|
762
|
-
node: manifest.engines?.node,
|
|
763
|
-
ranges: manifest.private ? /* @__PURE__ */ new Map() : declaredRanges(manifest)
|
|
764
|
-
};
|
|
765
|
-
});
|
|
766
|
-
const qualifying = packages.filter(({ ranges }) => ranges.size > 0);
|
|
767
|
-
const plan = {
|
|
768
|
-
readmes: [],
|
|
769
|
-
docsFiles: [],
|
|
770
|
-
errors: [],
|
|
771
|
-
exists: (path) => existsSync(join(root, path))
|
|
772
|
-
};
|
|
773
|
-
const shared = sharesLockfile(root);
|
|
774
|
-
const documents = /* @__PURE__ */ new Map();
|
|
775
|
-
const locks = new Map(qualifying.map(({ directory }) => [directory, manager === "pnpm" ? readLock(root, shared, directory, documents) : void 0]));
|
|
776
|
-
const missing = manager === "pnpm" ? qualifying.filter(({ directory }) => !locks.get(directory)) : [];
|
|
777
|
-
if (missing.length) {
|
|
778
|
-
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.`);
|
|
779
|
-
return plan;
|
|
780
|
-
}
|
|
781
|
-
const standard = rootManifest.antelopeJs?.docs?.standard === true;
|
|
782
|
-
for (const item of packages) planPackage(root, plan, locks.get(item.directory), standard, item);
|
|
783
|
-
return plan;
|
|
784
|
-
}
|
|
785
|
-
//#endregion
|
|
786
430
|
//#region src/guardrails/template-agent-layer.ts
|
|
787
431
|
/** The folders a project scaffolded from a template does not get, as `ajs project init` excludes them. */
|
|
788
432
|
const SCAFFOLD_EXCLUDED_PATHS = [".agents/", ".claude/skills/"];
|
|
@@ -867,182 +511,6 @@ function releaseHooks(files) {
|
|
|
867
511
|
return [...hooksIn(files, ".release-it.json", ["hooks"]), ...hooksIn(files, "package.json", ["release-it", "hooks"])];
|
|
868
512
|
}
|
|
869
513
|
//#endregion
|
|
870
|
-
//#region src/guardrails/script-steps.ts
|
|
871
|
-
const SEPARATORS = /&&|\|\||[;|\n]|(?<![>&])&(?!&)/u;
|
|
872
|
-
const ENV_ASSIGNMENT = /^[A-Za-z_]\w*=/u;
|
|
873
|
-
const TSC_COMMAND = /(?:^|[\\/])tsc(?:\.js)?$/u;
|
|
874
|
-
const MANAGERS = /* @__PURE__ */ new Set([
|
|
875
|
-
"pnpm",
|
|
876
|
-
"npm",
|
|
877
|
-
"yarn",
|
|
878
|
-
"bun"
|
|
879
|
-
]);
|
|
880
|
-
const NPM_BUILTINS = /* @__PURE__ */ new Set([
|
|
881
|
-
"test",
|
|
882
|
-
"start",
|
|
883
|
-
"stop",
|
|
884
|
-
"restart"
|
|
885
|
-
]);
|
|
886
|
-
const WRAPPERS = /* @__PURE__ */ new Set([
|
|
887
|
-
"cross-env",
|
|
888
|
-
"cross-env-shell",
|
|
889
|
-
"env",
|
|
890
|
-
"corepack"
|
|
891
|
-
]);
|
|
892
|
-
const EXEC_RUNNERS = /* @__PURE__ */ new Set([
|
|
893
|
-
"npx",
|
|
894
|
-
"bunx",
|
|
895
|
-
"pnpx"
|
|
896
|
-
]);
|
|
897
|
-
const EXEC_VERBS = /* @__PURE__ */ new Set([
|
|
898
|
-
"exec",
|
|
899
|
-
"x",
|
|
900
|
-
"dlx"
|
|
901
|
-
]);
|
|
902
|
-
const RUN_ALL = /* @__PURE__ */ new Set([
|
|
903
|
-
"run-s",
|
|
904
|
-
"run-p",
|
|
905
|
-
"npm-run-all",
|
|
906
|
-
"npm-run-all2"
|
|
907
|
-
]);
|
|
908
|
-
const RUN_ALL_VALUED = /* @__PURE__ */ new Set(["--max-parallel", "--npm-path"]);
|
|
909
|
-
const EXEC_VALUED = /* @__PURE__ */ new Set([
|
|
910
|
-
"-p",
|
|
911
|
-
"--package",
|
|
912
|
-
"-c",
|
|
913
|
-
"--call"
|
|
914
|
-
]);
|
|
915
|
-
const TARGET_VALUED = /* @__PURE__ */ new Set([
|
|
916
|
-
"--filter",
|
|
917
|
-
"-F",
|
|
918
|
-
"--dir",
|
|
919
|
-
"-C",
|
|
920
|
-
"--prefix",
|
|
921
|
-
"--cwd",
|
|
922
|
-
"--workspace"
|
|
923
|
-
]);
|
|
924
|
-
const TARGET_FLAGS = /* @__PURE__ */ new Set([
|
|
925
|
-
"-r",
|
|
926
|
-
"--recursive",
|
|
927
|
-
"--workspaces",
|
|
928
|
-
"-ws"
|
|
929
|
-
]);
|
|
930
|
-
function words(segment) {
|
|
931
|
-
return segment.replace(/[()]/gu, " ").split(/\s+/u).map((word) => word.replace(/^["']|["']$/gu, "")).filter(Boolean);
|
|
932
|
-
}
|
|
933
|
-
/** The simple commands of a script: `&&`, `||`, `;`, `|`, `&`, newlines and parentheses all end one. */
|
|
934
|
-
function lines(script) {
|
|
935
|
-
return script.split(SEPARATORS).map(words).filter((list) => list.length > 0);
|
|
936
|
-
}
|
|
937
|
-
/** Skips the options from `from`, and the values of those that take one; `elsewhere` when one points at another package. */
|
|
938
|
-
function skipOptions(args, from, valued) {
|
|
939
|
-
let index = from;
|
|
940
|
-
let elsewhere = false;
|
|
941
|
-
while (index < args.length && args[index].startsWith("-")) {
|
|
942
|
-
const [name, ...value] = args[index].split("=");
|
|
943
|
-
elsewhere ||= TARGET_VALUED.has(name) || TARGET_FLAGS.has(name);
|
|
944
|
-
index += valued.has(name) && value.length === 0 ? 2 : 1;
|
|
945
|
-
}
|
|
946
|
-
return {
|
|
947
|
-
index,
|
|
948
|
-
elsewhere
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
function isTsc(word) {
|
|
952
|
-
return TSC_COMMAND.test(word);
|
|
953
|
-
}
|
|
954
|
-
/** `tsc`, a path to it, or `node` running one. */
|
|
955
|
-
function programSteps(line) {
|
|
956
|
-
const [head, ...rest] = line;
|
|
957
|
-
if (head === void 0) return [];
|
|
958
|
-
if (isTsc(head)) return [{
|
|
959
|
-
kind: "tsc",
|
|
960
|
-
args: rest
|
|
961
|
-
}];
|
|
962
|
-
if (head !== "node") return [];
|
|
963
|
-
if (rest[0] === "--run" && rest[1] !== void 0) return [{
|
|
964
|
-
kind: "script",
|
|
965
|
-
names: [rest[1]],
|
|
966
|
-
elsewhere: false
|
|
967
|
-
}];
|
|
968
|
-
const at = rest.findIndex((word) => !word.startsWith("-"));
|
|
969
|
-
return at !== -1 && isTsc(rest[at]) ? [{
|
|
970
|
-
kind: "tsc",
|
|
971
|
-
args: rest.slice(at + 1)
|
|
972
|
-
}] : [];
|
|
973
|
-
}
|
|
974
|
-
/** What `npx`, `pnpm exec` and `npm exec` run: the command after the options and the packages they name. */
|
|
975
|
-
function execSteps(args) {
|
|
976
|
-
return programSteps(args.slice(skipOptions(args, 0, EXEC_VALUED).index));
|
|
977
|
-
}
|
|
978
|
-
function managerSteps(manager, args) {
|
|
979
|
-
const valued = new Set(TARGET_VALUED);
|
|
980
|
-
if (manager === "npm") valued.add("-w");
|
|
981
|
-
const first = skipOptions(args, 0, valued);
|
|
982
|
-
const verb = args[first.index];
|
|
983
|
-
if (verb === void 0) return [];
|
|
984
|
-
if (EXEC_VERBS.has(verb)) return execSteps(args.slice(first.index + 1));
|
|
985
|
-
if (verb === "run" || verb === "run-script") {
|
|
986
|
-
const second = skipOptions(args, first.index + 1, valued);
|
|
987
|
-
const name = args[second.index];
|
|
988
|
-
return name === void 0 ? [] : [{
|
|
989
|
-
kind: "script",
|
|
990
|
-
names: [name],
|
|
991
|
-
elsewhere: first.elsewhere || second.elsewhere
|
|
992
|
-
}];
|
|
993
|
-
}
|
|
994
|
-
if (isTsc(verb)) return programSteps(args.slice(first.index));
|
|
995
|
-
if (manager === "npm" && !NPM_BUILTINS.has(verb)) return [];
|
|
996
|
-
return [{
|
|
997
|
-
kind: "script",
|
|
998
|
-
names: [verb],
|
|
999
|
-
elsewhere: first.elsewhere
|
|
1000
|
-
}];
|
|
1001
|
-
}
|
|
1002
|
-
function runAllSteps(args) {
|
|
1003
|
-
const names = [];
|
|
1004
|
-
for (let index = 0; index < args.length && args[index] !== "--"; index++) if (!args[index].startsWith("-")) names.push(args[index]);
|
|
1005
|
-
else if (RUN_ALL_VALUED.has(args[index])) index++;
|
|
1006
|
-
return names.length === 0 ? [] : [{
|
|
1007
|
-
kind: "script",
|
|
1008
|
-
names,
|
|
1009
|
-
elsewhere: false
|
|
1010
|
-
}];
|
|
1011
|
-
}
|
|
1012
|
-
/** The line without its leading environment assignments and wrappers (`cross-env A=1`, `env`, `corepack`). */
|
|
1013
|
-
function unwrapped(line) {
|
|
1014
|
-
let index = 0;
|
|
1015
|
-
let wrapped = false;
|
|
1016
|
-
while (index < line.length) {
|
|
1017
|
-
const word = line[index];
|
|
1018
|
-
if (WRAPPERS.has(word)) wrapped = true;
|
|
1019
|
-
else if (!ENV_ASSIGNMENT.test(word) && !(wrapped && word.startsWith("-"))) break;
|
|
1020
|
-
index++;
|
|
1021
|
-
}
|
|
1022
|
-
return line.slice(index);
|
|
1023
|
-
}
|
|
1024
|
-
function lineSteps(line) {
|
|
1025
|
-
const [head, ...args] = unwrapped(line);
|
|
1026
|
-
if (head === void 0) return [];
|
|
1027
|
-
if (RUN_ALL.has(head)) return runAllSteps(args);
|
|
1028
|
-
if (MANAGERS.has(head)) return managerSteps(head, args);
|
|
1029
|
-
if (EXEC_RUNNERS.has(head)) return execSteps(args);
|
|
1030
|
-
return programSteps([head, ...args]);
|
|
1031
|
-
}
|
|
1032
|
-
/** The scripts and `tsc` runs a script's command lines start. */
|
|
1033
|
-
function stepsOf(script) {
|
|
1034
|
-
return lines(script).flatMap(lineSteps);
|
|
1035
|
-
}
|
|
1036
|
-
/** The script names a `run-s` pattern list selects among `available`. */
|
|
1037
|
-
function matchingScripts(names, available) {
|
|
1038
|
-
const all = [...available];
|
|
1039
|
-
return names.flatMap((name) => {
|
|
1040
|
-
if (!name.includes("*")) return [name];
|
|
1041
|
-
const pattern = new RegExp(`^${name.split("**").map((part) => part.split("*").map((piece) => piece.replace(/[.+?^${}()|[\]\\]/gu, "\\$&")).join("[^:]*")).join(".*")}$`, "u");
|
|
1042
|
-
return all.filter((script) => pattern.test(script));
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
//#endregion
|
|
1046
514
|
//#region src/guardrails/tsc-invocation.ts
|
|
1047
515
|
const ROOT_PROGRAM = "tsconfig.json";
|
|
1048
516
|
function normalizeProgram(project) {
|
|
@@ -1181,7 +649,7 @@ function reach(scripts, name, extra = []) {
|
|
|
1181
649
|
})));
|
|
1182
650
|
for (const { text, depth } of queue) for (const step of stepsOf(text)) {
|
|
1183
651
|
if (step.kind !== "script") continue;
|
|
1184
|
-
for (const script of matchingScripts(step.names, scripts.keys())) if (step.
|
|
652
|
+
for (const script of matchingScripts(step.names, scripts.keys())) if (step.targets.length) reached.elsewhere.add(script);
|
|
1185
653
|
else enter(script, depth + 1);
|
|
1186
654
|
}
|
|
1187
655
|
return reached;
|
|
@@ -1955,10 +1423,176 @@ function syncRepository(root, options = {}) {
|
|
|
1955
1423
|
};
|
|
1956
1424
|
}
|
|
1957
1425
|
//#endregion
|
|
1426
|
+
//#region src/guardrails/init.ts
|
|
1427
|
+
/** The `gh` arguments that turn `delete_branch_on_merge` on; `gh` fills `{owner}/{repo}` from the git remote. */
|
|
1428
|
+
const ENABLE_ARGS = [
|
|
1429
|
+
"api",
|
|
1430
|
+
"-X",
|
|
1431
|
+
"PATCH",
|
|
1432
|
+
"repos/{owner}/{repo}",
|
|
1433
|
+
"-F",
|
|
1434
|
+
"delete_branch_on_merge=true"
|
|
1435
|
+
];
|
|
1436
|
+
/** The command a person runs when `--init` could not turn `delete_branch_on_merge` on. */
|
|
1437
|
+
const ENABLE_BRANCH_CLEANUP = `gh ${ENABLE_ARGS.join(" ")}`;
|
|
1438
|
+
const NODE_MODULES_LINE = /^(?:\*\*\/|\/)?node_modules\/?$/;
|
|
1439
|
+
/** Creates `.gitignore` or appends `node_modules` to it, keeping every existing line; returns whether it wrote. */
|
|
1440
|
+
function ensureGitignore(root) {
|
|
1441
|
+
const path = join(root, ".gitignore");
|
|
1442
|
+
const current = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
1443
|
+
if (current.split(/\r?\n/).some((line) => NODE_MODULES_LINE.test(line.trim()))) return false;
|
|
1444
|
+
const newline = current.includes("\r\n") ? "\r\n" : "\n";
|
|
1445
|
+
const separator = current === "" || current.endsWith("\n") ? "" : newline;
|
|
1446
|
+
writeFileSync(path, `${current}${separator}node_modules${newline}`);
|
|
1447
|
+
return true;
|
|
1448
|
+
}
|
|
1449
|
+
function failureText(result) {
|
|
1450
|
+
if (result.error) return "code" in result.error && result.error.code === "ENOENT" ? "gh is not installed" : result.error.message;
|
|
1451
|
+
return result.stderr.trim().split("\n")[0] || `gh exited with ${result.status ?? result.signal}`;
|
|
1452
|
+
}
|
|
1453
|
+
function gh(root, args) {
|
|
1454
|
+
return spawnSync("gh", args, {
|
|
1455
|
+
cwd: root,
|
|
1456
|
+
encoding: "utf8"
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
/** Turns `delete_branch_on_merge` on through `gh`, reading it first so a repository that has it on is never written. */
|
|
1460
|
+
function ensureBranchCleanup(root) {
|
|
1461
|
+
const read = gh(root, [
|
|
1462
|
+
"api",
|
|
1463
|
+
"repos/{owner}/{repo}",
|
|
1464
|
+
"--jq",
|
|
1465
|
+
".delete_branch_on_merge"
|
|
1466
|
+
]);
|
|
1467
|
+
if (read.error || read.status !== 0) return {
|
|
1468
|
+
kind: "unavailable",
|
|
1469
|
+
reason: failureText(read)
|
|
1470
|
+
};
|
|
1471
|
+
const state = read.stdout.trim();
|
|
1472
|
+
if (state === "true") return { kind: "on" };
|
|
1473
|
+
if (state !== "false") return {
|
|
1474
|
+
kind: "unavailable",
|
|
1475
|
+
reason: `gh answered ${JSON.stringify(state)}`
|
|
1476
|
+
};
|
|
1477
|
+
const write = gh(root, ENABLE_ARGS);
|
|
1478
|
+
return write.error || write.status !== 0 ? {
|
|
1479
|
+
kind: "unavailable",
|
|
1480
|
+
reason: failureText(write)
|
|
1481
|
+
} : { kind: "enabled" };
|
|
1482
|
+
}
|
|
1483
|
+
/** Runs the package manager's install quietly; returns its output only when it failed. */
|
|
1484
|
+
function install(root, manager) {
|
|
1485
|
+
const result = spawnSync(manager, ["install"], {
|
|
1486
|
+
cwd: root,
|
|
1487
|
+
encoding: "utf8"
|
|
1488
|
+
});
|
|
1489
|
+
if (result.error) return `${manager} install failed: ${result.error.message}`;
|
|
1490
|
+
if (result.status === 0) return void 0;
|
|
1491
|
+
return `${manager} install failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd();
|
|
1492
|
+
}
|
|
1493
|
+
function resolveOxfmt(root) {
|
|
1494
|
+
const require = createRequire(join(root, "package.json"));
|
|
1495
|
+
return join(dirname(require.resolve("oxfmt/package.json")), "bin/oxfmt");
|
|
1496
|
+
}
|
|
1497
|
+
/** Formats `package.json` with the repository's installed oxfmt, which sorts the keys init and sync append out of order; returns its output only when it failed. */
|
|
1498
|
+
function formatManifest(root) {
|
|
1499
|
+
let binary;
|
|
1500
|
+
try {
|
|
1501
|
+
binary = resolveOxfmt(root);
|
|
1502
|
+
} catch {
|
|
1503
|
+
return "oxfmt is not installed in this repository, so package.json is not formatted.";
|
|
1504
|
+
}
|
|
1505
|
+
const result = spawnSync(process.execPath, [
|
|
1506
|
+
binary,
|
|
1507
|
+
"--no-error-on-unmatched-pattern",
|
|
1508
|
+
"package.json"
|
|
1509
|
+
], {
|
|
1510
|
+
cwd: root,
|
|
1511
|
+
encoding: "utf8"
|
|
1512
|
+
});
|
|
1513
|
+
if (result.error) return `oxfmt failed: ${result.error.message}`;
|
|
1514
|
+
if (result.status === 0) return void 0;
|
|
1515
|
+
return `oxfmt failed (exit ${result.status}).\n${result.stdout}${result.stderr}`.trimEnd();
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Onboards a repository in one run: `node_modules` in `.gitignore`, the pack,
|
|
1519
|
+
* oxlint and oxfmt as devDependencies, an install, a full-profile sync, a second
|
|
1520
|
+
* install when sync added devDependencies, `package.json` formatted by oxfmt,
|
|
1521
|
+
* and `delete_branch_on_merge` on GitHub, which runs whatever the file steps did.
|
|
1522
|
+
* Every step is idempotent, so a second run changes nothing.
|
|
1523
|
+
*/
|
|
1524
|
+
function initRepository(root, options = {}) {
|
|
1525
|
+
const path = join(root, "package.json");
|
|
1526
|
+
if (!existsSync(path)) throw new Error("package.json is missing. antelopejs-sync --init needs a repository that already has one.");
|
|
1527
|
+
const current = readFileSync(path, "utf8");
|
|
1528
|
+
const manifest = parseManifest(current);
|
|
1529
|
+
const manager = packageManager(manifest);
|
|
1530
|
+
const paths = [];
|
|
1531
|
+
if (ensureGitignore(root)) paths.push(".gitignore");
|
|
1532
|
+
const added = bootstrapDependencies(manifest, toolingVersions());
|
|
1533
|
+
if (added.length) {
|
|
1534
|
+
writeFileSync(path, withDevDependencies(current, added));
|
|
1535
|
+
paths.push("package.json");
|
|
1536
|
+
}
|
|
1537
|
+
const first = install(root, manager);
|
|
1538
|
+
if (first !== void 0) return {
|
|
1539
|
+
paths,
|
|
1540
|
+
failure: first,
|
|
1541
|
+
sync: void 0,
|
|
1542
|
+
branchCleanup: ensureBranchCleanup(root)
|
|
1543
|
+
};
|
|
1544
|
+
const sync = syncRepository(root, {
|
|
1545
|
+
profile: "full",
|
|
1546
|
+
verify: options.verify
|
|
1547
|
+
});
|
|
1548
|
+
let failure;
|
|
1549
|
+
if (!sync.errors.length) {
|
|
1550
|
+
failure = sync.dependenciesAdded ? install(root, manager) : void 0;
|
|
1551
|
+
const unformatted = readFileSync(path, "utf8");
|
|
1552
|
+
failure ??= formatManifest(root);
|
|
1553
|
+
if (readFileSync(path, "utf8") !== unformatted && !paths.includes("package.json")) paths.push("package.json");
|
|
1554
|
+
}
|
|
1555
|
+
return {
|
|
1556
|
+
paths,
|
|
1557
|
+
failure,
|
|
1558
|
+
sync,
|
|
1559
|
+
branchCleanup: ensureBranchCleanup(root)
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
//#endregion
|
|
1958
1563
|
//#region src/bin/sync.ts
|
|
1564
|
+
function printSync(result, { check, installed }) {
|
|
1565
|
+
for (const note of result.notes) process.stdout.write(`Note: ${check || result.errors.length ? "Planned migration. " : ""}${note}\n`);
|
|
1566
|
+
for (const note of result.verifyNotes) process.stdout.write(`Note: ${note}\n`);
|
|
1567
|
+
for (const advisory of result.advisories) process.stdout.write(`${advisory}\n`);
|
|
1568
|
+
for (const error of result.errors) process.stderr.write(`${error}\n`);
|
|
1569
|
+
if (result.errors.length) return 1;
|
|
1570
|
+
for (const path of result.paths) process.stdout.write(check ? `Drift: ${path}; run antelopejs-sync\n` : `${result.removed.includes(path) ? "Removed" : "Updated"}: ${path}\n`);
|
|
1571
|
+
if (!result.paths.length) process.stdout.write("Guardrails are in sync.\n");
|
|
1572
|
+
if (!check && !installed && result.dependenciesAdded) process.stdout.write("Added devDependencies. Run install with your package manager before using the hooks or checks.\n");
|
|
1573
|
+
return check && result.paths.length ? 1 : 0;
|
|
1574
|
+
}
|
|
1575
|
+
function init(verify) {
|
|
1576
|
+
const result = initRepository(repositoryRoot(), { verify });
|
|
1577
|
+
const reportedBySync = result.sync && !result.sync.errors.length ? result.sync.paths : [];
|
|
1578
|
+
for (const path of result.paths) if (!reportedBySync.includes(path)) process.stdout.write(`Updated: ${path}\n`);
|
|
1579
|
+
const synced = result.sync ? printSync(result.sync, {
|
|
1580
|
+
check: false,
|
|
1581
|
+
installed: true
|
|
1582
|
+
}) : 0;
|
|
1583
|
+
if (result.failure !== void 0) process.stderr.write(`${result.failure}\n`);
|
|
1584
|
+
const failed = synced !== 0 || result.failure !== void 0;
|
|
1585
|
+
if (failed) process.stderr.write("Fix the errors above, then rerun antelopejs-sync --init.\n");
|
|
1586
|
+
else process.stdout.write(`Commit and push to the default branch so ${CI_CONTEXT} is reported.\n`);
|
|
1587
|
+
const cleanup = result.branchCleanup;
|
|
1588
|
+
if (cleanup.kind === "enabled") process.stdout.write("Updated: delete_branch_on_merge on GitHub\n");
|
|
1589
|
+
if (cleanup.kind === "unavailable") process.stderr.write(`delete_branch_on_merge is not on (${cleanup.reason}). Run: ${ENABLE_BRANCH_CLEANUP}\n`);
|
|
1590
|
+
return failed || cleanup.kind === "unavailable" ? 1 : 0;
|
|
1591
|
+
}
|
|
1959
1592
|
runCli(() => {
|
|
1960
1593
|
const { values } = parseArgs({ options: {
|
|
1961
1594
|
check: { type: "boolean" },
|
|
1595
|
+
init: { type: "boolean" },
|
|
1962
1596
|
profile: {
|
|
1963
1597
|
type: "string",
|
|
1964
1598
|
default: "full"
|
|
@@ -1967,20 +1601,16 @@ runCli(() => {
|
|
|
1967
1601
|
} });
|
|
1968
1602
|
if (values.profile !== "full" && values.profile !== "template") throw new Error("--profile must be full or template.");
|
|
1969
1603
|
if (values.verify !== void 0 && !isVerifyChoice(values.verify)) throw new Error("--verify must be interface, module, template, or custom.");
|
|
1970
|
-
|
|
1604
|
+
if (values.init && (values.check || values.profile === "template")) throw new Error("--init sets up a full-profile repository; it cannot be combined with --check or --profile template.");
|
|
1605
|
+
if (values.init) return init(values.verify);
|
|
1606
|
+
return printSync(syncRepository(repositoryRoot(), {
|
|
1971
1607
|
check: values.check,
|
|
1972
1608
|
profile: values.profile,
|
|
1973
1609
|
verify: values.verify
|
|
1610
|
+
}), {
|
|
1611
|
+
check: Boolean(values.check),
|
|
1612
|
+
installed: false
|
|
1974
1613
|
});
|
|
1975
|
-
for (const note of result.notes) process.stdout.write(`Note: ${values.check || result.errors.length ? "Planned migration. " : ""}${note}\n`);
|
|
1976
|
-
for (const note of result.verifyNotes) process.stdout.write(`Note: ${note}\n`);
|
|
1977
|
-
for (const advisory of result.advisories) process.stdout.write(`${advisory}\n`);
|
|
1978
|
-
for (const error of result.errors) process.stderr.write(`${error}\n`);
|
|
1979
|
-
if (result.errors.length) return 1;
|
|
1980
|
-
for (const path of result.paths) process.stdout.write(values.check ? `Drift: ${path}; run antelopejs-sync\n` : `${result.removed.includes(path) ? "Removed" : "Updated"}: ${path}\n`);
|
|
1981
|
-
if (!result.paths.length) process.stdout.write("Guardrails are in sync.\n");
|
|
1982
|
-
if (!values.check && result.dependenciesAdded) process.stdout.write("Added devDependencies. Run install with your package manager before using the hooks or checks.\n");
|
|
1983
|
-
return values.check && result.paths.length ? 1 : 0;
|
|
1984
1614
|
});
|
|
1985
1615
|
//#endregion
|
|
1986
1616
|
export {};
|