@marktiderman/genesis-cli 1.19.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.
package/dist/doctor.d.ts CHANGED
@@ -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", "database-elsewhere"];
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 resolve16 = (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
- resolve16(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()) resolve16(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();
@@ -1143,7 +1143,7 @@ function globToRegExp(glob) {
1143
1143
  }
1144
1144
  function globMatcher(globs) {
1145
1145
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1146
- return (path39) => res.some((re) => re.test(path39));
1146
+ return (path43) => res.some((re) => re.test(path43));
1147
1147
  }
1148
1148
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1149
1149
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -2359,8 +2359,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
2359
2359
  } catch {
2360
2360
  continue;
2361
2361
  }
2362
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2363
- const spec = json[section]?.[name];
2362
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2363
+ const spec = json[section2]?.[name];
2364
2364
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2365
2365
  const parsed = v && parseVersion(v);
2366
2366
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -2513,7 +2513,9 @@ var BUILTIN_RULES = [
2513
2513
  // genesis.lock.json against the files (lock-files.ts)
2514
2514
  "lock-files",
2515
2515
  // an app whose database files live in another app (database.ts)
2516
- "database-elsewhere"
2516
+ "database-elsewhere",
2517
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2518
+ "genesis-eslint-config"
2517
2519
  ];
2518
2520
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2519
2521
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -5568,6 +5570,31 @@ function readsPracticeId(text) {
5568
5570
  var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
5569
5571
  var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
5570
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
+
5571
5598
  // src/upgrade/codemods.ts
5572
5599
  var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
5573
5600
  var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -6348,9 +6375,179 @@ function blockOfSource(source, manifests) {
6348
6375
  }
6349
6376
  return null;
6350
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
+ }
6351
6525
 
6352
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
+ }
6353
6549
  async function checkLockFiles(ctx) {
6550
+ checkBunLock(ctx);
6354
6551
  if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6355
6552
  let lock;
6356
6553
  try {
@@ -6463,7 +6660,37 @@ function checkDatabaseHome(ctx) {
6463
6660
  });
6464
6661
  }
6465
6662
  }
6466
- var RATCHETED_BY_DEFAULT = ["deprecated-import"];
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"];
6467
6694
  async function runDoctor(options = {}) {
6468
6695
  const root = path20.resolve(options.root ?? process.cwd());
6469
6696
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
@@ -6566,6 +6793,7 @@ function builtinChecks(config, options = {}) {
6566
6793
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6567
6794
  { name: "lock-files", check: checkLockFiles },
6568
6795
  { name: "database-elsewhere", check: checkDatabaseHome },
6796
+ { name: "eslint-config", check: checkEslintConfig },
6569
6797
  ...(config.packs ?? []).map((p) => packs[p]),
6570
6798
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6571
6799
  ];