@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/index.js CHANGED
@@ -456,14 +456,14 @@ function inherit(own, source) {
456
456
  }
457
457
  function resolveViews(relations) {
458
458
  const done = /* @__PURE__ */ new Set();
459
- const resolve16 = (relation, depth) => {
459
+ const resolve17 = (relation, depth) => {
460
460
  if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
461
461
  done.add(relation.oid);
462
462
  const sources = new Set([...relation.origins.values()].map((o) => o.relation));
463
463
  if (sources.size !== 1) return;
464
464
  const source = relations.get([...sources][0]);
465
465
  if (!source) return;
466
- resolve16(source, depth + 1);
466
+ resolve17(source, depth + 1);
467
467
  const viewAttnumOf = /* @__PURE__ */ new Map();
468
468
  for (const [attnum, origin] of relation.origins) {
469
469
  const own = relation.columns.get(attnum);
@@ -486,7 +486,7 @@ function resolveViews(relations) {
486
486
  };
487
487
  if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
488
488
  };
489
- for (const relation of relations.values()) resolve16(relation, 0);
489
+ for (const relation of relations.values()) resolve17(relation, 0);
490
490
  }
491
491
  async function introspectPostgres(sql, schemas, options = {}) {
492
492
  const relations = /* @__PURE__ */ new Map();
@@ -816,9 +816,9 @@ async function runScaffold(opts, fs) {
816
816
  function joinPath(...parts) {
817
817
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
818
818
  }
819
- function dirname(path39) {
820
- const idx = path39.lastIndexOf("/");
821
- return idx === -1 ? "." : path39.slice(0, idx);
819
+ function dirname(path43) {
820
+ const idx = path43.lastIndexOf("/");
821
+ return idx === -1 ? "." : path43.slice(0, idx);
822
822
  }
823
823
  function brandPackageJson(consumer, genesisVersion) {
824
824
  return JSON.stringify(
@@ -1076,8 +1076,8 @@ function routeTags(source) {
1076
1076
  var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
1077
1077
  function wireStudioRoute(source, route, pageImportPath) {
1078
1078
  const tags = routeTags(source);
1079
- const relative10 = route.replace(/^\//, "");
1080
- const existing = tags.find((t) => new RegExp(`path=["'](/?${relative10.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
1079
+ const relative11 = route.replace(/^\//, "");
1080
+ const existing = tags.find((t) => new RegExp(`path=["'](/?${relative11.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
1081
1081
  if (existing) {
1082
1082
  return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
1083
1083
  }
@@ -1085,17 +1085,17 @@ function wireStudioRoute(source, route, pageImportPath) {
1085
1085
  const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
1086
1086
  if (roots.length !== 1) {
1087
1087
  return {
1088
- skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative10}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
1088
+ skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative11}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
1089
1089
  };
1090
1090
  }
1091
1091
  const layout = roots[0];
1092
1092
  const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
1093
- if (base && !relative10.startsWith(`${base}/`)) {
1093
+ if (base && !relative11.startsWith(`${base}/`)) {
1094
1094
  return {
1095
1095
  skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
1096
1096
  };
1097
1097
  }
1098
- const childPath = base ? relative10.slice(base.length + 1) : relative10;
1098
+ const childPath = base ? relative11.slice(base.length + 1) : relative11;
1099
1099
  const guard = GUARD.exec(source)?.[1];
1100
1100
  const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
1101
1101
  const before = source.slice(0, layout.close);
@@ -1831,7 +1831,7 @@ function globToRegExp(glob) {
1831
1831
  }
1832
1832
  function globMatcher(globs) {
1833
1833
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1834
- return (path39) => res.some((re) => re.test(path39));
1834
+ return (path43) => res.some((re) => re.test(path43));
1835
1835
  }
1836
1836
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1837
1837
  var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
@@ -3047,8 +3047,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
3047
3047
  } catch {
3048
3048
  continue;
3049
3049
  }
3050
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
3051
- const spec = json[section]?.[name];
3050
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
3051
+ const spec = json[section2]?.[name];
3052
3052
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
3053
3053
  const parsed = v && parseVersion(v);
3054
3054
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -3201,7 +3201,9 @@ var BUILTIN_RULES = [
3201
3201
  // genesis.lock.json against the files (lock-files.ts)
3202
3202
  "lock-files",
3203
3203
  // an app whose database files live in another app (database.ts)
3204
- "database-elsewhere"
3204
+ "database-elsewhere",
3205
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
3206
+ "genesis-eslint-config"
3205
3207
  ];
3206
3208
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
3207
3209
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -6253,6 +6255,31 @@ function readsPracticeId(text) {
6253
6255
  var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
6254
6256
  var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
6255
6257
 
6258
+ // src/upgrade/eslint-config.ts
6259
+ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
6260
+ var TESTING_LIBRARY = "eslint-plugin-testing-library";
6261
+ var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
6262
+ function findEslintConfig(root) {
6263
+ return FLAT_CONFIG_FILES.find((name) => existsSync(path20.join(root, name))) ?? null;
6264
+ }
6265
+ function readPackageJson(root) {
6266
+ try {
6267
+ return JSON.parse(readFileSync(path20.join(root, "package.json"), "utf8"));
6268
+ } catch {
6269
+ return null;
6270
+ }
6271
+ }
6272
+ var declares = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name]);
6273
+ function appPlatform(pkg) {
6274
+ return declares(pkg, "expo") || declares(pkg, "react-native") ? "native" : "web";
6275
+ }
6276
+ function hasTestingLibrary(pkg) {
6277
+ return declares(pkg, TESTING_LIBRARY);
6278
+ }
6279
+ function usesGenesisLint(text) {
6280
+ return text.includes(ESLINT_EXPORT);
6281
+ }
6282
+
6256
6283
  // src/upgrade/codemods.ts
6257
6284
  var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
6258
6285
  var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -6995,9 +7022,179 @@ function blockOfSource(source, manifests) {
6995
7022
  }
6996
7023
  return null;
6997
7024
  }
7025
+ var BUN_LOCK = "bun.lock";
7026
+ var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
7027
+ var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
7028
+ function skipSpace(text, i) {
7029
+ for (; ; ) {
7030
+ while (i < text.length && /\s/.test(text[i])) i++;
7031
+ if (text.startsWith("//", i)) {
7032
+ const nl = text.indexOf("\n", i);
7033
+ i = nl === -1 ? text.length : nl + 1;
7034
+ } else if (text.startsWith("/*", i)) {
7035
+ const close = text.indexOf("*/", i + 2);
7036
+ i = close === -1 ? text.length : close + 2;
7037
+ } else return i;
7038
+ }
7039
+ }
7040
+ function skipString(text, i) {
7041
+ for (let j = i + 1; j < text.length; j++) {
7042
+ if (text[j] === "\\") j++;
7043
+ else if (text[j] === '"') return j + 1;
7044
+ }
7045
+ throw new Error("an unterminated string");
7046
+ }
7047
+ function skipValue(text, i) {
7048
+ const c = text[i];
7049
+ if (c === '"') return skipString(text, i);
7050
+ if (c === "{" || c === "[") {
7051
+ let depth = 0;
7052
+ for (let j2 = i; j2 < text.length; ) {
7053
+ const d = text[j2];
7054
+ if (d === '"') {
7055
+ j2 = skipString(text, j2);
7056
+ continue;
7057
+ }
7058
+ if (text.startsWith("//", j2) || text.startsWith("/*", j2)) {
7059
+ j2 = skipSpace(text, j2);
7060
+ continue;
7061
+ }
7062
+ if (d === "{" || d === "[") depth++;
7063
+ else if (d === "}" || d === "]") {
7064
+ depth--;
7065
+ if (depth === 0) return j2 + 1;
7066
+ }
7067
+ j2++;
7068
+ }
7069
+ throw new Error("an unclosed object or array");
7070
+ }
7071
+ let j = i;
7072
+ while (j < text.length && !/[\s,}\]]/.test(text[j])) j++;
7073
+ if (j === i) throw new Error(`an unexpected ${JSON.stringify(c ?? "end")} at ${i}`);
7074
+ return j;
7075
+ }
7076
+ function members(text, open) {
7077
+ const out = [];
7078
+ let i = skipSpace(text, open + 1);
7079
+ while (text[i] !== "}") {
7080
+ if (text[i] !== '"') throw new Error(`a key expected at ${i}`);
7081
+ const keyEnd = skipString(text, i);
7082
+ const key2 = JSON.parse(text.slice(i, keyEnd));
7083
+ let j = skipSpace(text, keyEnd);
7084
+ if (text[j] !== ":") throw new Error(`":" expected at ${j}`);
7085
+ const value = skipSpace(text, j + 1);
7086
+ const end = skipValue(text, value);
7087
+ out.push({ key: key2, start: i, end, value });
7088
+ j = skipSpace(text, end);
7089
+ if (text[j] === ",") j = skipSpace(text, j + 1);
7090
+ i = j;
7091
+ if (i >= text.length) throw new Error("an unclosed object");
7092
+ }
7093
+ return out;
7094
+ }
7095
+ function section(text, name) {
7096
+ const open = skipSpace(text, 0);
7097
+ if (text[open] !== "{") throw new Error("not an object");
7098
+ const m = members(text, open).find((x) => x.key === name);
7099
+ return m && text[m.value] === "{" ? m : null;
7100
+ }
7101
+ function parseLoose(fragment) {
7102
+ let out = "";
7103
+ for (let i = 0; i < fragment.length; ) {
7104
+ const c = fragment[i];
7105
+ if (c === '"') {
7106
+ const end = skipString(fragment, i);
7107
+ out += fragment.slice(i, end);
7108
+ i = end;
7109
+ } else if (c === ",") {
7110
+ const next = skipSpace(fragment, i + 1);
7111
+ if (fragment[next] !== "}" && fragment[next] !== "]") out += c;
7112
+ i++;
7113
+ } else if (fragment.startsWith("//", i) || fragment.startsWith("/*", i)) {
7114
+ i = skipSpace(fragment, i);
7115
+ } else {
7116
+ out += c;
7117
+ i++;
7118
+ }
7119
+ }
7120
+ return JSON.parse(out);
7121
+ }
7122
+ function resolution(value) {
7123
+ const first = Array.isArray(value) ? value[0] : null;
7124
+ if (typeof first !== "string") return null;
7125
+ const at = first.lastIndexOf("@");
7126
+ if (at <= 0) return null;
7127
+ return { name: first.slice(0, at), spec: first.slice(at + 1) };
7128
+ }
7129
+ function staleNestedEntries(text, want = () => null) {
7130
+ const packages = section(text, "packages");
7131
+ if (!packages) return [];
7132
+ const list = members(text, packages.value);
7133
+ const value = (m) => parseLoose(text.slice(m.value, m.end));
7134
+ const byKey = new Map(list.map((m) => [m.key, m]));
7135
+ const out = [];
7136
+ for (const m of list) {
7137
+ const tail = GENESIS_TAIL.exec(m.key);
7138
+ if (!tail || tail[1] === m.key) continue;
7139
+ const name = tail[1];
7140
+ const nested = resolution(value(m));
7141
+ if (!nested || nested.name !== name || !PLAIN_VERSION.test(nested.spec)) continue;
7142
+ const rootEntry = byKey.get(name);
7143
+ const rootRes = rootEntry ? resolution(value(rootEntry)) : null;
7144
+ const target = want(name) ?? (rootRes && PLAIN_VERSION.test(rootRes.spec) ? rootRes.spec : null);
7145
+ if (!rootEntry || !target || target === nested.spec) continue;
7146
+ const parent = m.key.slice(0, m.key.length - name.length - 1);
7147
+ const parentEntry = byKey.get(parent);
7148
+ const meta = parentEntry ? value(parentEntry)[2] : void 0;
7149
+ const declared = meta && typeof meta === "object" ? meta : {};
7150
+ const range = ["dependencies", "peerDependencies", "optionalDependencies"].map((s) => declared[s]?.[name]).find((r) => typeof r === "string");
7151
+ if (!range || satisfies(target, range) !== true) continue;
7152
+ out.push({ key: m.key, name, parent, version: nested.spec, root: target, range });
7153
+ }
7154
+ return out;
7155
+ }
7156
+ function readBunLock(dir) {
7157
+ const file = path20.join(dir, BUN_LOCK);
7158
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
7159
+ }
7160
+ function findLockfile(root) {
7161
+ let dir = path20.resolve(root);
7162
+ for (; ; ) {
7163
+ if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
7164
+ if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
7165
+ if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
7166
+ if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
7167
+ const parent = path20.dirname(dir);
7168
+ if (parent === dir) return null;
7169
+ dir = parent;
7170
+ }
7171
+ }
6998
7172
 
6999
7173
  // src/doctor/lock-files.ts
7174
+ function checkBunLock(ctx) {
7175
+ const found = findLockfile(ctx.root);
7176
+ if (found?.pm !== "bun") return;
7177
+ const text = readBunLock(found.dir);
7178
+ if (text === null) return;
7179
+ const file = path20.relative(ctx.root, path20.join(found.dir, BUN_LOCK)).split(path20.sep).join("/");
7180
+ let stale;
7181
+ try {
7182
+ stale = staleNestedEntries(text);
7183
+ } catch {
7184
+ return;
7185
+ }
7186
+ for (const s of stale) {
7187
+ ctx.report({
7188
+ rule: "lock-files",
7189
+ level: "warn",
7190
+ file,
7191
+ subject: s.key,
7192
+ 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`
7193
+ });
7194
+ }
7195
+ }
7000
7196
  async function checkLockFiles(ctx) {
7197
+ checkBunLock(ctx);
7001
7198
  if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
7002
7199
  let lock;
7003
7200
  try {
@@ -7110,7 +7307,37 @@ function checkDatabaseHome(ctx) {
7110
7307
  });
7111
7308
  }
7112
7309
  }
7113
- var RATCHETED_BY_DEFAULT = ["deprecated-import"];
7310
+ function checkEslintConfig(ctx) {
7311
+ const pkg = readPackageJson(ctx.root);
7312
+ const native = appPlatform(pkg) === "native" || (ctx.config.packs?.includes("native") ?? false);
7313
+ if (!native) return;
7314
+ const file = findEslintConfig(ctx.root);
7315
+ if (!file) return;
7316
+ let text;
7317
+ try {
7318
+ text = readFileSync(path20.join(ctx.root, file), "utf8");
7319
+ } catch {
7320
+ return;
7321
+ }
7322
+ if (!usesGenesisLint(text)) {
7323
+ ctx.report({
7324
+ rule: "genesis-eslint-config",
7325
+ level: "warn",
7326
+ file,
7327
+ subject: "@marktiderman/genesis-cli/eslint",
7328
+ 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`
7329
+ });
7330
+ } else if (!hasTestingLibrary(pkg)) {
7331
+ ctx.report({
7332
+ rule: "genesis-eslint-config",
7333
+ level: "warn",
7334
+ file: "package.json",
7335
+ subject: TESTING_LIBRARY,
7336
+ 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`
7337
+ });
7338
+ }
7339
+ }
7340
+ var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
7114
7341
  async function runDoctor(options = {}) {
7115
7342
  const root = path20.resolve(options.root ?? process.cwd());
7116
7343
  const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
@@ -7213,6 +7440,7 @@ function builtinChecks(config, options = {}) {
7213
7440
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
7214
7441
  { name: "lock-files", check: checkLockFiles },
7215
7442
  { name: "database-elsewhere", check: checkDatabaseHome },
7443
+ { name: "eslint-config", check: checkEslintConfig },
7216
7444
  ...(config.packs ?? []).map((p) => packs[p]),
7217
7445
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
7218
7446
  ];