@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/vite.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as path3 from 'path';
2
2
  import { spawnSync } from 'child_process';
3
- import { existsSync, readFileSync, statSync, readdirSync } from 'fs';
3
+ import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
4
4
  import { createRequire } from 'module';
5
5
  import { pathToFileURL } from 'url';
6
6
 
@@ -99,7 +99,7 @@ var PRIVACY_PURPOSES = {
99
99
  "third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
100
100
  other: "NSPrivacyCollectedDataTypePurposeOther"
101
101
  };
102
- var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
102
+ var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
103
103
  var STRINGS = ["uiPackage", "rulesDoc"];
104
104
  var KNOWN = /* @__PURE__ */ new Set([
105
105
  ...STRING_LISTS,
@@ -114,10 +114,11 @@ var KNOWN = /* @__PURE__ */ new Set([
114
114
  "packs",
115
115
  "native",
116
116
  "supabase",
117
+ "routesDir",
117
118
  "$schema",
118
119
  "$comment"
119
120
  ]);
120
- var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
121
+ var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
121
122
  var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
122
123
  var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
123
124
  var PACK_KEYS = {
@@ -176,7 +177,7 @@ function validatePrivacy(raw, source = "config") {
176
177
  };
177
178
  if (!isObject(raw)) fail(`"privacy" must be an object`);
178
179
  const c = raw;
179
- for (const key of Object.keys(c)) if (!PRIVACY_KEYS.has(key)) fail(`privacy: unknown setting "${key}"`);
180
+ for (const key2 of Object.keys(c)) if (!PRIVACY_KEYS.has(key2)) fail(`privacy: unknown setting "${key2}"`);
180
181
  const out = {};
181
182
  if (c.blocks !== void 0) {
182
183
  if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
@@ -191,7 +192,7 @@ function validatePrivacy(raw, source = "config") {
191
192
  out.collects = c.collects.map((entry, i) => {
192
193
  const where = `privacy.collects[${i}]`;
193
194
  if (!isObject(entry)) return fail(`${where} must be an object`);
194
- for (const key of Object.keys(entry)) if (!DATA_USE_KEYS.has(key)) fail(`${where}: unknown setting "${key}"`);
195
+ for (const key2 of Object.keys(entry)) if (!DATA_USE_KEYS.has(key2)) fail(`${where}: unknown setting "${key2}"`);
195
196
  if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
196
197
  fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
197
198
  }
@@ -214,7 +215,7 @@ function validateLinks(raw, source = "config") {
214
215
  };
215
216
  if (!isObject(raw)) fail(`"links" must be an object`);
216
217
  const c = raw;
217
- for (const key of Object.keys(c)) if (!LINK_KEYS.has(key)) fail(`links: unknown setting "${key}"`);
218
+ for (const key2 of Object.keys(c)) if (!LINK_KEYS.has(key2)) fail(`links: unknown setting "${key2}"`);
218
219
  if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
219
220
  for (const host of c.hosts) {
220
221
  if (!HOST.test(host)) {
@@ -241,15 +242,16 @@ function validateConfig(raw, source = "config") {
241
242
  };
242
243
  if (!isObject(raw)) fail("the doctor settings must be an object");
243
244
  const c = raw;
244
- for (const key of Object.keys(c)) if (!KNOWN.has(key)) fail(`unknown setting "${key}"`);
245
+ for (const key2 of Object.keys(c)) if (!KNOWN.has(key2)) fail(`unknown setting "${key2}"`);
245
246
  if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
246
247
  if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
247
- for (const key of STRING_LISTS) {
248
- if (c[key] !== void 0 && !isStringList(c[key])) fail(`"${key}" must be a list of strings`);
248
+ for (const key2 of STRING_LISTS) {
249
+ if (c[key2] !== void 0 && !isStringList(c[key2])) fail(`"${key2}" must be a list of strings`);
249
250
  }
250
- for (const key of STRINGS) {
251
- if (c[key] !== void 0 && typeof c[key] !== "string") fail(`"${key}" must be a string`);
251
+ for (const key2 of STRINGS) {
252
+ if (c[key2] !== void 0 && typeof c[key2] !== "string") fail(`"${key2}" must be a string`);
252
253
  }
254
+ if (c.routesDir !== void 0) c.routesDir = appPath(c.routesDir, `"routesDir"`, fail);
253
255
  if (c.rawTags !== void 0) {
254
256
  if (!isObject(c.rawTags)) fail(`"rawTags" must be an object`);
255
257
  for (const [tag, v] of Object.entries(c.rawTags)) {
@@ -267,7 +269,7 @@ function validateConfig(raw, source = "config") {
267
269
  if (c.rules !== void 0) {
268
270
  if (!isObject(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
269
271
  for (const [rule, level] of Object.entries(c.rules)) {
270
- if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
272
+ if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn", "info" or "off"`);
271
273
  }
272
274
  }
273
275
  if (c.allow !== void 0) {
@@ -360,11 +362,12 @@ function globToRegExp(glob) {
360
362
  }
361
363
  function globMatcher(globs) {
362
364
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
363
- return (path14) => res.some((re) => re.test(path14));
365
+ return (path17) => res.some((re) => re.test(path17));
364
366
  }
365
367
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
366
368
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
367
369
  var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
370
+ var DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
368
371
  var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
369
372
  var TAG_ALIASES = { hr: "Separator" };
370
373
  var NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
@@ -435,9 +438,23 @@ function loadGenesis(root, config) {
435
438
  components,
436
439
  tokens,
437
440
  rawTags,
438
- palette: loadPalette(root)
441
+ palette: loadPalette(root),
442
+ companions: loadCompanions(root, config, uiPackage)
439
443
  };
440
444
  }
445
+ function loadCompanions(root, config, uiPackage) {
446
+ const out = [];
447
+ for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
448
+ if (name === uiPackage) continue;
449
+ try {
450
+ const pkg = readPackageExports(root, name);
451
+ if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
452
+ } catch (err) {
453
+ if (!(err instanceof DoctorConfigError)) throw err;
454
+ }
455
+ }
456
+ return out;
457
+ }
441
458
  function readPackageExports(root, uiPackage) {
442
459
  const uiDir = findPackageDir(root, uiPackage);
443
460
  if (!uiDir) return null;
@@ -507,8 +524,8 @@ function exportTypes(target) {
507
524
  if (!target || typeof target !== "object") return void 0;
508
525
  const t = target;
509
526
  if (typeof t.types === "string") return t.types;
510
- for (const key of ["import", "default", "require"]) {
511
- const nested = exportTypes(t[key]);
527
+ for (const key2 of ["import", "default", "require"]) {
528
+ const nested = exportTypes(t[key2]);
512
529
  if (nested) return nested;
513
530
  }
514
531
  return void 0;
@@ -564,8 +581,8 @@ function loadPalette(root) {
564
581
  try {
565
582
  const req = createRequire(path3.join(root, "package.json"));
566
583
  const colors = req("tailwindcss/colors");
567
- for (const key of Object.keys(colors?.default ?? colors ?? {})) {
568
- if (/^[a-z]+$/.test(key) && !["inherit", "current", "transparent"].includes(key)) names.add(key);
584
+ for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
585
+ if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
569
586
  }
570
587
  } catch {
571
588
  }
@@ -803,11 +820,11 @@ function parseRulesMarkdown(markdown) {
803
820
  }
804
821
  const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message):\s*(.*)$/);
805
822
  if (!current || !kv) continue;
806
- const [, key, raw] = kv;
823
+ const [, key2, raw] = kv;
807
824
  const value = raw.trim();
808
- if (key === "files" || key === "exclude") current[key] = value.split(",").map((s) => s.trim()).filter(Boolean);
809
- else if (key === "level") current.level = value;
810
- else current[key] = value;
825
+ if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
826
+ else if (key2 === "level") current.level = value;
827
+ else current[key2] = value;
811
828
  }
812
829
  return rules;
813
830
  }
@@ -822,8 +839,8 @@ function compilePatternRules(rules, source) {
822
839
  if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
823
840
  ids.add(rule.id);
824
841
  const level = rule.level ?? "error";
825
- if (!["error", "warn", "guide"].includes(level)) {
826
- throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn or guide)`);
842
+ if (!["error", "warn", "info", "guide"].includes(level)) {
843
+ throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
827
844
  }
828
845
  if (level === "guide") continue;
829
846
  if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
@@ -926,6 +943,15 @@ var BUILTIN_RULES = [
926
943
  "undefined-token",
927
944
  "shadowed-export",
928
945
  "version-skew",
946
+ "duplicate-genesis-package",
947
+ "peer-range-mismatch",
948
+ // structure
949
+ "hand-rolled-sub-nav",
950
+ "local-genesis-copy",
951
+ "resource-workspace",
952
+ "page-layout",
953
+ // dates
954
+ "iso-date-slice",
929
955
  // native pack
930
956
  "native-raw-primitive",
931
957
  "native-literal-color",
@@ -936,7 +962,8 @@ var BUILTIN_RULES = [
936
962
  "migration-grants",
937
963
  "migration-rls",
938
964
  "migration-definer-search-path",
939
- "migration-edited"
965
+ "migration-edited",
966
+ "migration-testing-kit"
940
967
  ];
941
968
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
942
969
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -1152,11 +1179,105 @@ var appFunctionality = (type, ...more) => ({
1152
1179
  function privacyApisFor(dependencies2) {
1153
1180
  return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
1154
1181
  }
1155
-
1156
- // src/doctor/native.ts
1157
1182
  var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
1158
1183
  var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
1159
1184
  var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
1185
+ function localImports(root, file) {
1186
+ const out = [];
1187
+ for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
1188
+ const spec = m[1];
1189
+ const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
1190
+ for (const base of bases) {
1191
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
1192
+ (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
1193
+ );
1194
+ if (hit) {
1195
+ out.push(hit);
1196
+ break;
1197
+ }
1198
+ }
1199
+ }
1200
+ return out;
1201
+ }
1202
+ function readSource(abs) {
1203
+ try {
1204
+ return { absolutePath: abs, code: readFileSync(abs, "utf8") };
1205
+ } catch {
1206
+ return null;
1207
+ }
1208
+ }
1209
+ function viaOneImport(root, files, file, test2) {
1210
+ if (test2(file.code)) return true;
1211
+ const byPath = new Map(files.map((f) => [f.absolutePath, f]));
1212
+ return localImports(root, file).some((abs) => {
1213
+ const target = byPath.get(abs) ?? readSource(abs);
1214
+ return target !== null && test2(target.code);
1215
+ });
1216
+ }
1217
+ function tagEnd(code, start) {
1218
+ let depth = 0;
1219
+ let quote = null;
1220
+ for (let i = start + 1; i < code.length; i++) {
1221
+ const ch = code[i];
1222
+ if (quote) {
1223
+ if (ch === "\\") i++;
1224
+ else if (ch === quote) quote = null;
1225
+ continue;
1226
+ }
1227
+ if (ch === '"' || ch === "'" || ch === "`") quote = ch;
1228
+ else if (ch === "{") depth++;
1229
+ else if (ch === "}") depth--;
1230
+ else if (ch === ">" && depth === 0) {
1231
+ let j = i - 1;
1232
+ while (j > start && /\s/.test(code[j])) j--;
1233
+ return { end: i + 1, selfClosing: code[j] === "/" };
1234
+ }
1235
+ }
1236
+ return { end: code.length, selfClosing: false };
1237
+ }
1238
+ function openElementsAt(code, index, track) {
1239
+ const open = [];
1240
+ const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
1241
+ for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
1242
+ const name = m[2];
1243
+ if (!track(name)) continue;
1244
+ if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
1245
+ if (m[1]) {
1246
+ const at = open.lastIndexOf(name);
1247
+ if (at !== -1) open.splice(at, 1);
1248
+ continue;
1249
+ }
1250
+ const { end, selfClosing } = tagEnd(code, m.index);
1251
+ if (end > index) break;
1252
+ if (!selfClosing) open.push(name);
1253
+ }
1254
+ return open;
1255
+ }
1256
+ function renderedElements(code) {
1257
+ const out = [];
1258
+ for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
1259
+ return out;
1260
+ }
1261
+ function rendersJsx(code) {
1262
+ return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
1263
+ }
1264
+ function namedImportsFrom(code, pkg) {
1265
+ const out = [];
1266
+ for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
1267
+ if (!pkg.test(m[2])) continue;
1268
+ for (const part of m[1].split(",")) {
1269
+ const p = part.trim();
1270
+ if (!p || p.startsWith("type ")) continue;
1271
+ const local = p.split(/\s+as\s+/).pop()?.trim();
1272
+ if (local) out.push(local);
1273
+ }
1274
+ }
1275
+ return out;
1276
+ }
1277
+
1278
+ // src/doctor/native.ts
1279
+ var SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
1280
+ var JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
1160
1281
  var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
1161
1282
  var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
1162
1283
  var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
@@ -1191,7 +1312,7 @@ function checkRawPrimitives(ctx, pkg) {
1191
1312
  ];
1192
1313
  const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
1193
1314
  for (const file of ctx.files) {
1194
- if (!SCRIPT_EXTS2.has(file.ext)) continue;
1315
+ if (!SCRIPT_EXTS3.has(file.ext)) continue;
1195
1316
  const code = file.code;
1196
1317
  const report = (name, at) => {
1197
1318
  const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
@@ -1237,7 +1358,7 @@ function checkCustomHeaders(ctx, pkg) {
1237
1358
  const reported = /* @__PURE__ */ new Set();
1238
1359
  const hidingLayouts = /* @__PURE__ */ new Map();
1239
1360
  for (const file of ctx.files) {
1240
- if (!JSX_EXTS2.has(file.ext)) continue;
1361
+ if (!JSX_EXTS3.has(file.ext)) continue;
1241
1362
  const code = file.code;
1242
1363
  const hidden = HIDES_HEADER.exec(code);
1243
1364
  if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
@@ -1267,7 +1388,7 @@ function checkCustomHeaders(ctx, pkg) {
1267
1388
  }
1268
1389
  }
1269
1390
  for (const file of ctx.files) {
1270
- if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
1391
+ if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
1271
1392
  const layout = hidingLayouts.get(path3.posix.dirname(file.path));
1272
1393
  const own = layout ? ownHeader(file.code, pkg) : null;
1273
1394
  if (!layout || !own) continue;
@@ -1306,7 +1427,7 @@ function checkScreenLayouts(ctx, pkg) {
1306
1427
  const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
1307
1428
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
1308
1429
  for (const file of routes) {
1309
- if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
1430
+ if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
1310
1431
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
1311
1432
  if (renders.test(file.code)) continue;
1312
1433
  const viaImport = localImports(ctx.root, file).some((abs) => {
@@ -1322,30 +1443,6 @@ function checkScreenLayouts(ctx, pkg) {
1322
1443
  });
1323
1444
  }
1324
1445
  }
1325
- function localImports(root, file) {
1326
- const out = [];
1327
- for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
1328
- const spec = m[1];
1329
- const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
1330
- for (const base of bases) {
1331
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
1332
- (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
1333
- );
1334
- if (hit) {
1335
- out.push(hit);
1336
- break;
1337
- }
1338
- }
1339
- }
1340
- return out;
1341
- }
1342
- function readSource(abs) {
1343
- try {
1344
- return { code: readFileSync(abs, "utf8") };
1345
- } catch {
1346
- return null;
1347
- }
1348
- }
1349
1446
  var PERMISSIONS = [
1350
1447
  { module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
1351
1448
  { module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
@@ -1468,14 +1565,14 @@ function checkStoreReadiness(ctx) {
1468
1565
  });
1469
1566
  if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
1470
1567
  }
1471
- for (const [key, modules] of generic) {
1472
- const opt = PERMISSIONS.find((p) => p.key === key).option;
1568
+ for (const [key2, modules] of generic) {
1569
+ const opt = PERMISSIONS.find((p) => p.key === key2).option;
1473
1570
  ctx.report({
1474
1571
  rule: "store-readiness",
1475
1572
  level: "warn",
1476
1573
  file,
1477
- subject: key,
1478
- 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`
1574
+ subject: key2,
1575
+ 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`
1479
1576
  });
1480
1577
  }
1481
1578
  const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
@@ -1704,6 +1801,20 @@ function checkSupabasePack(ctx) {
1704
1801
  }
1705
1802
  checkRls(ctx, migrations, exposed);
1706
1803
  checkDefinerSearchPath(ctx, migrations);
1804
+ checkTestingKit(ctx, migrations);
1805
+ }
1806
+ function checkTestingKit(ctx, migrations) {
1807
+ for (const { file, statements } of migrations) {
1808
+ const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
1809
+ if (!hit) continue;
1810
+ ctx.report({
1811
+ rule: "migration-testing-kit",
1812
+ file,
1813
+ line: hit.line,
1814
+ subject: "genesis_testing",
1815
+ message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
1816
+ });
1817
+ }
1707
1818
  }
1708
1819
  function granteesOf(s) {
1709
1820
  return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
@@ -1832,8 +1943,8 @@ function checkDefinerSearchPath(ctx, migrations) {
1832
1943
  for (const { sql, line } of statements) {
1833
1944
  const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
1834
1945
  if (create) {
1835
- const [key] = keysFor(sql, create[0].length, qualify(create[1]));
1836
- fns.set(key, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
1946
+ const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
1947
+ fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
1837
1948
  continue;
1838
1949
  }
1839
1950
  const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
@@ -1842,13 +1953,13 @@ function checkDefinerSearchPath(ctx, migrations) {
1842
1953
  const keys = keysFor(sql, alter[0].length, fnName);
1843
1954
  const rename = / rename to ([\w$]+)$/.exec(sql);
1844
1955
  const move = / set schema ([\w$]+)$/.exec(sql);
1845
- for (const key of keys) {
1846
- const state = fns.get(key);
1956
+ for (const key2 of keys) {
1957
+ const state = fns.get(key2);
1847
1958
  if (rename || move) {
1848
1959
  if (!state) continue;
1849
- fns.delete(key);
1960
+ fns.delete(key2);
1850
1961
  const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
1851
- fns.set(newName + key.slice(fnName.length), state);
1962
+ fns.set(newName + key2.slice(fnName.length), state);
1852
1963
  continue;
1853
1964
  }
1854
1965
  const next = state ?? { definer: false, searchPath: false, file, line };
@@ -1856,7 +1967,7 @@ function checkDefinerSearchPath(ctx, migrations) {
1856
1967
  if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
1857
1968
  if (/\bset search_path\b/.test(sql)) next.searchPath = true;
1858
1969
  if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
1859
- fns.set(key, next);
1970
+ fns.set(key2, next);
1860
1971
  }
1861
1972
  continue;
1862
1973
  }
@@ -1864,19 +1975,19 @@ function checkDefinerSearchPath(ctx, migrations) {
1864
1975
  if (drop) {
1865
1976
  for (const part of splitTop(drop[1])) {
1866
1977
  const m = /^([\w$.]+)\s*/.exec(part);
1867
- if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
1978
+ if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
1868
1979
  }
1869
1980
  }
1870
1981
  }
1871
1982
  }
1872
- for (const [key, at] of fns) {
1983
+ for (const [key2, at] of fns) {
1873
1984
  if (!at.definer || at.searchPath) continue;
1874
1985
  ctx.report({
1875
1986
  rule: "migration-definer-search-path",
1876
1987
  file: at.file,
1877
1988
  line: at.line,
1878
- subject: key,
1879
- 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`
1989
+ subject: key2,
1990
+ 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`
1880
1991
  });
1881
1992
  }
1882
1993
  }
@@ -1905,6 +2016,445 @@ function checkVersionSkew(ctx) {
1905
2016
  }
1906
2017
  }
1907
2018
 
2019
+ // src/doctor/semver.ts
2020
+ var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2021
+ function parseVersion(v) {
2022
+ const m = VERSION.exec(v.trim());
2023
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2024
+ }
2025
+ function compareVersions(a, b) {
2026
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2027
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2028
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2029
+ const x = a.pre[i];
2030
+ const y = b.pre[i];
2031
+ if (x === void 0) return -1;
2032
+ if (y === void 0) return 1;
2033
+ if (x === y) continue;
2034
+ const nx = /^\d+$/.test(x);
2035
+ const ny = /^\d+$/.test(y);
2036
+ if (nx && ny) return +x < +y ? -1 : 1;
2037
+ if (nx !== ny) return nx ? -1 : 1;
2038
+ return x < y ? -1 : 1;
2039
+ }
2040
+ return 0;
2041
+ }
2042
+ function partial(s) {
2043
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2044
+ if (!m) return null;
2045
+ const nums = [];
2046
+ let wild = false;
2047
+ for (const part of [m[1], m[2], m[3]]) {
2048
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2049
+ wild = true;
2050
+ nums.push(null);
2051
+ } else nums.push(+part);
2052
+ }
2053
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2054
+ }
2055
+ var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2056
+ function comparators(token) {
2057
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2058
+ if (!m) return null;
2059
+ const op = m[1] ?? "";
2060
+ const p = partial(m[2]);
2061
+ if (!p) return null;
2062
+ const [major, mi, pa] = p.nums;
2063
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2064
+ const M = major;
2065
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2066
+ 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"]);
2067
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2068
+ const out = switchOp();
2069
+ if (p.pre.length) {
2070
+ for (const c of out) if (c.v === lo) c.pre = true;
2071
+ }
2072
+ return out;
2073
+ function switchOp() {
2074
+ switch (op) {
2075
+ case "^": {
2076
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2077
+ return [
2078
+ { op: ">=", v: lo },
2079
+ { op: "<", v: bound }
2080
+ ];
2081
+ }
2082
+ case "~":
2083
+ case "~>":
2084
+ return [
2085
+ { op: ">=", v: lo },
2086
+ { op: "<", v: mi === null ? next("major") : next("minor") }
2087
+ ];
2088
+ case ">":
2089
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2090
+ case ">=":
2091
+ return [{ op: ">=", v: lo }];
2092
+ case "<":
2093
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2094
+ case "<=":
2095
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2096
+ default:
2097
+ return upper ? [
2098
+ { op: ">=", v: lo },
2099
+ { op: "<", v: upper }
2100
+ ] : [{ op: "=", v: lo }];
2101
+ }
2102
+ }
2103
+ }
2104
+ function test(c, v) {
2105
+ const d = compareVersions(v, c.v);
2106
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2107
+ }
2108
+ function parseRange(range) {
2109
+ const alts = [];
2110
+ for (const raw of range.trim().split("||")) {
2111
+ const alt = raw.trim();
2112
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2113
+ if (hyphen) {
2114
+ const from = comparators(`>=${hyphen[1]}`);
2115
+ const to = comparators(`<=${hyphen[2]}`);
2116
+ if (!from || !to) return null;
2117
+ alts.push([...from, ...to]);
2118
+ continue;
2119
+ }
2120
+ const set = [];
2121
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
2122
+ const cs = comparators(token);
2123
+ if (!cs) return null;
2124
+ set.push(...cs);
2125
+ }
2126
+ alts.push(set);
2127
+ }
2128
+ return alts;
2129
+ }
2130
+ function satisfies(version, range) {
2131
+ const v = parseVersion(version);
2132
+ const alts = parseRange(range);
2133
+ if (!v || !alts) return null;
2134
+ return alts.some(
2135
+ (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))
2136
+ );
2137
+ }
2138
+
2139
+ // src/doctor/installs.ts
2140
+ var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
2141
+ var readManifest = (dir) => {
2142
+ try {
2143
+ return JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8"));
2144
+ } catch {
2145
+ return null;
2146
+ }
2147
+ };
2148
+ var real = (p) => {
2149
+ try {
2150
+ return realpathSync(p);
2151
+ } catch {
2152
+ return p;
2153
+ }
2154
+ };
2155
+ function packagesIn(nodeModules) {
2156
+ if (!existsSync(nodeModules)) return [];
2157
+ const out = [];
2158
+ for (const entry of readdirSync(nodeModules)) {
2159
+ if (entry.startsWith(".")) continue;
2160
+ const p = path3.join(nodeModules, entry);
2161
+ if (entry.startsWith("@")) {
2162
+ try {
2163
+ for (const sub of readdirSync(p)) out.push(path3.join(p, sub));
2164
+ } catch {
2165
+ }
2166
+ } else {
2167
+ out.push(p);
2168
+ }
2169
+ }
2170
+ return out;
2171
+ }
2172
+ function genesisInstalls(root) {
2173
+ const copies = /* @__PURE__ */ new Map();
2174
+ const realRoot = real(root);
2175
+ const rel = (abs) => path3.relative(realRoot, abs).split(path3.sep).join("/") || ".";
2176
+ const record = (real2, manifest, by, range) => {
2177
+ let copy = copies.get(real2);
2178
+ if (!copy) {
2179
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
2180
+ copies.set(real2, copy);
2181
+ }
2182
+ if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
2183
+ };
2184
+ const expanded = /* @__PURE__ */ new Set();
2185
+ const queue = [];
2186
+ const visit = (dir, by, range) => {
2187
+ const manifest = readManifest(dir);
2188
+ if (!manifest?.name) return;
2189
+ const realDir = real(dir);
2190
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range);
2191
+ if (expanded.has(realDir)) return;
2192
+ expanded.add(realDir);
2193
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
2194
+ };
2195
+ const app = readManifest(root);
2196
+ const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
2197
+ for (const name of Object.keys(appDeps)) {
2198
+ const dir = findPackageDir(root, name);
2199
+ if (dir) visit(dir, "the app", appDeps[name]);
2200
+ }
2201
+ const top = path3.join(root, "node_modules");
2202
+ for (const dir of packagesIn(top)) {
2203
+ const name = path3.relative(top, dir).split(path3.sep).join("/");
2204
+ if (!(name in appDeps)) visit(dir, "hoisted, not a direct dependency", void 0);
2205
+ }
2206
+ while (queue.length) {
2207
+ const { real: from, manifest, label } = queue.shift();
2208
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
2209
+ for (const [name, range] of Object.entries(deps)) {
2210
+ const dir = findPackageDir(from, name);
2211
+ if (dir) visit(dir, label, range);
2212
+ }
2213
+ }
2214
+ const byName = /* @__PURE__ */ new Map();
2215
+ for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
2216
+ for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
2217
+ return byName;
2218
+ }
2219
+ function checkDuplicatePackages(ctx) {
2220
+ for (const [name, copies] of genesisInstalls(ctx.root)) {
2221
+ if (copies.length < 2) continue;
2222
+ const where = copies.map((c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`).join(", ");
2223
+ ctx.report({
2224
+ rule: "duplicate-genesis-package",
2225
+ level: "warn",
2226
+ file: "package.json",
2227
+ subject: name,
2228
+ 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`
2229
+ });
2230
+ }
2231
+ }
2232
+ function checkPeerRanges(ctx) {
2233
+ const rel = (abs) => path3.relative(ctx.root, abs).split(path3.sep).join("/");
2234
+ for (const copies of genesisInstalls(ctx.root).values()) {
2235
+ for (const copy of copies) {
2236
+ const dir = copy.absolutePath;
2237
+ const peers = readManifest(dir)?.peerDependencies ?? {};
2238
+ for (const [peer, range] of Object.entries(peers)) {
2239
+ if (!GENESIS.test(peer)) continue;
2240
+ const peerDir = findPackageDir(dir, peer);
2241
+ const installed = peerDir && readManifest(peerDir)?.version;
2242
+ if (!peerDir || !installed) continue;
2243
+ if (satisfies(installed, range) !== false) continue;
2244
+ ctx.report({
2245
+ rule: "peer-range-mismatch",
2246
+ level: "warn",
2247
+ file: "package.json",
2248
+ subject: `${copy.name}>${peer}`,
2249
+ 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}`
2250
+ });
2251
+ }
2252
+ }
2253
+ }
2254
+ }
2255
+ var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
2256
+ var LAYOUT_STEMS = /* @__PURE__ */ new Set(["route", "layout", "_layout", "__root", "_app"]);
2257
+ var INDEX_STEMS = /* @__PURE__ */ new Set(["index", "page"]);
2258
+ var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
2259
+ var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
2260
+ function routesDir(ctx) {
2261
+ if (ctx.config.routesDir) return ctx.config.routesDir;
2262
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path3.join(ctx.root, d))) ?? null;
2263
+ }
2264
+ var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
2265
+ function webRoutes(ctx) {
2266
+ const dir = routesDir(ctx);
2267
+ if (!dir) return [];
2268
+ const routes = [];
2269
+ for (const file of ctx.files) {
2270
+ if (!JSX_EXTS2.has(file.ext) || !file.path.startsWith(`${dir}/`)) continue;
2271
+ const rel = file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "");
2272
+ const parts = rel.split("/");
2273
+ if (parts.some((p) => p.startsWith("-"))) continue;
2274
+ const stem = parts.pop();
2275
+ const segments = [...parts, ...LAYOUT_STEMS.has(stem) || INDEX_STEMS.has(stem) ? [] : stem.split(".")];
2276
+ let index = INDEX_STEMS.has(stem);
2277
+ if (!index && !LAYOUT_STEMS.has(stem) && INDEX_STEMS.has(segments.at(-1) ?? "")) {
2278
+ segments.pop();
2279
+ index = true;
2280
+ }
2281
+ const elements = renderedElements(file.code);
2282
+ const layout = LAYOUT_STEMS.has(stem) || elements.includes("Outlet");
2283
+ routes.push({
2284
+ file,
2285
+ segments,
2286
+ index,
2287
+ layout,
2288
+ detail: !index && !layout && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
2289
+ redirectOnly: elements.every((e) => NON_PAGE_ELEMENTS.has(e)) && !HTML_ELEMENT.test(file.code),
2290
+ parents: []
2291
+ });
2292
+ }
2293
+ for (const r of routes) {
2294
+ const own = r.segments;
2295
+ for (const p of routes) {
2296
+ if (p === r || !p.layout) continue;
2297
+ const n = p.segments.length;
2298
+ if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
2299
+ if (key(own.slice(0, n)) !== key(p.segments)) continue;
2300
+ if (n > 0 && own[n - 1].endsWith("_") && !p.segments[n - 1].endsWith("_")) continue;
2301
+ r.parents.push(p);
2302
+ }
2303
+ r.parents.sort((a, b) => b.segments.length - a.segments.length);
2304
+ }
2305
+ return routes;
2306
+ }
2307
+
2308
+ // src/doctor/structure.ts
2309
+ var SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
2310
+ var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
2311
+ var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
2312
+ var SHELL = /<AppShell(?=[\s>/])/;
2313
+ var GENESIS_PACKAGE = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
2314
+ var PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
2315
+ var PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
2316
+ var isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
2317
+ var rendersRe = (names) => {
2318
+ const list = [...names];
2319
+ return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
2320
+ };
2321
+ function insideShell(ctx, routes) {
2322
+ const shell = new Set(routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => SHELL.test(code))));
2323
+ const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
2324
+ return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
2325
+ }
2326
+ function checkHandRolledSubNav(ctx) {
2327
+ if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
2328
+ const routes = webRoutes(ctx);
2329
+ if (routes.length === 0) return;
2330
+ const inShell = insideShell(ctx, routes);
2331
+ const ui = ctx.genesis.uiPackage;
2332
+ for (const r of routes) {
2333
+ if (!inShell(r)) continue;
2334
+ const code = r.file.code;
2335
+ if (/\buseAppShellSubNav\s*\(/.test(code)) continue;
2336
+ for (const m of code.matchAll(SWITCHER)) {
2337
+ if (openElementsAt(code, m.index, (n) => CONTAINER.test(n)).length > 0) continue;
2338
+ ctx.report({
2339
+ rule: "hand-rolled-sub-nav",
2340
+ level: "warn",
2341
+ file: r.file.path,
2342
+ line: lineAt(code, m.index),
2343
+ subject: m[1],
2344
+ 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}`
2345
+ });
2346
+ break;
2347
+ }
2348
+ }
2349
+ }
2350
+ function checkLocalGenesisCopies(ctx) {
2351
+ const owner = /* @__PURE__ */ new Map();
2352
+ for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
2353
+ for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
2354
+ if (owner.size === 0) return;
2355
+ const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
2356
+ const routes = routesDir(ctx);
2357
+ for (const file of ctx.files) {
2358
+ if (!JSX_EXTS2.has(file.ext)) continue;
2359
+ const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE));
2360
+ const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
2361
+ const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
2362
+ const decls = [...file.code.matchAll(decl)];
2363
+ decls.forEach((m, i) => {
2364
+ const [, exported, name] = m;
2365
+ const pkg = owner.get(name);
2366
+ if (!pkg || imported.has(name) || routeComponents.has(name)) return;
2367
+ if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
2368
+ const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
2369
+ if (!rendersJsx(body)) return;
2370
+ if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
2371
+ const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
2372
+ if (/["']@marktiderman\/genesis/.test(init)) return;
2373
+ ctx.report({
2374
+ rule: "local-genesis-copy",
2375
+ level: "warn",
2376
+ file: file.path,
2377
+ line: lineAt(file.code, m.index),
2378
+ subject: name,
2379
+ message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
2380
+ });
2381
+ });
2382
+ }
2383
+ }
2384
+ function checkResourceWorkspaces(ctx) {
2385
+ if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
2386
+ const header = /<AppShellPageHeader(?=[\s>/])/;
2387
+ const byFolder = /* @__PURE__ */ new Map();
2388
+ for (const r of webRoutes(ctx)) {
2389
+ if (!r.detail || r.redirectOnly) continue;
2390
+ const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
2391
+ byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
2392
+ }
2393
+ for (const [dir, routes] of byFolder) {
2394
+ const has = routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => header.test(code)));
2395
+ if (has.length === 0) continue;
2396
+ const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
2397
+ for (const r of routes) {
2398
+ if (has.includes(r)) continue;
2399
+ ctx.report({
2400
+ rule: "resource-workspace",
2401
+ level: "info",
2402
+ file: r.file.path,
2403
+ 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`
2404
+ });
2405
+ }
2406
+ }
2407
+ }
2408
+ function checkPageLayouts(ctx) {
2409
+ if (isNative(ctx)) return;
2410
+ const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
2411
+ for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
2412
+ if (layouts.size === 0) return;
2413
+ const routes = webRoutes(ctx);
2414
+ const inShell = insideShell(ctx, routes);
2415
+ const rendersLayout = (code) => {
2416
+ const names = new Set(layouts);
2417
+ for (const n of namedImportsFrom(code, GENESIS_PACKAGE)) if (PACKAGE_SCREEN.test(n)) names.add(n);
2418
+ return rendersRe(names)?.test(code) ?? false;
2419
+ };
2420
+ const cache = /* @__PURE__ */ new Map();
2421
+ const provides = (r) => {
2422
+ if (!cache.has(r)) cache.set(r, viaOneImport(ctx.root, ctx.files, r.file, rendersLayout));
2423
+ return cache.get(r);
2424
+ };
2425
+ const list = [...layouts].sort();
2426
+ const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
2427
+ for (const r of routes) {
2428
+ if (r.layout || r.redirectOnly || !inShell(r)) continue;
2429
+ if (provides(r) || r.parents.some(provides)) continue;
2430
+ ctx.report({
2431
+ rule: "page-layout",
2432
+ level: "warn",
2433
+ file: r.file.path,
2434
+ 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`
2435
+ });
2436
+ }
2437
+ }
2438
+
2439
+ // src/doctor/dates.ts
2440
+ var SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2441
+ 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;
2442
+ function checkIsoDateSlices(ctx) {
2443
+ for (const file of ctx.files) {
2444
+ if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
2445
+ for (const m of file.code.matchAll(ISO_DAY_CUT)) {
2446
+ ctx.report({
2447
+ rule: "iso-date-slice",
2448
+ level: "warn",
2449
+ file: file.path,
2450
+ line: lineAt(file.code, m.index ?? 0),
2451
+ subject: "toISOString",
2452
+ 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)"
2453
+ });
2454
+ }
2455
+ }
2456
+ }
2457
+
1908
2458
  // src/doctor/index.ts
1909
2459
  async function runDoctor(options = {}) {
1910
2460
  const root = path3.resolve(options.root ?? process.cwd());
@@ -1920,18 +2470,7 @@ async function runDoctor(options = {}) {
1920
2470
  }
1921
2471
  const raw = [];
1922
2472
  const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
1923
- const builtins = [
1924
- { name: "layout", check: checkProjectLayout },
1925
- { name: "imports", check: checkImports },
1926
- { name: "raw-tags", check: checkRawTags },
1927
- { name: "colors", check: checkColors },
1928
- { name: "tokens", check: checkTokens },
1929
- { name: "shadowed-exports", check: checkShadowedExports },
1930
- { name: "version-skew", check: checkVersionSkew },
1931
- ...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
1932
- ...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
1933
- ];
1934
- for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
2473
+ for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
1935
2474
  try {
1936
2475
  await plugin.check(ctx);
1937
2476
  } catch (err) {
@@ -1945,7 +2484,8 @@ async function runDoctor(options = {}) {
1945
2484
  }
1946
2485
  const findings = applyConfig(raw, config);
1947
2486
  const errors = findings.filter((f) => f.level === "error").length;
1948
- const warnings = findings.length - errors;
2487
+ const warnings = findings.filter((f) => f.level === "warn").length;
2488
+ const infos = findings.length - errors - warnings;
1949
2489
  return {
1950
2490
  ok: errors === 0 && !(options.strict && warnings > 0),
1951
2491
  root,
@@ -1954,8 +2494,32 @@ async function runDoctor(options = {}) {
1954
2494
  unused: unusedComponents(ctx),
1955
2495
  ruleCount: (patterns?.count ?? 0) + plugins.length,
1956
2496
  errors,
1957
- warnings
2497
+ warnings,
2498
+ infos
2499
+ };
2500
+ }
2501
+ function builtinChecks(config) {
2502
+ const packs = {
2503
+ native: { name: "native", check: checkNativePack },
2504
+ supabase: { name: "supabase", check: checkSupabasePack }
1958
2505
  };
2506
+ return [
2507
+ { name: "layout", check: checkProjectLayout },
2508
+ { name: "imports", check: checkImports },
2509
+ { name: "raw-tags", check: checkRawTags },
2510
+ { name: "colors", check: checkColors },
2511
+ { name: "tokens", check: checkTokens },
2512
+ { name: "shadowed-exports", check: checkShadowedExports },
2513
+ { name: "version-skew", check: checkVersionSkew },
2514
+ { name: "duplicate-packages", check: checkDuplicatePackages },
2515
+ { name: "peer-ranges", check: checkPeerRanges },
2516
+ { name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
2517
+ { name: "local-genesis-copies", check: checkLocalGenesisCopies },
2518
+ { name: "resource-workspaces", check: checkResourceWorkspaces },
2519
+ { name: "page-layouts", check: checkPageLayouts },
2520
+ { name: "iso-date-slices", check: checkIsoDateSlices },
2521
+ ...(config.packs ?? []).map((p) => packs[p])
2522
+ ];
1959
2523
  }
1960
2524
  function applyConfig(raw, config) {
1961
2525
  const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
@@ -2003,12 +2567,13 @@ function formatReport(result) {
2003
2567
  lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
2004
2568
  }
2005
2569
  lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
2006
- lines.push(result.ok ? `PASS (${result.warnings} warnings)` : `FAIL (${result.errors} errors, ${result.warnings} warnings)`);
2570
+ const info = result.infos ? `, ${result.infos} info` : "";
2571
+ lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
2007
2572
  return lines.join("\n");
2008
2573
  }
2009
2574
 
2010
2575
  // src/vite.ts
2011
- var formatProblems = (result, withWarnings = false) => result.findings.filter((f) => f.level === "error" || withWarnings).map((f) => `${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`).join("\n");
2576
+ var formatProblems = (result, withWarnings = false) => result.findings.filter((f) => f.level === "error" || withWarnings && f.level === "warn").map((f) => `${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`).join("\n");
2012
2577
  function genesisDoctor(options = {}) {
2013
2578
  let root = options.root ?? process.cwd();
2014
2579
  return [