@marktiderman/genesis-cli 1.8.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync, existsSync, readdirSync, mkdirSync, writeFileSync, mkdtempSync, rmSync, realpathSync, statSync, lstatSync } from 'fs';
3
- import * as path28 from 'path';
3
+ import * as path32 from 'path';
4
4
  import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
5
5
  import { createHash } from 'crypto';
6
6
  import { fileURLToPath, pathToFileURL } from 'url';
@@ -26,7 +26,7 @@ var __export = (target, all) => {
26
26
  function buildCatalog(packagesDir) {
27
27
  const packages = {};
28
28
  for (const dir of readdirSync(packagesDir).sort()) {
29
- const file = path28.join(packagesDir, dir, "package.json");
29
+ const file = path32.join(packagesDir, dir, "package.json");
30
30
  if (!existsSync(file)) continue;
31
31
  const pkg = JSON.parse(readFileSync(file, "utf8"));
32
32
  if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
@@ -64,11 +64,11 @@ function parseManifest(home, id, raw, version) {
64
64
  if (!safe) problems.push(`${where}: ${JSON.stringify(value)} is not a plain path inside the package`);
65
65
  return safe ?? "";
66
66
  };
67
- const list = (key) => {
68
- const v = raw[key];
67
+ const list = (key2) => {
68
+ const v = raw[key2];
69
69
  if (v === void 0) return [];
70
70
  if (!Array.isArray(v)) {
71
- problems.push(`${at}.${key}: must be a list`);
71
+ problems.push(`${at}.${key2}: must be a list`);
72
72
  return [];
73
73
  }
74
74
  return v;
@@ -234,30 +234,30 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
234
234
  }
235
235
  });
236
236
  function inside(parent, child) {
237
- const rel = path28.relative(parent, child);
238
- return rel === "" || !rel.startsWith("..") && !path28.isAbsolute(rel);
237
+ const rel = path32.relative(parent, child);
238
+ return rel === "" || !rel.startsWith("..") && !path32.isAbsolute(rel);
239
239
  }
240
240
  function readPackageFile(packageDir2, rel) {
241
241
  const safe = safeRelative(rel);
242
242
  if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
243
243
  const root = realpathSync(packageDir2);
244
- const file = path28.join(root, ...safe.split("/"));
244
+ const file = path32.join(root, ...safe.split("/"));
245
245
  if (!existsSync(file)) return null;
246
- const real = realpathSync(file);
247
- if (!inside(root, real)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
248
- if (!statSync(real).isFile()) return null;
249
- return readFileSync(real, "utf8");
246
+ const real2 = realpathSync(file);
247
+ if (!inside(root, real2)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
248
+ if (!statSync(real2).isFile()) return null;
249
+ return readFileSync(real2, "utf8");
250
250
  }
251
251
  function readPackageDir(packageDir2, rel, skipped = []) {
252
252
  const safe = safeRelative(rel);
253
253
  if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
254
254
  const root = realpathSync(packageDir2);
255
- const dir = path28.join(root, ...safe.split("/"));
255
+ const dir = path32.join(root, ...safe.split("/"));
256
256
  if (!existsSync(dir)) return null;
257
- const real = realpathSync(dir);
258
- if (!inside(root, real) || !statSync(real).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
257
+ const real2 = realpathSync(dir);
258
+ if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
259
259
  const out = [];
260
- for (const entry of readdirSync(real, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
260
+ for (const entry of readdirSync(real2, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
261
261
  if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(entry.name) || entry.isDirectory()) {
262
262
  skipped.push(`${safe}/${entry.name}`);
263
263
  continue;
@@ -272,7 +272,7 @@ function appPath(root, rel) {
272
272
  if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
273
273
  if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
274
274
  const realRoot = realpathSync(root);
275
- const target = path28.join(realRoot, ...safe.split("/"));
275
+ const target = path32.join(realRoot, ...safe.split("/"));
276
276
  const there = (p) => {
277
277
  try {
278
278
  lstatSync(p);
@@ -281,15 +281,15 @@ function appPath(root, rel) {
281
281
  return false;
282
282
  }
283
283
  };
284
- let probe = path28.dirname(target);
285
- while (!there(probe)) probe = path28.dirname(probe);
286
- let real;
284
+ let probe = path32.dirname(target);
285
+ while (!there(probe)) probe = path32.dirname(probe);
286
+ let real2;
287
287
  try {
288
- real = realpathSync(probe);
288
+ real2 = realpathSync(probe);
289
289
  } catch {
290
- throw new Error(`${rel} goes through a broken symlink (${path28.relative(realRoot, probe)}); refused`);
290
+ throw new Error(`${rel} goes through a broken symlink (${path32.relative(realRoot, probe)}); refused`);
291
291
  }
292
- if (!inside(realRoot, real)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
292
+ if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
293
293
  if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
294
294
  return target;
295
295
  }
@@ -299,20 +299,20 @@ function readApp(root, rel) {
299
299
  }
300
300
  function createApp(root, rel, content) {
301
301
  const file = appPath(root, rel);
302
- mkdirSync(path28.dirname(file), { recursive: true });
302
+ mkdirSync(path32.dirname(file), { recursive: true });
303
303
  writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
304
304
  }
305
305
  function replaceApp(root, rel, content) {
306
306
  const file = appPath(root, rel);
307
- mkdirSync(path28.dirname(file), { recursive: true });
307
+ mkdirSync(path32.dirname(file), { recursive: true });
308
308
  writeFileSync(file, content, "utf8");
309
309
  }
310
310
  function listApp(root, rel, options = {}) {
311
- const dir = path28.join(root, rel);
311
+ const dir = path32.join(root, rel);
312
312
  if (!existsSync(dir)) return [];
313
313
  const out = [];
314
314
  const walk2 = (r) => {
315
- for (const entry of readdirSync(path28.join(root, r), { withFileTypes: true })) {
315
+ for (const entry of readdirSync(path32.join(root, r), { withFileTypes: true })) {
316
316
  const child = `${r}/${entry.name}`;
317
317
  if (entry.isDirectory()) walk2(child);
318
318
  else if (entry.isFile() || options.symlinks && entry.isSymbolicLink()) out.push(child);
@@ -345,41 +345,41 @@ __export(discover_exports, {
345
345
  workspacePackagesDir: () => workspacePackagesDir
346
346
  });
347
347
  function cliPackageDir() {
348
- let dir = path28.dirname(fileURLToPath(import.meta.url));
348
+ let dir = path32.dirname(fileURLToPath(import.meta.url));
349
349
  for (; ; ) {
350
- const file = path28.join(dir, "package.json");
350
+ const file = path32.join(dir, "package.json");
351
351
  if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
352
- const parent = path28.dirname(dir);
352
+ const parent = path32.dirname(dir);
353
353
  if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
354
354
  dir = parent;
355
355
  }
356
356
  }
357
357
  function workspacePackagesDir() {
358
- const dir = path28.resolve(cliPackageDir(), "..");
359
- return existsSync(path28.join(dir, "features", "package.json")) && existsSync(path28.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
358
+ const dir = path32.resolve(cliPackageDir(), "..");
359
+ return existsSync(path32.join(dir, "features", "package.json")) && existsSync(path32.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
360
360
  }
361
361
  function readCatalog() {
362
362
  if (catalogCache) return catalogCache;
363
363
  const workspace = workspacePackagesDir();
364
364
  if (workspace) return catalogCache = buildCatalog(workspace);
365
- const file = path28.join(cliPackageDir(), "dist", "genesis-catalog.json");
365
+ const file = path32.join(cliPackageDir(), "dist", "genesis-catalog.json");
366
366
  catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
367
367
  return catalogCache;
368
368
  }
369
369
  function installedGenesis(root) {
370
370
  const found = /* @__PURE__ */ new Map();
371
- let dir = path28.resolve(root);
371
+ let dir = path32.resolve(root);
372
372
  for (; ; ) {
373
- const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path28.join(dir, m)));
374
- const scope = path28.join(dir, "node_modules", "@marktiderman");
373
+ const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path32.join(dir, m)));
374
+ const scope = path32.join(dir, "node_modules", "@marktiderman");
375
375
  if (existsSync(scope)) {
376
376
  for (const entry of readdirSync(scope)) {
377
377
  const name = `@marktiderman/${entry}`;
378
378
  if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
379
- if (existsSync(path28.join(scope, entry, "package.json"))) found.set(name, path28.join(scope, entry));
379
+ if (existsSync(path32.join(scope, entry, "package.json"))) found.set(name, path32.join(scope, entry));
380
380
  }
381
381
  }
382
- const parent = path28.dirname(dir);
382
+ const parent = path32.dirname(dir);
383
383
  if (atInstallRoot || parent === dir) return found;
384
384
  dir = parent;
385
385
  }
@@ -391,28 +391,28 @@ function packageDir(root, name) {
391
391
  return null;
392
392
  }
393
393
  function packageVersion(dir) {
394
- return JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8")).version;
394
+ return JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8")).version;
395
395
  }
396
396
  function declarationsOf(dir, warnings) {
397
- const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
398
- const key = `${realpathSync(dir)}@${pkg.version ?? ""}`;
399
- let cached = declarationCache.get(key);
397
+ const pkg = JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
398
+ const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
399
+ let cached = declarationCache.get(key2);
400
400
  if (!cached) {
401
401
  cached = loadDeclarations(dir, warnings);
402
- declarationCache.set(key, cached);
402
+ declarationCache.set(key2, cached);
403
403
  }
404
404
  return cached;
405
405
  }
406
406
  async function loadDeclarations(dir, warnings) {
407
- const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
407
+ const pkg = JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
408
408
  const entry = pkg.exports?.["./blocks"];
409
409
  const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
410
410
  if (typeof target !== "string") return {};
411
411
  const rel = safeRelative(target.replace(/^\.\//, ""));
412
- const file = rel && path28.join(dir, ...rel.split("/"));
412
+ const file = rel && path32.join(dir, ...rel.split("/"));
413
413
  if (!file || !inside(dir, file) || !existsSync(file)) return {};
414
414
  try {
415
- const jiti = createJiti(path28.join(dir, "package.json"), { moduleCache: false });
415
+ const jiti = createJiti(path32.join(dir, "package.json"), { moduleCache: false });
416
416
  const mod = await jiti.import(file);
417
417
  const out = {};
418
418
  for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
@@ -423,7 +423,7 @@ async function loadDeclarations(dir, warnings) {
423
423
  }
424
424
  }
425
425
  async function blocksOfInstalled(dir, warnings = []) {
426
- const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
426
+ const pkg = JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
427
427
  const raw = rawBlocksOf(pkg);
428
428
  const declared = await declarationsOf(dir, warnings);
429
429
  const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
@@ -502,7 +502,7 @@ function emptyLock() {
502
502
  return { version: 1, blocks: {}, files: {} };
503
503
  }
504
504
  function readLock(root) {
505
- const file = path28.join(root, LOCK_FILE);
505
+ const file = path32.join(root, LOCK_FILE);
506
506
  if (!existsSync(file)) return emptyLock();
507
507
  const raw = JSON.parse(readFileSync(file, "utf8"));
508
508
  if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
@@ -557,7 +557,7 @@ function migrationHeader(pkg, file, source) {
557
557
  `;
558
558
  }
559
559
  function stemOrNull(file) {
560
- return MIGRATION_FILE.exec(path28.posix.basename(file))?.[2] ?? null;
560
+ return MIGRATION_FILE.exec(path32.posix.basename(file))?.[2] ?? null;
561
561
  }
562
562
  function stemOf(file) {
563
563
  const stem = stemOrNull(file);
@@ -567,7 +567,7 @@ function stemOf(file) {
567
567
  function readAppMigrations(root, dir = MIGRATIONS_DIR) {
568
568
  return listApp(root, dir, { symlinks: true }).filter((p) => p.endsWith(".sql")).map((p) => {
569
569
  const content = readApp(root, p) ?? "";
570
- const name = path28.posix.basename(p);
570
+ const name = path32.posix.basename(p);
571
571
  const m = HEADER.exec(content);
572
572
  if (m) return { path: p, name, content, tracked: { package: m[1], file: m[2], sha256: m[3], body: content.slice(m[0].length) } };
573
573
  const f = FORWARD.exec(content);
@@ -583,8 +583,8 @@ function timestampOf(date) {
583
583
  }
584
584
  function nextStamp(ts) {
585
585
  const d = new Date(Date.UTC(+ts.slice(0, 4), +ts.slice(4, 6) - 1, +ts.slice(6, 8), +ts.slice(8, 10), +ts.slice(10, 12), +ts.slice(12, 14)));
586
- const real = !Number.isNaN(d.getTime()) && d.getUTCFullYear() >= 1e3 && timestampOf(d) === ts;
587
- const next = real ? timestampOf(new Date(d.getTime() + 1e3)) : (BigInt(ts) + 1n).toString().padStart(14, "0");
586
+ const real2 = !Number.isNaN(d.getTime()) && d.getUTCFullYear() >= 1e3 && timestampOf(d) === ts;
587
+ const next = real2 ? timestampOf(new Date(d.getTime() + 1e3)) : (BigInt(ts) + 1n).toString().padStart(14, "0");
588
588
  if (next.length !== 14 || next <= ts) throw new Error(`No 14-digit timestamp follows ${ts}.`);
589
589
  return next;
590
590
  }
@@ -612,9 +612,9 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
612
612
  const pending = [];
613
613
  const seen = /* @__PURE__ */ new Set();
614
614
  for (const src of sources) {
615
- const key = `${src.package} ${src.file}`;
616
- if (seen.has(key)) continue;
617
- seen.add(key);
615
+ const key2 = `${src.package} ${src.file}`;
616
+ if (seen.has(key2)) continue;
617
+ seen.add(key2);
618
618
  const stem = stemOf(src.file);
619
619
  const base = { ...src.block ? { block: src.block } : {}, package: src.package, file: src.file, state: "current" };
620
620
  const sourceSha = src.source === null ? null : textSha(src.source);
@@ -649,7 +649,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
649
649
  detail = copy.tracked ? renamed.trim() : "copied before headers; matches the package";
650
650
  } else if (copy.tracked) {
651
651
  state = "changed-upstream";
652
- detail = `${src.package} now ships a different ${path28.posix.basename(src.file)}; the applied copy is never rewritten`;
652
+ detail = `${src.package} now ships a different ${path32.posix.basename(src.file)}; the applied copy is never rewritten`;
653
653
  } else {
654
654
  state = "differs";
655
655
  detail = "has the package migration's name but other text and no header; treated as the app's own";
@@ -671,8 +671,8 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
671
671
  row.target = target2;
672
672
  creates.push({ path: target2, content: migrationHeader(src.package, src.file, src.source) + src.source, kind, source: { package: src.package, file: src.file } });
673
673
  if (options.tests !== false && src.test && src.testSource != null) {
674
- const test = `${TESTS_DIR}/${path28.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
675
- if (readApp(root, test) === null && !creates.some((c) => c.path === test)) creates.push({ path: test, content: src.testSource, kind: "test", source: { package: src.package, file: src.test } });
674
+ const test2 = `${TESTS_DIR}/${path32.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
675
+ if (readApp(root, test2) === null && !creates.some((c) => c.path === test2)) creates.push({ path: test2, content: src.testSource, kind: "test", source: { package: src.package, file: src.test } });
676
676
  }
677
677
  return;
678
678
  }
@@ -731,25 +731,25 @@ function privacyDataType(type) {
731
731
  }
732
732
  function appPath2(v, where, fail) {
733
733
  if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
734
- if (path28.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
735
- const norm = path28.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
734
+ if (path32.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
735
+ const norm = path32.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
736
736
  if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
737
737
  return norm;
738
738
  }
739
739
  function loadConfig(root, configPath) {
740
740
  if (configPath) {
741
- const file = path28.resolve(root, configPath);
741
+ const file = path32.resolve(root, configPath);
742
742
  if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
743
743
  const json = readJson(file);
744
- const block = path28.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
745
- return { config: validateConfig(block ?? {}, file), file, dir: path28.dirname(file) };
744
+ const block = path32.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
745
+ return { config: validateConfig(block ?? {}, file), file, dir: path32.dirname(file) };
746
746
  }
747
- const own = path28.join(root, "genesis.config.json");
747
+ const own = path32.join(root, "genesis.config.json");
748
748
  if (existsSync(own)) {
749
749
  const block = readGenesisConfig(root)?.raw.doctor;
750
750
  return { config: validateConfig(block ?? {}, own), file: own, dir: root };
751
751
  }
752
- const pkg = path28.join(root, "package.json");
752
+ const pkg = path32.join(root, "package.json");
753
753
  if (existsSync(pkg)) {
754
754
  const block = readJson(pkg)?.genesis?.doctor;
755
755
  if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
@@ -764,7 +764,7 @@ function readJson(file) {
764
764
  }
765
765
  }
766
766
  function readGenesisConfig(root) {
767
- const file = path28.join(root, "genesis.config.json");
767
+ const file = path32.join(root, "genesis.config.json");
768
768
  if (!existsSync(file)) return null;
769
769
  const raw = readJson(file);
770
770
  if (!isObject2(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
@@ -779,7 +779,7 @@ function validatePrivacy(raw, source = "config") {
779
779
  };
780
780
  if (!isObject2(raw)) fail(`"privacy" must be an object`);
781
781
  const c = raw;
782
- for (const key of Object.keys(c)) if (!PRIVACY_KEYS.has(key)) fail(`privacy: unknown setting "${key}"`);
782
+ for (const key2 of Object.keys(c)) if (!PRIVACY_KEYS.has(key2)) fail(`privacy: unknown setting "${key2}"`);
783
783
  const out = {};
784
784
  if (c.blocks !== void 0) {
785
785
  if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
@@ -794,7 +794,7 @@ function validatePrivacy(raw, source = "config") {
794
794
  out.collects = c.collects.map((entry, i) => {
795
795
  const where = `privacy.collects[${i}]`;
796
796
  if (!isObject2(entry)) return fail(`${where} must be an object`);
797
- for (const key of Object.keys(entry)) if (!DATA_USE_KEYS.has(key)) fail(`${where}: unknown setting "${key}"`);
797
+ for (const key2 of Object.keys(entry)) if (!DATA_USE_KEYS.has(key2)) fail(`${where}: unknown setting "${key2}"`);
798
798
  if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
799
799
  fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
800
800
  }
@@ -815,7 +815,7 @@ function validateLinks(raw, source = "config") {
815
815
  };
816
816
  if (!isObject2(raw)) fail(`"links" must be an object`);
817
817
  const c = raw;
818
- for (const key of Object.keys(c)) if (!LINK_KEYS.has(key)) fail(`links: unknown setting "${key}"`);
818
+ for (const key2 of Object.keys(c)) if (!LINK_KEYS.has(key2)) fail(`links: unknown setting "${key2}"`);
819
819
  if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
820
820
  for (const host of c.hosts) {
821
821
  if (!HOST.test(host)) {
@@ -842,15 +842,16 @@ function validateConfig(raw, source = "config") {
842
842
  };
843
843
  if (!isObject2(raw)) fail("the doctor settings must be an object");
844
844
  const c = raw;
845
- for (const key of Object.keys(c)) if (!KNOWN.has(key)) fail(`unknown setting "${key}"`);
845
+ for (const key2 of Object.keys(c)) if (!KNOWN.has(key2)) fail(`unknown setting "${key2}"`);
846
846
  if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
847
847
  if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
848
- for (const key of STRING_LISTS) {
849
- if (c[key] !== void 0 && !isStringList(c[key])) fail(`"${key}" must be a list of strings`);
848
+ for (const key2 of STRING_LISTS) {
849
+ if (c[key2] !== void 0 && !isStringList(c[key2])) fail(`"${key2}" must be a list of strings`);
850
850
  }
851
- for (const key of STRINGS) {
852
- if (c[key] !== void 0 && typeof c[key] !== "string") fail(`"${key}" must be a string`);
851
+ for (const key2 of STRINGS) {
852
+ if (c[key2] !== void 0 && typeof c[key2] !== "string") fail(`"${key2}" must be a string`);
853
853
  }
854
+ if (c.routesDir !== void 0) c.routesDir = appPath2(c.routesDir, `"routesDir"`, fail);
854
855
  if (c.rawTags !== void 0) {
855
856
  if (!isObject2(c.rawTags)) fail(`"rawTags" must be an object`);
856
857
  for (const [tag, v] of Object.entries(c.rawTags)) {
@@ -868,7 +869,7 @@ function validateConfig(raw, source = "config") {
868
869
  if (c.rules !== void 0) {
869
870
  if (!isObject2(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
870
871
  for (const [rule, level] of Object.entries(c.rules)) {
871
- if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
872
+ if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn", "info" or "off"`);
872
873
  }
873
874
  }
874
875
  if (c.allow !== void 0) {
@@ -989,7 +990,7 @@ var init_config = __esm({
989
990
  "third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
990
991
  other: "NSPrivacyCollectedDataTypePurposeOther"
991
992
  };
992
- STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
993
+ STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
993
994
  STRINGS = ["uiPackage", "rulesDoc"];
994
995
  KNOWN = /* @__PURE__ */ new Set([
995
996
  ...STRING_LISTS,
@@ -1004,10 +1005,11 @@ var init_config = __esm({
1004
1005
  "packs",
1005
1006
  "native",
1006
1007
  "supabase",
1008
+ "routesDir",
1007
1009
  "$schema",
1008
1010
  "$comment"
1009
1011
  ]);
1010
- LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
1012
+ LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
1011
1013
  PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
1012
1014
  PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
1013
1015
  PACK_KEYS = {
@@ -1021,11 +1023,11 @@ var init_config = __esm({
1021
1023
  }
1022
1024
  });
1023
1025
  function findPackageDir(from, name) {
1024
- let dir = path28.resolve(from);
1026
+ let dir = path32.resolve(from);
1025
1027
  for (; ; ) {
1026
- const candidate = path28.join(dir, "node_modules", name);
1027
- if (existsSync(path28.join(candidate, "package.json"))) return candidate;
1028
- const parent = path28.dirname(dir);
1028
+ const candidate = path32.join(dir, "node_modules", name);
1029
+ if (existsSync(path32.join(candidate, "package.json"))) return candidate;
1030
+ const parent = path32.dirname(dir);
1029
1031
  if (parent === dir) return null;
1030
1032
  dir = parent;
1031
1033
  }
@@ -1057,13 +1059,27 @@ function loadGenesis(root, config) {
1057
1059
  components,
1058
1060
  tokens,
1059
1061
  rawTags,
1060
- palette: loadPalette(root)
1062
+ palette: loadPalette(root),
1063
+ companions: loadCompanions(root, config, uiPackage)
1061
1064
  };
1062
1065
  }
1066
+ function loadCompanions(root, config, uiPackage) {
1067
+ const out = [];
1068
+ for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
1069
+ if (name === uiPackage) continue;
1070
+ try {
1071
+ const pkg = readPackageExports(root, name);
1072
+ if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
1073
+ } catch (err) {
1074
+ if (!(err instanceof DoctorConfigError)) throw err;
1075
+ }
1076
+ }
1077
+ return out;
1078
+ }
1063
1079
  function readPackageExports(root, uiPackage) {
1064
1080
  const uiDir = findPackageDir(root, uiPackage);
1065
1081
  if (!uiDir) return null;
1066
- const uiPkg = JSON.parse(readFileSync(path28.join(uiDir, "package.json"), "utf8"));
1082
+ const uiPkg = JSON.parse(readFileSync(path32.join(uiDir, "package.json"), "utf8"));
1067
1083
  const typeEntries = /* @__PURE__ */ new Set();
1068
1084
  const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
1069
1085
  if (typeof mainTypes === "string") typeEntries.add(mainTypes);
@@ -1075,7 +1091,7 @@ function readPackageExports(root, uiPackage) {
1075
1091
  const reexportedPackages = /* @__PURE__ */ new Set();
1076
1092
  let readAny = false;
1077
1093
  for (const entry of typeEntries) {
1078
- const file = path28.join(uiDir, entry);
1094
+ const file = path32.join(uiDir, entry);
1079
1095
  if (!existsSync(file)) continue;
1080
1096
  readAny = true;
1081
1097
  const dts = readFileSync(file, "utf8");
@@ -1089,11 +1105,11 @@ function readPackageExports(root, uiPackage) {
1089
1105
  }
1090
1106
  const valueDecls = /* @__PURE__ */ new Set();
1091
1107
  const typeDecls = /* @__PURE__ */ new Set();
1092
- const declRoot = typeof mainTypes === "string" ? path28.dirname(path28.join(uiDir, mainTypes)) : uiDir;
1108
+ const declRoot = typeof mainTypes === "string" ? path32.dirname(path32.join(uiDir, mainTypes)) : uiDir;
1093
1109
  const declFiles = walkDts(declRoot);
1094
1110
  for (const pkg of reexportedPackages) {
1095
1111
  const dir = findPackageDir(uiDir, pkg);
1096
- if (dir) walkDts(path28.join(dir, "dist"), declFiles);
1112
+ if (dir) walkDts(path32.join(dir, "dist"), declFiles);
1097
1113
  }
1098
1114
  for (const file of declFiles) {
1099
1115
  const text = readFileSync(file, "utf8");
@@ -1129,8 +1145,8 @@ function exportTypes(target) {
1129
1145
  if (!target || typeof target !== "object") return void 0;
1130
1146
  const t = target;
1131
1147
  if (typeof t.types === "string") return t.types;
1132
- for (const key of ["import", "default", "require"]) {
1133
- const nested = exportTypes(t[key]);
1148
+ for (const key2 of ["import", "default", "require"]) {
1149
+ const nested = exportTypes(t[key2]);
1134
1150
  if (nested) return nested;
1135
1151
  }
1136
1152
  return void 0;
@@ -1139,7 +1155,7 @@ function walkDts(dir, out = []) {
1139
1155
  if (!existsSync(dir)) return out;
1140
1156
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
1141
1157
  if (entry.name === "node_modules") continue;
1142
- const p = path28.join(dir, entry.name);
1158
+ const p = path32.join(dir, entry.name);
1143
1159
  if (entry.isDirectory()) walkDts(p, out);
1144
1160
  else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
1145
1161
  }
@@ -1156,27 +1172,27 @@ function resolveThemeFiles(root, config, uiDir) {
1156
1172
  }
1157
1173
  const files = [];
1158
1174
  const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
1159
- const themes = ds && path28.join(ds, "dist", "themes");
1175
+ const themes = ds && path32.join(ds, "dist", "themes");
1160
1176
  if (themes && existsSync(themes)) {
1161
- for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path28.join(themes, name));
1177
+ for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path32.join(themes, name));
1162
1178
  }
1163
1179
  if (files.length === 0) {
1164
1180
  throw new DoctorConfigError(
1165
1181
  `No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
1166
1182
  );
1167
1183
  }
1168
- const uiStyles = path28.join(uiDir, "dist", "styles.css");
1184
+ const uiStyles = path32.join(uiDir, "dist", "styles.css");
1169
1185
  if (existsSync(uiStyles)) files.push(uiStyles);
1170
1186
  return files;
1171
1187
  }
1172
1188
  function resolveSpec(root, spec) {
1173
- const local = path28.resolve(root, spec);
1174
- if (spec.startsWith(".") || path28.isAbsolute(spec)) return existsSync(local) ? local : null;
1189
+ const local = path32.resolve(root, spec);
1190
+ if (spec.startsWith(".") || path32.isAbsolute(spec)) return existsSync(local) ? local : null;
1175
1191
  const parts = spec.split("/");
1176
1192
  const nameLength = spec.startsWith("@") ? 2 : 1;
1177
1193
  const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
1178
1194
  if (dir) {
1179
- const file = path28.join(dir, ...parts.slice(nameLength));
1195
+ const file = path32.join(dir, ...parts.slice(nameLength));
1180
1196
  if (existsSync(file) && statSync(file).isFile()) return file;
1181
1197
  }
1182
1198
  return existsSync(local) ? local : null;
@@ -1184,22 +1200,23 @@ function resolveSpec(root, spec) {
1184
1200
  function loadPalette(root) {
1185
1201
  const names = new Set(TAILWIND_PALETTE);
1186
1202
  try {
1187
- const req = createRequire(path28.join(root, "package.json"));
1203
+ const req = createRequire(path32.join(root, "package.json"));
1188
1204
  const colors = req("tailwindcss/colors");
1189
- for (const key of Object.keys(colors?.default ?? colors ?? {})) {
1190
- if (/^[a-z]+$/.test(key) && !["inherit", "current", "transparent"].includes(key)) names.add(key);
1205
+ for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
1206
+ if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
1191
1207
  }
1192
1208
  } catch {
1193
1209
  }
1194
1210
  return [...names].sort();
1195
1211
  }
1196
- var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
1212
+ var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, DEFAULT_COMPONENT_PACKAGES, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
1197
1213
  var init_genesis = __esm({
1198
1214
  "src/doctor/genesis.ts"() {
1199
1215
  init_config();
1200
1216
  DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1201
1217
  NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
1202
1218
  DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
1219
+ DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
1203
1220
  TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
1204
1221
  TAG_ALIASES = { hr: "Separator" };
1205
1222
  NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
@@ -1237,7 +1254,7 @@ var init_genesis = __esm({
1237
1254
  });
1238
1255
  function readReleaseManifest(root) {
1239
1256
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
1240
- const file = dir && path28.join(dir, "dist", "versions.json");
1257
+ const file = dir && path32.join(dir, "dist", "versions.json");
1241
1258
  if (!file || !existsSync(file)) return null;
1242
1259
  return JSON.parse(readFileSync(file, "utf8"));
1243
1260
  }
@@ -1247,7 +1264,7 @@ function checkVersionSkew(ctx) {
1247
1264
  for (const [name, want] of Object.entries(manifest.packages)) {
1248
1265
  const dir = findPackageDir(ctx.root, name);
1249
1266
  if (!dir) continue;
1250
- const have = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8")).version;
1267
+ const have = JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8")).version;
1251
1268
  if (have === want) continue;
1252
1269
  ctx.report({
1253
1270
  rule: "version-skew",
@@ -1266,13 +1283,13 @@ var init_versions = __esm({
1266
1283
  }
1267
1284
  });
1268
1285
  function detectPackageManager(root) {
1269
- let dir = path28.resolve(root);
1286
+ let dir = path32.resolve(root);
1270
1287
  for (; ; ) {
1271
- if (existsSync(path28.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1272
- if (existsSync(path28.join(dir, "bun.lock")) || existsSync(path28.join(dir, "bun.lockb"))) return "bun";
1273
- if (existsSync(path28.join(dir, "yarn.lock"))) return "yarn";
1274
- if (existsSync(path28.join(dir, "package-lock.json"))) return "npm";
1275
- const parent = path28.dirname(dir);
1288
+ if (existsSync(path32.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1289
+ if (existsSync(path32.join(dir, "bun.lock")) || existsSync(path32.join(dir, "bun.lockb"))) return "bun";
1290
+ if (existsSync(path32.join(dir, "yarn.lock"))) return "yarn";
1291
+ if (existsSync(path32.join(dir, "package-lock.json"))) return "npm";
1292
+ const parent = path32.dirname(dir);
1276
1293
  if (parent === dir) return "npm";
1277
1294
  dir = parent;
1278
1295
  }
@@ -1308,10 +1325,10 @@ var init_pm = __esm({
1308
1325
  function walk(dir, exclude = []) {
1309
1326
  const out = [];
1310
1327
  const visit = (rel) => {
1311
- for (const name of readdirSync(path28.join(dir, rel)).sort()) {
1328
+ for (const name of readdirSync(path32.join(dir, rel)).sort()) {
1312
1329
  const child = rel ? `${rel}/${name}` : name;
1313
1330
  if (exclude.some((r) => r.test(child))) continue;
1314
- const stat = statSync(path28.join(dir, child));
1331
+ const stat = statSync(path32.join(dir, child));
1315
1332
  if (stat.isDirectory()) visit(child);
1316
1333
  else if (stat.isFile()) out.push(child);
1317
1334
  }
@@ -1340,17 +1357,17 @@ var init_walk = __esm({
1340
1357
  });
1341
1358
  function starterDir() {
1342
1359
  const workspace = workspacePackagesDir();
1343
- const live = workspace && path28.join(workspace, "..", "apps", "genesis-rn-starter");
1344
- if (live && existsSync(path28.join(live, "package.json"))) return live;
1345
- const packaged = path28.join(cliPackageDir(), "dist", "starter");
1346
- if (existsSync(path28.join(packaged, "package.json"))) return packaged;
1360
+ const live = workspace && path32.join(workspace, "..", "apps", "genesis-rn-starter");
1361
+ if (live && existsSync(path32.join(live, "package.json"))) return live;
1362
+ const packaged = path32.join(cliPackageDir(), "dist", "starter");
1363
+ if (existsSync(path32.join(packaged, "package.json"))) return packaged;
1347
1364
  throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
1348
1365
  }
1349
1366
  function templatesDir(cliDir = cliPackageDir()) {
1350
1367
  const workspace = workspacePackagesDir();
1351
- const live = workspace && cliDir === cliPackageDir() ? path28.join(workspace, "..", "templates") : null;
1352
- if (live && existsSync(path28.join(live, "eas"))) return live;
1353
- const packaged = path28.join(cliDir, "dist", "templates");
1368
+ const live = workspace && cliDir === cliPackageDir() ? path32.join(workspace, "..", "templates") : null;
1369
+ if (live && existsSync(path32.join(live, "eas"))) return live;
1370
+ const packaged = path32.join(cliDir, "dist", "templates");
1354
1371
  if (existsSync(packaged)) return packaged;
1355
1372
  throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
1356
1373
  }
@@ -1381,9 +1398,9 @@ __export(init_native_exports, {
1381
1398
  starterIdentity: () => starterIdentity
1382
1399
  });
1383
1400
  function starterIdentity(config) {
1384
- const field2 = (key) => {
1385
- const m = new RegExp(`\\b${key}:\\s*"([^"]+)"`).exec(config);
1386
- if (!m) throw new Error(`starter.config.ts has no app.${key}`);
1401
+ const field2 = (key2) => {
1402
+ const m = new RegExp(`\\b${key2}:\\s*"([^"]+)"`).exec(config);
1403
+ if (!m) throw new Error(`starter.config.ts has no app.${key2}`);
1387
1404
  return m[1];
1388
1405
  };
1389
1406
  return { name: field2("name"), slug: field2("slug"), scheme: field2("scheme"), bundleId: field2("bundleId") };
@@ -1431,10 +1448,10 @@ function initNative(options) {
1431
1448
  if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
1432
1449
  if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
1433
1450
  if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
1434
- const target = path28.resolve(options.target);
1451
+ const target = path32.resolve(options.target);
1435
1452
  if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
1436
1453
  const source = starterDir();
1437
- const read = (rel) => readFileSync(path28.join(source, rel), "utf8");
1454
+ const read = (rel) => readFileSync(path32.join(source, rel), "utf8");
1438
1455
  const was = starterIdentity(read("starter.config.ts"));
1439
1456
  const substitutions = { [was.bundleId]: bundleId, [was.slug]: slug, [was.scheme]: scheme, [was.name]: display };
1440
1457
  const files = /* @__PURE__ */ new Map();
@@ -1465,14 +1482,14 @@ function initNative(options) {
1465
1482
  files.set("package.json", `${JSON.stringify(pkg, null, 2)}
1466
1483
  `);
1467
1484
  files.set("metro.config.js", METRO);
1468
- const pnpmSettings = [path28.join(source, "pnpm-workspace.yaml"), path28.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
1485
+ const pnpmSettings = [path32.join(source, "pnpm-workspace.yaml"), path32.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
1469
1486
  if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
1470
1487
  files.set("README.md", readme(display, slug));
1471
1488
  const lock = { ...emptyLock(), substitutions };
1472
1489
  const cliVersion2 = pinnedVersion(target, CLI_PACKAGE)?.version;
1473
1490
  const templates = templatesDir();
1474
1491
  for (const rel of walk(templates)) {
1475
- const text = substitute(readFileSync(path28.join(templates, rel), "utf8"), substitutions);
1492
+ const text = substitute(readFileSync(path32.join(templates, rel), "utf8"), substitutions);
1476
1493
  const to = templateTarget(rel, text);
1477
1494
  files.set(to, text);
1478
1495
  lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
@@ -1483,14 +1500,14 @@ function initNative(options) {
1483
1500
  const blocks = [];
1484
1501
  for (const block of options.blocks) {
1485
1502
  const stems = block.migrations.map((m) => stemOf(m.file));
1486
- const copies = stems.map((s) => migrations.find((f) => path28.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
1503
+ const copies = stems.map((s) => migrations.find((f) => path32.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
1487
1504
  if (!stems.length || copies.some((c) => !c)) continue;
1488
1505
  blocks.push(block.id);
1489
1506
  lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
1490
1507
  block.migrations.forEach((m) => {
1491
1508
  if (m.test) {
1492
- const test = `${TESTS_DIR}/${path28.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
1493
- if (files.has(test)) lock.files[test] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test)) };
1509
+ const test2 = `${TESTS_DIR}/${path32.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
1510
+ if (files.has(test2)) lock.files[test2] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test2)) };
1494
1511
  }
1495
1512
  });
1496
1513
  for (const fn of block.functions) {
@@ -1502,8 +1519,8 @@ function initNative(options) {
1502
1519
  }
1503
1520
  mkdirSync(target, { recursive: true });
1504
1521
  for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
1505
- const file = path28.join(target, ...rel.split("/"));
1506
- mkdirSync(path28.dirname(file), { recursive: true });
1522
+ const file = path32.join(target, ...rel.split("/"));
1523
+ mkdirSync(path32.dirname(file), { recursive: true });
1507
1524
  writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
1508
1525
  }
1509
1526
  writeLock(target, lock);
@@ -1558,12 +1575,12 @@ function parse(comment, keys, where) {
1558
1575
  throw new CommentSettingsError(`${where}: the text after ${MARKER} must be one JSON object.`);
1559
1576
  }
1560
1577
  const settings2 = {};
1561
- for (const [key, v] of Object.entries(value)) {
1562
- if (!keys.includes(key)) {
1563
- throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${key}". Allowed: ${keys.join(", ")}.`);
1578
+ for (const [key2, v] of Object.entries(value)) {
1579
+ if (!keys.includes(key2)) {
1580
+ throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${key2}". Allowed: ${keys.join(", ")}.`);
1564
1581
  }
1565
- if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${key}" must be a string.`);
1566
- settings2[key] = v;
1582
+ if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${key2}" must be a string.`);
1583
+ settings2[key2] = v;
1567
1584
  }
1568
1585
  return { ...description ? { description } : {}, ...Object.keys(settings2).length ? { settings: settings2 } : {} };
1569
1586
  }
@@ -1700,9 +1717,9 @@ function introspectOpenApi(doc, schema = "public") {
1700
1717
  const def = definitions[tableName];
1701
1718
  const name = `${schema}.${tableName}`;
1702
1719
  const required = new Set(def.required ?? []);
1703
- const key = [];
1720
+ const key2 = [];
1704
1721
  const columns = Object.entries(def.properties ?? {}).map(([column, prop]) => {
1705
- if (PK.test(prop.description ?? "")) key.push(column);
1722
+ if (PK.test(prop.description ?? "")) key2.push(column);
1706
1723
  const fk = FK.exec(prop.description ?? "");
1707
1724
  const isArray = prop.type === "array";
1708
1725
  const format = (isArray ? prop.items?.format : prop.format) ?? prop.type ?? "text";
@@ -1729,7 +1746,7 @@ function introspectOpenApi(doc, schema = "public") {
1729
1746
  name,
1730
1747
  schema,
1731
1748
  table: tableName,
1732
- key,
1749
+ key: key2,
1733
1750
  columns,
1734
1751
  ...comment.description ? { description: comment.description } : {},
1735
1752
  ...comment.settings ? { settings: comment.settings } : {}
@@ -1857,19 +1874,19 @@ var init_introspect = __esm({
1857
1874
  });
1858
1875
  function buildCommands(root, config) {
1859
1876
  if (config.build) return config.build;
1860
- const pkgFile = path28.join(root, "package.json");
1877
+ const pkgFile = path32.join(root, "package.json");
1861
1878
  const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
1862
1879
  const pm = packageManager(root);
1863
1880
  return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
1864
1881
  }
1865
1882
  function packageManager(root) {
1866
- let dir = path28.resolve(root);
1883
+ let dir = path32.resolve(root);
1867
1884
  for (; ; ) {
1868
- if (existsSync(path28.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1869
- if (existsSync(path28.join(dir, "bun.lock")) || existsSync(path28.join(dir, "bun.lockb"))) return "bun";
1870
- if (existsSync(path28.join(dir, "yarn.lock"))) return "yarn";
1871
- if (existsSync(path28.join(dir, "package-lock.json"))) return "npm";
1872
- const parent = path28.dirname(dir);
1885
+ if (existsSync(path32.join(dir, "pnpm-lock.yaml"))) return "pnpm";
1886
+ if (existsSync(path32.join(dir, "bun.lock")) || existsSync(path32.join(dir, "bun.lockb"))) return "bun";
1887
+ if (existsSync(path32.join(dir, "yarn.lock"))) return "yarn";
1888
+ if (existsSync(path32.join(dir, "package-lock.json"))) return "npm";
1889
+ const parent = path32.dirname(dir);
1873
1890
  if (parent === dir) return "npm";
1874
1891
  dir = parent;
1875
1892
  }
@@ -1926,7 +1943,7 @@ function globToRegExp(glob) {
1926
1943
  }
1927
1944
  function globMatcher(globs) {
1928
1945
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1929
- return (path29) => res.some((re) => re.test(path29));
1946
+ return (path33) => res.some((re) => re.test(path33));
1930
1947
  }
1931
1948
  var init_glob = __esm({
1932
1949
  "src/doctor/glob.ts"() {
@@ -2103,9 +2120,9 @@ function scanFiles(root, config) {
2103
2120
  const files = [];
2104
2121
  const seen = /* @__PURE__ */ new Set();
2105
2122
  const visit = (abs) => {
2106
- const rel = toPosix(path28.relative(root, abs));
2123
+ const rel = toPosix(path32.relative(root, abs));
2107
2124
  if (seen.has(rel) || ignored(rel)) return;
2108
- const ext = path28.extname(abs);
2125
+ const ext = path32.extname(abs);
2109
2126
  if (!extensions.has(ext)) return;
2110
2127
  if (statSync(abs).size > MAX_FILE_BYTES) return;
2111
2128
  seen.add(rel);
@@ -2115,14 +2132,14 @@ function scanFiles(root, config) {
2115
2132
  const walk2 = (dir) => {
2116
2133
  for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
2117
2134
  if (entry.isDirectory()) {
2118
- if (!SKIP_DIRS.has(entry.name)) walk2(path28.join(dir, entry.name));
2135
+ if (!SKIP_DIRS.has(entry.name)) walk2(path32.join(dir, entry.name));
2119
2136
  } else if (entry.isFile()) {
2120
- visit(path28.join(dir, entry.name));
2137
+ visit(path32.join(dir, entry.name));
2121
2138
  }
2122
2139
  }
2123
2140
  };
2124
2141
  for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
2125
- const abs = path28.resolve(root, src);
2142
+ const abs = path32.resolve(root, src);
2126
2143
  if (!existsSync(abs)) continue;
2127
2144
  if (statSync(abs).isDirectory()) walk2(abs);
2128
2145
  else visit(abs);
@@ -2153,7 +2170,7 @@ var init_scan = __esm({
2153
2170
  ];
2154
2171
  SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
2155
2172
  MAX_FILE_BYTES = 2 * 1024 * 1024;
2156
- toPosix = (p) => p.split(path28.sep).join("/");
2173
+ toPosix = (p) => p.split(path32.sep).join("/");
2157
2174
  }
2158
2175
  });
2159
2176
  function parseRulesMarkdown(markdown) {
@@ -2172,11 +2189,11 @@ function parseRulesMarkdown(markdown) {
2172
2189
  }
2173
2190
  const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message):\s*(.*)$/);
2174
2191
  if (!current || !kv) continue;
2175
- const [, key, raw] = kv;
2192
+ const [, key2, raw] = kv;
2176
2193
  const value = raw.trim();
2177
- if (key === "files" || key === "exclude") current[key] = value.split(",").map((s) => s.trim()).filter(Boolean);
2178
- else if (key === "level") current.level = value;
2179
- else current[key] = value;
2194
+ if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
2195
+ else if (key2 === "level") current.level = value;
2196
+ else current[key2] = value;
2180
2197
  }
2181
2198
  return rules;
2182
2199
  }
@@ -2191,8 +2208,8 @@ function compilePatternRules(rules, source) {
2191
2208
  if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
2192
2209
  ids.add(rule.id);
2193
2210
  const level = rule.level ?? "error";
2194
- if (!["error", "warn", "guide"].includes(level)) {
2195
- throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn or guide)`);
2211
+ if (!["error", "warn", "info", "guide"].includes(level)) {
2212
+ throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
2196
2213
  }
2197
2214
  if (level === "guide") continue;
2198
2215
  if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
@@ -2219,7 +2236,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
2219
2236
  const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
2220
2237
  let all = compiled;
2221
2238
  if (rulesDoc) {
2222
- const file = path28.resolve(root, rulesDoc);
2239
+ const file = path32.resolve(root, rulesDoc);
2223
2240
  if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
2224
2241
  const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
2225
2242
  const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
@@ -2285,14 +2302,14 @@ async function loadPlugins(specs, configDir) {
2285
2302
  }
2286
2303
  function resolvePlugin(id, configDir) {
2287
2304
  try {
2288
- if (id.startsWith(".") || path28.isAbsolute(id)) return resolveFrom(path28.resolve(configDir, id), configDir);
2305
+ if (id.startsWith(".") || path32.isAbsolute(id)) return resolveFrom(path32.resolve(configDir, id), configDir);
2289
2306
  return resolveFrom(id, configDir);
2290
2307
  } catch {
2291
2308
  throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
2292
2309
  }
2293
2310
  }
2294
2311
  function resolveFrom(id, from) {
2295
- return createRequire(path28.join(from, "noop.js")).resolve(id);
2312
+ return createRequire(path32.join(from, "noop.js")).resolve(id);
2296
2313
  }
2297
2314
  var init_plugins = __esm({
2298
2315
  "src/doctor/plugins.ts"() {
@@ -2310,7 +2327,7 @@ function importSpecifiers(file) {
2310
2327
  }
2311
2328
  function checkProjectLayout(ctx) {
2312
2329
  for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
2313
- if (existsSync(path28.join(ctx.root, dir))) {
2330
+ if (existsSync(path32.join(ctx.root, dir))) {
2314
2331
  ctx.report({
2315
2332
  rule: "local-primitives",
2316
2333
  file: dir,
@@ -2320,7 +2337,7 @@ function checkProjectLayout(ctx) {
2320
2337
  }
2321
2338
  }
2322
2339
  for (const file of STARTER_LEFTOVERS) {
2323
- if (existsSync(path28.join(ctx.root, file))) {
2340
+ if (existsSync(path32.join(ctx.root, file))) {
2324
2341
  ctx.report({
2325
2342
  rule: "starter-leftover",
2326
2343
  level: "warn",
@@ -2407,7 +2424,7 @@ function checkTokens(ctx) {
2407
2424
  }
2408
2425
  for (const pattern of ctx.config.tokenFiles ?? []) {
2409
2426
  if (/[*?]/.test(pattern)) continue;
2410
- const abs = path28.join(ctx.root, pattern);
2427
+ const abs = path32.join(ctx.root, pattern);
2411
2428
  if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
2412
2429
  for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
2413
2430
  }
@@ -2466,6 +2483,15 @@ var init_rules = __esm({
2466
2483
  "undefined-token",
2467
2484
  "shadowed-export",
2468
2485
  "version-skew",
2486
+ "duplicate-genesis-package",
2487
+ "peer-range-mismatch",
2488
+ // structure
2489
+ "hand-rolled-sub-nav",
2490
+ "local-genesis-copy",
2491
+ "resource-workspace",
2492
+ "page-layout",
2493
+ // dates
2494
+ "iso-date-slice",
2469
2495
  // native pack
2470
2496
  "native-raw-primitive",
2471
2497
  "native-literal-color",
@@ -2476,7 +2502,8 @@ var init_rules = __esm({
2476
2502
  "migration-grants",
2477
2503
  "migration-rls",
2478
2504
  "migration-definer-search-path",
2479
- "migration-edited"
2505
+ "migration-edited",
2506
+ "migration-testing-kit"
2480
2507
  ];
2481
2508
  DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2482
2509
  STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2560,6 +2587,98 @@ var init_expo = __esm({
2560
2587
  });
2561
2588
  }
2562
2589
  });
2590
+ function localImports(root, file) {
2591
+ const out = [];
2592
+ for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2593
+ const spec = m[1];
2594
+ const bases = spec.startsWith(".") ? [path32.resolve(path32.dirname(file.absolutePath), spec)] : [path32.join(root, spec.slice(2)), path32.join(root, "src", spec.slice(2))];
2595
+ for (const base of bases) {
2596
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path32.join(base, `index${e}`))].find(
2597
+ (p) => SCRIPT_EXTS2.has(path32.extname(p)) && existsSync(p)
2598
+ );
2599
+ if (hit) {
2600
+ out.push(hit);
2601
+ break;
2602
+ }
2603
+ }
2604
+ }
2605
+ return out;
2606
+ }
2607
+ function readSource(abs) {
2608
+ try {
2609
+ return { absolutePath: abs, code: readFileSync(abs, "utf8") };
2610
+ } catch {
2611
+ return null;
2612
+ }
2613
+ }
2614
+ function tagEnd(code, start) {
2615
+ let depth = 0;
2616
+ let quote2 = null;
2617
+ for (let i = start + 1; i < code.length; i++) {
2618
+ const ch = code[i];
2619
+ if (quote2) {
2620
+ if (ch === "\\") i++;
2621
+ else if (ch === quote2) quote2 = null;
2622
+ continue;
2623
+ }
2624
+ if (ch === '"' || ch === "'" || ch === "`") quote2 = ch;
2625
+ else if (ch === "{") depth++;
2626
+ else if (ch === "}") depth--;
2627
+ else if (ch === ">" && depth === 0) {
2628
+ let j = i - 1;
2629
+ while (j > start && /\s/.test(code[j])) j--;
2630
+ return { end: i + 1, selfClosing: code[j] === "/" };
2631
+ }
2632
+ }
2633
+ return { end: code.length, selfClosing: false };
2634
+ }
2635
+ function openElementsAt(code, index, track) {
2636
+ const open = [];
2637
+ const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
2638
+ for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
2639
+ const name = m[2];
2640
+ if (!track(name)) continue;
2641
+ if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
2642
+ if (m[1]) {
2643
+ const at = open.lastIndexOf(name);
2644
+ if (at !== -1) open.splice(at, 1);
2645
+ continue;
2646
+ }
2647
+ const { end, selfClosing } = tagEnd(code, m.index);
2648
+ if (end > index) break;
2649
+ if (!selfClosing) open.push(name);
2650
+ }
2651
+ return open;
2652
+ }
2653
+ function renderedElements(code) {
2654
+ const out = [];
2655
+ for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
2656
+ return out;
2657
+ }
2658
+ function rendersJsx(code) {
2659
+ return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
2660
+ }
2661
+ function namedImportsFrom(code, pkg) {
2662
+ const out = [];
2663
+ for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
2664
+ if (!pkg.test(m[2])) continue;
2665
+ for (const part of m[1].split(",")) {
2666
+ const p = part.trim();
2667
+ if (!p || p.startsWith("type ")) continue;
2668
+ const local = p.split(/\s+as\s+/).pop()?.trim();
2669
+ if (local) out.push(local);
2670
+ }
2671
+ }
2672
+ return out;
2673
+ }
2674
+ var SCRIPT_EXTS2, JSX_EXTS2, RESOLVE_EXTS;
2675
+ var init_source = __esm({
2676
+ "src/doctor/source.ts"() {
2677
+ SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2678
+ JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2679
+ RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2680
+ }
2681
+ });
2563
2682
  function nativePackage(ctx) {
2564
2683
  const pkg = readPackageExports(ctx.root, NATIVE_UI_PACKAGE);
2565
2684
  if (!pkg) throw new DoctorConfigError(`the native pack needs ${NATIVE_UI_PACKAGE}; install it, or remove "native" from doctor.packs`);
@@ -2589,7 +2708,7 @@ function checkRawPrimitives(ctx, pkg) {
2589
2708
  ];
2590
2709
  const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
2591
2710
  for (const file of ctx.files) {
2592
- if (!SCRIPT_EXTS2.has(file.ext)) continue;
2711
+ if (!SCRIPT_EXTS3.has(file.ext)) continue;
2593
2712
  const code = file.code;
2594
2713
  const report = (name, at) => {
2595
2714
  const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
@@ -2635,10 +2754,10 @@ function checkCustomHeaders(ctx, pkg) {
2635
2754
  const reported = /* @__PURE__ */ new Set();
2636
2755
  const hidingLayouts = /* @__PURE__ */ new Map();
2637
2756
  for (const file of ctx.files) {
2638
- if (!JSX_EXTS2.has(file.ext)) continue;
2757
+ if (!JSX_EXTS3.has(file.ext)) continue;
2639
2758
  const code = file.code;
2640
2759
  const hidden = HIDES_HEADER.exec(code);
2641
- if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path28.posix.dirname(file.path), file.path);
2760
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path32.posix.dirname(file.path), file.path);
2642
2761
  const own = hidden ? ownHeader(code, pkg) : null;
2643
2762
  if (hidden && own) {
2644
2763
  reported.add(file.path);
@@ -2665,8 +2784,8 @@ function checkCustomHeaders(ctx, pkg) {
2665
2784
  }
2666
2785
  }
2667
2786
  for (const file of ctx.files) {
2668
- if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2669
- const layout = hidingLayouts.get(path28.posix.dirname(file.path));
2787
+ if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2788
+ const layout = hidingLayouts.get(path32.posix.dirname(file.path));
2670
2789
  const own = layout ? ownHeader(file.code, pkg) : null;
2671
2790
  if (!layout || !own) continue;
2672
2791
  ctx.report({
@@ -2681,13 +2800,13 @@ function checkCustomHeaders(ctx, pkg) {
2681
2800
  }
2682
2801
  function routerRoot(ctx) {
2683
2802
  if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
2684
- return existsSync(path28.join(ctx.root, "src", "app")) ? "src/app" : "app";
2803
+ return existsSync(path32.join(ctx.root, "src", "app")) ? "src/app" : "app";
2685
2804
  }
2686
2805
  function checkScreenLayouts(ctx, pkg) {
2687
2806
  const layouts = nativeLayouts(pkg);
2688
2807
  if (layouts.length === 0) return;
2689
2808
  const rootDir = routerRoot(ctx);
2690
- if (!existsSync(path28.join(ctx.root, rootDir))) {
2809
+ if (!existsSync(path32.join(ctx.root, rootDir))) {
2691
2810
  ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
2692
2811
  return;
2693
2812
  }
@@ -2701,15 +2820,15 @@ function checkScreenLayouts(ctx, pkg) {
2701
2820
  });
2702
2821
  return;
2703
2822
  }
2704
- const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2823
+ const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2705
2824
  const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2706
2825
  for (const file of routes) {
2707
- if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2826
+ if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2708
2827
  if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
2709
- if (renders.test(file.code)) continue;
2828
+ if (renders2.test(file.code)) continue;
2710
2829
  const viaImport = localImports(ctx.root, file).some((abs) => {
2711
2830
  const target = byPath.get(abs) ?? readSource(abs);
2712
- return target !== null && renders.test(target.code);
2831
+ return target !== null && renders2.test(target.code);
2713
2832
  });
2714
2833
  if (viaImport) continue;
2715
2834
  ctx.report({
@@ -2720,34 +2839,10 @@ function checkScreenLayouts(ctx, pkg) {
2720
2839
  });
2721
2840
  }
2722
2841
  }
2723
- function localImports(root, file) {
2724
- const out = [];
2725
- for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2726
- const spec = m[1];
2727
- const bases = spec.startsWith(".") ? [path28.resolve(path28.dirname(file.absolutePath), spec)] : [path28.join(root, spec.slice(2)), path28.join(root, "src", spec.slice(2))];
2728
- for (const base of bases) {
2729
- const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path28.join(base, `index${e}`))].find(
2730
- (p) => SCRIPT_EXTS2.has(path28.extname(p)) && existsSync(p)
2731
- );
2732
- if (hit) {
2733
- out.push(hit);
2734
- break;
2735
- }
2736
- }
2737
- }
2738
- return out;
2739
- }
2740
- function readSource(abs) {
2741
- try {
2742
- return { code: readFileSync(abs, "utf8") };
2743
- } catch {
2744
- return null;
2745
- }
2746
- }
2747
2842
  function readExpoConfigs(root) {
2748
2843
  const out = [];
2749
2844
  for (const name of EXPO_CONFIGS) {
2750
- const abs = path28.join(root, name);
2845
+ const abs = path32.join(root, name);
2751
2846
  if (!existsSync(abs)) continue;
2752
2847
  const text = readFileSync(abs, "utf8");
2753
2848
  let json = null;
@@ -2781,13 +2876,13 @@ function pluginOptions(json, module) {
2781
2876
  return null;
2782
2877
  }
2783
2878
  function dependencies(root) {
2784
- const file = path28.join(root, "package.json");
2879
+ const file = path32.join(root, "package.json");
2785
2880
  if (!existsSync(file)) return /* @__PURE__ */ new Set();
2786
2881
  const pkg = JSON.parse(readFileSync(file, "utf8"));
2787
2882
  return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
2788
2883
  }
2789
2884
  function runtimeDependencies(root) {
2790
- const file = path28.join(root, "package.json");
2885
+ const file = path32.join(root, "package.json");
2791
2886
  if (!existsSync(file)) return {};
2792
2887
  return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
2793
2888
  }
@@ -2847,14 +2942,14 @@ function checkStoreReadiness(ctx) {
2847
2942
  });
2848
2943
  if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
2849
2944
  }
2850
- for (const [key, modules] of generic) {
2851
- const opt = PERMISSIONS.find((p) => p.key === key).option;
2945
+ for (const [key2, modules] of generic) {
2946
+ const opt = PERMISSIONS.find((p) => p.key === key2).option;
2852
2947
  ctx.report({
2853
2948
  rule: "store-readiness",
2854
2949
  level: "warn",
2855
2950
  file,
2856
- subject: key,
2857
- message: `leaves ${key} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
2951
+ subject: key2,
2952
+ message: `leaves ${key2} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key2}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
2858
2953
  });
2859
2954
  }
2860
2955
  const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
@@ -2868,7 +2963,7 @@ function checkStoreReadiness(ctx) {
2868
2963
  });
2869
2964
  }
2870
2965
  }
2871
- var SCRIPT_EXTS2, JSX_EXTS2, RESOLVE_EXTS, LAYOUT_NAME, NON_SCREEN_ROUTE, PART_HEADER, HIDES_HEADER, RN, PERMISSIONS, SOCIAL_SIGN_IN, WEAK_SOCIAL_SIGN_IN, APPLE_SIGN_IN, EXPO_CONFIGS, SUPABASE_SIGN_IN, GENESIS_PLUGIN, GENESIS_PLUGIN_TEXT, GENESIS_PLUGIN_IMPORT;
2966
+ var SCRIPT_EXTS3, JSX_EXTS3, LAYOUT_NAME, NON_SCREEN_ROUTE, PART_HEADER, HIDES_HEADER, RN, PERMISSIONS, SOCIAL_SIGN_IN, WEAK_SOCIAL_SIGN_IN, APPLE_SIGN_IN, EXPO_CONFIGS, SUPABASE_SIGN_IN, GENESIS_PLUGIN, GENESIS_PLUGIN_TEXT, GENESIS_PLUGIN_IMPORT;
2872
2967
  var init_native = __esm({
2873
2968
  "src/doctor/native.ts"() {
2874
2969
  init_native_primitives();
@@ -2876,9 +2971,9 @@ var init_native = __esm({
2876
2971
  init_config();
2877
2972
  init_genesis();
2878
2973
  init_scan();
2879
- SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2880
- JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2881
- RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2974
+ init_source();
2975
+ SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2976
+ JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2882
2977
  LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
2883
2978
  NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
2884
2979
  PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
@@ -3072,9 +3167,9 @@ function gitView(root, dir, base) {
3072
3167
  function checkSupabasePack(ctx) {
3073
3168
  const settings2 = ctx.config.supabase ?? {};
3074
3169
  const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
3075
- const abs = path28.join(ctx.root, dir);
3170
+ const abs = path32.join(ctx.root, dir);
3076
3171
  if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
3077
- const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path28.join(abs, n), "utf8")) }));
3172
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path32.join(abs, n), "utf8")) }));
3078
3173
  const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
3079
3174
  const base = settings2.base ?? DEFAULT_BASE;
3080
3175
  const view = gitView(ctx.root, dir, base);
@@ -3091,7 +3186,7 @@ function checkSupabasePack(ctx) {
3091
3186
  }
3092
3187
  }
3093
3188
  const since = settings2.since;
3094
- const afterSince = (file) => since === void 0 || path28.posix.basename(file) >= since;
3189
+ const afterSince = (file) => since === void 0 || path32.posix.basename(file) >= since;
3095
3190
  if ("reason" in view && since === void 0) {
3096
3191
  ctx.report({
3097
3192
  rule: "migration-grants",
@@ -3105,6 +3200,20 @@ function checkSupabasePack(ctx) {
3105
3200
  }
3106
3201
  checkRls(ctx, migrations, exposed);
3107
3202
  checkDefinerSearchPath(ctx, migrations);
3203
+ checkTestingKit(ctx, migrations);
3204
+ }
3205
+ function checkTestingKit(ctx, migrations) {
3206
+ for (const { file, statements } of migrations) {
3207
+ const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
3208
+ if (!hit) continue;
3209
+ ctx.report({
3210
+ rule: "migration-testing-kit",
3211
+ file,
3212
+ line: hit.line,
3213
+ subject: "genesis_testing",
3214
+ message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
3215
+ });
3216
+ }
3108
3217
  }
3109
3218
  function granteesOf(s) {
3110
3219
  return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
@@ -3233,8 +3342,8 @@ function checkDefinerSearchPath(ctx, migrations) {
3233
3342
  for (const { sql, line } of statements) {
3234
3343
  const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
3235
3344
  if (create) {
3236
- const [key] = keysFor(sql, create[0].length, qualify(create[1]));
3237
- fns.set(key, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
3345
+ const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
3346
+ fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
3238
3347
  continue;
3239
3348
  }
3240
3349
  const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
@@ -3243,13 +3352,13 @@ function checkDefinerSearchPath(ctx, migrations) {
3243
3352
  const keys = keysFor(sql, alter[0].length, fnName);
3244
3353
  const rename = / rename to ([\w$]+)$/.exec(sql);
3245
3354
  const move = / set schema ([\w$]+)$/.exec(sql);
3246
- for (const key of keys) {
3247
- const state = fns.get(key);
3355
+ for (const key2 of keys) {
3356
+ const state = fns.get(key2);
3248
3357
  if (rename || move) {
3249
3358
  if (!state) continue;
3250
- fns.delete(key);
3359
+ fns.delete(key2);
3251
3360
  const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
3252
- fns.set(newName + key.slice(fnName.length), state);
3361
+ fns.set(newName + key2.slice(fnName.length), state);
3253
3362
  continue;
3254
3363
  }
3255
3364
  const next = state ?? { definer: false, searchPath: false, file, line };
@@ -3257,7 +3366,7 @@ function checkDefinerSearchPath(ctx, migrations) {
3257
3366
  if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
3258
3367
  if (/\bset search_path\b/.test(sql)) next.searchPath = true;
3259
3368
  if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
3260
- fns.set(key, next);
3369
+ fns.set(key2, next);
3261
3370
  }
3262
3371
  continue;
3263
3372
  }
@@ -3265,19 +3374,19 @@ function checkDefinerSearchPath(ctx, migrations) {
3265
3374
  if (drop) {
3266
3375
  for (const part of splitTop(drop[1])) {
3267
3376
  const m = /^([\w$.]+)\s*/.exec(part);
3268
- if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
3377
+ if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
3269
3378
  }
3270
3379
  }
3271
3380
  }
3272
3381
  }
3273
- for (const [key, at] of fns) {
3382
+ for (const [key2, at] of fns) {
3274
3383
  if (!at.definer || at.searchPath) continue;
3275
3384
  ctx.report({
3276
3385
  rule: "migration-definer-search-path",
3277
3386
  file: at.file,
3278
3387
  line: at.line,
3279
- subject: key,
3280
- message: `${key} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
3388
+ subject: key2,
3389
+ message: `${key2} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
3281
3390
  });
3282
3391
  }
3283
3392
  }
@@ -3303,15 +3412,887 @@ var init_supabase = __esm({
3303
3412
  }
3304
3413
  });
3305
3414
 
3415
+ // src/doctor/semver.ts
3416
+ function parseVersion(v) {
3417
+ const m = VERSION.exec(v.trim());
3418
+ return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
3419
+ }
3420
+ function compareVersions(a, b) {
3421
+ for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
3422
+ if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
3423
+ for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
3424
+ const x = a.pre[i];
3425
+ const y = b.pre[i];
3426
+ if (x === void 0) return -1;
3427
+ if (y === void 0) return 1;
3428
+ if (x === y) continue;
3429
+ const nx = /^\d+$/.test(x);
3430
+ const ny = /^\d+$/.test(y);
3431
+ if (nx && ny) return +x < +y ? -1 : 1;
3432
+ if (nx !== ny) return nx ? -1 : 1;
3433
+ return x < y ? -1 : 1;
3434
+ }
3435
+ return 0;
3436
+ }
3437
+ function partial(s) {
3438
+ const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
3439
+ if (!m) return null;
3440
+ const nums = [];
3441
+ let wild = false;
3442
+ for (const part of [m[1], m[2], m[3]]) {
3443
+ if (wild || part === void 0 || /^[xX*]$/.test(part)) {
3444
+ wild = true;
3445
+ nums.push(null);
3446
+ } else nums.push(+part);
3447
+ }
3448
+ return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
3449
+ }
3450
+ function comparators(token) {
3451
+ const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
3452
+ if (!m) return null;
3453
+ const op = m[1] ?? "";
3454
+ const p = partial(m[2]);
3455
+ if (!p) return null;
3456
+ const [major, mi, pa] = p.nums;
3457
+ if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
3458
+ const M = major;
3459
+ const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
3460
+ const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
3461
+ const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
3462
+ const out = switchOp();
3463
+ if (p.pre.length) {
3464
+ for (const c of out) if (c.v === lo) c.pre = true;
3465
+ }
3466
+ return out;
3467
+ function switchOp() {
3468
+ switch (op) {
3469
+ case "^": {
3470
+ const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
3471
+ return [
3472
+ { op: ">=", v: lo },
3473
+ { op: "<", v: bound }
3474
+ ];
3475
+ }
3476
+ case "~":
3477
+ case "~>":
3478
+ return [
3479
+ { op: ">=", v: lo },
3480
+ { op: "<", v: mi === null ? next("major") : next("minor") }
3481
+ ];
3482
+ case ">":
3483
+ return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
3484
+ case ">=":
3485
+ return [{ op: ">=", v: lo }];
3486
+ case "<":
3487
+ return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
3488
+ case "<=":
3489
+ return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
3490
+ default:
3491
+ return upper ? [
3492
+ { op: ">=", v: lo },
3493
+ { op: "<", v: upper }
3494
+ ] : [{ op: "=", v: lo }];
3495
+ }
3496
+ }
3497
+ }
3498
+ function test(c, v) {
3499
+ const d = compareVersions(v, c.v);
3500
+ return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
3501
+ }
3502
+ function parseRange(range) {
3503
+ const alts = [];
3504
+ for (const raw of range.trim().split("||")) {
3505
+ const alt = raw.trim();
3506
+ const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
3507
+ if (hyphen) {
3508
+ const from = comparators(`>=${hyphen[1]}`);
3509
+ const to = comparators(`<=${hyphen[2]}`);
3510
+ if (!from || !to) return null;
3511
+ alts.push([...from, ...to]);
3512
+ continue;
3513
+ }
3514
+ const set = [];
3515
+ for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
3516
+ const cs = comparators(token);
3517
+ if (!cs) return null;
3518
+ set.push(...cs);
3519
+ }
3520
+ alts.push(set);
3521
+ }
3522
+ return alts;
3523
+ }
3524
+ function satisfies(version, range) {
3525
+ const v = parseVersion(version);
3526
+ const alts = parseRange(range);
3527
+ if (!v || !alts) return null;
3528
+ return alts.some(
3529
+ (set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
3530
+ );
3531
+ }
3532
+ var VERSION, ver;
3533
+ var init_semver = __esm({
3534
+ "src/doctor/semver.ts"() {
3535
+ VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
3536
+ ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
3537
+ }
3538
+ });
3539
+ function packagesIn(nodeModules) {
3540
+ if (!existsSync(nodeModules)) return [];
3541
+ const out = [];
3542
+ for (const entry of readdirSync(nodeModules)) {
3543
+ if (entry.startsWith(".")) continue;
3544
+ const p = path32.join(nodeModules, entry);
3545
+ if (entry.startsWith("@")) {
3546
+ try {
3547
+ for (const sub of readdirSync(p)) out.push(path32.join(p, sub));
3548
+ } catch {
3549
+ }
3550
+ } else {
3551
+ out.push(p);
3552
+ }
3553
+ }
3554
+ return out;
3555
+ }
3556
+ function genesisInstalls(root) {
3557
+ const copies = /* @__PURE__ */ new Map();
3558
+ const realRoot = real(root);
3559
+ const rel = (abs) => path32.relative(realRoot, abs).split(path32.sep).join("/") || ".";
3560
+ const via = /* @__PURE__ */ new Map();
3561
+ const record = (real2, manifest, by, range, root2) => {
3562
+ let copy = copies.get(real2);
3563
+ if (!copy) {
3564
+ copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
3565
+ copies.set(real2, copy);
3566
+ via.set(real2, /* @__PURE__ */ new Set());
3567
+ }
3568
+ via.get(real2).add(root2);
3569
+ if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
3570
+ };
3571
+ const walk2 = (kind, roots) => {
3572
+ const expanded = /* @__PURE__ */ new Set();
3573
+ const queue = [];
3574
+ const visit = (dir, by, range) => {
3575
+ const manifest = readManifest(dir);
3576
+ if (!manifest?.name) return;
3577
+ if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
3578
+ const realDir = real(dir);
3579
+ if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
3580
+ if (expanded.has(realDir)) return;
3581
+ expanded.add(realDir);
3582
+ queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
3583
+ };
3584
+ for (const r of roots) visit(r.dir, r.by, r.range);
3585
+ while (queue.length) {
3586
+ const { real: from, manifest, label } = queue.shift();
3587
+ const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
3588
+ for (const [name, range] of Object.entries(deps)) {
3589
+ const dir = findPackageDir(from, name);
3590
+ if (dir) visit(dir, label, range);
3591
+ }
3592
+ }
3593
+ };
3594
+ const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
3595
+ const dir = findPackageDir(root, name);
3596
+ return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
3597
+ });
3598
+ const app = readManifest(root);
3599
+ let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3600
+ let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
3601
+ if (Object.keys(runtimeDeps).length === 0) {
3602
+ runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
3603
+ devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
3604
+ }
3605
+ walk2("runtime", rootsOf(runtimeDeps, "the app"));
3606
+ const top = path32.join(root, "node_modules");
3607
+ walk2(
3608
+ "hoisted",
3609
+ packagesIn(top).filter((dir) => {
3610
+ const name = path32.relative(top, dir).split(path32.sep).join("/");
3611
+ return !(name in runtimeDeps) && !(name in devDeps);
3612
+ }).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
3613
+ );
3614
+ const devRoots = { ...devDeps };
3615
+ for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
3616
+ walk2("dev", rootsOf(devRoots, "the app (dev)"));
3617
+ for (const [key2, copy] of copies) {
3618
+ const kinds = via.get(key2);
3619
+ copy.runtime = kinds.has("runtime");
3620
+ copy.devOnly = kinds.size === 1 && kinds.has("dev");
3621
+ }
3622
+ const byName = /* @__PURE__ */ new Map();
3623
+ for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
3624
+ for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
3625
+ return byName;
3626
+ }
3627
+ function checkDuplicatePackages(ctx) {
3628
+ const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
3629
+ for (const [name, copies] of genesisInstalls(ctx.root)) {
3630
+ if (copies.length < 2) continue;
3631
+ const shipping = copies.filter((c) => c.runtime);
3632
+ if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
3633
+ ctx.report({
3634
+ rule: "duplicate-genesis-package",
3635
+ level: "warn",
3636
+ file: "package.json",
3637
+ subject: name,
3638
+ 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`
3639
+ });
3640
+ continue;
3641
+ }
3642
+ ctx.report({
3643
+ rule: "duplicate-genesis-package",
3644
+ level: "info",
3645
+ file: "package.json",
3646
+ subject: name,
3647
+ 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`
3648
+ });
3649
+ }
3650
+ }
3651
+ function checkPeerRanges(ctx) {
3652
+ const rel = (abs) => path32.relative(ctx.root, abs).split(path32.sep).join("/");
3653
+ for (const copies of genesisInstalls(ctx.root).values()) {
3654
+ for (const copy of copies) {
3655
+ const dir = copy.absolutePath;
3656
+ const peers = readManifest(dir)?.peerDependencies ?? {};
3657
+ for (const [peer, range] of Object.entries(peers)) {
3658
+ if (!GENESIS.test(peer)) continue;
3659
+ const peerDir = findPackageDir(dir, peer);
3660
+ const installed = peerDir && readManifest(peerDir)?.version;
3661
+ if (!peerDir || !installed) continue;
3662
+ if (satisfies(installed, range) !== false) continue;
3663
+ ctx.report({
3664
+ rule: "peer-range-mismatch",
3665
+ // A dev tool's own tree (the CLI's) doesn't run in the app.
3666
+ level: copy.devOnly ? "info" : "warn",
3667
+ file: "package.json",
3668
+ subject: `${copy.name}>${peer}`,
3669
+ 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}`
3670
+ });
3671
+ }
3672
+ }
3673
+ }
3674
+ }
3675
+ var GENESIS, DEV_TOOLS, readManifest, real;
3676
+ var init_installs = __esm({
3677
+ "src/doctor/installs.ts"() {
3678
+ init_genesis();
3679
+ init_semver();
3680
+ GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
3681
+ DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
3682
+ readManifest = (dir) => {
3683
+ try {
3684
+ return JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
3685
+ } catch {
3686
+ return null;
3687
+ }
3688
+ };
3689
+ real = (p) => {
3690
+ try {
3691
+ return realpathSync(p);
3692
+ } catch {
3693
+ return p;
3694
+ }
3695
+ };
3696
+ }
3697
+ });
3698
+ function stripForImports(code) {
3699
+ const out = [];
3700
+ const blank = (ch) => ch === "\n" ? "\n" : " ";
3701
+ const n = code.length;
3702
+ const templates = [];
3703
+ let depth = 0;
3704
+ let i = 0;
3705
+ const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
3706
+ const opensString = () => {
3707
+ const before = out.slice(-12).join("");
3708
+ if (!/[\w$]$/.test(before)) return true;
3709
+ return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
3710
+ };
3711
+ const templateBody = () => {
3712
+ while (i < n) {
3713
+ const ch = code[i];
3714
+ if (ch === "\\") {
3715
+ out.push(" ", blank(code[i + 1] ?? ""));
3716
+ i += 2;
3717
+ } else if (ch === "`") {
3718
+ out.push("`");
3719
+ i++;
3720
+ return;
3721
+ } else if (ch === "$" && code[i + 1] === "{") {
3722
+ out.push("${");
3723
+ i += 2;
3724
+ templates.push(depth);
3725
+ depth++;
3726
+ return;
3727
+ } else {
3728
+ out.push(blank(ch));
3729
+ i++;
3730
+ }
3731
+ }
3732
+ };
3733
+ while (i < n) {
3734
+ const ch = code[i];
3735
+ const next = code[i + 1];
3736
+ if (ch === "/" && next === "/") {
3737
+ while (i < n && code[i] !== "\n") {
3738
+ out.push(" ");
3739
+ i++;
3740
+ }
3741
+ } else if (ch === "/" && next === "*") {
3742
+ out.push(" ");
3743
+ i += 2;
3744
+ while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
3745
+ out.push(blank(code[i]));
3746
+ i++;
3747
+ }
3748
+ if (i < n) {
3749
+ out.push(" ");
3750
+ i += 2;
3751
+ }
3752
+ } else if ((ch === '"' || ch === "'") && opensString()) {
3753
+ const keep = isSpecifier();
3754
+ out.push(ch);
3755
+ i++;
3756
+ while (i < n && code[i] !== ch && code[i] !== "\n") {
3757
+ if (code[i] === "\\") {
3758
+ out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
3759
+ i += 2;
3760
+ } else {
3761
+ out.push(keep ? code[i] : blank(code[i]));
3762
+ i++;
3763
+ }
3764
+ }
3765
+ if (i < n) {
3766
+ out.push(code[i]);
3767
+ i++;
3768
+ }
3769
+ } else if (ch === "`") {
3770
+ out.push("`");
3771
+ i++;
3772
+ templateBody();
3773
+ } else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
3774
+ templates.pop();
3775
+ depth--;
3776
+ out.push("}");
3777
+ i++;
3778
+ templateBody();
3779
+ } else {
3780
+ if (ch === "{") depth++;
3781
+ else if (ch === "}") depth--;
3782
+ out.push(ch);
3783
+ i++;
3784
+ }
3785
+ }
3786
+ return out.join("");
3787
+ }
3788
+ function bindings(clause) {
3789
+ const out = [];
3790
+ const named = /\{([^}]*)\}/.exec(clause);
3791
+ for (const part of named?.[1].split(",") ?? []) {
3792
+ const p = part.trim();
3793
+ if (!p || p.startsWith("type ")) continue;
3794
+ out.push(p.split(/\s+as\s+/).pop().trim());
3795
+ }
3796
+ const rest = clause.replace(/\{[^}]*\}/, "");
3797
+ const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
3798
+ if (ns) out.push(ns[1]);
3799
+ const def = /^\s*([\w$]+)/.exec(rest);
3800
+ if (def && def[1] !== "as") out.push(def[1]);
3801
+ return out;
3802
+ }
3803
+ function readJsonc(file) {
3804
+ try {
3805
+ const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
3806
+ return JSON.parse(text);
3807
+ } catch {
3808
+ return null;
3809
+ }
3810
+ }
3811
+ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
3812
+ if (seen.has(file) || seen.size > 10) return {};
3813
+ seen.add(file);
3814
+ const json = readJsonc(file);
3815
+ if (!json) return {};
3816
+ const dir = path32.dirname(file);
3817
+ let merged = {};
3818
+ const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
3819
+ for (const ext of parents) {
3820
+ if (typeof ext !== "string") continue;
3821
+ let target = null;
3822
+ if (ext.startsWith(".") || path32.isAbsolute(ext)) {
3823
+ const abs = path32.resolve(dir, ext);
3824
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3825
+ } else {
3826
+ const parts = ext.split("/");
3827
+ const nameLength = ext.startsWith("@") ? 2 : 1;
3828
+ const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
3829
+ if (pkgDir) {
3830
+ const sub = parts.slice(nameLength).join("/");
3831
+ const abs = path32.join(pkgDir, sub || "tsconfig.json");
3832
+ target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
3833
+ }
3834
+ }
3835
+ if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
3836
+ }
3837
+ const opts = json.compilerOptions ?? {};
3838
+ if (typeof opts.baseUrl === "string") merged.baseUrl = path32.resolve(dir, opts.baseUrl);
3839
+ if (opts.paths && typeof opts.paths === "object") {
3840
+ merged.paths = opts.paths;
3841
+ merged.pathsDir = dir;
3842
+ }
3843
+ return merged;
3844
+ }
3845
+ function aliases(root) {
3846
+ const table = [];
3847
+ let baseUrl = null;
3848
+ for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
3849
+ const file = path32.join(root, name);
3850
+ if (!existsSync(file)) continue;
3851
+ const config = readTsconfig(root, file);
3852
+ baseUrl ??= config.baseUrl ?? null;
3853
+ const base = config.baseUrl ?? config.pathsDir ?? root;
3854
+ for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
3855
+ if (!Array.isArray(targets)) continue;
3856
+ const exact = !pattern.endsWith("*");
3857
+ table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path32.join(base, String(t).replace(/\*$/, ""))) });
3858
+ }
3859
+ }
3860
+ const pkg = readJsonc(path32.join(root, "package.json"));
3861
+ for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
3862
+ if (typeof target !== "string") continue;
3863
+ table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path32.join(root, target.replace(/\*.*$/, ""))] });
3864
+ }
3865
+ for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path32.join(root, "src") + path32.sep, root + path32.sep] });
3866
+ return { table, baseUrl };
3867
+ }
3868
+ function resolveFile(base) {
3869
+ const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path32.join(base, `index${e}`))];
3870
+ if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
3871
+ for (const p of tries) {
3872
+ if (SCRIPT_EXTS2.has(path32.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
3873
+ }
3874
+ return null;
3875
+ }
3876
+ function trailFor(ctx) {
3877
+ let t = trails.get(ctx.files);
3878
+ if (!t) trails.set(ctx.files, t = createTrail(ctx));
3879
+ return t;
3880
+ }
3881
+ function createTrail(ctx) {
3882
+ const { table, baseUrl } = aliases(ctx.root);
3883
+ let declared = null;
3884
+ try {
3885
+ const pkg = JSON.parse(readFileSync(path32.join(ctx.root, "package.json"), "utf8"));
3886
+ declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
3887
+ } catch {
3888
+ declared = null;
3889
+ }
3890
+ const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
3891
+ const read = (abs) => byPath.get(abs) ?? readSource(abs);
3892
+ const importsCache = /* @__PURE__ */ new Map();
3893
+ const importsOf = (file) => {
3894
+ const hit = importsCache.get(file.absolutePath);
3895
+ if (hit) return hit;
3896
+ const files = [];
3897
+ let lost = false;
3898
+ const code = stripped(file);
3899
+ const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
3900
+ for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3901
+ for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3902
+ 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]);
3903
+ const specs = [];
3904
+ for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
3905
+ for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
3906
+ for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
3907
+ for (const spec of specs) {
3908
+ if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
3909
+ let resolved = null;
3910
+ if (spec.startsWith(".")) {
3911
+ resolved = resolveFile(path32.resolve(path32.dirname(file.absolutePath), spec));
3912
+ if (!resolved) lost = true;
3913
+ } else {
3914
+ const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
3915
+ if (alias) {
3916
+ for (const t of alias.targets) {
3917
+ resolved = resolveFile(alias.exact ? t : path32.join(t, spec.slice(alias.prefix.length)));
3918
+ if (resolved) break;
3919
+ }
3920
+ }
3921
+ if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path32.join(baseUrl, spec));
3922
+ if (!resolved) {
3923
+ const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
3924
+ if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
3925
+ }
3926
+ }
3927
+ if (resolved && !files.includes(resolved)) files.push(resolved);
3928
+ }
3929
+ const out = { files, lost };
3930
+ importsCache.set(file.absolutePath, out);
3931
+ return out;
3932
+ };
3933
+ const strippedCache = /* @__PURE__ */ new Map();
3934
+ const stripped = (file) => {
3935
+ let c = strippedCache.get(file.absolutePath);
3936
+ if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
3937
+ return c;
3938
+ };
3939
+ const memo = /* @__PURE__ */ new WeakMap();
3940
+ const reach = (file, test2, depth, seen) => {
3941
+ let cache = memo.get(test2);
3942
+ if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
3943
+ const k = `${file.absolutePath}\0${depth}`;
3944
+ const cached = cache.get(k);
3945
+ if (cached) return [cached, false];
3946
+ let result;
3947
+ let cut = false;
3948
+ if (test2(stripped(file))) result = "yes";
3949
+ else {
3950
+ const { files, lost } = importsOf(file);
3951
+ let unknown = lost && depth > 0;
3952
+ result = "no";
3953
+ if (depth > 0) {
3954
+ seen.add(file.absolutePath);
3955
+ for (const abs of files) {
3956
+ if (seen.has(abs)) {
3957
+ cut = true;
3958
+ continue;
3959
+ }
3960
+ const target = read(abs);
3961
+ if (!target) {
3962
+ unknown = true;
3963
+ continue;
3964
+ }
3965
+ const [r, c] = reach(target, test2, depth - 1, seen);
3966
+ if (c) cut = true;
3967
+ if (r === "yes") {
3968
+ result = "yes";
3969
+ break;
3970
+ }
3971
+ if (r === "unknown") unknown = true;
3972
+ }
3973
+ seen.delete(file.absolutePath);
3974
+ }
3975
+ if (result === "no" && unknown) result = "unknown";
3976
+ }
3977
+ if (result === "yes" || !cut) cache.set(k, result);
3978
+ return [result, cut && result !== "yes"];
3979
+ };
3980
+ return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3981
+ }
3982
+ var TRAIL_DEPTH, RESOLVE_EXTS2, IMPORT_FROM, EXPORT_FROM, DYNAMIC, trails;
3983
+ var init_trail = __esm({
3984
+ "src/doctor/trail.ts"() {
3985
+ init_genesis();
3986
+ init_source();
3987
+ TRAIL_DEPTH = 6;
3988
+ RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
3989
+ IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
3990
+ EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
3991
+ DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
3992
+ trails = /* @__PURE__ */ new WeakMap();
3993
+ }
3994
+ });
3995
+ function routesDir(ctx) {
3996
+ if (ctx.config.routesDir) return ctx.config.routesDir;
3997
+ return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path32.join(ctx.root, d))) ?? null;
3998
+ }
3999
+ function flavorOf(dir, rels) {
4000
+ const stems = rels.map((r) => r.split("/").pop());
4001
+ if (stems.includes("__root")) return "tanstack";
4002
+ if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
4003
+ if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
4004
+ return "tanstack";
4005
+ }
4006
+ function renders(code) {
4007
+ const elements = renderedElements(code);
4008
+ if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
4009
+ const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
4010
+ const named = COMPONENT_OPTION.exec(code)?.[1];
4011
+ if (named && !definedHere(named)) return true;
4012
+ if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
4013
+ const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
4014
+ return exported !== void 0 && !definedHere(exported);
4015
+ }
4016
+ function webRoutes(ctx) {
4017
+ const dir = routesDir(ctx);
4018
+ if (!dir) return [];
4019
+ 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(/\.[^.]+$/, "") }));
4020
+ const flavor = flavorOf(dir, candidates.map((c) => c.rel));
4021
+ const stems = STEMS[flavor];
4022
+ const groups = /* @__PURE__ */ new Map();
4023
+ for (const { file, rel } of candidates) {
4024
+ const parts = rel.split("/");
4025
+ if (parts.some((p) => p.startsWith("-"))) continue;
4026
+ if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
4027
+ if (flavor === "next-pages" && parts[0] === "api") continue;
4028
+ if (stems.skip.test(parts.at(-1))) continue;
4029
+ if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
4030
+ const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
4031
+ groups.set(id, [...groups.get(id) ?? [], file]);
4032
+ }
4033
+ const trail = trailFor(ctx);
4034
+ const routes = [];
4035
+ for (const [id, files] of groups) {
4036
+ const parts = id.split("/");
4037
+ const stem = parts.pop();
4038
+ const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
4039
+ const named = stems.layout.has(stem) || stems.index.has(stem);
4040
+ const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
4041
+ const segments = [...folders, ...own];
4042
+ const tree = [...parts, ...own];
4043
+ let index = stems.index.has(stem);
4044
+ if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
4045
+ segments.pop();
4046
+ tree.pop();
4047
+ index = true;
4048
+ }
4049
+ const code = files.map((f) => f.code).join("\n");
4050
+ const elements = renderedElements(code);
4051
+ const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
4052
+ const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
4053
+ const layout = stems.layout.has(stem) || pathless || outlet;
4054
+ const rendering = renders(code);
4055
+ const ownContent = new RegExp(OWN_CONTENT).test(code);
4056
+ const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
4057
+ const page = !pure && !pathless && (!layout || ownContent);
4058
+ routes.push({
4059
+ file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
4060
+ files,
4061
+ segments,
4062
+ tree,
4063
+ index,
4064
+ layout,
4065
+ page,
4066
+ detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
4067
+ redirectOnly: !rendering,
4068
+ parents: []
4069
+ });
4070
+ }
4071
+ for (const r of routes) {
4072
+ const own = r.tree;
4073
+ for (const p of routes) {
4074
+ if (p === r || !p.layout) continue;
4075
+ const n = p.tree.length;
4076
+ if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
4077
+ if (key(own.slice(0, n)) !== key(p.tree)) continue;
4078
+ if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
4079
+ r.parents.push(p);
4080
+ }
4081
+ r.parents.sort((a, b) => b.tree.length - a.tree.length);
4082
+ }
4083
+ return routes;
4084
+ }
4085
+ var ROUTES_DIR_CANDIDATES, STEMS, NON_PAGE_ELEMENTS, HTML_ELEMENT, COMPONENT_OPTION, RENDERS_OUTLET, OWN_CONTENT, key;
4086
+ var init_routes = __esm({
4087
+ "src/doctor/routes.ts"() {
4088
+ init_source();
4089
+ init_trail();
4090
+ ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
4091
+ STEMS = {
4092
+ tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
4093
+ "next-app": {
4094
+ layout: /* @__PURE__ */ new Set(["layout"]),
4095
+ index: /* @__PURE__ */ new Set(["page"]),
4096
+ skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
4097
+ },
4098
+ "next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
4099
+ };
4100
+ NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
4101
+ HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
4102
+ COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
4103
+ RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
4104
+ 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;
4105
+ key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
4106
+ }
4107
+ });
4108
+
4109
+ // src/doctor/structure.ts
4110
+ function routeReach(ctx, r, test2) {
4111
+ const trail = trailFor(ctx);
4112
+ let unknown = false;
4113
+ for (const f of r.files) {
4114
+ const got = trail.reach(f, test2);
4115
+ if (got === "yes") return "yes";
4116
+ if (got === "unknown") unknown = true;
4117
+ }
4118
+ return unknown ? "unknown" : "no";
4119
+ }
4120
+ function insideShell(ctx, routes) {
4121
+ const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
4122
+ const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
4123
+ return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
4124
+ }
4125
+ function checkHandRolledSubNav(ctx) {
4126
+ if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
4127
+ const routes = webRoutes(ctx);
4128
+ if (routes.length === 0) return;
4129
+ const inShell = insideShell(ctx, routes);
4130
+ const ui = ctx.genesis.uiPackage;
4131
+ for (const r of routes) {
4132
+ if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
4133
+ 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);
4134
+ if (hit) {
4135
+ const { f, m } = hit;
4136
+ const code = f.code;
4137
+ ctx.report({
4138
+ rule: "hand-rolled-sub-nav",
4139
+ level: "warn",
4140
+ file: f.path,
4141
+ line: lineAt(code, m.index),
4142
+ subject: m[1],
4143
+ 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}`
4144
+ });
4145
+ }
4146
+ }
4147
+ }
4148
+ function checkLocalGenesisCopies(ctx) {
4149
+ const owner = /* @__PURE__ */ new Map();
4150
+ for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
4151
+ for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
4152
+ if (owner.size === 0) return;
4153
+ const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
4154
+ const routes = routesDir(ctx);
4155
+ for (const file of ctx.files) {
4156
+ if (!JSX_EXTS2.has(file.ext)) continue;
4157
+ const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
4158
+ const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
4159
+ const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
4160
+ const decls = [...file.code.matchAll(decl)];
4161
+ decls.forEach((m, i) => {
4162
+ const [, exported, name] = m;
4163
+ const pkg = owner.get(name);
4164
+ if (!pkg || imported.has(name) || routeComponents.has(name)) return;
4165
+ if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
4166
+ const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
4167
+ if (!rendersJsx(body)) return;
4168
+ if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
4169
+ const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
4170
+ if (/["']@marktiderman\/genesis/.test(init)) return;
4171
+ ctx.report({
4172
+ rule: "local-genesis-copy",
4173
+ level: "warn",
4174
+ file: file.path,
4175
+ line: lineAt(file.code, m.index),
4176
+ subject: name,
4177
+ message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
4178
+ });
4179
+ });
4180
+ }
4181
+ }
4182
+ function checkResourceWorkspaces(ctx) {
4183
+ if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
4184
+ const header = /<AppShellPageHeader(?=[\s>/])/;
4185
+ const byFolder = /* @__PURE__ */ new Map();
4186
+ for (const r of webRoutes(ctx)) {
4187
+ if (!r.detail || r.redirectOnly) continue;
4188
+ const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
4189
+ byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
4190
+ }
4191
+ for (const [dir, routes] of byFolder) {
4192
+ const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
4193
+ const has2 = routes.filter((r) => reach.get(r) === "yes");
4194
+ if (has2.length === 0) continue;
4195
+ const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
4196
+ for (const r of routes) {
4197
+ if (reach.get(r) !== "no") continue;
4198
+ ctx.report({
4199
+ rule: "resource-workspace",
4200
+ level: "info",
4201
+ file: r.file.path,
4202
+ message: `is a detail page without AppShellPageHeader, unlike ${ref} beside it; put its header in AppShellPageHeader and its sections in useAppShellSubNav so every workspace in ${dir} has the same header, tabs and phone bar`
4203
+ });
4204
+ }
4205
+ }
4206
+ }
4207
+ function checkPageLayouts(ctx) {
4208
+ if (isNative(ctx)) return;
4209
+ const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
4210
+ for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
4211
+ if (layouts.size === 0) return;
4212
+ const routes = webRoutes(ctx);
4213
+ const inShell = insideShell(ctx, routes);
4214
+ const rendersLayout = (code) => {
4215
+ const names = new Set(layouts);
4216
+ for (const n of namedImportsFrom(code, GENESIS_PACKAGE2)) if (PACKAGE_SCREEN.test(n)) names.add(n);
4217
+ return rendersRe(names)?.test(code) ?? false;
4218
+ };
4219
+ const cache = /* @__PURE__ */ new Map();
4220
+ const provides = (r) => {
4221
+ if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
4222
+ return cache.get(r);
4223
+ };
4224
+ const list = [...layouts].sort();
4225
+ const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
4226
+ for (const r of routes) {
4227
+ if (!r.page || r.redirectOnly || !inShell(r)) continue;
4228
+ if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
4229
+ ctx.report({
4230
+ rule: "page-layout",
4231
+ level: "warn",
4232
+ file: r.file.path,
4233
+ message: `renders no Genesis page layout (${named}) itself, through one local import, or from a layout route around it; wrap it in one so the header, width and spacing match every other page`
4234
+ });
4235
+ }
4236
+ }
4237
+ var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, PACKAGE_SCREEN, isNative, rendersRe, routeVia;
4238
+ var init_structure = __esm({
4239
+ "src/doctor/structure.ts"() {
4240
+ init_scan();
4241
+ init_routes();
4242
+ init_source();
4243
+ init_trail();
4244
+ SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
4245
+ CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
4246
+ SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
4247
+ SHELL = /<AppShell(?=[\s>/])/;
4248
+ GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
4249
+ PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
4250
+ PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
4251
+ isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
4252
+ rendersRe = (names) => {
4253
+ const list = [...names];
4254
+ return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
4255
+ };
4256
+ routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
4257
+ }
4258
+ });
4259
+
4260
+ // src/doctor/dates.ts
4261
+ function checkIsoDateSlices(ctx) {
4262
+ for (const file of ctx.files) {
4263
+ if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
4264
+ for (const m of file.code.matchAll(ISO_DAY_CUT)) {
4265
+ ctx.report({
4266
+ rule: "iso-date-slice",
4267
+ level: "warn",
4268
+ file: file.path,
4269
+ line: lineAt(file.code, m.index ?? 0),
4270
+ subject: "toISOString",
4271
+ message: "cuts a day from an ISO timestamp, which is the day in UTC, not the person's; use personDay(person) or dayIn(zone) from @marktiderman/genesis-core/dates (allow it with a reason where UTC is meant)"
4272
+ });
4273
+ }
4274
+ }
4275
+ }
4276
+ var SCRIPT_EXTS4, ISO_DAY_CUT;
4277
+ var init_dates = __esm({
4278
+ "src/doctor/dates.ts"() {
4279
+ init_scan();
4280
+ SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
4281
+ ISO_DAY_CUT = /\.toISOString\(\)\s*\.\s*(?:slice\(\s*0\s*,\s*10\s*\)|substring\(\s*0\s*,\s*10\s*\)|substr\(\s*0\s*,\s*10\s*\)|split\(\s*(["'`])T\1\s*\)\s*\[\s*0\s*\]|split\(\s*(["'`])T\2\s*\)\s*\.\s*at\(\s*0\s*\))/g;
4282
+ }
4283
+ });
4284
+
3306
4285
  // src/doctor/index.ts
3307
4286
  var doctor_exports = {};
3308
4287
  __export(doctor_exports, {
3309
4288
  BUILTIN_RULES: () => BUILTIN_RULES,
3310
4289
  DoctorConfigError: () => DoctorConfigError,
3311
4290
  GenesisConfigError: () => GenesisConfigError,
4291
+ builtinChecks: () => builtinChecks,
3312
4292
  defineDoctorPlugin: () => defineDoctorPlugin,
3313
4293
  findPackageDir: () => findPackageDir,
3314
4294
  formatReport: () => formatReport,
4295
+ genesisInstalls: () => genesisInstalls,
3315
4296
  genesisSummary: () => genesisSummary,
3316
4297
  globToRegExp: () => globToRegExp,
3317
4298
  loadConfig: () => loadConfig,
@@ -3322,14 +4303,17 @@ __export(doctor_exports, {
3322
4303
  readGenesisConfig: () => readGenesisConfig,
3323
4304
  readPackageExports: () => readPackageExports,
3324
4305
  readReleaseManifest: () => readReleaseManifest,
4306
+ routesDir: () => routesDir,
3325
4307
  runDoctor: () => runDoctor,
4308
+ satisfies: () => satisfies,
3326
4309
  sqlStatements: () => sqlStatements,
3327
4310
  toJson: () => toJson,
3328
4311
  validateConfig: () => validateConfig,
3329
- validateLinks: () => validateLinks
4312
+ validateLinks: () => validateLinks,
4313
+ webRoutes: () => webRoutes
3330
4314
  });
3331
4315
  async function runDoctor(options = {}) {
3332
- const root = path28.resolve(options.root ?? process.cwd());
4316
+ const root = path32.resolve(options.root ?? process.cwd());
3333
4317
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
3334
4318
  const config = loaded.config;
3335
4319
  const genesis = options.genesis ?? loadGenesis(root, config);
@@ -3342,18 +4326,7 @@ async function runDoctor(options = {}) {
3342
4326
  }
3343
4327
  const raw = [];
3344
4328
  const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
3345
- const builtins = [
3346
- { name: "layout", check: checkProjectLayout },
3347
- { name: "imports", check: checkImports },
3348
- { name: "raw-tags", check: checkRawTags },
3349
- { name: "colors", check: checkColors },
3350
- { name: "tokens", check: checkTokens },
3351
- { name: "shadowed-exports", check: checkShadowedExports },
3352
- { name: "version-skew", check: checkVersionSkew },
3353
- ...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
3354
- ...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
3355
- ];
3356
- for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
4329
+ for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
3357
4330
  try {
3358
4331
  await plugin.check(ctx);
3359
4332
  } catch (err) {
@@ -3367,7 +4340,8 @@ async function runDoctor(options = {}) {
3367
4340
  }
3368
4341
  const findings = applyConfig(raw, config);
3369
4342
  const errors = findings.filter((f) => f.level === "error").length;
3370
- const warnings = findings.length - errors;
4343
+ const warnings = findings.filter((f) => f.level === "warn").length;
4344
+ const infos = findings.length - errors - warnings;
3371
4345
  return {
3372
4346
  ok: errors === 0 && !(options.strict && warnings > 0),
3373
4347
  root,
@@ -3376,9 +4350,33 @@ async function runDoctor(options = {}) {
3376
4350
  unused: unusedComponents(ctx),
3377
4351
  ruleCount: (patterns?.count ?? 0) + plugins.length,
3378
4352
  errors,
3379
- warnings
4353
+ warnings,
4354
+ infos
3380
4355
  };
3381
4356
  }
4357
+ function builtinChecks(config) {
4358
+ const packs = {
4359
+ native: { name: "native", check: checkNativePack },
4360
+ supabase: { name: "supabase", check: checkSupabasePack }
4361
+ };
4362
+ return [
4363
+ { name: "layout", check: checkProjectLayout },
4364
+ { name: "imports", check: checkImports },
4365
+ { name: "raw-tags", check: checkRawTags },
4366
+ { name: "colors", check: checkColors },
4367
+ { name: "tokens", check: checkTokens },
4368
+ { name: "shadowed-exports", check: checkShadowedExports },
4369
+ { name: "version-skew", check: checkVersionSkew },
4370
+ { name: "duplicate-packages", check: checkDuplicatePackages },
4371
+ { name: "peer-ranges", check: checkPeerRanges },
4372
+ { name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
4373
+ { name: "local-genesis-copies", check: checkLocalGenesisCopies },
4374
+ { name: "resource-workspaces", check: checkResourceWorkspaces },
4375
+ { name: "page-layouts", check: checkPageLayouts },
4376
+ { name: "iso-date-slices", check: checkIsoDateSlices },
4377
+ ...(config.packs ?? []).map((p) => packs[p])
4378
+ ];
4379
+ }
3382
4380
  function applyConfig(raw, config) {
3383
4381
  const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
3384
4382
  const out = [];
@@ -3425,7 +4423,8 @@ function formatReport(result) {
3425
4423
  lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
3426
4424
  }
3427
4425
  lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
3428
- lines.push(result.ok ? `PASS (${result.warnings} warnings)` : `FAIL (${result.errors} errors, ${result.warnings} warnings)`);
4426
+ const info = result.infos ? `, ${result.infos} info` : "";
4427
+ lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
3429
4428
  return lines.join("\n");
3430
4429
  }
3431
4430
  function toJson(result) {
@@ -3434,6 +4433,7 @@ function toJson(result) {
3434
4433
  genesis: `${result.genesis.uiPackage}@${result.genesis.uiVersion}`,
3435
4434
  errors: result.errors,
3436
4435
  warnings: result.warnings,
4436
+ infos: result.infos,
3437
4437
  findings: result.findings,
3438
4438
  unused: result.unused
3439
4439
  };
@@ -3444,7 +4444,8 @@ function genesisSummary(g) {
3444
4444
  components: g.components,
3445
4445
  tokens: [...g.tokens].sort(),
3446
4446
  rawTags: Object.fromEntries(g.rawTags),
3447
- palette: g.palette
4447
+ palette: g.palette,
4448
+ companions: Object.fromEntries(g.companions.map((c) => [`${c.package}@${c.version}`, c.components]))
3448
4449
  };
3449
4450
  }
3450
4451
  var init_doctor = __esm({
@@ -3460,6 +4461,9 @@ var init_doctor = __esm({
3460
4461
  init_scan();
3461
4462
  init_supabase();
3462
4463
  init_versions();
4464
+ init_installs();
4465
+ init_structure();
4466
+ init_dates();
3463
4467
  init_config();
3464
4468
  init_genesis();
3465
4469
  init_patterns();
@@ -3469,6 +4473,9 @@ var init_doctor = __esm({
3469
4473
  init_native();
3470
4474
  init_supabase();
3471
4475
  init_versions();
4476
+ init_installs();
4477
+ init_semver();
4478
+ init_routes();
3472
4479
  }
3473
4480
  });
3474
4481
 
@@ -3485,29 +4492,29 @@ __export(features_exports, {
3485
4492
  function isObject3(value) {
3486
4493
  return typeof value === "object" && value !== null && !Array.isArray(value);
3487
4494
  }
3488
- function readObject(file, key) {
4495
+ function readObject(file, key2) {
3489
4496
  try {
3490
4497
  const json = JSON.parse(readFileSync(file, "utf-8"));
3491
- return isObject3(json[key]) ? json[key] : {};
4498
+ return isObject3(json[key2]) ? json[key2] : {};
3492
4499
  } catch {
3493
4500
  return {};
3494
4501
  }
3495
4502
  }
3496
4503
  function settings(root, options) {
3497
- const fromPackage = readObject(path28.join(root, "package.json"), "genesisFeatures");
3498
- const fromConfig = readObject(path28.join(root, "genesis.config.json"), "features");
4504
+ const fromPackage = readObject(path32.join(root, "package.json"), "genesisFeatures");
4505
+ const fromConfig = readObject(path32.join(root, "genesis.config.json"), "features");
3499
4506
  const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
3500
4507
  return { ...fromPackage, ...fromConfig, ...given };
3501
4508
  }
3502
4509
  async function loadRegistry(input) {
3503
- const root = path28.resolve(input.dir);
4510
+ const root = path32.resolve(input.dir);
3504
4511
  const options = settings(root, input);
3505
- const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path28.join(root, p)));
3506
- if (!registry || !existsSync(path28.join(root, registry))) {
4512
+ const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path32.join(root, p)));
4513
+ if (!registry || !existsSync(path32.join(root, registry))) {
3507
4514
  throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
3508
4515
  }
3509
- const jiti = createJiti(path28.join(root, "package.json"), { moduleCache: false });
3510
- const load = async (file) => await jiti.import(path28.join(root, file));
4516
+ const jiti = createJiti(path32.join(root, "package.json"), { moduleCache: false });
4517
+ const load = async (file) => await jiti.import(path32.join(root, file));
3511
4518
  const mod = await load(registry);
3512
4519
  const features2 = mod.features ?? mod.default;
3513
4520
  if (!isObject3(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
@@ -3519,7 +4526,7 @@ async function loadRegistry(input) {
3519
4526
  const project = {
3520
4527
  ...rest,
3521
4528
  root,
3522
- source: options.source ?? registry.split(path28.sep).join("/"),
4529
+ source: options.source ?? registry.split(path32.sep).join("/"),
3523
4530
  features: features2,
3524
4531
  flags
3525
4532
  };
@@ -3629,8 +4636,8 @@ function routeTags(source) {
3629
4636
  }
3630
4637
  function wireStudioRoute(source, route, pageImportPath) {
3631
4638
  const tags = routeTags(source);
3632
- const relative5 = route.replace(/^\//, "");
3633
- const existing = tags.find((t) => new RegExp(`path=["'](/?${relative5.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
4639
+ const relative6 = route.replace(/^\//, "");
4640
+ const existing = tags.find((t) => new RegExp(`path=["'](/?${relative6.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
3634
4641
  if (existing) {
3635
4642
  return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
3636
4643
  }
@@ -3638,17 +4645,17 @@ function wireStudioRoute(source, route, pageImportPath) {
3638
4645
  const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
3639
4646
  if (roots.length !== 1) {
3640
4647
  return {
3641
- skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative5}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
4648
+ skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative6}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
3642
4649
  };
3643
4650
  }
3644
4651
  const layout = roots[0];
3645
4652
  const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
3646
- if (base && !relative5.startsWith(`${base}/`)) {
4653
+ if (base && !relative6.startsWith(`${base}/`)) {
3647
4654
  return {
3648
4655
  skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
3649
4656
  };
3650
4657
  }
3651
- const childPath = base ? relative5.slice(base.length + 1) : relative5;
4658
+ const childPath = base ? relative6.slice(base.length + 1) : relative6;
3652
4659
  const guard = GUARD.exec(source)?.[1];
3653
4660
  const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
3654
4661
  const before = source.slice(0, layout.close);
@@ -4026,7 +5033,7 @@ function copyOwned(root, lock, write, dryRun = false) {
4026
5033
  }
4027
5034
  return "kept";
4028
5035
  }
4029
- function ownedKeyProblem(key, source) {
5036
+ function ownedKeyProblem(key2, source) {
4030
5037
  let parsed;
4031
5038
  try {
4032
5039
  parsed = parseSource(source);
@@ -4034,23 +5041,23 @@ function ownedKeyProblem(key, source) {
4034
5041
  return err instanceof Error ? err.message : String(err);
4035
5042
  }
4036
5043
  const { package: pkg, path: rel } = parsed;
4037
- if (!GENESIS_PACKAGE.test(pkg)) return `${key}'s source ${pkg} isn't a Genesis package`;
4038
- if (!safeRelative(rel) || !safeRelative(key)) return `${key} or its source isn't a plain path`;
4039
- if (key.startsWith("supabase/migrations/")) return `${key} is a migration; migrations are never refreshed`;
5044
+ if (!GENESIS_PACKAGE.test(pkg)) return `${key2}'s source ${pkg} isn't a Genesis package`;
5045
+ if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
5046
+ if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
4040
5047
  const base = rel.split("/").pop();
4041
5048
  if (pkg === CLI && rel.startsWith("templates/")) {
4042
- return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key) ? null : `${key} isn't where a template goes`;
5049
+ return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
4043
5050
  }
4044
5051
  const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
4045
- if (fn) return key === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key} isn't where ${rel} goes`;
4046
- if (/\.test\.sql$/.test(base)) return key === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key} isn't where ${rel} goes`;
4047
- if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key) && key.endsWith(`/${base}`)) return null;
4048
- return `${key} doesn't match its source ${source}`;
5052
+ if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
5053
+ if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
5054
+ if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
5055
+ return `${key2} doesn't match its source ${source}`;
4049
5056
  }
4050
5057
  function mergeThreeWay(mine, base, theirs) {
4051
- const dir = mkdtempSync(path28.join(tmpdir(), "genesis-merge-"));
5058
+ const dir = mkdtempSync(path32.join(tmpdir(), "genesis-merge-"));
4052
5059
  try {
4053
- const [m, b, t] = ["mine", "base", "theirs"].map((n) => path28.join(dir, n));
5060
+ const [m, b, t] = ["mine", "base", "theirs"].map((n) => path32.join(dir, n));
4054
5061
  writeFileSync(m, mine);
4055
5062
  writeFileSync(b, base);
4056
5063
  writeFileSync(t, theirs);
@@ -4219,12 +5226,12 @@ var init_registry_edit = __esm({
4219
5226
  });
4220
5227
  function routerRoot2(root) {
4221
5228
  try {
4222
- const config = JSON.parse(readFileSync(path28.join(root, "genesis.config.json"), "utf8"));
5229
+ const config = JSON.parse(readFileSync(path32.join(root, "genesis.config.json"), "utf8"));
4223
5230
  const configured = config.doctor?.native?.routerRoot;
4224
- if (configured && existsSync(path28.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
5231
+ if (configured && existsSync(path32.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
4225
5232
  } catch {
4226
5233
  }
4227
- for (const dir of ["src/app", "app"]) if (existsSync(path28.join(root, dir, "_layout.tsx"))) return dir;
5234
+ for (const dir of ["src/app", "app"]) if (existsSync(path32.join(root, dir, "_layout.tsx"))) return dir;
4228
5235
  return null;
4229
5236
  }
4230
5237
  function routeOf(file) {
@@ -4267,7 +5274,7 @@ export default function Screen() {
4267
5274
  }
4268
5275
  `;
4269
5276
  }
4270
- var init_routes = __esm({
5277
+ var init_routes2 = __esm({
4271
5278
  "src/blocks/routes.ts"() {
4272
5279
  init_files();
4273
5280
  }
@@ -4285,23 +5292,23 @@ __export(add_exports, {
4285
5292
  });
4286
5293
  function appDependencies(root) {
4287
5294
  try {
4288
- const pkg = JSON.parse(readFileSync(path28.join(root, "package.json"), "utf8"));
5295
+ const pkg = JSON.parse(readFileSync(path32.join(root, "package.json"), "utf8"));
4289
5296
  return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
4290
5297
  } catch {
4291
5298
  return {};
4292
5299
  }
4293
5300
  }
4294
5301
  function registryFile(root) {
4295
- const read = (file, key) => {
5302
+ const read = (file, key2) => {
4296
5303
  try {
4297
- const v = JSON.parse(readFileSync(path28.join(root, file), "utf8"))[key]?.registry;
5304
+ const v = JSON.parse(readFileSync(path32.join(root, file), "utf8"))[key2]?.registry;
4298
5305
  return typeof v === "string" ? v : void 0;
4299
5306
  } catch {
4300
5307
  return void 0;
4301
5308
  }
4302
5309
  };
4303
5310
  const named = read("genesis.config.json", "features") ?? read("package.json", "genesisFeatures");
4304
- for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path28.join(root, candidate))) return candidate;
5311
+ for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path32.join(root, candidate))) return candidate;
4305
5312
  return null;
4306
5313
  }
4307
5314
  async function registryIds(root, file) {
@@ -4378,7 +5385,7 @@ verify_jwt = false
4378
5385
  return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
4379
5386
  }
4380
5387
  async function runAdd(options) {
4381
- const root = path28.resolve(options.root);
5388
+ const root = path32.resolve(options.root);
4382
5389
  const log = options.log ?? SILENT;
4383
5390
  const now = options.now ?? /* @__PURE__ */ new Date();
4384
5391
  const warnings = [];
@@ -4540,7 +5547,7 @@ var init_add = __esm({
4540
5547
  init_owned();
4541
5548
  init_pm();
4542
5549
  init_registry_edit();
4543
- init_routes();
5550
+ init_routes2();
4544
5551
  SILENT = { info() {
4545
5552
  }, warn() {
4546
5553
  } };
@@ -4553,7 +5560,7 @@ __export(migrate_exports, {
4553
5560
  runMigrate: () => runMigrate
4554
5561
  });
4555
5562
  async function runMigrate(options) {
4556
- const root = path28.resolve(options.root);
5563
+ const root = path32.resolve(options.root);
4557
5564
  const lock = readLock(root);
4558
5565
  const warnings = [];
4559
5566
  const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks), ...options.blocks ?? []])];
@@ -4604,7 +5611,7 @@ var init_migrate = __esm({
4604
5611
  });
4605
5612
 
4606
5613
  // src/upgrade/bump-core.mjs
4607
- function compareVersions(a, b) {
5614
+ function compareVersions2(a, b) {
4608
5615
  const [ca, pa = ""] = a.split(/-(.*)/s);
4609
5616
  const [cb, pb = ""] = b.split(/-(.*)/s);
4610
5617
  const x = ca.split(".").map(Number), y = cb.split(".").map(Number);
@@ -4626,7 +5633,7 @@ function bumpPackageJson(file, text, wanted) {
4626
5633
  const changes = [], skipped = [];
4627
5634
  for (const section of SECTIONS) {
4628
5635
  for (const [name, spec] of Object.entries(pkg[section] ?? {})) {
4629
- if (!GENESIS.test(name)) continue;
5636
+ if (!GENESIS2.test(name)) continue;
4630
5637
  const m = EXACT.exec(spec);
4631
5638
  if (!m) {
4632
5639
  skipped.push({ file, name, spec, why: "not a plain version" });
@@ -4641,7 +5648,7 @@ function bumpPackageJson(file, text, wanted) {
4641
5648
  skipped.push({ file, name, spec, why: `the release names ${JSON.stringify(want)}, not a version` });
4642
5649
  continue;
4643
5650
  }
4644
- const cmp = compareVersions(want, m[2]);
5651
+ const cmp = compareVersions2(want, m[2]);
4645
5652
  if (cmp === 0) continue;
4646
5653
  if (cmp < 0) {
4647
5654
  skipped.push({ file, name, spec, why: `newer than ${want}` });
@@ -4664,11 +5671,11 @@ function bumpSummary(version, changes, skipped) {
4664
5671
  ...skipped.length ? ["", "Left alone:", "", ...skipped.map((s) => `- \`${s.name}\` ${s.spec} in ${s.file}: ${s.why}`)] : []
4665
5672
  ].join("\n");
4666
5673
  }
4667
- var UMBRELLA, GENESIS, EXACT, PLAIN, SECTIONS;
5674
+ var UMBRELLA, GENESIS2, EXACT, PLAIN, SECTIONS;
4668
5675
  var init_bump_core = __esm({
4669
5676
  "src/upgrade/bump-core.mjs"() {
4670
5677
  UMBRELLA = "@marktiderman/genesis";
4671
- GENESIS = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
5678
+ GENESIS2 = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
4672
5679
  EXACT = /^(\^|~|=)?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/;
4673
5680
  PLAIN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
4674
5681
  SECTIONS = ["dependencies", "devDependencies", "optionalDependencies"];
@@ -4678,7 +5685,7 @@ var init_bump_core = __esm({
4678
5685
  // src/upgrade/codemods.ts
4679
5686
  function codemodsFor(changes, registry = CODEMODS) {
4680
5687
  return registry.filter(
4681
- (mod) => changes.some((c) => c.name === mod.package && compareVersions(bare(c.from), mod.version) < 0 && compareVersions(bare(c.to), mod.version) >= 0)
5688
+ (mod) => changes.some((c) => c.name === mod.package && compareVersions2(bare(c.from), mod.version) < 0 && compareVersions2(bare(c.to), mod.version) >= 0)
4682
5689
  );
4683
5690
  }
4684
5691
  function uncoveredBreaks(changes, registry = CODEMODS) {
@@ -4713,11 +5720,11 @@ function npmLookup(cwd) {
4713
5720
  if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
4714
5721
  const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
4715
5722
  if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
4716
- const tmp = mkdtempSync(path28.join(tmpdir(), "genesis-umbrella-"));
5723
+ const tmp = mkdtempSync(path32.join(tmpdir(), "genesis-umbrella-"));
4717
5724
  try {
4718
5725
  const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
4719
- execFileSync("tar", ["-xzf", path28.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
4720
- const manifest = JSON.parse(readFileSync(path28.join(tmp, "package/dist/versions.json"), "utf8"));
5726
+ execFileSync("tar", ["-xzf", path32.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
5727
+ const manifest = JSON.parse(readFileSync(path32.join(tmp, "package/dist/versions.json"), "utf8"));
4721
5728
  if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
4722
5729
  return manifest;
4723
5730
  } finally {
@@ -4744,7 +5751,7 @@ function packageJsons(root) {
4744
5751
  if (files.length) return files;
4745
5752
  } catch {
4746
5753
  }
4747
- return existsSync(path28.join(root, "package.json")) ? ["package.json"] : [];
5754
+ return existsSync(path32.join(root, "package.json")) ? ["package.json"] : [];
4748
5755
  }
4749
5756
  function sourceText(root, source, substitutions) {
4750
5757
  const { package: pkg, path: rel } = parseSource(source);
@@ -4763,11 +5770,11 @@ function sourceText(root, source, substitutions) {
4763
5770
  }
4764
5771
  }
4765
5772
  async function runUpgrade(options) {
4766
- const root = path28.resolve(options.root);
5773
+ const root = path32.resolve(options.root);
4767
5774
  const log = options.log ?? (() => {
4768
5775
  });
4769
5776
  const lookup = options.lookup ?? npmLookup(root);
4770
- const release = options.manifest ? JSON.parse(readFileSync(path28.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
5777
+ const release = options.manifest ? JSON.parse(readFileSync(path32.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
4771
5778
  const pinned = { [UMBRELLA]: release.version, ...release.packages };
4772
5779
  const wanted = (name) => pinned[name] ?? lookup.latest(name);
4773
5780
  const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
@@ -4903,7 +5910,7 @@ function checkSubstitutions(substitutions) {
4903
5910
  if (!substitutions || !Object.keys(substitutions).length) return;
4904
5911
  let allowed;
4905
5912
  try {
4906
- const was = starterIdentity(readFileSync(path28.join(starterDir(), "starter.config.ts"), "utf8"));
5913
+ const was = starterIdentity(readFileSync(path32.join(starterDir(), "starter.config.ts"), "utf8"));
4907
5914
  allowed = [was.name, was.slug, was.scheme, was.bundleId];
4908
5915
  } catch {
4909
5916
  allowed = [];
@@ -4936,15 +5943,15 @@ function openPullRequest(root, version, report, base) {
4936
5943
  git2("switch", "-c", branch);
4937
5944
  const top = git2("rev-parse", "--show-toplevel");
4938
5945
  const lockfiles = [];
4939
- for (let dir = path28.resolve(root); ; dir = path28.dirname(dir)) {
4940
- for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path28.join(dir, f))) lockfiles.push(path28.relative(root, path28.join(dir, f)));
4941
- if (lockfiles.length || dir === top || path28.dirname(dir) === dir) break;
5946
+ for (let dir = path32.resolve(root); ; dir = path32.dirname(dir)) {
5947
+ for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path32.join(dir, f))) lockfiles.push(path32.relative(root, path32.join(dir, f)));
5948
+ if (lockfiles.length || dir === top || path32.dirname(dir) === dir) break;
4942
5949
  }
4943
- const paths = [...report.files.filter((f) => existsSync(path28.join(root, f))), ...lockfiles];
5950
+ const paths = [...report.files.filter((f) => existsSync(path32.join(root, f))), ...lockfiles];
4944
5951
  git2("add", "--", ...paths);
4945
5952
  git2("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
4946
5953
  git2("push", "-u", "origin", branch);
4947
- const body = path28.join(mkdtempSync(path28.join(tmpdir(), "genesis-pr-")), "body.md");
5954
+ const body = path32.join(mkdtempSync(path32.join(tmpdir(), "genesis-pr-")), "body.md");
4948
5955
  writeFileSync(body, `${report.summary}
4949
5956
 
4950
5957
  Opened by \`genesis upgrade --pr\`.
@@ -5067,9 +6074,9 @@ async function runScaffold(opts, fs2) {
5067
6074
  function joinPath(...parts) {
5068
6075
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
5069
6076
  }
5070
- function dirname(path29) {
5071
- const idx = path29.lastIndexOf("/");
5072
- return idx === -1 ? "." : path29.slice(0, idx);
6077
+ function dirname(path33) {
6078
+ const idx = path33.lastIndexOf("/");
6079
+ return idx === -1 ? "." : path33.slice(0, idx);
5073
6080
  }
5074
6081
  function brandPackageJson(consumer, genesisVersion) {
5075
6082
  return JSON.stringify(
@@ -5308,7 +6315,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
5308
6315
  const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
5309
6316
  const result2 = await runInitNative2({
5310
6317
  name: consumer,
5311
- target: path28.resolve(opts.target ?? consumer),
6318
+ target: path32.resolve(opts.target ?? consumer),
5312
6319
  ...opts.displayName ? { displayName: opts.displayName } : {},
5313
6320
  ...opts.bundleId ? { bundleId: opts.bundleId } : {},
5314
6321
  ...opts.scheme ? { scheme: opts.scheme } : {}
@@ -5318,7 +6325,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
5318
6325
  console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
5319
6326
  console.log("");
5320
6327
  console.log("Next steps:");
5321
- [`cd ${path28.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
6328
+ [`cd ${path32.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
5322
6329
  return;
5323
6330
  }
5324
6331
  opts.target ??= process.cwd();
@@ -5363,9 +6370,9 @@ program.command("introspect").description("Write a checked-in contract (resource
5363
6370
  if (schemas.length !== 1) throw new Error("--openapi reads one schema at a time; pass a single --schema.");
5364
6371
  const headers = [...opts.header ?? []];
5365
6372
  if (opts.apikeyEnv) {
5366
- const key = process.env[opts.apikeyEnv];
5367
- if (!key) throw new Error(`Set ${opts.apikeyEnv} to the API key.`);
5368
- headers.push(`apikey: ${key}`, `Authorization: Bearer ${key}`);
6373
+ const key2 = process.env[opts.apikeyEnv];
6374
+ if (!key2) throw new Error(`Set ${opts.apikeyEnv} to the API key.`);
6375
+ headers.push(`apikey: ${key2}`, `Authorization: Bearer ${key2}`);
5369
6376
  }
5370
6377
  const doc = await readOpenApi(opts.openapi, headers);
5371
6378
  tables = introspectOpenApi2(doc, schemas[0]);
@@ -5384,7 +6391,7 @@ program.command("introspect").description("Write a checked-in contract (resource
5384
6391
  source = `Postgres (${schemas.join(", ")})`;
5385
6392
  }
5386
6393
  const content = emitContracts2(tables, { source });
5387
- const target = path28.resolve(opts.out);
6394
+ const target = path32.resolve(opts.out);
5388
6395
  if (opts.check) {
5389
6396
  const current = await fs.readFile(target, "utf-8").catch(() => null);
5390
6397
  if (current !== content) {
@@ -5399,7 +6406,7 @@ program.command("introspect").description("Write a checked-in contract (resource
5399
6406
  });
5400
6407
  program.command("doctor").description("Check this app against the installed Genesis: components, tokens, imports, colors, plus the app's own rules").option("--strict", "Fail on warnings too", false).option("--json", "Print the report as JSON", false).option("--build", "Also run the app's typecheck and build (doctor.build, or its typecheck/build scripts)", false).option("-c, --config <path>", 'Config file (default: genesis.config.json, then package.json "genesis")').option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--print-genesis", "Print the components, tokens and raw tags read from Genesis, and exit", false).action(async (opts) => {
5401
6408
  const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
5402
- const root = path28.resolve(opts.dir);
6409
+ const root = path32.resolve(opts.dir);
5403
6410
  try {
5404
6411
  if (opts.printGenesis) {
5405
6412
  const { config } = doctor.loadConfig(root, opts.config);
@@ -5464,24 +6471,24 @@ featureOptions(
5464
6471
  var studio = program.command("studio").description("The Genesis Data Studio");
5465
6472
  studio.command("init").description("Turn the Data Studio on in this app: a server for every table, a page, and one migration to review").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--host <host>", "next, tanstack-start or supabase-function (default: detected)").option("--route <path>", "Where the page lives", "/admin/data").option("--login-role <name>", "The studio's database login", "genesis_studio_login").option("--force", "Overwrite files that already exist", false).action(async (opts) => {
5466
6473
  const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
5467
- const root = path28.resolve(opts.dir);
5468
- const packageJson = JSON.parse(await fs.readFile(path28.join(root, "package.json"), "utf-8").catch(() => "{}"));
5469
- const existsSync22 = (await import('fs')).existsSync;
6474
+ const root = path32.resolve(opts.dir);
6475
+ const packageJson = JSON.parse(await fs.readFile(path32.join(root, "package.json"), "utf-8").catch(() => "{}"));
6476
+ const existsSync26 = (await import('fs')).existsSync;
5470
6477
  const readSync = (await import('fs')).readFileSync;
5471
- const readdirSync9 = (await import('fs')).readdirSync;
6478
+ const readdirSync10 = (await import('fs')).readdirSync;
5472
6479
  if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
5473
6480
  throw new Error("--host must be next, tanstack-start or supabase-function.");
5474
6481
  }
5475
6482
  const plan = planStudioInit2(
5476
6483
  {
5477
6484
  packageJson,
5478
- exists: (p) => existsSync22(path28.join(root, p)),
5479
- read: (p) => existsSync22(path28.join(root, p)) ? readSync(path28.join(root, p), "utf-8") : null,
6485
+ exists: (p) => existsSync26(path32.join(root, p)),
6486
+ read: (p) => existsSync26(path32.join(root, p)) ? readSync(path32.join(root, p), "utf-8") : null,
5480
6487
  timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
5481
6488
  listDeep: (p) => {
5482
6489
  const out = [];
5483
6490
  const walk2 = (rel) => {
5484
- for (const entry of readdirSync9(path28.join(root, rel), { withFileTypes: true })) {
6491
+ for (const entry of readdirSync10(path32.join(root, rel), { withFileTypes: true })) {
5485
6492
  const child = `${rel}/${entry.name}`;
5486
6493
  if (entry.isDirectory()) walk2(child);
5487
6494
  else out.push(child);
@@ -5495,7 +6502,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
5495
6502
  },
5496
6503
  list: (p) => {
5497
6504
  try {
5498
- return readdirSync9(path28.join(root, p));
6505
+ return readdirSync10(path32.join(root, p));
5499
6506
  } catch {
5500
6507
  return [];
5501
6508
  }
@@ -5504,8 +6511,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
5504
6511
  { host: opts.host, route: opts.route, loginRole: opts.loginRole }
5505
6512
  );
5506
6513
  for (const file of plan.files) {
5507
- const target = path28.join(root, file.path);
5508
- await fs.mkdir(path28.dirname(target), { recursive: true });
6514
+ const target = path32.join(root, file.path);
6515
+ await fs.mkdir(path32.dirname(target), { recursive: true });
5509
6516
  if (file.edit) {
5510
6517
  await fs.writeFile(target, file.content, "utf-8");
5511
6518
  console.log(`~ ${file.path} (${file.edit})`);
@@ -5516,14 +6523,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
5516
6523
  console.log(`+ ${file.path} (appended)`);
5517
6524
  continue;
5518
6525
  }
5519
- if (existsSync22(target) && !opts.force) {
6526
+ if (existsSync26(target) && !opts.force) {
5520
6527
  console.log(`= ${file.path} exists; left as it is (--force to replace)`);
5521
6528
  continue;
5522
6529
  }
5523
6530
  await fs.writeFile(target, file.content, "utf-8");
5524
6531
  console.log(`+ ${file.path}`);
5525
6532
  }
5526
- const pm = existsSync22(path28.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync22(path28.join(root, "yarn.lock")) ? "yarn add" : existsSync22(path28.join(root, "bun.lock")) || existsSync22(path28.join(root, "bun.lockb")) ? "bun add" : "npm install";
6533
+ const pm = existsSync26(path32.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync26(path32.join(root, "yarn.lock")) ? "yarn add" : existsSync26(path32.join(root, "bun.lock")) || existsSync26(path32.join(root, "bun.lockb")) ? "bun add" : "npm install";
5527
6534
  console.log("");
5528
6535
  console.log(`\u2714 The Data Studio is set up for ${{ next: "Next.js", "tanstack-start": "TanStack Start", "supabase-function": "a Supabase Edge Function" }[plan.host]}. To finish:`);
5529
6536
  console.log(` 1. ${pm} ${plan.install.join(" ")}`);
@@ -5541,7 +6548,7 @@ async function confirm(question) {
5541
6548
  }
5542
6549
  var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
5543
6550
  program.command("add").description("Add a block (a feature an app adds whole) from the Genesis package that declares it: install, migrations, functions, skills, routes, registry entry").argument("[block]", "The block's id, e.g. tenant-features").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--package <name>", "The package that declares it, when two do").option("--list", "List the blocks this app can add, and exit", false).option("--dry-run", "Print the plan; write and install nothing", false).option("-y, --yes", "Don't ask before writing", false).option("--no-install", "Don't install packages (print the command instead)").option("--no-features-build", "Don't run features build after").action(async (block, opts) => {
5544
- const root = path28.resolve(opts.dir);
6551
+ const root = path32.resolve(opts.dir);
5545
6552
  if (opts.list || !block) {
5546
6553
  const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
5547
6554
  const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
@@ -5570,7 +6577,7 @@ program.command("add").description("Add a block (a feature an app adds whole) fr
5570
6577
  program.command("migrate").description("Copy new package migrations of the app's blocks in as new timestamped files; report edited or changed ones (never rewritten)").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--block <id...>", "Also check these blocks (beyond genesis.lock.json's)").option("--dry-run", "Report only", false).option("--forward", "Write a forward migration stub for each edited or changed migration", false).action(async (opts) => {
5571
6578
  const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
5572
6579
  const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
5573
- const report = await runMigrate2({ root: path28.resolve(opts.dir), ...opts.block ? { blocks: opts.block } : {}, dryRun: opts.dryRun, forward: opts.forward });
6580
+ const report = await runMigrate2({ root: path32.resolve(opts.dir), ...opts.block ? { blocks: opts.block } : {}, dryRun: opts.dryRun, forward: opts.forward });
5574
6581
  for (const w of report.warnings) logger.warn(w);
5575
6582
  console.log(formatMigrationRows2(report.plan.rows));
5576
6583
  for (const c of report.plan.creates) if (c.kind !== "migration") console.log(`+ ${c.path} (${c.kind === "test" ? "pgTAP test" : "forward migration: fill it in"})`);
@@ -5585,7 +6592,7 @@ program.command("migrate").description("Copy new package migrations of the app's
5585
6592
  program.command("upgrade").description("Move every @marktiderman/genesis* dependency to one Genesis release, refresh the files Genesis owns, run codemods and the doctor").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--version <v>", "The @marktiderman/genesis release: an exact version or a dist-tag", "latest").option("--manifest <file>", "Read the release from this versions.json instead of npm").option("--dry-run", "Report the bump, and owned files compared with the packages installed now; change nothing", false).option("--no-install", "Don't reinstall after the bump").option("--no-doctor", "Don't run genesis doctor after").option("--keep-mine", "Never merge an owned file you changed; write the new text to .genesis-next", false).option("--pr", "Commit to a genesis-upgrade/<version> branch, push it and open a pull request", false).action(async (opts) => {
5586
6593
  const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
5587
6594
  const report = await runUpgrade2({
5588
- root: path28.resolve(opts.dir),
6595
+ root: path32.resolve(opts.dir),
5589
6596
  version: opts.version,
5590
6597
  ...opts.manifest ? { manifest: opts.manifest } : {},
5591
6598
  dryRun: opts.dryRun,
@@ -5649,7 +6656,7 @@ function redactUrl(location) {
5649
6656
  const url = new URL(location);
5650
6657
  return `${url.origin}${url.pathname}`;
5651
6658
  } catch {
5652
- return path28.basename(location);
6659
+ return path32.basename(location);
5653
6660
  }
5654
6661
  }
5655
6662
  //# sourceMappingURL=cli.js.map