@marktiderman/genesis-cli 1.9.0 → 1.11.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,4 +1,4 @@
1
- import * as path3 from 'path';
1
+ import * as path14 from 'path';
2
2
  import { spawnSync } from 'child_process';
3
3
  import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
4
4
  import { createRequire } from 'module';
@@ -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
  }
@@ -127,25 +127,25 @@ var PACK_KEYS = {
127
127
  };
128
128
  function appPath(v, where, fail) {
129
129
  if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
130
- if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
131
- 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(/\/+$/, "");
132
132
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
133
133
  return norm;
134
134
  }
135
135
  function loadConfig(root, configPath) {
136
136
  if (configPath) {
137
- const file = path3.resolve(root, configPath);
137
+ const file = path14.resolve(root, configPath);
138
138
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
139
139
  const json = readJson(file);
140
- const block = path3.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
141
- 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) };
142
142
  }
143
- const own = path3.join(root, "genesis.config.json");
143
+ const own = path14.join(root, "genesis.config.json");
144
144
  if (existsSync(own)) {
145
145
  const block = readGenesisConfig(root)?.raw.doctor;
146
146
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
147
147
  }
148
- const pkg = path3.join(root, "package.json");
148
+ const pkg = path14.join(root, "package.json");
149
149
  if (existsSync(pkg)) {
150
150
  const block = readJson(pkg)?.genesis?.doctor;
151
151
  if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -160,7 +160,7 @@ function readJson(file) {
160
160
  }
161
161
  }
162
162
  function readGenesisConfig(root) {
163
- const file = path3.join(root, "genesis.config.json");
163
+ const file = path14.join(root, "genesis.config.json");
164
164
  if (!existsSync(file)) return null;
165
165
  const raw = readJson(file);
166
166
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -362,7 +362,7 @@ function globToRegExp(glob) {
362
362
  }
363
363
  function globMatcher(globs) {
364
364
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
365
- return (path17) => res.some((re) => re.test(path17));
365
+ return (path18) => res.some((re) => re.test(path18));
366
366
  }
367
367
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
368
368
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -402,11 +402,11 @@ var TAILWIND_PALETTE = [
402
402
  "olive"
403
403
  ];
404
404
  function findPackageDir(from, name) {
405
- let dir = path3.resolve(from);
405
+ let dir = path14.resolve(from);
406
406
  for (; ; ) {
407
- const candidate = path3.join(dir, "node_modules", name);
408
- if (existsSync(path3.join(candidate, "package.json"))) return candidate;
409
- 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);
410
410
  if (parent === dir) return null;
411
411
  dir = parent;
412
412
  }
@@ -458,7 +458,7 @@ function loadCompanions(root, config, uiPackage) {
458
458
  function readPackageExports(root, uiPackage) {
459
459
  const uiDir = findPackageDir(root, uiPackage);
460
460
  if (!uiDir) return null;
461
- const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
461
+ const uiPkg = JSON.parse(readFileSync(path14.join(uiDir, "package.json"), "utf8"));
462
462
  const typeEntries = /* @__PURE__ */ new Set();
463
463
  const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
464
464
  if (typeof mainTypes === "string") typeEntries.add(mainTypes);
@@ -470,7 +470,7 @@ function readPackageExports(root, uiPackage) {
470
470
  const reexportedPackages = /* @__PURE__ */ new Set();
471
471
  let readAny = false;
472
472
  for (const entry of typeEntries) {
473
- const file = path3.join(uiDir, entry);
473
+ const file = path14.join(uiDir, entry);
474
474
  if (!existsSync(file)) continue;
475
475
  readAny = true;
476
476
  const dts = readFileSync(file, "utf8");
@@ -484,11 +484,11 @@ function readPackageExports(root, uiPackage) {
484
484
  }
485
485
  const valueDecls = /* @__PURE__ */ new Set();
486
486
  const typeDecls = /* @__PURE__ */ new Set();
487
- 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;
488
488
  const declFiles = walkDts(declRoot);
489
489
  for (const pkg of reexportedPackages) {
490
490
  const dir = findPackageDir(uiDir, pkg);
491
- if (dir) walkDts(path3.join(dir, "dist"), declFiles);
491
+ if (dir) walkDts(path14.join(dir, "dist"), declFiles);
492
492
  }
493
493
  for (const file of declFiles) {
494
494
  const text = readFileSync(file, "utf8");
@@ -534,7 +534,7 @@ function walkDts(dir, out = []) {
534
534
  if (!existsSync(dir)) return out;
535
535
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
536
536
  if (entry.name === "node_modules") continue;
537
- const p = path3.join(dir, entry.name);
537
+ const p = path14.join(dir, entry.name);
538
538
  if (entry.isDirectory()) walkDts(p, out);
539
539
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
540
540
  }
@@ -551,27 +551,27 @@ function resolveThemeFiles(root, config, uiDir) {
551
551
  }
552
552
  const files = [];
553
553
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
554
- const themes = ds && path3.join(ds, "dist", "themes");
554
+ const themes = ds && path14.join(ds, "dist", "themes");
555
555
  if (themes && existsSync(themes)) {
556
- 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));
557
557
  }
558
558
  if (files.length === 0) {
559
559
  throw new DoctorConfigError(
560
560
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
561
561
  );
562
562
  }
563
- const uiStyles = path3.join(uiDir, "dist", "styles.css");
563
+ const uiStyles = path14.join(uiDir, "dist", "styles.css");
564
564
  if (existsSync(uiStyles)) files.push(uiStyles);
565
565
  return files;
566
566
  }
567
567
  function resolveSpec(root, spec) {
568
- const local = path3.resolve(root, spec);
569
- 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;
570
570
  const parts = spec.split("/");
571
571
  const nameLength = spec.startsWith("@") ? 2 : 1;
572
572
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
573
573
  if (dir) {
574
- const file = path3.join(dir, ...parts.slice(nameLength));
574
+ const file = path14.join(dir, ...parts.slice(nameLength));
575
575
  if (existsSync(file) && statSync(file).isFile()) return file;
576
576
  }
577
577
  return existsSync(local) ? local : null;
@@ -579,7 +579,7 @@ function resolveSpec(root, spec) {
579
579
  function loadPalette(root) {
580
580
  const names = new Set(TAILWIND_PALETTE);
581
581
  try {
582
- const req = createRequire(path3.join(root, "package.json"));
582
+ const req = createRequire(path14.join(root, "package.json"));
583
583
  const colors = req("tailwindcss/colors");
584
584
  for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
585
585
  if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
@@ -764,16 +764,16 @@ var DEFAULT_IGNORE = [
764
764
  ];
765
765
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
766
766
  var MAX_FILE_BYTES = 2 * 1024 * 1024;
767
- var toPosix = (p) => p.split(path3.sep).join("/");
767
+ var toPosix = (p) => p.split(path14.sep).join("/");
768
768
  function scanFiles(root, config) {
769
769
  const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
770
770
  const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
771
771
  const files = [];
772
772
  const seen = /* @__PURE__ */ new Set();
773
773
  const visit = (abs) => {
774
- const rel = toPosix(path3.relative(root, abs));
774
+ const rel = toPosix(path14.relative(root, abs));
775
775
  if (seen.has(rel) || ignored(rel)) return;
776
- const ext = path3.extname(abs);
776
+ const ext = path14.extname(abs);
777
777
  if (!extensions.has(ext)) return;
778
778
  if (statSync(abs).size > MAX_FILE_BYTES) return;
779
779
  seen.add(rel);
@@ -783,14 +783,14 @@ function scanFiles(root, config) {
783
783
  const walk = (dir) => {
784
784
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
785
785
  if (entry.isDirectory()) {
786
- 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));
787
787
  } else if (entry.isFile()) {
788
- visit(path3.join(dir, entry.name));
788
+ visit(path14.join(dir, entry.name));
789
789
  }
790
790
  }
791
791
  };
792
792
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
793
- const abs = path3.resolve(root, src);
793
+ const abs = path14.resolve(root, src);
794
794
  if (!existsSync(abs)) continue;
795
795
  if (statSync(abs).isDirectory()) walk(abs);
796
796
  else visit(abs);
@@ -867,7 +867,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
867
867
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
868
868
  let all = compiled;
869
869
  if (rulesDoc) {
870
- const file = path3.resolve(root, rulesDoc);
870
+ const file = path14.resolve(root, rulesDoc);
871
871
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
872
872
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
873
873
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -923,14 +923,14 @@ async function loadPlugins(specs, configDir) {
923
923
  }
924
924
  function resolvePlugin(id, configDir) {
925
925
  try {
926
- 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);
927
927
  return resolveFrom(id, configDir);
928
928
  } catch {
929
929
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
930
930
  }
931
931
  }
932
932
  function resolveFrom(id, from) {
933
- return createRequire(path3.join(from, "noop.js")).resolve(id);
933
+ return createRequire(path14.join(from, "noop.js")).resolve(id);
934
934
  }
935
935
  var BUILTIN_RULES = [
936
936
  "local-primitives",
@@ -963,7 +963,8 @@ var BUILTIN_RULES = [
963
963
  "migration-rls",
964
964
  "migration-definer-search-path",
965
965
  "migration-edited",
966
- "migration-testing-kit"
966
+ "migration-testing-kit",
967
+ "migration-view-rls"
967
968
  ];
968
969
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
969
970
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -981,7 +982,7 @@ function importSpecifiers(file) {
981
982
  }
982
983
  function checkProjectLayout(ctx) {
983
984
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
984
- if (existsSync(path3.join(ctx.root, dir))) {
985
+ if (existsSync(path14.join(ctx.root, dir))) {
985
986
  ctx.report({
986
987
  rule: "local-primitives",
987
988
  file: dir,
@@ -991,7 +992,7 @@ function checkProjectLayout(ctx) {
991
992
  }
992
993
  }
993
994
  for (const file of STARTER_LEFTOVERS) {
994
- if (existsSync(path3.join(ctx.root, file))) {
995
+ if (existsSync(path14.join(ctx.root, file))) {
995
996
  ctx.report({
996
997
  rule: "starter-leftover",
997
998
  level: "warn",
@@ -1080,7 +1081,7 @@ function checkTokens(ctx) {
1080
1081
  }
1081
1082
  for (const pattern of ctx.config.tokenFiles ?? []) {
1082
1083
  if (/[*?]/.test(pattern)) continue;
1083
- const abs = path3.join(ctx.root, pattern);
1084
+ const abs = path14.join(ctx.root, pattern);
1084
1085
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
1085
1086
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
1086
1087
  }
@@ -1186,10 +1187,10 @@ function localImports(root, file) {
1186
1187
  const out = [];
1187
1188
  for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
1188
1189
  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
+ 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
1191
  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)
1192
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
1193
+ (p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
1193
1194
  );
1194
1195
  if (hit) {
1195
1196
  out.push(hit);
@@ -1206,14 +1207,6 @@ function readSource(abs) {
1206
1207
  return null;
1207
1208
  }
1208
1209
  }
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
1210
  function tagEnd(code, start) {
1218
1211
  let depth = 0;
1219
1212
  let quote = null;
@@ -1361,7 +1354,7 @@ function checkCustomHeaders(ctx, pkg) {
1361
1354
  if (!JSX_EXTS3.has(file.ext)) continue;
1362
1355
  const code = file.code;
1363
1356
  const hidden = HIDES_HEADER.exec(code);
1364
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
1357
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
1365
1358
  const own = hidden ? ownHeader(code, pkg) : null;
1366
1359
  if (hidden && own) {
1367
1360
  reported.add(file.path);
@@ -1389,7 +1382,7 @@ function checkCustomHeaders(ctx, pkg) {
1389
1382
  }
1390
1383
  for (const file of ctx.files) {
1391
1384
  if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
1392
- const layout = hidingLayouts.get(path3.posix.dirname(file.path));
1385
+ const layout = hidingLayouts.get(path14.posix.dirname(file.path));
1393
1386
  const own = layout ? ownHeader(file.code, pkg) : null;
1394
1387
  if (!layout || !own) continue;
1395
1388
  ctx.report({
@@ -1404,13 +1397,13 @@ function checkCustomHeaders(ctx, pkg) {
1404
1397
  }
1405
1398
  function routerRoot(ctx) {
1406
1399
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
1407
- return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
1400
+ return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
1408
1401
  }
1409
1402
  function checkScreenLayouts(ctx, pkg) {
1410
1403
  const layouts = nativeLayouts(pkg);
1411
1404
  if (layouts.length === 0) return;
1412
1405
  const rootDir = routerRoot(ctx);
1413
- if (!existsSync(path3.join(ctx.root, rootDir))) {
1406
+ if (!existsSync(path14.join(ctx.root, rootDir))) {
1414
1407
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
1415
1408
  return;
1416
1409
  }
@@ -1424,15 +1417,15 @@ function checkScreenLayouts(ctx, pkg) {
1424
1417
  });
1425
1418
  return;
1426
1419
  }
1427
- const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
1420
+ const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
1428
1421
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
1429
1422
  for (const file of routes) {
1430
1423
  if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
1431
1424
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
1432
- if (renders.test(file.code)) continue;
1425
+ if (renders2.test(file.code)) continue;
1433
1426
  const viaImport = localImports(ctx.root, file).some((abs) => {
1434
1427
  const target = byPath.get(abs) ?? readSource(abs);
1435
- return target !== null && renders.test(target.code);
1428
+ return target !== null && renders2.test(target.code);
1436
1429
  });
1437
1430
  if (viaImport) continue;
1438
1431
  ctx.report({
@@ -1465,7 +1458,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
1465
1458
  function readExpoConfigs(root) {
1466
1459
  const out = [];
1467
1460
  for (const name of EXPO_CONFIGS) {
1468
- const abs = path3.join(root, name);
1461
+ const abs = path14.join(root, name);
1469
1462
  if (!existsSync(abs)) continue;
1470
1463
  const text = readFileSync(abs, "utf8");
1471
1464
  let json = null;
@@ -1499,13 +1492,13 @@ function pluginOptions(json, module) {
1499
1492
  return null;
1500
1493
  }
1501
1494
  function dependencies(root) {
1502
- const file = path3.join(root, "package.json");
1495
+ const file = path14.join(root, "package.json");
1503
1496
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
1504
1497
  const pkg = JSON.parse(readFileSync(file, "utf8"));
1505
1498
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
1506
1499
  }
1507
1500
  function runtimeDependencies(root) {
1508
- const file = path3.join(root, "package.json");
1501
+ const file = path14.join(root, "package.json");
1509
1502
  if (!existsSync(file)) return {};
1510
1503
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
1511
1504
  }
@@ -1768,9 +1761,9 @@ function gitView(root, dir, base) {
1768
1761
  function checkSupabasePack(ctx) {
1769
1762
  const settings = ctx.config.supabase ?? {};
1770
1763
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
1771
- const abs = path3.join(ctx.root, dir);
1764
+ const abs = path14.join(ctx.root, dir);
1772
1765
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
1773
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path3.join(abs, n), "utf8")) }));
1766
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
1774
1767
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
1775
1768
  const base = settings.base ?? DEFAULT_BASE;
1776
1769
  const view = gitView(ctx.root, dir, base);
@@ -1787,7 +1780,7 @@ function checkSupabasePack(ctx) {
1787
1780
  }
1788
1781
  }
1789
1782
  const since = settings.since;
1790
- const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
1783
+ const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
1791
1784
  if ("reason" in view && since === void 0) {
1792
1785
  ctx.report({
1793
1786
  rule: "migration-grants",
@@ -1800,6 +1793,7 @@ function checkSupabasePack(ctx) {
1800
1793
  checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
1801
1794
  }
1802
1795
  checkRls(ctx, migrations, exposed);
1796
+ checkViewInvoker(ctx, migrations, exposed);
1803
1797
  checkDefinerSearchPath(ctx, migrations);
1804
1798
  checkTestingKit(ctx, migrations);
1805
1799
  }
@@ -1929,6 +1923,50 @@ function checkRls(ctx, migrations, exposed) {
1929
1923
  });
1930
1924
  }
1931
1925
  }
1926
+ function checkViewInvoker(ctx, migrations, exposed) {
1927
+ const views = /* @__PURE__ */ new Map();
1928
+ const name = String.raw`([\w$.]+)`;
1929
+ const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
1930
+ for (const { file, statements } of migrations) {
1931
+ for (const { sql, line } of statements) {
1932
+ const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
1933
+ if (create) {
1934
+ if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
1935
+ const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
1936
+ views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
1937
+ continue;
1938
+ }
1939
+ const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
1940
+ if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
1941
+ const state = views.get(qualify(alter[1]));
1942
+ if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
1943
+ continue;
1944
+ }
1945
+ const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
1946
+ if (rename) {
1947
+ const from = qualify(rename[1]);
1948
+ const state = views.get(from);
1949
+ if (state) {
1950
+ views.delete(from);
1951
+ views.set(`${schemaOf(from)}.${rename[2]}`, state);
1952
+ }
1953
+ continue;
1954
+ }
1955
+ const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
1956
+ if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
1957
+ }
1958
+ }
1959
+ for (const [v, at] of views) {
1960
+ if (at.invoker || !exposed.has(schemaOf(v))) continue;
1961
+ ctx.report({
1962
+ rule: "migration-view-rls",
1963
+ file: at.file,
1964
+ line: at.line,
1965
+ subject: v,
1966
+ message: `${v} runs as its owner, so it reads past row level security; create it "with (security_invoker = true)" or add "alter view ${v} set (security_invoker = true);"`
1967
+ });
1968
+ }
1969
+ }
1932
1970
  function checkDefinerSearchPath(ctx, migrations) {
1933
1971
  const fns = /* @__PURE__ */ new Map();
1934
1972
  const keysFor = (sql, nameEnd, fnName) => {
@@ -1994,7 +2032,7 @@ function checkDefinerSearchPath(ctx, migrations) {
1994
2032
  var UMBRELLA_PACKAGE = "@marktiderman/genesis";
1995
2033
  function readReleaseManifest(root) {
1996
2034
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
1997
- const file = dir && path3.join(dir, "dist", "versions.json");
2035
+ const file = dir && path14.join(dir, "dist", "versions.json");
1998
2036
  if (!file || !existsSync(file)) return null;
1999
2037
  return JSON.parse(readFileSync(file, "utf8"));
2000
2038
  }
@@ -2004,7 +2042,7 @@ function checkVersionSkew(ctx) {
2004
2042
  for (const [name, want] of Object.entries(manifest.packages)) {
2005
2043
  const dir = findPackageDir(ctx.root, name);
2006
2044
  if (!dir) continue;
2007
- const have = JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8")).version;
2045
+ const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
2008
2046
  if (have === want) continue;
2009
2047
  ctx.report({
2010
2048
  rule: "version-skew",
@@ -2138,9 +2176,11 @@ function satisfies(version, range) {
2138
2176
 
2139
2177
  // src/doctor/installs.ts
2140
2178
  var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
2179
+ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
2180
+ var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
2141
2181
  var readManifest = (dir) => {
2142
2182
  try {
2143
- return JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8"));
2183
+ return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
2144
2184
  } catch {
2145
2185
  return null;
2146
2186
  }
@@ -2157,10 +2197,10 @@ function packagesIn(nodeModules) {
2157
2197
  const out = [];
2158
2198
  for (const entry of readdirSync(nodeModules)) {
2159
2199
  if (entry.startsWith(".")) continue;
2160
- const p = path3.join(nodeModules, entry);
2200
+ const p = path14.join(nodeModules, entry);
2161
2201
  if (entry.startsWith("@")) {
2162
2202
  try {
2163
- for (const sub of readdirSync(p)) out.push(path3.join(p, sub));
2203
+ for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
2164
2204
  } catch {
2165
2205
  }
2166
2206
  } else {
@@ -2172,44 +2212,70 @@ function packagesIn(nodeModules) {
2172
2212
  function genesisInstalls(root) {
2173
2213
  const copies = /* @__PURE__ */ new Map();
2174
2214
  const realRoot = real(root);
2175
- const rel = (abs) => path3.relative(realRoot, abs).split(path3.sep).join("/") || ".";
2176
- const record = (real2, manifest, by, range) => {
2215
+ const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
2216
+ const via = /* @__PURE__ */ new Map();
2217
+ const record = (real2, manifest, by, range, root2) => {
2177
2218
  let copy = copies.get(real2);
2178
2219
  if (!copy) {
2179
- copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
2220
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
2180
2221
  copies.set(real2, copy);
2222
+ via.set(real2, /* @__PURE__ */ new Set());
2181
2223
  }
2224
+ via.get(real2).add(root2);
2182
2225
  if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
2183
2226
  };
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 ?? "?"}` });
2227
+ const walk = (kind, roots) => {
2228
+ const expanded = /* @__PURE__ */ new Set();
2229
+ const queue = [];
2230
+ const visit = (dir, by, range) => {
2231
+ const manifest = readManifest(dir);
2232
+ if (!manifest?.name) return;
2233
+ if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
2234
+ const realDir = real(dir);
2235
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
2236
+ if (expanded.has(realDir)) return;
2237
+ expanded.add(realDir);
2238
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
2239
+ };
2240
+ for (const r of roots) visit(r.dir, r.by, r.range);
2241
+ while (queue.length) {
2242
+ const { real: from, manifest, label } = queue.shift();
2243
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
2244
+ for (const [name, range] of Object.entries(deps)) {
2245
+ const dir = findPackageDir(from, name);
2246
+ if (dir) visit(dir, label, range);
2247
+ }
2248
+ }
2194
2249
  };
2195
- const app = readManifest(root);
2196
- const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
2197
- for (const name of Object.keys(appDeps)) {
2250
+ const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
2198
2251
  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
- }
2252
+ return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
2253
+ });
2254
+ const app = readManifest(root);
2255
+ const declaredDev = Object.entries(app?.devDependencies ?? {});
2256
+ const runtimeDeps = {
2257
+ ...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
2258
+ ...app?.peerDependencies,
2259
+ ...app?.optionalDependencies,
2260
+ ...app?.dependencies
2261
+ };
2262
+ const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
2263
+ walk("runtime", rootsOf(runtimeDeps, "the app"));
2264
+ const top = path14.join(root, "node_modules");
2265
+ walk(
2266
+ "hoisted",
2267
+ packagesIn(top).filter((dir) => {
2268
+ const name = path14.relative(top, dir).split(path14.sep).join("/");
2269
+ return !(name in runtimeDeps) && !(name in devDeps);
2270
+ }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
2271
+ );
2272
+ const devRoots = { ...devDeps };
2273
+ for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
2274
+ walk("dev", rootsOf(devRoots, "the app (dev)"));
2275
+ for (const [key2, copy] of copies) {
2276
+ const kinds = via.get(key2);
2277
+ copy.runtime = kinds.has("runtime");
2278
+ copy.devOnly = kinds.size === 1 && kinds.has("dev");
2213
2279
  }
2214
2280
  const byName = /* @__PURE__ */ new Map();
2215
2281
  for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
@@ -2217,20 +2283,31 @@ function genesisInstalls(root) {
2217
2283
  return byName;
2218
2284
  }
2219
2285
  function checkDuplicatePackages(ctx) {
2286
+ const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
2220
2287
  for (const [name, copies] of genesisInstalls(ctx.root)) {
2221
2288
  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(", ");
2289
+ const shipping = copies.filter((c) => c.runtime);
2290
+ if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
2291
+ ctx.report({
2292
+ rule: "duplicate-genesis-package",
2293
+ level: "warn",
2294
+ file: "package.json",
2295
+ subject: name,
2296
+ 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`
2297
+ });
2298
+ continue;
2299
+ }
2223
2300
  ctx.report({
2224
2301
  rule: "duplicate-genesis-package",
2225
- level: "warn",
2302
+ level: "info",
2226
2303
  file: "package.json",
2227
2304
  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`
2305
+ 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`
2229
2306
  });
2230
2307
  }
2231
2308
  }
2232
2309
  function checkPeerRanges(ctx) {
2233
- const rel = (abs) => path3.relative(ctx.root, abs).split(path3.sep).join("/");
2310
+ const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
2234
2311
  for (const copies of genesisInstalls(ctx.root).values()) {
2235
2312
  for (const copy of copies) {
2236
2313
  const dir = copy.absolutePath;
@@ -2243,7 +2320,8 @@ function checkPeerRanges(ctx) {
2243
2320
  if (satisfies(installed, range) !== false) continue;
2244
2321
  ctx.report({
2245
2322
  rule: "peer-range-mismatch",
2246
- level: "warn",
2323
+ // A dev tool's own tree (the CLI's) doesn't run in the app.
2324
+ level: copy.devOnly ? "info" : "warn",
2247
2325
  file: "package.json",
2248
2326
  subject: `${copy.name}>${peer}`,
2249
2327
  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}`
@@ -2252,55 +2330,466 @@ function checkPeerRanges(ctx) {
2252
2330
  }
2253
2331
  }
2254
2332
  }
2333
+ var TRAIL_DEPTH = 6;
2334
+ var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
2335
+ var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
2336
+ var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
2337
+ var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
2338
+ function stripForImports(code) {
2339
+ const out = [];
2340
+ const blank = (ch) => ch === "\n" ? "\n" : " ";
2341
+ const n = code.length;
2342
+ const templates = [];
2343
+ let depth = 0;
2344
+ let i = 0;
2345
+ let sure = true;
2346
+ const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
2347
+ const before = () => out.slice(-24).join("");
2348
+ const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
2349
+ const startsExpression = (b) => {
2350
+ const t = b.replace(/\s+$/, "");
2351
+ if (!t) return true;
2352
+ if (KEYWORD.test(b)) return true;
2353
+ return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
2354
+ };
2355
+ const exprStart = () => startsExpression(before());
2356
+ const taggedTemplate = () => {
2357
+ const b = out.slice(-48).join("");
2358
+ const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
2359
+ return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
2360
+ };
2361
+ const templateBody = () => {
2362
+ while (i < n) {
2363
+ const ch = code[i];
2364
+ if (ch === "\\") {
2365
+ out.push(" ", blank(code[i + 1] ?? ""));
2366
+ i += 2;
2367
+ } else if (ch === "`") {
2368
+ out.push("`");
2369
+ i++;
2370
+ return;
2371
+ } else if (ch === "$" && code[i + 1] === "{") {
2372
+ out.push("${");
2373
+ i += 2;
2374
+ templates.push(depth);
2375
+ depth++;
2376
+ return;
2377
+ } else {
2378
+ out.push(blank(ch));
2379
+ i++;
2380
+ }
2381
+ }
2382
+ sure = false;
2383
+ };
2384
+ while (i < n && sure) {
2385
+ const ch = code[i];
2386
+ const next = code[i + 1];
2387
+ if (ch === "/" && next === "/") {
2388
+ while (i < n && code[i] !== "\n") {
2389
+ out.push(" ");
2390
+ i++;
2391
+ }
2392
+ } else if (ch === "/" && next === "*") {
2393
+ out.push(" ");
2394
+ i += 2;
2395
+ while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
2396
+ out.push(blank(code[i]));
2397
+ i++;
2398
+ }
2399
+ if (i < n) {
2400
+ out.push(" ");
2401
+ i += 2;
2402
+ }
2403
+ } else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
2404
+ const afterBrace = /[}>]\s*$/.test(before());
2405
+ const start = i;
2406
+ const mark = out.length;
2407
+ out.push("/");
2408
+ i++;
2409
+ let inClass = false;
2410
+ for (; ; ) {
2411
+ const c = code[i];
2412
+ if (c === void 0 || c === "\n") {
2413
+ if (afterBrace) {
2414
+ out.length = mark;
2415
+ out.push("/");
2416
+ i = start + 1;
2417
+ } else sure = false;
2418
+ break;
2419
+ }
2420
+ if (c === "\\") {
2421
+ out.push(" ", blank(code[i + 1] ?? ""));
2422
+ i += 2;
2423
+ continue;
2424
+ }
2425
+ i++;
2426
+ if (c === "[") inClass = true;
2427
+ else if (c === "]") inClass = false;
2428
+ else if (c === "/" && !inClass) {
2429
+ if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
2430
+ out.length = mark;
2431
+ out.push("/");
2432
+ i = start + 1;
2433
+ break;
2434
+ }
2435
+ out.push("/");
2436
+ break;
2437
+ }
2438
+ out.push(" ");
2439
+ }
2440
+ if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
2441
+ } else if ((ch === '"' || ch === "'") && exprStart()) {
2442
+ const keep = isSpecifier();
2443
+ out.push(ch);
2444
+ i++;
2445
+ while (i < n && code[i] !== ch && code[i] !== "\n") {
2446
+ if (code[i] === "\\") {
2447
+ out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
2448
+ i += 2;
2449
+ } else {
2450
+ out.push(keep ? code[i] : blank(code[i]));
2451
+ i++;
2452
+ }
2453
+ }
2454
+ if (code[i] !== ch) sure = false;
2455
+ else {
2456
+ out.push(code[i]);
2457
+ i++;
2458
+ }
2459
+ } else if (ch === "`" && (exprStart() || taggedTemplate())) {
2460
+ out.push("`");
2461
+ i++;
2462
+ templateBody();
2463
+ } else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
2464
+ templates.pop();
2465
+ depth--;
2466
+ out.push("}");
2467
+ i++;
2468
+ templateBody();
2469
+ } else {
2470
+ if (ch === "{") depth++;
2471
+ else if (ch === "}") depth--;
2472
+ out.push(ch);
2473
+ i++;
2474
+ }
2475
+ }
2476
+ return sure && templates.length === 0 ? out.join("") : null;
2477
+ }
2478
+ function bindings(clause) {
2479
+ const out = [];
2480
+ const named = /\{([^}]*)\}/.exec(clause);
2481
+ for (const part of named?.[1].split(",") ?? []) {
2482
+ const p = part.trim();
2483
+ if (!p || p.startsWith("type ")) continue;
2484
+ out.push(p.split(/\s+as\s+/).pop().trim());
2485
+ }
2486
+ const rest = clause.replace(/\{[^}]*\}/, "");
2487
+ const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
2488
+ if (ns) out.push(ns[1]);
2489
+ const def = /^\s*([\w$]+)/.exec(rest);
2490
+ if (def && def[1] !== "as") out.push(def[1]);
2491
+ return out;
2492
+ }
2493
+ function readJsonc(file) {
2494
+ try {
2495
+ const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
2496
+ return JSON.parse(text);
2497
+ } catch {
2498
+ return null;
2499
+ }
2500
+ }
2501
+ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
2502
+ if (seen.has(file) || seen.size > 10) return {};
2503
+ seen.add(file);
2504
+ const json = readJsonc(file);
2505
+ if (!json) return {};
2506
+ const dir = path14.dirname(file);
2507
+ let merged = {};
2508
+ const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
2509
+ for (const ext of parents) {
2510
+ if (typeof ext !== "string") continue;
2511
+ let target = null;
2512
+ if (ext.startsWith(".") || path14.isAbsolute(ext)) {
2513
+ const abs = path14.resolve(dir, ext);
2514
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
2515
+ } else {
2516
+ const parts = ext.split("/");
2517
+ const nameLength = ext.startsWith("@") ? 2 : 1;
2518
+ const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
2519
+ if (pkgDir) {
2520
+ const sub = parts.slice(nameLength).join("/");
2521
+ const abs = path14.join(pkgDir, sub || "tsconfig.json");
2522
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
2523
+ }
2524
+ }
2525
+ if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
2526
+ }
2527
+ const opts = json.compilerOptions ?? {};
2528
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
2529
+ if (opts.paths && typeof opts.paths === "object") {
2530
+ merged.paths = opts.paths;
2531
+ merged.pathsDir = dir;
2532
+ }
2533
+ return merged;
2534
+ }
2535
+ function aliases(root) {
2536
+ const table = [];
2537
+ let baseUrl = null;
2538
+ for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
2539
+ const file = path14.join(root, name);
2540
+ if (!existsSync(file)) continue;
2541
+ const config = readTsconfig(root, file);
2542
+ baseUrl ??= config.baseUrl ?? null;
2543
+ const base = config.baseUrl ?? config.pathsDir ?? root;
2544
+ for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
2545
+ if (!Array.isArray(targets)) continue;
2546
+ const exact = !pattern.endsWith("*");
2547
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
2548
+ }
2549
+ }
2550
+ const pkg = readJsonc(path14.join(root, "package.json"));
2551
+ for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
2552
+ if (typeof target !== "string") continue;
2553
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
2554
+ }
2555
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
2556
+ return { table, baseUrl };
2557
+ }
2558
+ function resolveFile(base) {
2559
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
2560
+ if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
2561
+ for (const p of tries) {
2562
+ if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
2563
+ }
2564
+ return null;
2565
+ }
2566
+ var trails = /* @__PURE__ */ new WeakMap();
2567
+ function trailFor(ctx) {
2568
+ let t = trails.get(ctx.files);
2569
+ if (!t) trails.set(ctx.files, t = createTrail(ctx));
2570
+ return t;
2571
+ }
2572
+ function createTrail(ctx) {
2573
+ const { table, baseUrl } = aliases(ctx.root);
2574
+ let declared = null;
2575
+ try {
2576
+ const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
2577
+ declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
2578
+ } catch {
2579
+ declared = null;
2580
+ }
2581
+ const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2582
+ const read = (abs) => byPath.get(abs) ?? readSource(abs);
2583
+ const importsCache = /* @__PURE__ */ new Map();
2584
+ const importsOf = (file) => {
2585
+ const hit = importsCache.get(file.absolutePath);
2586
+ if (hit) return hit;
2587
+ const files = [];
2588
+ let lost = false;
2589
+ const code = stripped(file);
2590
+ if (code === null) {
2591
+ const out2 = { files: [], lost: true };
2592
+ importsCache.set(file.absolutePath, out2);
2593
+ return out2;
2594
+ }
2595
+ const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
2596
+ for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
2597
+ for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
2598
+ 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]);
2599
+ const specs = [];
2600
+ for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
2601
+ for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
2602
+ for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
2603
+ for (const spec of specs) {
2604
+ if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
2605
+ let resolved = null;
2606
+ if (spec.startsWith(".")) {
2607
+ resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
2608
+ if (!resolved) lost = true;
2609
+ } else {
2610
+ const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
2611
+ if (alias) {
2612
+ for (const t of alias.targets) {
2613
+ resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
2614
+ if (resolved) break;
2615
+ }
2616
+ }
2617
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
2618
+ if (!resolved) {
2619
+ const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
2620
+ if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
2621
+ }
2622
+ }
2623
+ if (resolved && !files.includes(resolved)) files.push(resolved);
2624
+ }
2625
+ const out = { files, lost };
2626
+ importsCache.set(file.absolutePath, out);
2627
+ return out;
2628
+ };
2629
+ const strippedCache = /* @__PURE__ */ new Map();
2630
+ const stripped = (file) => {
2631
+ if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
2632
+ return strippedCache.get(file.absolutePath);
2633
+ };
2634
+ const memo = /* @__PURE__ */ new WeakMap();
2635
+ const reach = (file, test2, depth, seen) => {
2636
+ let cache = memo.get(test2);
2637
+ if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
2638
+ const k = `${file.absolutePath}\0${depth}`;
2639
+ const free = cache.free.get(k);
2640
+ if (free) return [free, /* @__PURE__ */ new Set()];
2641
+ const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
2642
+ if (reusable) return [reusable.result, new Set(reusable.cut)];
2643
+ let result;
2644
+ const cut = /* @__PURE__ */ new Set();
2645
+ const code = stripped(file);
2646
+ if (code === null) result = "unknown";
2647
+ else if (test2(code)) result = "yes";
2648
+ else {
2649
+ const { files, lost } = importsOf(file);
2650
+ let unknown = lost && depth > 0;
2651
+ result = "no";
2652
+ if (depth > 0) {
2653
+ seen.add(file.absolutePath);
2654
+ for (const abs of files) {
2655
+ if (seen.has(abs)) {
2656
+ cut.add(abs);
2657
+ continue;
2658
+ }
2659
+ const target = read(abs);
2660
+ if (!target) {
2661
+ unknown = true;
2662
+ continue;
2663
+ }
2664
+ const [r, c] = reach(target, test2, depth - 1, seen);
2665
+ for (const m of c) cut.add(m);
2666
+ if (r === "yes") {
2667
+ result = "yes";
2668
+ break;
2669
+ }
2670
+ if (r === "unknown") unknown = true;
2671
+ }
2672
+ seen.delete(file.absolutePath);
2673
+ cut.delete(file.absolutePath);
2674
+ }
2675
+ if (result === "no" && unknown) result = "unknown";
2676
+ }
2677
+ if (result === "yes" || cut.size === 0) {
2678
+ cache.free.set(k, result);
2679
+ return [result, /* @__PURE__ */ new Set()];
2680
+ }
2681
+ const entries = cache.cut.get(k) ?? [];
2682
+ entries.push({ cut: [...cut], result });
2683
+ cache.cut.set(k, entries);
2684
+ return [result, cut];
2685
+ };
2686
+ return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
2687
+ }
2688
+
2689
+ // src/doctor/routes.ts
2255
2690
  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"]);
2691
+ var STEMS = {
2692
+ tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
2693
+ "next-app": {
2694
+ layout: /* @__PURE__ */ new Set(["layout"]),
2695
+ index: /* @__PURE__ */ new Set(["page"]),
2696
+ skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
2697
+ },
2698
+ "next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
2699
+ };
2258
2700
  var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
2259
2701
  var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
2702
+ var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
2703
+ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
2704
+ 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;
2260
2705
  function routesDir(ctx) {
2261
2706
  if (ctx.config.routesDir) return ctx.config.routesDir;
2262
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path3.join(ctx.root, d))) ?? null;
2707
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
2263
2708
  }
2264
2709
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
2710
+ function flavorOf(dir, rels) {
2711
+ const stems = rels.map((r) => r.split("/").pop());
2712
+ if (stems.includes("__root")) return "tanstack";
2713
+ if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
2714
+ if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
2715
+ return "tanstack";
2716
+ }
2717
+ function renders(code) {
2718
+ const elements = renderedElements(code);
2719
+ if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
2720
+ const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
2721
+ const named = COMPONENT_OPTION.exec(code)?.[1];
2722
+ if (named && !definedHere(named)) return true;
2723
+ if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
2724
+ const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
2725
+ return exported !== void 0 && !definedHere(exported);
2726
+ }
2265
2727
  function webRoutes(ctx) {
2266
2728
  const dir = routesDir(ctx);
2267
2729
  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(/\.[^.]+$/, "");
2730
+ 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(/\.[^.]+$/, "") }));
2731
+ const flavor = flavorOf(dir, candidates.map((c) => c.rel));
2732
+ const stems = STEMS[flavor];
2733
+ const groups = /* @__PURE__ */ new Map();
2734
+ for (const { file, rel } of candidates) {
2272
2735
  const parts = rel.split("/");
2273
2736
  if (parts.some((p) => p.startsWith("-"))) continue;
2737
+ if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
2738
+ if (flavor === "next-pages" && parts[0] === "api") continue;
2739
+ if (stems.skip.test(parts.at(-1))) continue;
2740
+ if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
2741
+ const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
2742
+ groups.set(id, [...groups.get(id) ?? [], file]);
2743
+ }
2744
+ const trail = trailFor(ctx);
2745
+ const routes = [];
2746
+ for (const [id, files] of groups) {
2747
+ const parts = id.split("/");
2274
2748
  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) ?? "")) {
2749
+ const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
2750
+ const named = stems.layout.has(stem) || stems.index.has(stem);
2751
+ const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
2752
+ const segments = [...folders, ...own];
2753
+ const tree = [...parts, ...own];
2754
+ let index = stems.index.has(stem);
2755
+ if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
2278
2756
  segments.pop();
2757
+ tree.pop();
2279
2758
  index = true;
2280
2759
  }
2281
- const elements = renderedElements(file.code);
2282
- const layout = LAYOUT_STEMS.has(stem) || elements.includes("Outlet");
2760
+ const code = files.map((f) => f.code).join("\n");
2761
+ const elements = renderedElements(code);
2762
+ const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
2763
+ const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
2764
+ const layout = stems.layout.has(stem) || pathless || outlet;
2765
+ const rendering = renders(code);
2766
+ const ownContent = new RegExp(OWN_CONTENT).test(code);
2767
+ const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
2768
+ const page = !pure && !pathless && (!layout || ownContent);
2283
2769
  routes.push({
2284
- file,
2770
+ file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
2771
+ files,
2285
2772
  segments,
2773
+ tree,
2286
2774
  index,
2287
2775
  layout,
2288
- detail: !index && !layout && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
2289
- redirectOnly: elements.every((e) => NON_PAGE_ELEMENTS.has(e)) && !HTML_ELEMENT.test(file.code),
2776
+ page,
2777
+ detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
2778
+ redirectOnly: !rendering,
2290
2779
  parents: []
2291
2780
  });
2292
2781
  }
2293
2782
  for (const r of routes) {
2294
- const own = r.segments;
2783
+ const own = r.tree;
2295
2784
  for (const p of routes) {
2296
2785
  if (p === r || !p.layout) continue;
2297
- const n = p.segments.length;
2786
+ const n = p.tree.length;
2298
2787
  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;
2788
+ if (key(own.slice(0, n)) !== key(p.tree)) continue;
2789
+ if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
2301
2790
  r.parents.push(p);
2302
2791
  }
2303
- r.parents.sort((a, b) => b.segments.length - a.segments.length);
2792
+ r.parents.sort((a, b) => b.tree.length - a.tree.length);
2304
2793
  }
2305
2794
  return routes;
2306
2795
  }
@@ -2318,8 +2807,19 @@ var rendersRe = (names) => {
2318
2807
  const list = [...names];
2319
2808
  return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
2320
2809
  };
2810
+ function routeReach(ctx, r, test2) {
2811
+ const trail = trailFor(ctx);
2812
+ let unknown = false;
2813
+ for (const f of r.files) {
2814
+ const got = trail.reach(f, test2);
2815
+ if (got === "yes") return "yes";
2816
+ if (got === "unknown") unknown = true;
2817
+ }
2818
+ return unknown ? "unknown" : "no";
2819
+ }
2820
+ var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
2321
2821
  function insideShell(ctx, routes) {
2322
- const shell = new Set(routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => SHELL.test(code))));
2822
+ const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
2323
2823
  const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
2324
2824
  return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
2325
2825
  }
@@ -2330,20 +2830,19 @@ function checkHandRolledSubNav(ctx) {
2330
2830
  const inShell = insideShell(ctx, routes);
2331
2831
  const ui = ctx.genesis.uiPackage;
2332
2832
  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;
2833
+ if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
2834
+ 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);
2835
+ if (hit) {
2836
+ const { f, m } = hit;
2837
+ const code = f.code;
2338
2838
  ctx.report({
2339
2839
  rule: "hand-rolled-sub-nav",
2340
2840
  level: "warn",
2341
- file: r.file.path,
2841
+ file: f.path,
2342
2842
  line: lineAt(code, m.index),
2343
2843
  subject: m[1],
2344
2844
  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
2845
  });
2346
- break;
2347
2846
  }
2348
2847
  }
2349
2848
  }
@@ -2391,11 +2890,12 @@ function checkResourceWorkspaces(ctx) {
2391
2890
  byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
2392
2891
  }
2393
2892
  for (const [dir, routes] of byFolder) {
2394
- const has = routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => header.test(code)));
2893
+ const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
2894
+ const has = routes.filter((r) => reach.get(r) === "yes");
2395
2895
  if (has.length === 0) continue;
2396
2896
  const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
2397
2897
  for (const r of routes) {
2398
- if (has.includes(r)) continue;
2898
+ if (reach.get(r) !== "no") continue;
2399
2899
  ctx.report({
2400
2900
  rule: "resource-workspace",
2401
2901
  level: "info",
@@ -2419,14 +2919,14 @@ function checkPageLayouts(ctx) {
2419
2919
  };
2420
2920
  const cache = /* @__PURE__ */ new Map();
2421
2921
  const provides = (r) => {
2422
- if (!cache.has(r)) cache.set(r, viaOneImport(ctx.root, ctx.files, r.file, rendersLayout));
2922
+ if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
2423
2923
  return cache.get(r);
2424
2924
  };
2425
2925
  const list = [...layouts].sort();
2426
2926
  const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
2427
2927
  for (const r of routes) {
2428
- if (r.layout || r.redirectOnly || !inShell(r)) continue;
2429
- if (provides(r) || r.parents.some(provides)) continue;
2928
+ if (!r.page || r.redirectOnly || !inShell(r)) continue;
2929
+ if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
2430
2930
  ctx.report({
2431
2931
  rule: "page-layout",
2432
2932
  level: "warn",
@@ -2457,7 +2957,7 @@ function checkIsoDateSlices(ctx) {
2457
2957
 
2458
2958
  // src/doctor/index.ts
2459
2959
  async function runDoctor(options = {}) {
2460
- const root = path3.resolve(options.root ?? process.cwd());
2960
+ const root = path14.resolve(options.root ?? process.cwd());
2461
2961
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
2462
2962
  const config = loaded.config;
2463
2963
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -2637,15 +3137,15 @@ ${formatProblems(result)}`);
2637
3137
  }
2638
3138
  }
2639
3139
  };
2640
- const explicit = /* @__PURE__ */ new Set([path3.join(root, "genesis.config.json"), ...options.configPath ? [path3.resolve(root, options.configPath)] : []]);
3140
+ const explicit = /* @__PURE__ */ new Set([path14.join(root, "genesis.config.json"), ...options.configPath ? [path14.resolve(root, options.configPath)] : []]);
2641
3141
  try {
2642
3142
  const { config } = loadConfig(root, options.configPath);
2643
- if (config.rulesDoc) explicit.add(path3.resolve(root, config.rulesDoc));
3143
+ if (config.rulesDoc) explicit.add(path14.resolve(root, config.rulesDoc));
2644
3144
  } catch {
2645
3145
  }
2646
3146
  const schedule = (file) => {
2647
- if (!explicit.has(path3.resolve(file))) {
2648
- const rel = path3.relative(root, file).split(path3.sep).join("/");
3147
+ if (!explicit.has(path14.resolve(file))) {
3148
+ const rel = path14.relative(root, file).split(path14.sep).join("/");
2649
3149
  if (rel.startsWith("..") || rel.includes("node_modules/")) return;
2650
3150
  }
2651
3151
  clearTimeout(timer);