@marktiderman/genesis-cli 1.18.0 → 1.20.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.
Files changed (38) hide show
  1. package/README.md +147 -2
  2. package/dist/cli.js +1363 -456
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{config-1jP8eCZy.d.ts → config-Dj_f9T7J.d.ts} +14 -1
  5. package/dist/doctor.d.ts +3 -3
  6. package/dist/doctor.js +402 -40
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/eslint.cjs +99 -0
  9. package/dist/eslint.cjs.map +1 -0
  10. package/dist/eslint.d.cts +68 -0
  11. package/dist/eslint.d.ts +68 -0
  12. package/dist/eslint.js +72 -0
  13. package/dist/eslint.js.map +1 -0
  14. package/dist/expo.d.ts +2 -2
  15. package/dist/expo.js +18 -0
  16. package/dist/expo.js.map +1 -1
  17. package/dist/genesis-catalog.json +30 -14
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +410 -48
  20. package/dist/index.js.map +1 -1
  21. package/dist/starter/README.md +18 -0
  22. package/dist/starter/__tests__/components/gestures.test.tsx +64 -0
  23. package/dist/starter/__tests__/components/resolver.js +14 -2
  24. package/dist/starter/__tests__/components/setup.ts +5 -0
  25. package/dist/starter/__tests__/starter.test.ts +27 -7
  26. package/dist/starter/eslint.config.js +8 -1
  27. package/dist/starter/jest.config.js +3 -0
  28. package/dist/starter/nativewind-env.d.ts +1 -0
  29. package/dist/starter/package.json +3 -0
  30. package/dist/starter/src/lib/link-hosts.ts +7 -3
  31. package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +7 -2
  32. package/dist/starter/supabase/migrations/20261024000700_genesis_support_findings.sql +339 -0
  33. package/dist/starter/supabase/tests/database/genesis_support.test.sql +1 -1
  34. package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +219 -0
  35. package/dist/templates/ci/genesis-upgrade.yml +1 -0
  36. package/dist/vite.js +402 -40
  37. package/dist/vite.js.map +1 -1
  38. package/package.json +18 -4
package/dist/vite.js CHANGED
@@ -455,14 +455,14 @@ function inherit(own, source) {
455
455
  }
456
456
  function resolveViews(relations) {
457
457
  const done = /* @__PURE__ */ new Set();
458
- const resolve16 = (relation, depth) => {
458
+ const resolve18 = (relation, depth) => {
459
459
  if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
460
460
  done.add(relation.oid);
461
461
  const sources = new Set([...relation.origins.values()].map((o) => o.relation));
462
462
  if (sources.size !== 1) return;
463
463
  const source = relations.get([...sources][0]);
464
464
  if (!source) return;
465
- resolve16(source, depth + 1);
465
+ resolve18(source, depth + 1);
466
466
  const viewAttnumOf = /* @__PURE__ */ new Map();
467
467
  for (const [attnum, origin] of relation.origins) {
468
468
  const own = relation.columns.get(attnum);
@@ -485,7 +485,7 @@ function resolveViews(relations) {
485
485
  };
486
486
  if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
487
487
  };
488
- for (const relation of relations.values()) resolve16(relation, 0);
488
+ for (const relation of relations.values()) resolve18(relation, 0);
489
489
  }
490
490
  async function introspectPostgres(sql, schemas, options = {}) {
491
491
  const relations = /* @__PURE__ */ new Map();
@@ -899,8 +899,26 @@ function readGenesisConfig(root) {
899
899
  const out = { raw };
900
900
  if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
901
901
  if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
902
+ if (raw.supabase !== void 0) {
903
+ const supabase = validateSupabase(raw.supabase, file);
904
+ if (supabase !== true) out.supabase = supabase;
905
+ }
902
906
  return out;
903
907
  }
908
+ function validateSupabase(raw, source = "config") {
909
+ const fail = (msg) => {
910
+ throw new GenesisConfigError(`${source}: ${msg}`);
911
+ };
912
+ if (typeof raw === "boolean") return raw ? true : false;
913
+ if (!isObject(raw)) return fail(`"supabase" must be false or { "app": "<the folder of the app that holds supabase/>" }`);
914
+ for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
915
+ const app = raw.app;
916
+ if (typeof app !== "string" || !app.trim()) return fail(`supabase.app must be the folder of the app that holds supabase/, relative to this one (e.g. "../app")`);
917
+ if (path20.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
918
+ const norm = path20.posix.normalize(app).replace(/\/+$/, "");
919
+ if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
920
+ return { app: norm };
921
+ }
904
922
  var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
905
923
  var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
906
924
  function validatePrivacy(raw, source = "config") {
@@ -1125,7 +1143,7 @@ function globToRegExp(glob) {
1125
1143
  }
1126
1144
  function globMatcher(globs) {
1127
1145
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1128
- return (path37) => res.some((re) => re.test(path37));
1146
+ return (path44) => res.some((re) => re.test(path44));
1129
1147
  }
1130
1148
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1131
1149
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -1511,6 +1529,26 @@ function parseManifest(home, id, raw, version, options = {}) {
1511
1529
  const file = pathOf(m["file"], `${where2}.file`);
1512
1530
  if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
1513
1531
  const out = { package: pkgOf(m["package"], where2), file };
1532
+ if (m["provides"] !== void 0) {
1533
+ if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
1534
+ else {
1535
+ out.provides = m["provides"].map((p, j) => {
1536
+ const at2 = `${where2}.provides[${j}]`;
1537
+ if (!isObject2(p)) {
1538
+ problems.push(`${at2}: must be an object`);
1539
+ return { package: home, file: "" };
1540
+ }
1541
+ const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
1542
+ if (p["functions"] !== void 0) {
1543
+ if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
1544
+ else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
1545
+ }
1546
+ if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
1547
+ if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
1548
+ return provided;
1549
+ });
1550
+ }
1551
+ }
1514
1552
  if (m["test"] !== void 0) {
1515
1553
  out.test = pathOf(m["test"], `${where2}.test`);
1516
1554
  if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where2}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
@@ -1654,10 +1692,6 @@ function appPath2(root, rel) {
1654
1692
  if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
1655
1693
  return target;
1656
1694
  }
1657
- function readApp(root, rel) {
1658
- const file = appPath2(root, rel);
1659
- return existsSync(file) ? readFileSync(file, "utf8") : null;
1660
- }
1661
1695
 
1662
1696
  // src/blocks/local.ts
1663
1697
  var LOCAL_PACKAGES_KEY = "localPackages";
@@ -2322,8 +2356,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
2322
2356
  } catch {
2323
2357
  continue;
2324
2358
  }
2325
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2326
- const spec = json[section]?.[name];
2359
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2360
+ const spec = json[section2]?.[name];
2327
2361
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2328
2362
  const parsed = v && parseVersion(v);
2329
2363
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -2474,7 +2508,11 @@ var BUILTIN_RULES = [
2474
2508
  // supabase pack: contracts (contracts.ts)
2475
2509
  "contracts-stale",
2476
2510
  // genesis.lock.json against the files (lock-files.ts)
2477
- "lock-files"
2511
+ "lock-files",
2512
+ // an app whose database files live in another app (database.ts)
2513
+ "database-elsewhere",
2514
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2515
+ "genesis-eslint-config"
2478
2516
  ];
2479
2517
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2480
2518
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2697,7 +2735,7 @@ function privacyApisFor(dependencies2) {
2697
2735
  var EAS_PLACEHOLDERS = {
2698
2736
  REPLACE_WITH_APP_STORE_CONNECT_APP_ID: "the app's Apple ID from App Store Connect (create the app there, then App Information \u2192 General Information \u2192 Apple ID, a number)",
2699
2737
  REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
2700
- REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the path to your Google Play service account key, a JSON file kept out of git (Play Console \u2192 Setup \u2192 API access); or delete submit.production.android until you ship to Google Play",
2738
+ REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the Google Play service account key uploaded to EAS, not a local path (deploy-production.yml submits on EAS, where a local file isn't there): create a Google Cloud service account and its JSON key, invite it in Play Console \u2192 Users and permissions, upload the key with `eas credentials` (Android \u2192 Google Service Account), then remove only this serviceAccountKeyPath line (https://docs.expo.dev/submit/android/). Until you ship to Google Play, remove the submit_android job from deploy-production.yml instead, and keep submit.production.android as it is (the internal track, as a draft)",
2701
2739
  REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
2702
2740
  };
2703
2741
  function placeholderKey(line, placeholder) {
@@ -3606,11 +3644,21 @@ async function blocksOfInstalled(dir, warnings = [], options = {}) {
3606
3644
  const out = [];
3607
3645
  for (const id of [...ids].sort()) {
3608
3646
  const fromJson = raw[id] ?? {};
3609
- const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version, options), warnings);
3647
+ const merged = { ...fromJson, ...declared[id] };
3648
+ if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
3649
+ const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
3610
3650
  if (manifest) out.push(manifest);
3611
3651
  }
3612
3652
  return out;
3613
3653
  }
3654
+ function withProvides(declared, json) {
3655
+ if (!Array.isArray(declared)) return declared;
3656
+ const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
3657
+ return declared.map((m) => {
3658
+ const same = json.find((j) => fileOf(j) === fileOf(m));
3659
+ return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
3660
+ });
3661
+ }
3614
3662
  async function allBlocks(root, warnings = []) {
3615
3663
  const out = [];
3616
3664
  for (const local of localPackages(root)) {
@@ -4469,6 +4517,45 @@ function checkPackagesPack(ctx) {
4469
4517
  if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
4470
4518
  }
4471
4519
  }
4520
+ var LOCK_FILE = "genesis.lock.json";
4521
+ function emptyLock() {
4522
+ return { version: 1, blocks: {}, files: {} };
4523
+ }
4524
+ function readLock(root) {
4525
+ const file = path20.join(root, LOCK_FILE);
4526
+ if (!existsSync(file)) return emptyLock();
4527
+ const raw = JSON.parse(readFileSync(file, "utf8"));
4528
+ if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
4529
+ return {
4530
+ version: 1,
4531
+ ...raw.substitutions ? { substitutions: raw.substitutions } : {},
4532
+ blocks: raw.blocks ?? {},
4533
+ files: raw.files ?? {},
4534
+ ...raw.migrations ? { migrations: raw.migrations } : {}
4535
+ };
4536
+ }
4537
+ function parseSource(source) {
4538
+ const at = source.indexOf(":");
4539
+ if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
4540
+ return { package: source.slice(0, at), path: source.slice(at + 1) };
4541
+ }
4542
+
4543
+ // src/blocks/database.ts
4544
+ function databaseElsewhere(root) {
4545
+ const setting = readGenesisConfig(root)?.supabase;
4546
+ if (setting === void 0) return null;
4547
+ if (setting === false) return { app: null, dir: null, hasSupabase: false };
4548
+ const resolved = path20.resolve(root, setting.app);
4549
+ const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
4550
+ const dir = real2(resolved);
4551
+ if (dir === real2(path20.resolve(root))) throw new GenesisConfigError(`${path20.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
4552
+ return { app: setting.app, dir, hasSupabase: existsSync(path20.join(dir, "supabase")) };
4553
+ }
4554
+ function isSupabasePath(rel) {
4555
+ return rel === "supabase" || rel.startsWith("supabase/");
4556
+ }
4557
+
4558
+ // src/doctor/supabase.ts
4472
4559
  var DEFAULT_MIGRATIONS = "supabase/migrations";
4473
4560
  var DEFAULT_BASE = "origin/main";
4474
4561
  var DEFAULT_EXPOSED = ["public"];
@@ -4649,6 +4736,7 @@ function gitView(root, dir, base) {
4649
4736
  return { touched: touched2, edited };
4650
4737
  }
4651
4738
  function checkSupabasePack(ctx) {
4739
+ if (databaseElsewhere(ctx.root)) return;
4652
4740
  const settings = ctx.config.supabase ?? {};
4653
4741
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
4654
4742
  const abs = path20.join(ctx.root, dir);
@@ -5476,6 +5564,31 @@ function readsPracticeId(text) {
5476
5564
  var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
5477
5565
  var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
5478
5566
 
5567
+ // src/upgrade/eslint-config.ts
5568
+ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
5569
+ var TESTING_LIBRARY = "eslint-plugin-testing-library";
5570
+ var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
5571
+ function findEslintConfig(root) {
5572
+ return FLAT_CONFIG_FILES.find((name) => existsSync(path20.join(root, name))) ?? null;
5573
+ }
5574
+ function readPackageJson(root) {
5575
+ try {
5576
+ return JSON.parse(readFileSync(path20.join(root, "package.json"), "utf8"));
5577
+ } catch {
5578
+ return null;
5579
+ }
5580
+ }
5581
+ var declares = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name]);
5582
+ function appPlatform(pkg) {
5583
+ return declares(pkg, "expo") || declares(pkg, "react-native") ? "native" : "web";
5584
+ }
5585
+ function hasTestingLibrary(pkg) {
5586
+ return declares(pkg, TESTING_LIBRARY);
5587
+ }
5588
+ function usesGenesisLint(text) {
5589
+ return text.includes(ESLINT_EXPORT);
5590
+ }
5591
+
5479
5592
  // src/upgrade/codemods.ts
5480
5593
  var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
5481
5594
  var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -6068,28 +6181,6 @@ function checkAgentGuide(ctx) {
6068
6181
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
6069
6182
  }
6070
6183
  }
6071
- var LOCK_FILE = "genesis.lock.json";
6072
- function emptyLock() {
6073
- return { version: 1, blocks: {}, files: {} };
6074
- }
6075
- function readLock(root) {
6076
- const file = path20.join(root, LOCK_FILE);
6077
- if (!existsSync(file)) return emptyLock();
6078
- const raw = JSON.parse(readFileSync(file, "utf8"));
6079
- if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
6080
- return {
6081
- version: 1,
6082
- ...raw.substitutions ? { substitutions: raw.substitutions } : {},
6083
- blocks: raw.blocks ?? {},
6084
- files: raw.files ?? {},
6085
- ...raw.migrations ? { migrations: raw.migrations } : {}
6086
- };
6087
- }
6088
- function parseSource(source) {
6089
- const at = source.indexOf(":");
6090
- if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
6091
- return { package: source.slice(0, at), path: source.slice(at + 1) };
6092
- }
6093
6184
  var CLI = "@marktiderman/genesis-cli";
6094
6185
  function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
6095
6186
  let parsed;
@@ -6132,8 +6223,25 @@ function featuresBody(text) {
6132
6223
  const m = /\bfeatures:\s*\{/.exec(text);
6133
6224
  if (!m) return null;
6134
6225
  const start = m.index + m[0].length;
6135
- const end = text.indexOf("}", start);
6136
- return end < 0 ? null : { start, body: text.slice(start, end) };
6226
+ let depth = 1;
6227
+ for (let i = start; i < text.length; i++) {
6228
+ const c = text[i];
6229
+ if (c === "/" && text[i + 1] === "/") {
6230
+ const nl = text.indexOf("\n", i);
6231
+ if (nl < 0) return null;
6232
+ i = nl;
6233
+ } else if (c === "/" && text[i + 1] === "*") {
6234
+ const close = text.indexOf("*/", i + 2);
6235
+ if (close < 0) return null;
6236
+ i = close + 1;
6237
+ } else if (c === '"' || c === "'" || c === "`") {
6238
+ let j = i + 1;
6239
+ while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
6240
+ i = j;
6241
+ } else if (c === "{") depth++;
6242
+ else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
6243
+ }
6244
+ return null;
6137
6245
  }
6138
6246
  function parseStarterFeatures(text) {
6139
6247
  const found = featuresBody(text);
@@ -6155,6 +6263,7 @@ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
6155
6263
  const starter = raw?.starter;
6156
6264
  if (starter === void 0) return null;
6157
6265
  const blocks = starter?.blocks;
6266
+ if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
6158
6267
  if (typeof blocks !== "object" || blocks === null || Array.isArray(blocks)) throw new Error(`${source}: starter.blocks must map each feature switch to a list of block ids`);
6159
6268
  const out = {};
6160
6269
  for (const [name, ids] of Object.entries(blocks)) {
@@ -6222,9 +6331,179 @@ function blockOfSource(source, manifests) {
6222
6331
  }
6223
6332
  return null;
6224
6333
  }
6334
+ var BUN_LOCK = "bun.lock";
6335
+ var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
6336
+ var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
6337
+ function skipSpace(text, i) {
6338
+ for (; ; ) {
6339
+ while (i < text.length && /\s/.test(text[i])) i++;
6340
+ if (text.startsWith("//", i)) {
6341
+ const nl = text.indexOf("\n", i);
6342
+ i = nl === -1 ? text.length : nl + 1;
6343
+ } else if (text.startsWith("/*", i)) {
6344
+ const close = text.indexOf("*/", i + 2);
6345
+ i = close === -1 ? text.length : close + 2;
6346
+ } else return i;
6347
+ }
6348
+ }
6349
+ function skipString(text, i) {
6350
+ for (let j = i + 1; j < text.length; j++) {
6351
+ if (text[j] === "\\") j++;
6352
+ else if (text[j] === '"') return j + 1;
6353
+ }
6354
+ throw new Error("an unterminated string");
6355
+ }
6356
+ function skipValue(text, i) {
6357
+ const c = text[i];
6358
+ if (c === '"') return skipString(text, i);
6359
+ if (c === "{" || c === "[") {
6360
+ let depth = 0;
6361
+ for (let j2 = i; j2 < text.length; ) {
6362
+ const d = text[j2];
6363
+ if (d === '"') {
6364
+ j2 = skipString(text, j2);
6365
+ continue;
6366
+ }
6367
+ if (text.startsWith("//", j2) || text.startsWith("/*", j2)) {
6368
+ j2 = skipSpace(text, j2);
6369
+ continue;
6370
+ }
6371
+ if (d === "{" || d === "[") depth++;
6372
+ else if (d === "}" || d === "]") {
6373
+ depth--;
6374
+ if (depth === 0) return j2 + 1;
6375
+ }
6376
+ j2++;
6377
+ }
6378
+ throw new Error("an unclosed object or array");
6379
+ }
6380
+ let j = i;
6381
+ while (j < text.length && !/[\s,}\]]/.test(text[j])) j++;
6382
+ if (j === i) throw new Error(`an unexpected ${JSON.stringify(c ?? "end")} at ${i}`);
6383
+ return j;
6384
+ }
6385
+ function members(text, open) {
6386
+ const out = [];
6387
+ let i = skipSpace(text, open + 1);
6388
+ while (text[i] !== "}") {
6389
+ if (text[i] !== '"') throw new Error(`a key expected at ${i}`);
6390
+ const keyEnd = skipString(text, i);
6391
+ const key2 = JSON.parse(text.slice(i, keyEnd));
6392
+ let j = skipSpace(text, keyEnd);
6393
+ if (text[j] !== ":") throw new Error(`":" expected at ${j}`);
6394
+ const value = skipSpace(text, j + 1);
6395
+ const end = skipValue(text, value);
6396
+ out.push({ key: key2, start: i, end, value });
6397
+ j = skipSpace(text, end);
6398
+ if (text[j] === ",") j = skipSpace(text, j + 1);
6399
+ i = j;
6400
+ if (i >= text.length) throw new Error("an unclosed object");
6401
+ }
6402
+ return out;
6403
+ }
6404
+ function section(text, name) {
6405
+ const open = skipSpace(text, 0);
6406
+ if (text[open] !== "{") throw new Error("not an object");
6407
+ const m = members(text, open).find((x) => x.key === name);
6408
+ return m && text[m.value] === "{" ? m : null;
6409
+ }
6410
+ function parseLoose(fragment) {
6411
+ let out = "";
6412
+ for (let i = 0; i < fragment.length; ) {
6413
+ const c = fragment[i];
6414
+ if (c === '"') {
6415
+ const end = skipString(fragment, i);
6416
+ out += fragment.slice(i, end);
6417
+ i = end;
6418
+ } else if (c === ",") {
6419
+ const next = skipSpace(fragment, i + 1);
6420
+ if (fragment[next] !== "}" && fragment[next] !== "]") out += c;
6421
+ i++;
6422
+ } else if (fragment.startsWith("//", i) || fragment.startsWith("/*", i)) {
6423
+ i = skipSpace(fragment, i);
6424
+ } else {
6425
+ out += c;
6426
+ i++;
6427
+ }
6428
+ }
6429
+ return JSON.parse(out);
6430
+ }
6431
+ function resolution(value) {
6432
+ const first = Array.isArray(value) ? value[0] : null;
6433
+ if (typeof first !== "string") return null;
6434
+ const at = first.lastIndexOf("@");
6435
+ if (at <= 0) return null;
6436
+ return { name: first.slice(0, at), spec: first.slice(at + 1) };
6437
+ }
6438
+ function staleNestedEntries(text, want = () => null) {
6439
+ const packages = section(text, "packages");
6440
+ if (!packages) return [];
6441
+ const list = members(text, packages.value);
6442
+ const value = (m) => parseLoose(text.slice(m.value, m.end));
6443
+ const byKey = new Map(list.map((m) => [m.key, m]));
6444
+ const out = [];
6445
+ for (const m of list) {
6446
+ const tail = GENESIS_TAIL.exec(m.key);
6447
+ if (!tail || tail[1] === m.key) continue;
6448
+ const name = tail[1];
6449
+ const nested = resolution(value(m));
6450
+ if (!nested || nested.name !== name || !PLAIN_VERSION.test(nested.spec)) continue;
6451
+ const rootEntry = byKey.get(name);
6452
+ const rootRes = rootEntry ? resolution(value(rootEntry)) : null;
6453
+ const target = want(name) ?? (rootRes && PLAIN_VERSION.test(rootRes.spec) ? rootRes.spec : null);
6454
+ if (!rootEntry || !target || target === nested.spec) continue;
6455
+ const parent = m.key.slice(0, m.key.length - name.length - 1);
6456
+ const parentEntry = byKey.get(parent);
6457
+ const meta = parentEntry ? value(parentEntry)[2] : void 0;
6458
+ const declared = meta && typeof meta === "object" ? meta : {};
6459
+ const range = ["dependencies", "peerDependencies", "optionalDependencies"].map((s) => declared[s]?.[name]).find((r) => typeof r === "string");
6460
+ if (!range || satisfies(target, range) !== true) continue;
6461
+ out.push({ key: m.key, name, parent, version: nested.spec, root: target, range });
6462
+ }
6463
+ return out;
6464
+ }
6465
+ function readBunLock(dir) {
6466
+ const file = path20.join(dir, BUN_LOCK);
6467
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
6468
+ }
6469
+ function findLockfile(root) {
6470
+ let dir = path20.resolve(root);
6471
+ for (; ; ) {
6472
+ if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
6473
+ if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
6474
+ if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
6475
+ if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
6476
+ const parent = path20.dirname(dir);
6477
+ if (parent === dir) return null;
6478
+ dir = parent;
6479
+ }
6480
+ }
6225
6481
 
6226
6482
  // src/doctor/lock-files.ts
6483
+ function checkBunLock(ctx) {
6484
+ const found = findLockfile(ctx.root);
6485
+ if (found?.pm !== "bun") return;
6486
+ const text = readBunLock(found.dir);
6487
+ if (text === null) return;
6488
+ const file = path20.relative(ctx.root, path20.join(found.dir, BUN_LOCK)).split(path20.sep).join("/");
6489
+ let stale;
6490
+ try {
6491
+ stale = staleNestedEntries(text);
6492
+ } catch {
6493
+ return;
6494
+ }
6495
+ for (const s of stale) {
6496
+ ctx.report({
6497
+ rule: "lock-files",
6498
+ level: "warn",
6499
+ file,
6500
+ subject: s.key,
6501
+ message: `keeps a nested copy of ${s.name}@${s.version} under ${s.parent} beside the root's ${s.root}, which satisfies its ${s.range}: Bun keeps it across installs, so the app runs two copies (a provider from one is invisible to hooks from the other). Delete the "${s.key}" entry from ${file}'s packages, then reinstall (bun install); genesis upgrade does both`
6502
+ });
6503
+ }
6504
+ }
6227
6505
  async function checkLockFiles(ctx) {
6506
+ checkBunLock(ctx);
6228
6507
  if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6229
6508
  let lock;
6230
6509
  try {
@@ -6253,15 +6532,44 @@ async function checkLockFiles(ctx) {
6253
6532
  });
6254
6533
  }
6255
6534
  const local = localPackageNames(ctx.root);
6535
+ let home = null;
6536
+ try {
6537
+ home = databaseElsewhere(ctx.root);
6538
+ } catch {
6539
+ }
6540
+ const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
6541
+ if (home && elsewhere.length) {
6542
+ ctx.report({
6543
+ rule: "lock-files",
6544
+ level: "info",
6545
+ file: LOCK_FILE,
6546
+ subject: "supabase/",
6547
+ message: `lists ${elsewhere.length} file${elsewhere.length === 1 ? "" : "s"} under supabase/, but this app's database files live ${home.app ? `in ${home.app}` : "nowhere"} (genesis.config.json supabase): genesis upgrade leaves them alone, so delete those entries`
6548
+ });
6549
+ }
6256
6550
  for (const [rel, entry] of Object.entries(lock.files)) {
6551
+ if (home && isSupabasePath(rel)) continue;
6257
6552
  if (ownedKeyProblem(rel, entry.source, local)) continue;
6258
6553
  if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
6259
- let text;
6554
+ let file;
6260
6555
  try {
6261
- text = readApp(ctx.root, rel);
6556
+ file = appPath2(ctx.root, rel);
6262
6557
  } catch {
6263
6558
  continue;
6264
6559
  }
6560
+ let text;
6561
+ try {
6562
+ text = existsSync(file) ? readFileSync(file, "utf8") : null;
6563
+ } catch (err) {
6564
+ ctx.report({
6565
+ rule: "lock-files",
6566
+ level: "warn",
6567
+ file: rel,
6568
+ subject: rel,
6569
+ message: `is in ${LOCK_FILE} (from ${entry.source}) but can't be read (${err instanceof Error ? err.message : String(err)}), so genesis upgrade can't refresh it. Make it a file again, or remove its entry from ${LOCK_FILE}`
6570
+ });
6571
+ continue;
6572
+ }
6265
6573
  if (text === null) {
6266
6574
  if (entry.deleted) continue;
6267
6575
  ctx.report({
@@ -6286,7 +6594,59 @@ async function checkLockFiles(ctx) {
6286
6594
  });
6287
6595
  }
6288
6596
  }
6289
- var RATCHETED_BY_DEFAULT = ["deprecated-import"];
6597
+ function checkDatabaseHome(ctx) {
6598
+ const home = databaseElsewhere(ctx.root);
6599
+ if (!home) return;
6600
+ if (home.app && !home.hasSupabase) {
6601
+ ctx.report({
6602
+ rule: "database-elsewhere",
6603
+ level: "warn",
6604
+ file: "genesis.config.json",
6605
+ subject: home.app,
6606
+ message: `supabase.app is ${home.app}, which has no supabase folder; name the app that holds this app's database (its migrations, tests and Edge Functions)`
6607
+ });
6608
+ }
6609
+ if (existsSync(path20.join(ctx.root, "supabase"))) {
6610
+ ctx.report({
6611
+ rule: "database-elsewhere",
6612
+ level: "warn",
6613
+ file: "supabase",
6614
+ subject: "supabase/",
6615
+ message: `is here, but genesis.config.json says this app's database files live ${home.app ? `in ${home.app}/supabase` : "nowhere"}: genesis add, migrate and upgrade never plan it, so it is a second, unused copy. Delete it`
6616
+ });
6617
+ }
6618
+ }
6619
+ function checkEslintConfig(ctx) {
6620
+ const pkg = readPackageJson(ctx.root);
6621
+ const native = appPlatform(pkg) === "native" || (ctx.config.packs?.includes("native") ?? false);
6622
+ if (!native) return;
6623
+ const file = findEslintConfig(ctx.root);
6624
+ if (!file) return;
6625
+ let text;
6626
+ try {
6627
+ text = readFileSync(path20.join(ctx.root, file), "utf8");
6628
+ } catch {
6629
+ return;
6630
+ }
6631
+ if (!usesGenesisLint(text)) {
6632
+ ctx.report({
6633
+ rule: "genesis-eslint-config",
6634
+ level: "warn",
6635
+ file,
6636
+ subject: "@marktiderman/genesis-cli/eslint",
6637
+ message: `doesn't load Genesis's lint rules, so genesis upgrade can't bring new ones (React Native Testing Library 14's await rules today). Run genesis codemod genesis-cli-eslint-config, or add const { genesis } = require("@marktiderman/genesis-cli/eslint") (import { genesis } from \u2026 in an ES module) and ...genesis("native") last in the array the config exports, with ${TESTING_LIBRARY} in devDependencies`
6638
+ });
6639
+ } else if (!hasTestingLibrary(pkg)) {
6640
+ ctx.report({
6641
+ rule: "genesis-eslint-config",
6642
+ level: "warn",
6643
+ file: "package.json",
6644
+ subject: TESTING_LIBRARY,
6645
+ message: `${file} loads Genesis's native lint rules, which need ${TESTING_LIBRARY}: add it to devDependencies (pnpm add -D ${TESTING_LIBRARY}), or the lint can't load its config`
6646
+ });
6647
+ }
6648
+ }
6649
+ var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
6290
6650
  async function runDoctor(options = {}) {
6291
6651
  const root = path20.resolve(options.root ?? process.cwd());
6292
6652
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
@@ -6388,6 +6748,8 @@ function builtinChecks(config, options = {}) {
6388
6748
  { name: "agent-guide", check: checkAgentGuide },
6389
6749
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6390
6750
  { name: "lock-files", check: checkLockFiles },
6751
+ { name: "database-elsewhere", check: checkDatabaseHome },
6752
+ { name: "eslint-config", check: checkEslintConfig },
6391
6753
  ...(config.packs ?? []).map((p) => packs[p]),
6392
6754
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6393
6755
  ];