@marktiderman/genesis-cli 1.20.0 → 1.22.0
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 +168 -9
- package/dist/cli.js +1114 -103
- 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 +1515 -1095
- 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 +140 -20
- package/dist/index.d.ts +114 -2
- package/dist/index.js +1538 -1099
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +8 -5
- package/dist/starter/__tests__/components/setup.ts +11 -0
- package/dist/starter/__tests__/starter.test.ts +28 -0
- package/dist/starter/package.json +4 -3
- package/dist/starter/pnpm-workspace.yaml +22 -0
- package/dist/starter/src/lib/app.ts +13 -5
- package/dist/starter/src/lib/check-in.ts +5 -3
- package/dist/starter/src/lib/define-starter.ts +1 -1
- package/dist/starter/src/lib/devtools-overlay.ts +3 -4
- package/dist/starter/src/lib/native-modules.ts +9 -2
- package/dist/starter/src/lib/offline.ts +14 -0
- package/dist/starter/supabase/migrations/20261024000750_support_default_tenant.sql +18 -0
- package/dist/starter/supabase/migrations/20261024000800_genesis_support_tickets.sql +800 -0
- package/dist/starter/supabase/migrations/20261025000070_starter_tenancy.sql +26 -0
- package/dist/starter/supabase/migrations/20261025000080_genesis_chat_tenants.sql +716 -0
- package/dist/starter/supabase/migrations/20261025000090_genesis_chat_attachment_paths.sql +80 -0
- package/dist/starter/supabase/tests/database/chat_people.test.sql +1 -1
- package/dist/starter/supabase/tests/database/genesis_chat.test.sql +10 -2
- package/dist/starter/supabase/tests/database/genesis_chat_attachment_paths.test.sql +111 -0
- package/dist/starter/supabase/tests/database/genesis_chat_coaching.test.sql +8 -0
- package/dist/starter/supabase/tests/database/genesis_chat_search_threads.test.sql +8 -0
- package/dist/starter/supabase/tests/database/genesis_chat_tenants.test.sql +259 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +15 -3
- package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +10 -0
- package/dist/starter/supabase/tests/database/genesis_support_tickets.test.sql +327 -0
- package/dist/starter/supabase/tests/database/starter_tenancy.test.sql +19 -0
- package/dist/vite.js +1514 -1094
- 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,409 +1846,140 @@ 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);
|
|
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
|
+
}
|
|
1991
1969
|
}
|
|
1992
|
-
|
|
1993
|
-
|
|
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 ManifestError = class extends Error {
|
|
2147
|
-
constructor(problems) {
|
|
2148
|
-
super(`Invalid block manifest:
|
|
2149
|
-
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
2150
|
-
this.problems = problems;
|
|
2151
|
-
this.name = "ManifestError";
|
|
2152
|
-
}
|
|
2153
|
-
problems;
|
|
2154
|
-
};
|
|
2155
|
-
function safeRelative(value) {
|
|
2156
|
-
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
2157
|
-
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
2158
|
-
const segments = value.split("/");
|
|
2159
|
-
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
2160
|
-
return value;
|
|
2161
|
-
}
|
|
2162
|
-
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2163
|
-
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
2164
|
-
function parseManifest(home, id, raw, version, options = {}) {
|
|
2165
|
-
const problems = [];
|
|
2166
|
-
const at = `${home} genesis.blocks.${id}`;
|
|
2167
|
-
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
2168
|
-
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
2169
|
-
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
2170
|
-
const pkgOf = (value, where2) => {
|
|
2171
|
-
if (value === void 0) return home;
|
|
2172
|
-
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
2173
|
-
problems.push(`${where2}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
2174
|
-
return home;
|
|
2175
|
-
}
|
|
2176
|
-
return value;
|
|
2177
|
-
};
|
|
2178
|
-
const pathOf = (value, where2) => {
|
|
2179
|
-
const safe = safeRelative(value);
|
|
2180
|
-
if (!safe) problems.push(`${where2}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
2181
|
-
return safe ?? "";
|
|
2182
|
-
};
|
|
2183
|
-
const list = (key2) => {
|
|
2184
|
-
const v = raw[key2];
|
|
2185
|
-
if (v === void 0) return [];
|
|
2186
|
-
if (!Array.isArray(v)) {
|
|
2187
|
-
problems.push(`${at}.${key2}: must be a list`);
|
|
2188
|
-
return [];
|
|
2189
|
-
}
|
|
2190
|
-
return v;
|
|
2191
|
-
};
|
|
2192
|
-
const requires = list("requires").filter((r) => {
|
|
2193
|
-
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
2194
|
-
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
2195
|
-
return ok;
|
|
2196
|
-
});
|
|
2197
|
-
let platforms;
|
|
2198
|
-
if (raw["platforms"] !== void 0) {
|
|
2199
|
-
platforms = list("platforms").filter((p) => {
|
|
2200
|
-
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
2201
|
-
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
2202
|
-
return ok;
|
|
2203
|
-
});
|
|
2204
|
-
}
|
|
2205
|
-
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
2206
|
-
const install = list("install").filter((s) => {
|
|
2207
|
-
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
2208
|
-
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
2209
|
-
return ok;
|
|
2210
|
-
});
|
|
2211
|
-
const migrations = list("migrations").map((m, i) => {
|
|
2212
|
-
const where2 = `${at}.migrations[${i}]`;
|
|
2213
|
-
if (!isObject2(m)) {
|
|
2214
|
-
problems.push(`${where2}: must be an object`);
|
|
2215
|
-
return { package: home, file: "" };
|
|
2216
|
-
}
|
|
2217
|
-
const file = pathOf(m["file"], `${where2}.file`);
|
|
2218
|
-
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
2219
|
-
const out = { package: pkgOf(m["package"], where2), file };
|
|
2220
|
-
if (m["provides"] !== void 0) {
|
|
2221
|
-
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
1970
|
+
if (m["runsBefore"] !== void 0) {
|
|
1971
|
+
if (!Array.isArray(m["runsBefore"])) problems.push(`${where2}.runsBefore: must be a list of { package, file }`);
|
|
2222
1972
|
else {
|
|
2223
|
-
out.
|
|
2224
|
-
const at2 = `${where2}.
|
|
2225
|
-
if (!isObject2(
|
|
1973
|
+
out.runsBefore = m["runsBefore"].map((r, j) => {
|
|
1974
|
+
const at2 = `${where2}.runsBefore[${j}]`;
|
|
1975
|
+
if (!isObject2(r)) {
|
|
2226
1976
|
problems.push(`${at2}: must be an object`);
|
|
2227
1977
|
return { package: home, file: "" };
|
|
2228
1978
|
}
|
|
2229
|
-
const
|
|
2230
|
-
if (
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
}
|
|
2234
|
-
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
2235
|
-
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
2236
|
-
return provided;
|
|
1979
|
+
const before = { package: pkgOf(r["package"], at2), file: pathOf(r["file"], `${at2}.file`) };
|
|
1980
|
+
if (before.file && !MIGRATION_FILE.test(before.file.split("/").pop())) problems.push(`${at2}.file: "${before.file}" must be named NNNN_name.sql`);
|
|
1981
|
+
if (before.package === out.package && before.file === file) problems.push(`${at2}: a migration can't run before itself`);
|
|
1982
|
+
return before;
|
|
2237
1983
|
});
|
|
2238
1984
|
}
|
|
2239
1985
|
}
|
|
@@ -2351,15 +2097,15 @@ function isBlockDef(value) {
|
|
|
2351
2097
|
// src/blocks/files.ts
|
|
2352
2098
|
var sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
2353
2099
|
function inside(parent, child) {
|
|
2354
|
-
const rel =
|
|
2355
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
2100
|
+
const rel = path21.relative(parent, child);
|
|
2101
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
2356
2102
|
}
|
|
2357
2103
|
function appPath2(root, rel) {
|
|
2358
2104
|
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
2359
2105
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
2360
2106
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
2361
2107
|
const realRoot = realpathSync(root);
|
|
2362
|
-
const target =
|
|
2108
|
+
const target = path21.join(realRoot, ...safe.split("/"));
|
|
2363
2109
|
const there = (p) => {
|
|
2364
2110
|
try {
|
|
2365
2111
|
lstatSync(p);
|
|
@@ -2368,20 +2114,18 @@ function appPath2(root, rel) {
|
|
|
2368
2114
|
return false;
|
|
2369
2115
|
}
|
|
2370
2116
|
};
|
|
2371
|
-
let probe =
|
|
2372
|
-
while (!there(probe)) probe =
|
|
2117
|
+
let probe = path21.dirname(target);
|
|
2118
|
+
while (!there(probe)) probe = path21.dirname(probe);
|
|
2373
2119
|
let real2;
|
|
2374
2120
|
try {
|
|
2375
2121
|
real2 = realpathSync(probe);
|
|
2376
2122
|
} catch {
|
|
2377
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
2123
|
+
throw new Error(`${rel} goes through a broken symlink (${path21.relative(realRoot, probe)}); refused`);
|
|
2378
2124
|
}
|
|
2379
2125
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
2380
2126
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
2381
2127
|
return target;
|
|
2382
2128
|
}
|
|
2383
|
-
|
|
2384
|
-
// src/blocks/local.ts
|
|
2385
2129
|
var LOCAL_PACKAGES_KEY = "localPackages";
|
|
2386
2130
|
var LocalPackagesError = class extends Error {
|
|
2387
2131
|
name = "LocalPackagesError";
|
|
@@ -2391,8 +2135,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
2391
2135
|
return raw.map((entry, i) => {
|
|
2392
2136
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
2393
2137
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
2394
|
-
if (
|
|
2395
|
-
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(/\/+$/, "");
|
|
2396
2140
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
2397
2141
|
const parts = norm.split("/");
|
|
2398
2142
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -2403,7 +2147,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
2403
2147
|
});
|
|
2404
2148
|
}
|
|
2405
2149
|
function localPackageGlobs(root) {
|
|
2406
|
-
const file =
|
|
2150
|
+
const file = path21.join(root, "genesis.config.json");
|
|
2407
2151
|
if (!existsSync(file)) return [];
|
|
2408
2152
|
let raw;
|
|
2409
2153
|
try {
|
|
@@ -2417,14 +2161,14 @@ function localPackageGlobs(root) {
|
|
|
2417
2161
|
var cache = /* @__PURE__ */ new Map();
|
|
2418
2162
|
function repositoryRoot(appRoot) {
|
|
2419
2163
|
for (let dir = appRoot; ; ) {
|
|
2420
|
-
if (existsSync(
|
|
2421
|
-
const parent =
|
|
2164
|
+
if (existsSync(path21.join(dir, ".git"))) return dir;
|
|
2165
|
+
const parent = path21.dirname(dir);
|
|
2422
2166
|
if (parent === dir) return appRoot;
|
|
2423
2167
|
dir = parent;
|
|
2424
2168
|
}
|
|
2425
2169
|
}
|
|
2426
2170
|
function localPackages(root) {
|
|
2427
|
-
const appRoot =
|
|
2171
|
+
const appRoot = path21.resolve(root);
|
|
2428
2172
|
const globs = localPackageGlobs(appRoot);
|
|
2429
2173
|
const key2 = `${appRoot}
|
|
2430
2174
|
${globs.join("\n")}`;
|
|
@@ -2433,24 +2177,24 @@ ${globs.join("\n")}`;
|
|
|
2433
2177
|
const dirs = /* @__PURE__ */ new Set();
|
|
2434
2178
|
for (const glob of globs) {
|
|
2435
2179
|
if (glob.endsWith("/*") || glob === "*") {
|
|
2436
|
-
const parent =
|
|
2180
|
+
const parent = path21.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
2437
2181
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
2438
2182
|
for (const entry of readdirSync(parent).sort()) {
|
|
2439
2183
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
2440
|
-
dirs.add(
|
|
2184
|
+
dirs.add(path21.join(parent, entry));
|
|
2441
2185
|
}
|
|
2442
2186
|
} else {
|
|
2443
|
-
dirs.add(
|
|
2187
|
+
dirs.add(path21.join(appRoot, glob));
|
|
2444
2188
|
}
|
|
2445
2189
|
}
|
|
2446
2190
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
2447
2191
|
const out = [];
|
|
2448
2192
|
const byName = /* @__PURE__ */ new Map();
|
|
2449
2193
|
for (const dir of [...dirs].sort()) {
|
|
2450
|
-
const manifest =
|
|
2194
|
+
const manifest = path21.join(dir, "package.json");
|
|
2451
2195
|
if (!existsSync(manifest)) continue;
|
|
2452
2196
|
if (!inside(real2, realpathSync(dir))) {
|
|
2453
|
-
throw new LocalPackagesError(`${
|
|
2197
|
+
throw new LocalPackagesError(`${path21.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
2454
2198
|
}
|
|
2455
2199
|
let pkg;
|
|
2456
2200
|
try {
|
|
@@ -2459,7 +2203,7 @@ ${globs.join("\n")}`;
|
|
|
2459
2203
|
continue;
|
|
2460
2204
|
}
|
|
2461
2205
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
2462
|
-
const rel =
|
|
2206
|
+
const rel = path21.relative(appRoot, dir).split(path21.sep).join("/");
|
|
2463
2207
|
const other = byName.get(pkg.name);
|
|
2464
2208
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
2465
2209
|
byName.set(pkg.name, rel);
|
|
@@ -2647,35 +2391,35 @@ var DEFAULT_IGNORE = [
|
|
|
2647
2391
|
];
|
|
2648
2392
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2649
2393
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2650
|
-
var toPosix = (p) => p.split(
|
|
2394
|
+
var toPosix = (p) => p.split(path21.sep).join("/");
|
|
2651
2395
|
function scanFiles(root, config) {
|
|
2652
2396
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
2653
2397
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
2654
2398
|
const files = [];
|
|
2655
2399
|
const seen = /* @__PURE__ */ new Set();
|
|
2656
2400
|
const visit = (abs) => {
|
|
2657
|
-
const rel = toPosix(
|
|
2401
|
+
const rel = toPosix(path21.relative(root, abs));
|
|
2658
2402
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2659
|
-
const ext =
|
|
2403
|
+
const ext = path21.extname(abs);
|
|
2660
2404
|
if (!extensions.has(ext)) return;
|
|
2661
2405
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2662
2406
|
seen.add(rel);
|
|
2663
2407
|
const text = readFileSync(abs, "utf8");
|
|
2664
2408
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
2665
2409
|
};
|
|
2666
|
-
const
|
|
2410
|
+
const walk3 = (dir) => {
|
|
2667
2411
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2668
2412
|
if (entry.isDirectory()) {
|
|
2669
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
2413
|
+
if (!SKIP_DIRS.has(entry.name)) walk3(path21.join(dir, entry.name));
|
|
2670
2414
|
} else if (entry.isFile()) {
|
|
2671
|
-
visit(
|
|
2415
|
+
visit(path21.join(dir, entry.name));
|
|
2672
2416
|
}
|
|
2673
2417
|
}
|
|
2674
2418
|
};
|
|
2675
2419
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2676
|
-
const abs =
|
|
2420
|
+
const abs = path21.resolve(root, src);
|
|
2677
2421
|
if (!existsSync(abs)) continue;
|
|
2678
|
-
if (statSync(abs).isDirectory())
|
|
2422
|
+
if (statSync(abs).isDirectory()) walk3(abs);
|
|
2679
2423
|
else visit(abs);
|
|
2680
2424
|
}
|
|
2681
2425
|
let local = [];
|
|
@@ -2684,7 +2428,7 @@ function scanFiles(root, config) {
|
|
|
2684
2428
|
} catch {
|
|
2685
2429
|
local = [];
|
|
2686
2430
|
}
|
|
2687
|
-
for (const pkg of local)
|
|
2431
|
+
for (const pkg of local) walk3(pkg.dir);
|
|
2688
2432
|
return files;
|
|
2689
2433
|
}
|
|
2690
2434
|
function lineAt(text, index) {
|
|
@@ -2693,150 +2437,11 @@ function lineAt(text, index) {
|
|
|
2693
2437
|
return line;
|
|
2694
2438
|
}
|
|
2695
2439
|
|
|
2696
|
-
// src/doctor/
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
const heading = line.match(/^###\s+([A-Za-z0-9_-]+)\s*$/);
|
|
2702
|
-
if (heading) {
|
|
2703
|
-
current = { id: heading[1] };
|
|
2704
|
-
rules.push(current);
|
|
2705
|
-
continue;
|
|
2706
|
-
}
|
|
2707
|
-
if (/^#{1,2}\s/.test(line)) {
|
|
2708
|
-
current = null;
|
|
2709
|
-
continue;
|
|
2710
|
-
}
|
|
2711
|
-
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message|newOnly):\s*(.*)$/);
|
|
2712
|
-
if (!current || !kv) continue;
|
|
2713
|
-
const [, key2, raw] = kv;
|
|
2714
|
-
const value = raw.trim();
|
|
2715
|
-
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2716
|
-
else if (key2 === "level") current.level = value;
|
|
2717
|
-
else if (key2 === "newOnly") current.newOnly = value === "true" ? true : value === "false" ? false : value;
|
|
2718
|
-
else current[key2] = value;
|
|
2719
|
-
}
|
|
2720
|
-
return rules;
|
|
2721
|
-
}
|
|
2722
|
-
function toRegExp(source, flags = "") {
|
|
2723
|
-
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
2724
|
-
return new RegExp(source, flags);
|
|
2725
|
-
}
|
|
2726
|
-
function compilePatternRules(rules, source) {
|
|
2727
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2728
|
-
const out = [];
|
|
2729
|
-
for (const rule of rules) {
|
|
2730
|
-
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
2731
|
-
ids.add(rule.id);
|
|
2732
|
-
const level = rule.level ?? "error";
|
|
2733
|
-
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
2734
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
2735
|
-
}
|
|
2736
|
-
if (rule.newOnly !== void 0 && typeof rule.newOnly !== "boolean") {
|
|
2737
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has newOnly "${String(rule.newOnly)}" (use true or false)`);
|
|
2738
|
-
}
|
|
2739
|
-
if (level === "guide") continue;
|
|
2740
|
-
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
2741
|
-
if (!rule.forbid && !rule.require && !rule.path) {
|
|
2742
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" needs forbid, require or path (or level: guide)`);
|
|
2743
|
-
}
|
|
2744
|
-
try {
|
|
2745
|
-
out.push({
|
|
2746
|
-
rule,
|
|
2747
|
-
level,
|
|
2748
|
-
includes: globMatcher(rule.files),
|
|
2749
|
-
excludes: globMatcher(rule.exclude),
|
|
2750
|
-
forbid: rule.forbid ? toRegExp(rule.forbid, "m") : void 0,
|
|
2751
|
-
require: rule.require ? toRegExp(rule.require, "m") : void 0,
|
|
2752
|
-
path: rule.path ? toRegExp(rule.path) : void 0
|
|
2753
|
-
});
|
|
2754
|
-
} catch (err) {
|
|
2755
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has an invalid pattern: ${err.message}`);
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
return out;
|
|
2759
|
-
}
|
|
2760
|
-
function loadPatternRules(root, patterns, rulesDoc) {
|
|
2761
|
-
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2762
|
-
let all = compiled;
|
|
2763
|
-
if (rulesDoc) {
|
|
2764
|
-
const file = path20.resolve(root, rulesDoc);
|
|
2765
|
-
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2766
|
-
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2767
|
-
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
2768
|
-
if (clash) throw new DoctorConfigError(`rule "${clash.rule.id}" is defined in both doctor.patterns and ${rulesDoc}`);
|
|
2769
|
-
all = [...compiled, ...fromDoc];
|
|
2770
|
-
}
|
|
2771
|
-
if (all.length === 0) return null;
|
|
2772
|
-
return {
|
|
2773
|
-
count: all.length,
|
|
2774
|
-
ids: all.map((r) => r.rule.id),
|
|
2775
|
-
newOnly: all.filter((r) => r.rule.newOnly).map((r) => r.rule.id),
|
|
2776
|
-
plugin: {
|
|
2777
|
-
name: "patterns",
|
|
2778
|
-
check(ctx) {
|
|
2779
|
-
for (const r of all) {
|
|
2780
|
-
const message = r.rule.message ?? "breaks a design rule";
|
|
2781
|
-
for (const file of ctx.files) {
|
|
2782
|
-
if (!r.includes(file.path) || r.excludes(file.path)) continue;
|
|
2783
|
-
const report = (line) => ctx.report({ rule: r.rule.id, level: r.level, file: file.path, line, message });
|
|
2784
|
-
if (r.path && !r.path.test(file.path)) report(0);
|
|
2785
|
-
if (r.require && !r.require.test(file.code)) report(0);
|
|
2786
|
-
if (r.forbid) {
|
|
2787
|
-
const m = r.forbid.exec(file.code);
|
|
2788
|
-
if (m) report(lineAt(file.code, m.index));
|
|
2789
|
-
}
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
}
|
|
2794
|
-
};
|
|
2795
|
-
}
|
|
2796
|
-
function defineDoctorPlugin(plugin) {
|
|
2797
|
-
return plugin;
|
|
2798
|
-
}
|
|
2799
|
-
async function loadPlugins(specs, configDir) {
|
|
2800
|
-
const plugins = [];
|
|
2801
|
-
for (const spec of specs ?? []) {
|
|
2802
|
-
const [id, options] = typeof spec === "string" ? [spec, void 0] : spec;
|
|
2803
|
-
const file = resolvePlugin(id, configDir);
|
|
2804
|
-
const url = `${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`;
|
|
2805
|
-
let mod;
|
|
2806
|
-
try {
|
|
2807
|
-
mod = await import(url);
|
|
2808
|
-
} catch (err) {
|
|
2809
|
-
throw new DoctorConfigError(`doctor.plugins: could not load ${id}: ${err.message}`);
|
|
2810
|
-
}
|
|
2811
|
-
let value = mod.default;
|
|
2812
|
-
if (typeof value === "function") value = await value(options);
|
|
2813
|
-
const list = Array.isArray(value) ? value : [value];
|
|
2814
|
-
for (const p of list) {
|
|
2815
|
-
if (!p || typeof p !== "object" || typeof p.check !== "function" || typeof p.name !== "string") {
|
|
2816
|
-
throw new DoctorConfigError(`doctor.plugins: ${id} must default-export { name, check(context) } (or an array, or a factory returning one)`);
|
|
2817
|
-
}
|
|
2818
|
-
plugins.push(p);
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
|
-
return plugins;
|
|
2822
|
-
}
|
|
2823
|
-
function resolvePlugin(id, configDir) {
|
|
2824
|
-
try {
|
|
2825
|
-
if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
|
|
2826
|
-
return resolveFrom(id, configDir);
|
|
2827
|
-
} catch {
|
|
2828
|
-
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
|
-
function resolveFrom(id, from) {
|
|
2832
|
-
return createRequire(path20.join(from, "noop.js")).resolve(id);
|
|
2833
|
-
}
|
|
2834
|
-
|
|
2835
|
-
// src/doctor/semver.ts
|
|
2836
|
-
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2837
|
-
function parseVersion(v) {
|
|
2838
|
-
const m = VERSION.exec(v.trim());
|
|
2839
|
-
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2440
|
+
// src/doctor/semver.ts
|
|
2441
|
+
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2442
|
+
function parseVersion(v) {
|
|
2443
|
+
const m = VERSION.exec(v.trim());
|
|
2444
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2840
2445
|
}
|
|
2841
2446
|
function compareVersions(a, b) {
|
|
2842
2447
|
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
@@ -2951,46 +2556,6 @@ function satisfies(version, range) {
|
|
|
2951
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))
|
|
2952
2557
|
);
|
|
2953
2558
|
}
|
|
2954
|
-
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2955
|
-
function readReleaseManifest(root) {
|
|
2956
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2957
|
-
const file = dir && path20.join(dir, "dist", "versions.json");
|
|
2958
|
-
if (!file || !existsSync(file)) return null;
|
|
2959
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
2960
|
-
}
|
|
2961
|
-
function checkVersionSkew(ctx) {
|
|
2962
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
2963
|
-
if (!manifest) return;
|
|
2964
|
-
const overlays = markedOverlays(ctx);
|
|
2965
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2966
|
-
const overlay = overlays.get(name);
|
|
2967
|
-
if (overlay) {
|
|
2968
|
-
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
2969
|
-
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
2970
|
-
if (from !== want && !behind) {
|
|
2971
|
-
ctx.report({
|
|
2972
|
-
rule: "version-skew",
|
|
2973
|
-
level: "warn",
|
|
2974
|
-
file: "package.json",
|
|
2975
|
-
subject: name,
|
|
2976
|
-
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).`
|
|
2977
|
-
});
|
|
2978
|
-
}
|
|
2979
|
-
continue;
|
|
2980
|
-
}
|
|
2981
|
-
const dir = findPackageDir(ctx.root, name);
|
|
2982
|
-
if (!dir) continue;
|
|
2983
|
-
const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
|
|
2984
|
-
if (have === want) continue;
|
|
2985
|
-
ctx.report({
|
|
2986
|
-
rule: "version-skew",
|
|
2987
|
-
level: "warn",
|
|
2988
|
-
file: "package.json",
|
|
2989
|
-
subject: name,
|
|
2990
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2991
|
-
});
|
|
2992
|
-
}
|
|
2993
|
-
}
|
|
2994
2559
|
|
|
2995
2560
|
// src/doctor/overlays.ts
|
|
2996
2561
|
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
@@ -3006,7 +2571,7 @@ function overlayState(name, json) {
|
|
|
3006
2571
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
3007
2572
|
const problems = [];
|
|
3008
2573
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
3009
|
-
const rel =
|
|
2574
|
+
const rel = path21.relative(path21.resolve(root), path21.resolve(dir)).split(path21.sep).join("/");
|
|
3010
2575
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
3011
2576
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
3012
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})`);
|
|
@@ -3043,92 +2608,760 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
3043
2608
|
for (const file of manifests) {
|
|
3044
2609
|
let json;
|
|
3045
2610
|
try {
|
|
3046
|
-
json = JSON.parse(readFileSync(
|
|
3047
|
-
} catch {
|
|
3048
|
-
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}`);
|
|
3049
3337
|
}
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
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);
|
|
3055
3346
|
}
|
|
3056
3347
|
}
|
|
3057
|
-
return
|
|
3348
|
+
return plugins;
|
|
3058
3349
|
}
|
|
3059
|
-
function
|
|
3060
|
-
let packages;
|
|
3350
|
+
function resolvePlugin(id, configDir) {
|
|
3061
3351
|
try {
|
|
3062
|
-
|
|
3352
|
+
if (id.startsWith(".") || path21.isAbsolute(id)) return resolveFrom(path21.resolve(configDir, id), configDir);
|
|
3353
|
+
return resolveFrom(id, configDir);
|
|
3063
3354
|
} catch {
|
|
3064
|
-
|
|
3065
|
-
}
|
|
3066
|
-
for (const pkg of packages) {
|
|
3067
|
-
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
3068
|
-
const file = `${pkg.rel}/package.json`;
|
|
3069
|
-
let json;
|
|
3070
|
-
try {
|
|
3071
|
-
json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
3072
|
-
} catch {
|
|
3073
|
-
continue;
|
|
3074
|
-
}
|
|
3075
|
-
const state = overlayState(pkg.name, json);
|
|
3076
|
-
if (state.kind === "none") {
|
|
3077
|
-
ctx.report({
|
|
3078
|
-
rule: "overlay-unmarked",
|
|
3079
|
-
file,
|
|
3080
|
-
subject: pkg.name,
|
|
3081
|
-
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`
|
|
3082
|
-
});
|
|
3083
|
-
continue;
|
|
3084
|
-
}
|
|
3085
|
-
if (state.kind === "invalid") {
|
|
3086
|
-
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
3087
|
-
continue;
|
|
3088
|
-
}
|
|
3089
|
-
const { marker } = state;
|
|
3090
|
-
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 });
|
|
3091
|
-
const age = overlayAgeDays(marker.since, now);
|
|
3092
|
-
if (age < -1) {
|
|
3093
|
-
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` });
|
|
3094
|
-
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
3095
|
-
ctx.report({
|
|
3096
|
-
rule: "overlay-age",
|
|
3097
|
-
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
3098
|
-
file,
|
|
3099
|
-
subject: pkg.name,
|
|
3100
|
-
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)`
|
|
3101
|
-
});
|
|
3102
|
-
}
|
|
3103
|
-
const upstream = overlayUpstream(marker).version;
|
|
3104
|
-
const version = typeof json.version === "string" ? json.version : "";
|
|
3105
|
-
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
3106
|
-
ctx.report({
|
|
3107
|
-
rule: "overlay-version",
|
|
3108
|
-
level: "warn",
|
|
3109
|
-
file,
|
|
3110
|
-
subject: version || "(none)",
|
|
3111
|
-
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`
|
|
3112
|
-
});
|
|
3113
|
-
}
|
|
3114
|
-
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
3115
|
-
const from = parseVersion(upstream);
|
|
3116
|
-
const to = pinned ? parseVersion(pinned) : null;
|
|
3117
|
-
if (from && to && compareVersions(from, to) < 0) {
|
|
3118
|
-
ctx.report({
|
|
3119
|
-
rule: "overlay-behind",
|
|
3120
|
-
level: "warn",
|
|
3121
|
-
file,
|
|
3122
|
-
subject: pkg.name,
|
|
3123
|
-
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`
|
|
3124
|
-
});
|
|
3125
|
-
}
|
|
3355
|
+
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
3126
3356
|
}
|
|
3127
3357
|
}
|
|
3128
|
-
|
|
3129
|
-
|
|
3358
|
+
function resolveFrom(id, from) {
|
|
3359
|
+
return createRequire(path21.join(from, "noop.js")).resolve(id);
|
|
3360
|
+
}
|
|
3130
3361
|
var BUILTIN_RULES = [
|
|
3131
3362
|
"local-primitives",
|
|
3363
|
+
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
3364
|
+
"figma-routes",
|
|
3132
3365
|
"starter-leftover",
|
|
3133
3366
|
"forbidden-import",
|
|
3134
3367
|
"raw-tag",
|
|
@@ -3221,7 +3454,7 @@ function importSpecifiers(file) {
|
|
|
3221
3454
|
}
|
|
3222
3455
|
function checkProjectLayout(ctx) {
|
|
3223
3456
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
3224
|
-
if (existsSync(
|
|
3457
|
+
if (existsSync(path21.join(ctx.root, dir))) {
|
|
3225
3458
|
ctx.report({
|
|
3226
3459
|
rule: "local-primitives",
|
|
3227
3460
|
file: dir,
|
|
@@ -3231,7 +3464,7 @@ function checkProjectLayout(ctx) {
|
|
|
3231
3464
|
}
|
|
3232
3465
|
}
|
|
3233
3466
|
for (const file of STARTER_LEFTOVERS) {
|
|
3234
|
-
if (existsSync(
|
|
3467
|
+
if (existsSync(path21.join(ctx.root, file))) {
|
|
3235
3468
|
ctx.report({
|
|
3236
3469
|
rule: "starter-leftover",
|
|
3237
3470
|
level: "warn",
|
|
@@ -3321,7 +3554,7 @@ function checkTokens(ctx) {
|
|
|
3321
3554
|
}
|
|
3322
3555
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
3323
3556
|
if (/[*?]/.test(pattern)) continue;
|
|
3324
|
-
const abs =
|
|
3557
|
+
const abs = path21.join(ctx.root, pattern);
|
|
3325
3558
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
3326
3559
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
3327
3560
|
}
|
|
@@ -3345,7 +3578,7 @@ function checkShadowedExports(ctx) {
|
|
|
3345
3578
|
file.code.split("\n").forEach((text, i) => {
|
|
3346
3579
|
for (const m of text.matchAll(re)) {
|
|
3347
3580
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
3348
|
-
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)` });
|
|
3349
3582
|
}
|
|
3350
3583
|
});
|
|
3351
3584
|
}
|
|
@@ -3444,10 +3677,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
|
|
|
3444
3677
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
3445
3678
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
3446
3679
|
function resolveLocal(root, fromFile, spec) {
|
|
3447
|
-
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))];
|
|
3448
3681
|
for (const base of bases) {
|
|
3449
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
3450
|
-
(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)
|
|
3451
3684
|
);
|
|
3452
3685
|
if (hit) return hit;
|
|
3453
3686
|
}
|
|
@@ -3568,13 +3801,13 @@ function checkNativePack(ctx) {
|
|
|
3568
3801
|
}
|
|
3569
3802
|
function checkEasPlaceholders(ctx) {
|
|
3570
3803
|
const files = [];
|
|
3571
|
-
if (existsSync(
|
|
3572
|
-
const workflows =
|
|
3804
|
+
if (existsSync(path21.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
3805
|
+
const workflows = path21.join(ctx.root, ".eas", "workflows");
|
|
3573
3806
|
if (existsSync(workflows)) {
|
|
3574
3807
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
3575
3808
|
}
|
|
3576
3809
|
for (const file of files) {
|
|
3577
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
3810
|
+
for (const hit of findPlaceholders(file, readFileSync(path21.join(ctx.root, file), "utf8"))) {
|
|
3578
3811
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
3579
3812
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
3580
3813
|
ctx.report({
|
|
@@ -3653,7 +3886,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3653
3886
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
3654
3887
|
const code = file.code;
|
|
3655
3888
|
const hidden = HIDES_HEADER.exec(code);
|
|
3656
|
-
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);
|
|
3657
3890
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
3658
3891
|
if (hidden && own) {
|
|
3659
3892
|
reported.add(file.path);
|
|
@@ -3681,7 +3914,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3681
3914
|
}
|
|
3682
3915
|
for (const file of ctx.files) {
|
|
3683
3916
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
3684
|
-
const layout = hidingLayouts.get(
|
|
3917
|
+
const layout = hidingLayouts.get(path21.posix.dirname(file.path));
|
|
3685
3918
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
3686
3919
|
if (!layout || !own) continue;
|
|
3687
3920
|
ctx.report({
|
|
@@ -3703,13 +3936,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
3703
3936
|
}
|
|
3704
3937
|
function routerRoot(ctx) {
|
|
3705
3938
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
3706
|
-
return existsSync(
|
|
3939
|
+
return existsSync(path21.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
3707
3940
|
}
|
|
3708
3941
|
function checkScreenLayouts(ctx, pkg) {
|
|
3709
3942
|
const layouts = nativeLayouts(pkg);
|
|
3710
3943
|
if (layouts.length === 0) return;
|
|
3711
3944
|
const rootDir = routerRoot(ctx);
|
|
3712
|
-
if (!existsSync(
|
|
3945
|
+
if (!existsSync(path21.join(ctx.root, rootDir))) {
|
|
3713
3946
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
3714
3947
|
return;
|
|
3715
3948
|
}
|
|
@@ -3765,7 +3998,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
3765
3998
|
function readExpoConfigs(root) {
|
|
3766
3999
|
const out = [];
|
|
3767
4000
|
for (const name of EXPO_CONFIGS) {
|
|
3768
|
-
const abs =
|
|
4001
|
+
const abs = path21.join(root, name);
|
|
3769
4002
|
if (!existsSync(abs)) continue;
|
|
3770
4003
|
const text = readFileSync(abs, "utf8");
|
|
3771
4004
|
let json = null;
|
|
@@ -3799,13 +4032,13 @@ function pluginOptions(json, module) {
|
|
|
3799
4032
|
return null;
|
|
3800
4033
|
}
|
|
3801
4034
|
function dependencies(root) {
|
|
3802
|
-
const file =
|
|
4035
|
+
const file = path21.join(root, "package.json");
|
|
3803
4036
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
3804
4037
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3805
4038
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
3806
4039
|
}
|
|
3807
4040
|
function runtimeDependencies(root) {
|
|
3808
|
-
const file =
|
|
4041
|
+
const file = path21.join(root, "package.json");
|
|
3809
4042
|
if (!existsSync(file)) return {};
|
|
3810
4043
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
3811
4044
|
}
|
|
@@ -4059,14 +4292,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
4059
4292
|
seen.add(file);
|
|
4060
4293
|
const json = readJsonc(file);
|
|
4061
4294
|
if (!json) return {};
|
|
4062
|
-
const dir =
|
|
4295
|
+
const dir = path21.dirname(file);
|
|
4063
4296
|
let merged = {};
|
|
4064
4297
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
4065
4298
|
for (const ext of parents) {
|
|
4066
4299
|
if (typeof ext !== "string") continue;
|
|
4067
4300
|
let target = null;
|
|
4068
|
-
if (ext.startsWith(".") ||
|
|
4069
|
-
const abs =
|
|
4301
|
+
if (ext.startsWith(".") || path21.isAbsolute(ext)) {
|
|
4302
|
+
const abs = path21.resolve(dir, ext);
|
|
4070
4303
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
4071
4304
|
} else {
|
|
4072
4305
|
const parts = ext.split("/");
|
|
@@ -4074,14 +4307,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
4074
4307
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
4075
4308
|
if (pkgDir) {
|
|
4076
4309
|
const sub = parts.slice(nameLength).join("/");
|
|
4077
|
-
const abs =
|
|
4310
|
+
const abs = path21.join(pkgDir, sub || "tsconfig.json");
|
|
4078
4311
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
4079
4312
|
}
|
|
4080
4313
|
}
|
|
4081
4314
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
4082
4315
|
}
|
|
4083
4316
|
const opts = json.compilerOptions ?? {};
|
|
4084
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
4317
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path21.resolve(dir, opts.baseUrl);
|
|
4085
4318
|
if (opts.paths && typeof opts.paths === "object") {
|
|
4086
4319
|
merged.paths = opts.paths;
|
|
4087
4320
|
merged.pathsDir = dir;
|
|
@@ -4092,7 +4325,7 @@ function aliases(root) {
|
|
|
4092
4325
|
const table = [];
|
|
4093
4326
|
let baseUrl = null;
|
|
4094
4327
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
4095
|
-
const file =
|
|
4328
|
+
const file = path21.join(root, name);
|
|
4096
4329
|
if (!existsSync(file)) continue;
|
|
4097
4330
|
const config = readTsconfig(root, file);
|
|
4098
4331
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -4100,22 +4333,22 @@ function aliases(root) {
|
|
|
4100
4333
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
4101
4334
|
if (!Array.isArray(targets)) continue;
|
|
4102
4335
|
const exact = !pattern.endsWith("*");
|
|
4103
|
-
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(/\*$/, ""))) });
|
|
4104
4337
|
}
|
|
4105
4338
|
}
|
|
4106
|
-
const pkg = readJsonc(
|
|
4339
|
+
const pkg = readJsonc(path21.join(root, "package.json"));
|
|
4107
4340
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
4108
4341
|
if (typeof target !== "string") continue;
|
|
4109
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
4342
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path21.join(root, target.replace(/\*.*$/, ""))] });
|
|
4110
4343
|
}
|
|
4111
|
-
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] });
|
|
4112
4345
|
return { table, baseUrl };
|
|
4113
4346
|
}
|
|
4114
4347
|
function resolveFile(base) {
|
|
4115
|
-
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}`))];
|
|
4116
4349
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
4117
4350
|
for (const p of tries) {
|
|
4118
|
-
if (SCRIPT_EXTS2.has(
|
|
4351
|
+
if (SCRIPT_EXTS2.has(path21.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
4119
4352
|
}
|
|
4120
4353
|
return null;
|
|
4121
4354
|
}
|
|
@@ -4129,7 +4362,7 @@ function createTrail(ctx) {
|
|
|
4129
4362
|
const { table, baseUrl } = aliases(ctx.root);
|
|
4130
4363
|
let declared = null;
|
|
4131
4364
|
try {
|
|
4132
|
-
const pkg = JSON.parse(readFileSync(
|
|
4365
|
+
const pkg = JSON.parse(readFileSync(path21.join(ctx.root, "package.json"), "utf8"));
|
|
4133
4366
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
4134
4367
|
} catch {
|
|
4135
4368
|
declared = null;
|
|
@@ -4160,17 +4393,17 @@ function createTrail(ctx) {
|
|
|
4160
4393
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
4161
4394
|
let resolved = null;
|
|
4162
4395
|
if (spec.startsWith(".")) {
|
|
4163
|
-
resolved = resolveFile(
|
|
4396
|
+
resolved = resolveFile(path21.resolve(path21.dirname(file.absolutePath), spec));
|
|
4164
4397
|
if (!resolved) lost = true;
|
|
4165
4398
|
} else {
|
|
4166
4399
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
4167
4400
|
if (alias) {
|
|
4168
4401
|
for (const t of alias.targets) {
|
|
4169
|
-
resolved = resolveFile(alias.exact ? t :
|
|
4402
|
+
resolved = resolveFile(alias.exact ? t : path21.join(t, spec.slice(alias.prefix.length)));
|
|
4170
4403
|
if (resolved) break;
|
|
4171
4404
|
}
|
|
4172
4405
|
}
|
|
4173
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
4406
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path21.join(baseUrl, spec));
|
|
4174
4407
|
if (!resolved) {
|
|
4175
4408
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
4176
4409
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -4184,215 +4417,62 @@ function createTrail(ctx) {
|
|
|
4184
4417
|
};
|
|
4185
4418
|
const strippedCache = /* @__PURE__ */ new Map();
|
|
4186
4419
|
const stripped = (file) => {
|
|
4187
|
-
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
4188
|
-
return strippedCache.get(file.absolutePath);
|
|
4189
|
-
};
|
|
4190
|
-
const memo = /* @__PURE__ */ new WeakMap();
|
|
4191
|
-
const reach = (file, test2, depth, seen) => {
|
|
4192
|
-
let cache2 = memo.get(test2);
|
|
4193
|
-
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
4194
|
-
const k = `${file.absolutePath}\0${depth}`;
|
|
4195
|
-
const free = cache2.free.get(k);
|
|
4196
|
-
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
4197
|
-
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
4198
|
-
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
4199
|
-
let result;
|
|
4200
|
-
const cut = /* @__PURE__ */ new Set();
|
|
4201
|
-
const code = stripped(file);
|
|
4202
|
-
if (code === null) result = "unknown";
|
|
4203
|
-
else if (test2(code)) result = "yes";
|
|
4204
|
-
else {
|
|
4205
|
-
const { files, lost } = importsOf(file);
|
|
4206
|
-
let unknown = lost && depth > 0;
|
|
4207
|
-
result = "no";
|
|
4208
|
-
if (depth > 0) {
|
|
4209
|
-
seen.add(file.absolutePath);
|
|
4210
|
-
for (const abs of files) {
|
|
4211
|
-
if (seen.has(abs)) {
|
|
4212
|
-
cut.add(abs);
|
|
4213
|
-
continue;
|
|
4214
|
-
}
|
|
4215
|
-
const target = read2(abs);
|
|
4216
|
-
if (!target) {
|
|
4217
|
-
unknown = true;
|
|
4218
|
-
continue;
|
|
4219
|
-
}
|
|
4220
|
-
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
4221
|
-
for (const m of c) cut.add(m);
|
|
4222
|
-
if (r === "yes") {
|
|
4223
|
-
result = "yes";
|
|
4224
|
-
break;
|
|
4225
|
-
}
|
|
4226
|
-
if (r === "unknown") unknown = true;
|
|
4227
|
-
}
|
|
4228
|
-
seen.delete(file.absolutePath);
|
|
4229
|
-
cut.delete(file.absolutePath);
|
|
4230
|
-
}
|
|
4231
|
-
if (result === "no" && unknown) result = "unknown";
|
|
4232
|
-
}
|
|
4233
|
-
if (result === "yes" || cut.size === 0) {
|
|
4234
|
-
cache2.free.set(k, result);
|
|
4235
|
-
return [result, /* @__PURE__ */ new Set()];
|
|
4236
|
-
}
|
|
4237
|
-
const entries = cache2.cut.get(k) ?? [];
|
|
4238
|
-
entries.push({ cut: [...cut], result });
|
|
4239
|
-
cache2.cut.set(k, entries);
|
|
4240
|
-
return [result, cut];
|
|
4241
|
-
};
|
|
4242
|
-
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
4243
|
-
}
|
|
4244
|
-
function buildCatalog(packagesDir) {
|
|
4245
|
-
const packages = {};
|
|
4246
|
-
for (const dir of readdirSync(packagesDir).sort()) {
|
|
4247
|
-
const file = path20.join(packagesDir, dir, "package.json");
|
|
4248
|
-
if (!existsSync(file)) continue;
|
|
4249
|
-
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
4250
|
-
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
4251
|
-
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
4252
|
-
}
|
|
4253
|
-
return { packages };
|
|
4254
|
-
}
|
|
4255
|
-
|
|
4256
|
-
// src/blocks/discover.ts
|
|
4257
|
-
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
4258
|
-
function cliPackageDir() {
|
|
4259
|
-
let dir = path20.dirname(fileURLToPath(import.meta.url));
|
|
4260
|
-
for (; ; ) {
|
|
4261
|
-
const file = path20.join(dir, "package.json");
|
|
4262
|
-
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
4263
|
-
const parent = path20.dirname(dir);
|
|
4264
|
-
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
4265
|
-
dir = parent;
|
|
4266
|
-
}
|
|
4267
|
-
}
|
|
4268
|
-
function workspacePackagesDir() {
|
|
4269
|
-
const dir = path20.resolve(cliPackageDir(), "..");
|
|
4270
|
-
return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
4271
|
-
}
|
|
4272
|
-
var catalogCache;
|
|
4273
|
-
function readCatalog() {
|
|
4274
|
-
if (catalogCache) return catalogCache;
|
|
4275
|
-
const workspace = workspacePackagesDir();
|
|
4276
|
-
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
4277
|
-
const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
4278
|
-
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
4279
|
-
return catalogCache;
|
|
4280
|
-
}
|
|
4281
|
-
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
4282
|
-
function installedGenesis(root) {
|
|
4283
|
-
const found = /* @__PURE__ */ new Map();
|
|
4284
|
-
let dir = path20.resolve(root);
|
|
4285
|
-
for (; ; ) {
|
|
4286
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
|
|
4287
|
-
const scope = path20.join(dir, "node_modules", "@marktiderman");
|
|
4288
|
-
if (existsSync(scope)) {
|
|
4289
|
-
for (const entry of readdirSync(scope)) {
|
|
4290
|
-
const name = `@marktiderman/${entry}`;
|
|
4291
|
-
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
4292
|
-
if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
|
|
4293
|
-
}
|
|
4294
|
-
}
|
|
4295
|
-
const parent = path20.dirname(dir);
|
|
4296
|
-
if (atInstallRoot || parent === dir) return found;
|
|
4297
|
-
dir = parent;
|
|
4298
|
-
}
|
|
4299
|
-
}
|
|
4300
|
-
var declarationCache = /* @__PURE__ */ new Map();
|
|
4301
|
-
function declarationsOf(dir, warnings) {
|
|
4302
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4303
|
-
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
4304
|
-
let cached = declarationCache.get(key2);
|
|
4305
|
-
if (!cached) {
|
|
4306
|
-
cached = loadDeclarations(dir, warnings);
|
|
4307
|
-
declarationCache.set(key2, cached);
|
|
4308
|
-
}
|
|
4309
|
-
return cached;
|
|
4310
|
-
}
|
|
4311
|
-
async function loadDeclarations(dir, warnings) {
|
|
4312
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4313
|
-
const entry = pkg.exports?.["./blocks"];
|
|
4314
|
-
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
4315
|
-
if (typeof target !== "string") return {};
|
|
4316
|
-
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
4317
|
-
const file = rel && path20.join(dir, ...rel.split("/"));
|
|
4318
|
-
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
4319
|
-
try {
|
|
4320
|
-
const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
|
|
4321
|
-
const mod = await jiti.import(file);
|
|
4322
|
-
const out = {};
|
|
4323
|
-
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
4324
|
-
return out;
|
|
4325
|
-
} catch (err) {
|
|
4326
|
-
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.`);
|
|
4327
|
-
return {};
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
4331
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4332
|
-
const raw = rawBlocksOf(pkg);
|
|
4333
|
-
const declared = await declarationsOf(dir, warnings);
|
|
4334
|
-
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
4335
|
-
const out = [];
|
|
4336
|
-
for (const id of [...ids].sort()) {
|
|
4337
|
-
const fromJson = raw[id] ?? {};
|
|
4338
|
-
const merged = { ...fromJson, ...declared[id] };
|
|
4339
|
-
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
4340
|
-
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
4341
|
-
if (manifest) out.push(manifest);
|
|
4342
|
-
}
|
|
4343
|
-
return out;
|
|
4344
|
-
}
|
|
4345
|
-
function withProvides(declared, json) {
|
|
4346
|
-
if (!Array.isArray(declared)) return declared;
|
|
4347
|
-
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
4348
|
-
return declared.map((m) => {
|
|
4349
|
-
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
4350
|
-
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
4351
|
-
});
|
|
4352
|
-
}
|
|
4353
|
-
async function allBlocks(root, warnings = []) {
|
|
4354
|
-
const out = [];
|
|
4355
|
-
for (const local of localPackages(root)) {
|
|
4356
|
-
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
4357
|
-
}
|
|
4358
|
-
const installed = installedGenesis(root);
|
|
4359
|
-
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
4360
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
4361
|
-
if (installed.has(name)) continue;
|
|
4362
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
4363
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
4364
|
-
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";
|
|
4365
4465
|
}
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
function tryParse(parse2, warnings) {
|
|
4370
|
-
try {
|
|
4371
|
-
return parse2();
|
|
4372
|
-
} catch (err) {
|
|
4373
|
-
if (!(err instanceof ManifestError)) throw err;
|
|
4374
|
-
warnings.push(err.message);
|
|
4375
|
-
return null;
|
|
4376
|
-
}
|
|
4377
|
-
}
|
|
4378
|
-
function catalogBlocks(warnings = []) {
|
|
4379
|
-
const out = [];
|
|
4380
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
4381
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
4382
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
4383
|
-
if (manifest) out.push(manifest);
|
|
4466
|
+
if (result === "yes" || cut.size === 0) {
|
|
4467
|
+
cache2.free.set(k, result);
|
|
4468
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
4384
4469
|
}
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
4392
|
-
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
4393
|
-
}
|
|
4394
|
-
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
4395
|
-
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] };
|
|
4396
4476
|
}
|
|
4397
4477
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
4398
4478
|
var STEMS = {
|
|
@@ -4411,7 +4491,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
4411
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;
|
|
4412
4492
|
function routesDir(ctx) {
|
|
4413
4493
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
4414
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
4494
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path21.join(ctx.root, d))) ?? null;
|
|
4415
4495
|
}
|
|
4416
4496
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
4417
4497
|
function flavorOf(dir, rels) {
|
|
@@ -4546,7 +4626,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
4546
4626
|
});
|
|
4547
4627
|
if (typeof raw === "string") {
|
|
4548
4628
|
if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
|
|
4549
|
-
const file =
|
|
4629
|
+
const file = path21.resolve(packageDir, raw);
|
|
4550
4630
|
if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
|
|
4551
4631
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
4552
4632
|
let parsed;
|
|
@@ -4595,7 +4675,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
4595
4675
|
if (typeof c.plugin === "string") {
|
|
4596
4676
|
if (!packageDir) plugin = c.plugin;
|
|
4597
4677
|
else {
|
|
4598
|
-
plugin =
|
|
4678
|
+
plugin = path21.resolve(packageDir, c.plugin);
|
|
4599
4679
|
if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
4600
4680
|
}
|
|
4601
4681
|
}
|
|
@@ -4645,7 +4725,7 @@ function checkPattern(v, where2, fail) {
|
|
|
4645
4725
|
}
|
|
4646
4726
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
4647
4727
|
function readDeclaringPackage(dir, local) {
|
|
4648
|
-
const file =
|
|
4728
|
+
const file = path21.join(dir, "package.json");
|
|
4649
4729
|
let stamp;
|
|
4650
4730
|
let real2;
|
|
4651
4731
|
try {
|
|
@@ -4668,7 +4748,7 @@ ${local}`;
|
|
|
4668
4748
|
const pkg = {
|
|
4669
4749
|
name: json.name,
|
|
4670
4750
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
4671
|
-
dir:
|
|
4751
|
+
dir: path21.resolve(dir),
|
|
4672
4752
|
namespace: ruleNamespace(json.name),
|
|
4673
4753
|
local,
|
|
4674
4754
|
private: json.private === true,
|
|
@@ -4682,7 +4762,7 @@ ${local}`;
|
|
|
4682
4762
|
if (raw !== void 0) {
|
|
4683
4763
|
const ignored = [];
|
|
4684
4764
|
try {
|
|
4685
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
4765
|
+
pkg.declaration = validateDeclaration(raw, json.name, path21.resolve(dir), ignored);
|
|
4686
4766
|
if (ignored.length) pkg.ignored = ignored;
|
|
4687
4767
|
} catch (err) {
|
|
4688
4768
|
pkg.error = err.message;
|
|
@@ -4701,14 +4781,14 @@ function discoverPackages(root) {
|
|
|
4701
4781
|
for (const dir of installed) {
|
|
4702
4782
|
let scope;
|
|
4703
4783
|
try {
|
|
4704
|
-
scope =
|
|
4784
|
+
scope = path21.dirname(realpathSync(dir));
|
|
4705
4785
|
} catch {
|
|
4706
4786
|
continue;
|
|
4707
4787
|
}
|
|
4708
|
-
if (
|
|
4788
|
+
if (path21.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
4709
4789
|
for (const entry of readdirSync(scope)) {
|
|
4710
4790
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
4711
|
-
const pkg = readDeclaringPackage(
|
|
4791
|
+
const pkg = readDeclaringPackage(path21.join(scope, entry), false);
|
|
4712
4792
|
if (pkg) byName.set(pkg.name, pkg);
|
|
4713
4793
|
}
|
|
4714
4794
|
}
|
|
@@ -4892,10 +4972,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
4892
4972
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
4893
4973
|
function sourceFiles(dir, rel = "") {
|
|
4894
4974
|
const out = [];
|
|
4895
|
-
for (const entry of readdirSync(
|
|
4975
|
+
for (const entry of readdirSync(path21.join(dir, rel)).sort()) {
|
|
4896
4976
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
4897
4977
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
4898
|
-
const stat = lstatSync(
|
|
4978
|
+
const stat = lstatSync(path21.join(dir, child));
|
|
4899
4979
|
if (stat.isSymbolicLink()) continue;
|
|
4900
4980
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
4901
4981
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -4918,13 +4998,13 @@ function matchPattern(pattern, spec) {
|
|
|
4918
4998
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
4919
4999
|
}
|
|
4920
5000
|
function tsconfigPaths(dir) {
|
|
4921
|
-
const file =
|
|
5001
|
+
const file = path21.join(dir, "tsconfig.json");
|
|
4922
5002
|
if (!existsSync(file)) return [];
|
|
4923
5003
|
try {
|
|
4924
5004
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
4925
5005
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
4926
|
-
const base =
|
|
4927
|
-
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)) }));
|
|
4928
5008
|
} catch {
|
|
4929
5009
|
return [];
|
|
4930
5010
|
}
|
|
@@ -4938,8 +5018,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4938
5018
|
const hit = matchPattern(pattern, spec);
|
|
4939
5019
|
if (hit === null) continue;
|
|
4940
5020
|
return targets.some((t) => {
|
|
4941
|
-
const rel =
|
|
4942
|
-
return !rel.startsWith("..") && !
|
|
5021
|
+
const rel = path21.relative(pkg.dir, t.replace("*", hit));
|
|
5022
|
+
return !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
4943
5023
|
});
|
|
4944
5024
|
}
|
|
4945
5025
|
return null;
|
|
@@ -4952,7 +5032,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4952
5032
|
...Object.keys(json.optionalDependencies ?? {})
|
|
4953
5033
|
]);
|
|
4954
5034
|
for (const file of sourceFiles(pkg.dir)) {
|
|
4955
|
-
const code = stripForImports(readFileSync(
|
|
5035
|
+
const code = stripForImports(readFileSync(path21.join(pkg.dir, file), "utf8"));
|
|
4956
5036
|
if (code === null) continue;
|
|
4957
5037
|
const at = `${pkg.rel}/${file}`;
|
|
4958
5038
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -4977,9 +5057,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4977
5057
|
continue;
|
|
4978
5058
|
}
|
|
4979
5059
|
if (spec.startsWith(".")) {
|
|
4980
|
-
const target =
|
|
4981
|
-
const rel =
|
|
4982
|
-
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)) {
|
|
4983
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` });
|
|
4984
5064
|
}
|
|
4985
5065
|
continue;
|
|
@@ -5016,12 +5096,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5016
5096
|
const from = own ? "" : ` (in ${m.package})`;
|
|
5017
5097
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
5018
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` });
|
|
5019
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
5099
|
+
} else if (typeof m.test === "string" && !existsSync(path21.join(home, m.test))) {
|
|
5020
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` });
|
|
5021
5101
|
}
|
|
5022
5102
|
}
|
|
5023
5103
|
}
|
|
5024
|
-
const dir =
|
|
5104
|
+
const dir = path21.join(pkg.dir, "migrations");
|
|
5025
5105
|
if (!existsSync(dir)) return;
|
|
5026
5106
|
const seen = /* @__PURE__ */ new Map();
|
|
5027
5107
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -5030,21 +5110,21 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5030
5110
|
const other = seen.get(m[1]);
|
|
5031
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` });
|
|
5032
5112
|
else seen.set(m[1], name);
|
|
5033
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
5113
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path21.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
5034
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")})` });
|
|
5035
5115
|
}
|
|
5036
5116
|
}
|
|
5037
5117
|
}
|
|
5038
5118
|
function checkExports(ctx, pkg, json) {
|
|
5039
5119
|
const targets = [];
|
|
5040
|
-
const
|
|
5120
|
+
const walk3 = (v) => {
|
|
5041
5121
|
if (typeof v === "string") targets.push(v);
|
|
5042
|
-
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);
|
|
5043
5123
|
};
|
|
5044
|
-
|
|
5124
|
+
walk3(json.exports);
|
|
5045
5125
|
for (const t of targets) {
|
|
5046
5126
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
5047
|
-
if (!existsSync(
|
|
5127
|
+
if (!existsSync(path21.join(pkg.dir, t))) {
|
|
5048
5128
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
5049
5129
|
}
|
|
5050
5130
|
}
|
|
@@ -5062,11 +5142,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
5062
5142
|
function checkTaggedTests(ctx, pkg) {
|
|
5063
5143
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
5064
5144
|
if (!tests.length) return;
|
|
5065
|
-
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")));
|
|
5066
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>` });
|
|
5067
5147
|
}
|
|
5068
5148
|
function checkRegistered(ctx, pkg) {
|
|
5069
|
-
const file =
|
|
5149
|
+
const file = path21.join(ctx.root, "features.json");
|
|
5070
5150
|
if (!existsSync(file)) return;
|
|
5071
5151
|
let doc;
|
|
5072
5152
|
try {
|
|
@@ -5076,7 +5156,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
5076
5156
|
}
|
|
5077
5157
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
5078
5158
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
5079
|
-
if (top) forms.add(
|
|
5159
|
+
if (top) forms.add(path21.relative(top, realpathSync(pkg.dir)).split(path21.sep).join("/"));
|
|
5080
5160
|
const covered = (doc.features ?? []).some(
|
|
5081
5161
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
5082
5162
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -5106,8 +5186,8 @@ function mergeBaseOf(root, base) {
|
|
|
5106
5186
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
5107
5187
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
5108
5188
|
if (!top) return;
|
|
5109
|
-
const appRelative = (fromTop) =>
|
|
5110
|
-
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("/");
|
|
5111
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");
|
|
5112
5192
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
5113
5193
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -5130,11 +5210,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
5130
5210
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
5131
5211
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
5132
5212
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
5133
|
-
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)) : [];
|
|
5134
5214
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
5135
5215
|
const named = naming.length > 0;
|
|
5136
5216
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
5137
|
-
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` });
|
|
5138
5218
|
}
|
|
5139
5219
|
let jsonBefore = null;
|
|
5140
5220
|
try {
|
|
@@ -5144,7 +5224,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
5144
5224
|
}
|
|
5145
5225
|
const raw = json;
|
|
5146
5226
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
5147
|
-
const appInRepo =
|
|
5227
|
+
const appInRepo = path21.relative(top, realpathSync(ctx.root)).split(path21.sep).join("/");
|
|
5148
5228
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
5149
5229
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
5150
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` });
|
|
@@ -5196,7 +5276,7 @@ function checkPackagesPack(ctx) {
|
|
|
5196
5276
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
5197
5277
|
}
|
|
5198
5278
|
for (const pkg of packages) {
|
|
5199
|
-
const json = JSON.parse(readFileSync(
|
|
5279
|
+
const json = JSON.parse(readFileSync(path21.join(pkg.dir, "package.json"), "utf8"));
|
|
5200
5280
|
checkImports2(ctx, pkg, json);
|
|
5201
5281
|
checkExports(ctx, pkg, json);
|
|
5202
5282
|
checkBlocks(ctx, pkg, json);
|
|
@@ -5213,7 +5293,7 @@ function emptyLock() {
|
|
|
5213
5293
|
return { version: 1, blocks: {}, files: {} };
|
|
5214
5294
|
}
|
|
5215
5295
|
function readLock(root) {
|
|
5216
|
-
const file =
|
|
5296
|
+
const file = path21.join(root, LOCK_FILE);
|
|
5217
5297
|
if (!existsSync(file)) return emptyLock();
|
|
5218
5298
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
5219
5299
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -5236,11 +5316,11 @@ function databaseElsewhere(root) {
|
|
|
5236
5316
|
const setting = readGenesisConfig(root)?.supabase;
|
|
5237
5317
|
if (setting === void 0) return null;
|
|
5238
5318
|
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
5239
|
-
const resolved =
|
|
5319
|
+
const resolved = path21.resolve(root, setting.app);
|
|
5240
5320
|
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
5241
5321
|
const dir = real2(resolved);
|
|
5242
|
-
if (dir === real2(
|
|
5243
|
-
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")) };
|
|
5244
5324
|
}
|
|
5245
5325
|
function isSupabasePath(rel) {
|
|
5246
5326
|
return rel === "supabase" || rel.startsWith("supabase/");
|
|
@@ -5430,9 +5510,9 @@ function checkSupabasePack(ctx) {
|
|
|
5430
5510
|
if (databaseElsewhere(ctx.root)) return;
|
|
5431
5511
|
const settings = ctx.config.supabase ?? {};
|
|
5432
5512
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
5433
|
-
const abs =
|
|
5513
|
+
const abs = path21.join(ctx.root, dir);
|
|
5434
5514
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
5435
|
-
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")) }));
|
|
5436
5516
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
5437
5517
|
const base = settings.base ?? DEFAULT_BASE;
|
|
5438
5518
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -5449,7 +5529,7 @@ function checkSupabasePack(ctx) {
|
|
|
5449
5529
|
}
|
|
5450
5530
|
}
|
|
5451
5531
|
const since = settings.since;
|
|
5452
|
-
const afterSince = (file) => since === void 0 ||
|
|
5532
|
+
const afterSince = (file) => since === void 0 || path21.posix.basename(file) >= since;
|
|
5453
5533
|
if ("reason" in view && since === void 0) {
|
|
5454
5534
|
ctx.report({
|
|
5455
5535
|
rule: "migration-grants",
|
|
@@ -5732,7 +5812,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
|
5732
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)$/;
|
|
5733
5813
|
var readManifest = (dir) => {
|
|
5734
5814
|
try {
|
|
5735
|
-
return JSON.parse(readFileSync(
|
|
5815
|
+
return JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
5736
5816
|
} catch {
|
|
5737
5817
|
return null;
|
|
5738
5818
|
}
|
|
@@ -5746,18 +5826,18 @@ var real = (p) => {
|
|
|
5746
5826
|
};
|
|
5747
5827
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
5748
5828
|
function nodeModulesOf(dir) {
|
|
5749
|
-
const parent =
|
|
5750
|
-
return
|
|
5829
|
+
const parent = path21.dirname(dir);
|
|
5830
|
+
return path21.basename(parent).startsWith("@") ? path21.dirname(parent) : parent;
|
|
5751
5831
|
}
|
|
5752
5832
|
function packagesIn(nodeModules) {
|
|
5753
5833
|
if (!existsSync(nodeModules)) return [];
|
|
5754
5834
|
const out = [];
|
|
5755
5835
|
for (const entry of readdirSync(nodeModules)) {
|
|
5756
5836
|
if (entry.startsWith(".")) continue;
|
|
5757
|
-
const p =
|
|
5837
|
+
const p = path21.join(nodeModules, entry);
|
|
5758
5838
|
if (entry.startsWith("@")) {
|
|
5759
5839
|
try {
|
|
5760
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5840
|
+
for (const sub of readdirSync(p)) out.push(path21.join(p, sub));
|
|
5761
5841
|
} catch {
|
|
5762
5842
|
}
|
|
5763
5843
|
} else {
|
|
@@ -5769,7 +5849,7 @@ function packagesIn(nodeModules) {
|
|
|
5769
5849
|
function genesisInstalls(root) {
|
|
5770
5850
|
const copies = /* @__PURE__ */ new Map();
|
|
5771
5851
|
const realRoot = real(root);
|
|
5772
|
-
const rel = (abs) =>
|
|
5852
|
+
const rel = (abs) => path21.relative(realRoot, abs).split(path21.sep).join("/") || ".";
|
|
5773
5853
|
const via = /* @__PURE__ */ new Map();
|
|
5774
5854
|
const record = (real2, manifest, by, range, root2) => {
|
|
5775
5855
|
let copy = copies.get(real2);
|
|
@@ -5781,7 +5861,7 @@ function genesisInstalls(root) {
|
|
|
5781
5861
|
via.get(real2).add(root2);
|
|
5782
5862
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
5783
5863
|
};
|
|
5784
|
-
const
|
|
5864
|
+
const walk3 = (kind, roots) => {
|
|
5785
5865
|
const expanded = /* @__PURE__ */ new Set();
|
|
5786
5866
|
const queue = [];
|
|
5787
5867
|
const visit = (dir, by, range) => {
|
|
@@ -5814,7 +5894,7 @@ function genesisInstalls(root) {
|
|
|
5814
5894
|
if (!dir) return null;
|
|
5815
5895
|
if (!ownInstall || name in declared) return dir;
|
|
5816
5896
|
const realDir = real(dir);
|
|
5817
|
-
if (realDir.startsWith(realRoot +
|
|
5897
|
+
if (realDir.startsWith(realRoot + path21.sep)) return dir;
|
|
5818
5898
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
5819
5899
|
};
|
|
5820
5900
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -5822,7 +5902,7 @@ function genesisInstalls(root) {
|
|
|
5822
5902
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
5823
5903
|
});
|
|
5824
5904
|
const app = readManifest(root);
|
|
5825
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5905
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path21.join(root, f)));
|
|
5826
5906
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
5827
5907
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
5828
5908
|
const runtimeDeps = {
|
|
@@ -5832,18 +5912,18 @@ function genesisInstalls(root) {
|
|
|
5832
5912
|
...app?.dependencies
|
|
5833
5913
|
};
|
|
5834
5914
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
5835
|
-
|
|
5836
|
-
const top =
|
|
5837
|
-
|
|
5915
|
+
walk3("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5916
|
+
const top = path21.join(root, "node_modules");
|
|
5917
|
+
walk3(
|
|
5838
5918
|
"hoisted",
|
|
5839
5919
|
packagesIn(top).filter((dir) => {
|
|
5840
|
-
const name =
|
|
5920
|
+
const name = path21.relative(top, dir).split(path21.sep).join("/");
|
|
5841
5921
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
5842
5922
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
5843
5923
|
);
|
|
5844
5924
|
const devRoots = { ...devDeps };
|
|
5845
5925
|
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
5846
|
-
|
|
5926
|
+
walk3("dev", rootsOf(devRoots, "the app (dev)"));
|
|
5847
5927
|
for (const [key2, copy] of copies) {
|
|
5848
5928
|
const kinds = via.get(key2);
|
|
5849
5929
|
copy.runtime = kinds.has("runtime");
|
|
@@ -5879,7 +5959,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
5879
5959
|
}
|
|
5880
5960
|
}
|
|
5881
5961
|
function checkPeerRanges(ctx) {
|
|
5882
|
-
const rel = (abs) =>
|
|
5962
|
+
const rel = (abs) => path21.relative(ctx.root, abs).split(path21.sep).join("/");
|
|
5883
5963
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
5884
5964
|
for (const copy of copies) {
|
|
5885
5965
|
const dir = copy.absolutePath;
|
|
@@ -6066,6 +6146,24 @@ function checkIsoDateSlices(ctx) {
|
|
|
6066
6146
|
}
|
|
6067
6147
|
}
|
|
6068
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
|
+
}
|
|
6069
6167
|
|
|
6070
6168
|
// src/upgrade/scope-names.ts
|
|
6071
6169
|
var IMPORTS_GENESIS = /\bfrom\s*["']@marktiderman\/genesis[\w/-]*["']/;
|
|
@@ -6260,11 +6358,11 @@ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
|
|
|
6260
6358
|
var TESTING_LIBRARY = "eslint-plugin-testing-library";
|
|
6261
6359
|
var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
|
|
6262
6360
|
function findEslintConfig(root) {
|
|
6263
|
-
return FLAT_CONFIG_FILES.find((name) => existsSync(
|
|
6361
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path21.join(root, name))) ?? null;
|
|
6264
6362
|
}
|
|
6265
6363
|
function readPackageJson(root) {
|
|
6266
6364
|
try {
|
|
6267
|
-
return JSON.parse(readFileSync(
|
|
6365
|
+
return JSON.parse(readFileSync(path21.join(root, "package.json"), "utf8"));
|
|
6268
6366
|
} catch {
|
|
6269
6367
|
return null;
|
|
6270
6368
|
}
|
|
@@ -6280,26 +6378,6 @@ function usesGenesisLint(text) {
|
|
|
6280
6378
|
return text.includes(ESLINT_EXPORT);
|
|
6281
6379
|
}
|
|
6282
6380
|
|
|
6283
|
-
// src/upgrade/codemods.ts
|
|
6284
|
-
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
6285
|
-
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
6286
|
-
var MAX_BYTES = 2 * 1024 * 1024;
|
|
6287
|
-
function appScripts(root) {
|
|
6288
|
-
const out = [];
|
|
6289
|
-
const walk2 = (dir) => {
|
|
6290
|
-
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
6291
|
-
const abs = path20.join(dir, entry.name);
|
|
6292
|
-
if (entry.isDirectory()) {
|
|
6293
|
-
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
6294
|
-
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
6295
|
-
out.push(path20.relative(root, abs).split(path20.sep).join("/"));
|
|
6296
|
-
}
|
|
6297
|
-
}
|
|
6298
|
-
};
|
|
6299
|
-
walk2(root);
|
|
6300
|
-
return out;
|
|
6301
|
-
}
|
|
6302
|
-
|
|
6303
6381
|
// src/doctor/api-usage.ts
|
|
6304
6382
|
var SCRIPT_EXTS5 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
6305
6383
|
function openingTag(code, start) {
|
|
@@ -6380,7 +6458,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
6380
6458
|
function moduleFiles(ctx) {
|
|
6381
6459
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
6382
6460
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
6383
|
-
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) }));
|
|
6384
6462
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
6385
6463
|
}
|
|
6386
6464
|
function checkStudioServerImports(ctx) {
|
|
@@ -6416,7 +6494,7 @@ var REMOVED_WORDS = {
|
|
|
6416
6494
|
};
|
|
6417
6495
|
function checkRemovedScopeNames(ctx) {
|
|
6418
6496
|
let augmentedMemo;
|
|
6419
|
-
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")));
|
|
6420
6498
|
for (const file of ctx.files) {
|
|
6421
6499
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
6422
6500
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -6488,16 +6566,16 @@ function genesisNamedImports(source) {
|
|
|
6488
6566
|
}
|
|
6489
6567
|
function declarationFiles(dir, out = []) {
|
|
6490
6568
|
for (const name of readdirSync(dir)) {
|
|
6491
|
-
const full =
|
|
6569
|
+
const full = path21.join(dir, name);
|
|
6492
6570
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
6493
6571
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
6494
6572
|
}
|
|
6495
6573
|
return out;
|
|
6496
6574
|
}
|
|
6497
6575
|
function readPackageTags(dir) {
|
|
6498
|
-
const pkg = JSON.parse(readFileSync(
|
|
6576
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
6499
6577
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
6500
|
-
const dist =
|
|
6578
|
+
const dist = path21.join(dir, "dist");
|
|
6501
6579
|
if (!existsSync(dist)) return tags;
|
|
6502
6580
|
for (const file of declarationFiles(dist)) {
|
|
6503
6581
|
const text = readFileSync(file, "utf8");
|
|
@@ -6515,7 +6593,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
6515
6593
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
6516
6594
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
6517
6595
|
const types = typeof target === "object" && target ? target.types : null;
|
|
6518
|
-
return typeof types === "string" ?
|
|
6596
|
+
return typeof types === "string" ? path21.join(tags.dir, types) : null;
|
|
6519
6597
|
}
|
|
6520
6598
|
function tagFor(tags, entry, name) {
|
|
6521
6599
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -6570,7 +6648,7 @@ function showAt(dir, rev, file) {
|
|
|
6570
6648
|
function configAtBase(root, base, explicitFile) {
|
|
6571
6649
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
6572
6650
|
if (!mergeBase) return null;
|
|
6573
|
-
const candidates = explicitFile ? [{ dir:
|
|
6651
|
+
const candidates = explicitFile ? [{ dir: path21.dirname(explicitFile), file: path21.basename(explicitFile), explicit: true }] : [
|
|
6574
6652
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
6575
6653
|
{ dir: root, file: "package.json", explicit: false }
|
|
6576
6654
|
];
|
|
@@ -6682,7 +6760,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6682
6760
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
6683
6761
|
let current = null;
|
|
6684
6762
|
try {
|
|
6685
|
-
current = lf(readFileSync(
|
|
6763
|
+
current = lf(readFileSync(path21.join(ctx.root, out), "utf8"));
|
|
6686
6764
|
} catch {
|
|
6687
6765
|
current = null;
|
|
6688
6766
|
}
|
|
@@ -6706,7 +6784,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6706
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}` });
|
|
6707
6785
|
return;
|
|
6708
6786
|
}
|
|
6709
|
-
const target =
|
|
6787
|
+
const target = path21.relative(process.cwd(), path21.join(ctx.root, out)) || out;
|
|
6710
6788
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
6711
6789
|
if (current !== expected) {
|
|
6712
6790
|
ctx.report({
|
|
@@ -6720,7 +6798,7 @@ var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
|
|
|
6720
6798
|
var CORE = [
|
|
6721
6799
|
{
|
|
6722
6800
|
need: "anything, before building it",
|
|
6723
|
-
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`',
|
|
6724
6802
|
docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
|
|
6725
6803
|
from: "genesis-cli"
|
|
6726
6804
|
},
|
|
@@ -6849,8 +6927,8 @@ function currentAgentsBlock(agents) {
|
|
|
6849
6927
|
var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6850
6928
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6851
6929
|
const rows = primitivesCatalog(packages);
|
|
6852
|
-
const skill = read(
|
|
6853
|
-
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)));
|
|
6854
6932
|
return {
|
|
6855
6933
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6856
6934
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -6872,36 +6950,14 @@ function checkAgentGuide(ctx) {
|
|
|
6872
6950
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6873
6951
|
}
|
|
6874
6952
|
}
|
|
6875
|
-
var CLI = "@marktiderman/genesis-cli";
|
|
6876
|
-
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6877
|
-
let parsed;
|
|
6878
|
-
try {
|
|
6879
|
-
parsed = parseSource(source);
|
|
6880
|
-
} catch (err) {
|
|
6881
|
-
return err instanceof Error ? err.message : String(err);
|
|
6882
|
-
}
|
|
6883
|
-
const { package: pkg, path: rel } = parsed;
|
|
6884
|
-
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6885
|
-
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6886
|
-
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6887
|
-
const base = rel.split("/").pop();
|
|
6888
|
-
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6889
|
-
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6890
|
-
}
|
|
6891
|
-
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6892
|
-
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6893
|
-
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6894
|
-
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6895
|
-
return `${key2} doesn't match its source ${source}`;
|
|
6896
|
-
}
|
|
6897
6953
|
|
|
6898
6954
|
// src/blocks/templates.ts
|
|
6899
6955
|
function starterDir() {
|
|
6900
6956
|
const workspace = workspacePackagesDir();
|
|
6901
|
-
const live = workspace &&
|
|
6902
|
-
if (live && existsSync(
|
|
6903
|
-
const packaged =
|
|
6904
|
-
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;
|
|
6905
6961
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
6906
6962
|
}
|
|
6907
6963
|
|
|
@@ -6975,7 +7031,7 @@ function readText(file) {
|
|
|
6975
7031
|
}
|
|
6976
7032
|
function starterBlockMap(root) {
|
|
6977
7033
|
if (root) {
|
|
6978
|
-
const file =
|
|
7034
|
+
const file = path21.join(root, GENESIS_CONFIG);
|
|
6979
7035
|
const text2 = readText(file);
|
|
6980
7036
|
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
6981
7037
|
if (own) return own;
|
|
@@ -6986,7 +7042,7 @@ function starterBlockMap(root) {
|
|
|
6986
7042
|
} catch {
|
|
6987
7043
|
return {};
|
|
6988
7044
|
}
|
|
6989
|
-
const text = readText(
|
|
7045
|
+
const text = readText(path21.join(dir, GENESIS_CONFIG));
|
|
6990
7046
|
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
6991
7047
|
}
|
|
6992
7048
|
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
@@ -7006,10 +7062,10 @@ function blocksSwitchedOff(switches, map, manifests, present) {
|
|
|
7006
7062
|
return off;
|
|
7007
7063
|
}
|
|
7008
7064
|
function appBlocksSwitchedOff(root, manifests, present) {
|
|
7009
|
-
const text = readText(
|
|
7065
|
+
const text = readText(path21.join(root, STARTER_CONFIG));
|
|
7010
7066
|
const switches = text === null ? null : parseStarterFeatures(text);
|
|
7011
7067
|
if (!switches) return /* @__PURE__ */ new Map();
|
|
7012
|
-
return blocksSwitchedOff(switches, starterBlockMap(existsSync(
|
|
7068
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path21.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
7013
7069
|
}
|
|
7014
7070
|
function blockOfSource(source, manifests) {
|
|
7015
7071
|
const at = source.indexOf(":");
|
|
@@ -7022,6 +7078,34 @@ function blockOfSource(source, manifests) {
|
|
|
7022
7078
|
}
|
|
7023
7079
|
return null;
|
|
7024
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
|
+
}
|
|
7025
7109
|
var BUN_LOCK = "bun.lock";
|
|
7026
7110
|
var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
|
|
7027
7111
|
var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
|
|
@@ -7154,21 +7238,9 @@ function staleNestedEntries(text, want = () => null) {
|
|
|
7154
7238
|
return out;
|
|
7155
7239
|
}
|
|
7156
7240
|
function readBunLock(dir) {
|
|
7157
|
-
const file =
|
|
7241
|
+
const file = path21.join(dir, BUN_LOCK);
|
|
7158
7242
|
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
7159
7243
|
}
|
|
7160
|
-
function findLockfile(root) {
|
|
7161
|
-
let dir = path20.resolve(root);
|
|
7162
|
-
for (; ; ) {
|
|
7163
|
-
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
7164
|
-
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
7165
|
-
if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
7166
|
-
if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
7167
|
-
const parent = path20.dirname(dir);
|
|
7168
|
-
if (parent === dir) return null;
|
|
7169
|
-
dir = parent;
|
|
7170
|
-
}
|
|
7171
|
-
}
|
|
7172
7244
|
|
|
7173
7245
|
// src/doctor/lock-files.ts
|
|
7174
7246
|
function checkBunLock(ctx) {
|
|
@@ -7176,7 +7248,7 @@ function checkBunLock(ctx) {
|
|
|
7176
7248
|
if (found?.pm !== "bun") return;
|
|
7177
7249
|
const text = readBunLock(found.dir);
|
|
7178
7250
|
if (text === null) return;
|
|
7179
|
-
const file =
|
|
7251
|
+
const file = path21.relative(ctx.root, path21.join(found.dir, BUN_LOCK)).split(path21.sep).join("/");
|
|
7180
7252
|
let stale;
|
|
7181
7253
|
try {
|
|
7182
7254
|
stale = staleNestedEntries(text);
|
|
@@ -7195,7 +7267,7 @@ function checkBunLock(ctx) {
|
|
|
7195
7267
|
}
|
|
7196
7268
|
async function checkLockFiles(ctx) {
|
|
7197
7269
|
checkBunLock(ctx);
|
|
7198
|
-
if (!existsSync(
|
|
7270
|
+
if (!existsSync(path21.join(ctx.root, LOCK_FILE))) return;
|
|
7199
7271
|
let lock;
|
|
7200
7272
|
try {
|
|
7201
7273
|
lock = readLock(ctx.root);
|
|
@@ -7228,6 +7300,11 @@ async function checkLockFiles(ctx) {
|
|
|
7228
7300
|
home = databaseElsewhere(ctx.root);
|
|
7229
7301
|
} catch {
|
|
7230
7302
|
}
|
|
7303
|
+
let appFolder = null;
|
|
7304
|
+
try {
|
|
7305
|
+
appFolder = appFolderOf(ctx.root);
|
|
7306
|
+
} catch {
|
|
7307
|
+
}
|
|
7231
7308
|
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
7232
7309
|
if (home && elsewhere.length) {
|
|
7233
7310
|
ctx.report({
|
|
@@ -7263,6 +7340,7 @@ async function checkLockFiles(ctx) {
|
|
|
7263
7340
|
}
|
|
7264
7341
|
if (text === null) {
|
|
7265
7342
|
if (entry.deleted) continue;
|
|
7343
|
+
if (appFolder && isRepositoryWorkflow(rel)) continue;
|
|
7266
7344
|
ctx.report({
|
|
7267
7345
|
rule: "lock-files",
|
|
7268
7346
|
level: "warn",
|
|
@@ -7297,7 +7375,7 @@ function checkDatabaseHome(ctx) {
|
|
|
7297
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)`
|
|
7298
7376
|
});
|
|
7299
7377
|
}
|
|
7300
|
-
if (existsSync(
|
|
7378
|
+
if (existsSync(path21.join(ctx.root, "supabase"))) {
|
|
7301
7379
|
ctx.report({
|
|
7302
7380
|
rule: "database-elsewhere",
|
|
7303
7381
|
level: "warn",
|
|
@@ -7315,7 +7393,7 @@ function checkEslintConfig(ctx) {
|
|
|
7315
7393
|
if (!file) return;
|
|
7316
7394
|
let text;
|
|
7317
7395
|
try {
|
|
7318
|
-
text = readFileSync(
|
|
7396
|
+
text = readFileSync(path21.join(ctx.root, file), "utf8");
|
|
7319
7397
|
} catch {
|
|
7320
7398
|
return;
|
|
7321
7399
|
}
|
|
@@ -7335,11 +7413,371 @@ function checkEslintConfig(ctx) {
|
|
|
7335
7413
|
subject: TESTING_LIBRARY,
|
|
7336
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`
|
|
7337
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 routeFrames = figma.frames.filter((f) => platformOf(f.page));
|
|
7662
|
+
const framesFor = (r) => routeFrames.filter((f) => platformOf(f.page) === r.platform && (sameScreen(f.route, r.route) || r.route === "index" && f.route === "/"));
|
|
7663
|
+
const byId = new Map(figma.frames.map((f) => [f.id, f]));
|
|
7664
|
+
const framed = new Set(routes.flatMap((r) => framesFor(r).map((f) => f.id)));
|
|
7665
|
+
const covered = routes.filter((r) => framesFor(r).length > 0);
|
|
7666
|
+
const routesWithoutFrame = routes.filter((r) => framesFor(r).length === 0);
|
|
7667
|
+
const framesWithoutRoute = routeFrames.filter((f) => !framed.has(f.id));
|
|
7668
|
+
const proposals = {};
|
|
7669
|
+
for (const f of figma.frames.filter((x) => x.page === config.proposalsPage)) (proposals[f.section ?? "(no section)"] ??= []).push(f);
|
|
7670
|
+
const missingHotspots = [];
|
|
7671
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7672
|
+
for (const t of targets) {
|
|
7673
|
+
const source = routes.find((r) => r.file === t.file);
|
|
7674
|
+
if (!source) continue;
|
|
7675
|
+
const from = framesFor(source);
|
|
7676
|
+
if (!from.length) continue;
|
|
7677
|
+
const dest = routes.find((r) => r.platform === source.platform && routeMatches(r.route, t.target));
|
|
7678
|
+
if (!dest || dest === source) continue;
|
|
7679
|
+
const key2 = `${source.route}\u2192${dest.route}`;
|
|
7680
|
+
if (seen.has(key2)) continue;
|
|
7681
|
+
seen.add(key2);
|
|
7682
|
+
const to = new Set(framesFor(dest).map((f) => f.id));
|
|
7683
|
+
const linked = figma.hotspots.some((h) => from.some((f) => f.id === h.from) && to.has(h.to));
|
|
7684
|
+
if (!linked) missingHotspots.push({ ...t, from: source.route, to: dest.route, targetHasFrame: to.size > 0 });
|
|
7685
|
+
}
|
|
7686
|
+
const deadHotspots = [];
|
|
7687
|
+
for (const h of figma.hotspots) {
|
|
7688
|
+
const from = byId.get(h.from);
|
|
7689
|
+
const to = byId.get(h.to);
|
|
7690
|
+
if (from && to && platformOf(to.page) && !framed.has(to.id)) deadHotspots.push({ from, to });
|
|
7691
|
+
}
|
|
7692
|
+
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) }));
|
|
7693
|
+
const wantedPages = [...Object.values(config.pages), config.proposalsPage];
|
|
7694
|
+
const missingPages = wantedPages.filter((p) => !figma.pages.includes(p));
|
|
7695
|
+
const uncheckedNavigation = dynamicTargets.filter((t) => routes.some((r) => r.file === t.file));
|
|
7696
|
+
return {
|
|
7697
|
+
file: config.file,
|
|
7698
|
+
summary: {
|
|
7699
|
+
routes: routes.length,
|
|
7700
|
+
frames: routeFrames.length,
|
|
7701
|
+
covered: covered.length,
|
|
7702
|
+
coveredPercent: routes.length ? Math.round(covered.length / routes.length * 100) : 100,
|
|
7703
|
+
hotspots: figma.hotspots.length,
|
|
7704
|
+
missing: missingPages.length + routesWithoutFrame.length + missingHotspots.length + idMismatches.length
|
|
7705
|
+
},
|
|
7706
|
+
missingPages,
|
|
7707
|
+
routesWithoutFrame,
|
|
7708
|
+
framesWithoutRoute,
|
|
7709
|
+
proposals,
|
|
7710
|
+
missingHotspots,
|
|
7711
|
+
deadHotspots,
|
|
7712
|
+
idMismatches,
|
|
7713
|
+
uncheckedNavigation
|
|
7714
|
+
};
|
|
7715
|
+
}
|
|
7716
|
+
async function checkFigmaRoutes(options) {
|
|
7717
|
+
const config = options.config ?? readFigmaConfig(options.root);
|
|
7718
|
+
if (!config) throw new FigmaConfigError(`no "figma" block in ${path21.join(options.root, "genesis.config.json")}`);
|
|
7719
|
+
const token = options.token ?? process.env.FIGMA_ACCESS_TOKEN;
|
|
7720
|
+
if (!token) throw new FigmaConfigError("FIGMA_ACCESS_TOKEN isn't set");
|
|
7721
|
+
const figma = await readFigma(config, token, options.fetch);
|
|
7722
|
+
return compare(config, appRoutes(options.root), appNavTargets(options.root), figma, appDynamicNavTargets(options.root));
|
|
7723
|
+
}
|
|
7724
|
+
function formatCoverage(r) {
|
|
7725
|
+
const s = r.summary;
|
|
7726
|
+
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`];
|
|
7727
|
+
const table = (title, head, rows) => {
|
|
7728
|
+
if (!rows.length) return;
|
|
7729
|
+
const widths = head.map((h, i) => Math.max(h.length, ...rows.map((row) => row[i].length)));
|
|
7730
|
+
const fmt = (row) => ` ${row.map((c, i) => c.padEnd(widths[i])).join(" ")}`.trimEnd();
|
|
7731
|
+
lines.push("", `${title} (${rows.length})`, fmt(head), fmt(widths.map((w) => "-".repeat(w))), ...rows.map(fmt));
|
|
7732
|
+
};
|
|
7733
|
+
if (r.missingPages.length) lines.push("", `Pages not in the file: ${r.missingPages.join(", ")}`);
|
|
7734
|
+
table("Routes with no frame", ["platform", "route", "file"], r.routesWithoutFrame.map((x) => [x.platform, x.route, x.file]));
|
|
7735
|
+
table("Frames with no route (move to Proposals, or add the route)", ["page", "frame", "id"], r.framesWithoutRoute.map((f) => [f.page, f.name, f.id]));
|
|
7736
|
+
table("Navigation with no hotspot", ["from", "to", "at"], r.missingHotspots.map((m) => [m.from, `${m.to}${m.targetHasFrame ? "" : " (no frame)"}`, `${m.file}:${m.line}`]));
|
|
7737
|
+
table("Hotspots to a frame with no route", ["from", "to"], r.deadHotspots.map((d) => [d.from.name, d.to.name]));
|
|
7738
|
+
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"]));
|
|
7739
|
+
table("Navigation not checked (not a string literal)", ["at", "target"], r.uncheckedNavigation.map((t) => [`${t.file}:${t.line}`, t.target]));
|
|
7740
|
+
table("Proposals", ["section", "frame", "id"], Object.entries(r.proposals).flatMap(([sec, fs]) => fs.map((f) => [sec, f.name, f.id])));
|
|
7741
|
+
return lines.join("\n");
|
|
7742
|
+
}
|
|
7743
|
+
function coverageFindings(r, strict) {
|
|
7744
|
+
const gap = strict ? "warn" : "info";
|
|
7745
|
+
return [
|
|
7746
|
+
...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 })),
|
|
7747
|
+
...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 })),
|
|
7748
|
+
...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 })),
|
|
7749
|
+
...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 })),
|
|
7750
|
+
...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 })),
|
|
7751
|
+
...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 })),
|
|
7752
|
+
...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 }))
|
|
7753
|
+
];
|
|
7754
|
+
}
|
|
7755
|
+
|
|
7756
|
+
// src/doctor/figma-routes.ts
|
|
7757
|
+
async function checkFigmaRoutesRule(ctx) {
|
|
7758
|
+
let config;
|
|
7759
|
+
try {
|
|
7760
|
+
config = readFigmaConfig(ctx.root);
|
|
7761
|
+
} catch (err) {
|
|
7762
|
+
if (!(err instanceof FigmaConfigError)) throw err;
|
|
7763
|
+
ctx.report({ rule: "figma-routes", level: "warn", file: "genesis.config.json", message: err.message });
|
|
7764
|
+
return;
|
|
7765
|
+
}
|
|
7766
|
+
if (!config) return;
|
|
7767
|
+
if (!process.env.FIGMA_ACCESS_TOKEN) {
|
|
7768
|
+
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)" });
|
|
7769
|
+
return;
|
|
7770
|
+
}
|
|
7771
|
+
try {
|
|
7772
|
+
const report = await checkFigmaRoutes({ root: ctx.root, config });
|
|
7773
|
+
for (const f of coverageFindings(report, ctx.strict ?? false)) ctx.report({ rule: "figma-routes", ...f });
|
|
7774
|
+
} catch (err) {
|
|
7775
|
+
ctx.report({ rule: "figma-routes", level: "info", file: "genesis.config.json", message: `skipped: ${err.message}` });
|
|
7338
7776
|
}
|
|
7339
7777
|
}
|
|
7340
7778
|
var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
|
|
7341
7779
|
async function runDoctor(options = {}) {
|
|
7342
|
-
const root =
|
|
7780
|
+
const root = path21.resolve(options.root ?? process.cwd());
|
|
7343
7781
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
7344
7782
|
const config = loaded.config;
|
|
7345
7783
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -7354,7 +7792,7 @@ async function runDoctor(options = {}) {
|
|
|
7354
7792
|
}
|
|
7355
7793
|
const raw = [];
|
|
7356
7794
|
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
7357
|
-
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
7795
|
+
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true, figma: options.figma ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
7358
7796
|
try {
|
|
7359
7797
|
await plugin.check(ctx);
|
|
7360
7798
|
} catch (err) {
|
|
@@ -7393,7 +7831,7 @@ async function runDoctor(options = {}) {
|
|
|
7393
7831
|
}
|
|
7394
7832
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
7395
7833
|
if (options.base && changed) {
|
|
7396
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
7834
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path21.join(root, f)) });
|
|
7397
7835
|
}
|
|
7398
7836
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
7399
7837
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -7442,6 +7880,7 @@ function builtinChecks(config, options = {}) {
|
|
|
7442
7880
|
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
7443
7881
|
{ name: "eslint-config", check: checkEslintConfig },
|
|
7444
7882
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
7883
|
+
...options.figma !== false ? [{ name: "figma-routes", check: checkFigmaRoutesRule }] : [],
|
|
7445
7884
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
7446
7885
|
];
|
|
7447
7886
|
}
|
|
@@ -7494,7 +7933,7 @@ function applyConfig(raw, config, packageIds) {
|
|
|
7494
7933
|
}
|
|
7495
7934
|
return out.sort((x, y) => x.file.localeCompare(y.file) || x.line - y.line || x.rule.localeCompare(y.rule));
|
|
7496
7935
|
}
|
|
7497
|
-
function formatReport(result) {
|
|
7936
|
+
function formatReport(result, options = {}) {
|
|
7498
7937
|
const g = result.genesis;
|
|
7499
7938
|
const lines = [
|
|
7500
7939
|
`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"}`
|
|
@@ -7502,13 +7941,13 @@ function formatReport(result) {
|
|
|
7502
7941
|
for (const f of result.findings) {
|
|
7503
7942
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
7504
7943
|
}
|
|
7505
|
-
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
7944
|
+
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)`);
|
|
7506
7945
|
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
7507
7946
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
7508
7947
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
7509
7948
|
return lines.join("\n");
|
|
7510
7949
|
}
|
|
7511
7950
|
|
|
7512
|
-
export { CommentSettingsError, DoctorConfigError, EmitError, GenesisConfigError, defineDoctorPlugin, detectHost, emitContracts, formatReport, introspectOpenApi, introspectPostgres, parseColumnComment, parseTableComment, planScaffold, planStudioInit, readGenesisConfig, runDoctor, runScaffold, validateConsumerName, validateLinks };
|
|
7951
|
+
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 };
|
|
7513
7952
|
//# sourceMappingURL=index.js.map
|
|
7514
7953
|
//# sourceMappingURL=index.js.map
|