@marktiderman/genesis-cli 1.8.0 → 1.10.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
- import * as path3 from 'path';
1
+ import * as path14 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
 
@@ -8,19 +8,19 @@ import { pathToFileURL } from 'url';
8
8
  var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
9
9
  function buildCommands(root, config) {
10
10
  if (config.build) return config.build;
11
- const pkgFile = path3.join(root, "package.json");
11
+ const pkgFile = path14.join(root, "package.json");
12
12
  const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
13
13
  const pm = packageManager(root);
14
14
  return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
15
15
  }
16
16
  function packageManager(root) {
17
- let dir = path3.resolve(root);
17
+ let dir = path14.resolve(root);
18
18
  for (; ; ) {
19
- if (existsSync(path3.join(dir, "pnpm-lock.yaml"))) return "pnpm";
20
- if (existsSync(path3.join(dir, "bun.lock")) || existsSync(path3.join(dir, "bun.lockb"))) return "bun";
21
- if (existsSync(path3.join(dir, "yarn.lock"))) return "yarn";
22
- if (existsSync(path3.join(dir, "package-lock.json"))) return "npm";
23
- const parent = path3.dirname(dir);
19
+ if (existsSync(path14.join(dir, "pnpm-lock.yaml"))) return "pnpm";
20
+ if (existsSync(path14.join(dir, "bun.lock")) || existsSync(path14.join(dir, "bun.lockb"))) return "bun";
21
+ if (existsSync(path14.join(dir, "yarn.lock"))) return "yarn";
22
+ if (existsSync(path14.join(dir, "package-lock.json"))) return "npm";
23
+ const parent = path14.dirname(dir);
24
24
  if (parent === dir) return "npm";
25
25
  dir = parent;
26
26
  }
@@ -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 = {
@@ -126,25 +127,25 @@ var PACK_KEYS = {
126
127
  };
127
128
  function appPath(v, where, fail) {
128
129
  if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
129
- if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
130
- const norm = path3.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
130
+ if (path14.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
131
+ const norm = path14.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
131
132
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
132
133
  return norm;
133
134
  }
134
135
  function loadConfig(root, configPath) {
135
136
  if (configPath) {
136
- const file = path3.resolve(root, configPath);
137
+ const file = path14.resolve(root, configPath);
137
138
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
138
139
  const json = readJson(file);
139
- const block = path3.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
140
- return { config: validateConfig(block ?? {}, file), file, dir: path3.dirname(file) };
140
+ const block = path14.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
141
+ return { config: validateConfig(block ?? {}, file), file, dir: path14.dirname(file) };
141
142
  }
142
- const own = path3.join(root, "genesis.config.json");
143
+ const own = path14.join(root, "genesis.config.json");
143
144
  if (existsSync(own)) {
144
145
  const block = readGenesisConfig(root)?.raw.doctor;
145
146
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
146
147
  }
147
- const pkg = path3.join(root, "package.json");
148
+ const pkg = path14.join(root, "package.json");
148
149
  if (existsSync(pkg)) {
149
150
  const block = readJson(pkg)?.genesis?.doctor;
150
151
  if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -159,7 +160,7 @@ function readJson(file) {
159
160
  }
160
161
  }
161
162
  function readGenesisConfig(root) {
162
- const file = path3.join(root, "genesis.config.json");
163
+ const file = path14.join(root, "genesis.config.json");
163
164
  if (!existsSync(file)) return null;
164
165
  const raw = readJson(file);
165
166
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -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 (path18) => res.some((re) => re.test(path18));
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)$/;
@@ -399,11 +402,11 @@ var TAILWIND_PALETTE = [
399
402
  "olive"
400
403
  ];
401
404
  function findPackageDir(from, name) {
402
- let dir = path3.resolve(from);
405
+ let dir = path14.resolve(from);
403
406
  for (; ; ) {
404
- const candidate = path3.join(dir, "node_modules", name);
405
- if (existsSync(path3.join(candidate, "package.json"))) return candidate;
406
- const parent = path3.dirname(dir);
407
+ const candidate = path14.join(dir, "node_modules", name);
408
+ if (existsSync(path14.join(candidate, "package.json"))) return candidate;
409
+ const parent = path14.dirname(dir);
407
410
  if (parent === dir) return null;
408
411
  dir = parent;
409
412
  }
@@ -435,13 +438,27 @@ 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;
444
- const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
461
+ const uiPkg = JSON.parse(readFileSync(path14.join(uiDir, "package.json"), "utf8"));
445
462
  const typeEntries = /* @__PURE__ */ new Set();
446
463
  const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
447
464
  if (typeof mainTypes === "string") typeEntries.add(mainTypes);
@@ -453,7 +470,7 @@ function readPackageExports(root, uiPackage) {
453
470
  const reexportedPackages = /* @__PURE__ */ new Set();
454
471
  let readAny = false;
455
472
  for (const entry of typeEntries) {
456
- const file = path3.join(uiDir, entry);
473
+ const file = path14.join(uiDir, entry);
457
474
  if (!existsSync(file)) continue;
458
475
  readAny = true;
459
476
  const dts = readFileSync(file, "utf8");
@@ -467,11 +484,11 @@ function readPackageExports(root, uiPackage) {
467
484
  }
468
485
  const valueDecls = /* @__PURE__ */ new Set();
469
486
  const typeDecls = /* @__PURE__ */ new Set();
470
- const declRoot = typeof mainTypes === "string" ? path3.dirname(path3.join(uiDir, mainTypes)) : uiDir;
487
+ const declRoot = typeof mainTypes === "string" ? path14.dirname(path14.join(uiDir, mainTypes)) : uiDir;
471
488
  const declFiles = walkDts(declRoot);
472
489
  for (const pkg of reexportedPackages) {
473
490
  const dir = findPackageDir(uiDir, pkg);
474
- if (dir) walkDts(path3.join(dir, "dist"), declFiles);
491
+ if (dir) walkDts(path14.join(dir, "dist"), declFiles);
475
492
  }
476
493
  for (const file of declFiles) {
477
494
  const text = readFileSync(file, "utf8");
@@ -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;
@@ -517,7 +534,7 @@ function walkDts(dir, out = []) {
517
534
  if (!existsSync(dir)) return out;
518
535
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
519
536
  if (entry.name === "node_modules") continue;
520
- const p = path3.join(dir, entry.name);
537
+ const p = path14.join(dir, entry.name);
521
538
  if (entry.isDirectory()) walkDts(p, out);
522
539
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
523
540
  }
@@ -534,27 +551,27 @@ function resolveThemeFiles(root, config, uiDir) {
534
551
  }
535
552
  const files = [];
536
553
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
537
- const themes = ds && path3.join(ds, "dist", "themes");
554
+ const themes = ds && path14.join(ds, "dist", "themes");
538
555
  if (themes && existsSync(themes)) {
539
- for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path3.join(themes, name));
556
+ for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path14.join(themes, name));
540
557
  }
541
558
  if (files.length === 0) {
542
559
  throw new DoctorConfigError(
543
560
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
544
561
  );
545
562
  }
546
- const uiStyles = path3.join(uiDir, "dist", "styles.css");
563
+ const uiStyles = path14.join(uiDir, "dist", "styles.css");
547
564
  if (existsSync(uiStyles)) files.push(uiStyles);
548
565
  return files;
549
566
  }
550
567
  function resolveSpec(root, spec) {
551
- const local = path3.resolve(root, spec);
552
- if (spec.startsWith(".") || path3.isAbsolute(spec)) return existsSync(local) ? local : null;
568
+ const local = path14.resolve(root, spec);
569
+ if (spec.startsWith(".") || path14.isAbsolute(spec)) return existsSync(local) ? local : null;
553
570
  const parts = spec.split("/");
554
571
  const nameLength = spec.startsWith("@") ? 2 : 1;
555
572
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
556
573
  if (dir) {
557
- const file = path3.join(dir, ...parts.slice(nameLength));
574
+ const file = path14.join(dir, ...parts.slice(nameLength));
558
575
  if (existsSync(file) && statSync(file).isFile()) return file;
559
576
  }
560
577
  return existsSync(local) ? local : null;
@@ -562,10 +579,10 @@ function resolveSpec(root, spec) {
562
579
  function loadPalette(root) {
563
580
  const names = new Set(TAILWIND_PALETTE);
564
581
  try {
565
- const req = createRequire(path3.join(root, "package.json"));
582
+ const req = createRequire(path14.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
  }
@@ -747,16 +764,16 @@ var DEFAULT_IGNORE = [
747
764
  ];
748
765
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
749
766
  var MAX_FILE_BYTES = 2 * 1024 * 1024;
750
- var toPosix = (p) => p.split(path3.sep).join("/");
767
+ var toPosix = (p) => p.split(path14.sep).join("/");
751
768
  function scanFiles(root, config) {
752
769
  const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
753
770
  const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
754
771
  const files = [];
755
772
  const seen = /* @__PURE__ */ new Set();
756
773
  const visit = (abs) => {
757
- const rel = toPosix(path3.relative(root, abs));
774
+ const rel = toPosix(path14.relative(root, abs));
758
775
  if (seen.has(rel) || ignored(rel)) return;
759
- const ext = path3.extname(abs);
776
+ const ext = path14.extname(abs);
760
777
  if (!extensions.has(ext)) return;
761
778
  if (statSync(abs).size > MAX_FILE_BYTES) return;
762
779
  seen.add(rel);
@@ -766,14 +783,14 @@ function scanFiles(root, config) {
766
783
  const walk = (dir) => {
767
784
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
768
785
  if (entry.isDirectory()) {
769
- if (!SKIP_DIRS.has(entry.name)) walk(path3.join(dir, entry.name));
786
+ if (!SKIP_DIRS.has(entry.name)) walk(path14.join(dir, entry.name));
770
787
  } else if (entry.isFile()) {
771
- visit(path3.join(dir, entry.name));
788
+ visit(path14.join(dir, entry.name));
772
789
  }
773
790
  }
774
791
  };
775
792
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
776
- const abs = path3.resolve(root, src);
793
+ const abs = path14.resolve(root, src);
777
794
  if (!existsSync(abs)) continue;
778
795
  if (statSync(abs).isDirectory()) walk(abs);
779
796
  else visit(abs);
@@ -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)`);
@@ -850,7 +867,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
850
867
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
851
868
  let all = compiled;
852
869
  if (rulesDoc) {
853
- const file = path3.resolve(root, rulesDoc);
870
+ const file = path14.resolve(root, rulesDoc);
854
871
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
855
872
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
856
873
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -906,14 +923,14 @@ async function loadPlugins(specs, configDir) {
906
923
  }
907
924
  function resolvePlugin(id, configDir) {
908
925
  try {
909
- if (id.startsWith(".") || path3.isAbsolute(id)) return resolveFrom(path3.resolve(configDir, id), configDir);
926
+ if (id.startsWith(".") || path14.isAbsolute(id)) return resolveFrom(path14.resolve(configDir, id), configDir);
910
927
  return resolveFrom(id, configDir);
911
928
  } catch {
912
929
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
913
930
  }
914
931
  }
915
932
  function resolveFrom(id, from) {
916
- return createRequire(path3.join(from, "noop.js")).resolve(id);
933
+ return createRequire(path14.join(from, "noop.js")).resolve(id);
917
934
  }
918
935
  var BUILTIN_RULES = [
919
936
  "local-primitives",
@@ -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"];
@@ -954,7 +981,7 @@ function importSpecifiers(file) {
954
981
  }
955
982
  function checkProjectLayout(ctx) {
956
983
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
957
- if (existsSync(path3.join(ctx.root, dir))) {
984
+ if (existsSync(path14.join(ctx.root, dir))) {
958
985
  ctx.report({
959
986
  rule: "local-primitives",
960
987
  file: dir,
@@ -964,7 +991,7 @@ function checkProjectLayout(ctx) {
964
991
  }
965
992
  }
966
993
  for (const file of STARTER_LEFTOVERS) {
967
- if (existsSync(path3.join(ctx.root, file))) {
994
+ if (existsSync(path14.join(ctx.root, file))) {
968
995
  ctx.report({
969
996
  rule: "starter-leftover",
970
997
  level: "warn",
@@ -1053,7 +1080,7 @@ function checkTokens(ctx) {
1053
1080
  }
1054
1081
  for (const pattern of ctx.config.tokenFiles ?? []) {
1055
1082
  if (/[*?]/.test(pattern)) continue;
1056
- const abs = path3.join(ctx.root, pattern);
1083
+ const abs = path14.join(ctx.root, pattern);
1057
1084
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
1058
1085
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
1059
1086
  }
@@ -1152,11 +1179,97 @@ 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(".") ? [path14.resolve(path14.dirname(file.absolutePath), spec)] : [path14.join(root, spec.slice(2)), path14.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) => path14.join(base, `index${e}`))].find(
1192
+ (p) => SCRIPT_EXTS2.has(path14.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 tagEnd(code, start) {
1210
+ let depth = 0;
1211
+ let quote = null;
1212
+ for (let i = start + 1; i < code.length; i++) {
1213
+ const ch = code[i];
1214
+ if (quote) {
1215
+ if (ch === "\\") i++;
1216
+ else if (ch === quote) quote = null;
1217
+ continue;
1218
+ }
1219
+ if (ch === '"' || ch === "'" || ch === "`") quote = ch;
1220
+ else if (ch === "{") depth++;
1221
+ else if (ch === "}") depth--;
1222
+ else if (ch === ">" && depth === 0) {
1223
+ let j = i - 1;
1224
+ while (j > start && /\s/.test(code[j])) j--;
1225
+ return { end: i + 1, selfClosing: code[j] === "/" };
1226
+ }
1227
+ }
1228
+ return { end: code.length, selfClosing: false };
1229
+ }
1230
+ function openElementsAt(code, index, track) {
1231
+ const open = [];
1232
+ const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
1233
+ for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
1234
+ const name = m[2];
1235
+ if (!track(name)) continue;
1236
+ if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
1237
+ if (m[1]) {
1238
+ const at = open.lastIndexOf(name);
1239
+ if (at !== -1) open.splice(at, 1);
1240
+ continue;
1241
+ }
1242
+ const { end, selfClosing } = tagEnd(code, m.index);
1243
+ if (end > index) break;
1244
+ if (!selfClosing) open.push(name);
1245
+ }
1246
+ return open;
1247
+ }
1248
+ function renderedElements(code) {
1249
+ const out = [];
1250
+ for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
1251
+ return out;
1252
+ }
1253
+ function rendersJsx(code) {
1254
+ return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
1255
+ }
1256
+ function namedImportsFrom(code, pkg) {
1257
+ const out = [];
1258
+ for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
1259
+ if (!pkg.test(m[2])) continue;
1260
+ for (const part of m[1].split(",")) {
1261
+ const p = part.trim();
1262
+ if (!p || p.startsWith("type ")) continue;
1263
+ const local = p.split(/\s+as\s+/).pop()?.trim();
1264
+ if (local) out.push(local);
1265
+ }
1266
+ }
1267
+ return out;
1268
+ }
1269
+
1270
+ // src/doctor/native.ts
1271
+ var SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
1272
+ var JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
1160
1273
  var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
1161
1274
  var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
1162
1275
  var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
@@ -1191,7 +1304,7 @@ function checkRawPrimitives(ctx, pkg) {
1191
1304
  ];
1192
1305
  const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
1193
1306
  for (const file of ctx.files) {
1194
- if (!SCRIPT_EXTS2.has(file.ext)) continue;
1307
+ if (!SCRIPT_EXTS3.has(file.ext)) continue;
1195
1308
  const code = file.code;
1196
1309
  const report = (name, at) => {
1197
1310
  const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
@@ -1237,10 +1350,10 @@ function checkCustomHeaders(ctx, pkg) {
1237
1350
  const reported = /* @__PURE__ */ new Set();
1238
1351
  const hidingLayouts = /* @__PURE__ */ new Map();
1239
1352
  for (const file of ctx.files) {
1240
- if (!JSX_EXTS2.has(file.ext)) continue;
1353
+ if (!JSX_EXTS3.has(file.ext)) continue;
1241
1354
  const code = file.code;
1242
1355
  const hidden = HIDES_HEADER.exec(code);
1243
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
1356
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
1244
1357
  const own = hidden ? ownHeader(code, pkg) : null;
1245
1358
  if (hidden && own) {
1246
1359
  reported.add(file.path);
@@ -1267,8 +1380,8 @@ function checkCustomHeaders(ctx, pkg) {
1267
1380
  }
1268
1381
  }
1269
1382
  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;
1271
- const layout = hidingLayouts.get(path3.posix.dirname(file.path));
1383
+ if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
1384
+ const layout = hidingLayouts.get(path14.posix.dirname(file.path));
1272
1385
  const own = layout ? ownHeader(file.code, pkg) : null;
1273
1386
  if (!layout || !own) continue;
1274
1387
  ctx.report({
@@ -1283,13 +1396,13 @@ function checkCustomHeaders(ctx, pkg) {
1283
1396
  }
1284
1397
  function routerRoot(ctx) {
1285
1398
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
1286
- return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
1399
+ return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
1287
1400
  }
1288
1401
  function checkScreenLayouts(ctx, pkg) {
1289
1402
  const layouts = nativeLayouts(pkg);
1290
1403
  if (layouts.length === 0) return;
1291
1404
  const rootDir = routerRoot(ctx);
1292
- if (!existsSync(path3.join(ctx.root, rootDir))) {
1405
+ if (!existsSync(path14.join(ctx.root, rootDir))) {
1293
1406
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
1294
1407
  return;
1295
1408
  }
@@ -1303,15 +1416,15 @@ function checkScreenLayouts(ctx, pkg) {
1303
1416
  });
1304
1417
  return;
1305
1418
  }
1306
- const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
1419
+ const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
1307
1420
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
1308
1421
  for (const file of routes) {
1309
- if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
1422
+ if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
1310
1423
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
1311
- if (renders.test(file.code)) continue;
1424
+ if (renders2.test(file.code)) continue;
1312
1425
  const viaImport = localImports(ctx.root, file).some((abs) => {
1313
1426
  const target = byPath.get(abs) ?? readSource(abs);
1314
- return target !== null && renders.test(target.code);
1427
+ return target !== null && renders2.test(target.code);
1315
1428
  });
1316
1429
  if (viaImport) continue;
1317
1430
  ctx.report({
@@ -1322,30 +1435,6 @@ function checkScreenLayouts(ctx, pkg) {
1322
1435
  });
1323
1436
  }
1324
1437
  }
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
1438
  var PERMISSIONS = [
1350
1439
  { module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
1351
1440
  { module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
@@ -1368,7 +1457,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
1368
1457
  function readExpoConfigs(root) {
1369
1458
  const out = [];
1370
1459
  for (const name of EXPO_CONFIGS) {
1371
- const abs = path3.join(root, name);
1460
+ const abs = path14.join(root, name);
1372
1461
  if (!existsSync(abs)) continue;
1373
1462
  const text = readFileSync(abs, "utf8");
1374
1463
  let json = null;
@@ -1402,13 +1491,13 @@ function pluginOptions(json, module) {
1402
1491
  return null;
1403
1492
  }
1404
1493
  function dependencies(root) {
1405
- const file = path3.join(root, "package.json");
1494
+ const file = path14.join(root, "package.json");
1406
1495
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
1407
1496
  const pkg = JSON.parse(readFileSync(file, "utf8"));
1408
1497
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
1409
1498
  }
1410
1499
  function runtimeDependencies(root) {
1411
- const file = path3.join(root, "package.json");
1500
+ const file = path14.join(root, "package.json");
1412
1501
  if (!existsSync(file)) return {};
1413
1502
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
1414
1503
  }
@@ -1468,14 +1557,14 @@ function checkStoreReadiness(ctx) {
1468
1557
  });
1469
1558
  if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
1470
1559
  }
1471
- for (const [key, modules] of generic) {
1472
- const opt = PERMISSIONS.find((p) => p.key === key).option;
1560
+ for (const [key2, modules] of generic) {
1561
+ const opt = PERMISSIONS.find((p) => p.key === key2).option;
1473
1562
  ctx.report({
1474
1563
  rule: "store-readiness",
1475
1564
  level: "warn",
1476
1565
  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`
1566
+ subject: key2,
1567
+ 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
1568
  });
1480
1569
  }
1481
1570
  const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
@@ -1671,9 +1760,9 @@ function gitView(root, dir, base) {
1671
1760
  function checkSupabasePack(ctx) {
1672
1761
  const settings = ctx.config.supabase ?? {};
1673
1762
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
1674
- const abs = path3.join(ctx.root, dir);
1763
+ const abs = path14.join(ctx.root, dir);
1675
1764
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
1676
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path3.join(abs, n), "utf8")) }));
1765
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
1677
1766
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
1678
1767
  const base = settings.base ?? DEFAULT_BASE;
1679
1768
  const view = gitView(ctx.root, dir, base);
@@ -1690,7 +1779,7 @@ function checkSupabasePack(ctx) {
1690
1779
  }
1691
1780
  }
1692
1781
  const since = settings.since;
1693
- const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
1782
+ const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
1694
1783
  if ("reason" in view && since === void 0) {
1695
1784
  ctx.report({
1696
1785
  rule: "migration-grants",
@@ -1704,6 +1793,20 @@ function checkSupabasePack(ctx) {
1704
1793
  }
1705
1794
  checkRls(ctx, migrations, exposed);
1706
1795
  checkDefinerSearchPath(ctx, migrations);
1796
+ checkTestingKit(ctx, migrations);
1797
+ }
1798
+ function checkTestingKit(ctx, migrations) {
1799
+ for (const { file, statements } of migrations) {
1800
+ const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
1801
+ if (!hit) continue;
1802
+ ctx.report({
1803
+ rule: "migration-testing-kit",
1804
+ file,
1805
+ line: hit.line,
1806
+ subject: "genesis_testing",
1807
+ message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
1808
+ });
1809
+ }
1707
1810
  }
1708
1811
  function granteesOf(s) {
1709
1812
  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 +1935,8 @@ function checkDefinerSearchPath(ctx, migrations) {
1832
1935
  for (const { sql, line } of statements) {
1833
1936
  const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
1834
1937
  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 });
1938
+ const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
1939
+ fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
1837
1940
  continue;
1838
1941
  }
1839
1942
  const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
@@ -1842,13 +1945,13 @@ function checkDefinerSearchPath(ctx, migrations) {
1842
1945
  const keys = keysFor(sql, alter[0].length, fnName);
1843
1946
  const rename = / rename to ([\w$]+)$/.exec(sql);
1844
1947
  const move = / set schema ([\w$]+)$/.exec(sql);
1845
- for (const key of keys) {
1846
- const state = fns.get(key);
1948
+ for (const key2 of keys) {
1949
+ const state = fns.get(key2);
1847
1950
  if (rename || move) {
1848
1951
  if (!state) continue;
1849
- fns.delete(key);
1952
+ fns.delete(key2);
1850
1953
  const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
1851
- fns.set(newName + key.slice(fnName.length), state);
1954
+ fns.set(newName + key2.slice(fnName.length), state);
1852
1955
  continue;
1853
1956
  }
1854
1957
  const next = state ?? { definer: false, searchPath: false, file, line };
@@ -1856,7 +1959,7 @@ function checkDefinerSearchPath(ctx, migrations) {
1856
1959
  if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
1857
1960
  if (/\bset search_path\b/.test(sql)) next.searchPath = true;
1858
1961
  if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
1859
- fns.set(key, next);
1962
+ fns.set(key2, next);
1860
1963
  }
1861
1964
  continue;
1862
1965
  }
@@ -1864,26 +1967,26 @@ function checkDefinerSearchPath(ctx, migrations) {
1864
1967
  if (drop) {
1865
1968
  for (const part of splitTop(drop[1])) {
1866
1969
  const m = /^([\w$.]+)\s*/.exec(part);
1867
- if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
1970
+ if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
1868
1971
  }
1869
1972
  }
1870
1973
  }
1871
1974
  }
1872
- for (const [key, at] of fns) {
1975
+ for (const [key2, at] of fns) {
1873
1976
  if (!at.definer || at.searchPath) continue;
1874
1977
  ctx.report({
1875
1978
  rule: "migration-definer-search-path",
1876
1979
  file: at.file,
1877
1980
  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`
1981
+ subject: key2,
1982
+ 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
1983
  });
1881
1984
  }
1882
1985
  }
1883
1986
  var UMBRELLA_PACKAGE = "@marktiderman/genesis";
1884
1987
  function readReleaseManifest(root) {
1885
1988
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
1886
- const file = dir && path3.join(dir, "dist", "versions.json");
1989
+ const file = dir && path14.join(dir, "dist", "versions.json");
1887
1990
  if (!file || !existsSync(file)) return null;
1888
1991
  return JSON.parse(readFileSync(file, "utf8"));
1889
1992
  }
@@ -1893,7 +1996,7 @@ function checkVersionSkew(ctx) {
1893
1996
  for (const [name, want] of Object.entries(manifest.packages)) {
1894
1997
  const dir = findPackageDir(ctx.root, name);
1895
1998
  if (!dir) continue;
1896
- const have = JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8")).version;
1999
+ const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
1897
2000
  if (have === want) continue;
1898
2001
  ctx.report({
1899
2002
  rule: "version-skew",
@@ -1905,9 +2008,842 @@ function checkVersionSkew(ctx) {
1905
2008
  }
1906
2009
  }
1907
2010
 
2011
+ // src/doctor/semver.ts
2012
+ var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
2013
+ function parseVersion(v) {
2014
+ const m = VERSION.exec(v.trim());
2015
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
2016
+ }
2017
+ function compareVersions(a, b) {
2018
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
2019
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
2020
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
2021
+ const x = a.pre[i];
2022
+ const y = b.pre[i];
2023
+ if (x === void 0) return -1;
2024
+ if (y === void 0) return 1;
2025
+ if (x === y) continue;
2026
+ const nx = /^\d+$/.test(x);
2027
+ const ny = /^\d+$/.test(y);
2028
+ if (nx && ny) return +x < +y ? -1 : 1;
2029
+ if (nx !== ny) return nx ? -1 : 1;
2030
+ return x < y ? -1 : 1;
2031
+ }
2032
+ return 0;
2033
+ }
2034
+ function partial(s) {
2035
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
2036
+ if (!m) return null;
2037
+ const nums = [];
2038
+ let wild = false;
2039
+ for (const part of [m[1], m[2], m[3]]) {
2040
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
2041
+ wild = true;
2042
+ nums.push(null);
2043
+ } else nums.push(+part);
2044
+ }
2045
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
2046
+ }
2047
+ var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
2048
+ function comparators(token) {
2049
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
2050
+ if (!m) return null;
2051
+ const op = m[1] ?? "";
2052
+ const p = partial(m[2]);
2053
+ if (!p) return null;
2054
+ const [major, mi, pa] = p.nums;
2055
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
2056
+ const M = major;
2057
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
2058
+ 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"]);
2059
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
2060
+ const out = switchOp();
2061
+ if (p.pre.length) {
2062
+ for (const c of out) if (c.v === lo) c.pre = true;
2063
+ }
2064
+ return out;
2065
+ function switchOp() {
2066
+ switch (op) {
2067
+ case "^": {
2068
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
2069
+ return [
2070
+ { op: ">=", v: lo },
2071
+ { op: "<", v: bound }
2072
+ ];
2073
+ }
2074
+ case "~":
2075
+ case "~>":
2076
+ return [
2077
+ { op: ">=", v: lo },
2078
+ { op: "<", v: mi === null ? next("major") : next("minor") }
2079
+ ];
2080
+ case ">":
2081
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
2082
+ case ">=":
2083
+ return [{ op: ">=", v: lo }];
2084
+ case "<":
2085
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
2086
+ case "<=":
2087
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
2088
+ default:
2089
+ return upper ? [
2090
+ { op: ">=", v: lo },
2091
+ { op: "<", v: upper }
2092
+ ] : [{ op: "=", v: lo }];
2093
+ }
2094
+ }
2095
+ }
2096
+ function test(c, v) {
2097
+ const d = compareVersions(v, c.v);
2098
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
2099
+ }
2100
+ function parseRange(range) {
2101
+ const alts = [];
2102
+ for (const raw of range.trim().split("||")) {
2103
+ const alt = raw.trim();
2104
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
2105
+ if (hyphen) {
2106
+ const from = comparators(`>=${hyphen[1]}`);
2107
+ const to = comparators(`<=${hyphen[2]}`);
2108
+ if (!from || !to) return null;
2109
+ alts.push([...from, ...to]);
2110
+ continue;
2111
+ }
2112
+ const set = [];
2113
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
2114
+ const cs = comparators(token);
2115
+ if (!cs) return null;
2116
+ set.push(...cs);
2117
+ }
2118
+ alts.push(set);
2119
+ }
2120
+ return alts;
2121
+ }
2122
+ function satisfies(version, range) {
2123
+ const v = parseVersion(version);
2124
+ const alts = parseRange(range);
2125
+ if (!v || !alts) return null;
2126
+ return alts.some(
2127
+ (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))
2128
+ );
2129
+ }
2130
+
2131
+ // src/doctor/installs.ts
2132
+ var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
2133
+ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
2134
+ var readManifest = (dir) => {
2135
+ try {
2136
+ return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
2137
+ } catch {
2138
+ return null;
2139
+ }
2140
+ };
2141
+ var real = (p) => {
2142
+ try {
2143
+ return realpathSync(p);
2144
+ } catch {
2145
+ return p;
2146
+ }
2147
+ };
2148
+ function packagesIn(nodeModules) {
2149
+ if (!existsSync(nodeModules)) return [];
2150
+ const out = [];
2151
+ for (const entry of readdirSync(nodeModules)) {
2152
+ if (entry.startsWith(".")) continue;
2153
+ const p = path14.join(nodeModules, entry);
2154
+ if (entry.startsWith("@")) {
2155
+ try {
2156
+ for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
2157
+ } catch {
2158
+ }
2159
+ } else {
2160
+ out.push(p);
2161
+ }
2162
+ }
2163
+ return out;
2164
+ }
2165
+ function genesisInstalls(root) {
2166
+ const copies = /* @__PURE__ */ new Map();
2167
+ const realRoot = real(root);
2168
+ const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
2169
+ const via = /* @__PURE__ */ new Map();
2170
+ const record = (real2, manifest, by, range, root2) => {
2171
+ let copy = copies.get(real2);
2172
+ if (!copy) {
2173
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
2174
+ copies.set(real2, copy);
2175
+ via.set(real2, /* @__PURE__ */ new Set());
2176
+ }
2177
+ via.get(real2).add(root2);
2178
+ if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
2179
+ };
2180
+ const walk = (kind, roots) => {
2181
+ const expanded = /* @__PURE__ */ new Set();
2182
+ const queue = [];
2183
+ const visit = (dir, by, range) => {
2184
+ const manifest = readManifest(dir);
2185
+ if (!manifest?.name) return;
2186
+ if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
2187
+ const realDir = real(dir);
2188
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
2189
+ if (expanded.has(realDir)) return;
2190
+ expanded.add(realDir);
2191
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
2192
+ };
2193
+ for (const r of roots) visit(r.dir, r.by, r.range);
2194
+ while (queue.length) {
2195
+ const { real: from, manifest, label } = queue.shift();
2196
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
2197
+ for (const [name, range] of Object.entries(deps)) {
2198
+ const dir = findPackageDir(from, name);
2199
+ if (dir) visit(dir, label, range);
2200
+ }
2201
+ }
2202
+ };
2203
+ const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
2204
+ const dir = findPackageDir(root, name);
2205
+ return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
2206
+ });
2207
+ const app = readManifest(root);
2208
+ let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
2209
+ let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
2210
+ if (Object.keys(runtimeDeps).length === 0) {
2211
+ runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
2212
+ devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
2213
+ }
2214
+ walk("runtime", rootsOf(runtimeDeps, "the app"));
2215
+ const top = path14.join(root, "node_modules");
2216
+ walk(
2217
+ "hoisted",
2218
+ packagesIn(top).filter((dir) => {
2219
+ const name = path14.relative(top, dir).split(path14.sep).join("/");
2220
+ return !(name in runtimeDeps) && !(name in devDeps);
2221
+ }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
2222
+ );
2223
+ const devRoots = { ...devDeps };
2224
+ for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
2225
+ walk("dev", rootsOf(devRoots, "the app (dev)"));
2226
+ for (const [key2, copy] of copies) {
2227
+ const kinds = via.get(key2);
2228
+ copy.runtime = kinds.has("runtime");
2229
+ copy.devOnly = kinds.size === 1 && kinds.has("dev");
2230
+ }
2231
+ const byName = /* @__PURE__ */ new Map();
2232
+ for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
2233
+ for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
2234
+ return byName;
2235
+ }
2236
+ function checkDuplicatePackages(ctx) {
2237
+ const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
2238
+ for (const [name, copies] of genesisInstalls(ctx.root)) {
2239
+ if (copies.length < 2) continue;
2240
+ const shipping = copies.filter((c) => c.runtime);
2241
+ if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
2242
+ ctx.report({
2243
+ rule: "duplicate-genesis-package",
2244
+ level: "warn",
2245
+ file: "package.json",
2246
+ subject: name,
2247
+ message: `${name} is installed ${copies.length} times: ${copies.map((c) => `${describe(c)}${c.devOnly ? " [dev only]" : ""}`).join(", ")}. 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`
2248
+ });
2249
+ continue;
2250
+ }
2251
+ ctx.report({
2252
+ rule: "duplicate-genesis-package",
2253
+ level: "info",
2254
+ file: "package.json",
2255
+ subject: name,
2256
+ message: `${name} has dev-only copies beside the one the app loads: ${copies.filter((c) => c.devOnly).map(describe).join(", ")}. They run in tooling, not the app, so they can't split its contexts; upgrade the tool to drop them`
2257
+ });
2258
+ }
2259
+ }
2260
+ function checkPeerRanges(ctx) {
2261
+ const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
2262
+ for (const copies of genesisInstalls(ctx.root).values()) {
2263
+ for (const copy of copies) {
2264
+ const dir = copy.absolutePath;
2265
+ const peers = readManifest(dir)?.peerDependencies ?? {};
2266
+ for (const [peer, range] of Object.entries(peers)) {
2267
+ if (!GENESIS.test(peer)) continue;
2268
+ const peerDir = findPackageDir(dir, peer);
2269
+ const installed = peerDir && readManifest(peerDir)?.version;
2270
+ if (!peerDir || !installed) continue;
2271
+ if (satisfies(installed, range) !== false) continue;
2272
+ ctx.report({
2273
+ rule: "peer-range-mismatch",
2274
+ // A dev tool's own tree (the CLI's) doesn't run in the app.
2275
+ level: copy.devOnly ? "info" : "warn",
2276
+ file: "package.json",
2277
+ subject: `${copy.name}>${peer}`,
2278
+ 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}`
2279
+ });
2280
+ }
2281
+ }
2282
+ }
2283
+ }
2284
+ var TRAIL_DEPTH = 6;
2285
+ var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
2286
+ var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
2287
+ var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
2288
+ var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
2289
+ function stripForImports(code) {
2290
+ const out = [];
2291
+ const blank = (ch) => ch === "\n" ? "\n" : " ";
2292
+ const n = code.length;
2293
+ const templates = [];
2294
+ let depth = 0;
2295
+ let i = 0;
2296
+ const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
2297
+ const opensString = () => {
2298
+ const before = out.slice(-12).join("");
2299
+ if (!/[\w$]$/.test(before)) return true;
2300
+ return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
2301
+ };
2302
+ const templateBody = () => {
2303
+ while (i < n) {
2304
+ const ch = code[i];
2305
+ if (ch === "\\") {
2306
+ out.push(" ", blank(code[i + 1] ?? ""));
2307
+ i += 2;
2308
+ } else if (ch === "`") {
2309
+ out.push("`");
2310
+ i++;
2311
+ return;
2312
+ } else if (ch === "$" && code[i + 1] === "{") {
2313
+ out.push("${");
2314
+ i += 2;
2315
+ templates.push(depth);
2316
+ depth++;
2317
+ return;
2318
+ } else {
2319
+ out.push(blank(ch));
2320
+ i++;
2321
+ }
2322
+ }
2323
+ };
2324
+ while (i < n) {
2325
+ const ch = code[i];
2326
+ const next = code[i + 1];
2327
+ if (ch === "/" && next === "/") {
2328
+ while (i < n && code[i] !== "\n") {
2329
+ out.push(" ");
2330
+ i++;
2331
+ }
2332
+ } else if (ch === "/" && next === "*") {
2333
+ out.push(" ");
2334
+ i += 2;
2335
+ while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
2336
+ out.push(blank(code[i]));
2337
+ i++;
2338
+ }
2339
+ if (i < n) {
2340
+ out.push(" ");
2341
+ i += 2;
2342
+ }
2343
+ } else if ((ch === '"' || ch === "'") && opensString()) {
2344
+ const keep = isSpecifier();
2345
+ out.push(ch);
2346
+ i++;
2347
+ while (i < n && code[i] !== ch && code[i] !== "\n") {
2348
+ if (code[i] === "\\") {
2349
+ out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
2350
+ i += 2;
2351
+ } else {
2352
+ out.push(keep ? code[i] : blank(code[i]));
2353
+ i++;
2354
+ }
2355
+ }
2356
+ if (i < n) {
2357
+ out.push(code[i]);
2358
+ i++;
2359
+ }
2360
+ } else if (ch === "`") {
2361
+ out.push("`");
2362
+ i++;
2363
+ templateBody();
2364
+ } else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
2365
+ templates.pop();
2366
+ depth--;
2367
+ out.push("}");
2368
+ i++;
2369
+ templateBody();
2370
+ } else {
2371
+ if (ch === "{") depth++;
2372
+ else if (ch === "}") depth--;
2373
+ out.push(ch);
2374
+ i++;
2375
+ }
2376
+ }
2377
+ return out.join("");
2378
+ }
2379
+ function bindings(clause) {
2380
+ const out = [];
2381
+ const named = /\{([^}]*)\}/.exec(clause);
2382
+ for (const part of named?.[1].split(",") ?? []) {
2383
+ const p = part.trim();
2384
+ if (!p || p.startsWith("type ")) continue;
2385
+ out.push(p.split(/\s+as\s+/).pop().trim());
2386
+ }
2387
+ const rest = clause.replace(/\{[^}]*\}/, "");
2388
+ const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
2389
+ if (ns) out.push(ns[1]);
2390
+ const def = /^\s*([\w$]+)/.exec(rest);
2391
+ if (def && def[1] !== "as") out.push(def[1]);
2392
+ return out;
2393
+ }
2394
+ function readJsonc(file) {
2395
+ try {
2396
+ const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
2397
+ return JSON.parse(text);
2398
+ } catch {
2399
+ return null;
2400
+ }
2401
+ }
2402
+ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
2403
+ if (seen.has(file) || seen.size > 10) return {};
2404
+ seen.add(file);
2405
+ const json = readJsonc(file);
2406
+ if (!json) return {};
2407
+ const dir = path14.dirname(file);
2408
+ let merged = {};
2409
+ const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
2410
+ for (const ext of parents) {
2411
+ if (typeof ext !== "string") continue;
2412
+ let target = null;
2413
+ if (ext.startsWith(".") || path14.isAbsolute(ext)) {
2414
+ const abs = path14.resolve(dir, ext);
2415
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
2416
+ } else {
2417
+ const parts = ext.split("/");
2418
+ const nameLength = ext.startsWith("@") ? 2 : 1;
2419
+ const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
2420
+ if (pkgDir) {
2421
+ const sub = parts.slice(nameLength).join("/");
2422
+ const abs = path14.join(pkgDir, sub || "tsconfig.json");
2423
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
2424
+ }
2425
+ }
2426
+ if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
2427
+ }
2428
+ const opts = json.compilerOptions ?? {};
2429
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
2430
+ if (opts.paths && typeof opts.paths === "object") {
2431
+ merged.paths = opts.paths;
2432
+ merged.pathsDir = dir;
2433
+ }
2434
+ return merged;
2435
+ }
2436
+ function aliases(root) {
2437
+ const table = [];
2438
+ let baseUrl = null;
2439
+ for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
2440
+ const file = path14.join(root, name);
2441
+ if (!existsSync(file)) continue;
2442
+ const config = readTsconfig(root, file);
2443
+ baseUrl ??= config.baseUrl ?? null;
2444
+ const base = config.baseUrl ?? config.pathsDir ?? root;
2445
+ for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
2446
+ if (!Array.isArray(targets)) continue;
2447
+ const exact = !pattern.endsWith("*");
2448
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
2449
+ }
2450
+ }
2451
+ const pkg = readJsonc(path14.join(root, "package.json"));
2452
+ for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
2453
+ if (typeof target !== "string") continue;
2454
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
2455
+ }
2456
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
2457
+ return { table, baseUrl };
2458
+ }
2459
+ function resolveFile(base) {
2460
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
2461
+ if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
2462
+ for (const p of tries) {
2463
+ if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
2464
+ }
2465
+ return null;
2466
+ }
2467
+ var trails = /* @__PURE__ */ new WeakMap();
2468
+ function trailFor(ctx) {
2469
+ let t = trails.get(ctx.files);
2470
+ if (!t) trails.set(ctx.files, t = createTrail(ctx));
2471
+ return t;
2472
+ }
2473
+ function createTrail(ctx) {
2474
+ const { table, baseUrl } = aliases(ctx.root);
2475
+ let declared = null;
2476
+ try {
2477
+ const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
2478
+ declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
2479
+ } catch {
2480
+ declared = null;
2481
+ }
2482
+ const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2483
+ const read = (abs) => byPath.get(abs) ?? readSource(abs);
2484
+ const importsCache = /* @__PURE__ */ new Map();
2485
+ const importsOf = (file) => {
2486
+ const hit = importsCache.get(file.absolutePath);
2487
+ if (hit) return hit;
2488
+ const files = [];
2489
+ let lost = false;
2490
+ const code = stripped(file);
2491
+ const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
2492
+ for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
2493
+ for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
2494
+ for (const m of code.matchAll(/\bexport\s*\{([^}]*)\}\s*;/g)) for (const n of m[1].split(",")) used.add(n.trim().split(/\s+as\s+/)[0]);
2495
+ const specs = [];
2496
+ for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
2497
+ for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
2498
+ for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
2499
+ for (const spec of specs) {
2500
+ if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
2501
+ let resolved = null;
2502
+ if (spec.startsWith(".")) {
2503
+ resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
2504
+ if (!resolved) lost = true;
2505
+ } else {
2506
+ const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
2507
+ if (alias) {
2508
+ for (const t of alias.targets) {
2509
+ resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
2510
+ if (resolved) break;
2511
+ }
2512
+ }
2513
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
2514
+ if (!resolved) {
2515
+ const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
2516
+ if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
2517
+ }
2518
+ }
2519
+ if (resolved && !files.includes(resolved)) files.push(resolved);
2520
+ }
2521
+ const out = { files, lost };
2522
+ importsCache.set(file.absolutePath, out);
2523
+ return out;
2524
+ };
2525
+ const strippedCache = /* @__PURE__ */ new Map();
2526
+ const stripped = (file) => {
2527
+ let c = strippedCache.get(file.absolutePath);
2528
+ if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
2529
+ return c;
2530
+ };
2531
+ const memo = /* @__PURE__ */ new WeakMap();
2532
+ const reach = (file, test2, depth, seen) => {
2533
+ let cache = memo.get(test2);
2534
+ if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
2535
+ const k = `${file.absolutePath}\0${depth}`;
2536
+ const cached = cache.get(k);
2537
+ if (cached) return [cached, false];
2538
+ let result;
2539
+ let cut = false;
2540
+ if (test2(stripped(file))) result = "yes";
2541
+ else {
2542
+ const { files, lost } = importsOf(file);
2543
+ let unknown = lost && depth > 0;
2544
+ result = "no";
2545
+ if (depth > 0) {
2546
+ seen.add(file.absolutePath);
2547
+ for (const abs of files) {
2548
+ if (seen.has(abs)) {
2549
+ cut = true;
2550
+ continue;
2551
+ }
2552
+ const target = read(abs);
2553
+ if (!target) {
2554
+ unknown = true;
2555
+ continue;
2556
+ }
2557
+ const [r, c] = reach(target, test2, depth - 1, seen);
2558
+ if (c) cut = true;
2559
+ if (r === "yes") {
2560
+ result = "yes";
2561
+ break;
2562
+ }
2563
+ if (r === "unknown") unknown = true;
2564
+ }
2565
+ seen.delete(file.absolutePath);
2566
+ }
2567
+ if (result === "no" && unknown) result = "unknown";
2568
+ }
2569
+ if (result === "yes" || !cut) cache.set(k, result);
2570
+ return [result, cut && result !== "yes"];
2571
+ };
2572
+ return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
2573
+ }
2574
+
2575
+ // src/doctor/routes.ts
2576
+ var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
2577
+ var STEMS = {
2578
+ tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
2579
+ "next-app": {
2580
+ layout: /* @__PURE__ */ new Set(["layout"]),
2581
+ index: /* @__PURE__ */ new Set(["page"]),
2582
+ skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
2583
+ },
2584
+ "next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
2585
+ };
2586
+ var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
2587
+ var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
2588
+ var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
2589
+ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
2590
+ var OWN_CONTENT = /(?<![=-])>\s*[A-Za-z][^<>{}]*</.source + "|" + /(?<![\w$.])<(?:h[1-6]|ul|ol|table|dl|H[1-6]|[A-Z]\w*(?:Heading|Title|Table|List|Grid))(?=[\s>/])/.source;
2591
+ function routesDir(ctx) {
2592
+ if (ctx.config.routesDir) return ctx.config.routesDir;
2593
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
2594
+ }
2595
+ var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
2596
+ function flavorOf(dir, rels) {
2597
+ const stems = rels.map((r) => r.split("/").pop());
2598
+ if (stems.includes("__root")) return "tanstack";
2599
+ if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
2600
+ if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
2601
+ return "tanstack";
2602
+ }
2603
+ function renders(code) {
2604
+ const elements = renderedElements(code);
2605
+ if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
2606
+ const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
2607
+ const named = COMPONENT_OPTION.exec(code)?.[1];
2608
+ if (named && !definedHere(named)) return true;
2609
+ if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
2610
+ const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
2611
+ return exported !== void 0 && !definedHere(exported);
2612
+ }
2613
+ function webRoutes(ctx) {
2614
+ const dir = routesDir(ctx);
2615
+ if (!dir) return [];
2616
+ const candidates = ctx.files.filter((f) => JSX_EXTS2.has(f.ext) && f.path.startsWith(`${dir}/`)).map((file) => ({ file, rel: file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "") }));
2617
+ const flavor = flavorOf(dir, candidates.map((c) => c.rel));
2618
+ const stems = STEMS[flavor];
2619
+ const groups = /* @__PURE__ */ new Map();
2620
+ for (const { file, rel } of candidates) {
2621
+ const parts = rel.split("/");
2622
+ if (parts.some((p) => p.startsWith("-"))) continue;
2623
+ if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
2624
+ if (flavor === "next-pages" && parts[0] === "api") continue;
2625
+ if (stems.skip.test(parts.at(-1))) continue;
2626
+ if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
2627
+ const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
2628
+ groups.set(id, [...groups.get(id) ?? [], file]);
2629
+ }
2630
+ const trail = trailFor(ctx);
2631
+ const routes = [];
2632
+ for (const [id, files] of groups) {
2633
+ const parts = id.split("/");
2634
+ const stem = parts.pop();
2635
+ const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
2636
+ const named = stems.layout.has(stem) || stems.index.has(stem);
2637
+ const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
2638
+ const segments = [...folders, ...own];
2639
+ const tree = [...parts, ...own];
2640
+ let index = stems.index.has(stem);
2641
+ if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
2642
+ segments.pop();
2643
+ tree.pop();
2644
+ index = true;
2645
+ }
2646
+ const code = files.map((f) => f.code).join("\n");
2647
+ const elements = renderedElements(code);
2648
+ const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
2649
+ const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
2650
+ const layout = stems.layout.has(stem) || pathless || outlet;
2651
+ const rendering = renders(code);
2652
+ const ownContent = new RegExp(OWN_CONTENT).test(code);
2653
+ const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
2654
+ const page = !pure && !pathless && (!layout || ownContent);
2655
+ routes.push({
2656
+ file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
2657
+ files,
2658
+ segments,
2659
+ tree,
2660
+ index,
2661
+ layout,
2662
+ page,
2663
+ detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
2664
+ redirectOnly: !rendering,
2665
+ parents: []
2666
+ });
2667
+ }
2668
+ for (const r of routes) {
2669
+ const own = r.tree;
2670
+ for (const p of routes) {
2671
+ if (p === r || !p.layout) continue;
2672
+ const n = p.tree.length;
2673
+ if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
2674
+ if (key(own.slice(0, n)) !== key(p.tree)) continue;
2675
+ if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
2676
+ r.parents.push(p);
2677
+ }
2678
+ r.parents.sort((a, b) => b.tree.length - a.tree.length);
2679
+ }
2680
+ return routes;
2681
+ }
2682
+
2683
+ // src/doctor/structure.ts
2684
+ var SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
2685
+ var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
2686
+ var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
2687
+ var SHELL = /<AppShell(?=[\s>/])/;
2688
+ var GENESIS_PACKAGE = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
2689
+ var PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
2690
+ var PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
2691
+ var isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
2692
+ var rendersRe = (names) => {
2693
+ const list = [...names];
2694
+ return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
2695
+ };
2696
+ function routeReach(ctx, r, test2) {
2697
+ const trail = trailFor(ctx);
2698
+ let unknown = false;
2699
+ for (const f of r.files) {
2700
+ const got = trail.reach(f, test2);
2701
+ if (got === "yes") return "yes";
2702
+ if (got === "unknown") unknown = true;
2703
+ }
2704
+ return unknown ? "unknown" : "no";
2705
+ }
2706
+ var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
2707
+ function insideShell(ctx, routes) {
2708
+ const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
2709
+ const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
2710
+ return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
2711
+ }
2712
+ function checkHandRolledSubNav(ctx) {
2713
+ if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
2714
+ const routes = webRoutes(ctx);
2715
+ if (routes.length === 0) return;
2716
+ const inShell = insideShell(ctx, routes);
2717
+ const ui = ctx.genesis.uiPackage;
2718
+ for (const r of routes) {
2719
+ if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
2720
+ const hit = r.files.flatMap((f) => [...f.code.matchAll(SWITCHER)].map((m) => ({ f, m }))).find(({ f, m }) => openElementsAt(f.code, m.index, (n) => CONTAINER.test(n)).length === 0);
2721
+ if (hit) {
2722
+ const { f, m } = hit;
2723
+ const code = f.code;
2724
+ ctx.report({
2725
+ rule: "hand-rolled-sub-nav",
2726
+ level: "warn",
2727
+ file: f.path,
2728
+ line: lineAt(code, m.index),
2729
+ subject: m[1],
2730
+ 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}`
2731
+ });
2732
+ }
2733
+ }
2734
+ }
2735
+ function checkLocalGenesisCopies(ctx) {
2736
+ const owner = /* @__PURE__ */ new Map();
2737
+ for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
2738
+ for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
2739
+ if (owner.size === 0) return;
2740
+ const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
2741
+ const routes = routesDir(ctx);
2742
+ for (const file of ctx.files) {
2743
+ if (!JSX_EXTS2.has(file.ext)) continue;
2744
+ const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE));
2745
+ const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
2746
+ const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
2747
+ const decls = [...file.code.matchAll(decl)];
2748
+ decls.forEach((m, i) => {
2749
+ const [, exported, name] = m;
2750
+ const pkg = owner.get(name);
2751
+ if (!pkg || imported.has(name) || routeComponents.has(name)) return;
2752
+ if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
2753
+ const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
2754
+ if (!rendersJsx(body)) return;
2755
+ if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
2756
+ const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
2757
+ if (/["']@marktiderman\/genesis/.test(init)) return;
2758
+ ctx.report({
2759
+ rule: "local-genesis-copy",
2760
+ level: "warn",
2761
+ file: file.path,
2762
+ line: lineAt(file.code, m.index),
2763
+ subject: name,
2764
+ message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
2765
+ });
2766
+ });
2767
+ }
2768
+ }
2769
+ function checkResourceWorkspaces(ctx) {
2770
+ if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
2771
+ const header = /<AppShellPageHeader(?=[\s>/])/;
2772
+ const byFolder = /* @__PURE__ */ new Map();
2773
+ for (const r of webRoutes(ctx)) {
2774
+ if (!r.detail || r.redirectOnly) continue;
2775
+ const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
2776
+ byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
2777
+ }
2778
+ for (const [dir, routes] of byFolder) {
2779
+ const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
2780
+ const has = routes.filter((r) => reach.get(r) === "yes");
2781
+ if (has.length === 0) continue;
2782
+ const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
2783
+ for (const r of routes) {
2784
+ if (reach.get(r) !== "no") continue;
2785
+ ctx.report({
2786
+ rule: "resource-workspace",
2787
+ level: "info",
2788
+ file: r.file.path,
2789
+ 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`
2790
+ });
2791
+ }
2792
+ }
2793
+ }
2794
+ function checkPageLayouts(ctx) {
2795
+ if (isNative(ctx)) return;
2796
+ const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
2797
+ for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
2798
+ if (layouts.size === 0) return;
2799
+ const routes = webRoutes(ctx);
2800
+ const inShell = insideShell(ctx, routes);
2801
+ const rendersLayout = (code) => {
2802
+ const names = new Set(layouts);
2803
+ for (const n of namedImportsFrom(code, GENESIS_PACKAGE)) if (PACKAGE_SCREEN.test(n)) names.add(n);
2804
+ return rendersRe(names)?.test(code) ?? false;
2805
+ };
2806
+ const cache = /* @__PURE__ */ new Map();
2807
+ const provides = (r) => {
2808
+ if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
2809
+ return cache.get(r);
2810
+ };
2811
+ const list = [...layouts].sort();
2812
+ const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
2813
+ for (const r of routes) {
2814
+ if (!r.page || r.redirectOnly || !inShell(r)) continue;
2815
+ if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
2816
+ ctx.report({
2817
+ rule: "page-layout",
2818
+ level: "warn",
2819
+ file: r.file.path,
2820
+ 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`
2821
+ });
2822
+ }
2823
+ }
2824
+
2825
+ // src/doctor/dates.ts
2826
+ var SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2827
+ 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;
2828
+ function checkIsoDateSlices(ctx) {
2829
+ for (const file of ctx.files) {
2830
+ if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
2831
+ for (const m of file.code.matchAll(ISO_DAY_CUT)) {
2832
+ ctx.report({
2833
+ rule: "iso-date-slice",
2834
+ level: "warn",
2835
+ file: file.path,
2836
+ line: lineAt(file.code, m.index ?? 0),
2837
+ subject: "toISOString",
2838
+ 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)"
2839
+ });
2840
+ }
2841
+ }
2842
+ }
2843
+
1908
2844
  // src/doctor/index.ts
1909
2845
  async function runDoctor(options = {}) {
1910
- const root = path3.resolve(options.root ?? process.cwd());
2846
+ const root = path14.resolve(options.root ?? process.cwd());
1911
2847
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
1912
2848
  const config = loaded.config;
1913
2849
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -1920,18 +2856,7 @@ async function runDoctor(options = {}) {
1920
2856
  }
1921
2857
  const raw = [];
1922
2858
  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]) {
2859
+ for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
1935
2860
  try {
1936
2861
  await plugin.check(ctx);
1937
2862
  } catch (err) {
@@ -1945,7 +2870,8 @@ async function runDoctor(options = {}) {
1945
2870
  }
1946
2871
  const findings = applyConfig(raw, config);
1947
2872
  const errors = findings.filter((f) => f.level === "error").length;
1948
- const warnings = findings.length - errors;
2873
+ const warnings = findings.filter((f) => f.level === "warn").length;
2874
+ const infos = findings.length - errors - warnings;
1949
2875
  return {
1950
2876
  ok: errors === 0 && !(options.strict && warnings > 0),
1951
2877
  root,
@@ -1954,8 +2880,32 @@ async function runDoctor(options = {}) {
1954
2880
  unused: unusedComponents(ctx),
1955
2881
  ruleCount: (patterns?.count ?? 0) + plugins.length,
1956
2882
  errors,
1957
- warnings
2883
+ warnings,
2884
+ infos
2885
+ };
2886
+ }
2887
+ function builtinChecks(config) {
2888
+ const packs = {
2889
+ native: { name: "native", check: checkNativePack },
2890
+ supabase: { name: "supabase", check: checkSupabasePack }
1958
2891
  };
2892
+ return [
2893
+ { name: "layout", check: checkProjectLayout },
2894
+ { name: "imports", check: checkImports },
2895
+ { name: "raw-tags", check: checkRawTags },
2896
+ { name: "colors", check: checkColors },
2897
+ { name: "tokens", check: checkTokens },
2898
+ { name: "shadowed-exports", check: checkShadowedExports },
2899
+ { name: "version-skew", check: checkVersionSkew },
2900
+ { name: "duplicate-packages", check: checkDuplicatePackages },
2901
+ { name: "peer-ranges", check: checkPeerRanges },
2902
+ { name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
2903
+ { name: "local-genesis-copies", check: checkLocalGenesisCopies },
2904
+ { name: "resource-workspaces", check: checkResourceWorkspaces },
2905
+ { name: "page-layouts", check: checkPageLayouts },
2906
+ { name: "iso-date-slices", check: checkIsoDateSlices },
2907
+ ...(config.packs ?? []).map((p) => packs[p])
2908
+ ];
1959
2909
  }
1960
2910
  function applyConfig(raw, config) {
1961
2911
  const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
@@ -2003,12 +2953,13 @@ function formatReport(result) {
2003
2953
  lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
2004
2954
  }
2005
2955
  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)`);
2956
+ const info = result.infos ? `, ${result.infos} info` : "";
2957
+ lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
2007
2958
  return lines.join("\n");
2008
2959
  }
2009
2960
 
2010
2961
  // 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");
2962
+ 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
2963
  function genesisDoctor(options = {}) {
2013
2964
  let root = options.root ?? process.cwd();
2014
2965
  return [
@@ -2072,15 +3023,15 @@ ${formatProblems(result)}`);
2072
3023
  }
2073
3024
  }
2074
3025
  };
2075
- const explicit = /* @__PURE__ */ new Set([path3.join(root, "genesis.config.json"), ...options.configPath ? [path3.resolve(root, options.configPath)] : []]);
3026
+ const explicit = /* @__PURE__ */ new Set([path14.join(root, "genesis.config.json"), ...options.configPath ? [path14.resolve(root, options.configPath)] : []]);
2076
3027
  try {
2077
3028
  const { config } = loadConfig(root, options.configPath);
2078
- if (config.rulesDoc) explicit.add(path3.resolve(root, config.rulesDoc));
3029
+ if (config.rulesDoc) explicit.add(path14.resolve(root, config.rulesDoc));
2079
3030
  } catch {
2080
3031
  }
2081
3032
  const schedule = (file) => {
2082
- if (!explicit.has(path3.resolve(file))) {
2083
- const rel = path3.relative(root, file).split(path3.sep).join("/");
3033
+ if (!explicit.has(path14.resolve(file))) {
3034
+ const rel = path14.relative(root, file).split(path14.sep).join("/");
2084
3035
  if (rel.startsWith("..") || rel.includes("node_modules/")) return;
2085
3036
  }
2086
3037
  clearTimeout(timer);