@marktiderman/genesis-cli 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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",
@@ -1936,7 +1936,7 @@ function importSpecifiers(file) {
1936
1936
  }
1937
1937
  function checkProjectLayout(ctx) {
1938
1938
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
1939
- if (existsSync(path3.join(ctx.root, dir))) {
1939
+ if (existsSync(path14.join(ctx.root, dir))) {
1940
1940
  ctx.report({
1941
1941
  rule: "local-primitives",
1942
1942
  file: dir,
@@ -1946,7 +1946,7 @@ function checkProjectLayout(ctx) {
1946
1946
  }
1947
1947
  }
1948
1948
  for (const file of STARTER_LEFTOVERS) {
1949
- if (existsSync(path3.join(ctx.root, file))) {
1949
+ if (existsSync(path14.join(ctx.root, file))) {
1950
1950
  ctx.report({
1951
1951
  rule: "starter-leftover",
1952
1952
  level: "warn",
@@ -2035,7 +2035,7 @@ function checkTokens(ctx) {
2035
2035
  }
2036
2036
  for (const pattern of ctx.config.tokenFiles ?? []) {
2037
2037
  if (/[*?]/.test(pattern)) continue;
2038
- const abs = path3.join(ctx.root, pattern);
2038
+ const abs = path14.join(ctx.root, pattern);
2039
2039
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
2040
2040
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
2041
2041
  }
@@ -2141,10 +2141,10 @@ function localImports(root, file) {
2141
2141
  const out = [];
2142
2142
  for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2143
2143
  const spec = m[1];
2144
- const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
2144
+ 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
2145
  for (const base of bases) {
2146
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
2147
- (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
2146
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
2147
+ (p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
2148
2148
  );
2149
2149
  if (hit) {
2150
2150
  out.push(hit);
@@ -2161,14 +2161,6 @@ function readSource(abs) {
2161
2161
  return null;
2162
2162
  }
2163
2163
  }
2164
- function viaOneImport(root, files, file, test2) {
2165
- if (test2(file.code)) return true;
2166
- const byPath = new Map(files.map((f) => [f.absolutePath, f]));
2167
- return localImports(root, file).some((abs) => {
2168
- const target = byPath.get(abs) ?? readSource(abs);
2169
- return target !== null && test2(target.code);
2170
- });
2171
- }
2172
2164
  function tagEnd(code, start) {
2173
2165
  let depth = 0;
2174
2166
  let quote2 = null;
@@ -2316,7 +2308,7 @@ function checkCustomHeaders(ctx, pkg) {
2316
2308
  if (!JSX_EXTS3.has(file.ext)) continue;
2317
2309
  const code = file.code;
2318
2310
  const hidden = HIDES_HEADER.exec(code);
2319
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
2311
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
2320
2312
  const own = hidden ? ownHeader(code, pkg) : null;
2321
2313
  if (hidden && own) {
2322
2314
  reported.add(file.path);
@@ -2344,7 +2336,7 @@ function checkCustomHeaders(ctx, pkg) {
2344
2336
  }
2345
2337
  for (const file of ctx.files) {
2346
2338
  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));
2339
+ const layout = hidingLayouts.get(path14.posix.dirname(file.path));
2348
2340
  const own = layout ? ownHeader(file.code, pkg) : null;
2349
2341
  if (!layout || !own) continue;
2350
2342
  ctx.report({
@@ -2359,13 +2351,13 @@ function checkCustomHeaders(ctx, pkg) {
2359
2351
  }
2360
2352
  function routerRoot(ctx) {
2361
2353
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
2362
- return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
2354
+ return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
2363
2355
  }
2364
2356
  function checkScreenLayouts(ctx, pkg) {
2365
2357
  const layouts = nativeLayouts(pkg);
2366
2358
  if (layouts.length === 0) return;
2367
2359
  const rootDir = routerRoot(ctx);
2368
- if (!existsSync(path3.join(ctx.root, rootDir))) {
2360
+ if (!existsSync(path14.join(ctx.root, rootDir))) {
2369
2361
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
2370
2362
  return;
2371
2363
  }
@@ -2379,15 +2371,15 @@ function checkScreenLayouts(ctx, pkg) {
2379
2371
  });
2380
2372
  return;
2381
2373
  }
2382
- const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2374
+ const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2383
2375
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2384
2376
  for (const file of routes) {
2385
2377
  if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2386
2378
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
2387
- if (renders.test(file.code)) continue;
2379
+ if (renders2.test(file.code)) continue;
2388
2380
  const viaImport = localImports(ctx.root, file).some((abs) => {
2389
2381
  const target = byPath.get(abs) ?? readSource(abs);
2390
- return target !== null && renders.test(target.code);
2382
+ return target !== null && renders2.test(target.code);
2391
2383
  });
2392
2384
  if (viaImport) continue;
2393
2385
  ctx.report({
@@ -2420,7 +2412,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
2420
2412
  function readExpoConfigs(root) {
2421
2413
  const out = [];
2422
2414
  for (const name of EXPO_CONFIGS) {
2423
- const abs = path3.join(root, name);
2415
+ const abs = path14.join(root, name);
2424
2416
  if (!existsSync(abs)) continue;
2425
2417
  const text = readFileSync(abs, "utf8");
2426
2418
  let json = null;
@@ -2454,13 +2446,13 @@ function pluginOptions(json, module) {
2454
2446
  return null;
2455
2447
  }
2456
2448
  function dependencies(root) {
2457
- const file = path3.join(root, "package.json");
2449
+ const file = path14.join(root, "package.json");
2458
2450
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
2459
2451
  const pkg = JSON.parse(readFileSync(file, "utf8"));
2460
2452
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
2461
2453
  }
2462
2454
  function runtimeDependencies(root) {
2463
- const file = path3.join(root, "package.json");
2455
+ const file = path14.join(root, "package.json");
2464
2456
  if (!existsSync(file)) return {};
2465
2457
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
2466
2458
  }
@@ -2723,9 +2715,9 @@ function gitView(root, dir, base) {
2723
2715
  function checkSupabasePack(ctx) {
2724
2716
  const settings = ctx.config.supabase ?? {};
2725
2717
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
2726
- const abs = path3.join(ctx.root, dir);
2718
+ const abs = path14.join(ctx.root, dir);
2727
2719
  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")) }));
2720
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
2729
2721
  const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
2730
2722
  const base = settings.base ?? DEFAULT_BASE;
2731
2723
  const view = gitView(ctx.root, dir, base);
@@ -2742,7 +2734,7 @@ function checkSupabasePack(ctx) {
2742
2734
  }
2743
2735
  }
2744
2736
  const since = settings.since;
2745
- const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
2737
+ const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
2746
2738
  if ("reason" in view && since === void 0) {
2747
2739
  ctx.report({
2748
2740
  rule: "migration-grants",
@@ -2949,7 +2941,7 @@ function checkDefinerSearchPath(ctx, migrations) {
2949
2941
  var UMBRELLA_PACKAGE = "@marktiderman/genesis";
2950
2942
  function readReleaseManifest(root) {
2951
2943
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
2952
- const file = dir && path3.join(dir, "dist", "versions.json");
2944
+ const file = dir && path14.join(dir, "dist", "versions.json");
2953
2945
  if (!file || !existsSync(file)) return null;
2954
2946
  return JSON.parse(readFileSync(file, "utf8"));
2955
2947
  }
@@ -2959,7 +2951,7 @@ function checkVersionSkew(ctx) {
2959
2951
  for (const [name, want] of Object.entries(manifest.packages)) {
2960
2952
  const dir = findPackageDir(ctx.root, name);
2961
2953
  if (!dir) continue;
2962
- const have = JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8")).version;
2954
+ const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
2963
2955
  if (have === want) continue;
2964
2956
  ctx.report({
2965
2957
  rule: "version-skew",
@@ -3093,9 +3085,10 @@ function satisfies(version, range) {
3093
3085
 
3094
3086
  // src/doctor/installs.ts
3095
3087
  var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
3088
+ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
3096
3089
  var readManifest = (dir) => {
3097
3090
  try {
3098
- return JSON.parse(readFileSync(path3.join(dir, "package.json"), "utf8"));
3091
+ return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
3099
3092
  } catch {
3100
3093
  return null;
3101
3094
  }
@@ -3112,10 +3105,10 @@ function packagesIn(nodeModules) {
3112
3105
  const out = [];
3113
3106
  for (const entry of readdirSync(nodeModules)) {
3114
3107
  if (entry.startsWith(".")) continue;
3115
- const p = path3.join(nodeModules, entry);
3108
+ const p = path14.join(nodeModules, entry);
3116
3109
  if (entry.startsWith("@")) {
3117
3110
  try {
3118
- for (const sub of readdirSync(p)) out.push(path3.join(p, sub));
3111
+ for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
3119
3112
  } catch {
3120
3113
  }
3121
3114
  } else {
@@ -3127,44 +3120,68 @@ function packagesIn(nodeModules) {
3127
3120
  function genesisInstalls(root) {
3128
3121
  const copies = /* @__PURE__ */ new Map();
3129
3122
  const realRoot = real(root);
3130
- const rel = (abs) => path3.relative(realRoot, abs).split(path3.sep).join("/") || ".";
3131
- const record = (real2, manifest, by, range) => {
3123
+ const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
3124
+ const via = /* @__PURE__ */ new Map();
3125
+ const record = (real2, manifest, by, range, root2) => {
3132
3126
  let copy = copies.get(real2);
3133
3127
  if (!copy) {
3134
- copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
3128
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
3135
3129
  copies.set(real2, copy);
3130
+ via.set(real2, /* @__PURE__ */ new Set());
3136
3131
  }
3132
+ via.get(real2).add(root2);
3137
3133
  if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
3138
3134
  };
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 ?? "?"}` });
3135
+ const walk = (kind, roots) => {
3136
+ const expanded = /* @__PURE__ */ new Set();
3137
+ const queue = [];
3138
+ const visit = (dir, by, range) => {
3139
+ const manifest = readManifest(dir);
3140
+ if (!manifest?.name) return;
3141
+ if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
3142
+ const realDir = real(dir);
3143
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
3144
+ if (expanded.has(realDir)) return;
3145
+ expanded.add(realDir);
3146
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
3147
+ };
3148
+ for (const r of roots) visit(r.dir, r.by, r.range);
3149
+ while (queue.length) {
3150
+ const { real: from, manifest, label } = queue.shift();
3151
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
3152
+ for (const [name, range] of Object.entries(deps)) {
3153
+ const dir = findPackageDir(from, name);
3154
+ if (dir) visit(dir, label, range);
3155
+ }
3156
+ }
3149
3157
  };
3150
- const app = readManifest(root);
3151
- const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3152
- for (const name of Object.keys(appDeps)) {
3158
+ const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
3153
3159
  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
- }
3160
+ return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
3161
+ });
3162
+ const app = readManifest(root);
3163
+ let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3164
+ let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
3165
+ if (Object.keys(runtimeDeps).length === 0) {
3166
+ runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
3167
+ devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
3168
+ }
3169
+ walk("runtime", rootsOf(runtimeDeps, "the app"));
3170
+ const top = path14.join(root, "node_modules");
3171
+ walk(
3172
+ "hoisted",
3173
+ packagesIn(top).filter((dir) => {
3174
+ const name = path14.relative(top, dir).split(path14.sep).join("/");
3175
+ return !(name in runtimeDeps) && !(name in devDeps);
3176
+ }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
3177
+ );
3178
+ const devRoots = { ...devDeps };
3179
+ for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
3180
+ walk("dev", rootsOf(devRoots, "the app (dev)"));
3181
+ for (const [key2, copy] of copies) {
3182
+ const kinds = via.get(key2);
3183
+ copy.runtime = kinds.has("runtime");
3184
+ copy.devOnly = kinds.size === 1 && kinds.has("dev");
3168
3185
  }
3169
3186
  const byName = /* @__PURE__ */ new Map();
3170
3187
  for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
@@ -3172,20 +3189,31 @@ function genesisInstalls(root) {
3172
3189
  return byName;
3173
3190
  }
3174
3191
  function checkDuplicatePackages(ctx) {
3192
+ const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
3175
3193
  for (const [name, copies] of genesisInstalls(ctx.root)) {
3176
3194
  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(", ");
3195
+ const shipping = copies.filter((c) => c.runtime);
3196
+ if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
3197
+ ctx.report({
3198
+ rule: "duplicate-genesis-package",
3199
+ level: "warn",
3200
+ file: "package.json",
3201
+ subject: name,
3202
+ 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`
3203
+ });
3204
+ continue;
3205
+ }
3178
3206
  ctx.report({
3179
3207
  rule: "duplicate-genesis-package",
3180
- level: "warn",
3208
+ level: "info",
3181
3209
  file: "package.json",
3182
3210
  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`
3211
+ 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
3212
  });
3185
3213
  }
3186
3214
  }
3187
3215
  function checkPeerRanges(ctx) {
3188
- const rel = (abs) => path3.relative(ctx.root, abs).split(path3.sep).join("/");
3216
+ const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
3189
3217
  for (const copies of genesisInstalls(ctx.root).values()) {
3190
3218
  for (const copy of copies) {
3191
3219
  const dir = copy.absolutePath;
@@ -3198,7 +3226,8 @@ function checkPeerRanges(ctx) {
3198
3226
  if (satisfies(installed, range) !== false) continue;
3199
3227
  ctx.report({
3200
3228
  rule: "peer-range-mismatch",
3201
- level: "warn",
3229
+ // A dev tool's own tree (the CLI's) doesn't run in the app.
3230
+ level: copy.devOnly ? "info" : "warn",
3202
3231
  file: "package.json",
3203
3232
  subject: `${copy.name}>${peer}`,
3204
3233
  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 +3236,401 @@ function checkPeerRanges(ctx) {
3207
3236
  }
3208
3237
  }
3209
3238
  }
3239
+ var TRAIL_DEPTH = 6;
3240
+ var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
3241
+ var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
3242
+ var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
3243
+ var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
3244
+ function stripForImports(code) {
3245
+ const out = [];
3246
+ const blank = (ch) => ch === "\n" ? "\n" : " ";
3247
+ const n = code.length;
3248
+ const templates = [];
3249
+ let depth = 0;
3250
+ let i = 0;
3251
+ const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
3252
+ const opensString = () => {
3253
+ const before = out.slice(-12).join("");
3254
+ if (!/[\w$]$/.test(before)) return true;
3255
+ return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
3256
+ };
3257
+ const templateBody = () => {
3258
+ while (i < n) {
3259
+ const ch = code[i];
3260
+ if (ch === "\\") {
3261
+ out.push(" ", blank(code[i + 1] ?? ""));
3262
+ i += 2;
3263
+ } else if (ch === "`") {
3264
+ out.push("`");
3265
+ i++;
3266
+ return;
3267
+ } else if (ch === "$" && code[i + 1] === "{") {
3268
+ out.push("${");
3269
+ i += 2;
3270
+ templates.push(depth);
3271
+ depth++;
3272
+ return;
3273
+ } else {
3274
+ out.push(blank(ch));
3275
+ i++;
3276
+ }
3277
+ }
3278
+ };
3279
+ while (i < n) {
3280
+ const ch = code[i];
3281
+ const next = code[i + 1];
3282
+ if (ch === "/" && next === "/") {
3283
+ while (i < n && code[i] !== "\n") {
3284
+ out.push(" ");
3285
+ i++;
3286
+ }
3287
+ } else if (ch === "/" && next === "*") {
3288
+ out.push(" ");
3289
+ i += 2;
3290
+ while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
3291
+ out.push(blank(code[i]));
3292
+ i++;
3293
+ }
3294
+ if (i < n) {
3295
+ out.push(" ");
3296
+ i += 2;
3297
+ }
3298
+ } else if ((ch === '"' || ch === "'") && opensString()) {
3299
+ const keep = isSpecifier();
3300
+ out.push(ch);
3301
+ i++;
3302
+ while (i < n && code[i] !== ch && code[i] !== "\n") {
3303
+ if (code[i] === "\\") {
3304
+ out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
3305
+ i += 2;
3306
+ } else {
3307
+ out.push(keep ? code[i] : blank(code[i]));
3308
+ i++;
3309
+ }
3310
+ }
3311
+ if (i < n) {
3312
+ out.push(code[i]);
3313
+ i++;
3314
+ }
3315
+ } else if (ch === "`") {
3316
+ out.push("`");
3317
+ i++;
3318
+ templateBody();
3319
+ } else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
3320
+ templates.pop();
3321
+ depth--;
3322
+ out.push("}");
3323
+ i++;
3324
+ templateBody();
3325
+ } else {
3326
+ if (ch === "{") depth++;
3327
+ else if (ch === "}") depth--;
3328
+ out.push(ch);
3329
+ i++;
3330
+ }
3331
+ }
3332
+ return out.join("");
3333
+ }
3334
+ function bindings(clause) {
3335
+ const out = [];
3336
+ const named = /\{([^}]*)\}/.exec(clause);
3337
+ for (const part of named?.[1].split(",") ?? []) {
3338
+ const p = part.trim();
3339
+ if (!p || p.startsWith("type ")) continue;
3340
+ out.push(p.split(/\s+as\s+/).pop().trim());
3341
+ }
3342
+ const rest = clause.replace(/\{[^}]*\}/, "");
3343
+ const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
3344
+ if (ns) out.push(ns[1]);
3345
+ const def = /^\s*([\w$]+)/.exec(rest);
3346
+ if (def && def[1] !== "as") out.push(def[1]);
3347
+ return out;
3348
+ }
3349
+ function readJsonc(file) {
3350
+ try {
3351
+ const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
3352
+ return JSON.parse(text);
3353
+ } catch {
3354
+ return null;
3355
+ }
3356
+ }
3357
+ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3358
+ if (seen.has(file) || seen.size > 10) return {};
3359
+ seen.add(file);
3360
+ const json = readJsonc(file);
3361
+ if (!json) return {};
3362
+ const dir = path14.dirname(file);
3363
+ let merged = {};
3364
+ const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3365
+ for (const ext of parents) {
3366
+ if (typeof ext !== "string") continue;
3367
+ let target = null;
3368
+ if (ext.startsWith(".") || path14.isAbsolute(ext)) {
3369
+ const abs = path14.resolve(dir, ext);
3370
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3371
+ } else {
3372
+ const parts = ext.split("/");
3373
+ const nameLength = ext.startsWith("@") ? 2 : 1;
3374
+ const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3375
+ if (pkgDir) {
3376
+ const sub = parts.slice(nameLength).join("/");
3377
+ const abs = path14.join(pkgDir, sub || "tsconfig.json");
3378
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3379
+ }
3380
+ }
3381
+ if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3382
+ }
3383
+ const opts = json.compilerOptions ?? {};
3384
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
3385
+ if (opts.paths && typeof opts.paths === "object") {
3386
+ merged.paths = opts.paths;
3387
+ merged.pathsDir = dir;
3388
+ }
3389
+ return merged;
3390
+ }
3391
+ function aliases(root) {
3392
+ const table = [];
3393
+ let baseUrl = null;
3394
+ for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3395
+ const file = path14.join(root, name);
3396
+ if (!existsSync(file)) continue;
3397
+ const config = readTsconfig(root, file);
3398
+ baseUrl ??= config.baseUrl ?? null;
3399
+ const base = config.baseUrl ?? config.pathsDir ?? root;
3400
+ for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3401
+ if (!Array.isArray(targets)) continue;
3402
+ const exact = !pattern.endsWith("*");
3403
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
3404
+ }
3405
+ }
3406
+ const pkg = readJsonc(path14.join(root, "package.json"));
3407
+ for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3408
+ if (typeof target !== "string") continue;
3409
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
3410
+ }
3411
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
3412
+ return { table, baseUrl };
3413
+ }
3414
+ function resolveFile(base) {
3415
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
3416
+ if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3417
+ for (const p of tries) {
3418
+ if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3419
+ }
3420
+ return null;
3421
+ }
3422
+ var trails = /* @__PURE__ */ new WeakMap();
3423
+ function trailFor(ctx) {
3424
+ let t = trails.get(ctx.files);
3425
+ if (!t) trails.set(ctx.files, t = createTrail(ctx));
3426
+ return t;
3427
+ }
3428
+ function createTrail(ctx) {
3429
+ const { table, baseUrl } = aliases(ctx.root);
3430
+ let declared = null;
3431
+ try {
3432
+ const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
3433
+ declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3434
+ } catch {
3435
+ declared = null;
3436
+ }
3437
+ const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
3438
+ const read = (abs) => byPath.get(abs) ?? readSource(abs);
3439
+ const importsCache = /* @__PURE__ */ new Map();
3440
+ const importsOf = (file) => {
3441
+ const hit = importsCache.get(file.absolutePath);
3442
+ if (hit) return hit;
3443
+ const files = [];
3444
+ let lost = false;
3445
+ const code = stripped(file);
3446
+ const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
3447
+ for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3448
+ for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3449
+ 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]);
3450
+ const specs = [];
3451
+ for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
3452
+ for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
3453
+ for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
3454
+ for (const spec of specs) {
3455
+ if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3456
+ let resolved = null;
3457
+ if (spec.startsWith(".")) {
3458
+ resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
3459
+ if (!resolved) lost = true;
3460
+ } else {
3461
+ const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3462
+ if (alias) {
3463
+ for (const t of alias.targets) {
3464
+ resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
3465
+ if (resolved) break;
3466
+ }
3467
+ }
3468
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
3469
+ if (!resolved) {
3470
+ const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3471
+ if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
3472
+ }
3473
+ }
3474
+ if (resolved && !files.includes(resolved)) files.push(resolved);
3475
+ }
3476
+ const out = { files, lost };
3477
+ importsCache.set(file.absolutePath, out);
3478
+ return out;
3479
+ };
3480
+ const strippedCache = /* @__PURE__ */ new Map();
3481
+ const stripped = (file) => {
3482
+ let c = strippedCache.get(file.absolutePath);
3483
+ if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
3484
+ return c;
3485
+ };
3486
+ const memo = /* @__PURE__ */ new WeakMap();
3487
+ const reach = (file, test2, depth, seen) => {
3488
+ let cache = memo.get(test2);
3489
+ if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
3490
+ const k = `${file.absolutePath}\0${depth}`;
3491
+ const cached = cache.get(k);
3492
+ if (cached) return [cached, false];
3493
+ let result;
3494
+ let cut = false;
3495
+ if (test2(stripped(file))) result = "yes";
3496
+ else {
3497
+ const { files, lost } = importsOf(file);
3498
+ let unknown = lost && depth > 0;
3499
+ result = "no";
3500
+ if (depth > 0) {
3501
+ seen.add(file.absolutePath);
3502
+ for (const abs of files) {
3503
+ if (seen.has(abs)) {
3504
+ cut = true;
3505
+ continue;
3506
+ }
3507
+ const target = read(abs);
3508
+ if (!target) {
3509
+ unknown = true;
3510
+ continue;
3511
+ }
3512
+ const [r, c] = reach(target, test2, depth - 1, seen);
3513
+ if (c) cut = true;
3514
+ if (r === "yes") {
3515
+ result = "yes";
3516
+ break;
3517
+ }
3518
+ if (r === "unknown") unknown = true;
3519
+ }
3520
+ seen.delete(file.absolutePath);
3521
+ }
3522
+ if (result === "no" && unknown) result = "unknown";
3523
+ }
3524
+ if (result === "yes" || !cut) cache.set(k, result);
3525
+ return [result, cut && result !== "yes"];
3526
+ };
3527
+ return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3528
+ }
3529
+
3530
+ // src/doctor/routes.ts
3210
3531
  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"]);
3532
+ var STEMS = {
3533
+ tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
3534
+ "next-app": {
3535
+ layout: /* @__PURE__ */ new Set(["layout"]),
3536
+ index: /* @__PURE__ */ new Set(["page"]),
3537
+ skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
3538
+ },
3539
+ "next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
3540
+ };
3213
3541
  var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
3214
3542
  var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
3543
+ var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
3544
+ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
3545
+ 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
3546
  function routesDir(ctx) {
3216
3547
  if (ctx.config.routesDir) return ctx.config.routesDir;
3217
- return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path3.join(ctx.root, d))) ?? null;
3548
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
3218
3549
  }
3219
3550
  var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
3551
+ function flavorOf(dir, rels) {
3552
+ const stems = rels.map((r) => r.split("/").pop());
3553
+ if (stems.includes("__root")) return "tanstack";
3554
+ if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
3555
+ if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
3556
+ return "tanstack";
3557
+ }
3558
+ function renders(code) {
3559
+ const elements = renderedElements(code);
3560
+ if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
3561
+ const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
3562
+ const named = COMPONENT_OPTION.exec(code)?.[1];
3563
+ if (named && !definedHere(named)) return true;
3564
+ if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
3565
+ const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
3566
+ return exported !== void 0 && !definedHere(exported);
3567
+ }
3220
3568
  function webRoutes(ctx) {
3221
3569
  const dir = routesDir(ctx);
3222
3570
  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(/\.[^.]+$/, "");
3571
+ 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(/\.[^.]+$/, "") }));
3572
+ const flavor = flavorOf(dir, candidates.map((c) => c.rel));
3573
+ const stems = STEMS[flavor];
3574
+ const groups = /* @__PURE__ */ new Map();
3575
+ for (const { file, rel } of candidates) {
3227
3576
  const parts = rel.split("/");
3228
3577
  if (parts.some((p) => p.startsWith("-"))) continue;
3578
+ if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
3579
+ if (flavor === "next-pages" && parts[0] === "api") continue;
3580
+ if (stems.skip.test(parts.at(-1))) continue;
3581
+ if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
3582
+ const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
3583
+ groups.set(id, [...groups.get(id) ?? [], file]);
3584
+ }
3585
+ const trail = trailFor(ctx);
3586
+ const routes = [];
3587
+ for (const [id, files] of groups) {
3588
+ const parts = id.split("/");
3229
3589
  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) ?? "")) {
3590
+ const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
3591
+ const named = stems.layout.has(stem) || stems.index.has(stem);
3592
+ const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
3593
+ const segments = [...folders, ...own];
3594
+ const tree = [...parts, ...own];
3595
+ let index = stems.index.has(stem);
3596
+ if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
3233
3597
  segments.pop();
3598
+ tree.pop();
3234
3599
  index = true;
3235
3600
  }
3236
- const elements = renderedElements(file.code);
3237
- const layout = LAYOUT_STEMS.has(stem) || elements.includes("Outlet");
3601
+ const code = files.map((f) => f.code).join("\n");
3602
+ const elements = renderedElements(code);
3603
+ const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
3604
+ const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
3605
+ const layout = stems.layout.has(stem) || pathless || outlet;
3606
+ const rendering = renders(code);
3607
+ const ownContent = new RegExp(OWN_CONTENT).test(code);
3608
+ const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
3609
+ const page = !pure && !pathless && (!layout || ownContent);
3238
3610
  routes.push({
3239
- file,
3611
+ file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
3612
+ files,
3240
3613
  segments,
3614
+ tree,
3241
3615
  index,
3242
3616
  layout,
3243
- detail: !index && !layout && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
3244
- redirectOnly: elements.every((e) => NON_PAGE_ELEMENTS.has(e)) && !HTML_ELEMENT.test(file.code),
3617
+ page,
3618
+ detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
3619
+ redirectOnly: !rendering,
3245
3620
  parents: []
3246
3621
  });
3247
3622
  }
3248
3623
  for (const r of routes) {
3249
- const own = r.segments;
3624
+ const own = r.tree;
3250
3625
  for (const p of routes) {
3251
3626
  if (p === r || !p.layout) continue;
3252
- const n = p.segments.length;
3627
+ const n = p.tree.length;
3253
3628
  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;
3629
+ if (key(own.slice(0, n)) !== key(p.tree)) continue;
3630
+ if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
3256
3631
  r.parents.push(p);
3257
3632
  }
3258
- r.parents.sort((a, b) => b.segments.length - a.segments.length);
3633
+ r.parents.sort((a, b) => b.tree.length - a.tree.length);
3259
3634
  }
3260
3635
  return routes;
3261
3636
  }
@@ -3273,8 +3648,19 @@ var rendersRe = (names) => {
3273
3648
  const list = [...names];
3274
3649
  return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
3275
3650
  };
3651
+ function routeReach(ctx, r, test2) {
3652
+ const trail = trailFor(ctx);
3653
+ let unknown = false;
3654
+ for (const f of r.files) {
3655
+ const got = trail.reach(f, test2);
3656
+ if (got === "yes") return "yes";
3657
+ if (got === "unknown") unknown = true;
3658
+ }
3659
+ return unknown ? "unknown" : "no";
3660
+ }
3661
+ var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
3276
3662
  function insideShell(ctx, routes) {
3277
- const shell = new Set(routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => SHELL.test(code))));
3663
+ const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
3278
3664
  const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
3279
3665
  return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
3280
3666
  }
@@ -3285,20 +3671,19 @@ function checkHandRolledSubNav(ctx) {
3285
3671
  const inShell = insideShell(ctx, routes);
3286
3672
  const ui = ctx.genesis.uiPackage;
3287
3673
  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;
3674
+ if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
3675
+ 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);
3676
+ if (hit) {
3677
+ const { f, m } = hit;
3678
+ const code = f.code;
3293
3679
  ctx.report({
3294
3680
  rule: "hand-rolled-sub-nav",
3295
3681
  level: "warn",
3296
- file: r.file.path,
3682
+ file: f.path,
3297
3683
  line: lineAt(code, m.index),
3298
3684
  subject: m[1],
3299
3685
  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
3686
  });
3301
- break;
3302
3687
  }
3303
3688
  }
3304
3689
  }
@@ -3346,11 +3731,12 @@ function checkResourceWorkspaces(ctx) {
3346
3731
  byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
3347
3732
  }
3348
3733
  for (const [dir, routes] of byFolder) {
3349
- const has2 = routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => header.test(code)));
3734
+ const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
3735
+ const has2 = routes.filter((r) => reach.get(r) === "yes");
3350
3736
  if (has2.length === 0) continue;
3351
3737
  const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
3352
3738
  for (const r of routes) {
3353
- if (has2.includes(r)) continue;
3739
+ if (reach.get(r) !== "no") continue;
3354
3740
  ctx.report({
3355
3741
  rule: "resource-workspace",
3356
3742
  level: "info",
@@ -3374,14 +3760,14 @@ function checkPageLayouts(ctx) {
3374
3760
  };
3375
3761
  const cache = /* @__PURE__ */ new Map();
3376
3762
  const provides = (r) => {
3377
- if (!cache.has(r)) cache.set(r, viaOneImport(ctx.root, ctx.files, r.file, rendersLayout));
3763
+ if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
3378
3764
  return cache.get(r);
3379
3765
  };
3380
3766
  const list = [...layouts].sort();
3381
3767
  const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
3382
3768
  for (const r of routes) {
3383
- if (r.layout || r.redirectOnly || !inShell(r)) continue;
3384
- if (provides(r) || r.parents.some(provides)) continue;
3769
+ if (!r.page || r.redirectOnly || !inShell(r)) continue;
3770
+ if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
3385
3771
  ctx.report({
3386
3772
  rule: "page-layout",
3387
3773
  level: "warn",
@@ -3412,7 +3798,7 @@ function checkIsoDateSlices(ctx) {
3412
3798
 
3413
3799
  // src/doctor/index.ts
3414
3800
  async function runDoctor(options = {}) {
3415
- const root = path3.resolve(options.root ?? process.cwd());
3801
+ const root = path14.resolve(options.root ?? process.cwd());
3416
3802
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
3417
3803
  const config = loaded.config;
3418
3804
  const genesis = options.genesis ?? loadGenesis(root, config);