@marktiderman/genesis-cli 1.8.0 → 1.9.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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { createRequire } from 'module';
2
2
  import { studioSetupSql } from '@marktiderman/genesis-studio-server';
3
3
  import * as path3 from 'path';
4
4
  import { spawnSync } from 'child_process';
5
- import { existsSync, readFileSync, statSync, readdirSync } from 'fs';
5
+ import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
6
6
  import { pathToFileURL } from 'url';
7
7
 
8
8
  // src/scaffolder.ts
@@ -101,9 +101,9 @@ async function runScaffold(opts, fs) {
101
101
  function joinPath(...parts) {
102
102
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
103
103
  }
104
- function dirname(path13) {
105
- const idx = path13.lastIndexOf("/");
106
- return idx === -1 ? "." : path13.slice(0, idx);
104
+ function dirname(path16) {
105
+ const idx = path16.lastIndexOf("/");
106
+ return idx === -1 ? "." : path16.slice(0, idx);
107
107
  }
108
108
  function brandPackageJson(consumer, genesisVersion) {
109
109
  return JSON.stringify(
@@ -343,12 +343,12 @@ function parse(comment, keys, where) {
343
343
  throw new CommentSettingsError(`${where}: the text after ${MARKER} must be one JSON object.`);
344
344
  }
345
345
  const settings = {};
346
- for (const [key, v] of Object.entries(value)) {
347
- if (!keys.includes(key)) {
348
- throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${key}". Allowed: ${keys.join(", ")}.`);
346
+ for (const [key2, v] of Object.entries(value)) {
347
+ if (!keys.includes(key2)) {
348
+ throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${key2}". Allowed: ${keys.join(", ")}.`);
349
349
  }
350
- if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${key}" must be a string.`);
351
- settings[key] = v;
350
+ if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${key2}" must be a string.`);
351
+ settings[key2] = v;
352
352
  }
353
353
  return { ...description ? { description } : {}, ...Object.keys(settings).length ? { settings } : {} };
354
354
  }
@@ -468,9 +468,9 @@ function introspectOpenApi(doc, schema = "public") {
468
468
  const def = definitions[tableName];
469
469
  const name = `${schema}.${tableName}`;
470
470
  const required = new Set(def.required ?? []);
471
- const key = [];
471
+ const key2 = [];
472
472
  const columns = Object.entries(def.properties ?? {}).map(([column, prop]) => {
473
- if (PK.test(prop.description ?? "")) key.push(column);
473
+ if (PK.test(prop.description ?? "")) key2.push(column);
474
474
  const fk = FK.exec(prop.description ?? "");
475
475
  const isArray = prop.type === "array";
476
476
  const format = (isArray ? prop.items?.format : prop.format) ?? prop.type ?? "text";
@@ -497,7 +497,7 @@ function introspectOpenApi(doc, schema = "public") {
497
497
  name,
498
498
  schema,
499
499
  table: tableName,
500
- key,
500
+ key: key2,
501
501
  columns,
502
502
  ...comment.description ? { description: comment.description } : {},
503
503
  ...comment.settings ? { settings: comment.settings } : {}
@@ -627,8 +627,8 @@ function routeTags(source) {
627
627
  var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
628
628
  function wireStudioRoute(source, route, pageImportPath) {
629
629
  const tags = routeTags(source);
630
- const relative2 = route.replace(/^\//, "");
631
- const existing = tags.find((t) => new RegExp(`path=["'](/?${relative2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
630
+ const relative3 = route.replace(/^\//, "");
631
+ const existing = tags.find((t) => new RegExp(`path=["'](/?${relative3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
632
632
  if (existing) {
633
633
  return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
634
634
  }
@@ -636,17 +636,17 @@ function wireStudioRoute(source, route, pageImportPath) {
636
636
  const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
637
637
  if (roots.length !== 1) {
638
638
  return {
639
- 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="${relative2}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
639
+ 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="${relative3}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
640
640
  };
641
641
  }
642
642
  const layout = roots[0];
643
643
  const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
644
- if (base && !relative2.startsWith(`${base}/`)) {
644
+ if (base && !relative3.startsWith(`${base}/`)) {
645
645
  return {
646
646
  skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
647
647
  };
648
648
  }
649
- const childPath = base ? relative2.slice(base.length + 1) : relative2;
649
+ const childPath = base ? relative3.slice(base.length + 1) : relative3;
650
650
  const guard = GUARD.exec(source)?.[1];
651
651
  const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
652
652
  const before = source.slice(0, layout.close);
@@ -1051,7 +1051,7 @@ var PRIVACY_PURPOSES = {
1051
1051
  "third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
1052
1052
  other: "NSPrivacyCollectedDataTypePurposeOther"
1053
1053
  };
1054
- var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
1054
+ var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
1055
1055
  var STRINGS = ["uiPackage", "rulesDoc"];
1056
1056
  var KNOWN = /* @__PURE__ */ new Set([
1057
1057
  ...STRING_LISTS,
@@ -1066,10 +1066,11 @@ var KNOWN = /* @__PURE__ */ new Set([
1066
1066
  "packs",
1067
1067
  "native",
1068
1068
  "supabase",
1069
+ "routesDir",
1069
1070
  "$schema",
1070
1071
  "$comment"
1071
1072
  ]);
1072
- var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
1073
+ var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
1073
1074
  var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
1074
1075
  var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
1075
1076
  var PACK_KEYS = {
@@ -1128,7 +1129,7 @@ function validatePrivacy(raw, source = "config") {
1128
1129
  };
1129
1130
  if (!isObject(raw)) fail(`"privacy" must be an object`);
1130
1131
  const c = raw;
1131
- for (const key of Object.keys(c)) if (!PRIVACY_KEYS.has(key)) fail(`privacy: unknown setting "${key}"`);
1132
+ for (const key2 of Object.keys(c)) if (!PRIVACY_KEYS.has(key2)) fail(`privacy: unknown setting "${key2}"`);
1132
1133
  const out = {};
1133
1134
  if (c.blocks !== void 0) {
1134
1135
  if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
@@ -1143,7 +1144,7 @@ function validatePrivacy(raw, source = "config") {
1143
1144
  out.collects = c.collects.map((entry, i) => {
1144
1145
  const where = `privacy.collects[${i}]`;
1145
1146
  if (!isObject(entry)) return fail(`${where} must be an object`);
1146
- for (const key of Object.keys(entry)) if (!DATA_USE_KEYS.has(key)) fail(`${where}: unknown setting "${key}"`);
1147
+ for (const key2 of Object.keys(entry)) if (!DATA_USE_KEYS.has(key2)) fail(`${where}: unknown setting "${key2}"`);
1147
1148
  if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
1148
1149
  fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
1149
1150
  }
@@ -1166,7 +1167,7 @@ function validateLinks(raw, source = "config") {
1166
1167
  };
1167
1168
  if (!isObject(raw)) fail(`"links" must be an object`);
1168
1169
  const c = raw;
1169
- for (const key of Object.keys(c)) if (!LINK_KEYS.has(key)) fail(`links: unknown setting "${key}"`);
1170
+ for (const key2 of Object.keys(c)) if (!LINK_KEYS.has(key2)) fail(`links: unknown setting "${key2}"`);
1170
1171
  if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
1171
1172
  for (const host of c.hosts) {
1172
1173
  if (!HOST.test(host)) {
@@ -1193,15 +1194,16 @@ function validateConfig(raw, source = "config") {
1193
1194
  };
1194
1195
  if (!isObject(raw)) fail("the doctor settings must be an object");
1195
1196
  const c = raw;
1196
- for (const key of Object.keys(c)) if (!KNOWN.has(key)) fail(`unknown setting "${key}"`);
1197
+ for (const key2 of Object.keys(c)) if (!KNOWN.has(key2)) fail(`unknown setting "${key2}"`);
1197
1198
  if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
1198
1199
  if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
1199
- for (const key of STRING_LISTS) {
1200
- if (c[key] !== void 0 && !isStringList(c[key])) fail(`"${key}" must be a list of strings`);
1200
+ for (const key2 of STRING_LISTS) {
1201
+ if (c[key2] !== void 0 && !isStringList(c[key2])) fail(`"${key2}" must be a list of strings`);
1201
1202
  }
1202
- for (const key of STRINGS) {
1203
- if (c[key] !== void 0 && typeof c[key] !== "string") fail(`"${key}" must be a string`);
1203
+ for (const key2 of STRINGS) {
1204
+ if (c[key2] !== void 0 && typeof c[key2] !== "string") fail(`"${key2}" must be a string`);
1204
1205
  }
1206
+ if (c.routesDir !== void 0) c.routesDir = appPath(c.routesDir, `"routesDir"`, fail);
1205
1207
  if (c.rawTags !== void 0) {
1206
1208
  if (!isObject(c.rawTags)) fail(`"rawTags" must be an object`);
1207
1209
  for (const [tag, v] of Object.entries(c.rawTags)) {
@@ -1219,7 +1221,7 @@ function validateConfig(raw, source = "config") {
1219
1221
  if (c.rules !== void 0) {
1220
1222
  if (!isObject(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
1221
1223
  for (const [rule, level] of Object.entries(c.rules)) {
1222
- if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
1224
+ if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn", "info" or "off"`);
1223
1225
  }
1224
1226
  }
1225
1227
  if (c.allow !== void 0) {
@@ -1312,11 +1314,12 @@ function globToRegExp(glob) {
1312
1314
  }
1313
1315
  function globMatcher(globs) {
1314
1316
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1315
- return (path13) => res.some((re) => re.test(path13));
1317
+ return (path16) => res.some((re) => re.test(path16));
1316
1318
  }
1317
1319
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1318
1320
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
1319
1321
  var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
1322
+ var DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
1320
1323
  var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
1321
1324
  var TAG_ALIASES = { hr: "Separator" };
1322
1325
  var NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
@@ -1387,9 +1390,23 @@ function loadGenesis(root, config) {
1387
1390
  components,
1388
1391
  tokens,
1389
1392
  rawTags,
1390
- palette: loadPalette(root)
1393
+ palette: loadPalette(root),
1394
+ companions: loadCompanions(root, config, uiPackage)
1391
1395
  };
1392
1396
  }
1397
+ function loadCompanions(root, config, uiPackage) {
1398
+ const out = [];
1399
+ for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
1400
+ if (name === uiPackage) continue;
1401
+ try {
1402
+ const pkg = readPackageExports(root, name);
1403
+ if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
1404
+ } catch (err) {
1405
+ if (!(err instanceof DoctorConfigError)) throw err;
1406
+ }
1407
+ }
1408
+ return out;
1409
+ }
1393
1410
  function readPackageExports(root, uiPackage) {
1394
1411
  const uiDir = findPackageDir(root, uiPackage);
1395
1412
  if (!uiDir) return null;
@@ -1459,8 +1476,8 @@ function exportTypes(target) {
1459
1476
  if (!target || typeof target !== "object") return void 0;
1460
1477
  const t = target;
1461
1478
  if (typeof t.types === "string") return t.types;
1462
- for (const key of ["import", "default", "require"]) {
1463
- const nested = exportTypes(t[key]);
1479
+ for (const key2 of ["import", "default", "require"]) {
1480
+ const nested = exportTypes(t[key2]);
1464
1481
  if (nested) return nested;
1465
1482
  }
1466
1483
  return void 0;
@@ -1516,8 +1533,8 @@ function loadPalette(root) {
1516
1533
  try {
1517
1534
  const req = createRequire(path3.join(root, "package.json"));
1518
1535
  const colors = req("tailwindcss/colors");
1519
- for (const key of Object.keys(colors?.default ?? colors ?? {})) {
1520
- if (/^[a-z]+$/.test(key) && !["inherit", "current", "transparent"].includes(key)) names.add(key);
1536
+ for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
1537
+ if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
1521
1538
  }
1522
1539
  } catch {
1523
1540
  }
@@ -1755,11 +1772,11 @@ function parseRulesMarkdown(markdown) {
1755
1772
  }
1756
1773
  const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message):\s*(.*)$/);
1757
1774
  if (!current || !kv) continue;
1758
- const [, key, raw] = kv;
1775
+ const [, key2, raw] = kv;
1759
1776
  const value = raw.trim();
1760
- if (key === "files" || key === "exclude") current[key] = value.split(",").map((s) => s.trim()).filter(Boolean);
1761
- else if (key === "level") current.level = value;
1762
- else current[key] = value;
1777
+ if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
1778
+ else if (key2 === "level") current.level = value;
1779
+ else current[key2] = value;
1763
1780
  }
1764
1781
  return rules;
1765
1782
  }
@@ -1774,8 +1791,8 @@ function compilePatternRules(rules, source) {
1774
1791
  if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
1775
1792
  ids.add(rule.id);
1776
1793
  const level = rule.level ?? "error";
1777
- if (!["error", "warn", "guide"].includes(level)) {
1778
- throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn or guide)`);
1794
+ if (!["error", "warn", "info", "guide"].includes(level)) {
1795
+ throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
1779
1796
  }
1780
1797
  if (level === "guide") continue;
1781
1798
  if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
@@ -1881,6 +1898,15 @@ var BUILTIN_RULES = [
1881
1898
  "undefined-token",
1882
1899
  "shadowed-export",
1883
1900
  "version-skew",
1901
+ "duplicate-genesis-package",
1902
+ "peer-range-mismatch",
1903
+ // structure
1904
+ "hand-rolled-sub-nav",
1905
+ "local-genesis-copy",
1906
+ "resource-workspace",
1907
+ "page-layout",
1908
+ // dates
1909
+ "iso-date-slice",
1884
1910
  // native pack
1885
1911
  "native-raw-primitive",
1886
1912
  "native-literal-color",
@@ -1891,7 +1917,8 @@ var BUILTIN_RULES = [
1891
1917
  "migration-grants",
1892
1918
  "migration-rls",
1893
1919
  "migration-definer-search-path",
1894
- "migration-edited"
1920
+ "migration-edited",
1921
+ "migration-testing-kit"
1895
1922
  ];
1896
1923
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
1897
1924
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2107,11 +2134,105 @@ var appFunctionality = (type, ...more) => ({
2107
2134
  function privacyApisFor(dependencies2) {
2108
2135
  return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
2109
2136
  }
2110
-
2111
- // src/doctor/native.ts
2112
2137
  var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2113
2138
  var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2114
2139
  var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2140
+ function localImports(root, file) {
2141
+ const out = [];
2142
+ for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2143
+ const spec = m[1];
2144
+ const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
2145
+ for (const base of bases) {
2146
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
2147
+ (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
2148
+ );
2149
+ if (hit) {
2150
+ out.push(hit);
2151
+ break;
2152
+ }
2153
+ }
2154
+ }
2155
+ return out;
2156
+ }
2157
+ function readSource(abs) {
2158
+ try {
2159
+ return { absolutePath: abs, code: readFileSync(abs, "utf8") };
2160
+ } catch {
2161
+ return null;
2162
+ }
2163
+ }
2164
+ function viaOneImport(root, files, file, test2) {
2165
+ if (test2(file.code)) return true;
2166
+ const byPath = new Map(files.map((f) => [f.absolutePath, f]));
2167
+ return localImports(root, file).some((abs) => {
2168
+ const target = byPath.get(abs) ?? readSource(abs);
2169
+ return target !== null && test2(target.code);
2170
+ });
2171
+ }
2172
+ function tagEnd(code, start) {
2173
+ let depth = 0;
2174
+ let quote2 = null;
2175
+ for (let i = start + 1; i < code.length; i++) {
2176
+ const ch = code[i];
2177
+ if (quote2) {
2178
+ if (ch === "\\") i++;
2179
+ else if (ch === quote2) quote2 = null;
2180
+ continue;
2181
+ }
2182
+ if (ch === '"' || ch === "'" || ch === "`") quote2 = ch;
2183
+ else if (ch === "{") depth++;
2184
+ else if (ch === "}") depth--;
2185
+ else if (ch === ">" && depth === 0) {
2186
+ let j = i - 1;
2187
+ while (j > start && /\s/.test(code[j])) j--;
2188
+ return { end: i + 1, selfClosing: code[j] === "/" };
2189
+ }
2190
+ }
2191
+ return { end: code.length, selfClosing: false };
2192
+ }
2193
+ function openElementsAt(code, index, track) {
2194
+ const open = [];
2195
+ const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
2196
+ for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
2197
+ const name = m[2];
2198
+ if (!track(name)) continue;
2199
+ if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
2200
+ if (m[1]) {
2201
+ const at = open.lastIndexOf(name);
2202
+ if (at !== -1) open.splice(at, 1);
2203
+ continue;
2204
+ }
2205
+ const { end, selfClosing } = tagEnd(code, m.index);
2206
+ if (end > index) break;
2207
+ if (!selfClosing) open.push(name);
2208
+ }
2209
+ return open;
2210
+ }
2211
+ function renderedElements(code) {
2212
+ const out = [];
2213
+ for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
2214
+ return out;
2215
+ }
2216
+ function rendersJsx(code) {
2217
+ return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
2218
+ }
2219
+ function namedImportsFrom(code, pkg) {
2220
+ const out = [];
2221
+ for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
2222
+ if (!pkg.test(m[2])) continue;
2223
+ for (const part of m[1].split(",")) {
2224
+ const p = part.trim();
2225
+ if (!p || p.startsWith("type ")) continue;
2226
+ const local = p.split(/\s+as\s+/).pop()?.trim();
2227
+ if (local) out.push(local);
2228
+ }
2229
+ }
2230
+ return out;
2231
+ }
2232
+
2233
+ // src/doctor/native.ts
2234
+ var SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2235
+ var JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2115
2236
  var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
2116
2237
  var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
2117
2238
  var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
@@ -2146,7 +2267,7 @@ function checkRawPrimitives(ctx, pkg) {
2146
2267
  ];
2147
2268
  const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
2148
2269
  for (const file of ctx.files) {
2149
- if (!SCRIPT_EXTS2.has(file.ext)) continue;
2270
+ if (!SCRIPT_EXTS3.has(file.ext)) continue;
2150
2271
  const code = file.code;
2151
2272
  const report = (name, at) => {
2152
2273
  const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
@@ -2192,7 +2313,7 @@ function checkCustomHeaders(ctx, pkg) {
2192
2313
  const reported = /* @__PURE__ */ new Set();
2193
2314
  const hidingLayouts = /* @__PURE__ */ new Map();
2194
2315
  for (const file of ctx.files) {
2195
- if (!JSX_EXTS2.has(file.ext)) continue;
2316
+ if (!JSX_EXTS3.has(file.ext)) continue;
2196
2317
  const code = file.code;
2197
2318
  const hidden = HIDES_HEADER.exec(code);
2198
2319
  if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
@@ -2222,7 +2343,7 @@ function checkCustomHeaders(ctx, pkg) {
2222
2343
  }
2223
2344
  }
2224
2345
  for (const file of ctx.files) {
2225
- if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2346
+ if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2226
2347
  const layout = hidingLayouts.get(path3.posix.dirname(file.path));
2227
2348
  const own = layout ? ownHeader(file.code, pkg) : null;
2228
2349
  if (!layout || !own) continue;
@@ -2261,7 +2382,7 @@ function checkScreenLayouts(ctx, pkg) {
2261
2382
  const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2262
2383
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2263
2384
  for (const file of routes) {
2264
- if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2385
+ if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2265
2386
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
2266
2387
  if (renders.test(file.code)) continue;
2267
2388
  const viaImport = localImports(ctx.root, file).some((abs) => {
@@ -2277,30 +2398,6 @@ function checkScreenLayouts(ctx, pkg) {
2277
2398
  });
2278
2399
  }
2279
2400
  }
2280
- function localImports(root, file) {
2281
- const out = [];
2282
- for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2283
- const spec = m[1];
2284
- const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
2285
- for (const base of bases) {
2286
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
2287
- (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
2288
- );
2289
- if (hit) {
2290
- out.push(hit);
2291
- break;
2292
- }
2293
- }
2294
- }
2295
- return out;
2296
- }
2297
- function readSource(abs) {
2298
- try {
2299
- return { code: readFileSync(abs, "utf8") };
2300
- } catch {
2301
- return null;
2302
- }
2303
- }
2304
2401
  var PERMISSIONS = [
2305
2402
  { module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
2306
2403
  { module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
@@ -2423,14 +2520,14 @@ function checkStoreReadiness(ctx) {
2423
2520
  });
2424
2521
  if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
2425
2522
  }
2426
- for (const [key, modules] of generic) {
2427
- const opt = PERMISSIONS.find((p) => p.key === key).option;
2523
+ for (const [key2, modules] of generic) {
2524
+ const opt = PERMISSIONS.find((p) => p.key === key2).option;
2428
2525
  ctx.report({
2429
2526
  rule: "store-readiness",
2430
2527
  level: "warn",
2431
2528
  file,
2432
- subject: key,
2433
- message: `leaves ${key} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
2529
+ subject: key2,
2530
+ message: `leaves ${key2} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key2}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
2434
2531
  });
2435
2532
  }
2436
2533
  const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
@@ -2659,6 +2756,20 @@ function checkSupabasePack(ctx) {
2659
2756
  }
2660
2757
  checkRls(ctx, migrations, exposed);
2661
2758
  checkDefinerSearchPath(ctx, migrations);
2759
+ checkTestingKit(ctx, migrations);
2760
+ }
2761
+ function checkTestingKit(ctx, migrations) {
2762
+ for (const { file, statements } of migrations) {
2763
+ const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
2764
+ if (!hit) continue;
2765
+ ctx.report({
2766
+ rule: "migration-testing-kit",
2767
+ file,
2768
+ line: hit.line,
2769
+ subject: "genesis_testing",
2770
+ message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
2771
+ });
2772
+ }
2662
2773
  }
2663
2774
  function granteesOf(s) {
2664
2775
  return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
@@ -2787,8 +2898,8 @@ function checkDefinerSearchPath(ctx, migrations) {
2787
2898
  for (const { sql, line } of statements) {
2788
2899
  const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
2789
2900
  if (create) {
2790
- const [key] = keysFor(sql, create[0].length, qualify(create[1]));
2791
- fns.set(key, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
2901
+ const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
2902
+ fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
2792
2903
  continue;
2793
2904
  }
2794
2905
  const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
@@ -2797,13 +2908,13 @@ function checkDefinerSearchPath(ctx, migrations) {
2797
2908
  const keys = keysFor(sql, alter[0].length, fnName);
2798
2909
  const rename = / rename to ([\w$]+)$/.exec(sql);
2799
2910
  const move = / set schema ([\w$]+)$/.exec(sql);
2800
- for (const key of keys) {
2801
- const state = fns.get(key);
2911
+ for (const key2 of keys) {
2912
+ const state = fns.get(key2);
2802
2913
  if (rename || move) {
2803
2914
  if (!state) continue;
2804
- fns.delete(key);
2915
+ fns.delete(key2);
2805
2916
  const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
2806
- fns.set(newName + key.slice(fnName.length), state);
2917
+ fns.set(newName + key2.slice(fnName.length), state);
2807
2918
  continue;
2808
2919
  }
2809
2920
  const next = state ?? { definer: false, searchPath: false, file, line };
@@ -2811,7 +2922,7 @@ function checkDefinerSearchPath(ctx, migrations) {
2811
2922
  if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
2812
2923
  if (/\bset search_path\b/.test(sql)) next.searchPath = true;
2813
2924
  if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
2814
- fns.set(key, next);
2925
+ fns.set(key2, next);
2815
2926
  }
2816
2927
  continue;
2817
2928
  }
@@ -2819,19 +2930,19 @@ function checkDefinerSearchPath(ctx, migrations) {
2819
2930
  if (drop) {
2820
2931
  for (const part of splitTop(drop[1])) {
2821
2932
  const m = /^([\w$.]+)\s*/.exec(part);
2822
- if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
2933
+ if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
2823
2934
  }
2824
2935
  }
2825
2936
  }
2826
2937
  }
2827
- for (const [key, at] of fns) {
2938
+ for (const [key2, at] of fns) {
2828
2939
  if (!at.definer || at.searchPath) continue;
2829
2940
  ctx.report({
2830
2941
  rule: "migration-definer-search-path",
2831
2942
  file: at.file,
2832
2943
  line: at.line,
2833
- subject: key,
2834
- message: `${key} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
2944
+ subject: key2,
2945
+ message: `${key2} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
2835
2946
  });
2836
2947
  }
2837
2948
  }
@@ -2860,6 +2971,445 @@ function checkVersionSkew(ctx) {
2860
2971
  }
2861
2972
  }
2862
2973
 
2974
+ // src/doctor/semver.ts
2975
+ var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2976
+ function parseVersion(v) {
2977
+ const m = VERSION.exec(v.trim());
2978
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2979
+ }
2980
+ function compareVersions(a, b) {
2981
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2982
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2983
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2984
+ const x = a.pre[i];
2985
+ const y = b.pre[i];
2986
+ if (x === void 0) return -1;
2987
+ if (y === void 0) return 1;
2988
+ if (x === y) continue;
2989
+ const nx = /^\d+$/.test(x);
2990
+ const ny = /^\d+$/.test(y);
2991
+ if (nx && ny) return +x < +y ? -1 : 1;
2992
+ if (nx !== ny) return nx ? -1 : 1;
2993
+ return x < y ? -1 : 1;
2994
+ }
2995
+ return 0;
2996
+ }
2997
+ function partial(s) {
2998
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2999
+ if (!m) return null;
3000
+ const nums = [];
3001
+ let wild = false;
3002
+ for (const part of [m[1], m[2], m[3]]) {
3003
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
3004
+ wild = true;
3005
+ nums.push(null);
3006
+ } else nums.push(+part);
3007
+ }
3008
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
3009
+ }
3010
+ var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
3011
+ function comparators(token) {
3012
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
3013
+ if (!m) return null;
3014
+ const op = m[1] ?? "";
3015
+ const p = partial(m[2]);
3016
+ if (!p) return null;
3017
+ const [major, mi, pa] = p.nums;
3018
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
3019
+ const M = major;
3020
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
3021
+ const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
3022
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
3023
+ const out = switchOp();
3024
+ if (p.pre.length) {
3025
+ for (const c of out) if (c.v === lo) c.pre = true;
3026
+ }
3027
+ return out;
3028
+ function switchOp() {
3029
+ switch (op) {
3030
+ case "^": {
3031
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
3032
+ return [
3033
+ { op: ">=", v: lo },
3034
+ { op: "<", v: bound }
3035
+ ];
3036
+ }
3037
+ case "~":
3038
+ case "~>":
3039
+ return [
3040
+ { op: ">=", v: lo },
3041
+ { op: "<", v: mi === null ? next("major") : next("minor") }
3042
+ ];
3043
+ case ">":
3044
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
3045
+ case ">=":
3046
+ return [{ op: ">=", v: lo }];
3047
+ case "<":
3048
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
3049
+ case "<=":
3050
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
3051
+ default:
3052
+ return upper ? [
3053
+ { op: ">=", v: lo },
3054
+ { op: "<", v: upper }
3055
+ ] : [{ op: "=", v: lo }];
3056
+ }
3057
+ }
3058
+ }
3059
+ function test(c, v) {
3060
+ const d = compareVersions(v, c.v);
3061
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
3062
+ }
3063
+ function parseRange(range) {
3064
+ const alts = [];
3065
+ for (const raw of range.trim().split("||")) {
3066
+ const alt = raw.trim();
3067
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
3068
+ if (hyphen) {
3069
+ const from = comparators(`>=${hyphen[1]}`);
3070
+ const to = comparators(`<=${hyphen[2]}`);
3071
+ if (!from || !to) return null;
3072
+ alts.push([...from, ...to]);
3073
+ continue;
3074
+ }
3075
+ const set = [];
3076
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
3077
+ const cs = comparators(token);
3078
+ if (!cs) return null;
3079
+ set.push(...cs);
3080
+ }
3081
+ alts.push(set);
3082
+ }
3083
+ return alts;
3084
+ }
3085
+ function satisfies(version, range) {
3086
+ const v = parseVersion(version);
3087
+ const alts = parseRange(range);
3088
+ if (!v || !alts) return null;
3089
+ return alts.some(
3090
+ (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))
3091
+ );
3092
+ }
3093
+
3094
+ // src/doctor/installs.ts
3095
+ var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
3096
+ var readManifest = (dir) => {
3097
+ try {
3098
+ return JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8"));
3099
+ } catch {
3100
+ return null;
3101
+ }
3102
+ };
3103
+ var real = (p) => {
3104
+ try {
3105
+ return realpathSync(p);
3106
+ } catch {
3107
+ return p;
3108
+ }
3109
+ };
3110
+ function packagesIn(nodeModules) {
3111
+ if (!existsSync(nodeModules)) return [];
3112
+ const out = [];
3113
+ for (const entry of readdirSync(nodeModules)) {
3114
+ if (entry.startsWith(".")) continue;
3115
+ const p = path3.join(nodeModules, entry);
3116
+ if (entry.startsWith("@")) {
3117
+ try {
3118
+ for (const sub of readdirSync(p)) out.push(path3.join(p, sub));
3119
+ } catch {
3120
+ }
3121
+ } else {
3122
+ out.push(p);
3123
+ }
3124
+ }
3125
+ return out;
3126
+ }
3127
+ function genesisInstalls(root) {
3128
+ const copies = /* @__PURE__ */ new Map();
3129
+ const realRoot = real(root);
3130
+ const rel = (abs) => path3.relative(realRoot, abs).split(path3.sep).join("/") || ".";
3131
+ const record = (real2, manifest, by, range) => {
3132
+ let copy = copies.get(real2);
3133
+ if (!copy) {
3134
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
3135
+ copies.set(real2, copy);
3136
+ }
3137
+ if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
3138
+ };
3139
+ const expanded = /* @__PURE__ */ new Set();
3140
+ const queue = [];
3141
+ const visit = (dir, by, range) => {
3142
+ const manifest = readManifest(dir);
3143
+ if (!manifest?.name) return;
3144
+ const realDir = real(dir);
3145
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range);
3146
+ if (expanded.has(realDir)) return;
3147
+ expanded.add(realDir);
3148
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
3149
+ };
3150
+ const app = readManifest(root);
3151
+ const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3152
+ for (const name of Object.keys(appDeps)) {
3153
+ const dir = findPackageDir(root, name);
3154
+ if (dir) visit(dir, "the app", appDeps[name]);
3155
+ }
3156
+ const top = path3.join(root, "node_modules");
3157
+ for (const dir of packagesIn(top)) {
3158
+ const name = path3.relative(top, dir).split(path3.sep).join("/");
3159
+ if (!(name in appDeps)) visit(dir, "hoisted, not a direct dependency", void 0);
3160
+ }
3161
+ while (queue.length) {
3162
+ const { real: from, manifest, label } = queue.shift();
3163
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
3164
+ for (const [name, range] of Object.entries(deps)) {
3165
+ const dir = findPackageDir(from, name);
3166
+ if (dir) visit(dir, label, range);
3167
+ }
3168
+ }
3169
+ const byName = /* @__PURE__ */ new Map();
3170
+ for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
3171
+ for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
3172
+ return byName;
3173
+ }
3174
+ function checkDuplicatePackages(ctx) {
3175
+ for (const [name, copies] of genesisInstalls(ctx.root)) {
3176
+ if (copies.length < 2) continue;
3177
+ const where = copies.map((c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`).join(", ");
3178
+ ctx.report({
3179
+ rule: "duplicate-genesis-package",
3180
+ level: "warn",
3181
+ file: "package.json",
3182
+ subject: name,
3183
+ message: `${name} is installed ${copies.length} times: ${where}. Each copy is its own module, so a provider from one (DataProvider, the shell's contexts) is invisible to hooks from another. Align the ranges so one copy satisfies them all, or add an override/resolution`
3184
+ });
3185
+ }
3186
+ }
3187
+ function checkPeerRanges(ctx) {
3188
+ const rel = (abs) => path3.relative(ctx.root, abs).split(path3.sep).join("/");
3189
+ for (const copies of genesisInstalls(ctx.root).values()) {
3190
+ for (const copy of copies) {
3191
+ const dir = copy.absolutePath;
3192
+ const peers = readManifest(dir)?.peerDependencies ?? {};
3193
+ for (const [peer, range] of Object.entries(peers)) {
3194
+ if (!GENESIS.test(peer)) continue;
3195
+ const peerDir = findPackageDir(dir, peer);
3196
+ const installed = peerDir && readManifest(peerDir)?.version;
3197
+ if (!peerDir || !installed) continue;
3198
+ if (satisfies(installed, range) !== false) continue;
3199
+ ctx.report({
3200
+ rule: "peer-range-mismatch",
3201
+ level: "warn",
3202
+ file: "package.json",
3203
+ subject: `${copy.name}>${peer}`,
3204
+ message: `${copy.name}@${copy.version} (${copy.dir}) wants ${peer} ${range}, but ${installed} is installed (${rel(peerDir)}). Install a ${peer} in that range, or a ${copy.name} release built against ${installed}`
3205
+ });
3206
+ }
3207
+ }
3208
+ }
3209
+ }
3210
+ var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
3211
+ var LAYOUT_STEMS = /* @__PURE__ */ new Set(["route", "layout", "_layout", "__root", "_app"]);
3212
+ var INDEX_STEMS = /* @__PURE__ */ new Set(["index", "page"]);
3213
+ var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
3214
+ var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
3215
+ function routesDir(ctx) {
3216
+ if (ctx.config.routesDir) return ctx.config.routesDir;
3217
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path3.join(ctx.root, d))) ?? null;
3218
+ }
3219
+ var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
3220
+ function webRoutes(ctx) {
3221
+ const dir = routesDir(ctx);
3222
+ if (!dir) return [];
3223
+ const routes = [];
3224
+ for (const file of ctx.files) {
3225
+ if (!JSX_EXTS2.has(file.ext) || !file.path.startsWith(`${dir}/`)) continue;
3226
+ const rel = file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "");
3227
+ const parts = rel.split("/");
3228
+ if (parts.some((p) => p.startsWith("-"))) continue;
3229
+ const stem = parts.pop();
3230
+ const segments = [...parts, ...LAYOUT_STEMS.has(stem) || INDEX_STEMS.has(stem) ? [] : stem.split(".")];
3231
+ let index = INDEX_STEMS.has(stem);
3232
+ if (!index && !LAYOUT_STEMS.has(stem) && INDEX_STEMS.has(segments.at(-1) ?? "")) {
3233
+ segments.pop();
3234
+ index = true;
3235
+ }
3236
+ const elements = renderedElements(file.code);
3237
+ const layout = LAYOUT_STEMS.has(stem) || elements.includes("Outlet");
3238
+ routes.push({
3239
+ file,
3240
+ segments,
3241
+ index,
3242
+ layout,
3243
+ detail: !index && !layout && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
3244
+ redirectOnly: elements.every((e) => NON_PAGE_ELEMENTS.has(e)) && !HTML_ELEMENT.test(file.code),
3245
+ parents: []
3246
+ });
3247
+ }
3248
+ for (const r of routes) {
3249
+ const own = r.segments;
3250
+ for (const p of routes) {
3251
+ if (p === r || !p.layout) continue;
3252
+ const n = p.segments.length;
3253
+ if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
3254
+ if (key(own.slice(0, n)) !== key(p.segments)) continue;
3255
+ if (n > 0 && own[n - 1].endsWith("_") && !p.segments[n - 1].endsWith("_")) continue;
3256
+ r.parents.push(p);
3257
+ }
3258
+ r.parents.sort((a, b) => b.segments.length - a.segments.length);
3259
+ }
3260
+ return routes;
3261
+ }
3262
+
3263
+ // src/doctor/structure.ts
3264
+ var SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
3265
+ var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
3266
+ var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
3267
+ var SHELL = /<AppShell(?=[\s>/])/;
3268
+ var GENESIS_PACKAGE = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
3269
+ var PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
3270
+ var PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
3271
+ var isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
3272
+ var rendersRe = (names) => {
3273
+ const list = [...names];
3274
+ return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
3275
+ };
3276
+ function insideShell(ctx, routes) {
3277
+ const shell = new Set(routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => SHELL.test(code))));
3278
+ const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
3279
+ return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
3280
+ }
3281
+ function checkHandRolledSubNav(ctx) {
3282
+ if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
3283
+ const routes = webRoutes(ctx);
3284
+ if (routes.length === 0) return;
3285
+ const inShell = insideShell(ctx, routes);
3286
+ const ui = ctx.genesis.uiPackage;
3287
+ for (const r of routes) {
3288
+ if (!inShell(r)) continue;
3289
+ const code = r.file.code;
3290
+ if (/\buseAppShellSubNav\s*\(/.test(code)) continue;
3291
+ for (const m of code.matchAll(SWITCHER)) {
3292
+ if (openElementsAt(code, m.index, (n) => CONTAINER.test(n)).length > 0) continue;
3293
+ ctx.report({
3294
+ rule: "hand-rolled-sub-nav",
3295
+ level: "warn",
3296
+ file: r.file.path,
3297
+ line: lineAt(code, m.index),
3298
+ subject: m[1],
3299
+ message: `switches the page's sections with its own <${m[1]}>; hand them to the shell with useAppShellSubNav(items, { mode: "tabs" }) and put the header in AppShellPageHeader (chips in AppShellSubNavEnd), from ${ui}/layout, so the sections are the shell's tab row and the phone's bottom bar. See ${SUB_NAV_DOCS}`
3300
+ });
3301
+ break;
3302
+ }
3303
+ }
3304
+ }
3305
+ function checkLocalGenesisCopies(ctx) {
3306
+ const owner = /* @__PURE__ */ new Map();
3307
+ for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
3308
+ for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
3309
+ if (owner.size === 0) return;
3310
+ const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
3311
+ const routes = routesDir(ctx);
3312
+ for (const file of ctx.files) {
3313
+ if (!JSX_EXTS2.has(file.ext)) continue;
3314
+ const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE));
3315
+ const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
3316
+ const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
3317
+ const decls = [...file.code.matchAll(decl)];
3318
+ decls.forEach((m, i) => {
3319
+ const [, exported, name] = m;
3320
+ const pkg = owner.get(name);
3321
+ if (!pkg || imported.has(name) || routeComponents.has(name)) return;
3322
+ if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
3323
+ const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
3324
+ if (!rendersJsx(body)) return;
3325
+ if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
3326
+ const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
3327
+ if (/["']@marktiderman\/genesis/.test(init)) return;
3328
+ ctx.report({
3329
+ rule: "local-genesis-copy",
3330
+ level: "warn",
3331
+ file: file.path,
3332
+ line: lineAt(file.code, m.index),
3333
+ subject: name,
3334
+ message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
3335
+ });
3336
+ });
3337
+ }
3338
+ }
3339
+ function checkResourceWorkspaces(ctx) {
3340
+ if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
3341
+ const header = /<AppShellPageHeader(?=[\s>/])/;
3342
+ const byFolder = /* @__PURE__ */ new Map();
3343
+ for (const r of webRoutes(ctx)) {
3344
+ if (!r.detail || r.redirectOnly) continue;
3345
+ const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
3346
+ byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
3347
+ }
3348
+ for (const [dir, routes] of byFolder) {
3349
+ const has2 = routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => header.test(code)));
3350
+ if (has2.length === 0) continue;
3351
+ const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
3352
+ for (const r of routes) {
3353
+ if (has2.includes(r)) continue;
3354
+ ctx.report({
3355
+ rule: "resource-workspace",
3356
+ level: "info",
3357
+ file: r.file.path,
3358
+ message: `is a detail page without AppShellPageHeader, unlike ${ref} beside it; put its header in AppShellPageHeader and its sections in useAppShellSubNav so every workspace in ${dir} has the same header, tabs and phone bar`
3359
+ });
3360
+ }
3361
+ }
3362
+ }
3363
+ function checkPageLayouts(ctx) {
3364
+ if (isNative(ctx)) return;
3365
+ const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
3366
+ for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
3367
+ if (layouts.size === 0) return;
3368
+ const routes = webRoutes(ctx);
3369
+ const inShell = insideShell(ctx, routes);
3370
+ const rendersLayout = (code) => {
3371
+ const names = new Set(layouts);
3372
+ for (const n of namedImportsFrom(code, GENESIS_PACKAGE)) if (PACKAGE_SCREEN.test(n)) names.add(n);
3373
+ return rendersRe(names)?.test(code) ?? false;
3374
+ };
3375
+ const cache = /* @__PURE__ */ new Map();
3376
+ const provides = (r) => {
3377
+ if (!cache.has(r)) cache.set(r, viaOneImport(ctx.root, ctx.files, r.file, rendersLayout));
3378
+ return cache.get(r);
3379
+ };
3380
+ const list = [...layouts].sort();
3381
+ const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
3382
+ for (const r of routes) {
3383
+ if (r.layout || r.redirectOnly || !inShell(r)) continue;
3384
+ if (provides(r) || r.parents.some(provides)) continue;
3385
+ ctx.report({
3386
+ rule: "page-layout",
3387
+ level: "warn",
3388
+ file: r.file.path,
3389
+ message: `renders no Genesis page layout (${named}) itself, through one local import, or from a layout route around it; wrap it in one so the header, width and spacing match every other page`
3390
+ });
3391
+ }
3392
+ }
3393
+
3394
+ // src/doctor/dates.ts
3395
+ var SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
3396
+ var ISO_DAY_CUT = /\.toISOString\(\)\s*\.\s*(?:slice\(\s*0\s*,\s*10\s*\)|substring\(\s*0\s*,\s*10\s*\)|substr\(\s*0\s*,\s*10\s*\)|split\(\s*(["'`])T\1\s*\)\s*\[\s*0\s*\]|split\(\s*(["'`])T\2\s*\)\s*\.\s*at\(\s*0\s*\))/g;
3397
+ function checkIsoDateSlices(ctx) {
3398
+ for (const file of ctx.files) {
3399
+ if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
3400
+ for (const m of file.code.matchAll(ISO_DAY_CUT)) {
3401
+ ctx.report({
3402
+ rule: "iso-date-slice",
3403
+ level: "warn",
3404
+ file: file.path,
3405
+ line: lineAt(file.code, m.index ?? 0),
3406
+ subject: "toISOString",
3407
+ message: "cuts a day from an ISO timestamp, which is the day in UTC, not the person's; use personDay(person) or dayIn(zone) from @marktiderman/genesis-core/dates (allow it with a reason where UTC is meant)"
3408
+ });
3409
+ }
3410
+ }
3411
+ }
3412
+
2863
3413
  // src/doctor/index.ts
2864
3414
  async function runDoctor(options = {}) {
2865
3415
  const root = path3.resolve(options.root ?? process.cwd());
@@ -2875,18 +3425,7 @@ async function runDoctor(options = {}) {
2875
3425
  }
2876
3426
  const raw = [];
2877
3427
  const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
2878
- const builtins = [
2879
- { name: "layout", check: checkProjectLayout },
2880
- { name: "imports", check: checkImports },
2881
- { name: "raw-tags", check: checkRawTags },
2882
- { name: "colors", check: checkColors },
2883
- { name: "tokens", check: checkTokens },
2884
- { name: "shadowed-exports", check: checkShadowedExports },
2885
- { name: "version-skew", check: checkVersionSkew },
2886
- ...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
2887
- ...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
2888
- ];
2889
- for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
3428
+ for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
2890
3429
  try {
2891
3430
  await plugin.check(ctx);
2892
3431
  } catch (err) {
@@ -2900,7 +3439,8 @@ async function runDoctor(options = {}) {
2900
3439
  }
2901
3440
  const findings = applyConfig(raw, config);
2902
3441
  const errors = findings.filter((f) => f.level === "error").length;
2903
- const warnings = findings.length - errors;
3442
+ const warnings = findings.filter((f) => f.level === "warn").length;
3443
+ const infos = findings.length - errors - warnings;
2904
3444
  return {
2905
3445
  ok: errors === 0 && !(options.strict && warnings > 0),
2906
3446
  root,
@@ -2909,8 +3449,32 @@ async function runDoctor(options = {}) {
2909
3449
  unused: unusedComponents(ctx),
2910
3450
  ruleCount: (patterns?.count ?? 0) + plugins.length,
2911
3451
  errors,
2912
- warnings
3452
+ warnings,
3453
+ infos
3454
+ };
3455
+ }
3456
+ function builtinChecks(config) {
3457
+ const packs = {
3458
+ native: { name: "native", check: checkNativePack },
3459
+ supabase: { name: "supabase", check: checkSupabasePack }
2913
3460
  };
3461
+ return [
3462
+ { name: "layout", check: checkProjectLayout },
3463
+ { name: "imports", check: checkImports },
3464
+ { name: "raw-tags", check: checkRawTags },
3465
+ { name: "colors", check: checkColors },
3466
+ { name: "tokens", check: checkTokens },
3467
+ { name: "shadowed-exports", check: checkShadowedExports },
3468
+ { name: "version-skew", check: checkVersionSkew },
3469
+ { name: "duplicate-packages", check: checkDuplicatePackages },
3470
+ { name: "peer-ranges", check: checkPeerRanges },
3471
+ { name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
3472
+ { name: "local-genesis-copies", check: checkLocalGenesisCopies },
3473
+ { name: "resource-workspaces", check: checkResourceWorkspaces },
3474
+ { name: "page-layouts", check: checkPageLayouts },
3475
+ { name: "iso-date-slices", check: checkIsoDateSlices },
3476
+ ...(config.packs ?? []).map((p) => packs[p])
3477
+ ];
2914
3478
  }
2915
3479
  function applyConfig(raw, config) {
2916
3480
  const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
@@ -2958,7 +3522,8 @@ function formatReport(result) {
2958
3522
  lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
2959
3523
  }
2960
3524
  lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
2961
- lines.push(result.ok ? `PASS (${result.warnings} warnings)` : `FAIL (${result.errors} errors, ${result.warnings} warnings)`);
3525
+ const info = result.infos ? `, ${result.infos} info` : "";
3526
+ lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
2962
3527
  return lines.join("\n");
2963
3528
  }
2964
3529