@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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'module';
2
2
  import { studioSetupSql } from '@marktiderman/genesis-studio-server';
3
- import * as path3 from 'path';
3
+ import * as path14 from 'path';
4
4
  import { spawnSync } from 'child_process';
5
5
  import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
6
6
  import { pathToFileURL } from 'url';
@@ -101,9 +101,9 @@ async function runScaffold(opts, fs) {
101
101
  function joinPath(...parts) {
102
102
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
103
103
  }
104
- function dirname(path16) {
105
- const idx = path16.lastIndexOf("/");
106
- return idx === -1 ? "." : path16.slice(0, idx);
104
+ function dirname(path17) {
105
+ const idx = path17.lastIndexOf("/");
106
+ return idx === -1 ? "." : path17.slice(0, idx);
107
107
  }
108
108
  function brandPackageJson(consumer, genesisVersion) {
109
109
  return JSON.stringify(
@@ -960,19 +960,19 @@ ${line}
960
960
  var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
961
961
  function buildCommands(root, config) {
962
962
  if (config.build) return config.build;
963
- const pkgFile = path3.join(root, "package.json");
963
+ const pkgFile = path14.join(root, "package.json");
964
964
  const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
965
965
  const pm = packageManager(root);
966
966
  return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
967
967
  }
968
968
  function packageManager(root) {
969
- let dir = path3.resolve(root);
969
+ let dir = path14.resolve(root);
970
970
  for (; ; ) {
971
- if (existsSync(path3.join(dir, "pnpm-lock.yaml"))) return "pnpm";
972
- if (existsSync(path3.join(dir, "bun.lock")) || existsSync(path3.join(dir, "bun.lockb"))) return "bun";
973
- if (existsSync(path3.join(dir, "yarn.lock"))) return "yarn";
974
- if (existsSync(path3.join(dir, "package-lock.json"))) return "npm";
975
- const parent = path3.dirname(dir);
971
+ if (existsSync(path14.join(dir, "pnpm-lock.yaml"))) return "pnpm";
972
+ if (existsSync(path14.join(dir, "bun.lock")) || existsSync(path14.join(dir, "bun.lockb"))) return "bun";
973
+ if (existsSync(path14.join(dir, "yarn.lock"))) return "yarn";
974
+ if (existsSync(path14.join(dir, "package-lock.json"))) return "npm";
975
+ const parent = path14.dirname(dir);
976
976
  if (parent === dir) return "npm";
977
977
  dir = parent;
978
978
  }
@@ -1079,25 +1079,25 @@ var PACK_KEYS = {
1079
1079
  };
1080
1080
  function appPath(v, where, fail) {
1081
1081
  if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
1082
- if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
1083
- const norm = path3.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1082
+ if (path14.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
1083
+ const norm = path14.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1084
1084
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
1085
1085
  return norm;
1086
1086
  }
1087
1087
  function loadConfig(root, configPath) {
1088
1088
  if (configPath) {
1089
- const file = path3.resolve(root, configPath);
1089
+ const file = path14.resolve(root, configPath);
1090
1090
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
1091
1091
  const json = readJson(file);
1092
- const block = path3.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
1093
- return { config: validateConfig(block ?? {}, file), file, dir: path3.dirname(file) };
1092
+ const block = path14.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
1093
+ return { config: validateConfig(block ?? {}, file), file, dir: path14.dirname(file) };
1094
1094
  }
1095
- const own = path3.join(root, "genesis.config.json");
1095
+ const own = path14.join(root, "genesis.config.json");
1096
1096
  if (existsSync(own)) {
1097
1097
  const block = readGenesisConfig(root)?.raw.doctor;
1098
1098
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
1099
1099
  }
1100
- const pkg = path3.join(root, "package.json");
1100
+ const pkg = path14.join(root, "package.json");
1101
1101
  if (existsSync(pkg)) {
1102
1102
  const block = readJson(pkg)?.genesis?.doctor;
1103
1103
  if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -1112,7 +1112,7 @@ function readJson(file) {
1112
1112
  }
1113
1113
  }
1114
1114
  function readGenesisConfig(root) {
1115
- const file = path3.join(root, "genesis.config.json");
1115
+ const file = path14.join(root, "genesis.config.json");
1116
1116
  if (!existsSync(file)) return null;
1117
1117
  const raw = readJson(file);
1118
1118
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -1314,7 +1314,7 @@ function globToRegExp(glob) {
1314
1314
  }
1315
1315
  function globMatcher(globs) {
1316
1316
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1317
- return (path16) => res.some((re) => re.test(path16));
1317
+ return (path17) => res.some((re) => re.test(path17));
1318
1318
  }
1319
1319
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1320
1320
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -1354,11 +1354,11 @@ var TAILWIND_PALETTE = [
1354
1354
  "olive"
1355
1355
  ];
1356
1356
  function findPackageDir(from, name) {
1357
- let dir = path3.resolve(from);
1357
+ let dir = path14.resolve(from);
1358
1358
  for (; ; ) {
1359
- const candidate = path3.join(dir, "node_modules", name);
1360
- if (existsSync(path3.join(candidate, "package.json"))) return candidate;
1361
- const parent = path3.dirname(dir);
1359
+ const candidate = path14.join(dir, "node_modules", name);
1360
+ if (existsSync(path14.join(candidate, "package.json"))) return candidate;
1361
+ const parent = path14.dirname(dir);
1362
1362
  if (parent === dir) return null;
1363
1363
  dir = parent;
1364
1364
  }
@@ -1410,7 +1410,7 @@ function loadCompanions(root, config, uiPackage) {
1410
1410
  function readPackageExports(root, uiPackage) {
1411
1411
  const uiDir = findPackageDir(root, uiPackage);
1412
1412
  if (!uiDir) return null;
1413
- const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
1413
+ const uiPkg = JSON.parse(readFileSync(path14.join(uiDir, "package.json"), "utf8"));
1414
1414
  const typeEntries = /* @__PURE__ */ new Set();
1415
1415
  const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
1416
1416
  if (typeof mainTypes === "string") typeEntries.add(mainTypes);
@@ -1422,7 +1422,7 @@ function readPackageExports(root, uiPackage) {
1422
1422
  const reexportedPackages = /* @__PURE__ */ new Set();
1423
1423
  let readAny = false;
1424
1424
  for (const entry of typeEntries) {
1425
- const file = path3.join(uiDir, entry);
1425
+ const file = path14.join(uiDir, entry);
1426
1426
  if (!existsSync(file)) continue;
1427
1427
  readAny = true;
1428
1428
  const dts = readFileSync(file, "utf8");
@@ -1436,11 +1436,11 @@ function readPackageExports(root, uiPackage) {
1436
1436
  }
1437
1437
  const valueDecls = /* @__PURE__ */ new Set();
1438
1438
  const typeDecls = /* @__PURE__ */ new Set();
1439
- const declRoot = typeof mainTypes === "string" ? path3.dirname(path3.join(uiDir, mainTypes)) : uiDir;
1439
+ const declRoot = typeof mainTypes === "string" ? path14.dirname(path14.join(uiDir, mainTypes)) : uiDir;
1440
1440
  const declFiles = walkDts(declRoot);
1441
1441
  for (const pkg of reexportedPackages) {
1442
1442
  const dir = findPackageDir(uiDir, pkg);
1443
- if (dir) walkDts(path3.join(dir, "dist"), declFiles);
1443
+ if (dir) walkDts(path14.join(dir, "dist"), declFiles);
1444
1444
  }
1445
1445
  for (const file of declFiles) {
1446
1446
  const text = readFileSync(file, "utf8");
@@ -1486,7 +1486,7 @@ function walkDts(dir, out = []) {
1486
1486
  if (!existsSync(dir)) return out;
1487
1487
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
1488
1488
  if (entry.name === "node_modules") continue;
1489
- const p = path3.join(dir, entry.name);
1489
+ const p = path14.join(dir, entry.name);
1490
1490
  if (entry.isDirectory()) walkDts(p, out);
1491
1491
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
1492
1492
  }
@@ -1503,27 +1503,27 @@ function resolveThemeFiles(root, config, uiDir) {
1503
1503
  }
1504
1504
  const files = [];
1505
1505
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
1506
- const themes = ds && path3.join(ds, "dist", "themes");
1506
+ const themes = ds && path14.join(ds, "dist", "themes");
1507
1507
  if (themes && existsSync(themes)) {
1508
- for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path3.join(themes, name));
1508
+ for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path14.join(themes, name));
1509
1509
  }
1510
1510
  if (files.length === 0) {
1511
1511
  throw new DoctorConfigError(
1512
1512
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
1513
1513
  );
1514
1514
  }
1515
- const uiStyles = path3.join(uiDir, "dist", "styles.css");
1515
+ const uiStyles = path14.join(uiDir, "dist", "styles.css");
1516
1516
  if (existsSync(uiStyles)) files.push(uiStyles);
1517
1517
  return files;
1518
1518
  }
1519
1519
  function resolveSpec(root, spec) {
1520
- const local = path3.resolve(root, spec);
1521
- if (spec.startsWith(".") || path3.isAbsolute(spec)) return existsSync(local) ? local : null;
1520
+ const local = path14.resolve(root, spec);
1521
+ if (spec.startsWith(".") || path14.isAbsolute(spec)) return existsSync(local) ? local : null;
1522
1522
  const parts = spec.split("/");
1523
1523
  const nameLength = spec.startsWith("@") ? 2 : 1;
1524
1524
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
1525
1525
  if (dir) {
1526
- const file = path3.join(dir, ...parts.slice(nameLength));
1526
+ const file = path14.join(dir, ...parts.slice(nameLength));
1527
1527
  if (existsSync(file) && statSync(file).isFile()) return file;
1528
1528
  }
1529
1529
  return existsSync(local) ? local : null;
@@ -1531,7 +1531,7 @@ function resolveSpec(root, spec) {
1531
1531
  function loadPalette(root) {
1532
1532
  const names = new Set(TAILWIND_PALETTE);
1533
1533
  try {
1534
- const req = createRequire(path3.join(root, "package.json"));
1534
+ const req = createRequire(path14.join(root, "package.json"));
1535
1535
  const colors = req("tailwindcss/colors");
1536
1536
  for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
1537
1537
  if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
@@ -1716,16 +1716,16 @@ var DEFAULT_IGNORE = [
1716
1716
  ];
1717
1717
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
1718
1718
  var MAX_FILE_BYTES = 2 * 1024 * 1024;
1719
- var toPosix = (p) => p.split(path3.sep).join("/");
1719
+ var toPosix = (p) => p.split(path14.sep).join("/");
1720
1720
  function scanFiles(root, config) {
1721
1721
  const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
1722
1722
  const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
1723
1723
  const files = [];
1724
1724
  const seen = /* @__PURE__ */ new Set();
1725
1725
  const visit = (abs) => {
1726
- const rel = toPosix(path3.relative(root, abs));
1726
+ const rel = toPosix(path14.relative(root, abs));
1727
1727
  if (seen.has(rel) || ignored(rel)) return;
1728
- const ext = path3.extname(abs);
1728
+ const ext = path14.extname(abs);
1729
1729
  if (!extensions.has(ext)) return;
1730
1730
  if (statSync(abs).size > MAX_FILE_BYTES) return;
1731
1731
  seen.add(rel);
@@ -1735,14 +1735,14 @@ function scanFiles(root, config) {
1735
1735
  const walk = (dir) => {
1736
1736
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
1737
1737
  if (entry.isDirectory()) {
1738
- if (!SKIP_DIRS.has(entry.name)) walk(path3.join(dir, entry.name));
1738
+ if (!SKIP_DIRS.has(entry.name)) walk(path14.join(dir, entry.name));
1739
1739
  } else if (entry.isFile()) {
1740
- visit(path3.join(dir, entry.name));
1740
+ visit(path14.join(dir, entry.name));
1741
1741
  }
1742
1742
  }
1743
1743
  };
1744
1744
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
1745
- const abs = path3.resolve(root, src);
1745
+ const abs = path14.resolve(root, src);
1746
1746
  if (!existsSync(abs)) continue;
1747
1747
  if (statSync(abs).isDirectory()) walk(abs);
1748
1748
  else visit(abs);
@@ -1819,7 +1819,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
1819
1819
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
1820
1820
  let all = compiled;
1821
1821
  if (rulesDoc) {
1822
- const file = path3.resolve(root, rulesDoc);
1822
+ const file = path14.resolve(root, rulesDoc);
1823
1823
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
1824
1824
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
1825
1825
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -1878,14 +1878,14 @@ async function loadPlugins(specs, configDir) {
1878
1878
  }
1879
1879
  function resolvePlugin(id, configDir) {
1880
1880
  try {
1881
- if (id.startsWith(".") || path3.isAbsolute(id)) return resolveFrom(path3.resolve(configDir, id), configDir);
1881
+ if (id.startsWith(".") || path14.isAbsolute(id)) return resolveFrom(path14.resolve(configDir, id), configDir);
1882
1882
  return resolveFrom(id, configDir);
1883
1883
  } catch {
1884
1884
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
1885
1885
  }
1886
1886
  }
1887
1887
  function resolveFrom(id, from) {
1888
- return createRequire(path3.join(from, "noop.js")).resolve(id);
1888
+ return createRequire(path14.join(from, "noop.js")).resolve(id);
1889
1889
  }
1890
1890
  var BUILTIN_RULES = [
1891
1891
  "local-primitives",
@@ -1918,7 +1918,8 @@ var BUILTIN_RULES = [
1918
1918
  "migration-rls",
1919
1919
  "migration-definer-search-path",
1920
1920
  "migration-edited",
1921
- "migration-testing-kit"
1921
+ "migration-testing-kit",
1922
+ "migration-view-rls"
1922
1923
  ];
1923
1924
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
1924
1925
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -1936,7 +1937,7 @@ function importSpecifiers(file) {
1936
1937
  }
1937
1938
  function checkProjectLayout(ctx) {
1938
1939
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
1939
- if (existsSync(path3.join(ctx.root, dir))) {
1940
+ if (existsSync(path14.join(ctx.root, dir))) {
1940
1941
  ctx.report({
1941
1942
  rule: "local-primitives",
1942
1943
  file: dir,
@@ -1946,7 +1947,7 @@ function checkProjectLayout(ctx) {
1946
1947
  }
1947
1948
  }
1948
1949
  for (const file of STARTER_LEFTOVERS) {
1949
- if (existsSync(path3.join(ctx.root, file))) {
1950
+ if (existsSync(path14.join(ctx.root, file))) {
1950
1951
  ctx.report({
1951
1952
  rule: "starter-leftover",
1952
1953
  level: "warn",
@@ -2035,7 +2036,7 @@ function checkTokens(ctx) {
2035
2036
  }
2036
2037
  for (const pattern of ctx.config.tokenFiles ?? []) {
2037
2038
  if (/[*?]/.test(pattern)) continue;
2038
- const abs = path3.join(ctx.root, pattern);
2039
+ const abs = path14.join(ctx.root, pattern);
2039
2040
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
2040
2041
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
2041
2042
  }
@@ -2141,10 +2142,10 @@ function localImports(root, file) {
2141
2142
  const out = [];
2142
2143
  for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2143
2144
  const spec = m[1];
2144
- const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
2145
+ const bases = spec.startsWith(".") ? [path14.resolve(path14.dirname(file.absolutePath), spec)] : [path14.join(root, spec.slice(2)), path14.join(root, "src", spec.slice(2))];
2145
2146
  for (const base of bases) {
2146
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
2147
- (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
2147
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
2148
+ (p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
2148
2149
  );
2149
2150
  if (hit) {
2150
2151
  out.push(hit);
@@ -2161,14 +2162,6 @@ function readSource(abs) {
2161
2162
  return null;
2162
2163
  }
2163
2164
  }
2164
- function viaOneImport(root, files, file, test2) {
2165
- if (test2(file.code)) return true;
2166
- const byPath = new Map(files.map((f) => [f.absolutePath, f]));
2167
- return localImports(root, file).some((abs) => {
2168
- const target = byPath.get(abs) ?? readSource(abs);
2169
- return target !== null && test2(target.code);
2170
- });
2171
- }
2172
2165
  function tagEnd(code, start) {
2173
2166
  let depth = 0;
2174
2167
  let quote2 = null;
@@ -2316,7 +2309,7 @@ function checkCustomHeaders(ctx, pkg) {
2316
2309
  if (!JSX_EXTS3.has(file.ext)) continue;
2317
2310
  const code = file.code;
2318
2311
  const hidden = HIDES_HEADER.exec(code);
2319
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
2312
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
2320
2313
  const own = hidden ? ownHeader(code, pkg) : null;
2321
2314
  if (hidden && own) {
2322
2315
  reported.add(file.path);
@@ -2344,7 +2337,7 @@ function checkCustomHeaders(ctx, pkg) {
2344
2337
  }
2345
2338
  for (const file of ctx.files) {
2346
2339
  if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2347
- const layout = hidingLayouts.get(path3.posix.dirname(file.path));
2340
+ const layout = hidingLayouts.get(path14.posix.dirname(file.path));
2348
2341
  const own = layout ? ownHeader(file.code, pkg) : null;
2349
2342
  if (!layout || !own) continue;
2350
2343
  ctx.report({
@@ -2359,13 +2352,13 @@ function checkCustomHeaders(ctx, pkg) {
2359
2352
  }
2360
2353
  function routerRoot(ctx) {
2361
2354
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
2362
- return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
2355
+ return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
2363
2356
  }
2364
2357
  function checkScreenLayouts(ctx, pkg) {
2365
2358
  const layouts = nativeLayouts(pkg);
2366
2359
  if (layouts.length === 0) return;
2367
2360
  const rootDir = routerRoot(ctx);
2368
- if (!existsSync(path3.join(ctx.root, rootDir))) {
2361
+ if (!existsSync(path14.join(ctx.root, rootDir))) {
2369
2362
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
2370
2363
  return;
2371
2364
  }
@@ -2379,15 +2372,15 @@ function checkScreenLayouts(ctx, pkg) {
2379
2372
  });
2380
2373
  return;
2381
2374
  }
2382
- const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2375
+ const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2383
2376
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2384
2377
  for (const file of routes) {
2385
2378
  if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2386
2379
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
2387
- if (renders.test(file.code)) continue;
2380
+ if (renders2.test(file.code)) continue;
2388
2381
  const viaImport = localImports(ctx.root, file).some((abs) => {
2389
2382
  const target = byPath.get(abs) ?? readSource(abs);
2390
- return target !== null && renders.test(target.code);
2383
+ return target !== null && renders2.test(target.code);
2391
2384
  });
2392
2385
  if (viaImport) continue;
2393
2386
  ctx.report({
@@ -2420,7 +2413,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
2420
2413
  function readExpoConfigs(root) {
2421
2414
  const out = [];
2422
2415
  for (const name of EXPO_CONFIGS) {
2423
- const abs = path3.join(root, name);
2416
+ const abs = path14.join(root, name);
2424
2417
  if (!existsSync(abs)) continue;
2425
2418
  const text = readFileSync(abs, "utf8");
2426
2419
  let json = null;
@@ -2454,13 +2447,13 @@ function pluginOptions(json, module) {
2454
2447
  return null;
2455
2448
  }
2456
2449
  function dependencies(root) {
2457
- const file = path3.join(root, "package.json");
2450
+ const file = path14.join(root, "package.json");
2458
2451
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
2459
2452
  const pkg = JSON.parse(readFileSync(file, "utf8"));
2460
2453
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
2461
2454
  }
2462
2455
  function runtimeDependencies(root) {
2463
- const file = path3.join(root, "package.json");
2456
+ const file = path14.join(root, "package.json");
2464
2457
  if (!existsSync(file)) return {};
2465
2458
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
2466
2459
  }
@@ -2723,9 +2716,9 @@ function gitView(root, dir, base) {
2723
2716
  function checkSupabasePack(ctx) {
2724
2717
  const settings = ctx.config.supabase ?? {};
2725
2718
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
2726
- const abs = path3.join(ctx.root, dir);
2719
+ const abs = path14.join(ctx.root, dir);
2727
2720
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
2728
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path3.join(abs, n), "utf8")) }));
2721
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
2729
2722
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
2730
2723
  const base = settings.base ?? DEFAULT_BASE;
2731
2724
  const view = gitView(ctx.root, dir, base);
@@ -2742,7 +2735,7 @@ function checkSupabasePack(ctx) {
2742
2735
  }
2743
2736
  }
2744
2737
  const since = settings.since;
2745
- const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
2738
+ const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
2746
2739
  if ("reason" in view && since === void 0) {
2747
2740
  ctx.report({
2748
2741
  rule: "migration-grants",
@@ -2755,6 +2748,7 @@ function checkSupabasePack(ctx) {
2755
2748
  checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
2756
2749
  }
2757
2750
  checkRls(ctx, migrations, exposed);
2751
+ checkViewInvoker(ctx, migrations, exposed);
2758
2752
  checkDefinerSearchPath(ctx, migrations);
2759
2753
  checkTestingKit(ctx, migrations);
2760
2754
  }
@@ -2884,6 +2878,50 @@ function checkRls(ctx, migrations, exposed) {
2884
2878
  });
2885
2879
  }
2886
2880
  }
2881
+ function checkViewInvoker(ctx, migrations, exposed) {
2882
+ const views = /* @__PURE__ */ new Map();
2883
+ const name = String.raw`([\w$.]+)`;
2884
+ const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
2885
+ for (const { file, statements } of migrations) {
2886
+ for (const { sql, line } of statements) {
2887
+ const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
2888
+ if (create) {
2889
+ if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
2890
+ const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
2891
+ views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
2892
+ continue;
2893
+ }
2894
+ const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
2895
+ if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
2896
+ const state = views.get(qualify(alter[1]));
2897
+ if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
2898
+ continue;
2899
+ }
2900
+ const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
2901
+ if (rename) {
2902
+ const from = qualify(rename[1]);
2903
+ const state = views.get(from);
2904
+ if (state) {
2905
+ views.delete(from);
2906
+ views.set(`${schemaOf(from)}.${rename[2]}`, state);
2907
+ }
2908
+ continue;
2909
+ }
2910
+ const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
2911
+ if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
2912
+ }
2913
+ }
2914
+ for (const [v, at] of views) {
2915
+ if (at.invoker || !exposed.has(schemaOf(v))) continue;
2916
+ ctx.report({
2917
+ rule: "migration-view-rls",
2918
+ file: at.file,
2919
+ line: at.line,
2920
+ subject: v,
2921
+ 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);"`
2922
+ });
2923
+ }
2924
+ }
2887
2925
  function checkDefinerSearchPath(ctx, migrations) {
2888
2926
  const fns = /* @__PURE__ */ new Map();
2889
2927
  const keysFor = (sql, nameEnd, fnName) => {
@@ -2949,7 +2987,7 @@ function checkDefinerSearchPath(ctx, migrations) {
2949
2987
  var UMBRELLA_PACKAGE = "@marktiderman/genesis";
2950
2988
  function readReleaseManifest(root) {
2951
2989
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
2952
- const file = dir && path3.join(dir, "dist", "versions.json");
2990
+ const file = dir && path14.join(dir, "dist", "versions.json");
2953
2991
  if (!file || !existsSync(file)) return null;
2954
2992
  return JSON.parse(readFileSync(file, "utf8"));
2955
2993
  }
@@ -2959,7 +2997,7 @@ function checkVersionSkew(ctx) {
2959
2997
  for (const [name, want] of Object.entries(manifest.packages)) {
2960
2998
  const dir = findPackageDir(ctx.root, name);
2961
2999
  if (!dir) continue;
2962
- const have = JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8")).version;
3000
+ const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
2963
3001
  if (have === want) continue;
2964
3002
  ctx.report({
2965
3003
  rule: "version-skew",
@@ -3093,9 +3131,11 @@ function satisfies(version, range) {
3093
3131
 
3094
3132
  // src/doctor/installs.ts
3095
3133
  var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
3134
+ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
3135
+ 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)$/;
3096
3136
  var readManifest = (dir) => {
3097
3137
  try {
3098
- return JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8"));
3138
+ return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
3099
3139
  } catch {
3100
3140
  return null;
3101
3141
  }
@@ -3112,10 +3152,10 @@ function packagesIn(nodeModules) {
3112
3152
  const out = [];
3113
3153
  for (const entry of readdirSync(nodeModules)) {
3114
3154
  if (entry.startsWith(".")) continue;
3115
- const p = path3.join(nodeModules, entry);
3155
+ const p = path14.join(nodeModules, entry);
3116
3156
  if (entry.startsWith("@")) {
3117
3157
  try {
3118
- for (const sub of readdirSync(p)) out.push(path3.join(p, sub));
3158
+ for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
3119
3159
  } catch {
3120
3160
  }
3121
3161
  } else {
@@ -3127,44 +3167,70 @@ function packagesIn(nodeModules) {
3127
3167
  function genesisInstalls(root) {
3128
3168
  const copies = /* @__PURE__ */ new Map();
3129
3169
  const realRoot = real(root);
3130
- const rel = (abs) => path3.relative(realRoot, abs).split(path3.sep).join("/") || ".";
3131
- const record = (real2, manifest, by, range) => {
3170
+ const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
3171
+ const via = /* @__PURE__ */ new Map();
3172
+ const record = (real2, manifest, by, range, root2) => {
3132
3173
  let copy = copies.get(real2);
3133
3174
  if (!copy) {
3134
- copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
3175
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
3135
3176
  copies.set(real2, copy);
3177
+ via.set(real2, /* @__PURE__ */ new Set());
3136
3178
  }
3179
+ via.get(real2).add(root2);
3137
3180
  if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
3138
3181
  };
3139
- const expanded = /* @__PURE__ */ new Set();
3140
- const queue = [];
3141
- const visit = (dir, by, range) => {
3142
- const manifest = readManifest(dir);
3143
- if (!manifest?.name) return;
3144
- const realDir = real(dir);
3145
- if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range);
3146
- if (expanded.has(realDir)) return;
3147
- expanded.add(realDir);
3148
- queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
3182
+ const walk = (kind, roots) => {
3183
+ const expanded = /* @__PURE__ */ new Set();
3184
+ const queue = [];
3185
+ const visit = (dir, by, range) => {
3186
+ const manifest = readManifest(dir);
3187
+ if (!manifest?.name) return;
3188
+ if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
3189
+ const realDir = real(dir);
3190
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
3191
+ if (expanded.has(realDir)) return;
3192
+ expanded.add(realDir);
3193
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
3194
+ };
3195
+ for (const r of roots) visit(r.dir, r.by, r.range);
3196
+ while (queue.length) {
3197
+ const { real: from, manifest, label } = queue.shift();
3198
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
3199
+ for (const [name, range] of Object.entries(deps)) {
3200
+ const dir = findPackageDir(from, name);
3201
+ if (dir) visit(dir, label, range);
3202
+ }
3203
+ }
3149
3204
  };
3150
- const app = readManifest(root);
3151
- const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3152
- for (const name of Object.keys(appDeps)) {
3205
+ const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
3153
3206
  const dir = findPackageDir(root, name);
3154
- if (dir) visit(dir, "the app", appDeps[name]);
3155
- }
3156
- const top = path3.join(root, "node_modules");
3157
- for (const dir of packagesIn(top)) {
3158
- const name = path3.relative(top, dir).split(path3.sep).join("/");
3159
- if (!(name in appDeps)) visit(dir, "hoisted, not a direct dependency", void 0);
3160
- }
3161
- while (queue.length) {
3162
- const { real: from, manifest, label } = queue.shift();
3163
- const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
3164
- for (const [name, range] of Object.entries(deps)) {
3165
- const dir = findPackageDir(from, name);
3166
- if (dir) visit(dir, label, range);
3167
- }
3207
+ return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
3208
+ });
3209
+ const app = readManifest(root);
3210
+ const declaredDev = Object.entries(app?.devDependencies ?? {});
3211
+ const runtimeDeps = {
3212
+ ...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
3213
+ ...app?.peerDependencies,
3214
+ ...app?.optionalDependencies,
3215
+ ...app?.dependencies
3216
+ };
3217
+ const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
3218
+ walk("runtime", rootsOf(runtimeDeps, "the app"));
3219
+ const top = path14.join(root, "node_modules");
3220
+ walk(
3221
+ "hoisted",
3222
+ packagesIn(top).filter((dir) => {
3223
+ const name = path14.relative(top, dir).split(path14.sep).join("/");
3224
+ return !(name in runtimeDeps) && !(name in devDeps);
3225
+ }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
3226
+ );
3227
+ const devRoots = { ...devDeps };
3228
+ for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
3229
+ walk("dev", rootsOf(devRoots, "the app (dev)"));
3230
+ for (const [key2, copy] of copies) {
3231
+ const kinds = via.get(key2);
3232
+ copy.runtime = kinds.has("runtime");
3233
+ copy.devOnly = kinds.size === 1 && kinds.has("dev");
3168
3234
  }
3169
3235
  const byName = /* @__PURE__ */ new Map();
3170
3236
  for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
@@ -3172,20 +3238,31 @@ function genesisInstalls(root) {
3172
3238
  return byName;
3173
3239
  }
3174
3240
  function checkDuplicatePackages(ctx) {
3241
+ const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
3175
3242
  for (const [name, copies] of genesisInstalls(ctx.root)) {
3176
3243
  if (copies.length < 2) continue;
3177
- const where = copies.map((c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`).join(", ");
3244
+ const shipping = copies.filter((c) => c.runtime);
3245
+ if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
3246
+ ctx.report({
3247
+ rule: "duplicate-genesis-package",
3248
+ level: "warn",
3249
+ file: "package.json",
3250
+ subject: name,
3251
+ 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`
3252
+ });
3253
+ continue;
3254
+ }
3178
3255
  ctx.report({
3179
3256
  rule: "duplicate-genesis-package",
3180
- level: "warn",
3257
+ level: "info",
3181
3258
  file: "package.json",
3182
3259
  subject: name,
3183
- message: `${name} is installed ${copies.length} times: ${where}. Each copy is its own module, so a provider from one (DataProvider, the shell's contexts) is invisible to hooks from another. Align the ranges so one copy satisfies them all, or add an override/resolution`
3260
+ 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`
3184
3261
  });
3185
3262
  }
3186
3263
  }
3187
3264
  function checkPeerRanges(ctx) {
3188
- const rel = (abs) => path3.relative(ctx.root, abs).split(path3.sep).join("/");
3265
+ const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
3189
3266
  for (const copies of genesisInstalls(ctx.root).values()) {
3190
3267
  for (const copy of copies) {
3191
3268
  const dir = copy.absolutePath;
@@ -3198,7 +3275,8 @@ function checkPeerRanges(ctx) {
3198
3275
  if (satisfies(installed, range) !== false) continue;
3199
3276
  ctx.report({
3200
3277
  rule: "peer-range-mismatch",
3201
- level: "warn",
3278
+ // A dev tool's own tree (the CLI's) doesn't run in the app.
3279
+ level: copy.devOnly ? "info" : "warn",
3202
3280
  file: "package.json",
3203
3281
  subject: `${copy.name}>${peer}`,
3204
3282
  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}`
@@ -3207,55 +3285,466 @@ function checkPeerRanges(ctx) {
3207
3285
  }
3208
3286
  }
3209
3287
  }
3288
+ var TRAIL_DEPTH = 6;
3289
+ var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
3290
+ var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
3291
+ var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
3292
+ var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
3293
+ function stripForImports(code) {
3294
+ const out = [];
3295
+ const blank = (ch) => ch === "\n" ? "\n" : " ";
3296
+ const n = code.length;
3297
+ const templates = [];
3298
+ let depth = 0;
3299
+ let i = 0;
3300
+ let sure = true;
3301
+ const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
3302
+ const before = () => out.slice(-24).join("");
3303
+ const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
3304
+ const startsExpression = (b) => {
3305
+ const t = b.replace(/\s+$/, "");
3306
+ if (!t) return true;
3307
+ if (KEYWORD.test(b)) return true;
3308
+ return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
3309
+ };
3310
+ const exprStart = () => startsExpression(before());
3311
+ const taggedTemplate = () => {
3312
+ const b = out.slice(-48).join("");
3313
+ const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
3314
+ return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
3315
+ };
3316
+ const templateBody = () => {
3317
+ while (i < n) {
3318
+ const ch = code[i];
3319
+ if (ch === "\\") {
3320
+ out.push(" ", blank(code[i + 1] ?? ""));
3321
+ i += 2;
3322
+ } else if (ch === "`") {
3323
+ out.push("`");
3324
+ i++;
3325
+ return;
3326
+ } else if (ch === "$" && code[i + 1] === "{") {
3327
+ out.push("${");
3328
+ i += 2;
3329
+ templates.push(depth);
3330
+ depth++;
3331
+ return;
3332
+ } else {
3333
+ out.push(blank(ch));
3334
+ i++;
3335
+ }
3336
+ }
3337
+ sure = false;
3338
+ };
3339
+ while (i < n && sure) {
3340
+ const ch = code[i];
3341
+ const next = code[i + 1];
3342
+ if (ch === "/" && next === "/") {
3343
+ while (i < n && code[i] !== "\n") {
3344
+ out.push(" ");
3345
+ i++;
3346
+ }
3347
+ } else if (ch === "/" && next === "*") {
3348
+ out.push(" ");
3349
+ i += 2;
3350
+ while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
3351
+ out.push(blank(code[i]));
3352
+ i++;
3353
+ }
3354
+ if (i < n) {
3355
+ out.push(" ");
3356
+ i += 2;
3357
+ }
3358
+ } else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
3359
+ const afterBrace = /[}>]\s*$/.test(before());
3360
+ const start = i;
3361
+ const mark = out.length;
3362
+ out.push("/");
3363
+ i++;
3364
+ let inClass = false;
3365
+ for (; ; ) {
3366
+ const c = code[i];
3367
+ if (c === void 0 || c === "\n") {
3368
+ if (afterBrace) {
3369
+ out.length = mark;
3370
+ out.push("/");
3371
+ i = start + 1;
3372
+ } else sure = false;
3373
+ break;
3374
+ }
3375
+ if (c === "\\") {
3376
+ out.push(" ", blank(code[i + 1] ?? ""));
3377
+ i += 2;
3378
+ continue;
3379
+ }
3380
+ i++;
3381
+ if (c === "[") inClass = true;
3382
+ else if (c === "]") inClass = false;
3383
+ else if (c === "/" && !inClass) {
3384
+ if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
3385
+ out.length = mark;
3386
+ out.push("/");
3387
+ i = start + 1;
3388
+ break;
3389
+ }
3390
+ out.push("/");
3391
+ break;
3392
+ }
3393
+ out.push(" ");
3394
+ }
3395
+ if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
3396
+ } else if ((ch === '"' || ch === "'") && exprStart()) {
3397
+ const keep = isSpecifier();
3398
+ out.push(ch);
3399
+ i++;
3400
+ while (i < n && code[i] !== ch && code[i] !== "\n") {
3401
+ if (code[i] === "\\") {
3402
+ out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
3403
+ i += 2;
3404
+ } else {
3405
+ out.push(keep ? code[i] : blank(code[i]));
3406
+ i++;
3407
+ }
3408
+ }
3409
+ if (code[i] !== ch) sure = false;
3410
+ else {
3411
+ out.push(code[i]);
3412
+ i++;
3413
+ }
3414
+ } else if (ch === "`" && (exprStart() || taggedTemplate())) {
3415
+ out.push("`");
3416
+ i++;
3417
+ templateBody();
3418
+ } else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
3419
+ templates.pop();
3420
+ depth--;
3421
+ out.push("}");
3422
+ i++;
3423
+ templateBody();
3424
+ } else {
3425
+ if (ch === "{") depth++;
3426
+ else if (ch === "}") depth--;
3427
+ out.push(ch);
3428
+ i++;
3429
+ }
3430
+ }
3431
+ return sure && templates.length === 0 ? out.join("") : null;
3432
+ }
3433
+ function bindings(clause) {
3434
+ const out = [];
3435
+ const named = /\{([^}]*)\}/.exec(clause);
3436
+ for (const part of named?.[1].split(",") ?? []) {
3437
+ const p = part.trim();
3438
+ if (!p || p.startsWith("type ")) continue;
3439
+ out.push(p.split(/\s+as\s+/).pop().trim());
3440
+ }
3441
+ const rest = clause.replace(/\{[^}]*\}/, "");
3442
+ const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
3443
+ if (ns) out.push(ns[1]);
3444
+ const def = /^\s*([\w$]+)/.exec(rest);
3445
+ if (def && def[1] !== "as") out.push(def[1]);
3446
+ return out;
3447
+ }
3448
+ function readJsonc(file) {
3449
+ try {
3450
+ const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
3451
+ return JSON.parse(text);
3452
+ } catch {
3453
+ return null;
3454
+ }
3455
+ }
3456
+ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3457
+ if (seen.has(file) || seen.size > 10) return {};
3458
+ seen.add(file);
3459
+ const json = readJsonc(file);
3460
+ if (!json) return {};
3461
+ const dir = path14.dirname(file);
3462
+ let merged = {};
3463
+ const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3464
+ for (const ext of parents) {
3465
+ if (typeof ext !== "string") continue;
3466
+ let target = null;
3467
+ if (ext.startsWith(".") || path14.isAbsolute(ext)) {
3468
+ const abs = path14.resolve(dir, ext);
3469
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3470
+ } else {
3471
+ const parts = ext.split("/");
3472
+ const nameLength = ext.startsWith("@") ? 2 : 1;
3473
+ const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3474
+ if (pkgDir) {
3475
+ const sub = parts.slice(nameLength).join("/");
3476
+ const abs = path14.join(pkgDir, sub || "tsconfig.json");
3477
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3478
+ }
3479
+ }
3480
+ if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3481
+ }
3482
+ const opts = json.compilerOptions ?? {};
3483
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
3484
+ if (opts.paths && typeof opts.paths === "object") {
3485
+ merged.paths = opts.paths;
3486
+ merged.pathsDir = dir;
3487
+ }
3488
+ return merged;
3489
+ }
3490
+ function aliases(root) {
3491
+ const table = [];
3492
+ let baseUrl = null;
3493
+ for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3494
+ const file = path14.join(root, name);
3495
+ if (!existsSync(file)) continue;
3496
+ const config = readTsconfig(root, file);
3497
+ baseUrl ??= config.baseUrl ?? null;
3498
+ const base = config.baseUrl ?? config.pathsDir ?? root;
3499
+ for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3500
+ if (!Array.isArray(targets)) continue;
3501
+ const exact = !pattern.endsWith("*");
3502
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
3503
+ }
3504
+ }
3505
+ const pkg = readJsonc(path14.join(root, "package.json"));
3506
+ for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3507
+ if (typeof target !== "string") continue;
3508
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
3509
+ }
3510
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
3511
+ return { table, baseUrl };
3512
+ }
3513
+ function resolveFile(base) {
3514
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
3515
+ if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3516
+ for (const p of tries) {
3517
+ if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3518
+ }
3519
+ return null;
3520
+ }
3521
+ var trails = /* @__PURE__ */ new WeakMap();
3522
+ function trailFor(ctx) {
3523
+ let t = trails.get(ctx.files);
3524
+ if (!t) trails.set(ctx.files, t = createTrail(ctx));
3525
+ return t;
3526
+ }
3527
+ function createTrail(ctx) {
3528
+ const { table, baseUrl } = aliases(ctx.root);
3529
+ let declared = null;
3530
+ try {
3531
+ const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
3532
+ declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3533
+ } catch {
3534
+ declared = null;
3535
+ }
3536
+ const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
3537
+ const read = (abs) => byPath.get(abs) ?? readSource(abs);
3538
+ const importsCache = /* @__PURE__ */ new Map();
3539
+ const importsOf = (file) => {
3540
+ const hit = importsCache.get(file.absolutePath);
3541
+ if (hit) return hit;
3542
+ const files = [];
3543
+ let lost = false;
3544
+ const code = stripped(file);
3545
+ if (code === null) {
3546
+ const out2 = { files: [], lost: true };
3547
+ importsCache.set(file.absolutePath, out2);
3548
+ return out2;
3549
+ }
3550
+ const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
3551
+ for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3552
+ for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3553
+ 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]);
3554
+ const specs = [];
3555
+ for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
3556
+ for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
3557
+ for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
3558
+ for (const spec of specs) {
3559
+ if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3560
+ let resolved = null;
3561
+ if (spec.startsWith(".")) {
3562
+ resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
3563
+ if (!resolved) lost = true;
3564
+ } else {
3565
+ const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3566
+ if (alias) {
3567
+ for (const t of alias.targets) {
3568
+ resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
3569
+ if (resolved) break;
3570
+ }
3571
+ }
3572
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
3573
+ if (!resolved) {
3574
+ const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3575
+ if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
3576
+ }
3577
+ }
3578
+ if (resolved && !files.includes(resolved)) files.push(resolved);
3579
+ }
3580
+ const out = { files, lost };
3581
+ importsCache.set(file.absolutePath, out);
3582
+ return out;
3583
+ };
3584
+ const strippedCache = /* @__PURE__ */ new Map();
3585
+ const stripped = (file) => {
3586
+ if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
3587
+ return strippedCache.get(file.absolutePath);
3588
+ };
3589
+ const memo = /* @__PURE__ */ new WeakMap();
3590
+ const reach = (file, test2, depth, seen) => {
3591
+ let cache = memo.get(test2);
3592
+ if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
3593
+ const k = `${file.absolutePath}\0${depth}`;
3594
+ const free = cache.free.get(k);
3595
+ if (free) return [free, /* @__PURE__ */ new Set()];
3596
+ const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
3597
+ if (reusable) return [reusable.result, new Set(reusable.cut)];
3598
+ let result;
3599
+ const cut = /* @__PURE__ */ new Set();
3600
+ const code = stripped(file);
3601
+ if (code === null) result = "unknown";
3602
+ else if (test2(code)) result = "yes";
3603
+ else {
3604
+ const { files, lost } = importsOf(file);
3605
+ let unknown = lost && depth > 0;
3606
+ result = "no";
3607
+ if (depth > 0) {
3608
+ seen.add(file.absolutePath);
3609
+ for (const abs of files) {
3610
+ if (seen.has(abs)) {
3611
+ cut.add(abs);
3612
+ continue;
3613
+ }
3614
+ const target = read(abs);
3615
+ if (!target) {
3616
+ unknown = true;
3617
+ continue;
3618
+ }
3619
+ const [r, c] = reach(target, test2, depth - 1, seen);
3620
+ for (const m of c) cut.add(m);
3621
+ if (r === "yes") {
3622
+ result = "yes";
3623
+ break;
3624
+ }
3625
+ if (r === "unknown") unknown = true;
3626
+ }
3627
+ seen.delete(file.absolutePath);
3628
+ cut.delete(file.absolutePath);
3629
+ }
3630
+ if (result === "no" && unknown) result = "unknown";
3631
+ }
3632
+ if (result === "yes" || cut.size === 0) {
3633
+ cache.free.set(k, result);
3634
+ return [result, /* @__PURE__ */ new Set()];
3635
+ }
3636
+ const entries = cache.cut.get(k) ?? [];
3637
+ entries.push({ cut: [...cut], result });
3638
+ cache.cut.set(k, entries);
3639
+ return [result, cut];
3640
+ };
3641
+ return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3642
+ }
3643
+
3644
+ // src/doctor/routes.ts
3210
3645
  var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
3211
- var LAYOUT_STEMS = /* @__PURE__ */ new Set(["route", "layout", "_layout", "__root", "_app"]);
3212
- var INDEX_STEMS = /* @__PURE__ */ new Set(["index", "page"]);
3646
+ var STEMS = {
3647
+ tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
3648
+ "next-app": {
3649
+ layout: /* @__PURE__ */ new Set(["layout"]),
3650
+ index: /* @__PURE__ */ new Set(["page"]),
3651
+ skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
3652
+ },
3653
+ "next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
3654
+ };
3213
3655
  var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
3214
3656
  var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
3657
+ var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
3658
+ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
3659
+ 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;
3215
3660
  function routesDir(ctx) {
3216
3661
  if (ctx.config.routesDir) return ctx.config.routesDir;
3217
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path3.join(ctx.root, d))) ?? null;
3662
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
3218
3663
  }
3219
3664
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
3665
+ function flavorOf(dir, rels) {
3666
+ const stems = rels.map((r) => r.split("/").pop());
3667
+ if (stems.includes("__root")) return "tanstack";
3668
+ if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
3669
+ if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
3670
+ return "tanstack";
3671
+ }
3672
+ function renders(code) {
3673
+ const elements = renderedElements(code);
3674
+ if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
3675
+ const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
3676
+ const named = COMPONENT_OPTION.exec(code)?.[1];
3677
+ if (named && !definedHere(named)) return true;
3678
+ if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
3679
+ const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
3680
+ return exported !== void 0 && !definedHere(exported);
3681
+ }
3220
3682
  function webRoutes(ctx) {
3221
3683
  const dir = routesDir(ctx);
3222
3684
  if (!dir) return [];
3223
- const routes = [];
3224
- for (const file of ctx.files) {
3225
- if (!JSX_EXTS2.has(file.ext) || !file.path.startsWith(`${dir}/`)) continue;
3226
- const rel = file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "");
3685
+ 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(/\.[^.]+$/, "") }));
3686
+ const flavor = flavorOf(dir, candidates.map((c) => c.rel));
3687
+ const stems = STEMS[flavor];
3688
+ const groups = /* @__PURE__ */ new Map();
3689
+ for (const { file, rel } of candidates) {
3227
3690
  const parts = rel.split("/");
3228
3691
  if (parts.some((p) => p.startsWith("-"))) continue;
3692
+ if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
3693
+ if (flavor === "next-pages" && parts[0] === "api") continue;
3694
+ if (stems.skip.test(parts.at(-1))) continue;
3695
+ if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
3696
+ const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
3697
+ groups.set(id, [...groups.get(id) ?? [], file]);
3698
+ }
3699
+ const trail = trailFor(ctx);
3700
+ const routes = [];
3701
+ for (const [id, files] of groups) {
3702
+ const parts = id.split("/");
3229
3703
  const stem = parts.pop();
3230
- const segments = [...parts, ...LAYOUT_STEMS.has(stem) || INDEX_STEMS.has(stem) ? [] : stem.split(".")];
3231
- let index = INDEX_STEMS.has(stem);
3232
- if (!index && !LAYOUT_STEMS.has(stem) && INDEX_STEMS.has(segments.at(-1) ?? "")) {
3704
+ const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
3705
+ const named = stems.layout.has(stem) || stems.index.has(stem);
3706
+ const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
3707
+ const segments = [...folders, ...own];
3708
+ const tree = [...parts, ...own];
3709
+ let index = stems.index.has(stem);
3710
+ if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
3233
3711
  segments.pop();
3712
+ tree.pop();
3234
3713
  index = true;
3235
3714
  }
3236
- const elements = renderedElements(file.code);
3237
- const layout = LAYOUT_STEMS.has(stem) || elements.includes("Outlet");
3715
+ const code = files.map((f) => f.code).join("\n");
3716
+ const elements = renderedElements(code);
3717
+ const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
3718
+ const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
3719
+ const layout = stems.layout.has(stem) || pathless || outlet;
3720
+ const rendering = renders(code);
3721
+ const ownContent = new RegExp(OWN_CONTENT).test(code);
3722
+ const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
3723
+ const page = !pure && !pathless && (!layout || ownContent);
3238
3724
  routes.push({
3239
- file,
3725
+ file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
3726
+ files,
3240
3727
  segments,
3728
+ tree,
3241
3729
  index,
3242
3730
  layout,
3243
- detail: !index && !layout && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
3244
- redirectOnly: elements.every((e) => NON_PAGE_ELEMENTS.has(e)) && !HTML_ELEMENT.test(file.code),
3731
+ page,
3732
+ detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
3733
+ redirectOnly: !rendering,
3245
3734
  parents: []
3246
3735
  });
3247
3736
  }
3248
3737
  for (const r of routes) {
3249
- const own = r.segments;
3738
+ const own = r.tree;
3250
3739
  for (const p of routes) {
3251
3740
  if (p === r || !p.layout) continue;
3252
- const n = p.segments.length;
3741
+ const n = p.tree.length;
3253
3742
  if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
3254
- if (key(own.slice(0, n)) !== key(p.segments)) continue;
3255
- if (n > 0 && own[n - 1].endsWith("_") && !p.segments[n - 1].endsWith("_")) continue;
3743
+ if (key(own.slice(0, n)) !== key(p.tree)) continue;
3744
+ if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
3256
3745
  r.parents.push(p);
3257
3746
  }
3258
- r.parents.sort((a, b) => b.segments.length - a.segments.length);
3747
+ r.parents.sort((a, b) => b.tree.length - a.tree.length);
3259
3748
  }
3260
3749
  return routes;
3261
3750
  }
@@ -3273,8 +3762,19 @@ var rendersRe = (names) => {
3273
3762
  const list = [...names];
3274
3763
  return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
3275
3764
  };
3765
+ function routeReach(ctx, r, test2) {
3766
+ const trail = trailFor(ctx);
3767
+ let unknown = false;
3768
+ for (const f of r.files) {
3769
+ const got = trail.reach(f, test2);
3770
+ if (got === "yes") return "yes";
3771
+ if (got === "unknown") unknown = true;
3772
+ }
3773
+ return unknown ? "unknown" : "no";
3774
+ }
3775
+ var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
3276
3776
  function insideShell(ctx, routes) {
3277
- const shell = new Set(routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => SHELL.test(code))));
3777
+ const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
3278
3778
  const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
3279
3779
  return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
3280
3780
  }
@@ -3285,20 +3785,19 @@ function checkHandRolledSubNav(ctx) {
3285
3785
  const inShell = insideShell(ctx, routes);
3286
3786
  const ui = ctx.genesis.uiPackage;
3287
3787
  for (const r of routes) {
3288
- if (!inShell(r)) continue;
3289
- const code = r.file.code;
3290
- if (/\buseAppShellSubNav\s*\(/.test(code)) continue;
3291
- for (const m of code.matchAll(SWITCHER)) {
3292
- if (openElementsAt(code, m.index, (n) => CONTAINER.test(n)).length > 0) continue;
3788
+ if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
3789
+ 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);
3790
+ if (hit) {
3791
+ const { f, m } = hit;
3792
+ const code = f.code;
3293
3793
  ctx.report({
3294
3794
  rule: "hand-rolled-sub-nav",
3295
3795
  level: "warn",
3296
- file: r.file.path,
3796
+ file: f.path,
3297
3797
  line: lineAt(code, m.index),
3298
3798
  subject: m[1],
3299
3799
  message: `switches the page's sections with its own <${m[1]}>; hand them to the shell with useAppShellSubNav(items, { mode: "tabs" }) and put the header in AppShellPageHeader (chips in AppShellSubNavEnd), from ${ui}/layout, so the sections are the shell's tab row and the phone's bottom bar. See ${SUB_NAV_DOCS}`
3300
3800
  });
3301
- break;
3302
3801
  }
3303
3802
  }
3304
3803
  }
@@ -3346,11 +3845,12 @@ function checkResourceWorkspaces(ctx) {
3346
3845
  byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
3347
3846
  }
3348
3847
  for (const [dir, routes] of byFolder) {
3349
- const has2 = routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => header.test(code)));
3848
+ const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
3849
+ const has2 = routes.filter((r) => reach.get(r) === "yes");
3350
3850
  if (has2.length === 0) continue;
3351
3851
  const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
3352
3852
  for (const r of routes) {
3353
- if (has2.includes(r)) continue;
3853
+ if (reach.get(r) !== "no") continue;
3354
3854
  ctx.report({
3355
3855
  rule: "resource-workspace",
3356
3856
  level: "info",
@@ -3374,14 +3874,14 @@ function checkPageLayouts(ctx) {
3374
3874
  };
3375
3875
  const cache = /* @__PURE__ */ new Map();
3376
3876
  const provides = (r) => {
3377
- if (!cache.has(r)) cache.set(r, viaOneImport(ctx.root, ctx.files, r.file, rendersLayout));
3877
+ if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
3378
3878
  return cache.get(r);
3379
3879
  };
3380
3880
  const list = [...layouts].sort();
3381
3881
  const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
3382
3882
  for (const r of routes) {
3383
- if (r.layout || r.redirectOnly || !inShell(r)) continue;
3384
- if (provides(r) || r.parents.some(provides)) continue;
3883
+ if (!r.page || r.redirectOnly || !inShell(r)) continue;
3884
+ if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
3385
3885
  ctx.report({
3386
3886
  rule: "page-layout",
3387
3887
  level: "warn",
@@ -3412,7 +3912,7 @@ function checkIsoDateSlices(ctx) {
3412
3912
 
3413
3913
  // src/doctor/index.ts
3414
3914
  async function runDoctor(options = {}) {
3415
- const root = path3.resolve(options.root ?? process.cwd());
3915
+ const root = path14.resolve(options.root ?? process.cwd());
3416
3916
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
3417
3917
  const config = loaded.config;
3418
3918
  const genesis = options.genesis ?? loadGenesis(root, config);