@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.
@@ -208,6 +208,15 @@ sign-in, the tabs, Settings and account deletion. Supabase is the fake in
208
208
  native modules use jest-expo's mocks or their library's own. A test fails when the app reports an
209
209
  error (`[push]`, `[updates]`, `[observability]`) or React warns about act(); see `reports.ts`.
210
210
  Add a screen's test there; tests that only read files stay in vitest, outside that folder.
211
+ In React Native Testing Library 14, `render`, `renderHook`, `fireEvent`, `act`, `rerender` and
212
+ `unmount` return promises: always `await` them, or the test reads a stale screen and React logs
213
+ "overlapping act() calls". `pnpm lint` catches a missed one in test files: `eslint.config.js`
214
+ spreads `genesis("native")` from `@marktiderman/genesis-cli/eslint`, which brings testing-library's
215
+ `await-async-events` and a `no-restricted-syntax` rule for the render calls, `act`, `rerender` and
216
+ `unmount` (it needs `eslint-plugin-testing-library` in devDependencies). The rules ship with the
217
+ CLI, so `genesis upgrade` brings new and changed ones without an edit here; a render helper of your
218
+ own goes in `genesis("native", { renders: ["renderWithStore"] })`. See the
219
+ [genesis-cli README](../../packages/genesis-cli/README.md#lint-rules).
211
220
 
212
221
  Gestures and animations run in these tests as they are written, on Gesture Handler's mocks
213
222
  (`react-native-gesture-handler/jestSetup.js`, in `jest.config.js`) and Reanimated's test mode
@@ -1,5 +1,12 @@
1
1
  // https://docs.expo.dev/guides/using-eslint/
2
2
  const { defineConfig } = require("eslint/config");
3
3
  const expoConfig = require("eslint-config-expo/flat");
4
+ // Genesis's lint rules, shipped with the CLI so `genesis upgrade` brings new ones (React Native
5
+ // Testing Library 14's await rules today; they need eslint-plugin-testing-library).
6
+ const { genesis } = require("@marktiderman/genesis-cli/eslint");
4
7
 
5
- module.exports = defineConfig([expoConfig, { ignores: ["dist/*", ".expo/*", "supabase/functions/**"] }]);
8
+ module.exports = defineConfig([
9
+ expoConfig,
10
+ { ignores: ["dist/*", ".expo/*", "supabase/functions/**"] },
11
+ ...genesis("native"),
12
+ ]);
@@ -0,0 +1 @@
1
+ /// <reference types="nativewind/types" />
@@ -94,6 +94,7 @@
94
94
  "babel-plugin-react-compiler": "^1.0.0",
95
95
  "eslint": "^9.0.0",
96
96
  "eslint-config-expo": "~58.0.4",
97
+ "eslint-plugin-testing-library": "^7.16.2",
97
98
  "jest": "~30.5.2",
98
99
  "jest-expo": "~58.0.12",
99
100
  "tailwindcss": "^3.4.17",
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 resolve17 = (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
- resolve17(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()) resolve17(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();
@@ -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 (path40) => res.some((re) => re.test(path40));
1146
+ return (path44) => res.some((re) => re.test(path44));
1147
1147
  }
1148
1148
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1149
1149
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -2356,8 +2356,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
2356
2356
  } catch {
2357
2357
  continue;
2358
2358
  }
2359
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2360
- const spec = json[section]?.[name];
2359
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2360
+ const spec = json[section2]?.[name];
2361
2361
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2362
2362
  const parsed = v && parseVersion(v);
2363
2363
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -2510,7 +2510,9 @@ var BUILTIN_RULES = [
2510
2510
  // genesis.lock.json against the files (lock-files.ts)
2511
2511
  "lock-files",
2512
2512
  // an app whose database files live in another app (database.ts)
2513
- "database-elsewhere"
2513
+ "database-elsewhere",
2514
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
2515
+ "genesis-eslint-config"
2514
2516
  ];
2515
2517
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2516
2518
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -5562,6 +5564,31 @@ function readsPracticeId(text) {
5562
5564
  var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
5563
5565
  var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
5564
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
+
5565
5592
  // src/upgrade/codemods.ts
5566
5593
  var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
5567
5594
  var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -6304,9 +6331,179 @@ function blockOfSource(source, manifests) {
6304
6331
  }
6305
6332
  return null;
6306
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
+ }
6307
6481
 
6308
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
+ }
6309
6505
  async function checkLockFiles(ctx) {
6506
+ checkBunLock(ctx);
6310
6507
  if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
6311
6508
  let lock;
6312
6509
  try {
@@ -6419,7 +6616,37 @@ function checkDatabaseHome(ctx) {
6419
6616
  });
6420
6617
  }
6421
6618
  }
6422
- var RATCHETED_BY_DEFAULT = ["deprecated-import"];
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"];
6423
6650
  async function runDoctor(options = {}) {
6424
6651
  const root = path20.resolve(options.root ?? process.cwd());
6425
6652
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
@@ -6522,6 +6749,7 @@ function builtinChecks(config, options = {}) {
6522
6749
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
6523
6750
  { name: "lock-files", check: checkLockFiles },
6524
6751
  { name: "database-elsewhere", check: checkDatabaseHome },
6752
+ { name: "eslint-config", check: checkEslintConfig },
6525
6753
  ...(config.packs ?? []).map((p) => packs[p]),
6526
6754
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
6527
6755
  ];