@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/cli.js CHANGED
@@ -1910,7 +1910,7 @@ function globToRegExp(glob) {
1910
1910
  }
1911
1911
  function globMatcher(globs) {
1912
1912
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1913
- return (path53) => res.some((re) => re.test(path53));
1913
+ return (path56) => res.some((re) => re.test(path56));
1914
1914
  }
1915
1915
  var init_glob = __esm({
1916
1916
  "src/doctor/glob.ts"() {
@@ -2158,8 +2158,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
2158
2158
  } catch {
2159
2159
  continue;
2160
2160
  }
2161
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2162
- const spec = json[section]?.[name];
2161
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2162
+ const spec = json[section2]?.[name];
2163
2163
  const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
2164
2164
  const parsed = v && parseVersion(v);
2165
2165
  if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
@@ -2678,8 +2678,8 @@ function initNative(options) {
2678
2678
  pkg.name = slug;
2679
2679
  const unpinned = [];
2680
2680
  const dependencies2 = {};
2681
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
2682
- const deps = pkg[section];
2681
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
2682
+ const deps = pkg[section2];
2683
2683
  for (const [name, spec] of Object.entries(deps ?? {})) {
2684
2684
  if (!spec.startsWith("workspace:")) continue;
2685
2685
  const version = versionFor(name);
@@ -4119,7 +4119,9 @@ var init_rules = __esm({
4119
4119
  // genesis.lock.json against the files (lock-files.ts)
4120
4120
  "lock-files",
4121
4121
  // an app whose database files live in another app (database.ts)
4122
- "database-elsewhere"
4122
+ "database-elsewhere",
4123
+ // the app's eslint config loads Genesis's lint rules (eslint-config.ts)
4124
+ "genesis-eslint-config"
4123
4125
  ];
4124
4126
  DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
4125
4127
  STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -6745,8 +6747,8 @@ function compareVersions2(a, b) {
6745
6747
  function bumpPackageJson(file, text, wanted) {
6746
6748
  const pkg = JSON.parse(text);
6747
6749
  const changes = [], skipped = [];
6748
- for (const section of SECTIONS) {
6749
- for (const [name, spec] of Object.entries(pkg[section] ?? {})) {
6750
+ for (const section2 of SECTIONS) {
6751
+ for (const [name, spec] of Object.entries(pkg[section2] ?? {})) {
6750
6752
  if (!GENESIS3.test(name)) continue;
6751
6753
  const m = EXACT.exec(spec);
6752
6754
  if (!m) {
@@ -6768,8 +6770,8 @@ function bumpPackageJson(file, text, wanted) {
6768
6770
  skipped.push({ file, name, spec, why: `newer than ${want}` });
6769
6771
  continue;
6770
6772
  }
6771
- pkg[section][name] = `${m[1] ?? ""}${want}`;
6772
- changes.push({ file, name, from: spec, to: pkg[section][name] });
6773
+ pkg[section2][name] = `${m[1] ?? ""}${want}`;
6774
+ changes.push({ file, name, from: spec, to: pkg[section2][name] });
6773
6775
  }
6774
6776
  }
6775
6777
  if (!changes.length) return { text: null, changes, skipped };
@@ -7156,6 +7158,131 @@ var init_scope_names = __esm({
7156
7158
  PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
7157
7159
  }
7158
7160
  });
7161
+ function findEslintConfig(root) {
7162
+ return FLAT_CONFIG_FILES.find((name) => existsSync(path30.join(root, name))) ?? null;
7163
+ }
7164
+ function readPackageJson(root) {
7165
+ try {
7166
+ return JSON.parse(readFileSync(path30.join(root, "package.json"), "utf8"));
7167
+ } catch {
7168
+ return null;
7169
+ }
7170
+ }
7171
+ function appPlatform(pkg) {
7172
+ return declares(pkg, "expo") || declares(pkg, "react-native") ? "native" : "web";
7173
+ }
7174
+ function hasTestingLibrary(pkg) {
7175
+ return declares(pkg, TESTING_LIBRARY);
7176
+ }
7177
+ function usesGenesisLint(text) {
7178
+ return text.includes(ESLINT_EXPORT);
7179
+ }
7180
+ function inlinesRntlRules(text) {
7181
+ return /testing-library\/await-async-events/.test(maskComments(text));
7182
+ }
7183
+ function maskCode(text) {
7184
+ const masked = maskComments(text).split("");
7185
+ let quote2 = null;
7186
+ for (let i = 0; i < masked.length; i++) {
7187
+ const ch = masked[i];
7188
+ if (quote2) {
7189
+ if (ch === "\\") {
7190
+ masked[i] = " ";
7191
+ if (i + 1 < masked.length && masked[i + 1] !== "\n") masked[i + 1] = " ";
7192
+ i++;
7193
+ } else if (ch === quote2) quote2 = null;
7194
+ else if (ch !== "\n") masked[i] = " ";
7195
+ continue;
7196
+ }
7197
+ if (ch === '"' || ch === "'" || ch === "`") quote2 = ch;
7198
+ }
7199
+ return masked.join("");
7200
+ }
7201
+ function matching2(code, open) {
7202
+ const pairs = { "[": "]", "(": ")", "{": "}" };
7203
+ const stack = [];
7204
+ for (let i = open; i < code.length; i++) {
7205
+ const ch = code[i];
7206
+ if (ch in pairs) stack.push(pairs[ch]);
7207
+ else if (ch === "]" || ch === ")" || ch === "}") {
7208
+ if (stack.pop() !== ch) return -1;
7209
+ if (!stack.length) return i;
7210
+ }
7211
+ }
7212
+ return -1;
7213
+ }
7214
+ function importLine(kind, local = "genesis") {
7215
+ const binding = local === "genesis" ? "genesis" : `genesis: ${local}`;
7216
+ return kind === "cjs" ? `const { ${binding} } = require("${ESLINT_EXPORT}");` : `import { ${local === "genesis" ? "genesis" : `genesis as ${local}`} } from "${ESLINT_EXPORT}";`;
7217
+ }
7218
+ function spreadLine(platform, local = "genesis") {
7219
+ return `...${local}("${platform}")`;
7220
+ }
7221
+ function addGenesisLint(text, platform, file = "eslint.config.js") {
7222
+ const code = maskCode(text);
7223
+ const ext = path30.extname(file);
7224
+ const exportsCjs = [...code.matchAll(/(?:^|[\n;])\s*module\.exports\s*=\s*/g)];
7225
+ const exportsEsm = [...code.matchAll(/(?:^|[\n;])\s*export\s+default\s+/g)];
7226
+ const kind = ext === ".cjs" || ext === ".cts" ? "cjs" : ext === ".mjs" || ext === ".mts" ? "esm" : exportsCjs.length && !exportsEsm.length ? "cjs" : "esm";
7227
+ const found = [...exportsCjs, ...exportsEsm];
7228
+ if (found.length !== 1) return { ok: false, kind, reason: found.length ? "it exports its config more than once" : "it has no `module.exports =` or `export default`" };
7229
+ const local = /(?<![\w$])genesis(?![\w$])/.test(code) ? "genesisLint" : "genesis";
7230
+ if (local === "genesisLint" && /(?<![\w$])genesisLint(?![\w$])/.test(code)) return { ok: false, kind, reason: "it already declares `genesis` and `genesisLint`" };
7231
+ let at = found[0].index + found[0][0].length;
7232
+ let close;
7233
+ const call = /^(?!(?:async|function)\b)[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*\s*\(\s*/.exec(code.slice(at));
7234
+ if (code[at] === "[") {
7235
+ close = matching2(code, at);
7236
+ } else if (call) {
7237
+ const paren = at + call[0].lastIndexOf("(");
7238
+ at += call[0].length;
7239
+ close = code[at] === "[" ? matching2(code, at) : matching2(code, paren);
7240
+ if (code[at] !== "[") at = paren;
7241
+ } else {
7242
+ return { ok: false, kind, reason: "it doesn't export an array or a `defineConfig(...)` call" };
7243
+ }
7244
+ if (close < 0) return { ok: false, kind, reason: "its exported array doesn't close where expected" };
7245
+ let last = close - 1;
7246
+ while (last > at && /\s/.test(code[last])) last--;
7247
+ const entry = spreadLine(platform, local);
7248
+ let next;
7249
+ if (last === at) {
7250
+ next = `${text.slice(0, at + 1)}${entry}${text.slice(close)}`;
7251
+ } else {
7252
+ const comma = code[last] === "," ? "" : ",";
7253
+ const multiline = code.slice(last, close).includes("\n");
7254
+ const lineStart = code.lastIndexOf("\n", last) + 1;
7255
+ const indent = /^[ \t]*/.exec(text.slice(lineStart))[0];
7256
+ next = multiline ? `${text.slice(0, last + 1)}${comma}
7257
+ ${indent}${entry},${text.slice(last + 1)}` : `${text.slice(0, last + 1)}${comma} ${entry}${text.slice(last + 1)}`;
7258
+ }
7259
+ const exportAt = found[0].index + found[0][0].search(/module|export/);
7260
+ const head = maskCode(next).slice(0, exportAt);
7261
+ const imports = [...head.matchAll(kind === "cjs" ? /^(?:const|let|var)\s[^\n]*\brequire\s*\([^\n]*$/gm : /^import\b[\s\S]*?(?:from\s*)?["'][^"'\n]*["'][^\n]*$/gm)];
7262
+ const line = importLine(kind, local);
7263
+ if (imports.length) {
7264
+ const end = imports.at(-1).index + imports.at(-1)[0].length;
7265
+ return { ok: true, text: `${next.slice(0, end)}
7266
+ ${line}${next.slice(end)}` };
7267
+ }
7268
+ const shebang = next.startsWith("#!") ? next.indexOf("\n") + 1 : 0;
7269
+ return { ok: true, text: `${next.slice(0, shebang)}${line}
7270
+ ${next.slice(shebang)}` };
7271
+ }
7272
+ function manualLines(kind, platform) {
7273
+ return [importLine(kind), `${spreadLine(platform)}, // last in the array the config exports`];
7274
+ }
7275
+ var ESLINT_EXPORT, TESTING_LIBRARY, TESTING_LIBRARY_RANGE, FLAT_CONFIG_FILES, declares;
7276
+ var init_eslint_config = __esm({
7277
+ "src/upgrade/eslint-config.ts"() {
7278
+ init_scope_names();
7279
+ ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
7280
+ TESTING_LIBRARY = "eslint-plugin-testing-library";
7281
+ TESTING_LIBRARY_RANGE = "^7.16.2";
7282
+ FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
7283
+ declares = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name]);
7284
+ }
7285
+ });
7159
7286
 
7160
7287
  // src/upgrade/codemods.ts
7161
7288
  var codemods_exports = {};
@@ -7164,6 +7291,7 @@ __export(codemods_exports, {
7164
7291
  appScripts: () => appScripts,
7165
7292
  codemodById: () => codemodById,
7166
7293
  codemodsFor: () => codemodsFor,
7294
+ genesisEslintConfig: () => genesisEslintConfig,
7167
7295
  scopeNeutralNames: () => scopeNeutralNames,
7168
7296
  uncoveredBreaks: () => uncoveredBreaks
7169
7297
  });
@@ -7197,10 +7325,11 @@ function uncoveredBreaks(changes, registry = CODEMODS) {
7197
7325
  };
7198
7326
  return changes.filter((c) => major(c.from) !== major(c.to) && codemodsFor([c], registry).length === 0);
7199
7327
  }
7200
- var SKIP_DIRS3, SCRIPT2, MAX_BYTES, scopeNeutralNames, CODEMODS, bare;
7328
+ var SKIP_DIRS3, SCRIPT2, MAX_BYTES, scopeNeutralNames, genesisEslintConfig, CODEMODS, bare;
7201
7329
  var init_codemods = __esm({
7202
7330
  "src/upgrade/codemods.ts"() {
7203
7331
  init_bump_core();
7332
+ init_eslint_config();
7204
7333
  init_scope_names();
7205
7334
  SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
7206
7335
  SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
@@ -7232,7 +7361,49 @@ var init_codemods = __esm({
7232
7361
  return changed;
7233
7362
  }
7234
7363
  };
7235
- CODEMODS = [scopeNeutralNames];
7364
+ genesisEslintConfig = {
7365
+ id: "genesis-cli-eslint-config",
7366
+ package: "@marktiderman/genesis-cli",
7367
+ version: "1.20.0",
7368
+ description: "Loads Genesis's lint rules from @marktiderman/genesis-cli/eslint in the app's eslint.config, so genesis upgrade delivers new ones.",
7369
+ run({ root, dryRun, log }) {
7370
+ const file = findEslintConfig(root);
7371
+ if (!file) return [];
7372
+ const changed = [];
7373
+ const pkg = readPackageJson(root);
7374
+ const platform = appPlatform(pkg);
7375
+ const abs = path30.join(root, file);
7376
+ const text = readFileSync(abs, "utf8");
7377
+ if (!usesGenesisLint(text)) {
7378
+ const result = addGenesisLint(text, platform, file);
7379
+ if (result.ok) {
7380
+ changed.push(file);
7381
+ if (!dryRun) writeFileSync(abs, result.text);
7382
+ if (inlinesRntlRules(text)) {
7383
+ log(` ${file} still has its own React Native Testing Library await rules (testing-library/await-async-events and the no-restricted-syntax selectors); genesis("${platform}") now brings them, so delete that block.`);
7384
+ }
7385
+ } else {
7386
+ log(` ${file}: not edited, because ${result.reason}. Add Genesis's lint rules by hand:
7387
+ ${manualLines(result.kind, platform).map((l) => ` ${l}`).join("\n")}`);
7388
+ }
7389
+ }
7390
+ if (platform === "native" && pkg && !hasTestingLibrary(pkg)) {
7391
+ const pkgFile = path30.join(root, "package.json");
7392
+ const raw = readFileSync(pkgFile, "utf8");
7393
+ const indent = /^[ \t]+(?=")/m.exec(raw)?.[0] ?? " ";
7394
+ const json = JSON.parse(raw);
7395
+ const names = Object.keys(json.devDependencies ?? {});
7396
+ const sorted2 = names.every((name, i) => i === 0 || names[i - 1].localeCompare(name) <= 0);
7397
+ const dev = Object.entries({ ...json.devDependencies, [TESTING_LIBRARY]: TESTING_LIBRARY_RANGE });
7398
+ json.devDependencies = Object.fromEntries(sorted2 ? dev.sort(([a], [b]) => a.localeCompare(b)) : dev);
7399
+ changed.push("package.json");
7400
+ if (!dryRun) writeFileSync(pkgFile, `${JSON.stringify(json, null, indent)}${raw.endsWith("\n") ? "\n" : ""}`);
7401
+ log(` package.json: added ${TESTING_LIBRARY}@${TESTING_LIBRARY_RANGE} to devDependencies (Genesis's native lint rules use it); install to fetch it.`);
7402
+ }
7403
+ return changed;
7404
+ }
7405
+ };
7406
+ CODEMODS = [scopeNeutralNames, genesisEslintConfig];
7236
7407
  bare = (spec) => spec.replace(/^[\^~=]/, "");
7237
7408
  }
7238
7409
  });
@@ -7930,7 +8101,224 @@ var init_owned = __esm({
7930
8101
  CLI = "@marktiderman/genesis-cli";
7931
8102
  }
7932
8103
  });
8104
+ function skipSpace(text, i) {
8105
+ for (; ; ) {
8106
+ while (i < text.length && /\s/.test(text[i])) i++;
8107
+ if (text.startsWith("//", i)) {
8108
+ const nl = text.indexOf("\n", i);
8109
+ i = nl === -1 ? text.length : nl + 1;
8110
+ } else if (text.startsWith("/*", i)) {
8111
+ const close = text.indexOf("*/", i + 2);
8112
+ i = close === -1 ? text.length : close + 2;
8113
+ } else return i;
8114
+ }
8115
+ }
8116
+ function skipString(text, i) {
8117
+ for (let j = i + 1; j < text.length; j++) {
8118
+ if (text[j] === "\\") j++;
8119
+ else if (text[j] === '"') return j + 1;
8120
+ }
8121
+ throw new Error("an unterminated string");
8122
+ }
8123
+ function skipValue(text, i) {
8124
+ const c = text[i];
8125
+ if (c === '"') return skipString(text, i);
8126
+ if (c === "{" || c === "[") {
8127
+ let depth = 0;
8128
+ for (let j2 = i; j2 < text.length; ) {
8129
+ const d = text[j2];
8130
+ if (d === '"') {
8131
+ j2 = skipString(text, j2);
8132
+ continue;
8133
+ }
8134
+ if (text.startsWith("//", j2) || text.startsWith("/*", j2)) {
8135
+ j2 = skipSpace(text, j2);
8136
+ continue;
8137
+ }
8138
+ if (d === "{" || d === "[") depth++;
8139
+ else if (d === "}" || d === "]") {
8140
+ depth--;
8141
+ if (depth === 0) return j2 + 1;
8142
+ }
8143
+ j2++;
8144
+ }
8145
+ throw new Error("an unclosed object or array");
8146
+ }
8147
+ let j = i;
8148
+ while (j < text.length && !/[\s,}\]]/.test(text[j])) j++;
8149
+ if (j === i) throw new Error(`an unexpected ${JSON.stringify(c ?? "end")} at ${i}`);
8150
+ return j;
8151
+ }
8152
+ function members(text, open) {
8153
+ const out = [];
8154
+ let i = skipSpace(text, open + 1);
8155
+ while (text[i] !== "}") {
8156
+ if (text[i] !== '"') throw new Error(`a key expected at ${i}`);
8157
+ const keyEnd = skipString(text, i);
8158
+ const key2 = JSON.parse(text.slice(i, keyEnd));
8159
+ let j = skipSpace(text, keyEnd);
8160
+ if (text[j] !== ":") throw new Error(`":" expected at ${j}`);
8161
+ const value = skipSpace(text, j + 1);
8162
+ const end = skipValue(text, value);
8163
+ out.push({ key: key2, start: i, end, value });
8164
+ j = skipSpace(text, end);
8165
+ if (text[j] === ",") j = skipSpace(text, j + 1);
8166
+ i = j;
8167
+ if (i >= text.length) throw new Error("an unclosed object");
8168
+ }
8169
+ return out;
8170
+ }
8171
+ function section(text, name) {
8172
+ const open = skipSpace(text, 0);
8173
+ if (text[open] !== "{") throw new Error("not an object");
8174
+ const m = members(text, open).find((x) => x.key === name);
8175
+ return m && text[m.value] === "{" ? m : null;
8176
+ }
8177
+ function parseLoose(fragment) {
8178
+ let out = "";
8179
+ for (let i = 0; i < fragment.length; ) {
8180
+ const c = fragment[i];
8181
+ if (c === '"') {
8182
+ const end = skipString(fragment, i);
8183
+ out += fragment.slice(i, end);
8184
+ i = end;
8185
+ } else if (c === ",") {
8186
+ const next = skipSpace(fragment, i + 1);
8187
+ if (fragment[next] !== "}" && fragment[next] !== "]") out += c;
8188
+ i++;
8189
+ } else if (fragment.startsWith("//", i) || fragment.startsWith("/*", i)) {
8190
+ i = skipSpace(fragment, i);
8191
+ } else {
8192
+ out += c;
8193
+ i++;
8194
+ }
8195
+ }
8196
+ return JSON.parse(out);
8197
+ }
8198
+ function resolution(value) {
8199
+ const first = Array.isArray(value) ? value[0] : null;
8200
+ if (typeof first !== "string") return null;
8201
+ const at = first.lastIndexOf("@");
8202
+ if (at <= 0) return null;
8203
+ return { name: first.slice(0, at), spec: first.slice(at + 1) };
8204
+ }
8205
+ function staleNestedEntries(text, want = () => null) {
8206
+ const packages = section(text, "packages");
8207
+ if (!packages) return [];
8208
+ const list = members(text, packages.value);
8209
+ const value = (m) => parseLoose(text.slice(m.value, m.end));
8210
+ const byKey = new Map(list.map((m) => [m.key, m]));
8211
+ const out = [];
8212
+ for (const m of list) {
8213
+ const tail = GENESIS_TAIL.exec(m.key);
8214
+ if (!tail || tail[1] === m.key) continue;
8215
+ const name = tail[1];
8216
+ const nested = resolution(value(m));
8217
+ if (!nested || nested.name !== name || !PLAIN_VERSION.test(nested.spec)) continue;
8218
+ const rootEntry = byKey.get(name);
8219
+ const rootRes = rootEntry ? resolution(value(rootEntry)) : null;
8220
+ const target = want(name) ?? (rootRes && PLAIN_VERSION.test(rootRes.spec) ? rootRes.spec : null);
8221
+ if (!rootEntry || !target || target === nested.spec) continue;
8222
+ const parent = m.key.slice(0, m.key.length - name.length - 1);
8223
+ const parentEntry = byKey.get(parent);
8224
+ const meta = parentEntry ? value(parentEntry)[2] : void 0;
8225
+ const declared = meta && typeof meta === "object" ? meta : {};
8226
+ const range = ["dependencies", "peerDependencies", "optionalDependencies"].map((s) => declared[s]?.[name]).find((r) => typeof r === "string");
8227
+ if (!range || satisfies(target, range) !== true) continue;
8228
+ out.push({ key: m.key, name, parent, version: nested.spec, root: target, range });
8229
+ }
8230
+ return out;
8231
+ }
8232
+ function workspaceEntries(text, folder) {
8233
+ const rel = folder.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
8234
+ const ws = section(text, "workspaces");
8235
+ const workspaces = ws ? members(text, ws.value).filter((m) => m.key === rel).map((m) => m.key) : [];
8236
+ const pk = section(text, "packages");
8237
+ const packages = [];
8238
+ if (pk) {
8239
+ const list = members(text, pk.value);
8240
+ const names = list.filter((m) => resolution(parseLoose(text.slice(m.value, m.end)))?.spec === `workspace:${rel}`).map((m) => m.key);
8241
+ for (const m of list) if (names.some((n) => m.key === n || m.key.startsWith(`${n}/`))) packages.push(m.key);
8242
+ }
8243
+ return { workspaces, packages };
8244
+ }
8245
+ function removeBunLockEntries(text, remove) {
8246
+ const spans = [];
8247
+ const drop = (name, keys, nested) => {
8248
+ if (!keys?.length) return;
8249
+ const s = section(text, name);
8250
+ if (!s) return;
8251
+ const list = members(text, s.value);
8252
+ list.forEach((m, k) => {
8253
+ if (!keys.some((key2) => m.key === key2 || nested && m.key.startsWith(`${key2}/`))) return;
8254
+ let start = m.start;
8255
+ while (start > 0 && (text[start - 1] === " " || text[start - 1] === " ")) start--;
8256
+ let end = skipSpace(text, m.end);
8257
+ if (text[end] === ",") {
8258
+ end++;
8259
+ let eol = end;
8260
+ while (eol < text.length && (text[eol] === " " || text[eol] === " ")) eol++;
8261
+ if (text[eol] === "\n") end = eol + 1;
8262
+ else if (text.startsWith("\r\n", eol)) end = eol + 2;
8263
+ } else if (k > 0) {
8264
+ start = list[k - 1].end;
8265
+ end = m.end;
8266
+ } else {
8267
+ end = m.end;
8268
+ if (text[end] === "\n") end++;
8269
+ }
8270
+ spans.push([start, end]);
8271
+ });
8272
+ };
8273
+ drop("workspaces", remove.workspaces, false);
8274
+ drop("packages", remove.packages, true);
8275
+ if (!spans.length) return text;
8276
+ spans.sort((a, b) => a[0] - b[0]);
8277
+ let out = "";
8278
+ let at = 0;
8279
+ for (const [a, b] of spans) {
8280
+ if (a > at) out += text.slice(at, a);
8281
+ at = Math.max(at, b);
8282
+ }
8283
+ return out + text.slice(at);
8284
+ }
8285
+ function readBunLock(dir) {
8286
+ const file = path30.join(dir, BUN_LOCK);
8287
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
8288
+ }
8289
+ var BUN_LOCK, GENESIS_TAIL, PLAIN_VERSION;
8290
+ var init_bun_lock = __esm({
8291
+ "src/blocks/bun-lock.ts"() {
8292
+ init_semver();
8293
+ BUN_LOCK = "bun.lock";
8294
+ GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
8295
+ PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
8296
+ }
8297
+ });
8298
+ function checkBunLock(ctx) {
8299
+ const found = findLockfile(ctx.root);
8300
+ if (found?.pm !== "bun") return;
8301
+ const text = readBunLock(found.dir);
8302
+ if (text === null) return;
8303
+ const file = path30.relative(ctx.root, path30.join(found.dir, BUN_LOCK)).split(path30.sep).join("/");
8304
+ let stale;
8305
+ try {
8306
+ stale = staleNestedEntries(text);
8307
+ } catch {
8308
+ return;
8309
+ }
8310
+ for (const s of stale) {
8311
+ ctx.report({
8312
+ rule: "lock-files",
8313
+ level: "warn",
8314
+ file,
8315
+ subject: s.key,
8316
+ 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`
8317
+ });
8318
+ }
8319
+ }
7933
8320
  async function checkLockFiles(ctx) {
8321
+ checkBunLock(ctx);
7934
8322
  if (!existsSync(path30.join(ctx.root, LOCK_FILE))) return;
7935
8323
  let lock;
7936
8324
  try {
@@ -8030,6 +8418,8 @@ var init_lock_files = __esm({
8030
8418
  init_owned();
8031
8419
  init_starter_features();
8032
8420
  init_database();
8421
+ init_bun_lock();
8422
+ init_pm();
8033
8423
  }
8034
8424
  });
8035
8425
  function checkDatabaseHome(ctx) {
@@ -8059,6 +8449,41 @@ var init_database2 = __esm({
8059
8449
  init_database();
8060
8450
  }
8061
8451
  });
8452
+ function checkEslintConfig(ctx) {
8453
+ const pkg = readPackageJson(ctx.root);
8454
+ const native = appPlatform(pkg) === "native" || (ctx.config.packs?.includes("native") ?? false);
8455
+ if (!native) return;
8456
+ const file = findEslintConfig(ctx.root);
8457
+ if (!file) return;
8458
+ let text;
8459
+ try {
8460
+ text = readFileSync(path30.join(ctx.root, file), "utf8");
8461
+ } catch {
8462
+ return;
8463
+ }
8464
+ if (!usesGenesisLint(text)) {
8465
+ ctx.report({
8466
+ rule: "genesis-eslint-config",
8467
+ level: "warn",
8468
+ file,
8469
+ subject: "@marktiderman/genesis-cli/eslint",
8470
+ 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`
8471
+ });
8472
+ } else if (!hasTestingLibrary(pkg)) {
8473
+ ctx.report({
8474
+ rule: "genesis-eslint-config",
8475
+ level: "warn",
8476
+ file: "package.json",
8477
+ subject: TESTING_LIBRARY,
8478
+ 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`
8479
+ });
8480
+ }
8481
+ }
8482
+ var init_eslint_config2 = __esm({
8483
+ "src/doctor/eslint-config.ts"() {
8484
+ init_eslint_config();
8485
+ }
8486
+ });
8062
8487
 
8063
8488
  // src/doctor/index.ts
8064
8489
  var doctor_exports = {};
@@ -8210,6 +8635,7 @@ function builtinChecks(config, options = {}) {
8210
8635
  { name: "overlays", check: (ctx) => checkOverlays(ctx) },
8211
8636
  { name: "lock-files", check: checkLockFiles },
8212
8637
  { name: "database-elsewhere", check: checkDatabaseHome },
8638
+ { name: "eslint-config", check: checkEslintConfig },
8213
8639
  ...(config.packs ?? []).map((p) => packs[p]),
8214
8640
  ...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
8215
8641
  ];
@@ -8326,6 +8752,7 @@ var init_doctor = __esm({
8326
8752
  init_overlays();
8327
8753
  init_lock_files();
8328
8754
  init_database2();
8755
+ init_eslint_config2();
8329
8756
  init_config();
8330
8757
  init_genesis();
8331
8758
  init_patterns();
@@ -8342,7 +8769,7 @@ var init_doctor = __esm({
8342
8769
  init_primitives();
8343
8770
  init_ratchet();
8344
8771
  init_contracts();
8345
- RATCHETED_BY_DEFAULT = ["deprecated-import"];
8772
+ RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
8346
8773
  }
8347
8774
  });
8348
8775
 
@@ -8792,8 +9219,8 @@ function routeTags(source) {
8792
9219
  }
8793
9220
  function wireStudioRoute(source, route, pageImportPath) {
8794
9221
  const tags = routeTags(source);
8795
- const relative15 = route.replace(/^\//, "");
8796
- const existing = tags.find((t) => new RegExp(`path=["'](/?${relative15.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
9222
+ const relative17 = route.replace(/^\//, "");
9223
+ const existing = tags.find((t) => new RegExp(`path=["'](/?${relative17.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
8797
9224
  if (existing) {
8798
9225
  return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
8799
9226
  }
@@ -8801,17 +9228,17 @@ function wireStudioRoute(source, route, pageImportPath) {
8801
9228
  const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
8802
9229
  if (roots.length !== 1) {
8803
9230
  return {
8804
- 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="${relative15}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
9231
+ 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="${relative17}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
8805
9232
  };
8806
9233
  }
8807
9234
  const layout = roots[0];
8808
9235
  const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
8809
- if (base && !relative15.startsWith(`${base}/`)) {
9236
+ if (base && !relative17.startsWith(`${base}/`)) {
8810
9237
  return {
8811
9238
  skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
8812
9239
  };
8813
9240
  }
8814
- const childPath = base ? relative15.slice(base.length + 1) : relative15;
9241
+ const childPath = base ? relative17.slice(base.length + 1) : relative17;
8815
9242
  const guard = GUARD.exec(source)?.[1];
8816
9243
  const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
8817
9244
  const before = source.slice(0, layout.close);
@@ -9975,11 +10402,11 @@ function rebasedManifest(text, name, to, released, nextText) {
9975
10402
  const n = LOCAL_SUFFIX.exec(typeof json.version === "string" ? json.version : "")?.[1] ?? "1";
9976
10403
  json.version = `${to}+local.${n}`;
9977
10404
  if (json.genesis?.overlay) json.genesis.overlay.upstream = `${name}@${to}`;
9978
- for (const section of ["dependencies", "peerDependencies", "optionalDependencies"]) {
9979
- const deps = json[section];
10405
+ for (const section2 of ["dependencies", "peerDependencies", "optionalDependencies"]) {
10406
+ const deps = json[section2];
9980
10407
  if (!deps) continue;
9981
10408
  for (const [dep, spec] of Object.entries(deps)) {
9982
- if (!spec.startsWith("workspace:") && !next[section]?.[dep]?.startsWith("workspace:")) continue;
10409
+ if (!spec.startsWith("workspace:") && !next[section2]?.[dep]?.startsWith("workspace:")) continue;
9983
10410
  const v = released(dep);
9984
10411
  if (v && PLAIN.test(v)) deps[dep] = `^${v}`;
9985
10412
  }
@@ -10108,9 +10535,9 @@ function ownManifestFields(mergedText, upstreamText) {
10108
10535
  if (!Object.keys(genesis).length) delete json.genesis;
10109
10536
  }
10110
10537
  }
10111
- for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
10112
- const ours = mine[section];
10113
- const up = theirs[section];
10538
+ for (const section2 of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
10539
+ const ours = mine[section2];
10540
+ const up = theirs[section2];
10114
10541
  if (!ours || !up) continue;
10115
10542
  for (const [dep, spec] of Object.entries(up)) if (typeof spec === "string" && spec.startsWith("workspace:") && typeof ours[dep] === "string") ours[dep] = spec;
10116
10543
  }
@@ -10136,51 +10563,73 @@ function folderReferences(root, plan) {
10136
10563
  }
10137
10564
  function planPins(root, plan, manifests) {
10138
10565
  const pins = /* @__PURE__ */ new Map();
10139
- const overlay = path30.resolve(root, plan.rel);
10140
10566
  for (const file of manifests) {
10141
10567
  const abs = path30.join(root, file);
10142
10568
  if (!existsSync(abs)) continue;
10143
10569
  const text = readFileSync(abs, "utf8");
10144
- let json;
10145
- try {
10146
- json = JSON.parse(text);
10147
- } catch {
10570
+ const pinned = pinManifest(root, plan, file, text);
10571
+ if (pinned === void 0) {
10148
10572
  return `nothing of the app's own is left, but ${file} isn't valid JSON, so its dependency on ${plan.name} can't be pinned: fix it, then run genesis upgrade again`;
10149
10573
  }
10150
- const here = path30.dirname(abs);
10151
- const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) && path30.resolve(here, spec.slice(5)) === overlay);
10152
- let touched2 = false;
10153
- for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
10154
- const deps = json[section];
10155
- if (deps && local(deps[plan.name])) {
10156
- deps[plan.name] = plan.to;
10157
- touched2 = true;
10158
- }
10159
- }
10160
- for (const o of [json.overrides, json.resolutions, json.pnpm?.overrides]) {
10161
- if (isObject5(o) && local(o[plan.name])) {
10162
- delete o[plan.name];
10163
- touched2 = true;
10164
- }
10165
- }
10166
- if (!touched2) continue;
10167
- const indent = /^[ \t]+(?=")/m.exec(text)?.[0] ?? " ";
10168
- pins.set(file, JSON.stringify(json, null, indent) + (text.endsWith("\n") ? "\n" : ""));
10574
+ if (pinned !== null) pins.set(file, pinned);
10169
10575
  }
10170
10576
  return pins;
10171
10577
  }
10172
- function applyOverlayPlans(root, plans) {
10578
+ function pinManifest(root, plan, file, text) {
10579
+ let json;
10580
+ try {
10581
+ json = JSON.parse(text);
10582
+ } catch {
10583
+ return void 0;
10584
+ }
10585
+ const overlay = path30.resolve(root, plan.rel);
10586
+ const here = path30.dirname(path30.join(root, file));
10587
+ const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) && path30.resolve(here, spec.slice(5)) === overlay);
10588
+ let touched2 = false;
10589
+ for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
10590
+ const deps = json[section2];
10591
+ if (deps && local(deps[plan.name])) {
10592
+ deps[plan.name] = plan.to;
10593
+ touched2 = true;
10594
+ }
10595
+ }
10596
+ for (const o of [json.overrides, json.resolutions, json.pnpm?.overrides]) {
10597
+ if (isObject5(o) && local(o[plan.name])) {
10598
+ delete o[plan.name];
10599
+ touched2 = true;
10600
+ }
10601
+ }
10602
+ const names = (entry) => typeof entry === "string" && path30.resolve(here, entry) === overlay;
10603
+ const ws = json.workspaces;
10604
+ const list = Array.isArray(ws) ? ws : isObject5(ws) && Array.isArray(ws.packages) ? ws.packages : null;
10605
+ if (list?.some(names)) {
10606
+ const kept = list.filter((entry) => !names(entry));
10607
+ if (Array.isArray(ws)) json.workspaces = kept;
10608
+ else ws.packages = kept;
10609
+ touched2 = true;
10610
+ }
10611
+ if (!touched2) return null;
10612
+ const indent = /^[ \t]+(?=")/m.exec(text)?.[0] ?? " ";
10613
+ return JSON.stringify(json, null, indent) + (text.endsWith("\n") ? "\n" : "");
10614
+ }
10615
+ function applyOverlayPlans(root, plans, lockEdits = []) {
10173
10616
  const changed = [];
10617
+ const removedFolders = [];
10174
10618
  for (const plan of plans) {
10175
10619
  if (plan.skipped || plan.conflicts.length) continue;
10176
10620
  const dir = path30.join(root, plan.rel);
10177
10621
  if (plan.remove) {
10178
- for (const [file, text] of plan.pins) {
10179
- writeFileSync(path30.join(root, file), text);
10622
+ for (const file of plan.pins.keys()) {
10623
+ const abs = path30.join(root, file);
10624
+ const now = existsSync(abs) ? readFileSync(abs, "utf8") : null;
10625
+ const text = now === null ? plan.pins.get(file) : pinManifest(root, plan, file, now);
10626
+ if (typeof text !== "string") continue;
10627
+ writeFileSync(abs, text);
10180
10628
  changed.push(file);
10181
10629
  }
10182
10630
  rmSync(dir, { recursive: true, force: true });
10183
10631
  changed.push(`${plan.rel}/package.json`);
10632
+ removedFolders.push(dir);
10184
10633
  continue;
10185
10634
  }
10186
10635
  for (const [file, bytes] of plan.writes) {
@@ -10193,7 +10642,32 @@ function applyOverlayPlans(root, plans) {
10193
10642
  changed.push(`${plan.rel}/${file}`);
10194
10643
  }
10195
10644
  }
10196
- return changed;
10645
+ const edit = removedFolders.length ? dropRemovedWorkspaces(root, removedFolders) : null;
10646
+ if (edit) {
10647
+ lockEdits.push(edit);
10648
+ if (!edit.file.startsWith("..")) changed.push(edit.file);
10649
+ }
10650
+ return [...new Set(changed)];
10651
+ }
10652
+ function dropRemovedWorkspaces(root, folders) {
10653
+ const found = findLockfile(root);
10654
+ if (found?.pm !== "bun") return null;
10655
+ const text = readBunLock(found.dir);
10656
+ if (text === null) return null;
10657
+ const workspaces = [];
10658
+ const packages = [];
10659
+ try {
10660
+ for (const folder of folders) {
10661
+ const entries = workspaceEntries(text, path30.relative(found.dir, folder).split(path30.sep).join("/"));
10662
+ workspaces.push(...entries.workspaces);
10663
+ packages.push(...entries.packages);
10664
+ }
10665
+ } catch {
10666
+ return null;
10667
+ }
10668
+ if (!workspaces.length && !packages.length) return null;
10669
+ writeFileSync(path30.join(found.dir, BUN_LOCK), removeBunLockEntries(text, { workspaces, packages }));
10670
+ return { file: path30.relative(root, path30.join(found.dir, BUN_LOCK)).split(path30.sep).join("/"), workspaces };
10197
10671
  }
10198
10672
  function overlayChecklist(plans) {
10199
10673
  if (!plans.length) return [];
@@ -10225,6 +10699,8 @@ var init_overlays2 = __esm({
10225
10699
  init_local();
10226
10700
  init_overlays();
10227
10701
  init_upstream();
10702
+ init_bun_lock();
10703
+ init_pm();
10228
10704
  init_bump_core();
10229
10705
  GENESIS_REPOSITORY = "https://github.com/marktiderman/genesis.git";
10230
10706
  SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage", ".turbo", ".git"]);
@@ -10243,6 +10719,21 @@ __export(upgrade_exports, {
10243
10719
  releaseAgeError: () => releaseAgeError,
10244
10720
  runUpgrade: () => runUpgrade
10245
10721
  });
10722
+ function pruneBunLock(root, want, dryRun) {
10723
+ const found = findLockfile(root);
10724
+ if (found?.pm !== "bun") return null;
10725
+ const text = readBunLock(found.dir);
10726
+ if (text === null) return null;
10727
+ let pruned;
10728
+ try {
10729
+ pruned = staleNestedEntries(text, want);
10730
+ } catch {
10731
+ return null;
10732
+ }
10733
+ if (!pruned.length) return null;
10734
+ if (!dryRun) writeFileSync(path30.join(found.dir, BUN_LOCK), removeBunLockEntries(text, { packages: pruned.map((p) => p.key) }));
10735
+ return { file: path30.relative(root, path30.join(found.dir, BUN_LOCK)).split(path30.sep).join("/"), pruned };
10736
+ }
10246
10737
  function npm(args, cwd) {
10247
10738
  return execFileSync("npm", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
10248
10739
  }
@@ -10426,13 +10917,14 @@ async function runUpgrade(options) {
10426
10917
  if (text !== null && sha256(text) === entry.sha256) bases.set(file, text);
10427
10918
  }
10428
10919
  const files = /* @__PURE__ */ new Set();
10920
+ const lockEdits = [];
10429
10921
  const codemodRuns = [];
10430
10922
  if (!options.dryRun) {
10431
10923
  for (const [file, text] of bumped) {
10432
10924
  replaceApp(root, file, text);
10433
10925
  files.add(file);
10434
10926
  }
10435
- for (const file of applyOverlayPlans(root, overlays)) files.add(file);
10927
+ for (const file of applyOverlayPlans(root, overlays, lockEdits)) files.add(file);
10436
10928
  }
10437
10929
  for (const mod of mods) {
10438
10930
  log(`codemod ${mod.id}: ${mod.description}`);
@@ -10440,10 +10932,24 @@ async function runUpgrade(options) {
10440
10932
  codemodRuns.push({ id: mod.id, files: changed });
10441
10933
  for (const f of changed) files.add(f);
10442
10934
  }
10935
+ let bunLock;
10936
+ const prune = (want) => {
10937
+ const result = pruneBunLock(root, want, Boolean(options.dryRun));
10938
+ if (!result) return 0;
10939
+ bunLock ??= { file: result.file, pruned: [], workspaces: [], reinstalled: false };
10940
+ for (const p of result.pruned) if (!bunLock.pruned.some((q) => q.key === p.key)) bunLock.pruned.push(p);
10941
+ if (!options.dryRun && !result.file.startsWith("..")) files.add(result.file);
10942
+ return result.pruned.length;
10943
+ };
10944
+ prune((name) => pinned[name] ?? null);
10945
+ for (const edit of lockEdits) {
10946
+ bunLock ??= { file: edit.file, pruned: [], workspaces: [], reinstalled: false };
10947
+ bunLock.workspaces.push(...edit.workspaces);
10948
+ }
10443
10949
  const pm = detectPackageManager(root);
10444
10950
  let tidiedExcludes = null;
10445
10951
  const excludeWarnings = [];
10446
- if (!options.dryRun && options.install !== false && bumped.size) {
10952
+ if (!options.dryRun && options.install !== false && (bumped.size || bunLock)) {
10447
10953
  const workspaceFile = pm === "pnpm" ? pnpmWorkspaceFileFor(root) : null;
10448
10954
  const relWorkspace = workspaceFile ? path30.relative(realpathSync(root), workspaceFile) : null;
10449
10955
  const workspaceBefore = workspaceFile ? readText2(workspaceFile) : null;
@@ -10452,17 +10958,25 @@ async function runUpgrade(options) {
10452
10958
  tidiedExcludes = relWorkspace;
10453
10959
  log(`${tidiedExcludes}: minimumReleaseAgeExclude lists each Genesis package's pinned versions in one entry, exact versions the lockfile holds`);
10454
10960
  };
10455
- if (typeof options.install === "function") {
10456
- try {
10457
- options.install(root);
10458
- } catch (err) {
10459
- const e = err;
10460
- throw releaseAgeError([e.message, e.stdout, e.stderr].map((x) => x == null ? "" : String(x)).join("\n")) ?? err;
10961
+ const install = async () => {
10962
+ if (typeof options.install === "function") {
10963
+ try {
10964
+ options.install(root);
10965
+ } catch (err) {
10966
+ const e = err;
10967
+ throw releaseAgeError([e.message, e.stdout, e.stderr].map((x) => x == null ? "" : String(x)).join("\n")) ?? err;
10968
+ }
10969
+ } else {
10970
+ log(`install: ${shellLine(installCommand(pm))}`);
10971
+ await runInstall(root, installCommand(pm));
10461
10972
  }
10462
- } else {
10463
- log(`install: ${shellLine(installCommand(pm))}`);
10464
- await runInstall(root, installCommand(pm));
10973
+ };
10974
+ await install();
10975
+ if (prune(() => null)) {
10976
+ log(`${bunLock.file}: dropped nested Genesis copies the root's version satisfies; installing again`);
10977
+ await install();
10465
10978
  }
10979
+ if (bunLock) bunLock.reinstalled = true;
10466
10980
  tidy();
10467
10981
  const dedupe = options.dedupe ?? (typeof options.install === "function" ? false : true);
10468
10982
  const dedupeArgv = dedupeCommand(pm);
@@ -10596,11 +11110,17 @@ async function runUpgrade(options) {
10596
11110
  if (elsewhereEntries.length) lines.push("", `genesis.lock.json still lists ${elsewhereEntries.length} file${elsewhereEntries.length === 1 ? "" : "s"} under supabase/; they're left alone and can be deleted from the lock (and the folder).`);
10597
11111
  }
10598
11112
  if (tidiedExcludes) lines.push("", `pnpm pinned the new Genesis versions in \`${tidiedExcludes}\`'s \`minimumReleaseAgeExclude\` (they are younger than \`minimumReleaseAge\`). Each Genesis package now has one entry listing its exact versions in the lockfile (\`'name@1.0.0 || 1.1.0'\`), which \`pnpm install --frozen-lockfile\` honours; versions the lockfile no longer holds were dropped. Never a pattern, so a future Genesis release still waits out \`minimumReleaseAge\`. Other entries are as they were.`);
11113
+ if (bunLock) {
11114
+ lines.push("", `${bunLock.file}:`, "");
11115
+ for (const p of bunLock.pruned) lines.push(`- ${options.dryRun ? "would drop" : "dropped"} the nested copy of ${p.name}@${p.version} under ${p.parent} (\`${p.key}\`): the root's ${p.root} satisfies its ${p.range}, and two copies are two module instances`);
11116
+ for (const w of bunLock.workspaces) lines.push(`- dropped the workspace ${w}: the overlay there was deleted, and \`bun install\` stops on a workspace that isn't there`);
11117
+ lines.push(bunLock.reinstalled ? "- reinstalled (`bun install`), so the lockfile and node_modules match" : "- reinstall now: `bun install` (then `genesis doctor`), so node_modules holds one copy of each");
11118
+ }
10599
11119
  lines.push(...overlayChecklist(overlays));
10600
11120
  if (warnings.length) lines.push("", "Warnings:", "", ...warnings.map((w) => `- ${w}`));
10601
11121
  lines.push("", `\`genesis doctor\` ${doctor === "not run" ? "was not run" : doctor} after the upgrade.`);
10602
11122
  const summary = lines.join("\n");
10603
- const report = { version: release.version, changes, skipped, codemods: codemodRuns, breaks, refreshed, added, switchedOff, newMigrations, doctor, files: [...files].sort(), summary, overlays };
11123
+ const report = { version: release.version, changes, skipped, codemods: codemodRuns, breaks, refreshed, added, switchedOff, newMigrations, doctor, files: [...files].sort(), summary, overlays, ...bunLock ? { bunLock } : {} };
10604
11124
  if (options.pr && !options.dryRun && files.size) report.pr = openPullRequest(root, release.version, report, prBase);
10605
11125
  return report;
10606
11126
  }
@@ -10677,6 +11197,7 @@ var init_upgrade = __esm({
10677
11197
  init_bump_core();
10678
11198
  init_codemods();
10679
11199
  init_overlays2();
11200
+ init_bun_lock();
10680
11201
  EXACT_OR_TAG = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
10681
11202
  inside2 = (dir, file) => {
10682
11203
  const rel = path30.relative(dir, file);
@@ -10783,9 +11304,9 @@ async function runScaffold(opts, fs2) {
10783
11304
  function joinPath(...parts) {
10784
11305
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
10785
11306
  }
10786
- function dirname(path53) {
10787
- const idx = path53.lastIndexOf("/");
10788
- return idx === -1 ? "." : path53.slice(0, idx);
11307
+ function dirname(path56) {
11308
+ const idx = path56.lastIndexOf("/");
11309
+ return idx === -1 ? "." : path56.slice(0, idx);
10789
11310
  }
10790
11311
  function brandPackageJson(consumer, genesisVersion) {
10791
11312
  return JSON.stringify(
@@ -11274,7 +11795,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
11274
11795
  const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
11275
11796
  const root = path30.resolve(opts.dir);
11276
11797
  const packageJson = JSON.parse(await fs.readFile(path30.join(root, "package.json"), "utf-8").catch(() => "{}"));
11277
- const existsSync41 = (await import('fs')).existsSync;
11798
+ const existsSync43 = (await import('fs')).existsSync;
11278
11799
  const readSync = (await import('fs')).readFileSync;
11279
11800
  const readdirSync19 = (await import('fs')).readdirSync;
11280
11801
  if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
@@ -11283,8 +11804,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
11283
11804
  const plan = planStudioInit2(
11284
11805
  {
11285
11806
  packageJson,
11286
- exists: (p) => existsSync41(path30.join(root, p)),
11287
- read: (p) => existsSync41(path30.join(root, p)) ? readSync(path30.join(root, p), "utf-8") : null,
11807
+ exists: (p) => existsSync43(path30.join(root, p)),
11808
+ read: (p) => existsSync43(path30.join(root, p)) ? readSync(path30.join(root, p), "utf-8") : null,
11288
11809
  timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
11289
11810
  listDeep: (p) => {
11290
11811
  const out = [];
@@ -11324,14 +11845,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
11324
11845
  console.log(`+ ${file.path} (appended)`);
11325
11846
  continue;
11326
11847
  }
11327
- if (existsSync41(target) && !opts.force) {
11848
+ if (existsSync43(target) && !opts.force) {
11328
11849
  console.log(`= ${file.path} exists; left as it is (--force to replace)`);
11329
11850
  continue;
11330
11851
  }
11331
11852
  await fs.writeFile(target, file.content, "utf-8");
11332
11853
  console.log(`+ ${file.path}`);
11333
11854
  }
11334
- const pm = existsSync41(path30.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync41(path30.join(root, "yarn.lock")) ? "yarn add" : existsSync41(path30.join(root, "bun.lock")) || existsSync41(path30.join(root, "bun.lockb")) ? "bun add" : "npm install";
11855
+ const pm = existsSync43(path30.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync43(path30.join(root, "yarn.lock")) ? "yarn add" : existsSync43(path30.join(root, "bun.lock")) || existsSync43(path30.join(root, "bun.lockb")) ? "bun add" : "npm install";
11335
11856
  console.log("");
11336
11857
  console.log(`\u2714 The Data Studio is set up for ${{ next: "Next.js", "tanstack-start": "TanStack Start", "supabase-function": "a Supabase Edge Function" }[plan.host]}. To finish:`);
11337
11858
  console.log(` 1. ${pm} ${plan.install.map((p) => /[\s<>|]/.test(p) ? `"${p}"` : p).join(" ")}`);