@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
@@ -391,12 +391,25 @@ interface GenesisPrivacy {
391
391
  /** `NSPrivacyTracking`. Default false; true needs `NSPrivacyTrackingDomains` in app.config. */
392
392
  tracking?: boolean;
393
393
  }
394
+ /**
395
+ * The top-level `supabase` setting: where this app's database files (migrations, pgTAP tests,
396
+ * Edge Functions, config.toml) live. Left out (or `true`), they are this app's own `supabase/`.
397
+ * `false`: this app has none. `{ app }`: another Genesis app's folder, relative to this one
398
+ * (`"../app"`), whose `supabase/` holds them; a phone app beside a web app shares its database.
399
+ * Either way `genesis add`, `migrate`, `upgrade` and `init` never write or plan Supabase files
400
+ * here, and the doctor's supabase pack doesn't run.
401
+ */
402
+ type GenesisSupabase = false | {
403
+ app: string;
404
+ };
394
405
  /** genesis.config.json, parsed, with its shared blocks validated. */
395
406
  interface GenesisConfigFile {
396
407
  /** The whole parsed file, for blocks other readers own (`doctor`, `features`). */
397
408
  raw: Record<string, unknown>;
398
409
  links?: GenesisLinks;
399
410
  privacy?: GenesisPrivacy;
411
+ /** Set only when the database files live elsewhere (see {@link GenesisSupabase}). */
412
+ supabase?: GenesisSupabase;
400
413
  }
401
414
  interface LoadedConfig {
402
415
  config: DoctorConfig;
@@ -423,4 +436,4 @@ declare function validateLinks(raw: unknown, source?: string): GenesisLinks;
423
436
  /** Check the shape, so a typo fails loudly instead of silently disabling a check. */
424
437
  declare function validateConfig(raw: unknown, source?: string): DoctorConfig;
425
438
 
426
- export { type AllowEntry as A, loadConfig as B, type CompanionPackage as C, type DoctorConfig as D, validateConfig as E, type Finding as F, type GenesisDataUse as G, type Level as L, type NativePackConfig as N, PRIVACY_DATA_TYPES as P, type RuleSetting as R, type SourceFile as S, type GenesisPrivacy as a, type GenesisLinks as b, GenesisConfigError as c, PRIVACY_PURPOSES as d, validatePrivacy as e, DoctorConfigError as f, type DoctorContext as g, type DoctorPlugin as h, type DoctorResult as i, type GenesisConfigFile as j, type GenesisFacts as k, type PatternRule as l, type PreferRule as m, type DeclaringPackage as n, type PackageDeclaration as o, privacyDataType as p, type ContractsConfig as q, readGenesisConfig as r, type DoctorPack as s, type FindingInput as t, type PackageRuleSetting as u, validateLinks as v, type PackagesPackConfig as w, type PluginSpec as x, type PrimitiveEntry as y, type SupabasePackConfig as z };
439
+ export { type AllowEntry as A, type SupabasePackConfig as B, type CompanionPackage as C, type DoctorConfig as D, loadConfig as E, type Finding as F, type GenesisDataUse as G, validateConfig as H, type Level as L, type NativePackConfig as N, PRIVACY_DATA_TYPES as P, type RuleSetting as R, type SourceFile as S, type GenesisPrivacy as a, type GenesisLinks as b, GenesisConfigError as c, PRIVACY_PURPOSES as d, validatePrivacy as e, DoctorConfigError as f, type DoctorContext as g, type DoctorPlugin as h, type DoctorResult as i, type GenesisConfigFile as j, type GenesisSupabase as k, type GenesisFacts as l, type PatternRule as m, type PreferRule as n, type DeclaringPackage as o, privacyDataType as p, type PackageDeclaration as q, readGenesisConfig as r, type ContractsConfig as s, type DoctorPack as t, type FindingInput as u, validateLinks as v, type PackageRuleSetting as w, type PackagesPackConfig as x, type PluginSpec as y, type PrimitiveEntry as z };
package/dist/doctor.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DoctorConfig, k as GenesisFacts, l as PatternRule, h as DoctorPlugin, S as SourceFile, g as DoctorContext, m as PreferRule, n as DeclaringPackage, o as PackageDeclaration, i as DoctorResult, F as Finding } from './config-1jP8eCZy.js';
2
- export { A as AllowEntry, C as CompanionPackage, q as ContractsConfig, f as DoctorConfigError, s as DoctorPack, t as FindingInput, c as GenesisConfigError, j as GenesisConfigFile, b as GenesisLinks, L as Level, N as NativePackConfig, u as PackageRuleSetting, w as PackagesPackConfig, x as PluginSpec, y as PrimitiveEntry, R as RuleSetting, z as SupabasePackConfig, B as loadConfig, r as readGenesisConfig, E as validateConfig, v as validateLinks } from './config-1jP8eCZy.js';
1
+ import { D as DoctorConfig, l as GenesisFacts, m as PatternRule, h as DoctorPlugin, S as SourceFile, g as DoctorContext, n as PreferRule, o as DeclaringPackage, q as PackageDeclaration, i as DoctorResult, F as Finding } from './config-Dj_f9T7J.js';
2
+ export { A as AllowEntry, C as CompanionPackage, s as ContractsConfig, f as DoctorConfigError, t as DoctorPack, u as FindingInput, c as GenesisConfigError, j as GenesisConfigFile, b as GenesisLinks, k as GenesisSupabase, L as Level, N as NativePackConfig, w as PackageRuleSetting, x as PackagesPackConfig, y as PluginSpec, z as PrimitiveEntry, R as RuleSetting, B as SupabasePackConfig, E as loadConfig, r as readGenesisConfig, H as validateConfig, v as validateLinks } from './config-Dj_f9T7J.js';
3
3
  import '@marktiderman/genesis-features';
4
4
 
5
5
  /** The installed folder of `name`, looking in node_modules from `from` upward (works with hoisting and pnpm). */
@@ -27,7 +27,7 @@ declare function parseRulesMarkdown(markdown: string): PatternRule[];
27
27
  declare function defineDoctorPlugin(plugin: DoctorPlugin): DoctorPlugin;
28
28
 
29
29
  /** Ids of the built-in rules, for `rules` overrides and `allow` entries. */
30
- declare const BUILTIN_RULES: readonly ["local-primitives", "starter-leftover", "forbidden-import", "raw-tag", "palette-color", "arbitrary-color", "raw-color", "undefined-token", "shadowed-export", "version-skew", "duplicate-genesis-package", "peer-range-mismatch", "hand-rolled-sub-nav", "local-genesis-copy", "resource-workspace", "page-layout", "iso-date-slice", "resource-view-tree", "studio-server-auth-import", "removed-scope-name", "scope-practice-id", "deprecated-import", "beta-import", "native-raw-primitive", "native-literal-color", "native-custom-header", "native-screen-layout", "store-readiness", "eas-placeholder", "migration-grants", "migration-rls", "migration-definer-search-path", "migration-edited", "migration-testing-kit", "migration-view-rls", "package-app-import", "package-undeclared-dependency", "package-migration-test", "package-migration-number", "package-migration-edited", "package-unregistered", "package-unversioned-change", "package-export-missing", "package-block-invalid", "package-untagged-tests", "package-doctor-declaration", "overlay-unmarked", "overlay-invalid", "overlay-age", "overlay-version", "overlay-behind", "package-rules-invalid", "package-rule-override", "ratchet-skipped", "allow-grew", "rules-weakened", "agent-guide-stale", "contracts-stale", "lock-files"];
30
+ declare const BUILTIN_RULES: readonly ["local-primitives", "starter-leftover", "forbidden-import", "raw-tag", "palette-color", "arbitrary-color", "raw-color", "undefined-token", "shadowed-export", "version-skew", "duplicate-genesis-package", "peer-range-mismatch", "hand-rolled-sub-nav", "local-genesis-copy", "resource-workspace", "page-layout", "iso-date-slice", "resource-view-tree", "studio-server-auth-import", "removed-scope-name", "scope-practice-id", "deprecated-import", "beta-import", "native-raw-primitive", "native-literal-color", "native-custom-header", "native-screen-layout", "store-readiness", "eas-placeholder", "migration-grants", "migration-rls", "migration-definer-search-path", "migration-edited", "migration-testing-kit", "migration-view-rls", "package-app-import", "package-undeclared-dependency", "package-migration-test", "package-migration-number", "package-migration-edited", "package-unregistered", "package-unversioned-change", "package-export-missing", "package-block-invalid", "package-untagged-tests", "package-doctor-declaration", "overlay-unmarked", "overlay-invalid", "overlay-age", "overlay-version", "overlay-behind", "package-rules-invalid", "package-rule-override", "ratchet-skipped", "allow-grew", "rules-weakened", "agent-guide-stale", "contracts-stale", "lock-files", "database-elsewhere", "genesis-eslint-config"];
31
31
 
32
32
  /**
33
33
  * Minimal globs for config: `*` matches within a folder, `**` across folders,
package/dist/doctor.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 resolve15 = (relation, depth) => {
458
+ const resolve17 = (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
- resolve15(source, depth + 1);
465
+ resolve17(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()) resolve15(relation, 0);
488
+ for (const relation of relations.values()) resolve17(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 (path36) => res.some((re) => re.test(path36));
1146
+ return (path43) => res.some((re) => re.test(path43));
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";
@@ -2325,8 +2359,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
2325
2359
  } catch {
2326
2360
  continue;
2327
2361
  }
2328
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2329
- const spec = json[section]?.[name];
2362
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2363
+ const spec = json[section2]?.[name];
2330
2364
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2331
2365
  const parsed = v && parseVersion(v);
2332
2366
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -2477,7 +2511,11 @@ var BUILTIN_RULES = [
2477
2511
  // supabase pack: contracts (contracts.ts)
2478
2512
  "contracts-stale",
2479
2513
  // genesis.lock.json against the files (lock-files.ts)
2480
- "lock-files"
2514
+ "lock-files",
2515
+ // an app whose database files live in another app (database.ts)
2516
+ "database-elsewhere",
2517
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2518
+ "genesis-eslint-config"
2481
2519
  ];
2482
2520
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2483
2521
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -2700,7 +2738,7 @@ function privacyApisFor(dependencies2) {
2700
2738
  var EAS_PLACEHOLDERS = {
2701
2739
  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)",
2702
2740
  REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
2703
- 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",
2741
+ 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)",
2704
2742
  REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
2705
2743
  };
2706
2744
  function placeholderKey(line, placeholder) {
@@ -3609,11 +3647,21 @@ async function blocksOfInstalled(dir, warnings = [], options = {}) {
3609
3647
  const out = [];
3610
3648
  for (const id of [...ids].sort()) {
3611
3649
  const fromJson = raw[id] ?? {};
3612
- const manifest = tryParse(() => parseManifest(pkg.name, id, { ...fromJson, ...declared[id] }, pkg.version, options), warnings);
3650
+ const merged = { ...fromJson, ...declared[id] };
3651
+ if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
3652
+ const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
3613
3653
  if (manifest) out.push(manifest);
3614
3654
  }
3615
3655
  return out;
3616
3656
  }
3657
+ function withProvides(declared, json) {
3658
+ if (!Array.isArray(declared)) return declared;
3659
+ const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
3660
+ return declared.map((m) => {
3661
+ const same = json.find((j) => fileOf(j) === fileOf(m));
3662
+ return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
3663
+ });
3664
+ }
3617
3665
  async function allBlocks(root, warnings = []) {
3618
3666
  const out = [];
3619
3667
  for (const local of localPackages(root)) {
@@ -4475,6 +4523,45 @@ function checkPackagesPack(ctx) {
4475
4523
  if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
4476
4524
  }
4477
4525
  }
4526
+ var LOCK_FILE = "genesis.lock.json";
4527
+ function emptyLock() {
4528
+ return { version: 1, blocks: {}, files: {} };
4529
+ }
4530
+ function readLock(root) {
4531
+ const file = path20.join(root, LOCK_FILE);
4532
+ if (!existsSync(file)) return emptyLock();
4533
+ const raw = JSON.parse(readFileSync(file, "utf8"));
4534
+ if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
4535
+ return {
4536
+ version: 1,
4537
+ ...raw.substitutions ? { substitutions: raw.substitutions } : {},
4538
+ blocks: raw.blocks ?? {},
4539
+ files: raw.files ?? {},
4540
+ ...raw.migrations ? { migrations: raw.migrations } : {}
4541
+ };
4542
+ }
4543
+ function parseSource(source) {
4544
+ const at = source.indexOf(":");
4545
+ if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
4546
+ return { package: source.slice(0, at), path: source.slice(at + 1) };
4547
+ }
4548
+
4549
+ // src/blocks/database.ts
4550
+ function databaseElsewhere(root) {
4551
+ const setting = readGenesisConfig(root)?.supabase;
4552
+ if (setting === void 0) return null;
4553
+ if (setting === false) return { app: null, dir: null, hasSupabase: false };
4554
+ const resolved = path20.resolve(root, setting.app);
4555
+ const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
4556
+ const dir = real2(resolved);
4557
+ 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`);
4558
+ return { app: setting.app, dir, hasSupabase: existsSync(path20.join(dir, "supabase")) };
4559
+ }
4560
+ function isSupabasePath(rel) {
4561
+ return rel === "supabase" || rel.startsWith("supabase/");
4562
+ }
4563
+
4564
+ // src/doctor/supabase.ts
4478
4565
  var DEFAULT_MIGRATIONS = "supabase/migrations";
4479
4566
  var DEFAULT_BASE = "origin/main";
4480
4567
  var DEFAULT_EXPOSED = ["public"];
@@ -4655,6 +4742,7 @@ function gitView(root, dir, base) {
4655
4742
  return { touched: touched2, edited };
4656
4743
  }
4657
4744
  function checkSupabasePack(ctx) {
4745
+ if (databaseElsewhere(ctx.root)) return;
4658
4746
  const settings = ctx.config.supabase ?? {};
4659
4747
  const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
4660
4748
  const abs = path20.join(ctx.root, dir);
@@ -5482,6 +5570,31 @@ function readsPracticeId(text) {
5482
5570
  var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
5483
5571
  var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
5484
5572
 
5573
+ // src/upgrade/eslint-config.ts
5574
+ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
5575
+ var TESTING_LIBRARY = "eslint-plugin-testing-library";
5576
+ var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
5577
+ function findEslintConfig(root) {
5578
+ return FLAT_CONFIG_FILES.find((name) => existsSync(path20.join(root, name))) ?? null;
5579
+ }
5580
+ function readPackageJson(root) {
5581
+ try {
5582
+ return JSON.parse(readFileSync(path20.join(root, "package.json"), "utf8"));
5583
+ } catch {
5584
+ return null;
5585
+ }
5586
+ }
5587
+ var declares = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name]);
5588
+ function appPlatform(pkg) {
5589
+ return declares(pkg, "expo") || declares(pkg, "react-native") ? "native" : "web";
5590
+ }
5591
+ function hasTestingLibrary(pkg) {
5592
+ return declares(pkg, TESTING_LIBRARY);
5593
+ }
5594
+ function usesGenesisLint(text) {
5595
+ return text.includes(ESLINT_EXPORT);
5596
+ }
5597
+
5485
5598
  // src/upgrade/codemods.ts
5486
5599
  var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
5487
5600
  var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -6112,28 +6225,6 @@ function checkAgentGuide(ctx) {
6112
6225
  ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
6113
6226
  }
6114
6227
  }
6115
- var LOCK_FILE = "genesis.lock.json";
6116
- function emptyLock() {
6117
- return { version: 1, blocks: {}, files: {} };
6118
- }
6119
- function readLock(root) {
6120
- const file = path20.join(root, LOCK_FILE);
6121
- if (!existsSync(file)) return emptyLock();
6122
- const raw = JSON.parse(readFileSync(file, "utf8"));
6123
- if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
6124
- return {
6125
- version: 1,
6126
- ...raw.substitutions ? { substitutions: raw.substitutions } : {},
6127
- blocks: raw.blocks ?? {},
6128
- files: raw.files ?? {},
6129
- ...raw.migrations ? { migrations: raw.migrations } : {}
6130
- };
6131
- }
6132
- function parseSource(source) {
6133
- const at = source.indexOf(":");
6134
- if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
6135
- return { package: source.slice(0, at), path: source.slice(at + 1) };
6136
- }
6137
6228
  var CLI = "@marktiderman/genesis-cli";
6138
6229
  function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
6139
6230
  let parsed;
@@ -6176,8 +6267,25 @@ function featuresBody(text) {
6176
6267
  const m = /\bfeatures:\s*\{/.exec(text);
6177
6268
  if (!m) return null;
6178
6269
  const start = m.index + m[0].length;
6179
- const end = text.indexOf("}", start);
6180
- return end < 0 ? null : { start, body: text.slice(start, end) };
6270
+ let depth = 1;
6271
+ for (let i = start; i < text.length; i++) {
6272
+ const c = text[i];
6273
+ if (c === "/" && text[i + 1] === "/") {
6274
+ const nl = text.indexOf("\n", i);
6275
+ if (nl < 0) return null;
6276
+ i = nl;
6277
+ } else if (c === "/" && text[i + 1] === "*") {
6278
+ const close = text.indexOf("*/", i + 2);
6279
+ if (close < 0) return null;
6280
+ i = close + 1;
6281
+ } else if (c === '"' || c === "'" || c === "`") {
6282
+ let j = i + 1;
6283
+ while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
6284
+ i = j;
6285
+ } else if (c === "{") depth++;
6286
+ else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
6287
+ }
6288
+ return null;
6181
6289
  }
6182
6290
  function parseStarterFeatures(text) {
6183
6291
  const found = featuresBody(text);
@@ -6199,6 +6307,7 @@ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
6199
6307
  const starter = raw?.starter;
6200
6308
  if (starter === void 0) return null;
6201
6309
  const blocks = starter?.blocks;
6310
+ if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
6202
6311
  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`);
6203
6312
  const out = {};
6204
6313
  for (const [name, ids] of Object.entries(blocks)) {
@@ -6266,9 +6375,179 @@ function blockOfSource(source, manifests) {
6266
6375
  }
6267
6376
  return null;
6268
6377
  }
6378
+ var BUN_LOCK = "bun.lock";
6379
+ var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
6380
+ var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
6381
+ function skipSpace(text, i) {
6382
+ for (; ; ) {
6383
+ while (i < text.length && /\s/.test(text[i])) i++;
6384
+ if (text.startsWith("//", i)) {
6385
+ const nl = text.indexOf("\n", i);
6386
+ i = nl === -1 ? text.length : nl + 1;
6387
+ } else if (text.startsWith("/*", i)) {
6388
+ const close = text.indexOf("*/", i + 2);
6389
+ i = close === -1 ? text.length : close + 2;
6390
+ } else return i;
6391
+ }
6392
+ }
6393
+ function skipString(text, i) {
6394
+ for (let j = i + 1; j < text.length; j++) {
6395
+ if (text[j] === "\\") j++;
6396
+ else if (text[j] === '"') return j + 1;
6397
+ }
6398
+ throw new Error("an unterminated string");
6399
+ }
6400
+ function skipValue(text, i) {
6401
+ const c = text[i];
6402
+ if (c === '"') return skipString(text, i);
6403
+ if (c === "{" || c === "[") {
6404
+ let depth = 0;
6405
+ for (let j2 = i; j2 < text.length; ) {
6406
+ const d = text[j2];
6407
+ if (d === '"') {
6408
+ j2 = skipString(text, j2);
6409
+ continue;
6410
+ }
6411
+ if (text.startsWith("//", j2) || text.startsWith("/*", j2)) {
6412
+ j2 = skipSpace(text, j2);
6413
+ continue;
6414
+ }
6415
+ if (d === "{" || d === "[") depth++;
6416
+ else if (d === "}" || d === "]") {
6417
+ depth--;
6418
+ if (depth === 0) return j2 + 1;
6419
+ }
6420
+ j2++;
6421
+ }
6422
+ throw new Error("an unclosed object or array");
6423
+ }
6424
+ let j = i;
6425
+ while (j < text.length && !/[\s,}\]]/.test(text[j])) j++;
6426
+ if (j === i) throw new Error(`an unexpected ${JSON.stringify(c ?? "end")} at ${i}`);
6427
+ return j;
6428
+ }
6429
+ function members(text, open) {
6430
+ const out = [];
6431
+ let i = skipSpace(text, open + 1);
6432
+ while (text[i] !== "}") {
6433
+ if (text[i] !== '"') throw new Error(`a key expected at ${i}`);
6434
+ const keyEnd = skipString(text, i);
6435
+ const key2 = JSON.parse(text.slice(i, keyEnd));
6436
+ let j = skipSpace(text, keyEnd);
6437
+ if (text[j] !== ":") throw new Error(`":" expected at ${j}`);
6438
+ const value = skipSpace(text, j + 1);
6439
+ const end = skipValue(text, value);
6440
+ out.push({ key: key2, start: i, end, value });
6441
+ j = skipSpace(text, end);
6442
+ if (text[j] === ",") j = skipSpace(text, j + 1);
6443
+ i = j;
6444
+ if (i >= text.length) throw new Error("an unclosed object");
6445
+ }
6446
+ return out;
6447
+ }
6448
+ function section(text, name) {
6449
+ const open = skipSpace(text, 0);
6450
+ if (text[open] !== "{") throw new Error("not an object");
6451
+ const m = members(text, open).find((x) => x.key === name);
6452
+ return m && text[m.value] === "{" ? m : null;
6453
+ }
6454
+ function parseLoose(fragment) {
6455
+ let out = "";
6456
+ for (let i = 0; i < fragment.length; ) {
6457
+ const c = fragment[i];
6458
+ if (c === '"') {
6459
+ const end = skipString(fragment, i);
6460
+ out += fragment.slice(i, end);
6461
+ i = end;
6462
+ } else if (c === ",") {
6463
+ const next = skipSpace(fragment, i + 1);
6464
+ if (fragment[next] !== "}" && fragment[next] !== "]") out += c;
6465
+ i++;
6466
+ } else if (fragment.startsWith("//", i) || fragment.startsWith("/*", i)) {
6467
+ i = skipSpace(fragment, i);
6468
+ } else {
6469
+ out += c;
6470
+ i++;
6471
+ }
6472
+ }
6473
+ return JSON.parse(out);
6474
+ }
6475
+ function resolution(value) {
6476
+ const first = Array.isArray(value) ? value[0] : null;
6477
+ if (typeof first !== "string") return null;
6478
+ const at = first.lastIndexOf("@");
6479
+ if (at <= 0) return null;
6480
+ return { name: first.slice(0, at), spec: first.slice(at + 1) };
6481
+ }
6482
+ function staleNestedEntries(text, want = () => null) {
6483
+ const packages = section(text, "packages");
6484
+ if (!packages) return [];
6485
+ const list = members(text, packages.value);
6486
+ const value = (m) => parseLoose(text.slice(m.value, m.end));
6487
+ const byKey = new Map(list.map((m) => [m.key, m]));
6488
+ const out = [];
6489
+ for (const m of list) {
6490
+ const tail = GENESIS_TAIL.exec(m.key);
6491
+ if (!tail || tail[1] === m.key) continue;
6492
+ const name = tail[1];
6493
+ const nested = resolution(value(m));
6494
+ if (!nested || nested.name !== name || !PLAIN_VERSION.test(nested.spec)) continue;
6495
+ const rootEntry = byKey.get(name);
6496
+ const rootRes = rootEntry ? resolution(value(rootEntry)) : null;
6497
+ const target = want(name) ?? (rootRes && PLAIN_VERSION.test(rootRes.spec) ? rootRes.spec : null);
6498
+ if (!rootEntry || !target || target === nested.spec) continue;
6499
+ const parent = m.key.slice(0, m.key.length - name.length - 1);
6500
+ const parentEntry = byKey.get(parent);
6501
+ const meta = parentEntry ? value(parentEntry)[2] : void 0;
6502
+ const declared = meta && typeof meta === "object" ? meta : {};
6503
+ const range = ["dependencies", "peerDependencies", "optionalDependencies"].map((s) => declared[s]?.[name]).find((r) => typeof r === "string");
6504
+ if (!range || satisfies(target, range) !== true) continue;
6505
+ out.push({ key: m.key, name, parent, version: nested.spec, root: target, range });
6506
+ }
6507
+ return out;
6508
+ }
6509
+ function readBunLock(dir) {
6510
+ const file = path20.join(dir, BUN_LOCK);
6511
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
6512
+ }
6513
+ function findLockfile(root) {
6514
+ let dir = path20.resolve(root);
6515
+ for (; ; ) {
6516
+ if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
6517
+ if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
6518
+ if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
6519
+ if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
6520
+ const parent = path20.dirname(dir);
6521
+ if (parent === dir) return null;
6522
+ dir = parent;
6523
+ }
6524
+ }
6269
6525
 
6270
6526
  // src/doctor/lock-files.ts
6527
+ function checkBunLock(ctx) {
6528
+ const found = findLockfile(ctx.root);
6529
+ if (found?.pm !== "bun") return;
6530
+ const text = readBunLock(found.dir);
6531
+ if (text === null) return;
6532
+ const file = path20.relative(ctx.root, path20.join(found.dir, BUN_LOCK)).split(path20.sep).join("/");
6533
+ let stale;
6534
+ try {
6535
+ stale = staleNestedEntries(text);
6536
+ } catch {
6537
+ return;
6538
+ }
6539
+ for (const s of stale) {
6540
+ ctx.report({
6541
+ rule: "lock-files",
6542
+ level: "warn",
6543
+ file,
6544
+ subject: s.key,
6545
+ 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`
6546
+ });
6547
+ }
6548
+ }
6271
6549
  async function checkLockFiles(ctx) {
6550
+ checkBunLock(ctx);
6272
6551
  if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6273
6552
  let lock;
6274
6553
  try {
@@ -6297,15 +6576,44 @@ async function checkLockFiles(ctx) {
6297
6576
  });
6298
6577
  }
6299
6578
  const local = localPackageNames(ctx.root);
6579
+ let home = null;
6580
+ try {
6581
+ home = databaseElsewhere(ctx.root);
6582
+ } catch {
6583
+ }
6584
+ const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
6585
+ if (home && elsewhere.length) {
6586
+ ctx.report({
6587
+ rule: "lock-files",
6588
+ level: "info",
6589
+ file: LOCK_FILE,
6590
+ subject: "supabase/",
6591
+ 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`
6592
+ });
6593
+ }
6300
6594
  for (const [rel, entry] of Object.entries(lock.files)) {
6595
+ if (home && isSupabasePath(rel)) continue;
6301
6596
  if (ownedKeyProblem(rel, entry.source, local)) continue;
6302
6597
  if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
6303
- let text;
6598
+ let file;
6304
6599
  try {
6305
- text = readApp(ctx.root, rel);
6600
+ file = appPath2(ctx.root, rel);
6306
6601
  } catch {
6307
6602
  continue;
6308
6603
  }
6604
+ let text;
6605
+ try {
6606
+ text = existsSync(file) ? readFileSync(file, "utf8") : null;
6607
+ } catch (err) {
6608
+ ctx.report({
6609
+ rule: "lock-files",
6610
+ level: "warn",
6611
+ file: rel,
6612
+ subject: rel,
6613
+ 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}`
6614
+ });
6615
+ continue;
6616
+ }
6309
6617
  if (text === null) {
6310
6618
  if (entry.deleted) continue;
6311
6619
  ctx.report({
@@ -6330,7 +6638,59 @@ async function checkLockFiles(ctx) {
6330
6638
  });
6331
6639
  }
6332
6640
  }
6333
- var RATCHETED_BY_DEFAULT = ["deprecated-import"];
6641
+ function checkDatabaseHome(ctx) {
6642
+ const home = databaseElsewhere(ctx.root);
6643
+ if (!home) return;
6644
+ if (home.app && !home.hasSupabase) {
6645
+ ctx.report({
6646
+ rule: "database-elsewhere",
6647
+ level: "warn",
6648
+ file: "genesis.config.json",
6649
+ subject: home.app,
6650
+ 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)`
6651
+ });
6652
+ }
6653
+ if (existsSync(path20.join(ctx.root, "supabase"))) {
6654
+ ctx.report({
6655
+ rule: "database-elsewhere",
6656
+ level: "warn",
6657
+ file: "supabase",
6658
+ subject: "supabase/",
6659
+ 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`
6660
+ });
6661
+ }
6662
+ }
6663
+ function checkEslintConfig(ctx) {
6664
+ const pkg = readPackageJson(ctx.root);
6665
+ const native = appPlatform(pkg) === "native" || (ctx.config.packs?.includes("native") ?? false);
6666
+ if (!native) return;
6667
+ const file = findEslintConfig(ctx.root);
6668
+ if (!file) return;
6669
+ let text;
6670
+ try {
6671
+ text = readFileSync(path20.join(ctx.root, file), "utf8");
6672
+ } catch {
6673
+ return;
6674
+ }
6675
+ if (!usesGenesisLint(text)) {
6676
+ ctx.report({
6677
+ rule: "genesis-eslint-config",
6678
+ level: "warn",
6679
+ file,
6680
+ subject: "@marktiderman/genesis-cli/eslint",
6681
+ 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`
6682
+ });
6683
+ } else if (!hasTestingLibrary(pkg)) {
6684
+ ctx.report({
6685
+ rule: "genesis-eslint-config",
6686
+ level: "warn",
6687
+ file: "package.json",
6688
+ subject: TESTING_LIBRARY,
6689
+ 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`
6690
+ });
6691
+ }
6692
+ }
6693
+ var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
6334
6694
  async function runDoctor(options = {}) {
6335
6695
  const root = path20.resolve(options.root ?? process.cwd());
6336
6696
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
@@ -6432,6 +6792,8 @@ function builtinChecks(config, options = {}) {
6432
6792
  { name: "agent-guide", check: checkAgentGuide },
6433
6793
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6434
6794
  { name: "lock-files", check: checkLockFiles },
6795
+ { name: "database-elsewhere", check: checkDatabaseHome },
6796
+ { name: "eslint-config", check: checkEslintConfig },
6435
6797
  ...(config.packs ?? []).map((p) => packs[p]),
6436
6798
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6437
6799
  ];