@marktiderman/genesis-cli 1.21.0 → 1.22.1
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 +142 -9
- package/dist/cli.js +1026 -101
- package/dist/cli.js.map +1 -1
- package/dist/{config-Dj_f9T7J.d.ts → config-HOmiOLQc.d.ts} +2 -0
- package/dist/doctor.d.ts +10 -5
- package/dist/doctor.js +1502 -1115
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +10 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +69 -18
- package/dist/index.d.ts +114 -2
- package/dist/index.js +1525 -1119
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +4 -4
- package/dist/starter/__tests__/starter.test.ts +9 -0
- package/dist/starter/pnpm-workspace.yaml +22 -0
- package/dist/starter/src/lib/check-in.ts +5 -3
- package/dist/starter/src/lib/native-modules.ts +4 -1
- package/dist/starter/supabase/migrations/20261025000090_genesis_chat_attachment_paths.sql +80 -0
- package/dist/starter/supabase/tests/database/genesis_chat_attachment_paths.test.sql +111 -0
- package/dist/vite.js +1501 -1114
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { createRequire, builtinModules } from 'module';
|
|
2
2
|
import { studioSetupSql } from '@marktiderman/genesis-studio-server';
|
|
3
|
-
import * as
|
|
3
|
+
import * as path21 from 'path';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
|
-
import { existsSync, readFileSync, statSync, realpathSync,
|
|
5
|
+
import { existsSync, readFileSync, readdirSync, statSync, realpathSync, lstatSync } from 'fs';
|
|
6
|
+
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
6
7
|
import { createHash } from 'crypto';
|
|
7
8
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
8
9
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
9
|
-
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
10
10
|
import { createJiti } from 'jiti';
|
|
11
11
|
import 'os';
|
|
12
12
|
|
|
13
13
|
var __defProp = Object.defineProperty;
|
|
14
14
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
-
var __esm = (fn, res) => function __init() {
|
|
16
|
-
|
|
15
|
+
var __esm = (fn, res, err) => function __init() {
|
|
16
|
+
if (err) throw err[0];
|
|
17
|
+
try {
|
|
18
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw err = [e], e;
|
|
21
|
+
}
|
|
17
22
|
};
|
|
18
23
|
var __export = (target, all) => {
|
|
19
24
|
for (var name in all)
|
|
@@ -456,14 +461,14 @@ function inherit(own, source) {
|
|
|
456
461
|
}
|
|
457
462
|
function resolveViews(relations) {
|
|
458
463
|
const done = /* @__PURE__ */ new Set();
|
|
459
|
-
const
|
|
464
|
+
const resolve18 = (relation, depth) => {
|
|
460
465
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
461
466
|
done.add(relation.oid);
|
|
462
467
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
463
468
|
if (sources.size !== 1) return;
|
|
464
469
|
const source = relations.get([...sources][0]);
|
|
465
470
|
if (!source) return;
|
|
466
|
-
|
|
471
|
+
resolve18(source, depth + 1);
|
|
467
472
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
468
473
|
for (const [attnum, origin] of relation.origins) {
|
|
469
474
|
const own = relation.columns.get(attnum);
|
|
@@ -486,7 +491,7 @@ function resolveViews(relations) {
|
|
|
486
491
|
};
|
|
487
492
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
488
493
|
};
|
|
489
|
-
for (const relation of relations.values())
|
|
494
|
+
for (const relation of relations.values()) resolve18(relation, 0);
|
|
490
495
|
}
|
|
491
496
|
async function introspectPostgres(sql, schemas, options = {}) {
|
|
492
497
|
const relations = /* @__PURE__ */ new Map();
|
|
@@ -816,9 +821,9 @@ async function runScaffold(opts, fs) {
|
|
|
816
821
|
function joinPath(...parts) {
|
|
817
822
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
818
823
|
}
|
|
819
|
-
function dirname(
|
|
820
|
-
const idx =
|
|
821
|
-
return idx === -1 ? "." :
|
|
824
|
+
function dirname(path48) {
|
|
825
|
+
const idx = path48.lastIndexOf("/");
|
|
826
|
+
return idx === -1 ? "." : path48.slice(0, idx);
|
|
822
827
|
}
|
|
823
828
|
function brandPackageJson(consumer, genesisVersion) {
|
|
824
829
|
return JSON.stringify(
|
|
@@ -1076,8 +1081,8 @@ function routeTags(source) {
|
|
|
1076
1081
|
var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
|
|
1077
1082
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
1078
1083
|
const tags = routeTags(source);
|
|
1079
|
-
const
|
|
1080
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
1084
|
+
const relative13 = route.replace(/^\//, "");
|
|
1085
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative13.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
1081
1086
|
if (existing) {
|
|
1082
1087
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
1083
1088
|
}
|
|
@@ -1085,17 +1090,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
1085
1090
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
1086
1091
|
if (roots.length !== 1) {
|
|
1087
1092
|
return {
|
|
1088
|
-
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${
|
|
1093
|
+
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative13}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
1089
1094
|
};
|
|
1090
1095
|
}
|
|
1091
1096
|
const layout = roots[0];
|
|
1092
1097
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
1093
|
-
if (base && !
|
|
1098
|
+
if (base && !relative13.startsWith(`${base}/`)) {
|
|
1094
1099
|
return {
|
|
1095
1100
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
1096
1101
|
};
|
|
1097
1102
|
}
|
|
1098
|
-
const childPath = base ?
|
|
1103
|
+
const childPath = base ? relative13.slice(base.length + 1) : relative13;
|
|
1099
1104
|
const guard = GUARD.exec(source)?.[1];
|
|
1100
1105
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
1101
1106
|
const before = source.slice(0, layout.close);
|
|
@@ -1409,19 +1414,19 @@ ${line}
|
|
|
1409
1414
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
1410
1415
|
function buildCommands(root, config) {
|
|
1411
1416
|
if (config.build) return config.build;
|
|
1412
|
-
const pkgFile =
|
|
1417
|
+
const pkgFile = path21.join(root, "package.json");
|
|
1413
1418
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
1414
1419
|
const pm = packageManager(root);
|
|
1415
1420
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
1416
1421
|
}
|
|
1417
1422
|
function packageManager(root) {
|
|
1418
|
-
let dir =
|
|
1423
|
+
let dir = path21.resolve(root);
|
|
1419
1424
|
for (; ; ) {
|
|
1420
|
-
if (existsSync(
|
|
1421
|
-
if (existsSync(
|
|
1422
|
-
if (existsSync(
|
|
1423
|
-
if (existsSync(
|
|
1424
|
-
const parent =
|
|
1425
|
+
if (existsSync(path21.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1426
|
+
if (existsSync(path21.join(dir, "bun.lock")) || existsSync(path21.join(dir, "bun.lockb"))) return "bun";
|
|
1427
|
+
if (existsSync(path21.join(dir, "yarn.lock"))) return "yarn";
|
|
1428
|
+
if (existsSync(path21.join(dir, "package-lock.json"))) return "npm";
|
|
1429
|
+
const parent = path21.dirname(dir);
|
|
1425
1430
|
if (parent === dir) return "npm";
|
|
1426
1431
|
dir = parent;
|
|
1427
1432
|
}
|
|
@@ -1536,25 +1541,25 @@ var PACK_KEYS = {
|
|
|
1536
1541
|
};
|
|
1537
1542
|
function appPath(v, where2, fail) {
|
|
1538
1543
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
1539
|
-
if (
|
|
1540
|
-
const norm =
|
|
1544
|
+
if (path21.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
1545
|
+
const norm = path21.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1541
1546
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
1542
1547
|
return norm;
|
|
1543
1548
|
}
|
|
1544
1549
|
function loadConfig(root, configPath) {
|
|
1545
1550
|
if (configPath) {
|
|
1546
|
-
const file =
|
|
1551
|
+
const file = path21.resolve(root, configPath);
|
|
1547
1552
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
1548
1553
|
const json = readJson(file);
|
|
1549
|
-
const block =
|
|
1550
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
1554
|
+
const block = path21.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
1555
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path21.dirname(file) };
|
|
1551
1556
|
}
|
|
1552
|
-
const own =
|
|
1557
|
+
const own = path21.join(root, "genesis.config.json");
|
|
1553
1558
|
if (existsSync(own)) {
|
|
1554
1559
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
1555
1560
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
1556
1561
|
}
|
|
1557
|
-
const pkg =
|
|
1562
|
+
const pkg = path21.join(root, "package.json");
|
|
1558
1563
|
if (existsSync(pkg)) {
|
|
1559
1564
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
1560
1565
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -1563,7 +1568,7 @@ function loadConfig(root, configPath) {
|
|
|
1563
1568
|
}
|
|
1564
1569
|
function doctorBlock(json, file, explicit) {
|
|
1565
1570
|
const j = json;
|
|
1566
|
-
if (
|
|
1571
|
+
if (path21.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
1567
1572
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
1568
1573
|
}
|
|
1569
1574
|
function isPackageDeclaration(block) {
|
|
@@ -1580,7 +1585,7 @@ function readJson(file) {
|
|
|
1580
1585
|
}
|
|
1581
1586
|
}
|
|
1582
1587
|
function readGenesisConfig(root) {
|
|
1583
|
-
const file =
|
|
1588
|
+
const file = path21.join(root, "genesis.config.json");
|
|
1584
1589
|
if (!existsSync(file)) return null;
|
|
1585
1590
|
const raw = readJson(file);
|
|
1586
1591
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -1591,8 +1596,18 @@ function readGenesisConfig(root) {
|
|
|
1591
1596
|
const supabase = validateSupabase(raw.supabase, file);
|
|
1592
1597
|
if (supabase !== true) out.supabase = supabase;
|
|
1593
1598
|
}
|
|
1599
|
+
if (raw.appFolder !== void 0) out.appFolder = validateAppFolder(raw.appFolder, file);
|
|
1594
1600
|
return out;
|
|
1595
1601
|
}
|
|
1602
|
+
var PLAIN_FOLDER = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}(?:\/[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}){0,7}$/;
|
|
1603
|
+
function isPlainFolder(value) {
|
|
1604
|
+
return PLAIN_FOLDER.test(value) && !value.split("/").includes("..");
|
|
1605
|
+
}
|
|
1606
|
+
function validateAppFolder(raw, source = "config") {
|
|
1607
|
+
const norm = typeof raw === "string" ? raw.replace(/^\.\//, "").replace(/\/+$/, "") : "";
|
|
1608
|
+
if (!isPlainFolder(norm)) throw new GenesisConfigError(`${source}: "appFolder" must be the app's folder from the repository root, such as "mobile" or "apps/phone" (got ${JSON.stringify(raw)})`);
|
|
1609
|
+
return norm;
|
|
1610
|
+
}
|
|
1596
1611
|
function validateSupabase(raw, source = "config") {
|
|
1597
1612
|
const fail = (msg) => {
|
|
1598
1613
|
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
@@ -1602,8 +1617,8 @@ function validateSupabase(raw, source = "config") {
|
|
|
1602
1617
|
for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
|
|
1603
1618
|
const app = raw.app;
|
|
1604
1619
|
if (typeof app !== "string" || !app.trim()) return fail(`supabase.app must be the folder of the app that holds supabase/, relative to this one (e.g. "../app")`);
|
|
1605
|
-
if (
|
|
1606
|
-
const norm =
|
|
1620
|
+
if (path21.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
|
|
1621
|
+
const norm = path21.posix.normalize(app).replace(/\/+$/, "");
|
|
1607
1622
|
if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
|
|
1608
1623
|
return { app: norm };
|
|
1609
1624
|
}
|
|
@@ -1763,7 +1778,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1763
1778
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1764
1779
|
if (contracts.out !== void 0) {
|
|
1765
1780
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1766
|
-
if (
|
|
1781
|
+
if (path21.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1767
1782
|
}
|
|
1768
1783
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1769
1784
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1831,429 +1846,126 @@ function globToRegExp(glob) {
|
|
|
1831
1846
|
}
|
|
1832
1847
|
function globMatcher(globs) {
|
|
1833
1848
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1834
|
-
return (
|
|
1849
|
+
return (path48) => res.some((re) => re.test(path48));
|
|
1835
1850
|
}
|
|
1836
|
-
var
|
|
1837
|
-
var
|
|
1838
|
-
var
|
|
1839
|
-
var
|
|
1840
|
-
var
|
|
1841
|
-
var
|
|
1842
|
-
var
|
|
1843
|
-
var
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
"
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
"stone",
|
|
1851
|
-
"red",
|
|
1852
|
-
"orange",
|
|
1853
|
-
"amber",
|
|
1854
|
-
"yellow",
|
|
1855
|
-
"lime",
|
|
1856
|
-
"green",
|
|
1857
|
-
"emerald",
|
|
1858
|
-
"teal",
|
|
1859
|
-
"cyan",
|
|
1860
|
-
"sky",
|
|
1861
|
-
"blue",
|
|
1862
|
-
"indigo",
|
|
1863
|
-
"violet",
|
|
1864
|
-
"purple",
|
|
1865
|
-
"fuchsia",
|
|
1866
|
-
"pink",
|
|
1867
|
-
"rose",
|
|
1868
|
-
"taupe",
|
|
1869
|
-
"mauve",
|
|
1870
|
-
"mist",
|
|
1871
|
-
"olive"
|
|
1872
|
-
];
|
|
1873
|
-
function findPackageDir(from, name) {
|
|
1874
|
-
let dir = path20.resolve(from);
|
|
1875
|
-
for (; ; ) {
|
|
1876
|
-
const candidate = path20.join(dir, "node_modules", name);
|
|
1877
|
-
if (existsSync(path20.join(candidate, "package.json"))) return candidate;
|
|
1878
|
-
const parent = path20.dirname(dir);
|
|
1879
|
-
if (parent === dir) return null;
|
|
1880
|
-
dir = parent;
|
|
1851
|
+
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
1852
|
+
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
1853
|
+
var MIGRATION_FILE = /^(\d{4})_([a-z0-9_]+)\.sql$/;
|
|
1854
|
+
var FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
1855
|
+
var ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
|
|
1856
|
+
var INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
|
|
1857
|
+
var SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
1858
|
+
var SQL_FUNCTION = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/;
|
|
1859
|
+
var ManifestError = class extends Error {
|
|
1860
|
+
constructor(problems) {
|
|
1861
|
+
super(`Invalid block manifest:
|
|
1862
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
1863
|
+
this.problems = problems;
|
|
1864
|
+
this.name = "ManifestError";
|
|
1881
1865
|
}
|
|
1866
|
+
problems;
|
|
1867
|
+
};
|
|
1868
|
+
function safeRelative(value) {
|
|
1869
|
+
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
1870
|
+
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
1871
|
+
const segments = value.split("/");
|
|
1872
|
+
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
1873
|
+
return value;
|
|
1882
1874
|
}
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1889
|
-
if (!
|
|
1890
|
-
|
|
1891
|
-
const
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
1899
|
-
if (comp === false) rawTags.delete(tag);
|
|
1900
|
-
else rawTags.set(tag, comp);
|
|
1901
|
-
}
|
|
1902
|
-
return {
|
|
1903
|
-
uiPackage,
|
|
1904
|
-
uiVersion: pkg.version,
|
|
1905
|
-
exports: exportNames,
|
|
1906
|
-
values,
|
|
1907
|
-
components,
|
|
1908
|
-
tokens,
|
|
1909
|
-
rawTags,
|
|
1910
|
-
palette: loadPalette(root),
|
|
1911
|
-
companions: loadCompanions(root, config, uiPackage)
|
|
1875
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1876
|
+
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
1877
|
+
function parseManifest(home, id, raw, version, options = {}) {
|
|
1878
|
+
const problems = [];
|
|
1879
|
+
const at = `${home} genesis.blocks.${id}`;
|
|
1880
|
+
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
1881
|
+
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
1882
|
+
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
1883
|
+
const pkgOf = (value, where2) => {
|
|
1884
|
+
if (value === void 0) return home;
|
|
1885
|
+
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
1886
|
+
problems.push(`${where2}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
1887
|
+
return home;
|
|
1888
|
+
}
|
|
1889
|
+
return value;
|
|
1912
1890
|
};
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1891
|
+
const pathOf = (value, where2) => {
|
|
1892
|
+
const safe = safeRelative(value);
|
|
1893
|
+
if (!safe) problems.push(`${where2}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
1894
|
+
return safe ?? "";
|
|
1895
|
+
};
|
|
1896
|
+
const list = (key2) => {
|
|
1897
|
+
const v = raw[key2];
|
|
1898
|
+
if (v === void 0) return [];
|
|
1899
|
+
if (!Array.isArray(v)) {
|
|
1900
|
+
problems.push(`${at}.${key2}: must be a list`);
|
|
1901
|
+
return [];
|
|
1923
1902
|
}
|
|
1903
|
+
return v;
|
|
1904
|
+
};
|
|
1905
|
+
const requires = list("requires").filter((r) => {
|
|
1906
|
+
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
1907
|
+
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
1908
|
+
return ok;
|
|
1909
|
+
});
|
|
1910
|
+
let platforms;
|
|
1911
|
+
if (raw["platforms"] !== void 0) {
|
|
1912
|
+
platforms = list("platforms").filter((p) => {
|
|
1913
|
+
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
1914
|
+
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
1915
|
+
return ok;
|
|
1916
|
+
});
|
|
1924
1917
|
}
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
const
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
|
|
1937
|
-
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
1938
|
-
for (const target of subpaths) {
|
|
1939
|
-
const t = entryOf(target);
|
|
1940
|
-
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
1941
|
-
}
|
|
1942
|
-
const exportNames = /* @__PURE__ */ new Set();
|
|
1943
|
-
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1944
|
-
let readAny = false;
|
|
1945
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1946
|
-
const readEntry = (file) => {
|
|
1947
|
-
if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
|
|
1948
|
-
seen.add(file);
|
|
1949
|
-
readAny = true;
|
|
1950
|
-
const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
|
|
1951
|
-
for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
|
|
1952
|
-
for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
1953
|
-
reexportedPackages.add(packageName(m[1]));
|
|
1918
|
+
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
1919
|
+
const install = list("install").filter((s) => {
|
|
1920
|
+
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
1921
|
+
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
1922
|
+
return ok;
|
|
1923
|
+
});
|
|
1924
|
+
const migrations = list("migrations").map((m, i) => {
|
|
1925
|
+
const where2 = `${at}.migrations[${i}]`;
|
|
1926
|
+
if (!isObject2(m)) {
|
|
1927
|
+
problems.push(`${where2}: must be an object`);
|
|
1928
|
+
return { package: home, file: "" };
|
|
1954
1929
|
}
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1930
|
+
const file = pathOf(m["file"], `${where2}.file`);
|
|
1931
|
+
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
1932
|
+
const out = { package: pkgOf(m["package"], where2), file };
|
|
1933
|
+
if (m["provides"] !== void 0) {
|
|
1934
|
+
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
1935
|
+
else {
|
|
1936
|
+
out.provides = m["provides"].map((p, j) => {
|
|
1937
|
+
const at2 = `${where2}.provides[${j}]`;
|
|
1938
|
+
if (!isObject2(p)) {
|
|
1939
|
+
problems.push(`${at2}: must be an object`);
|
|
1940
|
+
return { package: home, file: "" };
|
|
1941
|
+
}
|
|
1942
|
+
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
1943
|
+
if (p["functions"] !== void 0) {
|
|
1944
|
+
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
1945
|
+
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
1946
|
+
}
|
|
1947
|
+
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
1948
|
+
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
1949
|
+
return provided;
|
|
1950
|
+
});
|
|
1959
1951
|
}
|
|
1960
1952
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
for (const m of text.matchAll(/\b(?:declare\s+)?(?:const|let|var|function|class|enum)\s+([A-Za-z_$][\w$]*)/g)) valueDecls.add(m[1]);
|
|
1978
|
-
for (const m of text.matchAll(/\b(?:interface|type)\s+([A-Za-z_$][\w$]*)/g)) typeDecls.add(m[1]);
|
|
1979
|
-
}
|
|
1980
|
-
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
1981
|
-
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
1982
|
-
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
1983
|
-
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
1984
|
-
}
|
|
1985
|
-
function parseExportNames(dts) {
|
|
1986
|
-
const names = [];
|
|
1987
|
-
for (const m of dts.matchAll(/export\s+(?:type\s+)?\{([^}]*)\}/g)) {
|
|
1988
|
-
for (const part of m[1].split(",")) {
|
|
1989
|
-
const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
1990
|
-
if (name && name !== "default") names.push(name);
|
|
1991
|
-
}
|
|
1992
|
-
}
|
|
1993
|
-
for (const m of dts.matchAll(/export\s+(?:declare\s+)?(?:const|let|function|class|enum|interface|type)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
1994
|
-
names.push(m[1]);
|
|
1995
|
-
}
|
|
1996
|
-
return names;
|
|
1997
|
-
}
|
|
1998
|
-
function declaredTokens(css) {
|
|
1999
|
-
return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
|
|
2000
|
-
}
|
|
2001
|
-
function packageName(specifier) {
|
|
2002
|
-
const parts = specifier.split("/");
|
|
2003
|
-
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
2004
|
-
}
|
|
2005
|
-
function parseSourceExportNames(code) {
|
|
2006
|
-
const names = parseExportNames(code);
|
|
2007
|
-
for (const m of code.matchAll(/export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:var|class|function\*?)\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
2008
|
-
for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
2009
|
-
return [...new Set(names)];
|
|
2010
|
-
}
|
|
2011
|
-
var TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
2012
|
-
var isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
|
|
2013
|
-
function exportSource(target) {
|
|
2014
|
-
if (isTsSource(target)) return target;
|
|
2015
|
-
if (!target || typeof target !== "object") return void 0;
|
|
2016
|
-
for (const value of Object.values(target)) {
|
|
2017
|
-
const nested = exportSource(value);
|
|
2018
|
-
if (nested) return nested;
|
|
2019
|
-
}
|
|
2020
|
-
return void 0;
|
|
2021
|
-
}
|
|
2022
|
-
function resolveSource(dir, spec) {
|
|
2023
|
-
const base = path20.resolve(dir, spec.replace(/\.js$/, ""));
|
|
2024
|
-
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path20.join(base, i))];
|
|
2025
|
-
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
2026
|
-
}
|
|
2027
|
-
function insidePackage(dir, file) {
|
|
2028
|
-
const rel = path20.relative(path20.resolve(dir), path20.resolve(file));
|
|
2029
|
-
return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
2030
|
-
}
|
|
2031
|
-
function stripComments(code) {
|
|
2032
|
-
let out = "";
|
|
2033
|
-
let i = 0;
|
|
2034
|
-
while (i < code.length) {
|
|
2035
|
-
const c = code[i];
|
|
2036
|
-
const next = code[i + 1];
|
|
2037
|
-
if (c === "/" && next === "*") {
|
|
2038
|
-
const end = code.indexOf("*/", i + 2);
|
|
2039
|
-
const stop = end < 0 ? code.length : end + 2;
|
|
2040
|
-
out += code.slice(i, stop).replace(/[^\n]/g, " ");
|
|
2041
|
-
i = stop;
|
|
2042
|
-
} else if (c === "/" && next === "/") {
|
|
2043
|
-
const end = code.indexOf("\n", i);
|
|
2044
|
-
i = end < 0 ? code.length : end;
|
|
2045
|
-
} else if (c === '"' || c === "'" || c === "`") {
|
|
2046
|
-
let j = i + 1;
|
|
2047
|
-
while (j < code.length && code[j] !== c) {
|
|
2048
|
-
if (code[j] === "\\") j++;
|
|
2049
|
-
else if (c !== "`" && code[j] === "\n") break;
|
|
2050
|
-
j++;
|
|
2051
|
-
}
|
|
2052
|
-
out += code.slice(i, j + 1);
|
|
2053
|
-
i = j + 1;
|
|
2054
|
-
} else {
|
|
2055
|
-
out += c;
|
|
2056
|
-
i++;
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
return out;
|
|
2060
|
-
}
|
|
2061
|
-
function walkSource(dir, out = []) {
|
|
2062
|
-
if (!existsSync(dir)) return out;
|
|
2063
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2064
|
-
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
2065
|
-
const p = path20.join(dir, entry.name);
|
|
2066
|
-
if (entry.isDirectory()) walkSource(p, out);
|
|
2067
|
-
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
2068
|
-
}
|
|
2069
|
-
return out;
|
|
2070
|
-
}
|
|
2071
|
-
function exportTypes(target) {
|
|
2072
|
-
if (!target || typeof target !== "object") return void 0;
|
|
2073
|
-
const t = target;
|
|
2074
|
-
if (typeof t.types === "string") return t.types;
|
|
2075
|
-
for (const key2 of ["import", "default", "require"]) {
|
|
2076
|
-
const nested = exportTypes(t[key2]);
|
|
2077
|
-
if (nested) return nested;
|
|
2078
|
-
}
|
|
2079
|
-
return void 0;
|
|
2080
|
-
}
|
|
2081
|
-
function walkDts(dir, out = []) {
|
|
2082
|
-
if (!existsSync(dir)) return out;
|
|
2083
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2084
|
-
if (entry.name === "node_modules") continue;
|
|
2085
|
-
const p = path20.join(dir, entry.name);
|
|
2086
|
-
if (entry.isDirectory()) walkDts(p, out);
|
|
2087
|
-
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
2088
|
-
}
|
|
2089
|
-
return out;
|
|
2090
|
-
}
|
|
2091
|
-
function resolveThemeFiles(root, config, uiDir) {
|
|
2092
|
-
if (config.themeCss) {
|
|
2093
|
-
const specs = typeof config.themeCss === "string" ? [config.themeCss] : config.themeCss;
|
|
2094
|
-
return specs.map((spec) => {
|
|
2095
|
-
const file = resolveSpec(root, spec);
|
|
2096
|
-
if (!file) throw new DoctorConfigError(`doctor.themeCss: cannot find ${spec}`);
|
|
2097
|
-
return file;
|
|
2098
|
-
});
|
|
2099
|
-
}
|
|
2100
|
-
const files = [];
|
|
2101
|
-
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
2102
|
-
const themes = ds && path20.join(ds, "dist", "themes");
|
|
2103
|
-
if (themes && existsSync(themes)) {
|
|
2104
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path20.join(themes, name));
|
|
2105
|
-
}
|
|
2106
|
-
if (files.length === 0) {
|
|
2107
|
-
throw new DoctorConfigError(
|
|
2108
|
-
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
2109
|
-
);
|
|
2110
|
-
}
|
|
2111
|
-
const uiStyles = path20.join(uiDir, "dist", "styles.css");
|
|
2112
|
-
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
2113
|
-
return files;
|
|
2114
|
-
}
|
|
2115
|
-
function resolveSpec(root, spec) {
|
|
2116
|
-
const local = path20.resolve(root, spec);
|
|
2117
|
-
if (spec.startsWith(".") || path20.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
2118
|
-
const parts = spec.split("/");
|
|
2119
|
-
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
2120
|
-
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2121
|
-
if (dir) {
|
|
2122
|
-
const file = path20.join(dir, ...parts.slice(nameLength));
|
|
2123
|
-
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
2124
|
-
}
|
|
2125
|
-
return existsSync(local) ? local : null;
|
|
2126
|
-
}
|
|
2127
|
-
function loadPalette(root) {
|
|
2128
|
-
const names = new Set(TAILWIND_PALETTE);
|
|
2129
|
-
try {
|
|
2130
|
-
const req = createRequire(path20.join(root, "package.json"));
|
|
2131
|
-
const colors = req("tailwindcss/colors");
|
|
2132
|
-
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
2133
|
-
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
2134
|
-
}
|
|
2135
|
-
} catch {
|
|
2136
|
-
}
|
|
2137
|
-
return [...names].sort();
|
|
2138
|
-
}
|
|
2139
|
-
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
2140
|
-
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
2141
|
-
var MIGRATION_FILE = /^(\d{4})_([a-z0-9_]+)\.sql$/;
|
|
2142
|
-
var FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
2143
|
-
var ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
|
|
2144
|
-
var INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
|
|
2145
|
-
var SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
2146
|
-
var SQL_FUNCTION = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/;
|
|
2147
|
-
var ManifestError = class extends Error {
|
|
2148
|
-
constructor(problems) {
|
|
2149
|
-
super(`Invalid block manifest:
|
|
2150
|
-
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
2151
|
-
this.problems = problems;
|
|
2152
|
-
this.name = "ManifestError";
|
|
2153
|
-
}
|
|
2154
|
-
problems;
|
|
2155
|
-
};
|
|
2156
|
-
function safeRelative(value) {
|
|
2157
|
-
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
2158
|
-
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
2159
|
-
const segments = value.split("/");
|
|
2160
|
-
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
2161
|
-
return value;
|
|
2162
|
-
}
|
|
2163
|
-
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2164
|
-
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
2165
|
-
function parseManifest(home, id, raw, version, options = {}) {
|
|
2166
|
-
const problems = [];
|
|
2167
|
-
const at = `${home} genesis.blocks.${id}`;
|
|
2168
|
-
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
2169
|
-
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
2170
|
-
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
2171
|
-
const pkgOf = (value, where2) => {
|
|
2172
|
-
if (value === void 0) return home;
|
|
2173
|
-
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
2174
|
-
problems.push(`${where2}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
2175
|
-
return home;
|
|
2176
|
-
}
|
|
2177
|
-
return value;
|
|
2178
|
-
};
|
|
2179
|
-
const pathOf = (value, where2) => {
|
|
2180
|
-
const safe = safeRelative(value);
|
|
2181
|
-
if (!safe) problems.push(`${where2}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
2182
|
-
return safe ?? "";
|
|
2183
|
-
};
|
|
2184
|
-
const list = (key2) => {
|
|
2185
|
-
const v = raw[key2];
|
|
2186
|
-
if (v === void 0) return [];
|
|
2187
|
-
if (!Array.isArray(v)) {
|
|
2188
|
-
problems.push(`${at}.${key2}: must be a list`);
|
|
2189
|
-
return [];
|
|
2190
|
-
}
|
|
2191
|
-
return v;
|
|
2192
|
-
};
|
|
2193
|
-
const requires = list("requires").filter((r) => {
|
|
2194
|
-
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
2195
|
-
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
2196
|
-
return ok;
|
|
2197
|
-
});
|
|
2198
|
-
let platforms;
|
|
2199
|
-
if (raw["platforms"] !== void 0) {
|
|
2200
|
-
platforms = list("platforms").filter((p) => {
|
|
2201
|
-
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
2202
|
-
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
2203
|
-
return ok;
|
|
2204
|
-
});
|
|
2205
|
-
}
|
|
2206
|
-
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
2207
|
-
const install = list("install").filter((s) => {
|
|
2208
|
-
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
2209
|
-
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
2210
|
-
return ok;
|
|
2211
|
-
});
|
|
2212
|
-
const migrations = list("migrations").map((m, i) => {
|
|
2213
|
-
const where2 = `${at}.migrations[${i}]`;
|
|
2214
|
-
if (!isObject2(m)) {
|
|
2215
|
-
problems.push(`${where2}: must be an object`);
|
|
2216
|
-
return { package: home, file: "" };
|
|
2217
|
-
}
|
|
2218
|
-
const file = pathOf(m["file"], `${where2}.file`);
|
|
2219
|
-
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
2220
|
-
const out = { package: pkgOf(m["package"], where2), file };
|
|
2221
|
-
if (m["provides"] !== void 0) {
|
|
2222
|
-
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
2223
|
-
else {
|
|
2224
|
-
out.provides = m["provides"].map((p, j) => {
|
|
2225
|
-
const at2 = `${where2}.provides[${j}]`;
|
|
2226
|
-
if (!isObject2(p)) {
|
|
2227
|
-
problems.push(`${at2}: must be an object`);
|
|
2228
|
-
return { package: home, file: "" };
|
|
2229
|
-
}
|
|
2230
|
-
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
2231
|
-
if (p["functions"] !== void 0) {
|
|
2232
|
-
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
2233
|
-
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
2234
|
-
}
|
|
2235
|
-
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
2236
|
-
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
2237
|
-
return provided;
|
|
2238
|
-
});
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
if (m["needs"] !== void 0) {
|
|
2242
|
-
if (!Array.isArray(m["needs"])) problems.push(`${where2}.needs: must be a list of { function, how }`);
|
|
2243
|
-
else {
|
|
2244
|
-
out.needs = m["needs"].flatMap((n, j) => {
|
|
2245
|
-
const at2 = `${where2}.needs[${j}]`;
|
|
2246
|
-
if (!isObject2(n) || typeof n["function"] !== "string" || typeof n["how"] !== "string" || !n["how"].trim()) {
|
|
2247
|
-
problems.push(`${at2}: must be { function: "schema.name", how: "what to add" }`);
|
|
2248
|
-
return [];
|
|
2249
|
-
}
|
|
2250
|
-
if (!SQL_FUNCTION.test(n["function"])) {
|
|
2251
|
-
problems.push(`${at2}.function: "${n["function"]}" must be a schema-qualified function name, like private.genesis_viewer_people`);
|
|
2252
|
-
return [];
|
|
2253
|
-
}
|
|
2254
|
-
return [{ function: n["function"], how: n["how"].trim() }];
|
|
2255
|
-
});
|
|
2256
|
-
}
|
|
1953
|
+
if (m["needs"] !== void 0) {
|
|
1954
|
+
if (!Array.isArray(m["needs"])) problems.push(`${where2}.needs: must be a list of { function, how }`);
|
|
1955
|
+
else {
|
|
1956
|
+
out.needs = m["needs"].flatMap((n, j) => {
|
|
1957
|
+
const at2 = `${where2}.needs[${j}]`;
|
|
1958
|
+
if (!isObject2(n) || typeof n["function"] !== "string" || typeof n["how"] !== "string" || !n["how"].trim()) {
|
|
1959
|
+
problems.push(`${at2}: must be { function: "schema.name", how: "what to add" }`);
|
|
1960
|
+
return [];
|
|
1961
|
+
}
|
|
1962
|
+
if (!SQL_FUNCTION.test(n["function"])) {
|
|
1963
|
+
problems.push(`${at2}.function: "${n["function"]}" must be a schema-qualified function name, like private.genesis_viewer_people`);
|
|
1964
|
+
return [];
|
|
1965
|
+
}
|
|
1966
|
+
return [{ function: n["function"], how: n["how"].trim() }];
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
2257
1969
|
}
|
|
2258
1970
|
if (m["runsBefore"] !== void 0) {
|
|
2259
1971
|
if (!Array.isArray(m["runsBefore"])) problems.push(`${where2}.runsBefore: must be a list of { package, file }`);
|
|
@@ -2385,15 +2097,15 @@ function isBlockDef(value) {
|
|
|
2385
2097
|
// src/blocks/files.ts
|
|
2386
2098
|
var sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
2387
2099
|
function inside(parent, child) {
|
|
2388
|
-
const rel =
|
|
2389
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
2100
|
+
const rel = path21.relative(parent, child);
|
|
2101
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
2390
2102
|
}
|
|
2391
2103
|
function appPath2(root, rel) {
|
|
2392
2104
|
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
2393
2105
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
2394
2106
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
2395
2107
|
const realRoot = realpathSync(root);
|
|
2396
|
-
const target =
|
|
2108
|
+
const target = path21.join(realRoot, ...safe.split("/"));
|
|
2397
2109
|
const there = (p) => {
|
|
2398
2110
|
try {
|
|
2399
2111
|
lstatSync(p);
|
|
@@ -2402,20 +2114,18 @@ function appPath2(root, rel) {
|
|
|
2402
2114
|
return false;
|
|
2403
2115
|
}
|
|
2404
2116
|
};
|
|
2405
|
-
let probe =
|
|
2406
|
-
while (!there(probe)) probe =
|
|
2117
|
+
let probe = path21.dirname(target);
|
|
2118
|
+
while (!there(probe)) probe = path21.dirname(probe);
|
|
2407
2119
|
let real2;
|
|
2408
2120
|
try {
|
|
2409
2121
|
real2 = realpathSync(probe);
|
|
2410
2122
|
} catch {
|
|
2411
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
2123
|
+
throw new Error(`${rel} goes through a broken symlink (${path21.relative(realRoot, probe)}); refused`);
|
|
2412
2124
|
}
|
|
2413
2125
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
2414
2126
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
2415
2127
|
return target;
|
|
2416
2128
|
}
|
|
2417
|
-
|
|
2418
|
-
// src/blocks/local.ts
|
|
2419
2129
|
var LOCAL_PACKAGES_KEY = "localPackages";
|
|
2420
2130
|
var LocalPackagesError = class extends Error {
|
|
2421
2131
|
name = "LocalPackagesError";
|
|
@@ -2425,8 +2135,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
2425
2135
|
return raw.map((entry, i) => {
|
|
2426
2136
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
2427
2137
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
2428
|
-
if (
|
|
2429
|
-
const norm =
|
|
2138
|
+
if (path21.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
2139
|
+
const norm = path21.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
2430
2140
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
2431
2141
|
const parts = norm.split("/");
|
|
2432
2142
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -2437,7 +2147,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
2437
2147
|
});
|
|
2438
2148
|
}
|
|
2439
2149
|
function localPackageGlobs(root) {
|
|
2440
|
-
const file =
|
|
2150
|
+
const file = path21.join(root, "genesis.config.json");
|
|
2441
2151
|
if (!existsSync(file)) return [];
|
|
2442
2152
|
let raw;
|
|
2443
2153
|
try {
|
|
@@ -2451,14 +2161,14 @@ function localPackageGlobs(root) {
|
|
|
2451
2161
|
var cache = /* @__PURE__ */ new Map();
|
|
2452
2162
|
function repositoryRoot(appRoot) {
|
|
2453
2163
|
for (let dir = appRoot; ; ) {
|
|
2454
|
-
if (existsSync(
|
|
2455
|
-
const parent =
|
|
2164
|
+
if (existsSync(path21.join(dir, ".git"))) return dir;
|
|
2165
|
+
const parent = path21.dirname(dir);
|
|
2456
2166
|
if (parent === dir) return appRoot;
|
|
2457
2167
|
dir = parent;
|
|
2458
2168
|
}
|
|
2459
2169
|
}
|
|
2460
2170
|
function localPackages(root) {
|
|
2461
|
-
const appRoot =
|
|
2171
|
+
const appRoot = path21.resolve(root);
|
|
2462
2172
|
const globs = localPackageGlobs(appRoot);
|
|
2463
2173
|
const key2 = `${appRoot}
|
|
2464
2174
|
${globs.join("\n")}`;
|
|
@@ -2467,24 +2177,24 @@ ${globs.join("\n")}`;
|
|
|
2467
2177
|
const dirs = /* @__PURE__ */ new Set();
|
|
2468
2178
|
for (const glob of globs) {
|
|
2469
2179
|
if (glob.endsWith("/*") || glob === "*") {
|
|
2470
|
-
const parent =
|
|
2180
|
+
const parent = path21.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
2471
2181
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
2472
2182
|
for (const entry of readdirSync(parent).sort()) {
|
|
2473
2183
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
2474
|
-
dirs.add(
|
|
2184
|
+
dirs.add(path21.join(parent, entry));
|
|
2475
2185
|
}
|
|
2476
2186
|
} else {
|
|
2477
|
-
dirs.add(
|
|
2187
|
+
dirs.add(path21.join(appRoot, glob));
|
|
2478
2188
|
}
|
|
2479
2189
|
}
|
|
2480
2190
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
2481
2191
|
const out = [];
|
|
2482
2192
|
const byName = /* @__PURE__ */ new Map();
|
|
2483
2193
|
for (const dir of [...dirs].sort()) {
|
|
2484
|
-
const manifest =
|
|
2194
|
+
const manifest = path21.join(dir, "package.json");
|
|
2485
2195
|
if (!existsSync(manifest)) continue;
|
|
2486
2196
|
if (!inside(real2, realpathSync(dir))) {
|
|
2487
|
-
throw new LocalPackagesError(`${
|
|
2197
|
+
throw new LocalPackagesError(`${path21.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
2488
2198
|
}
|
|
2489
2199
|
let pkg;
|
|
2490
2200
|
try {
|
|
@@ -2493,7 +2203,7 @@ ${globs.join("\n")}`;
|
|
|
2493
2203
|
continue;
|
|
2494
2204
|
}
|
|
2495
2205
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
2496
|
-
const rel =
|
|
2206
|
+
const rel = path21.relative(appRoot, dir).split(path21.sep).join("/");
|
|
2497
2207
|
const other = byName.get(pkg.name);
|
|
2498
2208
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
2499
2209
|
byName.set(pkg.name, rel);
|
|
@@ -2681,35 +2391,35 @@ var DEFAULT_IGNORE = [
|
|
|
2681
2391
|
];
|
|
2682
2392
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2683
2393
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2684
|
-
var toPosix = (p) => p.split(
|
|
2394
|
+
var toPosix = (p) => p.split(path21.sep).join("/");
|
|
2685
2395
|
function scanFiles(root, config) {
|
|
2686
2396
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
2687
2397
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
2688
2398
|
const files = [];
|
|
2689
2399
|
const seen = /* @__PURE__ */ new Set();
|
|
2690
2400
|
const visit = (abs) => {
|
|
2691
|
-
const rel = toPosix(
|
|
2401
|
+
const rel = toPosix(path21.relative(root, abs));
|
|
2692
2402
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2693
|
-
const ext =
|
|
2403
|
+
const ext = path21.extname(abs);
|
|
2694
2404
|
if (!extensions.has(ext)) return;
|
|
2695
2405
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2696
2406
|
seen.add(rel);
|
|
2697
2407
|
const text = readFileSync(abs, "utf8");
|
|
2698
2408
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
2699
2409
|
};
|
|
2700
|
-
const
|
|
2410
|
+
const walk3 = (dir) => {
|
|
2701
2411
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2702
2412
|
if (entry.isDirectory()) {
|
|
2703
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
2413
|
+
if (!SKIP_DIRS.has(entry.name)) walk3(path21.join(dir, entry.name));
|
|
2704
2414
|
} else if (entry.isFile()) {
|
|
2705
|
-
visit(
|
|
2415
|
+
visit(path21.join(dir, entry.name));
|
|
2706
2416
|
}
|
|
2707
2417
|
}
|
|
2708
2418
|
};
|
|
2709
2419
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2710
|
-
const abs =
|
|
2420
|
+
const abs = path21.resolve(root, src);
|
|
2711
2421
|
if (!existsSync(abs)) continue;
|
|
2712
|
-
if (statSync(abs).isDirectory())
|
|
2422
|
+
if (statSync(abs).isDirectory()) walk3(abs);
|
|
2713
2423
|
else visit(abs);
|
|
2714
2424
|
}
|
|
2715
2425
|
let local = [];
|
|
@@ -2718,7 +2428,7 @@ function scanFiles(root, config) {
|
|
|
2718
2428
|
} catch {
|
|
2719
2429
|
local = [];
|
|
2720
2430
|
}
|
|
2721
|
-
for (const pkg of local)
|
|
2431
|
+
for (const pkg of local) walk3(pkg.dir);
|
|
2722
2432
|
return files;
|
|
2723
2433
|
}
|
|
2724
2434
|
function lineAt(text, index) {
|
|
@@ -2727,145 +2437,6 @@ function lineAt(text, index) {
|
|
|
2727
2437
|
return line;
|
|
2728
2438
|
}
|
|
2729
2439
|
|
|
2730
|
-
// src/doctor/patterns.ts
|
|
2731
|
-
function parseRulesMarkdown(markdown) {
|
|
2732
|
-
const rules = [];
|
|
2733
|
-
let current = null;
|
|
2734
|
-
for (const line of markdown.split("\n")) {
|
|
2735
|
-
const heading = line.match(/^###\s+([A-Za-z0-9_-]+)\s*$/);
|
|
2736
|
-
if (heading) {
|
|
2737
|
-
current = { id: heading[1] };
|
|
2738
|
-
rules.push(current);
|
|
2739
|
-
continue;
|
|
2740
|
-
}
|
|
2741
|
-
if (/^#{1,2}\s/.test(line)) {
|
|
2742
|
-
current = null;
|
|
2743
|
-
continue;
|
|
2744
|
-
}
|
|
2745
|
-
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message|newOnly):\s*(.*)$/);
|
|
2746
|
-
if (!current || !kv) continue;
|
|
2747
|
-
const [, key2, raw] = kv;
|
|
2748
|
-
const value = raw.trim();
|
|
2749
|
-
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2750
|
-
else if (key2 === "level") current.level = value;
|
|
2751
|
-
else if (key2 === "newOnly") current.newOnly = value === "true" ? true : value === "false" ? false : value;
|
|
2752
|
-
else current[key2] = value;
|
|
2753
|
-
}
|
|
2754
|
-
return rules;
|
|
2755
|
-
}
|
|
2756
|
-
function toRegExp(source, flags = "") {
|
|
2757
|
-
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
2758
|
-
return new RegExp(source, flags);
|
|
2759
|
-
}
|
|
2760
|
-
function compilePatternRules(rules, source) {
|
|
2761
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2762
|
-
const out = [];
|
|
2763
|
-
for (const rule of rules) {
|
|
2764
|
-
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
2765
|
-
ids.add(rule.id);
|
|
2766
|
-
const level = rule.level ?? "error";
|
|
2767
|
-
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
2768
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
2769
|
-
}
|
|
2770
|
-
if (rule.newOnly !== void 0 && typeof rule.newOnly !== "boolean") {
|
|
2771
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has newOnly "${String(rule.newOnly)}" (use true or false)`);
|
|
2772
|
-
}
|
|
2773
|
-
if (level === "guide") continue;
|
|
2774
|
-
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
2775
|
-
if (!rule.forbid && !rule.require && !rule.path) {
|
|
2776
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" needs forbid, require or path (or level: guide)`);
|
|
2777
|
-
}
|
|
2778
|
-
try {
|
|
2779
|
-
out.push({
|
|
2780
|
-
rule,
|
|
2781
|
-
level,
|
|
2782
|
-
includes: globMatcher(rule.files),
|
|
2783
|
-
excludes: globMatcher(rule.exclude),
|
|
2784
|
-
forbid: rule.forbid ? toRegExp(rule.forbid, "m") : void 0,
|
|
2785
|
-
require: rule.require ? toRegExp(rule.require, "m") : void 0,
|
|
2786
|
-
path: rule.path ? toRegExp(rule.path) : void 0
|
|
2787
|
-
});
|
|
2788
|
-
} catch (err) {
|
|
2789
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has an invalid pattern: ${err.message}`);
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
return out;
|
|
2793
|
-
}
|
|
2794
|
-
function loadPatternRules(root, patterns, rulesDoc) {
|
|
2795
|
-
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2796
|
-
let all = compiled;
|
|
2797
|
-
if (rulesDoc) {
|
|
2798
|
-
const file = path20.resolve(root, rulesDoc);
|
|
2799
|
-
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2800
|
-
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2801
|
-
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
2802
|
-
if (clash) throw new DoctorConfigError(`rule "${clash.rule.id}" is defined in both doctor.patterns and ${rulesDoc}`);
|
|
2803
|
-
all = [...compiled, ...fromDoc];
|
|
2804
|
-
}
|
|
2805
|
-
if (all.length === 0) return null;
|
|
2806
|
-
return {
|
|
2807
|
-
count: all.length,
|
|
2808
|
-
ids: all.map((r) => r.rule.id),
|
|
2809
|
-
newOnly: all.filter((r) => r.rule.newOnly).map((r) => r.rule.id),
|
|
2810
|
-
plugin: {
|
|
2811
|
-
name: "patterns",
|
|
2812
|
-
check(ctx) {
|
|
2813
|
-
for (const r of all) {
|
|
2814
|
-
const message = r.rule.message ?? "breaks a design rule";
|
|
2815
|
-
for (const file of ctx.files) {
|
|
2816
|
-
if (!r.includes(file.path) || r.excludes(file.path)) continue;
|
|
2817
|
-
const report = (line) => ctx.report({ rule: r.rule.id, level: r.level, file: file.path, line, message });
|
|
2818
|
-
if (r.path && !r.path.test(file.path)) report(0);
|
|
2819
|
-
if (r.require && !r.require.test(file.code)) report(0);
|
|
2820
|
-
if (r.forbid) {
|
|
2821
|
-
const m = r.forbid.exec(file.code);
|
|
2822
|
-
if (m) report(lineAt(file.code, m.index));
|
|
2823
|
-
}
|
|
2824
|
-
}
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
}
|
|
2828
|
-
};
|
|
2829
|
-
}
|
|
2830
|
-
function defineDoctorPlugin(plugin) {
|
|
2831
|
-
return plugin;
|
|
2832
|
-
}
|
|
2833
|
-
async function loadPlugins(specs, configDir) {
|
|
2834
|
-
const plugins = [];
|
|
2835
|
-
for (const spec of specs ?? []) {
|
|
2836
|
-
const [id, options] = typeof spec === "string" ? [spec, void 0] : spec;
|
|
2837
|
-
const file = resolvePlugin(id, configDir);
|
|
2838
|
-
const url = `${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`;
|
|
2839
|
-
let mod;
|
|
2840
|
-
try {
|
|
2841
|
-
mod = await import(url);
|
|
2842
|
-
} catch (err) {
|
|
2843
|
-
throw new DoctorConfigError(`doctor.plugins: could not load ${id}: ${err.message}`);
|
|
2844
|
-
}
|
|
2845
|
-
let value = mod.default;
|
|
2846
|
-
if (typeof value === "function") value = await value(options);
|
|
2847
|
-
const list = Array.isArray(value) ? value : [value];
|
|
2848
|
-
for (const p of list) {
|
|
2849
|
-
if (!p || typeof p !== "object" || typeof p.check !== "function" || typeof p.name !== "string") {
|
|
2850
|
-
throw new DoctorConfigError(`doctor.plugins: ${id} must default-export { name, check(context) } (or an array, or a factory returning one)`);
|
|
2851
|
-
}
|
|
2852
|
-
plugins.push(p);
|
|
2853
|
-
}
|
|
2854
|
-
}
|
|
2855
|
-
return plugins;
|
|
2856
|
-
}
|
|
2857
|
-
function resolvePlugin(id, configDir) {
|
|
2858
|
-
try {
|
|
2859
|
-
if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
|
|
2860
|
-
return resolveFrom(id, configDir);
|
|
2861
|
-
} catch {
|
|
2862
|
-
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2863
|
-
}
|
|
2864
|
-
}
|
|
2865
|
-
function resolveFrom(id, from) {
|
|
2866
|
-
return createRequire(path20.join(from, "noop.js")).resolve(id);
|
|
2867
|
-
}
|
|
2868
|
-
|
|
2869
2440
|
// src/doctor/semver.ts
|
|
2870
2441
|
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2871
2442
|
function parseVersion(v) {
|
|
@@ -2985,46 +2556,6 @@ function satisfies(version, range) {
|
|
|
2985
2556
|
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
2986
2557
|
);
|
|
2987
2558
|
}
|
|
2988
|
-
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2989
|
-
function readReleaseManifest(root) {
|
|
2990
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2991
|
-
const file = dir && path20.join(dir, "dist", "versions.json");
|
|
2992
|
-
if (!file || !existsSync(file)) return null;
|
|
2993
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
2994
|
-
}
|
|
2995
|
-
function checkVersionSkew(ctx) {
|
|
2996
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
2997
|
-
if (!manifest) return;
|
|
2998
|
-
const overlays = markedOverlays(ctx);
|
|
2999
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
3000
|
-
const overlay = overlays.get(name);
|
|
3001
|
-
if (overlay) {
|
|
3002
|
-
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
3003
|
-
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
3004
|
-
if (from !== want && !behind) {
|
|
3005
|
-
ctx.report({
|
|
3006
|
-
rule: "version-skew",
|
|
3007
|
-
level: "warn",
|
|
3008
|
-
file: "package.json",
|
|
3009
|
-
subject: name,
|
|
3010
|
-
message: `the app's overlay of ${name} was copied from ${from}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Bring the overlay onto ${want} (or promote it and adopt the release).`
|
|
3011
|
-
});
|
|
3012
|
-
}
|
|
3013
|
-
continue;
|
|
3014
|
-
}
|
|
3015
|
-
const dir = findPackageDir(ctx.root, name);
|
|
3016
|
-
if (!dir) continue;
|
|
3017
|
-
const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
|
|
3018
|
-
if (have === want) continue;
|
|
3019
|
-
ctx.report({
|
|
3020
|
-
rule: "version-skew",
|
|
3021
|
-
level: "warn",
|
|
3022
|
-
file: "package.json",
|
|
3023
|
-
subject: name,
|
|
3024
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
2559
|
|
|
3029
2560
|
// src/doctor/overlays.ts
|
|
3030
2561
|
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
@@ -3040,7 +2571,7 @@ function overlayState(name, json) {
|
|
|
3040
2571
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
3041
2572
|
const problems = [];
|
|
3042
2573
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
3043
|
-
const rel =
|
|
2574
|
+
const rel = path21.relative(path21.resolve(root), path21.resolve(dir)).split(path21.sep).join("/");
|
|
3044
2575
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
3045
2576
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
3046
2577
|
if (holds !== void 0) problems.push(`${name}: an overlay lives in a package folder of its own, not in ${rel || "the app root"}, which holds the app's source (${holds})`);
|
|
@@ -3077,92 +2608,760 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
3077
2608
|
for (const file of manifests) {
|
|
3078
2609
|
let json;
|
|
3079
2610
|
try {
|
|
3080
|
-
json = JSON.parse(readFileSync(
|
|
3081
|
-
} catch {
|
|
3082
|
-
continue;
|
|
2611
|
+
json = JSON.parse(readFileSync(path21.join(root, file), "utf8"));
|
|
2612
|
+
} catch {
|
|
2613
|
+
continue;
|
|
2614
|
+
}
|
|
2615
|
+
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
2616
|
+
const spec = json[section2]?.[name];
|
|
2617
|
+
const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
|
|
2618
|
+
const parsed = v && parseVersion(v);
|
|
2619
|
+
if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
return best;
|
|
2623
|
+
}
|
|
2624
|
+
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
2625
|
+
let packages;
|
|
2626
|
+
try {
|
|
2627
|
+
packages = localPackages(ctx.root);
|
|
2628
|
+
} catch {
|
|
2629
|
+
return;
|
|
2630
|
+
}
|
|
2631
|
+
for (const pkg of packages) {
|
|
2632
|
+
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
2633
|
+
const file = `${pkg.rel}/package.json`;
|
|
2634
|
+
let json;
|
|
2635
|
+
try {
|
|
2636
|
+
json = JSON.parse(readFileSync(path21.join(pkg.dir, "package.json"), "utf8"));
|
|
2637
|
+
} catch {
|
|
2638
|
+
continue;
|
|
2639
|
+
}
|
|
2640
|
+
const state = overlayState(pkg.name, json);
|
|
2641
|
+
if (state.kind === "none") {
|
|
2642
|
+
ctx.report({
|
|
2643
|
+
rule: "overlay-unmarked",
|
|
2644
|
+
file,
|
|
2645
|
+
subject: pkg.name,
|
|
2646
|
+
message: `${pkg.name} is a local package with a Genesis package's name, so it shadows the published one, but it carries no overlay marker; add "genesis": { "overlay": { "upstream": "${pkg.name}@<version copied>", "since": "YYYY-MM-DD", "owner": "\u2026", "reason": "\u2026" } }, or rename it`
|
|
2647
|
+
});
|
|
2648
|
+
continue;
|
|
2649
|
+
}
|
|
2650
|
+
if (state.kind === "invalid") {
|
|
2651
|
+
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2652
|
+
continue;
|
|
2653
|
+
}
|
|
2654
|
+
const { marker } = state;
|
|
2655
|
+
for (const problem of overlaySetupProblems(ctx.root, ctx.config, pkg.dir, pkg.name, json)) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2656
|
+
const age = overlayAgeDays(marker.since, now);
|
|
2657
|
+
if (age < -1) {
|
|
2658
|
+
ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: `${pkg.name} genesis.overlay.since: ${marker.since} is in the future; use the day the overlay was made` });
|
|
2659
|
+
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
2660
|
+
ctx.report({
|
|
2661
|
+
rule: "overlay-age",
|
|
2662
|
+
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
2663
|
+
file,
|
|
2664
|
+
subject: pkg.name,
|
|
2665
|
+
message: `the overlay of ${marker.upstream} is ${age} days old (since ${marker.since}, owner ${marker.owner}); promote its change to Genesis and adopt the release, or drop it (an overlay is reported after ${OVERLAY_NOTICE_DAYS} days, and after ${OVERLAY_WARN_DAYS} it warns, which fails --strict)`
|
|
2666
|
+
});
|
|
2667
|
+
}
|
|
2668
|
+
const upstream = overlayUpstream(marker).version;
|
|
2669
|
+
const version = typeof json.version === "string" ? json.version : "";
|
|
2670
|
+
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
2671
|
+
ctx.report({
|
|
2672
|
+
rule: "overlay-version",
|
|
2673
|
+
level: "warn",
|
|
2674
|
+
file,
|
|
2675
|
+
subject: version || "(none)",
|
|
2676
|
+
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
2680
|
+
const from = parseVersion(upstream);
|
|
2681
|
+
const to = pinned ? parseVersion(pinned) : null;
|
|
2682
|
+
if (from && to && compareVersions(from, to) < 0) {
|
|
2683
|
+
ctx.report({
|
|
2684
|
+
rule: "overlay-behind",
|
|
2685
|
+
level: "warn",
|
|
2686
|
+
file,
|
|
2687
|
+
subject: pkg.name,
|
|
2688
|
+
message: `the overlay of ${marker.upstream} is behind ${pkg.name}@${pinned}, the version the app now pins; run genesis upgrade, which rebases the overlay onto it (dropping what Genesis now ships) and moves the marker's upstream, or rebase it by hand`
|
|
2689
|
+
});
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
// src/doctor/versions.ts
|
|
2695
|
+
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2696
|
+
function readReleaseManifest(root) {
|
|
2697
|
+
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2698
|
+
const file = dir && path21.join(dir, "dist", "versions.json");
|
|
2699
|
+
if (!file || !existsSync(file)) return null;
|
|
2700
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
2701
|
+
}
|
|
2702
|
+
function checkVersionSkew(ctx) {
|
|
2703
|
+
const manifest = readReleaseManifest(ctx.root);
|
|
2704
|
+
if (!manifest) return;
|
|
2705
|
+
const overlays = markedOverlays(ctx);
|
|
2706
|
+
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2707
|
+
const overlay = overlays.get(name);
|
|
2708
|
+
if (overlay) {
|
|
2709
|
+
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
2710
|
+
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
2711
|
+
if (from !== want && !behind) {
|
|
2712
|
+
ctx.report({
|
|
2713
|
+
rule: "version-skew",
|
|
2714
|
+
level: "warn",
|
|
2715
|
+
file: "package.json",
|
|
2716
|
+
subject: name,
|
|
2717
|
+
message: `the app's overlay of ${name} was copied from ${from}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Bring the overlay onto ${want} (or promote it and adopt the release).`
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
continue;
|
|
2721
|
+
}
|
|
2722
|
+
const dir = findPackageDir(ctx.root, name);
|
|
2723
|
+
if (!dir) continue;
|
|
2724
|
+
const have = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8")).version;
|
|
2725
|
+
if (have === want) continue;
|
|
2726
|
+
ctx.report({
|
|
2727
|
+
rule: "version-skew",
|
|
2728
|
+
level: "warn",
|
|
2729
|
+
file: "package.json",
|
|
2730
|
+
subject: name,
|
|
2731
|
+
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
function buildCatalog(packagesDir) {
|
|
2736
|
+
const packages = {};
|
|
2737
|
+
for (const dir of readdirSync(packagesDir).sort()) {
|
|
2738
|
+
const file = path21.join(packagesDir, dir, "package.json");
|
|
2739
|
+
if (!existsSync(file)) continue;
|
|
2740
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2741
|
+
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
2742
|
+
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
2743
|
+
}
|
|
2744
|
+
return { packages };
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
// src/blocks/discover.ts
|
|
2748
|
+
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
2749
|
+
function cliPackageDir() {
|
|
2750
|
+
let dir = path21.dirname(fileURLToPath(import.meta.url));
|
|
2751
|
+
for (; ; ) {
|
|
2752
|
+
const file = path21.join(dir, "package.json");
|
|
2753
|
+
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
2754
|
+
const parent = path21.dirname(dir);
|
|
2755
|
+
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
2756
|
+
dir = parent;
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
function workspacePackagesDir() {
|
|
2760
|
+
const dir = path21.resolve(cliPackageDir(), "..");
|
|
2761
|
+
return existsSync(path21.join(dir, "features", "package.json")) && existsSync(path21.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
2762
|
+
}
|
|
2763
|
+
var catalogCache;
|
|
2764
|
+
function readCatalog() {
|
|
2765
|
+
if (catalogCache) return catalogCache;
|
|
2766
|
+
const workspace = workspacePackagesDir();
|
|
2767
|
+
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
2768
|
+
const file = path21.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
2769
|
+
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
2770
|
+
return catalogCache;
|
|
2771
|
+
}
|
|
2772
|
+
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
2773
|
+
function installedGenesis(root) {
|
|
2774
|
+
const found = /* @__PURE__ */ new Map();
|
|
2775
|
+
let dir = path21.resolve(root);
|
|
2776
|
+
for (; ; ) {
|
|
2777
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path21.join(dir, m)));
|
|
2778
|
+
const scope = path21.join(dir, "node_modules", "@marktiderman");
|
|
2779
|
+
if (existsSync(scope)) {
|
|
2780
|
+
for (const entry of readdirSync(scope)) {
|
|
2781
|
+
const name = `@marktiderman/${entry}`;
|
|
2782
|
+
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
2783
|
+
if (existsSync(path21.join(scope, entry, "package.json"))) found.set(name, path21.join(scope, entry));
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
const parent = path21.dirname(dir);
|
|
2787
|
+
if (atInstallRoot || parent === dir) return found;
|
|
2788
|
+
dir = parent;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
var declarationCache = /* @__PURE__ */ new Map();
|
|
2792
|
+
function declarationsOf(dir, warnings) {
|
|
2793
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
2794
|
+
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
2795
|
+
let cached = declarationCache.get(key2);
|
|
2796
|
+
if (!cached) {
|
|
2797
|
+
cached = loadDeclarations(dir, warnings);
|
|
2798
|
+
declarationCache.set(key2, cached);
|
|
2799
|
+
}
|
|
2800
|
+
return cached;
|
|
2801
|
+
}
|
|
2802
|
+
async function loadDeclarations(dir, warnings) {
|
|
2803
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
2804
|
+
const entry = pkg.exports?.["./blocks"];
|
|
2805
|
+
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
2806
|
+
if (typeof target !== "string") return {};
|
|
2807
|
+
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
2808
|
+
const file = rel && path21.join(dir, ...rel.split("/"));
|
|
2809
|
+
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
2810
|
+
try {
|
|
2811
|
+
const jiti = createJiti(path21.join(dir, "package.json"), { moduleCache: false });
|
|
2812
|
+
const mod = await jiti.import(file);
|
|
2813
|
+
const out = {};
|
|
2814
|
+
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
2815
|
+
return out;
|
|
2816
|
+
} catch (err) {
|
|
2817
|
+
warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
|
|
2818
|
+
return {};
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
2822
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
2823
|
+
const raw = rawBlocksOf(pkg);
|
|
2824
|
+
const declared = await declarationsOf(dir, warnings);
|
|
2825
|
+
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
2826
|
+
const out = [];
|
|
2827
|
+
for (const id of [...ids].sort()) {
|
|
2828
|
+
const fromJson = raw[id] ?? {};
|
|
2829
|
+
const merged = { ...fromJson, ...declared[id] };
|
|
2830
|
+
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
2831
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
2832
|
+
if (manifest) out.push(manifest);
|
|
2833
|
+
}
|
|
2834
|
+
return out;
|
|
2835
|
+
}
|
|
2836
|
+
function withProvides(declared, json) {
|
|
2837
|
+
if (!Array.isArray(declared)) return declared;
|
|
2838
|
+
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
2839
|
+
return declared.map((m) => {
|
|
2840
|
+
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
2841
|
+
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
async function allBlocks(root, warnings = []) {
|
|
2845
|
+
const out = [];
|
|
2846
|
+
for (const local of localPackages(root)) {
|
|
2847
|
+
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
2848
|
+
}
|
|
2849
|
+
const installed = installedGenesis(root);
|
|
2850
|
+
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
2851
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
2852
|
+
if (installed.has(name)) continue;
|
|
2853
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
2854
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
2855
|
+
if (manifest) out.push({ manifest, from: "catalog" });
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
return out;
|
|
2859
|
+
}
|
|
2860
|
+
function tryParse(parse2, warnings) {
|
|
2861
|
+
try {
|
|
2862
|
+
return parse2();
|
|
2863
|
+
} catch (err) {
|
|
2864
|
+
if (!(err instanceof ManifestError)) throw err;
|
|
2865
|
+
warnings.push(err.message);
|
|
2866
|
+
return null;
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
function catalogBlocks(warnings = []) {
|
|
2870
|
+
const out = [];
|
|
2871
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
2872
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
2873
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
2874
|
+
if (manifest) out.push(manifest);
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
return out;
|
|
2878
|
+
}
|
|
2879
|
+
async function findBlock(root, id, options = {}) {
|
|
2880
|
+
const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
|
|
2881
|
+
if (all.length === 0) {
|
|
2882
|
+
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
2883
|
+
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
2884
|
+
}
|
|
2885
|
+
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
2886
|
+
return all[0];
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
// src/blocks/pm.ts
|
|
2890
|
+
function findLockfile(root) {
|
|
2891
|
+
let dir = path21.resolve(root);
|
|
2892
|
+
for (; ; ) {
|
|
2893
|
+
if (existsSync(path21.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
2894
|
+
if (existsSync(path21.join(dir, "bun.lock")) || existsSync(path21.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
2895
|
+
if (existsSync(path21.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
2896
|
+
if (existsSync(path21.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
2897
|
+
const parent = path21.dirname(dir);
|
|
2898
|
+
if (parent === dir) return null;
|
|
2899
|
+
dir = parent;
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
function detectPackageManager(root) {
|
|
2903
|
+
return findLockfile(root)?.pm ?? "npm";
|
|
2904
|
+
}
|
|
2905
|
+
function installCommand(pm) {
|
|
2906
|
+
return pm === "yarn" ? ["yarn", "install"] : [pm, "install"];
|
|
2907
|
+
}
|
|
2908
|
+
var shellLine = (argv) => argv.map((a) => /^[\w@./:^~=-]+$/.test(a) ? a : `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
2909
|
+
|
|
2910
|
+
// src/doctor/genesis.ts
|
|
2911
|
+
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
2912
|
+
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
2913
|
+
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
2914
|
+
var DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
|
|
2915
|
+
var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
2916
|
+
var TAG_ALIASES = { hr: "Separator" };
|
|
2917
|
+
var NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
2918
|
+
var TAILWIND_PALETTE = [
|
|
2919
|
+
"black",
|
|
2920
|
+
"white",
|
|
2921
|
+
"slate",
|
|
2922
|
+
"gray",
|
|
2923
|
+
"zinc",
|
|
2924
|
+
"neutral",
|
|
2925
|
+
"stone",
|
|
2926
|
+
"red",
|
|
2927
|
+
"orange",
|
|
2928
|
+
"amber",
|
|
2929
|
+
"yellow",
|
|
2930
|
+
"lime",
|
|
2931
|
+
"green",
|
|
2932
|
+
"emerald",
|
|
2933
|
+
"teal",
|
|
2934
|
+
"cyan",
|
|
2935
|
+
"sky",
|
|
2936
|
+
"blue",
|
|
2937
|
+
"indigo",
|
|
2938
|
+
"violet",
|
|
2939
|
+
"purple",
|
|
2940
|
+
"fuchsia",
|
|
2941
|
+
"pink",
|
|
2942
|
+
"rose",
|
|
2943
|
+
"taupe",
|
|
2944
|
+
"mauve",
|
|
2945
|
+
"mist",
|
|
2946
|
+
"olive"
|
|
2947
|
+
];
|
|
2948
|
+
function findPackageDir(from, name) {
|
|
2949
|
+
let dir = path21.resolve(from);
|
|
2950
|
+
for (; ; ) {
|
|
2951
|
+
const candidate = path21.join(dir, "node_modules", name);
|
|
2952
|
+
if (existsSync(path21.join(candidate, "package.json"))) return candidate;
|
|
2953
|
+
const parent = path21.dirname(dir);
|
|
2954
|
+
if (parent === dir) return null;
|
|
2955
|
+
dir = parent;
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
function uiPackageFor(config) {
|
|
2959
|
+
return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
|
|
2960
|
+
}
|
|
2961
|
+
function loadGenesis(root, config) {
|
|
2962
|
+
const uiPackage = uiPackageFor(config);
|
|
2963
|
+
const pkg = readPackageExports(root, uiPackage);
|
|
2964
|
+
if (!pkg) throw new DoctorConfigError(notInstalled(root, uiPackage));
|
|
2965
|
+
const { dir: uiDir, exports: exportNames, values, components } = pkg;
|
|
2966
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
2967
|
+
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
2968
|
+
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
2969
|
+
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
2970
|
+
const rawTags = /* @__PURE__ */ new Map();
|
|
2971
|
+
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
2972
|
+
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
2973
|
+
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
2974
|
+
if (comp === false) rawTags.delete(tag);
|
|
2975
|
+
else rawTags.set(tag, comp);
|
|
2976
|
+
}
|
|
2977
|
+
return {
|
|
2978
|
+
uiPackage,
|
|
2979
|
+
uiVersion: pkg.version,
|
|
2980
|
+
exports: exportNames,
|
|
2981
|
+
values,
|
|
2982
|
+
components,
|
|
2983
|
+
tokens,
|
|
2984
|
+
rawTags,
|
|
2985
|
+
palette: loadPalette(root),
|
|
2986
|
+
companions: loadCompanions(root, config, uiPackage)
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
function notInstalled(root, uiPackage) {
|
|
2990
|
+
let declared = false;
|
|
2991
|
+
try {
|
|
2992
|
+
const pkg = JSON.parse(readFileSync(path21.join(root, "package.json"), "utf8"));
|
|
2993
|
+
declared = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"].some((s) => pkg[s]?.[uiPackage] !== void 0);
|
|
2994
|
+
} catch {
|
|
2995
|
+
}
|
|
2996
|
+
if (!declared) return `${uiPackage} is not installed here and isn't in this app's package.json. Add it, or set doctor.uiPackage.`;
|
|
2997
|
+
return `${uiPackage} is in package.json but not installed, so this app's dependencies aren't installed. Run \`${shellLine(installCommand(detectPackageManager(root)))}\`, then run this again.`;
|
|
2998
|
+
}
|
|
2999
|
+
function loadCompanions(root, config, uiPackage) {
|
|
3000
|
+
const out = [];
|
|
3001
|
+
for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
|
|
3002
|
+
if (name === uiPackage) continue;
|
|
3003
|
+
try {
|
|
3004
|
+
const pkg = readPackageExports(root, name);
|
|
3005
|
+
if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
|
|
3006
|
+
} catch (err) {
|
|
3007
|
+
if (!(err instanceof DoctorConfigError)) throw err;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
return out;
|
|
3011
|
+
}
|
|
3012
|
+
function readPackageExports(root, uiPackage) {
|
|
3013
|
+
const uiDir = findPackageDir(root, uiPackage);
|
|
3014
|
+
if (!uiDir) return null;
|
|
3015
|
+
const uiPkg = JSON.parse(readFileSync(path21.join(uiDir, "package.json"), "utf8"));
|
|
3016
|
+
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
3017
|
+
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
3018
|
+
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
3019
|
+
const entryOf = fromSource ? exportSource : exportTypes;
|
|
3020
|
+
const typeEntries = /* @__PURE__ */ new Set();
|
|
3021
|
+
const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
|
|
3022
|
+
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
3023
|
+
for (const target of subpaths) {
|
|
3024
|
+
const t = entryOf(target);
|
|
3025
|
+
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
3026
|
+
}
|
|
3027
|
+
const exportNames = /* @__PURE__ */ new Set();
|
|
3028
|
+
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
3029
|
+
let readAny = false;
|
|
3030
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3031
|
+
const readEntry = (file) => {
|
|
3032
|
+
if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
|
|
3033
|
+
seen.add(file);
|
|
3034
|
+
readAny = true;
|
|
3035
|
+
const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
|
|
3036
|
+
for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
|
|
3037
|
+
for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
3038
|
+
reexportedPackages.add(packageName(m[1]));
|
|
3039
|
+
}
|
|
3040
|
+
if (fromSource) {
|
|
3041
|
+
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
3042
|
+
const next = resolveSource(path21.dirname(file), m[1]);
|
|
3043
|
+
if (next) readEntry(next);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
};
|
|
3047
|
+
for (const entry of typeEntries) readEntry(path21.join(uiDir, entry));
|
|
3048
|
+
if (!readAny) {
|
|
3049
|
+
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
3050
|
+
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
3051
|
+
}
|
|
3052
|
+
const valueDecls = /* @__PURE__ */ new Set();
|
|
3053
|
+
const typeDecls = /* @__PURE__ */ new Set();
|
|
3054
|
+
const declRoot = typeof mainTypes === "string" ? path21.dirname(path21.join(uiDir, mainTypes)) : uiDir;
|
|
3055
|
+
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
3056
|
+
for (const pkg of reexportedPackages) {
|
|
3057
|
+
const dir = findPackageDir(uiDir, pkg);
|
|
3058
|
+
if (dir) walkDts(path21.join(dir, "dist"), declFiles);
|
|
3059
|
+
}
|
|
3060
|
+
for (const file of declFiles) {
|
|
3061
|
+
const text = readFileSync(file, "utf8");
|
|
3062
|
+
for (const m of text.matchAll(/\b(?:declare\s+)?(?:const|let|var|function|class|enum)\s+([A-Za-z_$][\w$]*)/g)) valueDecls.add(m[1]);
|
|
3063
|
+
for (const m of text.matchAll(/\b(?:interface|type)\s+([A-Za-z_$][\w$]*)/g)) typeDecls.add(m[1]);
|
|
3064
|
+
}
|
|
3065
|
+
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
3066
|
+
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
3067
|
+
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
3068
|
+
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
3069
|
+
}
|
|
3070
|
+
function parseExportNames(dts) {
|
|
3071
|
+
const names = [];
|
|
3072
|
+
for (const m of dts.matchAll(/export\s+(?:type\s+)?\{([^}]*)\}/g)) {
|
|
3073
|
+
for (const part of m[1].split(",")) {
|
|
3074
|
+
const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
3075
|
+
if (name && name !== "default") names.push(name);
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
for (const m of dts.matchAll(/export\s+(?:declare\s+)?(?:const|let|function|class|enum|interface|type)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
3079
|
+
names.push(m[1]);
|
|
3080
|
+
}
|
|
3081
|
+
return names;
|
|
3082
|
+
}
|
|
3083
|
+
function declaredTokens(css) {
|
|
3084
|
+
return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
|
|
3085
|
+
}
|
|
3086
|
+
function packageName(specifier) {
|
|
3087
|
+
const parts = specifier.split("/");
|
|
3088
|
+
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
3089
|
+
}
|
|
3090
|
+
function parseSourceExportNames(code) {
|
|
3091
|
+
const names = parseExportNames(code);
|
|
3092
|
+
for (const m of code.matchAll(/export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:var|class|function\*?)\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
3093
|
+
for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
3094
|
+
return [...new Set(names)];
|
|
3095
|
+
}
|
|
3096
|
+
var TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
3097
|
+
var isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
|
|
3098
|
+
function exportSource(target) {
|
|
3099
|
+
if (isTsSource(target)) return target;
|
|
3100
|
+
if (!target || typeof target !== "object") return void 0;
|
|
3101
|
+
for (const value of Object.values(target)) {
|
|
3102
|
+
const nested = exportSource(value);
|
|
3103
|
+
if (nested) return nested;
|
|
3104
|
+
}
|
|
3105
|
+
return void 0;
|
|
3106
|
+
}
|
|
3107
|
+
function resolveSource(dir, spec) {
|
|
3108
|
+
const base = path21.resolve(dir, spec.replace(/\.js$/, ""));
|
|
3109
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path21.join(base, i))];
|
|
3110
|
+
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
3111
|
+
}
|
|
3112
|
+
function insidePackage(dir, file) {
|
|
3113
|
+
const rel = path21.relative(path21.resolve(dir), path21.resolve(file));
|
|
3114
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
3115
|
+
}
|
|
3116
|
+
function stripComments(code) {
|
|
3117
|
+
let out = "";
|
|
3118
|
+
let i = 0;
|
|
3119
|
+
while (i < code.length) {
|
|
3120
|
+
const c = code[i];
|
|
3121
|
+
const next = code[i + 1];
|
|
3122
|
+
if (c === "/" && next === "*") {
|
|
3123
|
+
const end = code.indexOf("*/", i + 2);
|
|
3124
|
+
const stop = end < 0 ? code.length : end + 2;
|
|
3125
|
+
out += code.slice(i, stop).replace(/[^\n]/g, " ");
|
|
3126
|
+
i = stop;
|
|
3127
|
+
} else if (c === "/" && next === "/") {
|
|
3128
|
+
const end = code.indexOf("\n", i);
|
|
3129
|
+
i = end < 0 ? code.length : end;
|
|
3130
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
3131
|
+
let j = i + 1;
|
|
3132
|
+
while (j < code.length && code[j] !== c) {
|
|
3133
|
+
if (code[j] === "\\") j++;
|
|
3134
|
+
else if (c !== "`" && code[j] === "\n") break;
|
|
3135
|
+
j++;
|
|
3136
|
+
}
|
|
3137
|
+
out += code.slice(i, j + 1);
|
|
3138
|
+
i = j + 1;
|
|
3139
|
+
} else {
|
|
3140
|
+
out += c;
|
|
3141
|
+
i++;
|
|
3142
|
+
}
|
|
3143
|
+
}
|
|
3144
|
+
return out;
|
|
3145
|
+
}
|
|
3146
|
+
function walkSource(dir, out = []) {
|
|
3147
|
+
if (!existsSync(dir)) return out;
|
|
3148
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
3149
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
3150
|
+
const p = path21.join(dir, entry.name);
|
|
3151
|
+
if (entry.isDirectory()) walkSource(p, out);
|
|
3152
|
+
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
3153
|
+
}
|
|
3154
|
+
return out;
|
|
3155
|
+
}
|
|
3156
|
+
function exportTypes(target) {
|
|
3157
|
+
if (!target || typeof target !== "object") return void 0;
|
|
3158
|
+
const t = target;
|
|
3159
|
+
if (typeof t.types === "string") return t.types;
|
|
3160
|
+
for (const key2 of ["import", "default", "require"]) {
|
|
3161
|
+
const nested = exportTypes(t[key2]);
|
|
3162
|
+
if (nested) return nested;
|
|
3163
|
+
}
|
|
3164
|
+
return void 0;
|
|
3165
|
+
}
|
|
3166
|
+
function walkDts(dir, out = []) {
|
|
3167
|
+
if (!existsSync(dir)) return out;
|
|
3168
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
3169
|
+
if (entry.name === "node_modules") continue;
|
|
3170
|
+
const p = path21.join(dir, entry.name);
|
|
3171
|
+
if (entry.isDirectory()) walkDts(p, out);
|
|
3172
|
+
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
3173
|
+
}
|
|
3174
|
+
return out;
|
|
3175
|
+
}
|
|
3176
|
+
function resolveThemeFiles(root, config, uiDir) {
|
|
3177
|
+
if (config.themeCss) {
|
|
3178
|
+
const specs = typeof config.themeCss === "string" ? [config.themeCss] : config.themeCss;
|
|
3179
|
+
return specs.map((spec) => {
|
|
3180
|
+
const file = resolveSpec(root, spec);
|
|
3181
|
+
if (!file) throw new DoctorConfigError(`doctor.themeCss: cannot find ${spec}`);
|
|
3182
|
+
return file;
|
|
3183
|
+
});
|
|
3184
|
+
}
|
|
3185
|
+
const files = [];
|
|
3186
|
+
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
3187
|
+
const themes = ds && path21.join(ds, "dist", "themes");
|
|
3188
|
+
if (themes && existsSync(themes)) {
|
|
3189
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path21.join(themes, name));
|
|
3190
|
+
}
|
|
3191
|
+
if (files.length === 0) {
|
|
3192
|
+
throw new DoctorConfigError(
|
|
3193
|
+
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
3194
|
+
);
|
|
3195
|
+
}
|
|
3196
|
+
const uiStyles = path21.join(uiDir, "dist", "styles.css");
|
|
3197
|
+
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
3198
|
+
return files;
|
|
3199
|
+
}
|
|
3200
|
+
function resolveSpec(root, spec) {
|
|
3201
|
+
const local = path21.resolve(root, spec);
|
|
3202
|
+
if (spec.startsWith(".") || path21.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
3203
|
+
const parts = spec.split("/");
|
|
3204
|
+
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
3205
|
+
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3206
|
+
if (dir) {
|
|
3207
|
+
const file = path21.join(dir, ...parts.slice(nameLength));
|
|
3208
|
+
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
3209
|
+
}
|
|
3210
|
+
return existsSync(local) ? local : null;
|
|
3211
|
+
}
|
|
3212
|
+
function loadPalette(root) {
|
|
3213
|
+
const names = new Set(TAILWIND_PALETTE);
|
|
3214
|
+
try {
|
|
3215
|
+
const req = createRequire(path21.join(root, "package.json"));
|
|
3216
|
+
const colors = req("tailwindcss/colors");
|
|
3217
|
+
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
3218
|
+
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
3219
|
+
}
|
|
3220
|
+
} catch {
|
|
3221
|
+
}
|
|
3222
|
+
return [...names].sort();
|
|
3223
|
+
}
|
|
3224
|
+
function parseRulesMarkdown(markdown) {
|
|
3225
|
+
const rules = [];
|
|
3226
|
+
let current = null;
|
|
3227
|
+
for (const line of markdown.split("\n")) {
|
|
3228
|
+
const heading = line.match(/^###\s+([A-Za-z0-9_-]+)\s*$/);
|
|
3229
|
+
if (heading) {
|
|
3230
|
+
current = { id: heading[1] };
|
|
3231
|
+
rules.push(current);
|
|
3232
|
+
continue;
|
|
3233
|
+
}
|
|
3234
|
+
if (/^#{1,2}\s/.test(line)) {
|
|
3235
|
+
current = null;
|
|
3236
|
+
continue;
|
|
3237
|
+
}
|
|
3238
|
+
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message|newOnly):\s*(.*)$/);
|
|
3239
|
+
if (!current || !kv) continue;
|
|
3240
|
+
const [, key2, raw] = kv;
|
|
3241
|
+
const value = raw.trim();
|
|
3242
|
+
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
3243
|
+
else if (key2 === "level") current.level = value;
|
|
3244
|
+
else if (key2 === "newOnly") current.newOnly = value === "true" ? true : value === "false" ? false : value;
|
|
3245
|
+
else current[key2] = value;
|
|
3246
|
+
}
|
|
3247
|
+
return rules;
|
|
3248
|
+
}
|
|
3249
|
+
function toRegExp(source, flags = "") {
|
|
3250
|
+
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
3251
|
+
return new RegExp(source, flags);
|
|
3252
|
+
}
|
|
3253
|
+
function compilePatternRules(rules, source) {
|
|
3254
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3255
|
+
const out = [];
|
|
3256
|
+
for (const rule of rules) {
|
|
3257
|
+
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
3258
|
+
ids.add(rule.id);
|
|
3259
|
+
const level = rule.level ?? "error";
|
|
3260
|
+
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
3261
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
3262
|
+
}
|
|
3263
|
+
if (rule.newOnly !== void 0 && typeof rule.newOnly !== "boolean") {
|
|
3264
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has newOnly "${String(rule.newOnly)}" (use true or false)`);
|
|
3265
|
+
}
|
|
3266
|
+
if (level === "guide") continue;
|
|
3267
|
+
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
3268
|
+
if (!rule.forbid && !rule.require && !rule.path) {
|
|
3269
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" needs forbid, require or path (or level: guide)`);
|
|
3270
|
+
}
|
|
3271
|
+
try {
|
|
3272
|
+
out.push({
|
|
3273
|
+
rule,
|
|
3274
|
+
level,
|
|
3275
|
+
includes: globMatcher(rule.files),
|
|
3276
|
+
excludes: globMatcher(rule.exclude),
|
|
3277
|
+
forbid: rule.forbid ? toRegExp(rule.forbid, "m") : void 0,
|
|
3278
|
+
require: rule.require ? toRegExp(rule.require, "m") : void 0,
|
|
3279
|
+
path: rule.path ? toRegExp(rule.path) : void 0
|
|
3280
|
+
});
|
|
3281
|
+
} catch (err) {
|
|
3282
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has an invalid pattern: ${err.message}`);
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
return out;
|
|
3286
|
+
}
|
|
3287
|
+
function loadPatternRules(root, patterns, rulesDoc) {
|
|
3288
|
+
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
3289
|
+
let all = compiled;
|
|
3290
|
+
if (rulesDoc) {
|
|
3291
|
+
const file = path21.resolve(root, rulesDoc);
|
|
3292
|
+
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
3293
|
+
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
3294
|
+
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
3295
|
+
if (clash) throw new DoctorConfigError(`rule "${clash.rule.id}" is defined in both doctor.patterns and ${rulesDoc}`);
|
|
3296
|
+
all = [...compiled, ...fromDoc];
|
|
3297
|
+
}
|
|
3298
|
+
if (all.length === 0) return null;
|
|
3299
|
+
return {
|
|
3300
|
+
count: all.length,
|
|
3301
|
+
ids: all.map((r) => r.rule.id),
|
|
3302
|
+
newOnly: all.filter((r) => r.rule.newOnly).map((r) => r.rule.id),
|
|
3303
|
+
plugin: {
|
|
3304
|
+
name: "patterns",
|
|
3305
|
+
check(ctx) {
|
|
3306
|
+
for (const r of all) {
|
|
3307
|
+
const message = r.rule.message ?? "breaks a design rule";
|
|
3308
|
+
for (const file of ctx.files) {
|
|
3309
|
+
if (!r.includes(file.path) || r.excludes(file.path)) continue;
|
|
3310
|
+
const report = (line) => ctx.report({ rule: r.rule.id, level: r.level, file: file.path, line, message });
|
|
3311
|
+
if (r.path && !r.path.test(file.path)) report(0);
|
|
3312
|
+
if (r.require && !r.require.test(file.code)) report(0);
|
|
3313
|
+
if (r.forbid) {
|
|
3314
|
+
const m = r.forbid.exec(file.code);
|
|
3315
|
+
if (m) report(lineAt(file.code, m.index));
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3323
|
+
function defineDoctorPlugin(plugin) {
|
|
3324
|
+
return plugin;
|
|
3325
|
+
}
|
|
3326
|
+
async function loadPlugins(specs, configDir) {
|
|
3327
|
+
const plugins = [];
|
|
3328
|
+
for (const spec of specs ?? []) {
|
|
3329
|
+
const [id, options] = typeof spec === "string" ? [spec, void 0] : spec;
|
|
3330
|
+
const file = resolvePlugin(id, configDir);
|
|
3331
|
+
const url = `${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`;
|
|
3332
|
+
let mod;
|
|
3333
|
+
try {
|
|
3334
|
+
mod = await import(url);
|
|
3335
|
+
} catch (err) {
|
|
3336
|
+
throw new DoctorConfigError(`doctor.plugins: could not load ${id}: ${err.message}`);
|
|
3083
3337
|
}
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
if (
|
|
3338
|
+
let value = mod.default;
|
|
3339
|
+
if (typeof value === "function") value = await value(options);
|
|
3340
|
+
const list = Array.isArray(value) ? value : [value];
|
|
3341
|
+
for (const p of list) {
|
|
3342
|
+
if (!p || typeof p !== "object" || typeof p.check !== "function" || typeof p.name !== "string") {
|
|
3343
|
+
throw new DoctorConfigError(`doctor.plugins: ${id} must default-export { name, check(context) } (or an array, or a factory returning one)`);
|
|
3344
|
+
}
|
|
3345
|
+
plugins.push(p);
|
|
3089
3346
|
}
|
|
3090
3347
|
}
|
|
3091
|
-
return
|
|
3348
|
+
return plugins;
|
|
3092
3349
|
}
|
|
3093
|
-
function
|
|
3094
|
-
let packages;
|
|
3350
|
+
function resolvePlugin(id, configDir) {
|
|
3095
3351
|
try {
|
|
3096
|
-
|
|
3352
|
+
if (id.startsWith(".") || path21.isAbsolute(id)) return resolveFrom(path21.resolve(configDir, id), configDir);
|
|
3353
|
+
return resolveFrom(id, configDir);
|
|
3097
3354
|
} catch {
|
|
3098
|
-
|
|
3099
|
-
}
|
|
3100
|
-
for (const pkg of packages) {
|
|
3101
|
-
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
3102
|
-
const file = `${pkg.rel}/package.json`;
|
|
3103
|
-
let json;
|
|
3104
|
-
try {
|
|
3105
|
-
json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
3106
|
-
} catch {
|
|
3107
|
-
continue;
|
|
3108
|
-
}
|
|
3109
|
-
const state = overlayState(pkg.name, json);
|
|
3110
|
-
if (state.kind === "none") {
|
|
3111
|
-
ctx.report({
|
|
3112
|
-
rule: "overlay-unmarked",
|
|
3113
|
-
file,
|
|
3114
|
-
subject: pkg.name,
|
|
3115
|
-
message: `${pkg.name} is a local package with a Genesis package's name, so it shadows the published one, but it carries no overlay marker; add "genesis": { "overlay": { "upstream": "${pkg.name}@<version copied>", "since": "YYYY-MM-DD", "owner": "\u2026", "reason": "\u2026" } }, or rename it`
|
|
3116
|
-
});
|
|
3117
|
-
continue;
|
|
3118
|
-
}
|
|
3119
|
-
if (state.kind === "invalid") {
|
|
3120
|
-
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
3121
|
-
continue;
|
|
3122
|
-
}
|
|
3123
|
-
const { marker } = state;
|
|
3124
|
-
for (const problem of overlaySetupProblems(ctx.root, ctx.config, pkg.dir, pkg.name, json)) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
3125
|
-
const age = overlayAgeDays(marker.since, now);
|
|
3126
|
-
if (age < -1) {
|
|
3127
|
-
ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: `${pkg.name} genesis.overlay.since: ${marker.since} is in the future; use the day the overlay was made` });
|
|
3128
|
-
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
3129
|
-
ctx.report({
|
|
3130
|
-
rule: "overlay-age",
|
|
3131
|
-
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
3132
|
-
file,
|
|
3133
|
-
subject: pkg.name,
|
|
3134
|
-
message: `the overlay of ${marker.upstream} is ${age} days old (since ${marker.since}, owner ${marker.owner}); promote its change to Genesis and adopt the release, or drop it (an overlay is reported after ${OVERLAY_NOTICE_DAYS} days, and after ${OVERLAY_WARN_DAYS} it warns, which fails --strict)`
|
|
3135
|
-
});
|
|
3136
|
-
}
|
|
3137
|
-
const upstream = overlayUpstream(marker).version;
|
|
3138
|
-
const version = typeof json.version === "string" ? json.version : "";
|
|
3139
|
-
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
3140
|
-
ctx.report({
|
|
3141
|
-
rule: "overlay-version",
|
|
3142
|
-
level: "warn",
|
|
3143
|
-
file,
|
|
3144
|
-
subject: version || "(none)",
|
|
3145
|
-
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
|
|
3146
|
-
});
|
|
3147
|
-
}
|
|
3148
|
-
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
3149
|
-
const from = parseVersion(upstream);
|
|
3150
|
-
const to = pinned ? parseVersion(pinned) : null;
|
|
3151
|
-
if (from && to && compareVersions(from, to) < 0) {
|
|
3152
|
-
ctx.report({
|
|
3153
|
-
rule: "overlay-behind",
|
|
3154
|
-
level: "warn",
|
|
3155
|
-
file,
|
|
3156
|
-
subject: pkg.name,
|
|
3157
|
-
message: `the overlay of ${marker.upstream} is behind ${pkg.name}@${pinned}, the version the app now pins; run genesis upgrade, which rebases the overlay onto it (dropping what Genesis now ships) and moves the marker's upstream, or rebase it by hand`
|
|
3158
|
-
});
|
|
3159
|
-
}
|
|
3355
|
+
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
3160
3356
|
}
|
|
3161
3357
|
}
|
|
3162
|
-
|
|
3163
|
-
|
|
3358
|
+
function resolveFrom(id, from) {
|
|
3359
|
+
return createRequire(path21.join(from, "noop.js")).resolve(id);
|
|
3360
|
+
}
|
|
3164
3361
|
var BUILTIN_RULES = [
|
|
3165
3362
|
"local-primitives",
|
|
3363
|
+
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
3364
|
+
"figma-routes",
|
|
3166
3365
|
"starter-leftover",
|
|
3167
3366
|
"forbidden-import",
|
|
3168
3367
|
"raw-tag",
|
|
@@ -3255,7 +3454,7 @@ function importSpecifiers(file) {
|
|
|
3255
3454
|
}
|
|
3256
3455
|
function checkProjectLayout(ctx) {
|
|
3257
3456
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
3258
|
-
if (existsSync(
|
|
3457
|
+
if (existsSync(path21.join(ctx.root, dir))) {
|
|
3259
3458
|
ctx.report({
|
|
3260
3459
|
rule: "local-primitives",
|
|
3261
3460
|
file: dir,
|
|
@@ -3265,7 +3464,7 @@ function checkProjectLayout(ctx) {
|
|
|
3265
3464
|
}
|
|
3266
3465
|
}
|
|
3267
3466
|
for (const file of STARTER_LEFTOVERS) {
|
|
3268
|
-
if (existsSync(
|
|
3467
|
+
if (existsSync(path21.join(ctx.root, file))) {
|
|
3269
3468
|
ctx.report({
|
|
3270
3469
|
rule: "starter-leftover",
|
|
3271
3470
|
level: "warn",
|
|
@@ -3355,7 +3554,7 @@ function checkTokens(ctx) {
|
|
|
3355
3554
|
}
|
|
3356
3555
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
3357
3556
|
if (/[*?]/.test(pattern)) continue;
|
|
3358
|
-
const abs =
|
|
3557
|
+
const abs = path21.join(ctx.root, pattern);
|
|
3359
3558
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
3360
3559
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
3361
3560
|
}
|
|
@@ -3379,7 +3578,7 @@ function checkShadowedExports(ctx) {
|
|
|
3379
3578
|
file.code.split("\n").forEach((text, i) => {
|
|
3380
3579
|
for (const m of text.matchAll(re)) {
|
|
3381
3580
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
3382
|
-
ctx.report({ rule: "shadowed-export", file: file.path, line: i + 1, subject: m[1], message: `shadows the Genesis export '${m[1]}'; reuse or extend
|
|
3581
|
+
ctx.report({ rule: "shadowed-export", file: file.path, line: i + 1, subject: m[1], message: `shadows the Genesis export '${m[1]}'; reuse or extend ${m[1]} from ${ctx.genesis.uiPackage} (or rename yours if it's a different thing)` });
|
|
3383
3582
|
}
|
|
3384
3583
|
});
|
|
3385
3584
|
}
|
|
@@ -3478,10 +3677,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
|
|
|
3478
3677
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
3479
3678
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
3480
3679
|
function resolveLocal(root, fromFile, spec) {
|
|
3481
|
-
const bases = spec.startsWith(".") ? [
|
|
3680
|
+
const bases = spec.startsWith(".") ? [path21.resolve(path21.dirname(fromFile), spec)] : [path21.join(root, spec.slice(2)), path21.join(root, "src", spec.slice(2))];
|
|
3482
3681
|
for (const base of bases) {
|
|
3483
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
3484
|
-
(p) => SCRIPT_EXTS2.has(
|
|
3682
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path21.join(base, `index${e}`))].find(
|
|
3683
|
+
(p) => SCRIPT_EXTS2.has(path21.extname(p)) && existsSync(p)
|
|
3485
3684
|
);
|
|
3486
3685
|
if (hit) return hit;
|
|
3487
3686
|
}
|
|
@@ -3602,13 +3801,13 @@ function checkNativePack(ctx) {
|
|
|
3602
3801
|
}
|
|
3603
3802
|
function checkEasPlaceholders(ctx) {
|
|
3604
3803
|
const files = [];
|
|
3605
|
-
if (existsSync(
|
|
3606
|
-
const workflows =
|
|
3804
|
+
if (existsSync(path21.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
3805
|
+
const workflows = path21.join(ctx.root, ".eas", "workflows");
|
|
3607
3806
|
if (existsSync(workflows)) {
|
|
3608
3807
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
3609
3808
|
}
|
|
3610
3809
|
for (const file of files) {
|
|
3611
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
3810
|
+
for (const hit of findPlaceholders(file, readFileSync(path21.join(ctx.root, file), "utf8"))) {
|
|
3612
3811
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
3613
3812
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
3614
3813
|
ctx.report({
|
|
@@ -3687,7 +3886,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3687
3886
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
3688
3887
|
const code = file.code;
|
|
3689
3888
|
const hidden = HIDES_HEADER.exec(code);
|
|
3690
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
3889
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path21.posix.dirname(file.path), file.path);
|
|
3691
3890
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
3692
3891
|
if (hidden && own) {
|
|
3693
3892
|
reported.add(file.path);
|
|
@@ -3715,7 +3914,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3715
3914
|
}
|
|
3716
3915
|
for (const file of ctx.files) {
|
|
3717
3916
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
3718
|
-
const layout = hidingLayouts.get(
|
|
3917
|
+
const layout = hidingLayouts.get(path21.posix.dirname(file.path));
|
|
3719
3918
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
3720
3919
|
if (!layout || !own) continue;
|
|
3721
3920
|
ctx.report({
|
|
@@ -3737,13 +3936,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
3737
3936
|
}
|
|
3738
3937
|
function routerRoot(ctx) {
|
|
3739
3938
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
3740
|
-
return existsSync(
|
|
3939
|
+
return existsSync(path21.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
3741
3940
|
}
|
|
3742
3941
|
function checkScreenLayouts(ctx, pkg) {
|
|
3743
3942
|
const layouts = nativeLayouts(pkg);
|
|
3744
3943
|
if (layouts.length === 0) return;
|
|
3745
3944
|
const rootDir = routerRoot(ctx);
|
|
3746
|
-
if (!existsSync(
|
|
3945
|
+
if (!existsSync(path21.join(ctx.root, rootDir))) {
|
|
3747
3946
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
3748
3947
|
return;
|
|
3749
3948
|
}
|
|
@@ -3799,7 +3998,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
3799
3998
|
function readExpoConfigs(root) {
|
|
3800
3999
|
const out = [];
|
|
3801
4000
|
for (const name of EXPO_CONFIGS) {
|
|
3802
|
-
const abs =
|
|
4001
|
+
const abs = path21.join(root, name);
|
|
3803
4002
|
if (!existsSync(abs)) continue;
|
|
3804
4003
|
const text = readFileSync(abs, "utf8");
|
|
3805
4004
|
let json = null;
|
|
@@ -3833,13 +4032,13 @@ function pluginOptions(json, module) {
|
|
|
3833
4032
|
return null;
|
|
3834
4033
|
}
|
|
3835
4034
|
function dependencies(root) {
|
|
3836
|
-
const file =
|
|
4035
|
+
const file = path21.join(root, "package.json");
|
|
3837
4036
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
3838
4037
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3839
4038
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
3840
4039
|
}
|
|
3841
4040
|
function runtimeDependencies(root) {
|
|
3842
|
-
const file =
|
|
4041
|
+
const file = path21.join(root, "package.json");
|
|
3843
4042
|
if (!existsSync(file)) return {};
|
|
3844
4043
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
3845
4044
|
}
|
|
@@ -4093,14 +4292,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
4093
4292
|
seen.add(file);
|
|
4094
4293
|
const json = readJsonc(file);
|
|
4095
4294
|
if (!json) return {};
|
|
4096
|
-
const dir =
|
|
4295
|
+
const dir = path21.dirname(file);
|
|
4097
4296
|
let merged = {};
|
|
4098
4297
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
4099
4298
|
for (const ext of parents) {
|
|
4100
4299
|
if (typeof ext !== "string") continue;
|
|
4101
4300
|
let target = null;
|
|
4102
|
-
if (ext.startsWith(".") ||
|
|
4103
|
-
const abs =
|
|
4301
|
+
if (ext.startsWith(".") || path21.isAbsolute(ext)) {
|
|
4302
|
+
const abs = path21.resolve(dir, ext);
|
|
4104
4303
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
4105
4304
|
} else {
|
|
4106
4305
|
const parts = ext.split("/");
|
|
@@ -4108,14 +4307,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
4108
4307
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
4109
4308
|
if (pkgDir) {
|
|
4110
4309
|
const sub = parts.slice(nameLength).join("/");
|
|
4111
|
-
const abs =
|
|
4310
|
+
const abs = path21.join(pkgDir, sub || "tsconfig.json");
|
|
4112
4311
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
4113
4312
|
}
|
|
4114
4313
|
}
|
|
4115
4314
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
4116
4315
|
}
|
|
4117
4316
|
const opts = json.compilerOptions ?? {};
|
|
4118
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
4317
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path21.resolve(dir, opts.baseUrl);
|
|
4119
4318
|
if (opts.paths && typeof opts.paths === "object") {
|
|
4120
4319
|
merged.paths = opts.paths;
|
|
4121
4320
|
merged.pathsDir = dir;
|
|
@@ -4126,7 +4325,7 @@ function aliases(root) {
|
|
|
4126
4325
|
const table = [];
|
|
4127
4326
|
let baseUrl = null;
|
|
4128
4327
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
4129
|
-
const file =
|
|
4328
|
+
const file = path21.join(root, name);
|
|
4130
4329
|
if (!existsSync(file)) continue;
|
|
4131
4330
|
const config = readTsconfig(root, file);
|
|
4132
4331
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -4134,22 +4333,22 @@ function aliases(root) {
|
|
|
4134
4333
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
4135
4334
|
if (!Array.isArray(targets)) continue;
|
|
4136
4335
|
const exact = !pattern.endsWith("*");
|
|
4137
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
4336
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path21.join(base, String(t).replace(/\*$/, ""))) });
|
|
4138
4337
|
}
|
|
4139
4338
|
}
|
|
4140
|
-
const pkg = readJsonc(
|
|
4339
|
+
const pkg = readJsonc(path21.join(root, "package.json"));
|
|
4141
4340
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
4142
4341
|
if (typeof target !== "string") continue;
|
|
4143
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
4342
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path21.join(root, target.replace(/\*.*$/, ""))] });
|
|
4144
4343
|
}
|
|
4145
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
4344
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path21.join(root, "src") + path21.sep, root + path21.sep] });
|
|
4146
4345
|
return { table, baseUrl };
|
|
4147
4346
|
}
|
|
4148
4347
|
function resolveFile(base) {
|
|
4149
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
4348
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path21.join(base, `index${e}`))];
|
|
4150
4349
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
4151
4350
|
for (const p of tries) {
|
|
4152
|
-
if (SCRIPT_EXTS2.has(
|
|
4351
|
+
if (SCRIPT_EXTS2.has(path21.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
4153
4352
|
}
|
|
4154
4353
|
return null;
|
|
4155
4354
|
}
|
|
@@ -4163,7 +4362,7 @@ function createTrail(ctx) {
|
|
|
4163
4362
|
const { table, baseUrl } = aliases(ctx.root);
|
|
4164
4363
|
let declared = null;
|
|
4165
4364
|
try {
|
|
4166
|
-
const pkg = JSON.parse(readFileSync(
|
|
4365
|
+
const pkg = JSON.parse(readFileSync(path21.join(ctx.root, "package.json"), "utf8"));
|
|
4167
4366
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
4168
4367
|
} catch {
|
|
4169
4368
|
declared = null;
|
|
@@ -4194,17 +4393,17 @@ function createTrail(ctx) {
|
|
|
4194
4393
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
4195
4394
|
let resolved = null;
|
|
4196
4395
|
if (spec.startsWith(".")) {
|
|
4197
|
-
resolved = resolveFile(
|
|
4396
|
+
resolved = resolveFile(path21.resolve(path21.dirname(file.absolutePath), spec));
|
|
4198
4397
|
if (!resolved) lost = true;
|
|
4199
4398
|
} else {
|
|
4200
4399
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
4201
4400
|
if (alias) {
|
|
4202
4401
|
for (const t of alias.targets) {
|
|
4203
|
-
resolved = resolveFile(alias.exact ? t :
|
|
4402
|
+
resolved = resolveFile(alias.exact ? t : path21.join(t, spec.slice(alias.prefix.length)));
|
|
4204
4403
|
if (resolved) break;
|
|
4205
4404
|
}
|
|
4206
4405
|
}
|
|
4207
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
4406
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path21.join(baseUrl, spec));
|
|
4208
4407
|
if (!resolved) {
|
|
4209
4408
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
4210
4409
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -4218,215 +4417,62 @@ function createTrail(ctx) {
|
|
|
4218
4417
|
};
|
|
4219
4418
|
const strippedCache = /* @__PURE__ */ new Map();
|
|
4220
4419
|
const stripped = (file) => {
|
|
4221
|
-
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
4222
|
-
return strippedCache.get(file.absolutePath);
|
|
4223
|
-
};
|
|
4224
|
-
const memo = /* @__PURE__ */ new WeakMap();
|
|
4225
|
-
const reach = (file, test2, depth, seen) => {
|
|
4226
|
-
let cache2 = memo.get(test2);
|
|
4227
|
-
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
4228
|
-
const k = `${file.absolutePath}\0${depth}`;
|
|
4229
|
-
const free = cache2.free.get(k);
|
|
4230
|
-
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
4231
|
-
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
4232
|
-
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
4233
|
-
let result;
|
|
4234
|
-
const cut = /* @__PURE__ */ new Set();
|
|
4235
|
-
const code = stripped(file);
|
|
4236
|
-
if (code === null) result = "unknown";
|
|
4237
|
-
else if (test2(code)) result = "yes";
|
|
4238
|
-
else {
|
|
4239
|
-
const { files, lost } = importsOf(file);
|
|
4240
|
-
let unknown = lost && depth > 0;
|
|
4241
|
-
result = "no";
|
|
4242
|
-
if (depth > 0) {
|
|
4243
|
-
seen.add(file.absolutePath);
|
|
4244
|
-
for (const abs of files) {
|
|
4245
|
-
if (seen.has(abs)) {
|
|
4246
|
-
cut.add(abs);
|
|
4247
|
-
continue;
|
|
4248
|
-
}
|
|
4249
|
-
const target = read2(abs);
|
|
4250
|
-
if (!target) {
|
|
4251
|
-
unknown = true;
|
|
4252
|
-
continue;
|
|
4253
|
-
}
|
|
4254
|
-
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
4255
|
-
for (const m of c) cut.add(m);
|
|
4256
|
-
if (r === "yes") {
|
|
4257
|
-
result = "yes";
|
|
4258
|
-
break;
|
|
4259
|
-
}
|
|
4260
|
-
if (r === "unknown") unknown = true;
|
|
4261
|
-
}
|
|
4262
|
-
seen.delete(file.absolutePath);
|
|
4263
|
-
cut.delete(file.absolutePath);
|
|
4264
|
-
}
|
|
4265
|
-
if (result === "no" && unknown) result = "unknown";
|
|
4266
|
-
}
|
|
4267
|
-
if (result === "yes" || cut.size === 0) {
|
|
4268
|
-
cache2.free.set(k, result);
|
|
4269
|
-
return [result, /* @__PURE__ */ new Set()];
|
|
4270
|
-
}
|
|
4271
|
-
const entries = cache2.cut.get(k) ?? [];
|
|
4272
|
-
entries.push({ cut: [...cut], result });
|
|
4273
|
-
cache2.cut.set(k, entries);
|
|
4274
|
-
return [result, cut];
|
|
4275
|
-
};
|
|
4276
|
-
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
4277
|
-
}
|
|
4278
|
-
function buildCatalog(packagesDir) {
|
|
4279
|
-
const packages = {};
|
|
4280
|
-
for (const dir of readdirSync(packagesDir).sort()) {
|
|
4281
|
-
const file = path20.join(packagesDir, dir, "package.json");
|
|
4282
|
-
if (!existsSync(file)) continue;
|
|
4283
|
-
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
4284
|
-
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
4285
|
-
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
4286
|
-
}
|
|
4287
|
-
return { packages };
|
|
4288
|
-
}
|
|
4289
|
-
|
|
4290
|
-
// src/blocks/discover.ts
|
|
4291
|
-
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
4292
|
-
function cliPackageDir() {
|
|
4293
|
-
let dir = path20.dirname(fileURLToPath(import.meta.url));
|
|
4294
|
-
for (; ; ) {
|
|
4295
|
-
const file = path20.join(dir, "package.json");
|
|
4296
|
-
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
4297
|
-
const parent = path20.dirname(dir);
|
|
4298
|
-
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
4299
|
-
dir = parent;
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
function workspacePackagesDir() {
|
|
4303
|
-
const dir = path20.resolve(cliPackageDir(), "..");
|
|
4304
|
-
return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
4305
|
-
}
|
|
4306
|
-
var catalogCache;
|
|
4307
|
-
function readCatalog() {
|
|
4308
|
-
if (catalogCache) return catalogCache;
|
|
4309
|
-
const workspace = workspacePackagesDir();
|
|
4310
|
-
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
4311
|
-
const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
4312
|
-
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
4313
|
-
return catalogCache;
|
|
4314
|
-
}
|
|
4315
|
-
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
4316
|
-
function installedGenesis(root) {
|
|
4317
|
-
const found = /* @__PURE__ */ new Map();
|
|
4318
|
-
let dir = path20.resolve(root);
|
|
4319
|
-
for (; ; ) {
|
|
4320
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
|
|
4321
|
-
const scope = path20.join(dir, "node_modules", "@marktiderman");
|
|
4322
|
-
if (existsSync(scope)) {
|
|
4323
|
-
for (const entry of readdirSync(scope)) {
|
|
4324
|
-
const name = `@marktiderman/${entry}`;
|
|
4325
|
-
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
4326
|
-
if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
|
|
4327
|
-
}
|
|
4328
|
-
}
|
|
4329
|
-
const parent = path20.dirname(dir);
|
|
4330
|
-
if (atInstallRoot || parent === dir) return found;
|
|
4331
|
-
dir = parent;
|
|
4332
|
-
}
|
|
4333
|
-
}
|
|
4334
|
-
var declarationCache = /* @__PURE__ */ new Map();
|
|
4335
|
-
function declarationsOf(dir, warnings) {
|
|
4336
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4337
|
-
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
4338
|
-
let cached = declarationCache.get(key2);
|
|
4339
|
-
if (!cached) {
|
|
4340
|
-
cached = loadDeclarations(dir, warnings);
|
|
4341
|
-
declarationCache.set(key2, cached);
|
|
4342
|
-
}
|
|
4343
|
-
return cached;
|
|
4344
|
-
}
|
|
4345
|
-
async function loadDeclarations(dir, warnings) {
|
|
4346
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4347
|
-
const entry = pkg.exports?.["./blocks"];
|
|
4348
|
-
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
4349
|
-
if (typeof target !== "string") return {};
|
|
4350
|
-
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
4351
|
-
const file = rel && path20.join(dir, ...rel.split("/"));
|
|
4352
|
-
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
4353
|
-
try {
|
|
4354
|
-
const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
|
|
4355
|
-
const mod = await jiti.import(file);
|
|
4356
|
-
const out = {};
|
|
4357
|
-
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
4358
|
-
return out;
|
|
4359
|
-
} catch (err) {
|
|
4360
|
-
warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
|
|
4361
|
-
return {};
|
|
4362
|
-
}
|
|
4363
|
-
}
|
|
4364
|
-
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
4365
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4366
|
-
const raw = rawBlocksOf(pkg);
|
|
4367
|
-
const declared = await declarationsOf(dir, warnings);
|
|
4368
|
-
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
4369
|
-
const out = [];
|
|
4370
|
-
for (const id of [...ids].sort()) {
|
|
4371
|
-
const fromJson = raw[id] ?? {};
|
|
4372
|
-
const merged = { ...fromJson, ...declared[id] };
|
|
4373
|
-
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
4374
|
-
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
4375
|
-
if (manifest) out.push(manifest);
|
|
4376
|
-
}
|
|
4377
|
-
return out;
|
|
4378
|
-
}
|
|
4379
|
-
function withProvides(declared, json) {
|
|
4380
|
-
if (!Array.isArray(declared)) return declared;
|
|
4381
|
-
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
4382
|
-
return declared.map((m) => {
|
|
4383
|
-
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
4384
|
-
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
4385
|
-
});
|
|
4386
|
-
}
|
|
4387
|
-
async function allBlocks(root, warnings = []) {
|
|
4388
|
-
const out = [];
|
|
4389
|
-
for (const local of localPackages(root)) {
|
|
4390
|
-
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
4391
|
-
}
|
|
4392
|
-
const installed = installedGenesis(root);
|
|
4393
|
-
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
4394
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
4395
|
-
if (installed.has(name)) continue;
|
|
4396
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
4397
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
4398
|
-
if (manifest) out.push({ manifest, from: "catalog" });
|
|
4420
|
+
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
4421
|
+
return strippedCache.get(file.absolutePath);
|
|
4422
|
+
};
|
|
4423
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
4424
|
+
const reach = (file, test2, depth, seen) => {
|
|
4425
|
+
let cache2 = memo.get(test2);
|
|
4426
|
+
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
4427
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
4428
|
+
const free = cache2.free.get(k);
|
|
4429
|
+
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
4430
|
+
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
4431
|
+
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
4432
|
+
let result;
|
|
4433
|
+
const cut = /* @__PURE__ */ new Set();
|
|
4434
|
+
const code = stripped(file);
|
|
4435
|
+
if (code === null) result = "unknown";
|
|
4436
|
+
else if (test2(code)) result = "yes";
|
|
4437
|
+
else {
|
|
4438
|
+
const { files, lost } = importsOf(file);
|
|
4439
|
+
let unknown = lost && depth > 0;
|
|
4440
|
+
result = "no";
|
|
4441
|
+
if (depth > 0) {
|
|
4442
|
+
seen.add(file.absolutePath);
|
|
4443
|
+
for (const abs of files) {
|
|
4444
|
+
if (seen.has(abs)) {
|
|
4445
|
+
cut.add(abs);
|
|
4446
|
+
continue;
|
|
4447
|
+
}
|
|
4448
|
+
const target = read2(abs);
|
|
4449
|
+
if (!target) {
|
|
4450
|
+
unknown = true;
|
|
4451
|
+
continue;
|
|
4452
|
+
}
|
|
4453
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
4454
|
+
for (const m of c) cut.add(m);
|
|
4455
|
+
if (r === "yes") {
|
|
4456
|
+
result = "yes";
|
|
4457
|
+
break;
|
|
4458
|
+
}
|
|
4459
|
+
if (r === "unknown") unknown = true;
|
|
4460
|
+
}
|
|
4461
|
+
seen.delete(file.absolutePath);
|
|
4462
|
+
cut.delete(file.absolutePath);
|
|
4463
|
+
}
|
|
4464
|
+
if (result === "no" && unknown) result = "unknown";
|
|
4399
4465
|
}
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
function tryParse(parse2, warnings) {
|
|
4404
|
-
try {
|
|
4405
|
-
return parse2();
|
|
4406
|
-
} catch (err) {
|
|
4407
|
-
if (!(err instanceof ManifestError)) throw err;
|
|
4408
|
-
warnings.push(err.message);
|
|
4409
|
-
return null;
|
|
4410
|
-
}
|
|
4411
|
-
}
|
|
4412
|
-
function catalogBlocks(warnings = []) {
|
|
4413
|
-
const out = [];
|
|
4414
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
4415
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
4416
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
4417
|
-
if (manifest) out.push(manifest);
|
|
4466
|
+
if (result === "yes" || cut.size === 0) {
|
|
4467
|
+
cache2.free.set(k, result);
|
|
4468
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
4418
4469
|
}
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
4426
|
-
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
4427
|
-
}
|
|
4428
|
-
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
4429
|
-
return all[0];
|
|
4470
|
+
const entries = cache2.cut.get(k) ?? [];
|
|
4471
|
+
entries.push({ cut: [...cut], result });
|
|
4472
|
+
cache2.cut.set(k, entries);
|
|
4473
|
+
return [result, cut];
|
|
4474
|
+
};
|
|
4475
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
4430
4476
|
}
|
|
4431
4477
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
4432
4478
|
var STEMS = {
|
|
@@ -4445,7 +4491,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
4445
4491
|
var OWN_CONTENT = /(?<![=-])>\s*[A-Za-z][^<>{}]*</.source + "|" + /(?<![\w$.])<(?:h[1-6]|ul|ol|table|dl|H[1-6]|[A-Z]\w*(?:Heading|Title|Table|List|Grid))(?=[\s>/])/.source;
|
|
4446
4492
|
function routesDir(ctx) {
|
|
4447
4493
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
4448
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
4494
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path21.join(ctx.root, d))) ?? null;
|
|
4449
4495
|
}
|
|
4450
4496
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
4451
4497
|
function flavorOf(dir, rels) {
|
|
@@ -4580,7 +4626,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
4580
4626
|
});
|
|
4581
4627
|
if (typeof raw === "string") {
|
|
4582
4628
|
if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
|
|
4583
|
-
const file =
|
|
4629
|
+
const file = path21.resolve(packageDir, raw);
|
|
4584
4630
|
if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
|
|
4585
4631
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
4586
4632
|
let parsed;
|
|
@@ -4629,7 +4675,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
4629
4675
|
if (typeof c.plugin === "string") {
|
|
4630
4676
|
if (!packageDir) plugin = c.plugin;
|
|
4631
4677
|
else {
|
|
4632
|
-
plugin =
|
|
4678
|
+
plugin = path21.resolve(packageDir, c.plugin);
|
|
4633
4679
|
if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
4634
4680
|
}
|
|
4635
4681
|
}
|
|
@@ -4679,7 +4725,7 @@ function checkPattern(v, where2, fail) {
|
|
|
4679
4725
|
}
|
|
4680
4726
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
4681
4727
|
function readDeclaringPackage(dir, local) {
|
|
4682
|
-
const file =
|
|
4728
|
+
const file = path21.join(dir, "package.json");
|
|
4683
4729
|
let stamp;
|
|
4684
4730
|
let real2;
|
|
4685
4731
|
try {
|
|
@@ -4702,7 +4748,7 @@ ${local}`;
|
|
|
4702
4748
|
const pkg = {
|
|
4703
4749
|
name: json.name,
|
|
4704
4750
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
4705
|
-
dir:
|
|
4751
|
+
dir: path21.resolve(dir),
|
|
4706
4752
|
namespace: ruleNamespace(json.name),
|
|
4707
4753
|
local,
|
|
4708
4754
|
private: json.private === true,
|
|
@@ -4716,7 +4762,7 @@ ${local}`;
|
|
|
4716
4762
|
if (raw !== void 0) {
|
|
4717
4763
|
const ignored = [];
|
|
4718
4764
|
try {
|
|
4719
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
4765
|
+
pkg.declaration = validateDeclaration(raw, json.name, path21.resolve(dir), ignored);
|
|
4720
4766
|
if (ignored.length) pkg.ignored = ignored;
|
|
4721
4767
|
} catch (err) {
|
|
4722
4768
|
pkg.error = err.message;
|
|
@@ -4735,14 +4781,14 @@ function discoverPackages(root) {
|
|
|
4735
4781
|
for (const dir of installed) {
|
|
4736
4782
|
let scope;
|
|
4737
4783
|
try {
|
|
4738
|
-
scope =
|
|
4784
|
+
scope = path21.dirname(realpathSync(dir));
|
|
4739
4785
|
} catch {
|
|
4740
4786
|
continue;
|
|
4741
4787
|
}
|
|
4742
|
-
if (
|
|
4788
|
+
if (path21.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
4743
4789
|
for (const entry of readdirSync(scope)) {
|
|
4744
4790
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
4745
|
-
const pkg = readDeclaringPackage(
|
|
4791
|
+
const pkg = readDeclaringPackage(path21.join(scope, entry), false);
|
|
4746
4792
|
if (pkg) byName.set(pkg.name, pkg);
|
|
4747
4793
|
}
|
|
4748
4794
|
}
|
|
@@ -4926,10 +4972,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
4926
4972
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
4927
4973
|
function sourceFiles(dir, rel = "") {
|
|
4928
4974
|
const out = [];
|
|
4929
|
-
for (const entry of readdirSync(
|
|
4975
|
+
for (const entry of readdirSync(path21.join(dir, rel)).sort()) {
|
|
4930
4976
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
4931
4977
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
4932
|
-
const stat = lstatSync(
|
|
4978
|
+
const stat = lstatSync(path21.join(dir, child));
|
|
4933
4979
|
if (stat.isSymbolicLink()) continue;
|
|
4934
4980
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
4935
4981
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -4952,13 +4998,13 @@ function matchPattern(pattern, spec) {
|
|
|
4952
4998
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
4953
4999
|
}
|
|
4954
5000
|
function tsconfigPaths(dir) {
|
|
4955
|
-
const file =
|
|
5001
|
+
const file = path21.join(dir, "tsconfig.json");
|
|
4956
5002
|
if (!existsSync(file)) return [];
|
|
4957
5003
|
try {
|
|
4958
5004
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
4959
5005
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
4960
|
-
const base =
|
|
4961
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
5006
|
+
const base = path21.resolve(dir, options.baseUrl ?? ".");
|
|
5007
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path21.resolve(base, t)) }));
|
|
4962
5008
|
} catch {
|
|
4963
5009
|
return [];
|
|
4964
5010
|
}
|
|
@@ -4972,8 +5018,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4972
5018
|
const hit = matchPattern(pattern, spec);
|
|
4973
5019
|
if (hit === null) continue;
|
|
4974
5020
|
return targets.some((t) => {
|
|
4975
|
-
const rel =
|
|
4976
|
-
return !rel.startsWith("..") && !
|
|
5021
|
+
const rel = path21.relative(pkg.dir, t.replace("*", hit));
|
|
5022
|
+
return !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
4977
5023
|
});
|
|
4978
5024
|
}
|
|
4979
5025
|
return null;
|
|
@@ -4986,7 +5032,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4986
5032
|
...Object.keys(json.optionalDependencies ?? {})
|
|
4987
5033
|
]);
|
|
4988
5034
|
for (const file of sourceFiles(pkg.dir)) {
|
|
4989
|
-
const code = stripForImports(readFileSync(
|
|
5035
|
+
const code = stripForImports(readFileSync(path21.join(pkg.dir, file), "utf8"));
|
|
4990
5036
|
if (code === null) continue;
|
|
4991
5037
|
const at = `${pkg.rel}/${file}`;
|
|
4992
5038
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -5011,9 +5057,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5011
5057
|
continue;
|
|
5012
5058
|
}
|
|
5013
5059
|
if (spec.startsWith(".")) {
|
|
5014
|
-
const target =
|
|
5015
|
-
const rel =
|
|
5016
|
-
if (rel.startsWith("..") ||
|
|
5060
|
+
const target = path21.resolve(pkg.dir, path21.dirname(file), spec);
|
|
5061
|
+
const rel = path21.relative(pkg.dir, target);
|
|
5062
|
+
if (rel.startsWith("..") || path21.isAbsolute(rel)) {
|
|
5017
5063
|
ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} reaches outside its folder (${spec}); move what it needs into the package or a dependency` });
|
|
5018
5064
|
}
|
|
5019
5065
|
continue;
|
|
@@ -5050,12 +5096,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5050
5096
|
const from = own ? "" : ` (in ${m.package})`;
|
|
5051
5097
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
5052
5098
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file}${from} has no pgTAP test; declare one as "test" beside it` });
|
|
5053
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
5099
|
+
} else if (typeof m.test === "string" && !existsSync(path21.join(home, m.test))) {
|
|
5054
5100
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test}${from} doesn't exist` });
|
|
5055
5101
|
}
|
|
5056
5102
|
}
|
|
5057
5103
|
}
|
|
5058
|
-
const dir =
|
|
5104
|
+
const dir = path21.join(pkg.dir, "migrations");
|
|
5059
5105
|
if (!existsSync(dir)) return;
|
|
5060
5106
|
const seen = /* @__PURE__ */ new Map();
|
|
5061
5107
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -5064,21 +5110,21 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5064
5110
|
const other = seen.get(m[1]);
|
|
5065
5111
|
if (other) ctx.report({ rule: "package-migration-number", file: `${pkg.rel}/migrations/${name}`, subject: m[1], message: `${pkg.name}: ${name} and ${other} share the number ${m[1]}; give each migration its own` });
|
|
5066
5112
|
else seen.set(m[1], name);
|
|
5067
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
5113
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path21.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
5068
5114
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/migrations/${name}`, subject: name, message: `${pkg.name}: ${name} has no pgTAP test (migrations/tests/${name.replace(/\.sql$/, ".test.sql")})` });
|
|
5069
5115
|
}
|
|
5070
5116
|
}
|
|
5071
5117
|
}
|
|
5072
5118
|
function checkExports(ctx, pkg, json) {
|
|
5073
5119
|
const targets = [];
|
|
5074
|
-
const
|
|
5120
|
+
const walk3 = (v) => {
|
|
5075
5121
|
if (typeof v === "string") targets.push(v);
|
|
5076
|
-
else if (v && typeof v === "object") for (const x of Object.values(v))
|
|
5122
|
+
else if (v && typeof v === "object") for (const x of Object.values(v)) walk3(x);
|
|
5077
5123
|
};
|
|
5078
|
-
|
|
5124
|
+
walk3(json.exports);
|
|
5079
5125
|
for (const t of targets) {
|
|
5080
5126
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
5081
|
-
if (!existsSync(
|
|
5127
|
+
if (!existsSync(path21.join(pkg.dir, t))) {
|
|
5082
5128
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
5083
5129
|
}
|
|
5084
5130
|
}
|
|
@@ -5096,11 +5142,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
5096
5142
|
function checkTaggedTests(ctx, pkg) {
|
|
5097
5143
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
5098
5144
|
if (!tests.length) return;
|
|
5099
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
5145
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path21.join(pkg.dir, f), "utf8")));
|
|
5100
5146
|
if (!tagged) ctx.report({ rule: "package-untagged-tests", level: "warn", file: pkg.rel, message: `${pkg.name}'s tests name no feature; tag them with // @feat:<feature id>` });
|
|
5101
5147
|
}
|
|
5102
5148
|
function checkRegistered(ctx, pkg) {
|
|
5103
|
-
const file =
|
|
5149
|
+
const file = path21.join(ctx.root, "features.json");
|
|
5104
5150
|
if (!existsSync(file)) return;
|
|
5105
5151
|
let doc;
|
|
5106
5152
|
try {
|
|
@@ -5110,7 +5156,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
5110
5156
|
}
|
|
5111
5157
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
5112
5158
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
5113
|
-
if (top) forms.add(
|
|
5159
|
+
if (top) forms.add(path21.relative(top, realpathSync(pkg.dir)).split(path21.sep).join("/"));
|
|
5114
5160
|
const covered = (doc.features ?? []).some(
|
|
5115
5161
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
5116
5162
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -5140,8 +5186,8 @@ function mergeBaseOf(root, base) {
|
|
|
5140
5186
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
5141
5187
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
5142
5188
|
if (!top) return;
|
|
5143
|
-
const appRelative = (fromTop) =>
|
|
5144
|
-
const inRepo =
|
|
5189
|
+
const appRelative = (fromTop) => path21.relative(realpathSync(ctx.root), path21.join(top, fromTop)).split(path21.sep).join("/");
|
|
5190
|
+
const inRepo = path21.relative(top, realpathSync(pkg.dir)).split(path21.sep).join("/");
|
|
5145
5191
|
const diff = (git(top, ["diff", "--name-status", "-M", mergeBase, "--", inRepo]) ?? "").split("\n").filter(Boolean).map((row) => row.split(" ").map((cell2, i) => i === 0 ? cell2 : appRelative(cell2)).join(" ")).join("\n");
|
|
5146
5192
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
5147
5193
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -5164,11 +5210,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
5164
5210
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
5165
5211
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
5166
5212
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
5167
|
-
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) =>
|
|
5213
|
+
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path21.join(top, f)) : [];
|
|
5168
5214
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
5169
5215
|
const named = naming.length > 0;
|
|
5170
5216
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
5171
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
5217
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path21.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
5172
5218
|
}
|
|
5173
5219
|
let jsonBefore = null;
|
|
5174
5220
|
try {
|
|
@@ -5178,7 +5224,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
5178
5224
|
}
|
|
5179
5225
|
const raw = json;
|
|
5180
5226
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
5181
|
-
const appInRepo =
|
|
5227
|
+
const appInRepo = path21.relative(top, realpathSync(ctx.root)).split(path21.sep).join("/");
|
|
5182
5228
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
5183
5229
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
5184
5230
|
if (!registry) ctx.report({ rule: "package-unversioned-change", level: "warn", file: `${pkg.rel}/package.json`, message: `${pkg.name}'s blocks or exports changed but features.ts didn't; update the features they belong to` });
|
|
@@ -5230,7 +5276,7 @@ function checkPackagesPack(ctx) {
|
|
|
5230
5276
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
5231
5277
|
}
|
|
5232
5278
|
for (const pkg of packages) {
|
|
5233
|
-
const json = JSON.parse(readFileSync(
|
|
5279
|
+
const json = JSON.parse(readFileSync(path21.join(pkg.dir, "package.json"), "utf8"));
|
|
5234
5280
|
checkImports2(ctx, pkg, json);
|
|
5235
5281
|
checkExports(ctx, pkg, json);
|
|
5236
5282
|
checkBlocks(ctx, pkg, json);
|
|
@@ -5247,7 +5293,7 @@ function emptyLock() {
|
|
|
5247
5293
|
return { version: 1, blocks: {}, files: {} };
|
|
5248
5294
|
}
|
|
5249
5295
|
function readLock(root) {
|
|
5250
|
-
const file =
|
|
5296
|
+
const file = path21.join(root, LOCK_FILE);
|
|
5251
5297
|
if (!existsSync(file)) return emptyLock();
|
|
5252
5298
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
5253
5299
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -5270,11 +5316,11 @@ function databaseElsewhere(root) {
|
|
|
5270
5316
|
const setting = readGenesisConfig(root)?.supabase;
|
|
5271
5317
|
if (setting === void 0) return null;
|
|
5272
5318
|
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
5273
|
-
const resolved =
|
|
5319
|
+
const resolved = path21.resolve(root, setting.app);
|
|
5274
5320
|
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
5275
5321
|
const dir = real2(resolved);
|
|
5276
|
-
if (dir === real2(
|
|
5277
|
-
return { app: setting.app, dir, hasSupabase: existsSync(
|
|
5322
|
+
if (dir === real2(path21.resolve(root))) throw new GenesisConfigError(`${path21.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
|
|
5323
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path21.join(dir, "supabase")) };
|
|
5278
5324
|
}
|
|
5279
5325
|
function isSupabasePath(rel) {
|
|
5280
5326
|
return rel === "supabase" || rel.startsWith("supabase/");
|
|
@@ -5464,9 +5510,9 @@ function checkSupabasePack(ctx) {
|
|
|
5464
5510
|
if (databaseElsewhere(ctx.root)) return;
|
|
5465
5511
|
const settings = ctx.config.supabase ?? {};
|
|
5466
5512
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
5467
|
-
const abs =
|
|
5513
|
+
const abs = path21.join(ctx.root, dir);
|
|
5468
5514
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
5469
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
5515
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path21.join(abs, n), "utf8")) }));
|
|
5470
5516
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
5471
5517
|
const base = settings.base ?? DEFAULT_BASE;
|
|
5472
5518
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -5483,7 +5529,7 @@ function checkSupabasePack(ctx) {
|
|
|
5483
5529
|
}
|
|
5484
5530
|
}
|
|
5485
5531
|
const since = settings.since;
|
|
5486
|
-
const afterSince = (file) => since === void 0 ||
|
|
5532
|
+
const afterSince = (file) => since === void 0 || path21.posix.basename(file) >= since;
|
|
5487
5533
|
if ("reason" in view && since === void 0) {
|
|
5488
5534
|
ctx.report({
|
|
5489
5535
|
rule: "migration-grants",
|
|
@@ -5766,7 +5812,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
|
5766
5812
|
var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
5767
5813
|
var readManifest = (dir) => {
|
|
5768
5814
|
try {
|
|
5769
|
-
return JSON.parse(readFileSync(
|
|
5815
|
+
return JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
5770
5816
|
} catch {
|
|
5771
5817
|
return null;
|
|
5772
5818
|
}
|
|
@@ -5780,18 +5826,18 @@ var real = (p) => {
|
|
|
5780
5826
|
};
|
|
5781
5827
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
5782
5828
|
function nodeModulesOf(dir) {
|
|
5783
|
-
const parent =
|
|
5784
|
-
return
|
|
5829
|
+
const parent = path21.dirname(dir);
|
|
5830
|
+
return path21.basename(parent).startsWith("@") ? path21.dirname(parent) : parent;
|
|
5785
5831
|
}
|
|
5786
5832
|
function packagesIn(nodeModules) {
|
|
5787
5833
|
if (!existsSync(nodeModules)) return [];
|
|
5788
5834
|
const out = [];
|
|
5789
5835
|
for (const entry of readdirSync(nodeModules)) {
|
|
5790
5836
|
if (entry.startsWith(".")) continue;
|
|
5791
|
-
const p =
|
|
5837
|
+
const p = path21.join(nodeModules, entry);
|
|
5792
5838
|
if (entry.startsWith("@")) {
|
|
5793
5839
|
try {
|
|
5794
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5840
|
+
for (const sub of readdirSync(p)) out.push(path21.join(p, sub));
|
|
5795
5841
|
} catch {
|
|
5796
5842
|
}
|
|
5797
5843
|
} else {
|
|
@@ -5803,7 +5849,7 @@ function packagesIn(nodeModules) {
|
|
|
5803
5849
|
function genesisInstalls(root) {
|
|
5804
5850
|
const copies = /* @__PURE__ */ new Map();
|
|
5805
5851
|
const realRoot = real(root);
|
|
5806
|
-
const rel = (abs) =>
|
|
5852
|
+
const rel = (abs) => path21.relative(realRoot, abs).split(path21.sep).join("/") || ".";
|
|
5807
5853
|
const via = /* @__PURE__ */ new Map();
|
|
5808
5854
|
const record = (real2, manifest, by, range, root2) => {
|
|
5809
5855
|
let copy = copies.get(real2);
|
|
@@ -5815,7 +5861,7 @@ function genesisInstalls(root) {
|
|
|
5815
5861
|
via.get(real2).add(root2);
|
|
5816
5862
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
5817
5863
|
};
|
|
5818
|
-
const
|
|
5864
|
+
const walk3 = (kind, roots) => {
|
|
5819
5865
|
const expanded = /* @__PURE__ */ new Set();
|
|
5820
5866
|
const queue = [];
|
|
5821
5867
|
const visit = (dir, by, range) => {
|
|
@@ -5848,7 +5894,7 @@ function genesisInstalls(root) {
|
|
|
5848
5894
|
if (!dir) return null;
|
|
5849
5895
|
if (!ownInstall || name in declared) return dir;
|
|
5850
5896
|
const realDir = real(dir);
|
|
5851
|
-
if (realDir.startsWith(realRoot +
|
|
5897
|
+
if (realDir.startsWith(realRoot + path21.sep)) return dir;
|
|
5852
5898
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
5853
5899
|
};
|
|
5854
5900
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -5856,7 +5902,7 @@ function genesisInstalls(root) {
|
|
|
5856
5902
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
5857
5903
|
});
|
|
5858
5904
|
const app = readManifest(root);
|
|
5859
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5905
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path21.join(root, f)));
|
|
5860
5906
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
5861
5907
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
5862
5908
|
const runtimeDeps = {
|
|
@@ -5866,18 +5912,18 @@ function genesisInstalls(root) {
|
|
|
5866
5912
|
...app?.dependencies
|
|
5867
5913
|
};
|
|
5868
5914
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
5869
|
-
|
|
5870
|
-
const top =
|
|
5871
|
-
|
|
5915
|
+
walk3("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5916
|
+
const top = path21.join(root, "node_modules");
|
|
5917
|
+
walk3(
|
|
5872
5918
|
"hoisted",
|
|
5873
5919
|
packagesIn(top).filter((dir) => {
|
|
5874
|
-
const name =
|
|
5920
|
+
const name = path21.relative(top, dir).split(path21.sep).join("/");
|
|
5875
5921
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
5876
5922
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
5877
5923
|
);
|
|
5878
5924
|
const devRoots = { ...devDeps };
|
|
5879
5925
|
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
5880
|
-
|
|
5926
|
+
walk3("dev", rootsOf(devRoots, "the app (dev)"));
|
|
5881
5927
|
for (const [key2, copy] of copies) {
|
|
5882
5928
|
const kinds = via.get(key2);
|
|
5883
5929
|
copy.runtime = kinds.has("runtime");
|
|
@@ -5913,7 +5959,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
5913
5959
|
}
|
|
5914
5960
|
}
|
|
5915
5961
|
function checkPeerRanges(ctx) {
|
|
5916
|
-
const rel = (abs) =>
|
|
5962
|
+
const rel = (abs) => path21.relative(ctx.root, abs).split(path21.sep).join("/");
|
|
5917
5963
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
5918
5964
|
for (const copy of copies) {
|
|
5919
5965
|
const dir = copy.absolutePath;
|
|
@@ -6100,6 +6146,24 @@ function checkIsoDateSlices(ctx) {
|
|
|
6100
6146
|
}
|
|
6101
6147
|
}
|
|
6102
6148
|
}
|
|
6149
|
+
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
6150
|
+
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
6151
|
+
var MAX_BYTES = 2 * 1024 * 1024;
|
|
6152
|
+
function appScripts(root) {
|
|
6153
|
+
const out = [];
|
|
6154
|
+
const walk3 = (dir) => {
|
|
6155
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
6156
|
+
const abs = path21.join(dir, entry.name);
|
|
6157
|
+
if (entry.isDirectory()) {
|
|
6158
|
+
if (!SKIP_DIRS3.has(entry.name)) walk3(abs);
|
|
6159
|
+
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
6160
|
+
out.push(path21.relative(root, abs).split(path21.sep).join("/"));
|
|
6161
|
+
}
|
|
6162
|
+
}
|
|
6163
|
+
};
|
|
6164
|
+
walk3(root);
|
|
6165
|
+
return out;
|
|
6166
|
+
}
|
|
6103
6167
|
|
|
6104
6168
|
// src/upgrade/scope-names.ts
|
|
6105
6169
|
var IMPORTS_GENESIS = /\bfrom\s*["']@marktiderman\/genesis[\w/-]*["']/;
|
|
@@ -6294,11 +6358,11 @@ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
|
|
|
6294
6358
|
var TESTING_LIBRARY = "eslint-plugin-testing-library";
|
|
6295
6359
|
var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
|
|
6296
6360
|
function findEslintConfig(root) {
|
|
6297
|
-
return FLAT_CONFIG_FILES.find((name) => existsSync(
|
|
6361
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path21.join(root, name))) ?? null;
|
|
6298
6362
|
}
|
|
6299
6363
|
function readPackageJson(root) {
|
|
6300
6364
|
try {
|
|
6301
|
-
return JSON.parse(readFileSync(
|
|
6365
|
+
return JSON.parse(readFileSync(path21.join(root, "package.json"), "utf8"));
|
|
6302
6366
|
} catch {
|
|
6303
6367
|
return null;
|
|
6304
6368
|
}
|
|
@@ -6314,26 +6378,6 @@ function usesGenesisLint(text) {
|
|
|
6314
6378
|
return text.includes(ESLINT_EXPORT);
|
|
6315
6379
|
}
|
|
6316
6380
|
|
|
6317
|
-
// src/upgrade/codemods.ts
|
|
6318
|
-
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
6319
|
-
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
6320
|
-
var MAX_BYTES = 2 * 1024 * 1024;
|
|
6321
|
-
function appScripts(root) {
|
|
6322
|
-
const out = [];
|
|
6323
|
-
const walk2 = (dir) => {
|
|
6324
|
-
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
6325
|
-
const abs = path20.join(dir, entry.name);
|
|
6326
|
-
if (entry.isDirectory()) {
|
|
6327
|
-
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
6328
|
-
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
6329
|
-
out.push(path20.relative(root, abs).split(path20.sep).join("/"));
|
|
6330
|
-
}
|
|
6331
|
-
}
|
|
6332
|
-
};
|
|
6333
|
-
walk2(root);
|
|
6334
|
-
return out;
|
|
6335
|
-
}
|
|
6336
|
-
|
|
6337
6381
|
// src/doctor/api-usage.ts
|
|
6338
6382
|
var SCRIPT_EXTS5 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
6339
6383
|
function openingTag(code, start) {
|
|
@@ -6414,7 +6458,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
6414
6458
|
function moduleFiles(ctx) {
|
|
6415
6459
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
6416
6460
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
6417
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
6461
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path21.join(ctx.root, rel), "utf8"), true) }));
|
|
6418
6462
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
6419
6463
|
}
|
|
6420
6464
|
function checkStudioServerImports(ctx) {
|
|
@@ -6450,7 +6494,7 @@ var REMOVED_WORDS = {
|
|
|
6450
6494
|
};
|
|
6451
6495
|
function checkRemovedScopeNames(ctx) {
|
|
6452
6496
|
let augmentedMemo;
|
|
6453
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
6497
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path21.join(ctx.root, rel), "utf8")));
|
|
6454
6498
|
for (const file of ctx.files) {
|
|
6455
6499
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
6456
6500
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -6522,16 +6566,16 @@ function genesisNamedImports(source) {
|
|
|
6522
6566
|
}
|
|
6523
6567
|
function declarationFiles(dir, out = []) {
|
|
6524
6568
|
for (const name of readdirSync(dir)) {
|
|
6525
|
-
const full =
|
|
6569
|
+
const full = path21.join(dir, name);
|
|
6526
6570
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
6527
6571
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
6528
6572
|
}
|
|
6529
6573
|
return out;
|
|
6530
6574
|
}
|
|
6531
6575
|
function readPackageTags(dir) {
|
|
6532
|
-
const pkg = JSON.parse(readFileSync(
|
|
6576
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
6533
6577
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
6534
|
-
const dist =
|
|
6578
|
+
const dist = path21.join(dir, "dist");
|
|
6535
6579
|
if (!existsSync(dist)) return tags;
|
|
6536
6580
|
for (const file of declarationFiles(dist)) {
|
|
6537
6581
|
const text = readFileSync(file, "utf8");
|
|
@@ -6549,7 +6593,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
6549
6593
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
6550
6594
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
6551
6595
|
const types = typeof target === "object" && target ? target.types : null;
|
|
6552
|
-
return typeof types === "string" ?
|
|
6596
|
+
return typeof types === "string" ? path21.join(tags.dir, types) : null;
|
|
6553
6597
|
}
|
|
6554
6598
|
function tagFor(tags, entry, name) {
|
|
6555
6599
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -6604,7 +6648,7 @@ function showAt(dir, rev, file) {
|
|
|
6604
6648
|
function configAtBase(root, base, explicitFile) {
|
|
6605
6649
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
6606
6650
|
if (!mergeBase) return null;
|
|
6607
|
-
const candidates = explicitFile ? [{ dir:
|
|
6651
|
+
const candidates = explicitFile ? [{ dir: path21.dirname(explicitFile), file: path21.basename(explicitFile), explicit: true }] : [
|
|
6608
6652
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
6609
6653
|
{ dir: root, file: "package.json", explicit: false }
|
|
6610
6654
|
];
|
|
@@ -6716,7 +6760,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6716
6760
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
6717
6761
|
let current = null;
|
|
6718
6762
|
try {
|
|
6719
|
-
current = lf(readFileSync(
|
|
6763
|
+
current = lf(readFileSync(path21.join(ctx.root, out), "utf8"));
|
|
6720
6764
|
} catch {
|
|
6721
6765
|
current = null;
|
|
6722
6766
|
}
|
|
@@ -6740,7 +6784,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6740
6784
|
ctx.report({ rule: "contracts-stale", level: generation ? "error" : "warn", file: out, message: generation ? `couldn't be generated: ${message}` : `couldn't read the database through ${env}: ${message}` });
|
|
6741
6785
|
return;
|
|
6742
6786
|
}
|
|
6743
|
-
const target =
|
|
6787
|
+
const target = path21.relative(process.cwd(), path21.join(ctx.root, out)) || out;
|
|
6744
6788
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
6745
6789
|
if (current !== expected) {
|
|
6746
6790
|
ctx.report({
|
|
@@ -6754,7 +6798,7 @@ var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
|
|
|
6754
6798
|
var CORE = [
|
|
6755
6799
|
{
|
|
6756
6800
|
need: "anything, before building it",
|
|
6757
|
-
use: 'search what exists: `genesis features find <term>`, this catalog, and the
|
|
6801
|
+
use: 'search what exists: `genesis features find <term>`, this catalog, and the "Available but unused" list in `genesis doctor --verbose`',
|
|
6758
6802
|
docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
|
|
6759
6803
|
from: "genesis-cli"
|
|
6760
6804
|
},
|
|
@@ -6883,8 +6927,8 @@ function currentAgentsBlock(agents) {
|
|
|
6883
6927
|
var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6884
6928
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6885
6929
|
const rows = primitivesCatalog(packages);
|
|
6886
|
-
const skill = read(
|
|
6887
|
-
const block = currentAgentsBlock(read(
|
|
6930
|
+
const skill = read(path21.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
6931
|
+
const block = currentAgentsBlock(read(path21.join(root, agentsFile)));
|
|
6888
6932
|
return {
|
|
6889
6933
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6890
6934
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -6906,36 +6950,14 @@ function checkAgentGuide(ctx) {
|
|
|
6906
6950
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6907
6951
|
}
|
|
6908
6952
|
}
|
|
6909
|
-
var CLI = "@marktiderman/genesis-cli";
|
|
6910
|
-
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6911
|
-
let parsed;
|
|
6912
|
-
try {
|
|
6913
|
-
parsed = parseSource(source);
|
|
6914
|
-
} catch (err) {
|
|
6915
|
-
return err instanceof Error ? err.message : String(err);
|
|
6916
|
-
}
|
|
6917
|
-
const { package: pkg, path: rel } = parsed;
|
|
6918
|
-
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6919
|
-
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6920
|
-
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6921
|
-
const base = rel.split("/").pop();
|
|
6922
|
-
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6923
|
-
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6924
|
-
}
|
|
6925
|
-
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6926
|
-
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6927
|
-
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6928
|
-
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6929
|
-
return `${key2} doesn't match its source ${source}`;
|
|
6930
|
-
}
|
|
6931
6953
|
|
|
6932
6954
|
// src/blocks/templates.ts
|
|
6933
6955
|
function starterDir() {
|
|
6934
6956
|
const workspace = workspacePackagesDir();
|
|
6935
|
-
const live = workspace &&
|
|
6936
|
-
if (live && existsSync(
|
|
6937
|
-
const packaged =
|
|
6938
|
-
if (existsSync(
|
|
6957
|
+
const live = workspace && path21.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
6958
|
+
if (live && existsSync(path21.join(live, "package.json"))) return live;
|
|
6959
|
+
const packaged = path21.join(cliPackageDir(), "dist", "starter");
|
|
6960
|
+
if (existsSync(path21.join(packaged, "package.json"))) return packaged;
|
|
6939
6961
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
6940
6962
|
}
|
|
6941
6963
|
|
|
@@ -7009,7 +7031,7 @@ function readText(file) {
|
|
|
7009
7031
|
}
|
|
7010
7032
|
function starterBlockMap(root) {
|
|
7011
7033
|
if (root) {
|
|
7012
|
-
const file =
|
|
7034
|
+
const file = path21.join(root, GENESIS_CONFIG);
|
|
7013
7035
|
const text2 = readText(file);
|
|
7014
7036
|
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
7015
7037
|
if (own) return own;
|
|
@@ -7020,7 +7042,7 @@ function starterBlockMap(root) {
|
|
|
7020
7042
|
} catch {
|
|
7021
7043
|
return {};
|
|
7022
7044
|
}
|
|
7023
|
-
const text = readText(
|
|
7045
|
+
const text = readText(path21.join(dir, GENESIS_CONFIG));
|
|
7024
7046
|
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
7025
7047
|
}
|
|
7026
7048
|
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
@@ -7040,10 +7062,10 @@ function blocksSwitchedOff(switches, map, manifests, present) {
|
|
|
7040
7062
|
return off;
|
|
7041
7063
|
}
|
|
7042
7064
|
function appBlocksSwitchedOff(root, manifests, present) {
|
|
7043
|
-
const text = readText(
|
|
7065
|
+
const text = readText(path21.join(root, STARTER_CONFIG));
|
|
7044
7066
|
const switches = text === null ? null : parseStarterFeatures(text);
|
|
7045
7067
|
if (!switches) return /* @__PURE__ */ new Map();
|
|
7046
|
-
return blocksSwitchedOff(switches, starterBlockMap(existsSync(
|
|
7068
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path21.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
7047
7069
|
}
|
|
7048
7070
|
function blockOfSource(source, manifests) {
|
|
7049
7071
|
const at = source.indexOf(":");
|
|
@@ -7056,6 +7078,34 @@ function blockOfSource(source, manifests) {
|
|
|
7056
7078
|
}
|
|
7057
7079
|
return null;
|
|
7058
7080
|
}
|
|
7081
|
+
|
|
7082
|
+
// src/blocks/app-folder.ts
|
|
7083
|
+
function appFolderOf(root) {
|
|
7084
|
+
return readGenesisConfig(root)?.appFolder ?? null;
|
|
7085
|
+
}
|
|
7086
|
+
var isRepositoryWorkflow = (rel) => rel.startsWith(".github/workflows/");
|
|
7087
|
+
var CLI = "@marktiderman/genesis-cli";
|
|
7088
|
+
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
7089
|
+
let parsed;
|
|
7090
|
+
try {
|
|
7091
|
+
parsed = parseSource(source);
|
|
7092
|
+
} catch (err) {
|
|
7093
|
+
return err instanceof Error ? err.message : String(err);
|
|
7094
|
+
}
|
|
7095
|
+
const { package: pkg, path: rel } = parsed;
|
|
7096
|
+
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
7097
|
+
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
7098
|
+
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
7099
|
+
const base = rel.split("/").pop();
|
|
7100
|
+
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
7101
|
+
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
7102
|
+
}
|
|
7103
|
+
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
7104
|
+
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
7105
|
+
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
7106
|
+
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
7107
|
+
return `${key2} doesn't match its source ${source}`;
|
|
7108
|
+
}
|
|
7059
7109
|
var BUN_LOCK = "bun.lock";
|
|
7060
7110
|
var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
|
|
7061
7111
|
var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
|
|
@@ -7188,21 +7238,9 @@ function staleNestedEntries(text, want = () => null) {
|
|
|
7188
7238
|
return out;
|
|
7189
7239
|
}
|
|
7190
7240
|
function readBunLock(dir) {
|
|
7191
|
-
const file =
|
|
7241
|
+
const file = path21.join(dir, BUN_LOCK);
|
|
7192
7242
|
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
7193
7243
|
}
|
|
7194
|
-
function findLockfile(root) {
|
|
7195
|
-
let dir = path20.resolve(root);
|
|
7196
|
-
for (; ; ) {
|
|
7197
|
-
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
7198
|
-
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
7199
|
-
if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
7200
|
-
if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
7201
|
-
const parent = path20.dirname(dir);
|
|
7202
|
-
if (parent === dir) return null;
|
|
7203
|
-
dir = parent;
|
|
7204
|
-
}
|
|
7205
|
-
}
|
|
7206
7244
|
|
|
7207
7245
|
// src/doctor/lock-files.ts
|
|
7208
7246
|
function checkBunLock(ctx) {
|
|
@@ -7210,7 +7248,7 @@ function checkBunLock(ctx) {
|
|
|
7210
7248
|
if (found?.pm !== "bun") return;
|
|
7211
7249
|
const text = readBunLock(found.dir);
|
|
7212
7250
|
if (text === null) return;
|
|
7213
|
-
const file =
|
|
7251
|
+
const file = path21.relative(ctx.root, path21.join(found.dir, BUN_LOCK)).split(path21.sep).join("/");
|
|
7214
7252
|
let stale;
|
|
7215
7253
|
try {
|
|
7216
7254
|
stale = staleNestedEntries(text);
|
|
@@ -7229,7 +7267,7 @@ function checkBunLock(ctx) {
|
|
|
7229
7267
|
}
|
|
7230
7268
|
async function checkLockFiles(ctx) {
|
|
7231
7269
|
checkBunLock(ctx);
|
|
7232
|
-
if (!existsSync(
|
|
7270
|
+
if (!existsSync(path21.join(ctx.root, LOCK_FILE))) return;
|
|
7233
7271
|
let lock;
|
|
7234
7272
|
try {
|
|
7235
7273
|
lock = readLock(ctx.root);
|
|
@@ -7262,6 +7300,11 @@ async function checkLockFiles(ctx) {
|
|
|
7262
7300
|
home = databaseElsewhere(ctx.root);
|
|
7263
7301
|
} catch {
|
|
7264
7302
|
}
|
|
7303
|
+
let appFolder = null;
|
|
7304
|
+
try {
|
|
7305
|
+
appFolder = appFolderOf(ctx.root);
|
|
7306
|
+
} catch {
|
|
7307
|
+
}
|
|
7265
7308
|
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
7266
7309
|
if (home && elsewhere.length) {
|
|
7267
7310
|
ctx.report({
|
|
@@ -7297,6 +7340,7 @@ async function checkLockFiles(ctx) {
|
|
|
7297
7340
|
}
|
|
7298
7341
|
if (text === null) {
|
|
7299
7342
|
if (entry.deleted) continue;
|
|
7343
|
+
if (appFolder && isRepositoryWorkflow(rel)) continue;
|
|
7300
7344
|
ctx.report({
|
|
7301
7345
|
rule: "lock-files",
|
|
7302
7346
|
level: "warn",
|
|
@@ -7331,7 +7375,7 @@ function checkDatabaseHome(ctx) {
|
|
|
7331
7375
|
message: `supabase.app is ${home.app}, which has no supabase folder; name the app that holds this app's database (its migrations, tests and Edge Functions)`
|
|
7332
7376
|
});
|
|
7333
7377
|
}
|
|
7334
|
-
if (existsSync(
|
|
7378
|
+
if (existsSync(path21.join(ctx.root, "supabase"))) {
|
|
7335
7379
|
ctx.report({
|
|
7336
7380
|
rule: "database-elsewhere",
|
|
7337
7381
|
level: "warn",
|
|
@@ -7349,7 +7393,7 @@ function checkEslintConfig(ctx) {
|
|
|
7349
7393
|
if (!file) return;
|
|
7350
7394
|
let text;
|
|
7351
7395
|
try {
|
|
7352
|
-
text = readFileSync(
|
|
7396
|
+
text = readFileSync(path21.join(ctx.root, file), "utf8");
|
|
7353
7397
|
} catch {
|
|
7354
7398
|
return;
|
|
7355
7399
|
}
|
|
@@ -7369,11 +7413,372 @@ function checkEslintConfig(ctx) {
|
|
|
7369
7413
|
subject: TESTING_LIBRARY,
|
|
7370
7414
|
message: `${file} loads Genesis's native lint rules, which need ${TESTING_LIBRARY}: add it to devDependencies (pnpm add -D ${TESTING_LIBRARY}), or the lint can't load its config`
|
|
7371
7415
|
});
|
|
7416
|
+
} else if (!findPackageDir(ctx.root, TESTING_LIBRARY)) {
|
|
7417
|
+
ctx.report({
|
|
7418
|
+
rule: "genesis-eslint-config",
|
|
7419
|
+
level: "warn",
|
|
7420
|
+
file: "package.json",
|
|
7421
|
+
subject: TESTING_LIBRARY,
|
|
7422
|
+
message: `lists ${TESTING_LIBRARY}, which ${file} needs, but it isn't installed, so the lint can't load its config: run ${shellLine(installCommand(detectPackageManager(ctx.root)))}`
|
|
7423
|
+
});
|
|
7424
|
+
}
|
|
7425
|
+
}
|
|
7426
|
+
var FigmaConfigError = class extends Error {
|
|
7427
|
+
};
|
|
7428
|
+
function validateFigmaConfig(raw, source = "genesis.config.json") {
|
|
7429
|
+
const obj = raw;
|
|
7430
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) throw new FigmaConfigError(`${source}: figma must be an object`);
|
|
7431
|
+
if (typeof obj.file !== "string" || !/^[A-Za-z0-9]+$/.test(obj.file)) throw new FigmaConfigError(`${source}: figma.file must be the file key (letters and digits, from the file's URL)`);
|
|
7432
|
+
const pages = obj.pages;
|
|
7433
|
+
if (!pages || typeof pages !== "object" || Array.isArray(pages)) throw new FigmaConfigError(`${source}: figma.pages must be { "web"?: "<page>", "native"?: "<page>" }`);
|
|
7434
|
+
const out = {};
|
|
7435
|
+
for (const [k, v] of Object.entries(pages)) {
|
|
7436
|
+
if (k !== "web" && k !== "native") throw new FigmaConfigError(`${source}: figma.pages.${k}: only "web" and "native"`);
|
|
7437
|
+
if (typeof v !== "string" || !v) throw new FigmaConfigError(`${source}: figma.pages.${k} must be a page name`);
|
|
7438
|
+
out[k] = v;
|
|
7439
|
+
}
|
|
7440
|
+
if (!out.web && !out.native) throw new FigmaConfigError(`${source}: figma.pages needs "web" or "native"`);
|
|
7441
|
+
if (obj.proposalsPage !== void 0 && (typeof obj.proposalsPage !== "string" || !obj.proposalsPage)) throw new FigmaConfigError(`${source}: figma.proposalsPage must be a page name`);
|
|
7442
|
+
return { file: obj.file, pages: out, proposalsPage: obj.proposalsPage ?? "Proposals" };
|
|
7443
|
+
}
|
|
7444
|
+
function readFigmaConfig(root) {
|
|
7445
|
+
const file = path21.join(root, "genesis.config.json");
|
|
7446
|
+
if (!existsSync(file)) return null;
|
|
7447
|
+
let raw;
|
|
7448
|
+
try {
|
|
7449
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
7450
|
+
} catch (err) {
|
|
7451
|
+
throw new FigmaConfigError(`${file} isn't valid JSON: ${err.message}`);
|
|
7452
|
+
}
|
|
7453
|
+
return raw?.figma === void 0 ? null : validateFigmaConfig(raw.figma, file);
|
|
7454
|
+
}
|
|
7455
|
+
var CODE = /\.(?:tsx|ts|jsx|js)$/;
|
|
7456
|
+
var FIGMA_ID = /^\s*\/\/\s*figma:\s*(\d+[:-]\d+)\s*$/;
|
|
7457
|
+
function walk2(dir, out = []) {
|
|
7458
|
+
if (!existsSync(dir)) return out;
|
|
7459
|
+
for (const name of readdirSync(dir).sort()) {
|
|
7460
|
+
if (name === "node_modules" || name.startsWith(".")) continue;
|
|
7461
|
+
const full = path21.join(dir, name);
|
|
7462
|
+
if (statSync(full).isDirectory()) walk2(full, out);
|
|
7463
|
+
else if (CODE.test(name) && !/\.(?:test|spec|d)\.[jt]sx?$/.test(name)) out.push(full);
|
|
7464
|
+
}
|
|
7465
|
+
return out;
|
|
7466
|
+
}
|
|
7467
|
+
function figmaIdOf(code) {
|
|
7468
|
+
for (const line of code.split("\n").slice(0, 5)) {
|
|
7469
|
+
const m = FIGMA_ID.exec(line);
|
|
7470
|
+
if (m) return m[1].replace("-", ":");
|
|
7471
|
+
}
|
|
7472
|
+
return void 0;
|
|
7473
|
+
}
|
|
7474
|
+
function tanstackSegments(stem) {
|
|
7475
|
+
const out = [];
|
|
7476
|
+
let cur = "";
|
|
7477
|
+
let depth = 0;
|
|
7478
|
+
for (const ch of stem) {
|
|
7479
|
+
if (ch === "{") depth++;
|
|
7480
|
+
if (ch === "}") depth--;
|
|
7481
|
+
if (ch === "." && depth === 0) {
|
|
7482
|
+
out.push(cur);
|
|
7483
|
+
cur = "";
|
|
7484
|
+
} else cur += ch;
|
|
7485
|
+
}
|
|
7486
|
+
out.push(cur);
|
|
7487
|
+
return out;
|
|
7488
|
+
}
|
|
7489
|
+
function expoRoot(root) {
|
|
7490
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path21.join(root, dir))) return dir;
|
|
7491
|
+
return null;
|
|
7492
|
+
}
|
|
7493
|
+
function appRoutes(root) {
|
|
7494
|
+
const out = [];
|
|
7495
|
+
const rel = (f) => path21.relative(root, f).split(path21.sep).join("/");
|
|
7496
|
+
const expo = expoRoot(root);
|
|
7497
|
+
if (expo) {
|
|
7498
|
+
for (const f of walk2(path21.join(root, expo))) {
|
|
7499
|
+
const parts = path21.relative(path21.join(root, expo), f).split(path21.sep);
|
|
7500
|
+
const stem = parts.pop().replace(CODE, "");
|
|
7501
|
+
if (stem === "_layout" || stem.startsWith("+")) continue;
|
|
7502
|
+
if (stem !== "index") parts.push(stem);
|
|
7503
|
+
out.push(withId({ route: parts.join("/") || "index", platform: "native", file: rel(f) }, f));
|
|
7504
|
+
}
|
|
7505
|
+
}
|
|
7506
|
+
const tanstack = path21.join(root, "src/routes");
|
|
7507
|
+
if (existsSync(tanstack)) {
|
|
7508
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7509
|
+
for (const f of walk2(tanstack)) {
|
|
7510
|
+
const parts = path21.relative(tanstack, f).split(path21.sep);
|
|
7511
|
+
const stem = parts.pop().replace(CODE, "").replace(/\.lazy$/, "");
|
|
7512
|
+
if (stem === "__root" || stem === "route" || stem.startsWith("-") || parts.some((p) => p.startsWith("-"))) continue;
|
|
7513
|
+
const segs = [...parts.flatMap(tanstackSegments), ...tanstackSegments(stem)];
|
|
7514
|
+
if (segs.at(-1) === "index") segs.pop();
|
|
7515
|
+
const route = segs.join("/") || "index";
|
|
7516
|
+
if (seen.has(route)) continue;
|
|
7517
|
+
seen.add(route);
|
|
7518
|
+
out.push(withId({ route, platform: "web", file: rel(f) }, f));
|
|
7519
|
+
}
|
|
7520
|
+
}
|
|
7521
|
+
return out;
|
|
7522
|
+
}
|
|
7523
|
+
function withId(r, file) {
|
|
7524
|
+
const id = figmaIdOf(readFileSync(file, "utf8"));
|
|
7525
|
+
return id ? { ...r, figmaId: id } : r;
|
|
7526
|
+
}
|
|
7527
|
+
function urlSegments(route) {
|
|
7528
|
+
return route.replace(/^\/+/, "").split("/").filter((s) => s && s !== "index" && !/^\(.*\)$/.test(s) && !/^_/.test(s)).map((s) => s.replace(/_$/, "")).map((s) => /^\{-\$.*\}$/.test(s) ? "?" : /^\[\.\.\..+\]$/.test(s) ? "**" : /^\$|^\[.*\]$/.test(s) ? "*" : s);
|
|
7529
|
+
}
|
|
7530
|
+
function routeMatches(route, target) {
|
|
7531
|
+
const pattern = urlSegments(route);
|
|
7532
|
+
const url = target.split(/[?#]/)[0].split("/").filter(Boolean);
|
|
7533
|
+
if (/(?:^|\/)\$$/.test(route)) {
|
|
7534
|
+
const head = pattern.slice(0, -1);
|
|
7535
|
+
return url.length >= head.length && head.every((p, i) => p === "*" || p === url[i]);
|
|
7536
|
+
}
|
|
7537
|
+
const go = (i, j) => {
|
|
7538
|
+
if (i === pattern.length) return j === url.length;
|
|
7539
|
+
const p = pattern[i];
|
|
7540
|
+
if (p === "?") return go(i + 1, j) || j < url.length && go(i + 1, j + 1);
|
|
7541
|
+
if (j === url.length) return false;
|
|
7542
|
+
if (p === "**") {
|
|
7543
|
+
for (let k = j + 1; k <= url.length; k++) if (go(i + 1, k)) return true;
|
|
7544
|
+
return false;
|
|
7545
|
+
}
|
|
7546
|
+
return (p === "*" || p === url[j]) && go(i + 1, j + 1);
|
|
7547
|
+
};
|
|
7548
|
+
return go(0, 0);
|
|
7549
|
+
}
|
|
7550
|
+
function sameScreen(a, b) {
|
|
7551
|
+
return a.replace(/^\/+/, "") === b.replace(/^\/+/, "") || urlSegments(a).join("/") === urlSegments(b).join("/");
|
|
7552
|
+
}
|
|
7553
|
+
var STR = String.raw`(?:"([^"\n]*)"|'([^'\n]*)'|` + "`([^`$\\n]*)`)";
|
|
7554
|
+
var NAV_PATTERNS = [
|
|
7555
|
+
new RegExp(String.raw`\brouter\.(?:push|replace|navigate)\(\s*` + STR, "g"),
|
|
7556
|
+
new RegExp(String.raw`<Link\b[^>]*?\b(?:href|to)=\{?\s*` + STR, "g"),
|
|
7557
|
+
new RegExp(String.raw`\bnavigate\(\s*\{[^}]*?\bto\s*:\s*` + STR, "g")
|
|
7558
|
+
];
|
|
7559
|
+
var DYNAMIC_PATTERNS = [
|
|
7560
|
+
new RegExp(String.raw`\brouter\.(?:push|replace|navigate)\(\s*` + "(`[^`\\n]*\\$\\{[^`\\n]*`)", "g"),
|
|
7561
|
+
new RegExp(String.raw`<Link\b[^>]*?\b(?:href|to)=\{\s*` + "(`[^`\\n]*\\$\\{[^`\\n]*`)", "g"),
|
|
7562
|
+
new RegExp(String.raw`\bnavigate\(\s*\{[^}]*?\bto\s*:\s*` + "(`[^`\\n]*\\$\\{[^`\\n]*`)", "g"),
|
|
7563
|
+
new RegExp(String.raw`\brouter\.(?:push|replace|navigate)\(\s*(\{[^}\n]*?\bpathname\b[^}\n]*\}?)`, "g"),
|
|
7564
|
+
new RegExp(String.raw`<Link\b[^>]*?\bhref=\{(\{[^}\n]*?\bpathname\b[^}\n]*\}?)`, "g")
|
|
7565
|
+
];
|
|
7566
|
+
function dynamicNavTargets(code, file) {
|
|
7567
|
+
const out = [];
|
|
7568
|
+
for (const re of DYNAMIC_PATTERNS) {
|
|
7569
|
+
for (const m of code.matchAll(re)) {
|
|
7570
|
+
const raw = m[1].trim();
|
|
7571
|
+
out.push({ file, line: code.slice(0, m.index).split("\n").length, target: raw.length > 60 ? `${raw.slice(0, 57)}...` : raw });
|
|
7572
|
+
}
|
|
7573
|
+
}
|
|
7574
|
+
return out.sort((a, b) => a.line - b.line);
|
|
7575
|
+
}
|
|
7576
|
+
function navTargets(code, file) {
|
|
7577
|
+
const out = [];
|
|
7578
|
+
for (const re of NAV_PATTERNS) {
|
|
7579
|
+
for (const m of code.matchAll(re)) {
|
|
7580
|
+
const target = m[1] ?? m[2] ?? m[3];
|
|
7581
|
+
if (target === void 0 || /^[a-z]+:/i.test(target) || target.startsWith("#") || target.startsWith(".")) continue;
|
|
7582
|
+
out.push({ file, line: code.slice(0, m.index).split("\n").length, target });
|
|
7583
|
+
}
|
|
7584
|
+
}
|
|
7585
|
+
return out.sort((a, b) => a.line - b.line);
|
|
7586
|
+
}
|
|
7587
|
+
function appNavTargets(root) {
|
|
7588
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path21.join(root, "src")), ...walk2(path21.join(root, "app"))])];
|
|
7589
|
+
return files.flatMap((f) => navTargets(readFileSync(f, "utf8"), path21.relative(root, f).split(path21.sep).join("/")));
|
|
7590
|
+
}
|
|
7591
|
+
function appDynamicNavTargets(root) {
|
|
7592
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path21.join(root, "src")), ...walk2(path21.join(root, "app"))])];
|
|
7593
|
+
return files.flatMap((f) => dynamicNavTargets(readFileSync(f, "utf8"), path21.relative(root, f).split(path21.sep).join("/")));
|
|
7594
|
+
}
|
|
7595
|
+
var FIGMA_API = "https://api.figma.com";
|
|
7596
|
+
var FIGMA_TIMEOUT_MS = 3e4;
|
|
7597
|
+
function splitName(name) {
|
|
7598
|
+
const i = name.indexOf(" \xB7 ");
|
|
7599
|
+
return i < 0 ? { route: name.trim() } : { route: name.slice(0, i).trim(), state: name.slice(i + 3).trim() };
|
|
7600
|
+
}
|
|
7601
|
+
function destinations(node, out = /* @__PURE__ */ new Set()) {
|
|
7602
|
+
if (node.transitionNodeID) out.add(node.transitionNodeID);
|
|
7603
|
+
for (const i of node.interactions ?? []) {
|
|
7604
|
+
for (const a of i.actions ?? []) if (a?.type === "NODE" && a.destinationId && a.navigation !== "CHANGE_TO") out.add(a.destinationId);
|
|
7605
|
+
}
|
|
7606
|
+
for (const c of node.children ?? []) destinations(c, out);
|
|
7607
|
+
return out;
|
|
7608
|
+
}
|
|
7609
|
+
var SCREEN_TYPES = /* @__PURE__ */ new Set(["FRAME", "COMPONENT", "COMPONENT_SET", "INSTANCE"]);
|
|
7610
|
+
async function readFigma(config, token, fetchImpl = fetch, timeoutMs = FIGMA_TIMEOUT_MS) {
|
|
7611
|
+
const get2 = async (p) => {
|
|
7612
|
+
const where2 = p.split("?")[0];
|
|
7613
|
+
try {
|
|
7614
|
+
const res = await fetchImpl(`${FIGMA_API}${p}`, { headers: { "X-Figma-Token": token }, signal: AbortSignal.timeout(timeoutMs) });
|
|
7615
|
+
if (!res.ok) throw new Error(`Figma API ${where2} answered ${res.status}${res.status === 403 ? " (check FIGMA_ACCESS_TOKEN and its access to the file)" : ""}`);
|
|
7616
|
+
return await res.json();
|
|
7617
|
+
} catch (err) {
|
|
7618
|
+
const name = err?.name;
|
|
7619
|
+
if (name === "TimeoutError" || name === "AbortError") throw new Error(`Figma API ${where2} didn't answer within ${Math.round(timeoutMs / 1e3)}s`);
|
|
7620
|
+
throw err;
|
|
7621
|
+
}
|
|
7622
|
+
};
|
|
7623
|
+
const nodes = async (ids, depth) => {
|
|
7624
|
+
const out = [];
|
|
7625
|
+
for (let i = 0; i < ids.length; i += 50) {
|
|
7626
|
+
const chunk = ids.slice(i, i + 50);
|
|
7627
|
+
const body = await get2(`/v1/files/${config.file}/nodes?ids=${encodeURIComponent(chunk.join(","))}${depth ? `&depth=${depth}` : ""}`);
|
|
7628
|
+
for (const id of chunk) {
|
|
7629
|
+
const doc = body.nodes[id]?.document;
|
|
7630
|
+
if (doc) out.push(doc);
|
|
7631
|
+
}
|
|
7632
|
+
}
|
|
7633
|
+
return out;
|
|
7634
|
+
};
|
|
7635
|
+
const file = await get2(`/v1/files/${config.file}?depth=2`);
|
|
7636
|
+
const canvases = file.document.children ?? [];
|
|
7637
|
+
const wanted = /* @__PURE__ */ new Set([...Object.values(config.pages), config.proposalsPage]);
|
|
7638
|
+
const frames = [];
|
|
7639
|
+
const sections = [];
|
|
7640
|
+
for (const page of canvases) {
|
|
7641
|
+
if (!wanted.has(page.name)) continue;
|
|
7642
|
+
for (const child of page.children ?? []) {
|
|
7643
|
+
if (child.type === "SECTION") sections.push({ id: child.id, name: child.name, page: page.name });
|
|
7644
|
+
else if (SCREEN_TYPES.has(child.type)) frames.push({ id: child.id, name: child.name, page: page.name, ...splitName(child.name) });
|
|
7645
|
+
}
|
|
7646
|
+
}
|
|
7647
|
+
for (const s of await nodes(sections.map((x) => x.id), 1)) {
|
|
7648
|
+
const section2 = sections.find((x) => x.id === s.id);
|
|
7649
|
+
for (const child of s.children ?? []) {
|
|
7650
|
+
if (SCREEN_TYPES.has(child.type)) frames.push({ id: child.id, name: child.name, page: section2.page, section: section2.name, ...splitName(child.name) });
|
|
7651
|
+
}
|
|
7652
|
+
}
|
|
7653
|
+
const hotspots = [];
|
|
7654
|
+
for (const tree of await nodes(frames.filter((f) => f.page !== config.proposalsPage).map((f) => f.id))) {
|
|
7655
|
+
for (const to of destinations(tree)) if (to !== tree.id) hotspots.push({ from: tree.id, to });
|
|
7656
|
+
}
|
|
7657
|
+
return { pages: canvases.map((p) => p.name), frames, hotspots };
|
|
7658
|
+
}
|
|
7659
|
+
function compare(config, routes, targets, figma, dynamicTargets = []) {
|
|
7660
|
+
const platformOf = (page) => config.pages.web === page ? "web" : config.pages.native === page ? "native" : void 0;
|
|
7661
|
+
const inProposal = (f) => /^Proposal\s*·/.test(f.section ?? "");
|
|
7662
|
+
const routeFrames = figma.frames.filter((f) => platformOf(f.page) && !inProposal(f));
|
|
7663
|
+
const framesFor = (r) => routeFrames.filter((f) => platformOf(f.page) === r.platform && (sameScreen(f.route, r.route) || r.route === "index" && f.route === "/"));
|
|
7664
|
+
const byId = new Map(figma.frames.map((f) => [f.id, f]));
|
|
7665
|
+
const framed = new Set(routes.flatMap((r) => framesFor(r).map((f) => f.id)));
|
|
7666
|
+
const covered = routes.filter((r) => framesFor(r).length > 0);
|
|
7667
|
+
const routesWithoutFrame = routes.filter((r) => framesFor(r).length === 0);
|
|
7668
|
+
const framesWithoutRoute = routeFrames.filter((f) => !framed.has(f.id));
|
|
7669
|
+
const proposals = {};
|
|
7670
|
+
for (const f of figma.frames.filter((x) => x.page === config.proposalsPage || platformOf(x.page) && inProposal(x))) (proposals[f.section ?? "(no section)"] ??= []).push(f);
|
|
7671
|
+
const missingHotspots = [];
|
|
7672
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7673
|
+
for (const t of targets) {
|
|
7674
|
+
const source = routes.find((r) => r.file === t.file);
|
|
7675
|
+
if (!source) continue;
|
|
7676
|
+
const from = framesFor(source);
|
|
7677
|
+
if (!from.length) continue;
|
|
7678
|
+
const dest = routes.find((r) => r.platform === source.platform && routeMatches(r.route, t.target));
|
|
7679
|
+
if (!dest || dest === source) continue;
|
|
7680
|
+
const key2 = `${source.route}\u2192${dest.route}`;
|
|
7681
|
+
if (seen.has(key2)) continue;
|
|
7682
|
+
seen.add(key2);
|
|
7683
|
+
const to = new Set(framesFor(dest).map((f) => f.id));
|
|
7684
|
+
const linked = figma.hotspots.some((h) => from.some((f) => f.id === h.from) && to.has(h.to));
|
|
7685
|
+
if (!linked) missingHotspots.push({ ...t, from: source.route, to: dest.route, targetHasFrame: to.size > 0 });
|
|
7686
|
+
}
|
|
7687
|
+
const deadHotspots = [];
|
|
7688
|
+
for (const h of figma.hotspots) {
|
|
7689
|
+
const from = byId.get(h.from);
|
|
7690
|
+
const to = byId.get(h.to);
|
|
7691
|
+
if (from && to && platformOf(to.page) && !inProposal(to) && !framed.has(to.id)) deadHotspots.push({ from, to });
|
|
7692
|
+
}
|
|
7693
|
+
const idMismatches = routes.filter((r) => r.figmaId && !framesFor(r).some((f) => f.id === r.figmaId)).map((r) => ({ ...r, frames: framesFor(r).map((f) => f.id) }));
|
|
7694
|
+
const wantedPages = [...Object.values(config.pages), config.proposalsPage];
|
|
7695
|
+
const missingPages = wantedPages.filter((p) => p !== config.proposalsPage && !figma.pages.includes(p));
|
|
7696
|
+
const uncheckedNavigation = dynamicTargets.filter((t) => routes.some((r) => r.file === t.file));
|
|
7697
|
+
return {
|
|
7698
|
+
file: config.file,
|
|
7699
|
+
summary: {
|
|
7700
|
+
routes: routes.length,
|
|
7701
|
+
frames: routeFrames.length,
|
|
7702
|
+
covered: covered.length,
|
|
7703
|
+
coveredPercent: routes.length ? Math.round(covered.length / routes.length * 100) : 100,
|
|
7704
|
+
hotspots: figma.hotspots.length,
|
|
7705
|
+
missing: missingPages.length + routesWithoutFrame.length + missingHotspots.length + idMismatches.length
|
|
7706
|
+
},
|
|
7707
|
+
missingPages,
|
|
7708
|
+
routesWithoutFrame,
|
|
7709
|
+
framesWithoutRoute,
|
|
7710
|
+
proposals,
|
|
7711
|
+
missingHotspots,
|
|
7712
|
+
deadHotspots,
|
|
7713
|
+
idMismatches,
|
|
7714
|
+
uncheckedNavigation
|
|
7715
|
+
};
|
|
7716
|
+
}
|
|
7717
|
+
async function checkFigmaRoutes(options) {
|
|
7718
|
+
const config = options.config ?? readFigmaConfig(options.root);
|
|
7719
|
+
if (!config) throw new FigmaConfigError(`no "figma" block in ${path21.join(options.root, "genesis.config.json")}`);
|
|
7720
|
+
const token = options.token ?? process.env.FIGMA_ACCESS_TOKEN;
|
|
7721
|
+
if (!token) throw new FigmaConfigError("FIGMA_ACCESS_TOKEN isn't set");
|
|
7722
|
+
const figma = await readFigma(config, token, options.fetch);
|
|
7723
|
+
return compare(config, appRoutes(options.root), appNavTargets(options.root), figma, appDynamicNavTargets(options.root));
|
|
7724
|
+
}
|
|
7725
|
+
function formatCoverage(r) {
|
|
7726
|
+
const s = r.summary;
|
|
7727
|
+
const lines = [`Figma route coverage (file ${r.file}): ${s.routes} routes, ${s.frames} frames, ${s.covered} covered (${s.coveredPercent}%), ${s.hotspots} hotspots, ${s.missing} missing`];
|
|
7728
|
+
const table = (title, head, rows) => {
|
|
7729
|
+
if (!rows.length) return;
|
|
7730
|
+
const widths = head.map((h, i) => Math.max(h.length, ...rows.map((row) => row[i].length)));
|
|
7731
|
+
const fmt = (row) => ` ${row.map((c, i) => c.padEnd(widths[i])).join(" ")}`.trimEnd();
|
|
7732
|
+
lines.push("", `${title} (${rows.length})`, fmt(head), fmt(widths.map((w) => "-".repeat(w))), ...rows.map(fmt));
|
|
7733
|
+
};
|
|
7734
|
+
if (r.missingPages.length) lines.push("", `Pages not in the file: ${r.missingPages.join(", ")}`);
|
|
7735
|
+
table("Routes with no frame", ["platform", "route", "file"], r.routesWithoutFrame.map((x) => [x.platform, x.route, x.file]));
|
|
7736
|
+
table("Frames with no route (put them in a Proposal section, or add the route)", ["page", "frame", "id"], r.framesWithoutRoute.map((f) => [f.page, f.name, f.id]));
|
|
7737
|
+
table("Navigation with no hotspot", ["from", "to", "at"], r.missingHotspots.map((m) => [m.from, `${m.to}${m.targetHasFrame ? "" : " (no frame)"}`, `${m.file}:${m.line}`]));
|
|
7738
|
+
table("Hotspots to a frame with no route", ["from", "to"], r.deadHotspots.map((d) => [d.from.name, d.to.name]));
|
|
7739
|
+
table("figma: ids that don't match the route's frame", ["route", "comment", "frames"], r.idMismatches.map((m) => [m.route, m.figmaId, m.frames.join(", ") || "none"]));
|
|
7740
|
+
table("Navigation not checked (not a string literal)", ["at", "target"], r.uncheckedNavigation.map((t) => [`${t.file}:${t.line}`, t.target]));
|
|
7741
|
+
table("Proposals", ["section", "frame", "id"], Object.entries(r.proposals).flatMap(([sec, fs]) => fs.map((f) => [sec, f.name, f.id])));
|
|
7742
|
+
return lines.join("\n");
|
|
7743
|
+
}
|
|
7744
|
+
function coverageFindings(r, strict) {
|
|
7745
|
+
const gap = strict ? "warn" : "info";
|
|
7746
|
+
return [
|
|
7747
|
+
...r.missingPages.map((p) => ({ level: gap, file: `figma:${p}`, message: `the Figma file has no page "${p}" (named in genesis.config.json figma)`, subject: p })),
|
|
7748
|
+
...r.routesWithoutFrame.map((x) => ({ level: gap, file: x.file, message: `route ${x.route} has no ${x.platform} frame in the Figma file`, subject: x.route })),
|
|
7749
|
+
...r.missingHotspots.map((m) => ({ level: gap, file: m.file, line: m.line, message: `navigates to ${m.to}, but the ${m.from} frame has no hotspot to it${m.targetHasFrame ? "" : " (and it has no frame)"}`, subject: m.to })),
|
|
7750
|
+
...r.idMismatches.map((m) => ({ level: gap, file: m.file, line: 1, message: `// figma: ${m.figmaId} isn't the frame named ${m.route} (${m.frames.join(", ") || "none"})`, subject: m.route })),
|
|
7751
|
+
...r.framesWithoutRoute.map((f) => ({ level: "info", file: `figma:${f.page}`, message: `frame "${f.name}" (${f.id}) has no route: move it to Proposals, or add the route`, subject: f.route })),
|
|
7752
|
+
...r.deadHotspots.map((d) => ({ level: "info", file: `figma:${d.from.page}`, message: `"${d.from.name}" links to "${d.to.name}", which has no route`, subject: d.to.route })),
|
|
7753
|
+
...r.uncheckedNavigation.map((t) => ({ level: "info", file: t.file, line: t.line, message: `navigation to ${t.target} isn't a string literal, so it isn't checked against the Figma file`, subject: t.target }))
|
|
7754
|
+
];
|
|
7755
|
+
}
|
|
7756
|
+
|
|
7757
|
+
// src/doctor/figma-routes.ts
|
|
7758
|
+
async function checkFigmaRoutesRule(ctx) {
|
|
7759
|
+
let config;
|
|
7760
|
+
try {
|
|
7761
|
+
config = readFigmaConfig(ctx.root);
|
|
7762
|
+
} catch (err) {
|
|
7763
|
+
if (!(err instanceof FigmaConfigError)) throw err;
|
|
7764
|
+
ctx.report({ rule: "figma-routes", level: "warn", file: "genesis.config.json", message: err.message });
|
|
7765
|
+
return;
|
|
7766
|
+
}
|
|
7767
|
+
if (!config) return;
|
|
7768
|
+
if (!process.env.FIGMA_ACCESS_TOKEN) {
|
|
7769
|
+
ctx.report({ rule: "figma-routes", level: "info", file: "genesis.config.json", message: "skipped: FIGMA_ACCESS_TOKEN isn't set (CI sets it from a secret)" });
|
|
7770
|
+
return;
|
|
7771
|
+
}
|
|
7772
|
+
try {
|
|
7773
|
+
const report = await checkFigmaRoutes({ root: ctx.root, config });
|
|
7774
|
+
for (const f of coverageFindings(report, ctx.strict ?? false)) ctx.report({ rule: "figma-routes", ...f });
|
|
7775
|
+
} catch (err) {
|
|
7776
|
+
ctx.report({ rule: "figma-routes", level: "info", file: "genesis.config.json", message: `skipped: ${err.message}` });
|
|
7372
7777
|
}
|
|
7373
7778
|
}
|
|
7374
7779
|
var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
|
|
7375
7780
|
async function runDoctor(options = {}) {
|
|
7376
|
-
const root =
|
|
7781
|
+
const root = path21.resolve(options.root ?? process.cwd());
|
|
7377
7782
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
7378
7783
|
const config = loaded.config;
|
|
7379
7784
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -7388,7 +7793,7 @@ async function runDoctor(options = {}) {
|
|
|
7388
7793
|
}
|
|
7389
7794
|
const raw = [];
|
|
7390
7795
|
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
7391
|
-
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
7796
|
+
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true, figma: options.figma ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
7392
7797
|
try {
|
|
7393
7798
|
await plugin.check(ctx);
|
|
7394
7799
|
} catch (err) {
|
|
@@ -7427,7 +7832,7 @@ async function runDoctor(options = {}) {
|
|
|
7427
7832
|
}
|
|
7428
7833
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
7429
7834
|
if (options.base && changed) {
|
|
7430
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
7835
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path21.join(root, f)) });
|
|
7431
7836
|
}
|
|
7432
7837
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
7433
7838
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -7476,6 +7881,7 @@ function builtinChecks(config, options = {}) {
|
|
|
7476
7881
|
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
7477
7882
|
{ name: "eslint-config", check: checkEslintConfig },
|
|
7478
7883
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
7884
|
+
...options.figma !== false ? [{ name: "figma-routes", check: checkFigmaRoutesRule }] : [],
|
|
7479
7885
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
7480
7886
|
];
|
|
7481
7887
|
}
|
|
@@ -7528,7 +7934,7 @@ function applyConfig(raw, config, packageIds) {
|
|
|
7528
7934
|
}
|
|
7529
7935
|
return out.sort((x, y) => x.file.localeCompare(y.file) || x.line - y.line || x.rule.localeCompare(y.rule));
|
|
7530
7936
|
}
|
|
7531
|
-
function formatReport(result) {
|
|
7937
|
+
function formatReport(result, options = {}) {
|
|
7532
7938
|
const g = result.genesis;
|
|
7533
7939
|
const lines = [
|
|
7534
7940
|
`Genesis doctor: ${g.uiPackage}@${g.uiVersion}, ${g.components.length} components, ${g.tokens.size} tokens, ${result.ruleCount} app rules; raw tags checked: ${[...g.rawTags.keys()].join(", ") || "none"}`
|
|
@@ -7536,13 +7942,13 @@ function formatReport(result) {
|
|
|
7536
7942
|
for (const f of result.findings) {
|
|
7537
7943
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
7538
7944
|
}
|
|
7539
|
-
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
7945
|
+
lines.push(options.verbose ? `Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}` : `Available but unused: ${result.unused.length} (genesis doctor --verbose lists them)`);
|
|
7540
7946
|
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
7541
7947
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
7542
7948
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
7543
7949
|
return lines.join("\n");
|
|
7544
7950
|
}
|
|
7545
7951
|
|
|
7546
|
-
export { CommentSettingsError, DoctorConfigError, EmitError, GenesisConfigError, defineDoctorPlugin, detectHost, emitContracts, formatReport, introspectOpenApi, introspectPostgres, parseColumnComment, parseTableComment, planScaffold, planStudioInit, readGenesisConfig, runDoctor, runScaffold, validateConsumerName, validateLinks };
|
|
7952
|
+
export { CommentSettingsError, DoctorConfigError, EmitError, FigmaConfigError, GenesisConfigError, appNavTargets, appRoutes, checkFigmaRoutes, compare as compareFigmaRoutes, defineDoctorPlugin, detectHost, emitContracts, formatCoverage, formatReport, introspectOpenApi, introspectPostgres, parseColumnComment, parseTableComment, planScaffold, planStudioInit, readFigma, readFigmaConfig, readGenesisConfig, runDoctor, runScaffold, validateConsumerName, validateFigmaConfig, validateLinks };
|
|
7547
7953
|
//# sourceMappingURL=index.js.map
|
|
7548
7954
|
//# sourceMappingURL=index.js.map
|