@marktiderman/genesis-cli 1.18.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -2
- package/dist/cli.js +1363 -456
- package/dist/cli.js.map +1 -1
- package/dist/{config-1jP8eCZy.d.ts → config-Dj_f9T7J.d.ts} +14 -1
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +402 -40
- package/dist/doctor.js.map +1 -1
- package/dist/eslint.cjs +99 -0
- package/dist/eslint.cjs.map +1 -0
- package/dist/eslint.d.cts +68 -0
- package/dist/eslint.d.ts +68 -0
- package/dist/eslint.js +72 -0
- package/dist/eslint.js.map +1 -0
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +18 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +30 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +410 -48
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +18 -0
- package/dist/starter/__tests__/components/gestures.test.tsx +64 -0
- package/dist/starter/__tests__/components/resolver.js +14 -2
- package/dist/starter/__tests__/components/setup.ts +5 -0
- package/dist/starter/__tests__/starter.test.ts +27 -7
- package/dist/starter/eslint.config.js +8 -1
- package/dist/starter/jest.config.js +3 -0
- package/dist/starter/nativewind-env.d.ts +1 -0
- package/dist/starter/package.json +3 -0
- package/dist/starter/src/lib/link-hosts.ts +7 -3
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +7 -2
- package/dist/starter/supabase/migrations/20261024000700_genesis_support_findings.sql +339 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +1 -1
- package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +219 -0
- package/dist/templates/ci/genesis-upgrade.yml +1 -0
- package/dist/vite.js +402 -40
- package/dist/vite.js.map +1 -1
- package/package.json +18 -4
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, mkdirSync, writeFileSync, mkdtempSync, rmSync, realpathSync, statSync, lstatSync } from 'fs';
|
|
3
|
-
import * as
|
|
3
|
+
import * as path30 from 'path';
|
|
4
4
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
@@ -26,7 +26,7 @@ var __export = (target, all) => {
|
|
|
26
26
|
function buildCatalog(packagesDir) {
|
|
27
27
|
const packages = {};
|
|
28
28
|
for (const dir of readdirSync(packagesDir).sort()) {
|
|
29
|
-
const file =
|
|
29
|
+
const file = path30.join(packagesDir, dir, "package.json");
|
|
30
30
|
if (!existsSync(file)) continue;
|
|
31
31
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
32
32
|
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
@@ -101,6 +101,26 @@ function parseManifest(home, id, raw, version, options = {}) {
|
|
|
101
101
|
const file = pathOf(m["file"], `${where2}.file`);
|
|
102
102
|
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
103
103
|
const out = { package: pkgOf(m["package"], where2), file };
|
|
104
|
+
if (m["provides"] !== void 0) {
|
|
105
|
+
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
106
|
+
else {
|
|
107
|
+
out.provides = m["provides"].map((p, j) => {
|
|
108
|
+
const at2 = `${where2}.provides[${j}]`;
|
|
109
|
+
if (!isObject(p)) {
|
|
110
|
+
problems.push(`${at2}: must be an object`);
|
|
111
|
+
return { package: home, file: "" };
|
|
112
|
+
}
|
|
113
|
+
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
114
|
+
if (p["functions"] !== void 0) {
|
|
115
|
+
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
116
|
+
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
117
|
+
}
|
|
118
|
+
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
119
|
+
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
120
|
+
return provided;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
104
124
|
if (m["test"] !== void 0) {
|
|
105
125
|
out.test = pathOf(m["test"], `${where2}.test`);
|
|
106
126
|
if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where2}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
|
|
@@ -235,14 +255,14 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
235
255
|
}
|
|
236
256
|
});
|
|
237
257
|
function inside(parent, child) {
|
|
238
|
-
const rel =
|
|
239
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
258
|
+
const rel = path30.relative(parent, child);
|
|
259
|
+
return rel === "" || !rel.startsWith("..") && !path30.isAbsolute(rel);
|
|
240
260
|
}
|
|
241
261
|
function readPackageFile(packageDir2, rel) {
|
|
242
262
|
const safe = safeRelative(rel);
|
|
243
263
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
244
264
|
const root = realpathSync(packageDir2);
|
|
245
|
-
const file =
|
|
265
|
+
const file = path30.join(root, ...safe.split("/"));
|
|
246
266
|
if (!existsSync(file)) return null;
|
|
247
267
|
const real2 = realpathSync(file);
|
|
248
268
|
if (!inside(root, real2)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
|
|
@@ -253,7 +273,7 @@ function readPackageDir(packageDir2, rel, skipped = []) {
|
|
|
253
273
|
const safe = safeRelative(rel);
|
|
254
274
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
255
275
|
const root = realpathSync(packageDir2);
|
|
256
|
-
const dir =
|
|
276
|
+
const dir = path30.join(root, ...safe.split("/"));
|
|
257
277
|
if (!existsSync(dir)) return null;
|
|
258
278
|
const real2 = realpathSync(dir);
|
|
259
279
|
if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
|
|
@@ -273,7 +293,7 @@ function appPath(root, rel) {
|
|
|
273
293
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
274
294
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
275
295
|
const realRoot = realpathSync(root);
|
|
276
|
-
const target =
|
|
296
|
+
const target = path30.join(realRoot, ...safe.split("/"));
|
|
277
297
|
const there = (p) => {
|
|
278
298
|
try {
|
|
279
299
|
lstatSync(p);
|
|
@@ -282,13 +302,13 @@ function appPath(root, rel) {
|
|
|
282
302
|
return false;
|
|
283
303
|
}
|
|
284
304
|
};
|
|
285
|
-
let probe =
|
|
286
|
-
while (!there(probe)) probe =
|
|
305
|
+
let probe = path30.dirname(target);
|
|
306
|
+
while (!there(probe)) probe = path30.dirname(probe);
|
|
287
307
|
let real2;
|
|
288
308
|
try {
|
|
289
309
|
real2 = realpathSync(probe);
|
|
290
310
|
} catch {
|
|
291
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
311
|
+
throw new Error(`${rel} goes through a broken symlink (${path30.relative(realRoot, probe)}); refused`);
|
|
292
312
|
}
|
|
293
313
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
294
314
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
@@ -300,20 +320,20 @@ function readApp(root, rel) {
|
|
|
300
320
|
}
|
|
301
321
|
function createApp(root, rel, content) {
|
|
302
322
|
const file = appPath(root, rel);
|
|
303
|
-
mkdirSync(
|
|
323
|
+
mkdirSync(path30.dirname(file), { recursive: true });
|
|
304
324
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
305
325
|
}
|
|
306
326
|
function replaceApp(root, rel, content) {
|
|
307
327
|
const file = appPath(root, rel);
|
|
308
|
-
mkdirSync(
|
|
328
|
+
mkdirSync(path30.dirname(file), { recursive: true });
|
|
309
329
|
writeFileSync(file, content, "utf8");
|
|
310
330
|
}
|
|
311
331
|
function listApp(root, rel, options = {}) {
|
|
312
|
-
const dir =
|
|
332
|
+
const dir = path30.join(root, rel);
|
|
313
333
|
if (!existsSync(dir)) return [];
|
|
314
334
|
const out = [];
|
|
315
335
|
const walk3 = (r) => {
|
|
316
|
-
for (const entry of readdirSync(
|
|
336
|
+
for (const entry of readdirSync(path30.join(root, r), { withFileTypes: true })) {
|
|
317
337
|
const child = `${r}/${entry.name}`;
|
|
318
338
|
if (entry.isDirectory()) walk3(child);
|
|
319
339
|
else if (entry.isFile() || options.symlinks && entry.isSymbolicLink()) out.push(child);
|
|
@@ -334,8 +354,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
334
354
|
return raw.map((entry, i) => {
|
|
335
355
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
336
356
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
337
|
-
if (
|
|
338
|
-
const norm =
|
|
357
|
+
if (path30.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
358
|
+
const norm = path30.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
339
359
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
340
360
|
const parts = norm.split("/");
|
|
341
361
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -346,7 +366,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
346
366
|
});
|
|
347
367
|
}
|
|
348
368
|
function localPackageGlobs(root) {
|
|
349
|
-
const file =
|
|
369
|
+
const file = path30.join(root, "genesis.config.json");
|
|
350
370
|
if (!existsSync(file)) return [];
|
|
351
371
|
let raw;
|
|
352
372
|
try {
|
|
@@ -359,14 +379,14 @@ function localPackageGlobs(root) {
|
|
|
359
379
|
}
|
|
360
380
|
function repositoryRoot(appRoot) {
|
|
361
381
|
for (let dir = appRoot; ; ) {
|
|
362
|
-
if (existsSync(
|
|
363
|
-
const parent =
|
|
382
|
+
if (existsSync(path30.join(dir, ".git"))) return dir;
|
|
383
|
+
const parent = path30.dirname(dir);
|
|
364
384
|
if (parent === dir) return appRoot;
|
|
365
385
|
dir = parent;
|
|
366
386
|
}
|
|
367
387
|
}
|
|
368
388
|
function localPackages(root) {
|
|
369
|
-
const appRoot =
|
|
389
|
+
const appRoot = path30.resolve(root);
|
|
370
390
|
const globs = localPackageGlobs(appRoot);
|
|
371
391
|
const key2 = `${appRoot}
|
|
372
392
|
${globs.join("\n")}`;
|
|
@@ -375,24 +395,24 @@ ${globs.join("\n")}`;
|
|
|
375
395
|
const dirs = /* @__PURE__ */ new Set();
|
|
376
396
|
for (const glob of globs) {
|
|
377
397
|
if (glob.endsWith("/*") || glob === "*") {
|
|
378
|
-
const parent =
|
|
398
|
+
const parent = path30.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
379
399
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
380
400
|
for (const entry of readdirSync(parent).sort()) {
|
|
381
401
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
382
|
-
dirs.add(
|
|
402
|
+
dirs.add(path30.join(parent, entry));
|
|
383
403
|
}
|
|
384
404
|
} else {
|
|
385
|
-
dirs.add(
|
|
405
|
+
dirs.add(path30.join(appRoot, glob));
|
|
386
406
|
}
|
|
387
407
|
}
|
|
388
408
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
389
409
|
const out = [];
|
|
390
410
|
const byName = /* @__PURE__ */ new Map();
|
|
391
411
|
for (const dir of [...dirs].sort()) {
|
|
392
|
-
const manifest =
|
|
412
|
+
const manifest = path30.join(dir, "package.json");
|
|
393
413
|
if (!existsSync(manifest)) continue;
|
|
394
414
|
if (!inside(real2, realpathSync(dir))) {
|
|
395
|
-
throw new LocalPackagesError(`${
|
|
415
|
+
throw new LocalPackagesError(`${path30.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
396
416
|
}
|
|
397
417
|
let pkg;
|
|
398
418
|
try {
|
|
@@ -401,7 +421,7 @@ ${globs.join("\n")}`;
|
|
|
401
421
|
continue;
|
|
402
422
|
}
|
|
403
423
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
404
|
-
const rel =
|
|
424
|
+
const rel = path30.relative(appRoot, dir).split(path30.sep).join("/");
|
|
405
425
|
const other = byName.get(pkg.name);
|
|
406
426
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
407
427
|
byName.set(pkg.name, rel);
|
|
@@ -444,41 +464,41 @@ __export(discover_exports, {
|
|
|
444
464
|
workspacePackagesDir: () => workspacePackagesDir
|
|
445
465
|
});
|
|
446
466
|
function cliPackageDir() {
|
|
447
|
-
let dir =
|
|
467
|
+
let dir = path30.dirname(fileURLToPath(import.meta.url));
|
|
448
468
|
for (; ; ) {
|
|
449
|
-
const file =
|
|
469
|
+
const file = path30.join(dir, "package.json");
|
|
450
470
|
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
451
|
-
const parent =
|
|
471
|
+
const parent = path30.dirname(dir);
|
|
452
472
|
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
453
473
|
dir = parent;
|
|
454
474
|
}
|
|
455
475
|
}
|
|
456
476
|
function workspacePackagesDir() {
|
|
457
|
-
const dir =
|
|
458
|
-
return existsSync(
|
|
477
|
+
const dir = path30.resolve(cliPackageDir(), "..");
|
|
478
|
+
return existsSync(path30.join(dir, "features", "package.json")) && existsSync(path30.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
459
479
|
}
|
|
460
480
|
function readCatalog() {
|
|
461
481
|
if (catalogCache) return catalogCache;
|
|
462
482
|
const workspace = workspacePackagesDir();
|
|
463
483
|
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
464
|
-
const file =
|
|
484
|
+
const file = path30.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
465
485
|
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
466
486
|
return catalogCache;
|
|
467
487
|
}
|
|
468
488
|
function installedGenesis(root) {
|
|
469
489
|
const found = /* @__PURE__ */ new Map();
|
|
470
|
-
let dir =
|
|
490
|
+
let dir = path30.resolve(root);
|
|
471
491
|
for (; ; ) {
|
|
472
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
473
|
-
const scope =
|
|
492
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path30.join(dir, m)));
|
|
493
|
+
const scope = path30.join(dir, "node_modules", "@marktiderman");
|
|
474
494
|
if (existsSync(scope)) {
|
|
475
495
|
for (const entry of readdirSync(scope)) {
|
|
476
496
|
const name = `@marktiderman/${entry}`;
|
|
477
497
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
478
|
-
if (existsSync(
|
|
498
|
+
if (existsSync(path30.join(scope, entry, "package.json"))) found.set(name, path30.join(scope, entry));
|
|
479
499
|
}
|
|
480
500
|
}
|
|
481
|
-
const parent =
|
|
501
|
+
const parent = path30.dirname(dir);
|
|
482
502
|
if (atInstallRoot || parent === dir) return found;
|
|
483
503
|
dir = parent;
|
|
484
504
|
}
|
|
@@ -492,10 +512,10 @@ function packageDir(root, name) {
|
|
|
492
512
|
return null;
|
|
493
513
|
}
|
|
494
514
|
function packageVersion(dir) {
|
|
495
|
-
return JSON.parse(readFileSync(
|
|
515
|
+
return JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8")).version;
|
|
496
516
|
}
|
|
497
517
|
function declarationsOf(dir, warnings) {
|
|
498
|
-
const pkg = JSON.parse(readFileSync(
|
|
518
|
+
const pkg = JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8"));
|
|
499
519
|
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
500
520
|
let cached = declarationCache.get(key2);
|
|
501
521
|
if (!cached) {
|
|
@@ -505,15 +525,15 @@ function declarationsOf(dir, warnings) {
|
|
|
505
525
|
return cached;
|
|
506
526
|
}
|
|
507
527
|
async function loadDeclarations(dir, warnings) {
|
|
508
|
-
const pkg = JSON.parse(readFileSync(
|
|
528
|
+
const pkg = JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8"));
|
|
509
529
|
const entry = pkg.exports?.["./blocks"];
|
|
510
530
|
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
511
531
|
if (typeof target !== "string") return {};
|
|
512
532
|
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
513
|
-
const file = rel &&
|
|
533
|
+
const file = rel && path30.join(dir, ...rel.split("/"));
|
|
514
534
|
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
515
535
|
try {
|
|
516
|
-
const jiti = createJiti(
|
|
536
|
+
const jiti = createJiti(path30.join(dir, "package.json"), { moduleCache: false });
|
|
517
537
|
const mod = await jiti.import(file);
|
|
518
538
|
const out = {};
|
|
519
539
|
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
@@ -524,18 +544,28 @@ async function loadDeclarations(dir, warnings) {
|
|
|
524
544
|
}
|
|
525
545
|
}
|
|
526
546
|
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
527
|
-
const pkg = JSON.parse(readFileSync(
|
|
547
|
+
const pkg = JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8"));
|
|
528
548
|
const raw = rawBlocksOf(pkg);
|
|
529
549
|
const declared = await declarationsOf(dir, warnings);
|
|
530
550
|
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
531
551
|
const out = [];
|
|
532
552
|
for (const id of [...ids].sort()) {
|
|
533
553
|
const fromJson = raw[id] ?? {};
|
|
534
|
-
const
|
|
554
|
+
const merged = { ...fromJson, ...declared[id] };
|
|
555
|
+
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
556
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
535
557
|
if (manifest) out.push(manifest);
|
|
536
558
|
}
|
|
537
559
|
return out;
|
|
538
560
|
}
|
|
561
|
+
function withProvides(declared, json) {
|
|
562
|
+
if (!Array.isArray(declared)) return declared;
|
|
563
|
+
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
564
|
+
return declared.map((m) => {
|
|
565
|
+
const same2 = json.find((j) => fileOf(j) === fileOf(m));
|
|
566
|
+
return same2?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same2["provides"] } : m;
|
|
567
|
+
});
|
|
568
|
+
}
|
|
539
569
|
async function allBlocks(root, warnings = []) {
|
|
540
570
|
const out = [];
|
|
541
571
|
for (const local of localPackages(root)) {
|
|
@@ -608,7 +638,7 @@ function emptyLock() {
|
|
|
608
638
|
return { version: 1, blocks: {}, files: {} };
|
|
609
639
|
}
|
|
610
640
|
function readLock(root) {
|
|
611
|
-
const file =
|
|
641
|
+
const file = path30.join(root, LOCK_FILE);
|
|
612
642
|
if (!existsSync(file)) return emptyLock();
|
|
613
643
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
614
644
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -665,10 +695,12 @@ __export(migrations_exports, {
|
|
|
665
695
|
nextStamp: () => nextStamp,
|
|
666
696
|
nextTimestamps: () => nextTimestamps,
|
|
667
697
|
planMigrations: () => planMigrations,
|
|
698
|
+
providingMigrations: () => providingMigrations,
|
|
668
699
|
readAppMigrations: () => readAppMigrations,
|
|
669
700
|
rememberMigrationCopies: () => rememberMigrationCopies,
|
|
670
701
|
stemOf: () => stemOf,
|
|
671
702
|
stemOrNull: () => stemOrNull,
|
|
703
|
+
supersededFunctions: () => supersededFunctions,
|
|
672
704
|
textSha: () => textSha,
|
|
673
705
|
timestampOf: () => timestampOf,
|
|
674
706
|
validHeaderFile: () => validHeaderFile
|
|
@@ -679,7 +711,7 @@ function migrationHeader(pkg, file, source) {
|
|
|
679
711
|
`;
|
|
680
712
|
}
|
|
681
713
|
function stemOrNull(file) {
|
|
682
|
-
return MIGRATION_FILE.exec(
|
|
714
|
+
return MIGRATION_FILE.exec(path30.posix.basename(file))?.[2] ?? null;
|
|
683
715
|
}
|
|
684
716
|
function stemOf(file) {
|
|
685
717
|
const stem = stemOrNull(file);
|
|
@@ -689,7 +721,7 @@ function stemOf(file) {
|
|
|
689
721
|
function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
690
722
|
return listApp(root, dir, { symlinks: true }).filter((p) => p.endsWith(".sql")).map((p) => {
|
|
691
723
|
const content = readApp(root, p) ?? "";
|
|
692
|
-
const name =
|
|
724
|
+
const name = path30.posix.basename(p);
|
|
693
725
|
const m = HEADER.exec(content);
|
|
694
726
|
if (m) return { path: p, name, content, tracked: { package: m[1], file: m[2], sha256: m[3], body: content.slice(m[0].length) } };
|
|
695
727
|
const f = FORWARD.exec(content);
|
|
@@ -698,7 +730,28 @@ function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
|
698
730
|
});
|
|
699
731
|
}
|
|
700
732
|
function needsAttention(row) {
|
|
701
|
-
return row.state !== "current" && row.state !== "new" && row.state !== "deleted" && !row.forward;
|
|
733
|
+
return row.state !== "current" && row.state !== "new" && row.state !== "deleted" && row.state !== "provided" && !row.forward;
|
|
734
|
+
}
|
|
735
|
+
function supersededFunctions(rows, providers) {
|
|
736
|
+
const out = /* @__PURE__ */ new Map();
|
|
737
|
+
for (const row of rows) {
|
|
738
|
+
if (row.state !== "provided" || !row.providedBy) continue;
|
|
739
|
+
const by = providers.find((p) => p.package === row.providedBy.package && p.file === row.providedBy.file);
|
|
740
|
+
const entry = by?.provides.find((x) => x.package === row.package && x.file === row.file);
|
|
741
|
+
for (const dir of entry?.functions ?? []) out.set(`${row.package}:${dir}`, row.providedBy);
|
|
742
|
+
}
|
|
743
|
+
return out;
|
|
744
|
+
}
|
|
745
|
+
function providingMigrations(manifests) {
|
|
746
|
+
const out = [];
|
|
747
|
+
for (const m of manifests) {
|
|
748
|
+
for (const mig of m.migrations) {
|
|
749
|
+
if (!mig.provides?.length || out.some((o) => o.package === mig.package && o.file === mig.file)) continue;
|
|
750
|
+
const block = m.id ?? mig.block;
|
|
751
|
+
out.push({ ...block ? { block } : {}, package: mig.package, file: mig.file, provides: mig.provides });
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return out;
|
|
702
755
|
}
|
|
703
756
|
function timestampOf(date) {
|
|
704
757
|
return date.toISOString().replace(/\D/g, "").slice(0, 14);
|
|
@@ -731,6 +784,16 @@ function nextTimestamps(existing, now, count) {
|
|
|
731
784
|
function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date() }) {
|
|
732
785
|
const app = readAppMigrations(root);
|
|
733
786
|
const rows = [];
|
|
787
|
+
const providers = providingMigrations([{ migrations: sources }]);
|
|
788
|
+
for (const p of options.providers ?? []) if (!providers.some((o) => o.package === p.package && o.file === p.file)) providers.push(p);
|
|
789
|
+
const providerAt = (p) => {
|
|
790
|
+
const stem = stemOrNull(p.file);
|
|
791
|
+
const copy = app.find((m) => !m.forward && (m.tracked ? m.tracked.package === p.package && m.tracked.file === p.file : stem !== null && m.name.replace(/^\d+_/, "") === `${stem}.sql`));
|
|
792
|
+
if (copy) return copy.path;
|
|
793
|
+
const copied = options.copied?.[migrationKey(p.package, p.file)];
|
|
794
|
+
if (copied) return app.some((m) => m.path === copied) ? copied : null;
|
|
795
|
+
return sources.some((s) => s.package === p.package && s.file === p.file && s.source !== null) ? "this run" : null;
|
|
796
|
+
};
|
|
734
797
|
const pending = [];
|
|
735
798
|
const seen = /* @__PURE__ */ new Set();
|
|
736
799
|
for (const src of sources) {
|
|
@@ -758,6 +821,12 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
758
821
|
continue;
|
|
759
822
|
}
|
|
760
823
|
if (!copy) {
|
|
824
|
+
const by = providers.find((p) => p.provides.some((x) => x.package === src.package && x.file === src.file) && providerAt(p) !== null);
|
|
825
|
+
if (by) {
|
|
826
|
+
const at = providerAt(by);
|
|
827
|
+
rows.push({ ...base, state: "provided", providedBy: { package: by.package, file: by.file }, detail: `${by.package} ${by.file} provides its objects (${at === "this run" ? "copied in this run" : at}); not copied` });
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
761
830
|
const row2 = { ...base, state: "new" };
|
|
762
831
|
rows.push(row2);
|
|
763
832
|
pending.push({ row: row2, src, kind: "migration" });
|
|
@@ -776,7 +845,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
776
845
|
detail = copy.tracked ? renamed.trim() : "copied before headers; matches the package";
|
|
777
846
|
} else if (copy.tracked) {
|
|
778
847
|
state = "changed-upstream";
|
|
779
|
-
detail = `${src.package} now ships a different ${
|
|
848
|
+
detail = `${src.package} now ships a different ${path30.posix.basename(src.file)}; the applied copy is never rewritten`;
|
|
780
849
|
} else {
|
|
781
850
|
state = "differs";
|
|
782
851
|
detail = "has the package migration's name but other text and no header; treated as the app's own";
|
|
@@ -798,7 +867,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
798
867
|
row.target = target2;
|
|
799
868
|
creates.push({ path: target2, content: migrationHeader(src.package, src.file, src.source) + src.source, kind, source: { package: src.package, file: src.file } });
|
|
800
869
|
if (options.tests !== false && src.test && src.testSource != null) {
|
|
801
|
-
const test2 = `${TESTS_DIR}/${
|
|
870
|
+
const test2 = `${TESTS_DIR}/${path30.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
|
|
802
871
|
if (readApp(root, test2) === null && !creates.some((c) => c.path === test2)) creates.push({ path: test2, content: src.testSource, kind: "test", source: { package: src.package, file: src.test } });
|
|
803
872
|
}
|
|
804
873
|
return;
|
|
@@ -844,7 +913,7 @@ function validHeaderFile(file) {
|
|
|
844
913
|
}
|
|
845
914
|
function formatMigrationRows(rows) {
|
|
846
915
|
if (!rows.length) return "No package migrations to compare.";
|
|
847
|
-
const mark = { current: "=", new: "+", edited: "!", "changed-upstream": "!", differs: "!", deleted: "!", unavailable: "?" };
|
|
916
|
+
const mark = { current: "=", new: "+", edited: "!", "changed-upstream": "!", differs: "!", deleted: "!", provided: "=", unavailable: "?" };
|
|
848
917
|
return rows.map((r) => {
|
|
849
918
|
const where2 = r.target ? ` \u2192 ${r.target}` : r.copy ? ` (${r.copy})` : "";
|
|
850
919
|
const fwd = r.forward && !r.target ? `; carried by ${r.forward}` : "";
|
|
@@ -882,32 +951,33 @@ __export(config_exports, {
|
|
|
882
951
|
readGenesisConfig: () => readGenesisConfig,
|
|
883
952
|
validateConfig: () => validateConfig,
|
|
884
953
|
validateLinks: () => validateLinks,
|
|
885
|
-
validatePrivacy: () => validatePrivacy
|
|
954
|
+
validatePrivacy: () => validatePrivacy,
|
|
955
|
+
validateSupabase: () => validateSupabase
|
|
886
956
|
});
|
|
887
957
|
function privacyDataType(type) {
|
|
888
958
|
return PRIVACY_DATA_TYPES[type.toLowerCase()];
|
|
889
959
|
}
|
|
890
960
|
function appPath2(v, where2, fail) {
|
|
891
961
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
892
|
-
if (
|
|
893
|
-
const norm =
|
|
962
|
+
if (path30.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
963
|
+
const norm = path30.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
894
964
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
895
965
|
return norm;
|
|
896
966
|
}
|
|
897
967
|
function loadConfig(root, configPath) {
|
|
898
968
|
if (configPath) {
|
|
899
|
-
const file =
|
|
969
|
+
const file = path30.resolve(root, configPath);
|
|
900
970
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
901
971
|
const json = readJson(file);
|
|
902
|
-
const block =
|
|
903
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
972
|
+
const block = path30.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
973
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path30.dirname(file) };
|
|
904
974
|
}
|
|
905
|
-
const own =
|
|
975
|
+
const own = path30.join(root, "genesis.config.json");
|
|
906
976
|
if (existsSync(own)) {
|
|
907
977
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
908
978
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
909
979
|
}
|
|
910
|
-
const pkg =
|
|
980
|
+
const pkg = path30.join(root, "package.json");
|
|
911
981
|
if (existsSync(pkg)) {
|
|
912
982
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
913
983
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -916,7 +986,7 @@ function loadConfig(root, configPath) {
|
|
|
916
986
|
}
|
|
917
987
|
function doctorBlock(json, file, explicit) {
|
|
918
988
|
const j = json;
|
|
919
|
-
if (
|
|
989
|
+
if (path30.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
920
990
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
921
991
|
}
|
|
922
992
|
function isPackageDeclaration(block) {
|
|
@@ -933,15 +1003,33 @@ function readJson(file) {
|
|
|
933
1003
|
}
|
|
934
1004
|
}
|
|
935
1005
|
function readGenesisConfig(root) {
|
|
936
|
-
const file =
|
|
1006
|
+
const file = path30.join(root, "genesis.config.json");
|
|
937
1007
|
if (!existsSync(file)) return null;
|
|
938
1008
|
const raw = readJson(file);
|
|
939
1009
|
if (!isObject2(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
940
1010
|
const out = { raw };
|
|
941
1011
|
if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
|
|
942
1012
|
if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
|
|
1013
|
+
if (raw.supabase !== void 0) {
|
|
1014
|
+
const supabase = validateSupabase(raw.supabase, file);
|
|
1015
|
+
if (supabase !== true) out.supabase = supabase;
|
|
1016
|
+
}
|
|
943
1017
|
return out;
|
|
944
1018
|
}
|
|
1019
|
+
function validateSupabase(raw, source = "config") {
|
|
1020
|
+
const fail = (msg) => {
|
|
1021
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
1022
|
+
};
|
|
1023
|
+
if (typeof raw === "boolean") return raw ? true : false;
|
|
1024
|
+
if (!isObject2(raw)) return fail(`"supabase" must be false or { "app": "<the folder of the app that holds supabase/>" }`);
|
|
1025
|
+
for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
|
|
1026
|
+
const app = raw.app;
|
|
1027
|
+
if (typeof app !== "string" || !app.trim()) return fail(`supabase.app must be the folder of the app that holds supabase/, relative to this one (e.g. "../app")`);
|
|
1028
|
+
if (path30.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
|
|
1029
|
+
const norm = path30.posix.normalize(app).replace(/\/+$/, "");
|
|
1030
|
+
if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
|
|
1031
|
+
return { app: norm };
|
|
1032
|
+
}
|
|
945
1033
|
function validatePrivacy(raw, source = "config") {
|
|
946
1034
|
const fail = (msg) => {
|
|
947
1035
|
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
@@ -1094,7 +1182,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1094
1182
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1095
1183
|
if (contracts.out !== void 0) {
|
|
1096
1184
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1097
|
-
if (
|
|
1185
|
+
if (path30.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1098
1186
|
}
|
|
1099
1187
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1100
1188
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1230,12 +1318,104 @@ var init_config = __esm({
|
|
|
1230
1318
|
HOST = /^(?=.{1,253}$)(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
1231
1319
|
}
|
|
1232
1320
|
});
|
|
1321
|
+
function databaseElsewhere(root) {
|
|
1322
|
+
const setting = readGenesisConfig(root)?.supabase;
|
|
1323
|
+
if (setting === void 0) return null;
|
|
1324
|
+
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
1325
|
+
const resolved = path30.resolve(root, setting.app);
|
|
1326
|
+
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
1327
|
+
const dir = real2(resolved);
|
|
1328
|
+
if (dir === real2(path30.resolve(root))) throw new GenesisConfigError(`${path30.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
|
|
1329
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path30.join(dir, "supabase")) };
|
|
1330
|
+
}
|
|
1331
|
+
function isSupabasePath(rel) {
|
|
1332
|
+
return rel === "supabase" || rel.startsWith("supabase/");
|
|
1333
|
+
}
|
|
1334
|
+
function elsewhereNote(home, command = "genesis migrate") {
|
|
1335
|
+
if (!home.app) return `This app has no database files (genesis.config.json "supabase": false), so no Supabase files are written or planned here.`;
|
|
1336
|
+
return `This app's database files live in ${home.app}/supabase (genesis.config.json supabase.app), so no Supabase files are written or planned here: run ${command} in ${home.app}.`;
|
|
1337
|
+
}
|
|
1338
|
+
function blocksMissingThere(home, ids, manifests) {
|
|
1339
|
+
const missing = migrationsMissingThere(home, ids, manifests);
|
|
1340
|
+
if (!missing) return null;
|
|
1341
|
+
return ids.filter((id) => missing.some((m) => m.block === id));
|
|
1342
|
+
}
|
|
1343
|
+
function migrationsMissingThere(home, ids, manifests) {
|
|
1344
|
+
if (!home.dir) return null;
|
|
1345
|
+
let copied;
|
|
1346
|
+
let app;
|
|
1347
|
+
try {
|
|
1348
|
+
copied = readLock(home.dir).migrations ?? {};
|
|
1349
|
+
app = readAppMigrations(home.dir);
|
|
1350
|
+
} catch {
|
|
1351
|
+
return null;
|
|
1352
|
+
}
|
|
1353
|
+
const has2 = (pkg, file) => {
|
|
1354
|
+
if (Object.hasOwn(copied, migrationKey(pkg, file))) return true;
|
|
1355
|
+
const stem = stemOrNull(file);
|
|
1356
|
+
return app.some((m) => !m.forward && (m.tracked ? m.tracked.package === pkg && m.tracked.file === file : stem !== null && m.name.replace(/^\d+_/, "") === `${stem}.sql`));
|
|
1357
|
+
};
|
|
1358
|
+
const providers = providingMigrations(manifests);
|
|
1359
|
+
const out = [];
|
|
1360
|
+
for (const id of ids) {
|
|
1361
|
+
const m = manifests.find((b) => b.id === id);
|
|
1362
|
+
if (!m) continue;
|
|
1363
|
+
const superseded = /* @__PURE__ */ new Set();
|
|
1364
|
+
for (const mig of m.migrations) {
|
|
1365
|
+
if (has2(mig.package, mig.file)) continue;
|
|
1366
|
+
const by = providers.find((p) => has2(p.package, p.file) && p.provides.some((x) => x.package === mig.package && x.file === mig.file));
|
|
1367
|
+
if (by) {
|
|
1368
|
+
for (const dir of by.provides.find((x) => x.package === mig.package && x.file === mig.file)?.functions ?? []) superseded.add(`${mig.package}:${dir}`);
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
out.push({ block: id, what: `${mig.package} ${mig.file}`, kind: "migration" });
|
|
1372
|
+
}
|
|
1373
|
+
for (const fn of m.functions) {
|
|
1374
|
+
if (superseded.has(`${fn.package}:${fn.dir}`)) continue;
|
|
1375
|
+
if (!existsSync(path30.join(home.dir, "supabase", "functions", fn.dir.split("/").pop()))) out.push({ block: id, what: `${fn.package} ${fn.dir}`, kind: "function" });
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return out;
|
|
1379
|
+
}
|
|
1380
|
+
function orderForAdding(ids, manifests) {
|
|
1381
|
+
const byId = new Map(manifests.map((m) => [m.id, m]));
|
|
1382
|
+
const before = (id) => {
|
|
1383
|
+
const m = byId.get(id);
|
|
1384
|
+
if (!m) return [];
|
|
1385
|
+
const providers = manifests.filter((p) => p.id !== id && p.migrations.some((pm) => pm.provides?.some((x) => m.migrations.some((mm) => mm.package === x.package && mm.file === x.file))));
|
|
1386
|
+
return [...m.requires, ...providers.map((p) => p.id)].filter((x) => ids.includes(x));
|
|
1387
|
+
};
|
|
1388
|
+
const out = [];
|
|
1389
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
1390
|
+
const visit = (id) => {
|
|
1391
|
+
if (out.includes(id) || visiting.has(id)) return;
|
|
1392
|
+
visiting.add(id);
|
|
1393
|
+
for (const b of before(id)) visit(b);
|
|
1394
|
+
out.push(id);
|
|
1395
|
+
};
|
|
1396
|
+
for (const id of ids) visit(id);
|
|
1397
|
+
return out;
|
|
1398
|
+
}
|
|
1399
|
+
function addThereCommand(id) {
|
|
1400
|
+
return `genesis add ${id} --database-only`;
|
|
1401
|
+
}
|
|
1402
|
+
function addThereLine(home, ids) {
|
|
1403
|
+
if (!home.app || !ids.length) return null;
|
|
1404
|
+
return `In ${home.app} (it holds this app's database), run: ${ids.map(addThereCommand).join(" && ")}`;
|
|
1405
|
+
}
|
|
1406
|
+
var init_database = __esm({
|
|
1407
|
+
"src/blocks/database.ts"() {
|
|
1408
|
+
init_config();
|
|
1409
|
+
init_lock();
|
|
1410
|
+
init_migrations();
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1233
1413
|
function findPackageDir(from, name) {
|
|
1234
|
-
let dir =
|
|
1414
|
+
let dir = path30.resolve(from);
|
|
1235
1415
|
for (; ; ) {
|
|
1236
|
-
const candidate =
|
|
1237
|
-
if (existsSync(
|
|
1238
|
-
const parent =
|
|
1416
|
+
const candidate = path30.join(dir, "node_modules", name);
|
|
1417
|
+
if (existsSync(path30.join(candidate, "package.json"))) return candidate;
|
|
1418
|
+
const parent = path30.dirname(dir);
|
|
1239
1419
|
if (parent === dir) return null;
|
|
1240
1420
|
dir = parent;
|
|
1241
1421
|
}
|
|
@@ -1287,7 +1467,7 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1287
1467
|
function readPackageExports(root, uiPackage) {
|
|
1288
1468
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1289
1469
|
if (!uiDir) return null;
|
|
1290
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1470
|
+
const uiPkg = JSON.parse(readFileSync(path30.join(uiDir, "package.json"), "utf8"));
|
|
1291
1471
|
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
1292
1472
|
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1293
1473
|
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
@@ -1314,23 +1494,23 @@ function readPackageExports(root, uiPackage) {
|
|
|
1314
1494
|
}
|
|
1315
1495
|
if (fromSource) {
|
|
1316
1496
|
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
1317
|
-
const next = resolveSource(
|
|
1497
|
+
const next = resolveSource(path30.dirname(file), m[1]);
|
|
1318
1498
|
if (next) readEntry(next);
|
|
1319
1499
|
}
|
|
1320
1500
|
}
|
|
1321
1501
|
};
|
|
1322
|
-
for (const entry of typeEntries) readEntry(
|
|
1502
|
+
for (const entry of typeEntries) readEntry(path30.join(uiDir, entry));
|
|
1323
1503
|
if (!readAny) {
|
|
1324
1504
|
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
1325
1505
|
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1326
1506
|
}
|
|
1327
1507
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1328
1508
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1329
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1509
|
+
const declRoot = typeof mainTypes === "string" ? path30.dirname(path30.join(uiDir, mainTypes)) : uiDir;
|
|
1330
1510
|
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
1331
1511
|
for (const pkg of reexportedPackages) {
|
|
1332
1512
|
const dir = findPackageDir(uiDir, pkg);
|
|
1333
|
-
if (dir) walkDts(
|
|
1513
|
+
if (dir) walkDts(path30.join(dir, "dist"), declFiles);
|
|
1334
1514
|
}
|
|
1335
1515
|
for (const file of declFiles) {
|
|
1336
1516
|
const text = readFileSync(file, "utf8");
|
|
@@ -1378,13 +1558,13 @@ function exportSource(target) {
|
|
|
1378
1558
|
return void 0;
|
|
1379
1559
|
}
|
|
1380
1560
|
function resolveSource(dir, spec) {
|
|
1381
|
-
const base =
|
|
1382
|
-
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) =>
|
|
1561
|
+
const base = path30.resolve(dir, spec.replace(/\.js$/, ""));
|
|
1562
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path30.join(base, i))];
|
|
1383
1563
|
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
1384
1564
|
}
|
|
1385
1565
|
function insidePackage(dir, file) {
|
|
1386
|
-
const rel =
|
|
1387
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1566
|
+
const rel = path30.relative(path30.resolve(dir), path30.resolve(file));
|
|
1567
|
+
return rel === "" || !rel.startsWith("..") && !path30.isAbsolute(rel);
|
|
1388
1568
|
}
|
|
1389
1569
|
function stripComments(code) {
|
|
1390
1570
|
let out = "";
|
|
@@ -1420,7 +1600,7 @@ function walkSource(dir, out = []) {
|
|
|
1420
1600
|
if (!existsSync(dir)) return out;
|
|
1421
1601
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1422
1602
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
1423
|
-
const p =
|
|
1603
|
+
const p = path30.join(dir, entry.name);
|
|
1424
1604
|
if (entry.isDirectory()) walkSource(p, out);
|
|
1425
1605
|
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1426
1606
|
}
|
|
@@ -1440,7 +1620,7 @@ function walkDts(dir, out = []) {
|
|
|
1440
1620
|
if (!existsSync(dir)) return out;
|
|
1441
1621
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1442
1622
|
if (entry.name === "node_modules") continue;
|
|
1443
|
-
const p =
|
|
1623
|
+
const p = path30.join(dir, entry.name);
|
|
1444
1624
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1445
1625
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1446
1626
|
}
|
|
@@ -1457,27 +1637,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1457
1637
|
}
|
|
1458
1638
|
const files = [];
|
|
1459
1639
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1460
|
-
const themes = ds &&
|
|
1640
|
+
const themes = ds && path30.join(ds, "dist", "themes");
|
|
1461
1641
|
if (themes && existsSync(themes)) {
|
|
1462
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1642
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path30.join(themes, name));
|
|
1463
1643
|
}
|
|
1464
1644
|
if (files.length === 0) {
|
|
1465
1645
|
throw new DoctorConfigError(
|
|
1466
1646
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1467
1647
|
);
|
|
1468
1648
|
}
|
|
1469
|
-
const uiStyles =
|
|
1649
|
+
const uiStyles = path30.join(uiDir, "dist", "styles.css");
|
|
1470
1650
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1471
1651
|
return files;
|
|
1472
1652
|
}
|
|
1473
1653
|
function resolveSpec(root, spec) {
|
|
1474
|
-
const local =
|
|
1475
|
-
if (spec.startsWith(".") ||
|
|
1654
|
+
const local = path30.resolve(root, spec);
|
|
1655
|
+
if (spec.startsWith(".") || path30.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1476
1656
|
const parts = spec.split("/");
|
|
1477
1657
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1478
1658
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1479
1659
|
if (dir) {
|
|
1480
|
-
const file =
|
|
1660
|
+
const file = path30.join(dir, ...parts.slice(nameLength));
|
|
1481
1661
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1482
1662
|
}
|
|
1483
1663
|
return existsSync(local) ? local : null;
|
|
@@ -1485,7 +1665,7 @@ function resolveSpec(root, spec) {
|
|
|
1485
1665
|
function loadPalette(root) {
|
|
1486
1666
|
const names = new Set(TAILWIND_PALETTE);
|
|
1487
1667
|
try {
|
|
1488
|
-
const req = createRequire(
|
|
1668
|
+
const req = createRequire(path30.join(root, "package.json"));
|
|
1489
1669
|
const colors = req("tailwindcss/colors");
|
|
1490
1670
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1491
1671
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -1730,7 +1910,7 @@ function globToRegExp(glob) {
|
|
|
1730
1910
|
}
|
|
1731
1911
|
function globMatcher(globs) {
|
|
1732
1912
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1733
|
-
return (
|
|
1913
|
+
return (path56) => res.some((re) => re.test(path56));
|
|
1734
1914
|
}
|
|
1735
1915
|
var init_glob = __esm({
|
|
1736
1916
|
"src/doctor/glob.ts"() {
|
|
@@ -1742,9 +1922,9 @@ function scanFiles(root, config) {
|
|
|
1742
1922
|
const files = [];
|
|
1743
1923
|
const seen = /* @__PURE__ */ new Set();
|
|
1744
1924
|
const visit = (abs) => {
|
|
1745
|
-
const rel = toPosix(
|
|
1925
|
+
const rel = toPosix(path30.relative(root, abs));
|
|
1746
1926
|
if (seen.has(rel) || ignored(rel)) return;
|
|
1747
|
-
const ext =
|
|
1927
|
+
const ext = path30.extname(abs);
|
|
1748
1928
|
if (!extensions.has(ext)) return;
|
|
1749
1929
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1750
1930
|
seen.add(rel);
|
|
@@ -1754,14 +1934,14 @@ function scanFiles(root, config) {
|
|
|
1754
1934
|
const walk3 = (dir) => {
|
|
1755
1935
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1756
1936
|
if (entry.isDirectory()) {
|
|
1757
|
-
if (!SKIP_DIRS.has(entry.name)) walk3(
|
|
1937
|
+
if (!SKIP_DIRS.has(entry.name)) walk3(path30.join(dir, entry.name));
|
|
1758
1938
|
} else if (entry.isFile()) {
|
|
1759
|
-
visit(
|
|
1939
|
+
visit(path30.join(dir, entry.name));
|
|
1760
1940
|
}
|
|
1761
1941
|
}
|
|
1762
1942
|
};
|
|
1763
1943
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1764
|
-
const abs =
|
|
1944
|
+
const abs = path30.resolve(root, src);
|
|
1765
1945
|
if (!existsSync(abs)) continue;
|
|
1766
1946
|
if (statSync(abs).isDirectory()) walk3(abs);
|
|
1767
1947
|
else visit(abs);
|
|
@@ -1800,7 +1980,7 @@ var init_scan = __esm({
|
|
|
1800
1980
|
];
|
|
1801
1981
|
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1802
1982
|
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1803
|
-
toPosix = (p) => p.split(
|
|
1983
|
+
toPosix = (p) => p.split(path30.sep).join("/");
|
|
1804
1984
|
}
|
|
1805
1985
|
});
|
|
1806
1986
|
|
|
@@ -1938,7 +2118,7 @@ function overlayState(name, json) {
|
|
|
1938
2118
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
1939
2119
|
const problems = [];
|
|
1940
2120
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
1941
|
-
const rel =
|
|
2121
|
+
const rel = path30.relative(path30.resolve(root), path30.resolve(dir)).split(path30.sep).join("/");
|
|
1942
2122
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
1943
2123
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
1944
2124
|
if (holds !== void 0) problems.push(`${name}: an overlay lives in a package folder of its own, not in ${rel || "the app root"}, which holds the app's source (${holds})`);
|
|
@@ -1974,12 +2154,12 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
1974
2154
|
for (const file of manifests) {
|
|
1975
2155
|
let json;
|
|
1976
2156
|
try {
|
|
1977
|
-
json = JSON.parse(readFileSync(
|
|
2157
|
+
json = JSON.parse(readFileSync(path30.join(root, file), "utf8"));
|
|
1978
2158
|
} catch {
|
|
1979
2159
|
continue;
|
|
1980
2160
|
}
|
|
1981
|
-
for (const
|
|
1982
|
-
const spec = json[
|
|
2161
|
+
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
2162
|
+
const spec = json[section2]?.[name];
|
|
1983
2163
|
const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
|
|
1984
2164
|
const parsed = v && parseVersion(v);
|
|
1985
2165
|
if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
|
|
@@ -1999,7 +2179,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
|
1999
2179
|
const file = `${pkg.rel}/package.json`;
|
|
2000
2180
|
let json;
|
|
2001
2181
|
try {
|
|
2002
|
-
json = JSON.parse(readFileSync(
|
|
2182
|
+
json = JSON.parse(readFileSync(path30.join(pkg.dir, "package.json"), "utf8"));
|
|
2003
2183
|
} catch {
|
|
2004
2184
|
continue;
|
|
2005
2185
|
}
|
|
@@ -2072,7 +2252,7 @@ var init_overlays = __esm({
|
|
|
2072
2252
|
});
|
|
2073
2253
|
function readReleaseManifest(root) {
|
|
2074
2254
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2075
|
-
const file = dir &&
|
|
2255
|
+
const file = dir && path30.join(dir, "dist", "versions.json");
|
|
2076
2256
|
if (!file || !existsSync(file)) return null;
|
|
2077
2257
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
2078
2258
|
}
|
|
@@ -2098,7 +2278,7 @@ function checkVersionSkew(ctx) {
|
|
|
2098
2278
|
}
|
|
2099
2279
|
const dir = findPackageDir(ctx.root, name);
|
|
2100
2280
|
if (!dir) continue;
|
|
2101
|
-
const have = JSON.parse(readFileSync(
|
|
2281
|
+
const have = JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8")).version;
|
|
2102
2282
|
if (have === want) continue;
|
|
2103
2283
|
ctx.report({
|
|
2104
2284
|
rule: "version-skew",
|
|
@@ -2119,13 +2299,13 @@ var init_versions = __esm({
|
|
|
2119
2299
|
}
|
|
2120
2300
|
});
|
|
2121
2301
|
function findLockfile(root) {
|
|
2122
|
-
let dir =
|
|
2302
|
+
let dir = path30.resolve(root);
|
|
2123
2303
|
for (; ; ) {
|
|
2124
|
-
if (existsSync(
|
|
2125
|
-
if (existsSync(
|
|
2126
|
-
if (existsSync(
|
|
2127
|
-
if (existsSync(
|
|
2128
|
-
const parent =
|
|
2304
|
+
if (existsSync(path30.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
2305
|
+
if (existsSync(path30.join(dir, "bun.lock")) || existsSync(path30.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
2306
|
+
if (existsSync(path30.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
2307
|
+
if (existsSync(path30.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
2308
|
+
const parent = path30.dirname(dir);
|
|
2129
2309
|
if (parent === dir) return null;
|
|
2130
2310
|
dir = parent;
|
|
2131
2311
|
}
|
|
@@ -2169,10 +2349,10 @@ var init_pm = __esm({
|
|
|
2169
2349
|
function walk(dir, exclude = []) {
|
|
2170
2350
|
const out = [];
|
|
2171
2351
|
const visit = (rel) => {
|
|
2172
|
-
for (const name of readdirSync(
|
|
2352
|
+
for (const name of readdirSync(path30.join(dir, rel)).sort()) {
|
|
2173
2353
|
const child = rel ? `${rel}/${name}` : name;
|
|
2174
2354
|
if (exclude.some((r) => r.test(child))) continue;
|
|
2175
|
-
const stat = statSync(
|
|
2355
|
+
const stat = statSync(path30.join(dir, child));
|
|
2176
2356
|
if (stat.isDirectory()) visit(child);
|
|
2177
2357
|
else if (stat.isFile()) out.push(child);
|
|
2178
2358
|
}
|
|
@@ -2201,17 +2381,17 @@ var init_walk = __esm({
|
|
|
2201
2381
|
});
|
|
2202
2382
|
function starterDir() {
|
|
2203
2383
|
const workspace = workspacePackagesDir();
|
|
2204
|
-
const live = workspace &&
|
|
2205
|
-
if (live && existsSync(
|
|
2206
|
-
const packaged =
|
|
2207
|
-
if (existsSync(
|
|
2384
|
+
const live = workspace && path30.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
2385
|
+
if (live && existsSync(path30.join(live, "package.json"))) return live;
|
|
2386
|
+
const packaged = path30.join(cliPackageDir(), "dist", "starter");
|
|
2387
|
+
if (existsSync(path30.join(packaged, "package.json"))) return packaged;
|
|
2208
2388
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
2209
2389
|
}
|
|
2210
2390
|
function templatesDir(cliDir = cliPackageDir()) {
|
|
2211
2391
|
const workspace = workspacePackagesDir();
|
|
2212
|
-
const live = workspace && cliDir === cliPackageDir() ?
|
|
2213
|
-
if (live && existsSync(
|
|
2214
|
-
const packaged =
|
|
2392
|
+
const live = workspace && cliDir === cliPackageDir() ? path30.join(workspace, "..", "templates") : null;
|
|
2393
|
+
if (live && existsSync(path30.join(live, "eas"))) return live;
|
|
2394
|
+
const packaged = path30.join(cliDir, "dist", "templates");
|
|
2215
2395
|
if (existsSync(packaged)) return packaged;
|
|
2216
2396
|
throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
|
|
2217
2397
|
}
|
|
@@ -2236,8 +2416,25 @@ function featuresBody(text) {
|
|
|
2236
2416
|
const m = /\bfeatures:\s*\{/.exec(text);
|
|
2237
2417
|
if (!m) return null;
|
|
2238
2418
|
const start = m.index + m[0].length;
|
|
2239
|
-
|
|
2240
|
-
|
|
2419
|
+
let depth = 1;
|
|
2420
|
+
for (let i = start; i < text.length; i++) {
|
|
2421
|
+
const c = text[i];
|
|
2422
|
+
if (c === "/" && text[i + 1] === "/") {
|
|
2423
|
+
const nl = text.indexOf("\n", i);
|
|
2424
|
+
if (nl < 0) return null;
|
|
2425
|
+
i = nl;
|
|
2426
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
2427
|
+
const close = text.indexOf("*/", i + 2);
|
|
2428
|
+
if (close < 0) return null;
|
|
2429
|
+
i = close + 1;
|
|
2430
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
2431
|
+
let j = i + 1;
|
|
2432
|
+
while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
|
|
2433
|
+
i = j;
|
|
2434
|
+
} else if (c === "{") depth++;
|
|
2435
|
+
else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
|
|
2436
|
+
}
|
|
2437
|
+
return null;
|
|
2241
2438
|
}
|
|
2242
2439
|
function parseStarterFeatures(text) {
|
|
2243
2440
|
const found = featuresBody(text);
|
|
@@ -2270,6 +2467,7 @@ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
|
|
|
2270
2467
|
const starter = raw?.starter;
|
|
2271
2468
|
if (starter === void 0) return null;
|
|
2272
2469
|
const blocks = starter?.blocks;
|
|
2470
|
+
if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
|
|
2273
2471
|
if (typeof blocks !== "object" || blocks === null || Array.isArray(blocks)) throw new Error(`${source}: starter.blocks must map each feature switch to a list of block ids`);
|
|
2274
2472
|
const out = {};
|
|
2275
2473
|
for (const [name, ids] of Object.entries(blocks)) {
|
|
@@ -2290,7 +2488,7 @@ function readText(file) {
|
|
|
2290
2488
|
}
|
|
2291
2489
|
function starterBlockMap(root) {
|
|
2292
2490
|
if (root) {
|
|
2293
|
-
const file =
|
|
2491
|
+
const file = path30.join(root, GENESIS_CONFIG);
|
|
2294
2492
|
const text2 = readText(file);
|
|
2295
2493
|
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
2296
2494
|
if (own) return own;
|
|
@@ -2301,7 +2499,7 @@ function starterBlockMap(root) {
|
|
|
2301
2499
|
} catch {
|
|
2302
2500
|
return {};
|
|
2303
2501
|
}
|
|
2304
|
-
const text = readText(
|
|
2502
|
+
const text = readText(path30.join(dir, GENESIS_CONFIG));
|
|
2305
2503
|
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
2306
2504
|
}
|
|
2307
2505
|
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
@@ -2321,10 +2519,10 @@ function blocksSwitchedOff(switches, map, manifests, present) {
|
|
|
2321
2519
|
return off;
|
|
2322
2520
|
}
|
|
2323
2521
|
function appBlocksSwitchedOff(root, manifests, present) {
|
|
2324
|
-
const text = readText(
|
|
2522
|
+
const text = readText(path30.join(root, STARTER_CONFIG));
|
|
2325
2523
|
const switches = text === null ? null : parseStarterFeatures(text);
|
|
2326
2524
|
if (!switches) return /* @__PURE__ */ new Map();
|
|
2327
|
-
return blocksSwitchedOff(switches, starterBlockMap(existsSync(
|
|
2525
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path30.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
2328
2526
|
}
|
|
2329
2527
|
function switchedOffNote(id, feature) {
|
|
2330
2528
|
return `${id}: features.${feature} is off in ${STARTER_CONFIG}, so it's left out (turn it on to have it again)`;
|
|
@@ -2375,7 +2573,7 @@ var init_eas_placeholders = __esm({
|
|
|
2375
2573
|
EAS_PLACEHOLDERS = {
|
|
2376
2574
|
REPLACE_WITH_APP_STORE_CONNECT_APP_ID: "the app's Apple ID from App Store Connect (create the app there, then App Information \u2192 General Information \u2192 Apple ID, a number)",
|
|
2377
2575
|
REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
|
|
2378
|
-
REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the
|
|
2576
|
+
REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the Google Play service account key uploaded to EAS, not a local path (deploy-production.yml submits on EAS, where a local file isn't there): create a Google Cloud service account and its JSON key, invite it in Play Console \u2192 Users and permissions, upload the key with `eas credentials` (Android \u2192 Google Service Account), then remove only this serviceAccountKeyPath line (https://docs.expo.dev/submit/android/). Until you ship to Google Play, remove the submit_android job from deploy-production.yml instead, and keep submit.production.android as it is (the internal track, as a draft)",
|
|
2379
2577
|
REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
|
|
2380
2578
|
};
|
|
2381
2579
|
}
|
|
@@ -2385,7 +2583,9 @@ var init_eas_placeholders = __esm({
|
|
|
2385
2583
|
var init_native_exports = {};
|
|
2386
2584
|
__export(init_native_exports, {
|
|
2387
2585
|
APP_FOLDER_PLACEHOLDER: () => APP_FOLDER_PLACEHOLDER,
|
|
2586
|
+
DATABASE_TEMPLATES: () => DATABASE_TEMPLATES,
|
|
2388
2587
|
appPnpmSettings: () => appPnpmSettings,
|
|
2588
|
+
besideConfig: () => besideConfig,
|
|
2389
2589
|
initNative: () => initNative,
|
|
2390
2590
|
runInitNative: () => runInitNative,
|
|
2391
2591
|
starterIdentity: () => starterIdentity
|
|
@@ -2414,14 +2614,15 @@ function appPnpmSettings(text) {
|
|
|
2414
2614
|
return `# pnpm settings for this app, from the Genesis monorepo it was made from.
|
|
2415
2615
|
${out.join("\n").replace(/^\n+/, "")}`;
|
|
2416
2616
|
}
|
|
2417
|
-
function readme(display, slug) {
|
|
2617
|
+
function readme(display, slug, database) {
|
|
2618
|
+
const apply = database ? `The database is ${database}'s: this app has no supabase/ folder. Add blocks' database files there (\`genesis add <block>\` in ${database}) and apply its migrations from there.` : `Apply \`supabase/migrations\` (\`supabase db push\`, or \`supabase start\` for a local stack).`;
|
|
2418
2619
|
return `# ${display}
|
|
2419
2620
|
|
|
2420
2621
|
An Expo app made with \`genesis init ${slug} --template native\` from the Genesis RN starter.
|
|
2421
2622
|
|
|
2422
|
-
1. \`cp .env.example .env\` and fill in your Supabase project's URL and publishable key.
|
|
2623
|
+
1. \`cp .env.example .env\` and fill in your Supabase project's URL and publishable key${database ? ` (${database}'s project)` : ""}.
|
|
2423
2624
|
2. Install: \`pnpm install\` (or your package manager).
|
|
2424
|
-
3.
|
|
2625
|
+
3. ${apply}
|
|
2425
2626
|
4. \`pnpm ios\` or \`pnpm android\`.
|
|
2426
2627
|
|
|
2427
2628
|
- Turn features off in \`starter.config.ts\`.
|
|
@@ -2441,10 +2642,18 @@ function initNative(options) {
|
|
|
2441
2642
|
if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
|
|
2442
2643
|
if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
|
|
2443
2644
|
if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
|
|
2444
|
-
const target =
|
|
2645
|
+
const target = path30.resolve(options.target);
|
|
2445
2646
|
if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
|
|
2647
|
+
let beside;
|
|
2648
|
+
if (options.beside !== void 0) {
|
|
2649
|
+
const dir = path30.resolve(options.beside);
|
|
2650
|
+
if (!existsSync(dir)) throw new Error(`--beside: ${options.beside} doesn't exist; name the web app's folder.`);
|
|
2651
|
+
if (dir === target) throw new Error("--beside names the new app's own folder; name the web app's folder.");
|
|
2652
|
+
beside = { dir, app: path30.relative(target, dir).split(path30.sep).join("/"), shared: existsSync(path30.join(dir, "supabase")) };
|
|
2653
|
+
}
|
|
2654
|
+
const shared = beside?.shared === true;
|
|
2446
2655
|
const source = starterDir();
|
|
2447
|
-
const read2 = (rel) => readFileSync(
|
|
2656
|
+
const read2 = (rel) => readFileSync(path30.join(source, rel), "utf8");
|
|
2448
2657
|
const was = starterIdentity(read2(STARTER_CONFIG));
|
|
2449
2658
|
const switches = parseStarterFeatures(read2(STARTER_CONFIG)) ?? {};
|
|
2450
2659
|
const without = [...new Set(options.without ?? [])];
|
|
@@ -2469,8 +2678,8 @@ function initNative(options) {
|
|
|
2469
2678
|
pkg.name = slug;
|
|
2470
2679
|
const unpinned = [];
|
|
2471
2680
|
const dependencies2 = {};
|
|
2472
|
-
for (const
|
|
2473
|
-
const deps = pkg[
|
|
2681
|
+
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
2682
|
+
const deps = pkg[section2];
|
|
2474
2683
|
for (const [name, spec] of Object.entries(deps ?? {})) {
|
|
2475
2684
|
if (!spec.startsWith("workspace:")) continue;
|
|
2476
2685
|
const version = versionFor(name);
|
|
@@ -2487,22 +2696,28 @@ function initNative(options) {
|
|
|
2487
2696
|
files.set("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
2488
2697
|
`);
|
|
2489
2698
|
files.set("metro.config.js", METRO);
|
|
2490
|
-
const pnpmSettings = [
|
|
2699
|
+
const pnpmSettings = [path30.join(source, "pnpm-workspace.yaml"), path30.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
|
|
2491
2700
|
if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
|
|
2492
|
-
files.set("README.md", readme(display, slug));
|
|
2701
|
+
files.set("README.md", readme(display, slug, shared ? beside.app : void 0));
|
|
2493
2702
|
if (without.length) files.set(STARTER_CONFIG, setStarterFeatures(files.get(STARTER_CONFIG), Object.fromEntries(without.map((w) => [w, false]))));
|
|
2494
2703
|
const carried = options.blocks.filter((b) => carriedBy(files, b)).map((b) => b.id);
|
|
2495
2704
|
const switchedOff = blocksSwitchedOff(features2, parseStarterBlocks(read2("genesis.config.json")) ?? {}, options.blocks, carried);
|
|
2496
2705
|
const leftOut = options.blocks.filter((b) => switchedOff.has(b.id)).map((b) => b.id);
|
|
2497
2706
|
if (leftOut.length) leaveOut(files, options.blocks.filter((b) => switchedOff.has(b.id)));
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2707
|
+
if (shared) {
|
|
2708
|
+
for (const rel of [...files.keys()]) if (isSupabasePath(rel)) files.delete(rel);
|
|
2709
|
+
files.set("genesis.config.json", besideConfig(files.get("genesis.config.json"), beside.app));
|
|
2710
|
+
} else {
|
|
2711
|
+
const since = sinceAfter(files);
|
|
2712
|
+
const config = files.get("genesis.config.json");
|
|
2713
|
+
if (since && config && !/"since"\s*:/.test(config)) files.set("genesis.config.json", config.replace(/("supabase"\s*:\s*\{[^}]*?)(\s*\})/, `$1, "since": "${since}"$2`));
|
|
2714
|
+
}
|
|
2501
2715
|
const lock = { ...emptyLock(), substitutions };
|
|
2502
2716
|
const cliVersion2 = pinnedVersion2(target, CLI_PACKAGE)?.version;
|
|
2503
2717
|
const templates = templatesDir();
|
|
2504
2718
|
for (const rel of walk(templates)) {
|
|
2505
|
-
|
|
2719
|
+
if (shared && DATABASE_TEMPLATES.has(rel)) continue;
|
|
2720
|
+
const text = substitute(readFileSync(path30.join(templates, rel), "utf8"), substitutions);
|
|
2506
2721
|
const to = templateTarget(rel, text);
|
|
2507
2722
|
files.set(to, text);
|
|
2508
2723
|
lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
|
|
@@ -2513,15 +2728,22 @@ function initNative(options) {
|
|
|
2513
2728
|
const blocks = [];
|
|
2514
2729
|
for (const block of options.blocks) {
|
|
2515
2730
|
if (switchedOff.has(block.id)) continue;
|
|
2731
|
+
if (shared) {
|
|
2732
|
+
if (carried.includes(block.id)) {
|
|
2733
|
+
blocks.push(block.id);
|
|
2734
|
+
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
2735
|
+
}
|
|
2736
|
+
continue;
|
|
2737
|
+
}
|
|
2516
2738
|
const stems = block.migrations.map((m) => stemOf(m.file));
|
|
2517
|
-
const copies = stems.map((s) => migrations.find((f) =>
|
|
2739
|
+
const copies = stems.map((s) => migrations.find((f) => path30.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
|
|
2518
2740
|
if (!stems.length || copies.some((c) => !c)) continue;
|
|
2519
2741
|
blocks.push(block.id);
|
|
2520
2742
|
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
2521
2743
|
block.migrations.forEach((m, i) => {
|
|
2522
2744
|
lock.migrations = { ...lock.migrations, [migrationKey(m.package, m.file)]: copies[i] };
|
|
2523
2745
|
if (m.test) {
|
|
2524
|
-
const test2 = `${TESTS_DIR}/${
|
|
2746
|
+
const test2 = `${TESTS_DIR}/${path30.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
|
|
2525
2747
|
if (files.has(test2)) lock.files[test2] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test2)) };
|
|
2526
2748
|
}
|
|
2527
2749
|
});
|
|
@@ -2534,8 +2756,8 @@ function initNative(options) {
|
|
|
2534
2756
|
}
|
|
2535
2757
|
mkdirSync(target, { recursive: true });
|
|
2536
2758
|
for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
2537
|
-
const file =
|
|
2538
|
-
mkdirSync(
|
|
2759
|
+
const file = path30.join(target, ...rel.split("/"));
|
|
2760
|
+
mkdirSync(path30.dirname(file), { recursive: true });
|
|
2539
2761
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
2540
2762
|
}
|
|
2541
2763
|
writeLock(target, lock);
|
|
@@ -2545,17 +2767,40 @@ function initNative(options) {
|
|
|
2545
2767
|
"Set links.hosts in genesis.config.json to your web domain, or delete the links block (no app links then).",
|
|
2546
2768
|
...[...files].flatMap(([rel, text]) => rel === "eas.json" || rel.startsWith(".eas/") ? findPlaceholders(rel, text).map((p) => placeholderStep(rel, p.text, p.placeholder)) : [])
|
|
2547
2769
|
);
|
|
2548
|
-
|
|
2770
|
+
let besideResult;
|
|
2771
|
+
if (beside) {
|
|
2772
|
+
const home = { app: beside.app, dir: beside.dir, hasSupabase: beside.shared };
|
|
2773
|
+
const missing = shared ? orderForAdding(blocksMissingThere(home, blocks, options.blocks) ?? blocks, options.blocks) : [];
|
|
2774
|
+
const line = !shared ? `${beside.app} has no supabase folder, so this app keeps its own supabase/ (as without --beside).` : addThereLine(home, missing) ?? `${beside.app} already has the database side of every block this app uses (${blocks.join(", ") || "none"}).`;
|
|
2775
|
+
besideResult = { app: beside.app, shared, missing, line };
|
|
2776
|
+
steps.unshift(line);
|
|
2777
|
+
}
|
|
2778
|
+
return { target, files: [...files.keys(), "genesis.lock.json"].sort(), dependencies: dependencies2, unpinned, blocks, leftOut, steps, ...besideResult ? { beside: besideResult } : {} };
|
|
2549
2779
|
}
|
|
2550
2780
|
}
|
|
2781
|
+
function besideConfig(text, app) {
|
|
2782
|
+
const json = JSON.parse(text);
|
|
2783
|
+
const out = {};
|
|
2784
|
+
for (const [key2, value] of Object.entries(json)) {
|
|
2785
|
+
if (key2 === "doctor" && value && typeof value === "object") {
|
|
2786
|
+
const { supabase: _settings, contracts: _contracts, ...rest } = value;
|
|
2787
|
+
if (Array.isArray(rest.packs)) rest.packs = rest.packs.filter((p) => p !== "supabase");
|
|
2788
|
+
out[key2] = rest;
|
|
2789
|
+
} else out[key2] = value;
|
|
2790
|
+
if (key2 === "doctor") out["supabase"] = { $comment: "This app has no supabase/ folder: its database files (migrations, pgTAP tests, Edge Functions) are in the supabase/ folder of the app named here. Run genesis add and migrate there.", app };
|
|
2791
|
+
}
|
|
2792
|
+
if (!("supabase" in out)) out["supabase"] = { app };
|
|
2793
|
+
return `${JSON.stringify(out, null, 2)}
|
|
2794
|
+
`;
|
|
2795
|
+
}
|
|
2551
2796
|
function carriedBy(files, block) {
|
|
2552
|
-
const names = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) =>
|
|
2797
|
+
const names = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) => path30.posix.basename(f).replace(/^\d+_/, ""));
|
|
2553
2798
|
return block.migrations.length > 0 && block.migrations.every((m) => names.includes(`${stemOf(m.file)}.sql`));
|
|
2554
2799
|
}
|
|
2555
2800
|
function sinceAfter(files) {
|
|
2556
|
-
const versions = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) => /^(\d{14})_/.exec(
|
|
2801
|
+
const versions = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) => /^(\d{14})_/.exec(path30.posix.basename(f))?.[1]).filter((v) => Boolean(v)).sort();
|
|
2557
2802
|
const last = versions.at(-1);
|
|
2558
|
-
return last ?
|
|
2803
|
+
return last ? nextStamp(last) : null;
|
|
2559
2804
|
}
|
|
2560
2805
|
function featTags(text) {
|
|
2561
2806
|
return [...(text.split("\n", 1)[0] ?? "").matchAll(/@feat:([a-z0-9][a-z0-9-]*)/g)].map((m) => m[1]);
|
|
@@ -2568,12 +2813,12 @@ function leaveOut(files, blocks) {
|
|
|
2568
2813
|
for (const block of blocks) {
|
|
2569
2814
|
for (const m of block.migrations) {
|
|
2570
2815
|
const stem = stemOf(m.file);
|
|
2571
|
-
for (const copy of migrations.filter((f) =>
|
|
2816
|
+
for (const copy of migrations.filter((f) => path30.posix.basename(f).replace(/^\d+_/, "") === `${stem}.sql`)) {
|
|
2572
2817
|
for (const s of files.get(copy).matchAll(/\bcreate\s+schema\s+(?:if\s+not\s+exists\s+)?"?([a-z_][a-z0-9_]*)"?/gi)) schemas.add(s[1].toLowerCase());
|
|
2573
2818
|
files.delete(copy);
|
|
2574
2819
|
}
|
|
2575
2820
|
files.delete(`${TESTS_DIR}/${stem}.test.sql`);
|
|
2576
|
-
if (m.test) files.delete(`${TESTS_DIR}/${
|
|
2821
|
+
if (m.test) files.delete(`${TESTS_DIR}/${path30.posix.basename(m.test).replace(/^\d{4}_/, "")}`);
|
|
2577
2822
|
}
|
|
2578
2823
|
for (const fn of block.functions) {
|
|
2579
2824
|
const name = fn.dir.split("/").pop();
|
|
@@ -2615,18 +2860,20 @@ function leaveOut(files, blocks) {
|
|
|
2615
2860
|
async function runInitNative(options) {
|
|
2616
2861
|
return initNative({ ...options, blocks: catalogBlocks() });
|
|
2617
2862
|
}
|
|
2618
|
-
var APP_FOLDER_PLACEHOLDER, SLUG, BUNDLE, SCHEME, METRO;
|
|
2863
|
+
var DATABASE_TEMPLATES, APP_FOLDER_PLACEHOLDER, SLUG, BUNDLE, SCHEME, METRO;
|
|
2619
2864
|
var init_init_native = __esm({
|
|
2620
2865
|
"src/blocks/init-native.ts"() {
|
|
2621
2866
|
init_discover();
|
|
2622
2867
|
init_files();
|
|
2623
2868
|
init_lock();
|
|
2624
2869
|
init_migrations();
|
|
2870
|
+
init_database();
|
|
2625
2871
|
init_pm();
|
|
2626
2872
|
init_starter_features();
|
|
2627
2873
|
init_eas_placeholders();
|
|
2628
2874
|
init_templates();
|
|
2629
2875
|
init_walk();
|
|
2876
|
+
DATABASE_TEMPLATES = /* @__PURE__ */ new Set(["ci/supabase-ci.yml"]);
|
|
2630
2877
|
APP_FOLDER_PLACEHOLDER = "REPLACE_WITH_APP_FOLDER";
|
|
2631
2878
|
SLUG = /^[a-z][a-z0-9-]{1,40}$/;
|
|
2632
2879
|
BUNDLE = /^[a-zA-Z][a-zA-Z0-9]*(\.[a-zA-Z][a-zA-Z0-9]*)+$/;
|
|
@@ -3077,14 +3324,14 @@ function inherit(own, source) {
|
|
|
3077
3324
|
}
|
|
3078
3325
|
function resolveViews(relations) {
|
|
3079
3326
|
const done = /* @__PURE__ */ new Set();
|
|
3080
|
-
const
|
|
3327
|
+
const resolve27 = (relation, depth) => {
|
|
3081
3328
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
3082
3329
|
done.add(relation.oid);
|
|
3083
3330
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
3084
3331
|
if (sources.size !== 1) return;
|
|
3085
3332
|
const source = relations.get([...sources][0]);
|
|
3086
3333
|
if (!source) return;
|
|
3087
|
-
|
|
3334
|
+
resolve27(source, depth + 1);
|
|
3088
3335
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
3089
3336
|
for (const [attnum, origin] of relation.origins) {
|
|
3090
3337
|
const own = relation.columns.get(attnum);
|
|
@@ -3107,7 +3354,7 @@ function resolveViews(relations) {
|
|
|
3107
3354
|
};
|
|
3108
3355
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
3109
3356
|
};
|
|
3110
|
-
for (const relation of relations.values())
|
|
3357
|
+
for (const relation of relations.values()) resolve27(relation, 0);
|
|
3111
3358
|
}
|
|
3112
3359
|
async function introspectPostgres(sql, schemas, options = {}) {
|
|
3113
3360
|
const relations = /* @__PURE__ */ new Map();
|
|
@@ -3379,7 +3626,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
3379
3626
|
const env = settings2.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
3380
3627
|
let current = null;
|
|
3381
3628
|
try {
|
|
3382
|
-
current = lf(readFileSync(
|
|
3629
|
+
current = lf(readFileSync(path30.join(ctx.root, out), "utf8"));
|
|
3383
3630
|
} catch {
|
|
3384
3631
|
current = null;
|
|
3385
3632
|
}
|
|
@@ -3403,7 +3650,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
3403
3650
|
ctx.report({ rule: "contracts-stale", level: generation ? "error" : "warn", file: out, message: generation ? `couldn't be generated: ${message}` : `couldn't read the database through ${env}: ${message}` });
|
|
3404
3651
|
return;
|
|
3405
3652
|
}
|
|
3406
|
-
const target =
|
|
3653
|
+
const target = path30.relative(process.cwd(), path30.join(ctx.root, out)) || out;
|
|
3407
3654
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
3408
3655
|
if (current !== expected) {
|
|
3409
3656
|
ctx.report({
|
|
@@ -3431,7 +3678,7 @@ __export(settings_exports, {
|
|
|
3431
3678
|
});
|
|
3432
3679
|
function introspectSettings(flags, root, contracts, readCurrent = () => null) {
|
|
3433
3680
|
const out = flags.out ?? contracts?.out ?? DEFAULT_CONTRACT_OUT;
|
|
3434
|
-
const target =
|
|
3681
|
+
const target = path30.resolve(root, out);
|
|
3435
3682
|
return { target, label: out, schemas: schemasFor(flags, target, contracts, readCurrent), databaseEnv: flags.databaseEnv ?? contracts?.databaseEnv ?? DEFAULT_DATABASE_ENV };
|
|
3436
3683
|
}
|
|
3437
3684
|
function schemasFor(flags, target, contracts, readCurrent) {
|
|
@@ -3447,19 +3694,19 @@ var init_settings = __esm({
|
|
|
3447
3694
|
});
|
|
3448
3695
|
function buildCommands(root, config) {
|
|
3449
3696
|
if (config.build) return config.build;
|
|
3450
|
-
const pkgFile =
|
|
3697
|
+
const pkgFile = path30.join(root, "package.json");
|
|
3451
3698
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
3452
3699
|
const pm = packageManager(root);
|
|
3453
3700
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
3454
3701
|
}
|
|
3455
3702
|
function packageManager(root) {
|
|
3456
|
-
let dir =
|
|
3703
|
+
let dir = path30.resolve(root);
|
|
3457
3704
|
for (; ; ) {
|
|
3458
|
-
if (existsSync(
|
|
3459
|
-
if (existsSync(
|
|
3460
|
-
if (existsSync(
|
|
3461
|
-
if (existsSync(
|
|
3462
|
-
const parent =
|
|
3705
|
+
if (existsSync(path30.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
3706
|
+
if (existsSync(path30.join(dir, "bun.lock")) || existsSync(path30.join(dir, "bun.lockb"))) return "bun";
|
|
3707
|
+
if (existsSync(path30.join(dir, "yarn.lock"))) return "yarn";
|
|
3708
|
+
if (existsSync(path30.join(dir, "package-lock.json"))) return "npm";
|
|
3709
|
+
const parent = path30.dirname(dir);
|
|
3463
3710
|
if (parent === dir) return "npm";
|
|
3464
3711
|
dir = parent;
|
|
3465
3712
|
}
|
|
@@ -3557,7 +3804,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
3557
3804
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
3558
3805
|
let all = compiled;
|
|
3559
3806
|
if (rulesDoc) {
|
|
3560
|
-
const file =
|
|
3807
|
+
const file = path30.resolve(root, rulesDoc);
|
|
3561
3808
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
3562
3809
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
3563
3810
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -3625,14 +3872,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
3625
3872
|
}
|
|
3626
3873
|
function resolvePlugin(id, configDir) {
|
|
3627
3874
|
try {
|
|
3628
|
-
if (id.startsWith(".") ||
|
|
3875
|
+
if (id.startsWith(".") || path30.isAbsolute(id)) return resolveFrom(path30.resolve(configDir, id), configDir);
|
|
3629
3876
|
return resolveFrom(id, configDir);
|
|
3630
3877
|
} catch {
|
|
3631
3878
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
3632
3879
|
}
|
|
3633
3880
|
}
|
|
3634
3881
|
function resolveFrom(id, from) {
|
|
3635
|
-
return createRequire(
|
|
3882
|
+
return createRequire(path30.join(from, "noop.js")).resolve(id);
|
|
3636
3883
|
}
|
|
3637
3884
|
var init_plugins = __esm({
|
|
3638
3885
|
"src/doctor/plugins.ts"() {
|
|
@@ -3650,7 +3897,7 @@ function importSpecifiers(file) {
|
|
|
3650
3897
|
}
|
|
3651
3898
|
function checkProjectLayout(ctx) {
|
|
3652
3899
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
3653
|
-
if (existsSync(
|
|
3900
|
+
if (existsSync(path30.join(ctx.root, dir))) {
|
|
3654
3901
|
ctx.report({
|
|
3655
3902
|
rule: "local-primitives",
|
|
3656
3903
|
file: dir,
|
|
@@ -3660,7 +3907,7 @@ function checkProjectLayout(ctx) {
|
|
|
3660
3907
|
}
|
|
3661
3908
|
}
|
|
3662
3909
|
for (const file of STARTER_LEFTOVERS) {
|
|
3663
|
-
if (existsSync(
|
|
3910
|
+
if (existsSync(path30.join(ctx.root, file))) {
|
|
3664
3911
|
ctx.report({
|
|
3665
3912
|
rule: "starter-leftover",
|
|
3666
3913
|
level: "warn",
|
|
@@ -3748,7 +3995,7 @@ function checkTokens(ctx) {
|
|
|
3748
3995
|
}
|
|
3749
3996
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
3750
3997
|
if (/[*?]/.test(pattern)) continue;
|
|
3751
|
-
const abs =
|
|
3998
|
+
const abs = path30.join(ctx.root, pattern);
|
|
3752
3999
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
3753
4000
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
3754
4001
|
}
|
|
@@ -3870,7 +4117,11 @@ var init_rules = __esm({
|
|
|
3870
4117
|
// supabase pack: contracts (contracts.ts)
|
|
3871
4118
|
"contracts-stale",
|
|
3872
4119
|
// genesis.lock.json against the files (lock-files.ts)
|
|
3873
|
-
"lock-files"
|
|
4120
|
+
"lock-files",
|
|
4121
|
+
// an app whose database files live in another app (database.ts)
|
|
4122
|
+
"database-elsewhere",
|
|
4123
|
+
// the app's eslint config loads Genesis's lint rules (eslint-config.ts)
|
|
4124
|
+
"genesis-eslint-config"
|
|
3874
4125
|
];
|
|
3875
4126
|
DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
3876
4127
|
STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -3955,10 +4206,10 @@ var init_expo = __esm({
|
|
|
3955
4206
|
}
|
|
3956
4207
|
});
|
|
3957
4208
|
function resolveLocal(root, fromFile, spec) {
|
|
3958
|
-
const bases = spec.startsWith(".") ? [
|
|
4209
|
+
const bases = spec.startsWith(".") ? [path30.resolve(path30.dirname(fromFile), spec)] : [path30.join(root, spec.slice(2)), path30.join(root, "src", spec.slice(2))];
|
|
3959
4210
|
for (const base of bases) {
|
|
3960
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
3961
|
-
(p) => SCRIPT_EXTS2.has(
|
|
4211
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path30.join(base, `index${e}`))].find(
|
|
4212
|
+
(p) => SCRIPT_EXTS2.has(path30.extname(p)) && existsSync(p)
|
|
3962
4213
|
);
|
|
3963
4214
|
if (hit) return hit;
|
|
3964
4215
|
}
|
|
@@ -4079,13 +4330,13 @@ function checkNativePack(ctx) {
|
|
|
4079
4330
|
}
|
|
4080
4331
|
function checkEasPlaceholders(ctx) {
|
|
4081
4332
|
const files = [];
|
|
4082
|
-
if (existsSync(
|
|
4083
|
-
const workflows =
|
|
4333
|
+
if (existsSync(path30.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
4334
|
+
const workflows = path30.join(ctx.root, ".eas", "workflows");
|
|
4084
4335
|
if (existsSync(workflows)) {
|
|
4085
4336
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
4086
4337
|
}
|
|
4087
4338
|
for (const file of files) {
|
|
4088
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
4339
|
+
for (const hit of findPlaceholders(file, readFileSync(path30.join(ctx.root, file), "utf8"))) {
|
|
4089
4340
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
4090
4341
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
4091
4342
|
ctx.report({
|
|
@@ -4163,7 +4414,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
4163
4414
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
4164
4415
|
const code = file.code;
|
|
4165
4416
|
const hidden = HIDES_HEADER.exec(code);
|
|
4166
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
4417
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path30.posix.dirname(file.path), file.path);
|
|
4167
4418
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
4168
4419
|
if (hidden && own) {
|
|
4169
4420
|
reported.add(file.path);
|
|
@@ -4191,7 +4442,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
4191
4442
|
}
|
|
4192
4443
|
for (const file of ctx.files) {
|
|
4193
4444
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
4194
|
-
const layout = hidingLayouts.get(
|
|
4445
|
+
const layout = hidingLayouts.get(path30.posix.dirname(file.path));
|
|
4195
4446
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
4196
4447
|
if (!layout || !own) continue;
|
|
4197
4448
|
ctx.report({
|
|
@@ -4212,13 +4463,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
4212
4463
|
}
|
|
4213
4464
|
function routerRoot(ctx) {
|
|
4214
4465
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
4215
|
-
return existsSync(
|
|
4466
|
+
return existsSync(path30.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
4216
4467
|
}
|
|
4217
4468
|
function checkScreenLayouts(ctx, pkg) {
|
|
4218
4469
|
const layouts = nativeLayouts(pkg);
|
|
4219
4470
|
if (layouts.length === 0) return;
|
|
4220
4471
|
const rootDir = routerRoot(ctx);
|
|
4221
|
-
if (!existsSync(
|
|
4472
|
+
if (!existsSync(path30.join(ctx.root, rootDir))) {
|
|
4222
4473
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
4223
4474
|
return;
|
|
4224
4475
|
}
|
|
@@ -4255,7 +4506,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
4255
4506
|
function readExpoConfigs(root) {
|
|
4256
4507
|
const out = [];
|
|
4257
4508
|
for (const name of EXPO_CONFIGS) {
|
|
4258
|
-
const abs =
|
|
4509
|
+
const abs = path30.join(root, name);
|
|
4259
4510
|
if (!existsSync(abs)) continue;
|
|
4260
4511
|
const text = readFileSync(abs, "utf8");
|
|
4261
4512
|
let json = null;
|
|
@@ -4289,13 +4540,13 @@ function pluginOptions(json, module) {
|
|
|
4289
4540
|
return null;
|
|
4290
4541
|
}
|
|
4291
4542
|
function dependencies(root) {
|
|
4292
|
-
const file =
|
|
4543
|
+
const file = path30.join(root, "package.json");
|
|
4293
4544
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
4294
4545
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
4295
4546
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
4296
4547
|
}
|
|
4297
4548
|
function runtimeDependencies(root) {
|
|
4298
|
-
const file =
|
|
4549
|
+
const file = path30.join(root, "package.json");
|
|
4299
4550
|
if (!existsSync(file)) return {};
|
|
4300
4551
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
4301
4552
|
}
|
|
@@ -4584,14 +4835,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
4584
4835
|
seen.add(file);
|
|
4585
4836
|
const json = readJsonc(file);
|
|
4586
4837
|
if (!json) return {};
|
|
4587
|
-
const dir =
|
|
4838
|
+
const dir = path30.dirname(file);
|
|
4588
4839
|
let merged = {};
|
|
4589
4840
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
4590
4841
|
for (const ext of parents) {
|
|
4591
4842
|
if (typeof ext !== "string") continue;
|
|
4592
4843
|
let target = null;
|
|
4593
|
-
if (ext.startsWith(".") ||
|
|
4594
|
-
const abs =
|
|
4844
|
+
if (ext.startsWith(".") || path30.isAbsolute(ext)) {
|
|
4845
|
+
const abs = path30.resolve(dir, ext);
|
|
4595
4846
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
4596
4847
|
} else {
|
|
4597
4848
|
const parts = ext.split("/");
|
|
@@ -4599,14 +4850,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
4599
4850
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
4600
4851
|
if (pkgDir) {
|
|
4601
4852
|
const sub = parts.slice(nameLength).join("/");
|
|
4602
|
-
const abs =
|
|
4853
|
+
const abs = path30.join(pkgDir, sub || "tsconfig.json");
|
|
4603
4854
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
4604
4855
|
}
|
|
4605
4856
|
}
|
|
4606
4857
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
4607
4858
|
}
|
|
4608
4859
|
const opts = json.compilerOptions ?? {};
|
|
4609
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
4860
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path30.resolve(dir, opts.baseUrl);
|
|
4610
4861
|
if (opts.paths && typeof opts.paths === "object") {
|
|
4611
4862
|
merged.paths = opts.paths;
|
|
4612
4863
|
merged.pathsDir = dir;
|
|
@@ -4617,7 +4868,7 @@ function aliases(root) {
|
|
|
4617
4868
|
const table = [];
|
|
4618
4869
|
let baseUrl = null;
|
|
4619
4870
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
4620
|
-
const file =
|
|
4871
|
+
const file = path30.join(root, name);
|
|
4621
4872
|
if (!existsSync(file)) continue;
|
|
4622
4873
|
const config = readTsconfig(root, file);
|
|
4623
4874
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -4625,22 +4876,22 @@ function aliases(root) {
|
|
|
4625
4876
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
4626
4877
|
if (!Array.isArray(targets)) continue;
|
|
4627
4878
|
const exact = !pattern.endsWith("*");
|
|
4628
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
4879
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path30.join(base, String(t).replace(/\*$/, ""))) });
|
|
4629
4880
|
}
|
|
4630
4881
|
}
|
|
4631
|
-
const pkg = readJsonc(
|
|
4882
|
+
const pkg = readJsonc(path30.join(root, "package.json"));
|
|
4632
4883
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
4633
4884
|
if (typeof target !== "string") continue;
|
|
4634
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
4885
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path30.join(root, target.replace(/\*.*$/, ""))] });
|
|
4635
4886
|
}
|
|
4636
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
4887
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path30.join(root, "src") + path30.sep, root + path30.sep] });
|
|
4637
4888
|
return { table, baseUrl };
|
|
4638
4889
|
}
|
|
4639
4890
|
function resolveFile(base) {
|
|
4640
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
4891
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path30.join(base, `index${e}`))];
|
|
4641
4892
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
4642
4893
|
for (const p of tries) {
|
|
4643
|
-
if (SCRIPT_EXTS2.has(
|
|
4894
|
+
if (SCRIPT_EXTS2.has(path30.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
4644
4895
|
}
|
|
4645
4896
|
return null;
|
|
4646
4897
|
}
|
|
@@ -4653,7 +4904,7 @@ function createTrail(ctx) {
|
|
|
4653
4904
|
const { table, baseUrl } = aliases(ctx.root);
|
|
4654
4905
|
let declared = null;
|
|
4655
4906
|
try {
|
|
4656
|
-
const pkg = JSON.parse(readFileSync(
|
|
4907
|
+
const pkg = JSON.parse(readFileSync(path30.join(ctx.root, "package.json"), "utf8"));
|
|
4657
4908
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
4658
4909
|
} catch {
|
|
4659
4910
|
declared = null;
|
|
@@ -4684,17 +4935,17 @@ function createTrail(ctx) {
|
|
|
4684
4935
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
4685
4936
|
let resolved = null;
|
|
4686
4937
|
if (spec.startsWith(".")) {
|
|
4687
|
-
resolved = resolveFile(
|
|
4938
|
+
resolved = resolveFile(path30.resolve(path30.dirname(file.absolutePath), spec));
|
|
4688
4939
|
if (!resolved) lost = true;
|
|
4689
4940
|
} else {
|
|
4690
4941
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
4691
4942
|
if (alias) {
|
|
4692
4943
|
for (const t of alias.targets) {
|
|
4693
|
-
resolved = resolveFile(alias.exact ? t :
|
|
4944
|
+
resolved = resolveFile(alias.exact ? t : path30.join(t, spec.slice(alias.prefix.length)));
|
|
4694
4945
|
if (resolved) break;
|
|
4695
4946
|
}
|
|
4696
4947
|
}
|
|
4697
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
4948
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path30.join(baseUrl, spec));
|
|
4698
4949
|
if (!resolved) {
|
|
4699
4950
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
4700
4951
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -4780,7 +5031,7 @@ var init_trail = __esm({
|
|
|
4780
5031
|
});
|
|
4781
5032
|
function routesDir(ctx) {
|
|
4782
5033
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
4783
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
5034
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path30.join(ctx.root, d))) ?? null;
|
|
4784
5035
|
}
|
|
4785
5036
|
function flavorOf(dir, rels) {
|
|
4786
5037
|
const stems = rels.map((r) => r.split("/").pop());
|
|
@@ -4921,7 +5172,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4921
5172
|
});
|
|
4922
5173
|
if (typeof raw === "string") {
|
|
4923
5174
|
if (!packageDir2) fail(`points at ${raw}, but the package folder is unknown`);
|
|
4924
|
-
const file =
|
|
5175
|
+
const file = path30.resolve(packageDir2, raw);
|
|
4925
5176
|
if (!inside(packageDir2, file)) fail(`points outside the package (${raw})`);
|
|
4926
5177
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
4927
5178
|
let parsed;
|
|
@@ -4970,7 +5221,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4970
5221
|
if (typeof c.plugin === "string") {
|
|
4971
5222
|
if (!packageDir2) plugin = c.plugin;
|
|
4972
5223
|
else {
|
|
4973
|
-
plugin =
|
|
5224
|
+
plugin = path30.resolve(packageDir2, c.plugin);
|
|
4974
5225
|
if (!inside(packageDir2, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
4975
5226
|
}
|
|
4976
5227
|
}
|
|
@@ -5019,7 +5270,7 @@ function checkPattern(v, where2, fail) {
|
|
|
5019
5270
|
}
|
|
5020
5271
|
}
|
|
5021
5272
|
function readDeclaringPackage(dir, local) {
|
|
5022
|
-
const file =
|
|
5273
|
+
const file = path30.join(dir, "package.json");
|
|
5023
5274
|
let stamp;
|
|
5024
5275
|
let real2;
|
|
5025
5276
|
try {
|
|
@@ -5042,7 +5293,7 @@ ${local}`;
|
|
|
5042
5293
|
const pkg = {
|
|
5043
5294
|
name: json.name,
|
|
5044
5295
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
5045
|
-
dir:
|
|
5296
|
+
dir: path30.resolve(dir),
|
|
5046
5297
|
namespace: ruleNamespace(json.name),
|
|
5047
5298
|
local,
|
|
5048
5299
|
private: json.private === true,
|
|
@@ -5056,7 +5307,7 @@ ${local}`;
|
|
|
5056
5307
|
if (raw !== void 0) {
|
|
5057
5308
|
const ignored = [];
|
|
5058
5309
|
try {
|
|
5059
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
5310
|
+
pkg.declaration = validateDeclaration(raw, json.name, path30.resolve(dir), ignored);
|
|
5060
5311
|
if (ignored.length) pkg.ignored = ignored;
|
|
5061
5312
|
} catch (err) {
|
|
5062
5313
|
pkg.error = err.message;
|
|
@@ -5075,14 +5326,14 @@ function discoverPackages(root) {
|
|
|
5075
5326
|
for (const dir of installed) {
|
|
5076
5327
|
let scope;
|
|
5077
5328
|
try {
|
|
5078
|
-
scope =
|
|
5329
|
+
scope = path30.dirname(realpathSync(dir));
|
|
5079
5330
|
} catch {
|
|
5080
5331
|
continue;
|
|
5081
5332
|
}
|
|
5082
|
-
if (
|
|
5333
|
+
if (path30.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
5083
5334
|
for (const entry of readdirSync(scope)) {
|
|
5084
5335
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
5085
|
-
const pkg = readDeclaringPackage(
|
|
5336
|
+
const pkg = readDeclaringPackage(path30.join(scope, entry), false);
|
|
5086
5337
|
if (pkg) byName.set(pkg.name, pkg);
|
|
5087
5338
|
}
|
|
5088
5339
|
}
|
|
@@ -5292,10 +5543,10 @@ var init_package_rules = __esm({
|
|
|
5292
5543
|
});
|
|
5293
5544
|
function sourceFiles(dir, rel = "") {
|
|
5294
5545
|
const out = [];
|
|
5295
|
-
for (const entry of readdirSync(
|
|
5546
|
+
for (const entry of readdirSync(path30.join(dir, rel)).sort()) {
|
|
5296
5547
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
5297
5548
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
5298
|
-
const stat = lstatSync(
|
|
5549
|
+
const stat = lstatSync(path30.join(dir, child));
|
|
5299
5550
|
if (stat.isSymbolicLink()) continue;
|
|
5300
5551
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
5301
5552
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -5318,13 +5569,13 @@ function matchPattern(pattern, spec) {
|
|
|
5318
5569
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
5319
5570
|
}
|
|
5320
5571
|
function tsconfigPaths(dir) {
|
|
5321
|
-
const file =
|
|
5572
|
+
const file = path30.join(dir, "tsconfig.json");
|
|
5322
5573
|
if (!existsSync(file)) return [];
|
|
5323
5574
|
try {
|
|
5324
5575
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
5325
5576
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
5326
|
-
const base =
|
|
5327
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
5577
|
+
const base = path30.resolve(dir, options.baseUrl ?? ".");
|
|
5578
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path30.resolve(base, t)) }));
|
|
5328
5579
|
} catch {
|
|
5329
5580
|
return [];
|
|
5330
5581
|
}
|
|
@@ -5338,8 +5589,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5338
5589
|
const hit = matchPattern(pattern, spec);
|
|
5339
5590
|
if (hit === null) continue;
|
|
5340
5591
|
return targets.some((t) => {
|
|
5341
|
-
const rel =
|
|
5342
|
-
return !rel.startsWith("..") && !
|
|
5592
|
+
const rel = path30.relative(pkg.dir, t.replace("*", hit));
|
|
5593
|
+
return !rel.startsWith("..") && !path30.isAbsolute(rel);
|
|
5343
5594
|
});
|
|
5344
5595
|
}
|
|
5345
5596
|
return null;
|
|
@@ -5352,7 +5603,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5352
5603
|
...Object.keys(json.optionalDependencies ?? {})
|
|
5353
5604
|
]);
|
|
5354
5605
|
for (const file of sourceFiles(pkg.dir)) {
|
|
5355
|
-
const code = stripForImports(readFileSync(
|
|
5606
|
+
const code = stripForImports(readFileSync(path30.join(pkg.dir, file), "utf8"));
|
|
5356
5607
|
if (code === null) continue;
|
|
5357
5608
|
const at = `${pkg.rel}/${file}`;
|
|
5358
5609
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -5377,9 +5628,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5377
5628
|
continue;
|
|
5378
5629
|
}
|
|
5379
5630
|
if (spec.startsWith(".")) {
|
|
5380
|
-
const target =
|
|
5381
|
-
const rel =
|
|
5382
|
-
if (rel.startsWith("..") ||
|
|
5631
|
+
const target = path30.resolve(pkg.dir, path30.dirname(file), spec);
|
|
5632
|
+
const rel = path30.relative(pkg.dir, target);
|
|
5633
|
+
if (rel.startsWith("..") || path30.isAbsolute(rel)) {
|
|
5383
5634
|
ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} reaches outside its folder (${spec}); move what it needs into the package or a dependency` });
|
|
5384
5635
|
}
|
|
5385
5636
|
continue;
|
|
@@ -5415,12 +5666,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5415
5666
|
const from = own ? "" : ` (in ${m.package})`;
|
|
5416
5667
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
5417
5668
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file}${from} has no pgTAP test; declare one as "test" beside it` });
|
|
5418
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
5669
|
+
} else if (typeof m.test === "string" && !existsSync(path30.join(home, m.test))) {
|
|
5419
5670
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test}${from} doesn't exist` });
|
|
5420
5671
|
}
|
|
5421
5672
|
}
|
|
5422
5673
|
}
|
|
5423
|
-
const dir =
|
|
5674
|
+
const dir = path30.join(pkg.dir, "migrations");
|
|
5424
5675
|
if (!existsSync(dir)) return;
|
|
5425
5676
|
const seen = /* @__PURE__ */ new Map();
|
|
5426
5677
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -5429,7 +5680,7 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5429
5680
|
const other = seen.get(m[1]);
|
|
5430
5681
|
if (other) ctx.report({ rule: "package-migration-number", file: `${pkg.rel}/migrations/${name}`, subject: m[1], message: `${pkg.name}: ${name} and ${other} share the number ${m[1]}; give each migration its own` });
|
|
5431
5682
|
else seen.set(m[1], name);
|
|
5432
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
5683
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path30.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
5433
5684
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/migrations/${name}`, subject: name, message: `${pkg.name}: ${name} has no pgTAP test (migrations/tests/${name.replace(/\.sql$/, ".test.sql")})` });
|
|
5434
5685
|
}
|
|
5435
5686
|
}
|
|
@@ -5443,7 +5694,7 @@ function checkExports(ctx, pkg, json) {
|
|
|
5443
5694
|
walk3(json.exports);
|
|
5444
5695
|
for (const t of targets) {
|
|
5445
5696
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
5446
|
-
if (!existsSync(
|
|
5697
|
+
if (!existsSync(path30.join(pkg.dir, t))) {
|
|
5447
5698
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
5448
5699
|
}
|
|
5449
5700
|
}
|
|
@@ -5461,11 +5712,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
5461
5712
|
function checkTaggedTests(ctx, pkg) {
|
|
5462
5713
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
5463
5714
|
if (!tests.length) return;
|
|
5464
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
5715
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path30.join(pkg.dir, f), "utf8")));
|
|
5465
5716
|
if (!tagged) ctx.report({ rule: "package-untagged-tests", level: "warn", file: pkg.rel, message: `${pkg.name}'s tests name no feature; tag them with // @feat:<feature id>` });
|
|
5466
5717
|
}
|
|
5467
5718
|
function checkRegistered(ctx, pkg) {
|
|
5468
|
-
const file =
|
|
5719
|
+
const file = path30.join(ctx.root, "features.json");
|
|
5469
5720
|
if (!existsSync(file)) return;
|
|
5470
5721
|
let doc;
|
|
5471
5722
|
try {
|
|
@@ -5475,7 +5726,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
5475
5726
|
}
|
|
5476
5727
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
5477
5728
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
5478
|
-
if (top) forms.add(
|
|
5729
|
+
if (top) forms.add(path30.relative(top, realpathSync(pkg.dir)).split(path30.sep).join("/"));
|
|
5479
5730
|
const covered = (doc.features ?? []).some(
|
|
5480
5731
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
5481
5732
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -5505,8 +5756,8 @@ function mergeBaseOf(root, base) {
|
|
|
5505
5756
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
5506
5757
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
5507
5758
|
if (!top) return;
|
|
5508
|
-
const appRelative = (fromTop) =>
|
|
5509
|
-
const inRepo =
|
|
5759
|
+
const appRelative = (fromTop) => path30.relative(realpathSync(ctx.root), path30.join(top, fromTop)).split(path30.sep).join("/");
|
|
5760
|
+
const inRepo = path30.relative(top, realpathSync(pkg.dir)).split(path30.sep).join("/");
|
|
5510
5761
|
const diff = (git(top, ["diff", "--name-status", "-M", mergeBase, "--", inRepo]) ?? "").split("\n").filter(Boolean).map((row) => row.split(" ").map((cell2, i) => i === 0 ? cell2 : appRelative(cell2)).join(" ")).join("\n");
|
|
5511
5762
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
5512
5763
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -5529,11 +5780,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
5529
5780
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
5530
5781
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
5531
5782
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
5532
|
-
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) =>
|
|
5783
|
+
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path30.join(top, f)) : [];
|
|
5533
5784
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
5534
5785
|
const named = naming.length > 0;
|
|
5535
5786
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
5536
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
5787
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path30.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
5537
5788
|
}
|
|
5538
5789
|
let jsonBefore = null;
|
|
5539
5790
|
try {
|
|
@@ -5543,7 +5794,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
5543
5794
|
}
|
|
5544
5795
|
const raw = json;
|
|
5545
5796
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
5546
|
-
const appInRepo =
|
|
5797
|
+
const appInRepo = path30.relative(top, realpathSync(ctx.root)).split(path30.sep).join("/");
|
|
5547
5798
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
5548
5799
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
5549
5800
|
if (!registry) ctx.report({ rule: "package-unversioned-change", level: "warn", file: `${pkg.rel}/package.json`, message: `${pkg.name}'s blocks or exports changed but features.ts didn't; update the features they belong to` });
|
|
@@ -5594,7 +5845,7 @@ function checkPackagesPack(ctx) {
|
|
|
5594
5845
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
5595
5846
|
}
|
|
5596
5847
|
for (const pkg of packages) {
|
|
5597
|
-
const json = JSON.parse(readFileSync(
|
|
5848
|
+
const json = JSON.parse(readFileSync(path30.join(pkg.dir, "package.json"), "utf8"));
|
|
5598
5849
|
checkImports2(ctx, pkg, json);
|
|
5599
5850
|
checkExports(ctx, pkg, json);
|
|
5600
5851
|
checkBlocks(ctx, pkg, json);
|
|
@@ -5790,11 +6041,12 @@ function gitView(root, dir, base) {
|
|
|
5790
6041
|
return { touched: touched2, edited };
|
|
5791
6042
|
}
|
|
5792
6043
|
function checkSupabasePack(ctx) {
|
|
6044
|
+
if (databaseElsewhere(ctx.root)) return;
|
|
5793
6045
|
const settings2 = ctx.config.supabase ?? {};
|
|
5794
6046
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
5795
|
-
const abs =
|
|
6047
|
+
const abs = path30.join(ctx.root, dir);
|
|
5796
6048
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
5797
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
6049
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path30.join(abs, n), "utf8")) }));
|
|
5798
6050
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
5799
6051
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
5800
6052
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -5811,7 +6063,7 @@ function checkSupabasePack(ctx) {
|
|
|
5811
6063
|
}
|
|
5812
6064
|
}
|
|
5813
6065
|
const since = settings2.since;
|
|
5814
|
-
const afterSince = (file) => since === void 0 ||
|
|
6066
|
+
const afterSince = (file) => since === void 0 || path30.posix.basename(file) >= since;
|
|
5815
6067
|
if ("reason" in view && since === void 0) {
|
|
5816
6068
|
ctx.report({
|
|
5817
6069
|
rule: "migration-grants",
|
|
@@ -6093,6 +6345,7 @@ var DEFAULT_MIGRATIONS, DEFAULT_BASE, DEFAULT_EXPOSED, schemaOf, TYPE_ALIASES, M
|
|
|
6093
6345
|
var init_supabase = __esm({
|
|
6094
6346
|
"src/doctor/supabase.ts"() {
|
|
6095
6347
|
init_config();
|
|
6348
|
+
init_database();
|
|
6096
6349
|
DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
6097
6350
|
DEFAULT_BASE = "origin/main";
|
|
6098
6351
|
DEFAULT_EXPOSED = ["public"];
|
|
@@ -6111,18 +6364,18 @@ var init_supabase = __esm({
|
|
|
6111
6364
|
}
|
|
6112
6365
|
});
|
|
6113
6366
|
function nodeModulesOf(dir) {
|
|
6114
|
-
const parent =
|
|
6115
|
-
return
|
|
6367
|
+
const parent = path30.dirname(dir);
|
|
6368
|
+
return path30.basename(parent).startsWith("@") ? path30.dirname(parent) : parent;
|
|
6116
6369
|
}
|
|
6117
6370
|
function packagesIn(nodeModules) {
|
|
6118
6371
|
if (!existsSync(nodeModules)) return [];
|
|
6119
6372
|
const out = [];
|
|
6120
6373
|
for (const entry of readdirSync(nodeModules)) {
|
|
6121
6374
|
if (entry.startsWith(".")) continue;
|
|
6122
|
-
const p =
|
|
6375
|
+
const p = path30.join(nodeModules, entry);
|
|
6123
6376
|
if (entry.startsWith("@")) {
|
|
6124
6377
|
try {
|
|
6125
|
-
for (const sub of readdirSync(p)) out.push(
|
|
6378
|
+
for (const sub of readdirSync(p)) out.push(path30.join(p, sub));
|
|
6126
6379
|
} catch {
|
|
6127
6380
|
}
|
|
6128
6381
|
} else {
|
|
@@ -6134,7 +6387,7 @@ function packagesIn(nodeModules) {
|
|
|
6134
6387
|
function genesisInstalls(root) {
|
|
6135
6388
|
const copies = /* @__PURE__ */ new Map();
|
|
6136
6389
|
const realRoot = real(root);
|
|
6137
|
-
const rel = (abs) =>
|
|
6390
|
+
const rel = (abs) => path30.relative(realRoot, abs).split(path30.sep).join("/") || ".";
|
|
6138
6391
|
const via = /* @__PURE__ */ new Map();
|
|
6139
6392
|
const record = (real2, manifest, by, range, root2) => {
|
|
6140
6393
|
let copy = copies.get(real2);
|
|
@@ -6179,7 +6432,7 @@ function genesisInstalls(root) {
|
|
|
6179
6432
|
if (!dir) return null;
|
|
6180
6433
|
if (!ownInstall || name in declared) return dir;
|
|
6181
6434
|
const realDir = real(dir);
|
|
6182
|
-
if (realDir.startsWith(realRoot +
|
|
6435
|
+
if (realDir.startsWith(realRoot + path30.sep)) return dir;
|
|
6183
6436
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
6184
6437
|
};
|
|
6185
6438
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -6187,7 +6440,7 @@ function genesisInstalls(root) {
|
|
|
6187
6440
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
6188
6441
|
});
|
|
6189
6442
|
const app = readManifest(root);
|
|
6190
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
6443
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path30.join(root, f)));
|
|
6191
6444
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
6192
6445
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
6193
6446
|
const runtimeDeps = {
|
|
@@ -6198,11 +6451,11 @@ function genesisInstalls(root) {
|
|
|
6198
6451
|
};
|
|
6199
6452
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
6200
6453
|
walk3("runtime", rootsOf(runtimeDeps, "the app"));
|
|
6201
|
-
const top =
|
|
6454
|
+
const top = path30.join(root, "node_modules");
|
|
6202
6455
|
walk3(
|
|
6203
6456
|
"hoisted",
|
|
6204
6457
|
packagesIn(top).filter((dir) => {
|
|
6205
|
-
const name =
|
|
6458
|
+
const name = path30.relative(top, dir).split(path30.sep).join("/");
|
|
6206
6459
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
6207
6460
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
6208
6461
|
);
|
|
@@ -6244,7 +6497,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
6244
6497
|
}
|
|
6245
6498
|
}
|
|
6246
6499
|
function checkPeerRanges(ctx) {
|
|
6247
|
-
const rel = (abs) =>
|
|
6500
|
+
const rel = (abs) => path30.relative(ctx.root, abs).split(path30.sep).join("/");
|
|
6248
6501
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
6249
6502
|
for (const copy of copies) {
|
|
6250
6503
|
const dir = copy.absolutePath;
|
|
@@ -6277,7 +6530,7 @@ var init_installs = __esm({
|
|
|
6277
6530
|
NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
6278
6531
|
readManifest = (dir) => {
|
|
6279
6532
|
try {
|
|
6280
|
-
return JSON.parse(readFileSync(
|
|
6533
|
+
return JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8"));
|
|
6281
6534
|
} catch {
|
|
6282
6535
|
return null;
|
|
6283
6536
|
}
|
|
@@ -6494,8 +6747,8 @@ function compareVersions2(a, b) {
|
|
|
6494
6747
|
function bumpPackageJson(file, text, wanted) {
|
|
6495
6748
|
const pkg = JSON.parse(text);
|
|
6496
6749
|
const changes = [], skipped = [];
|
|
6497
|
-
for (const
|
|
6498
|
-
for (const [name, spec] of Object.entries(pkg[
|
|
6750
|
+
for (const section2 of SECTIONS) {
|
|
6751
|
+
for (const [name, spec] of Object.entries(pkg[section2] ?? {})) {
|
|
6499
6752
|
if (!GENESIS3.test(name)) continue;
|
|
6500
6753
|
const m = EXACT.exec(spec);
|
|
6501
6754
|
if (!m) {
|
|
@@ -6517,8 +6770,8 @@ function bumpPackageJson(file, text, wanted) {
|
|
|
6517
6770
|
skipped.push({ file, name, spec, why: `newer than ${want}` });
|
|
6518
6771
|
continue;
|
|
6519
6772
|
}
|
|
6520
|
-
pkg[
|
|
6521
|
-
changes.push({ file, name, from: spec, to: pkg[
|
|
6773
|
+
pkg[section2][name] = `${m[1] ?? ""}${want}`;
|
|
6774
|
+
changes.push({ file, name, from: spec, to: pkg[section2][name] });
|
|
6522
6775
|
}
|
|
6523
6776
|
}
|
|
6524
6777
|
if (!changes.length) return { text: null, changes, skipped };
|
|
@@ -6905,6 +7158,131 @@ var init_scope_names = __esm({
|
|
|
6905
7158
|
PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
|
|
6906
7159
|
}
|
|
6907
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
|
+
});
|
|
6908
7286
|
|
|
6909
7287
|
// src/upgrade/codemods.ts
|
|
6910
7288
|
var codemods_exports = {};
|
|
@@ -6913,6 +7291,7 @@ __export(codemods_exports, {
|
|
|
6913
7291
|
appScripts: () => appScripts,
|
|
6914
7292
|
codemodById: () => codemodById,
|
|
6915
7293
|
codemodsFor: () => codemodsFor,
|
|
7294
|
+
genesisEslintConfig: () => genesisEslintConfig,
|
|
6916
7295
|
scopeNeutralNames: () => scopeNeutralNames,
|
|
6917
7296
|
uncoveredBreaks: () => uncoveredBreaks
|
|
6918
7297
|
});
|
|
@@ -6920,11 +7299,11 @@ function appScripts(root) {
|
|
|
6920
7299
|
const out = [];
|
|
6921
7300
|
const walk3 = (dir) => {
|
|
6922
7301
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
6923
|
-
const abs =
|
|
7302
|
+
const abs = path30.join(dir, entry.name);
|
|
6924
7303
|
if (entry.isDirectory()) {
|
|
6925
7304
|
if (!SKIP_DIRS3.has(entry.name)) walk3(abs);
|
|
6926
7305
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
6927
|
-
out.push(
|
|
7306
|
+
out.push(path30.relative(root, abs).split(path30.sep).join("/"));
|
|
6928
7307
|
}
|
|
6929
7308
|
}
|
|
6930
7309
|
};
|
|
@@ -6946,10 +7325,11 @@ function uncoveredBreaks(changes, registry = CODEMODS) {
|
|
|
6946
7325
|
};
|
|
6947
7326
|
return changes.filter((c) => major(c.from) !== major(c.to) && codemodsFor([c], registry).length === 0);
|
|
6948
7327
|
}
|
|
6949
|
-
var SKIP_DIRS3, SCRIPT2, MAX_BYTES, scopeNeutralNames, CODEMODS, bare;
|
|
7328
|
+
var SKIP_DIRS3, SCRIPT2, MAX_BYTES, scopeNeutralNames, genesisEslintConfig, CODEMODS, bare;
|
|
6950
7329
|
var init_codemods = __esm({
|
|
6951
7330
|
"src/upgrade/codemods.ts"() {
|
|
6952
7331
|
init_bump_core();
|
|
7332
|
+
init_eslint_config();
|
|
6953
7333
|
init_scope_names();
|
|
6954
7334
|
SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
6955
7335
|
SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
@@ -6964,7 +7344,7 @@ var init_codemods = __esm({
|
|
|
6964
7344
|
let readsId = false;
|
|
6965
7345
|
let augmented = false;
|
|
6966
7346
|
for (const rel of appScripts(root)) {
|
|
6967
|
-
const abs =
|
|
7347
|
+
const abs = path30.join(root, rel);
|
|
6968
7348
|
const text = readFileSync(abs, "utf8");
|
|
6969
7349
|
if (augmentsResourceScope(text)) augmented = true;
|
|
6970
7350
|
if (!IMPORTS_GENESIS.test(text)) continue;
|
|
@@ -6981,7 +7361,49 @@ var init_codemods = __esm({
|
|
|
6981
7361
|
return changed;
|
|
6982
7362
|
}
|
|
6983
7363
|
};
|
|
6984
|
-
|
|
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];
|
|
6985
7407
|
bare = (spec) => spec.replace(/^[\^~=]/, "");
|
|
6986
7408
|
}
|
|
6987
7409
|
});
|
|
@@ -7060,7 +7482,7 @@ function checkTreeViews(ctx) {
|
|
|
7060
7482
|
function moduleFiles(ctx) {
|
|
7061
7483
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
7062
7484
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
7063
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
7485
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path30.join(ctx.root, rel), "utf8"), true) }));
|
|
7064
7486
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
7065
7487
|
}
|
|
7066
7488
|
function checkStudioServerImports(ctx) {
|
|
@@ -7090,7 +7512,7 @@ function checkStudioServerImports(ctx) {
|
|
|
7090
7512
|
}
|
|
7091
7513
|
function checkRemovedScopeNames(ctx) {
|
|
7092
7514
|
let augmentedMemo;
|
|
7093
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
7515
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path30.join(ctx.root, rel), "utf8")));
|
|
7094
7516
|
for (const file of ctx.files) {
|
|
7095
7517
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
7096
7518
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -7179,16 +7601,16 @@ function genesisNamedImports(source) {
|
|
|
7179
7601
|
}
|
|
7180
7602
|
function declarationFiles(dir, out = []) {
|
|
7181
7603
|
for (const name of readdirSync(dir)) {
|
|
7182
|
-
const full =
|
|
7604
|
+
const full = path30.join(dir, name);
|
|
7183
7605
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
7184
7606
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
7185
7607
|
}
|
|
7186
7608
|
return out;
|
|
7187
7609
|
}
|
|
7188
7610
|
function readPackageTags(dir) {
|
|
7189
|
-
const pkg = JSON.parse(readFileSync(
|
|
7611
|
+
const pkg = JSON.parse(readFileSync(path30.join(dir, "package.json"), "utf8"));
|
|
7190
7612
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
7191
|
-
const dist =
|
|
7613
|
+
const dist = path30.join(dir, "dist");
|
|
7192
7614
|
if (!existsSync(dist)) return tags;
|
|
7193
7615
|
for (const file of declarationFiles(dist)) {
|
|
7194
7616
|
const text = readFileSync(file, "utf8");
|
|
@@ -7206,7 +7628,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
7206
7628
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
7207
7629
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
7208
7630
|
const types = typeof target === "object" && target ? target.types : null;
|
|
7209
|
-
return typeof types === "string" ?
|
|
7631
|
+
return typeof types === "string" ? path30.join(tags.dir, types) : null;
|
|
7210
7632
|
}
|
|
7211
7633
|
function tagFor(tags, entry, name) {
|
|
7212
7634
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -7270,7 +7692,7 @@ function showAt(dir, rev, file) {
|
|
|
7270
7692
|
function configAtBase(root, base, explicitFile) {
|
|
7271
7693
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
7272
7694
|
if (!mergeBase) return null;
|
|
7273
|
-
const candidates = explicitFile ? [{ dir:
|
|
7695
|
+
const candidates = explicitFile ? [{ dir: path30.dirname(explicitFile), file: path30.basename(explicitFile), explicit: true }] : [
|
|
7274
7696
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
7275
7697
|
{ dir: root, file: "package.json", explicit: false }
|
|
7276
7698
|
];
|
|
@@ -7460,13 +7882,13 @@ function currentAgentsBlock(agents) {
|
|
|
7460
7882
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
7461
7883
|
const rows = primitivesCatalog(packages);
|
|
7462
7884
|
const changed = [];
|
|
7463
|
-
const agents =
|
|
7885
|
+
const agents = path30.join(root, agentsFile);
|
|
7464
7886
|
const before = read(agents);
|
|
7465
7887
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
7466
|
-
const skill =
|
|
7888
|
+
const skill = path30.join(root, SKILL_PATH);
|
|
7467
7889
|
const skillText = renderSkill(rows);
|
|
7468
7890
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
7469
|
-
mkdirSync(
|
|
7891
|
+
mkdirSync(path30.dirname(skill), { recursive: true });
|
|
7470
7892
|
writeFileSync(skill, skillText);
|
|
7471
7893
|
changed.push(SKILL_PATH);
|
|
7472
7894
|
}
|
|
@@ -7478,8 +7900,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
7478
7900
|
}
|
|
7479
7901
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
7480
7902
|
const rows = primitivesCatalog(packages);
|
|
7481
|
-
const skill = read(
|
|
7482
|
-
const block = currentAgentsBlock(read(
|
|
7903
|
+
const skill = read(path30.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
7904
|
+
const block = currentAgentsBlock(read(path30.join(root, agentsFile)));
|
|
7483
7905
|
return {
|
|
7484
7906
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
7485
7907
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -7595,9 +8017,9 @@ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
|
7595
8017
|
return `${key2} doesn't match its source ${source}`;
|
|
7596
8018
|
}
|
|
7597
8019
|
function mergeThreeWay(mine, base, theirs) {
|
|
7598
|
-
const dir = mkdtempSync(
|
|
8020
|
+
const dir = mkdtempSync(path30.join(tmpdir(), "genesis-merge-"));
|
|
7599
8021
|
try {
|
|
7600
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
8022
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path30.join(dir, n));
|
|
7601
8023
|
writeFileSync(m, mine);
|
|
7602
8024
|
writeFileSync(b, base);
|
|
7603
8025
|
writeFileSync(t, theirs);
|
|
@@ -7679,8 +8101,225 @@ var init_owned = __esm({
|
|
|
7679
8101
|
CLI = "@marktiderman/genesis-cli";
|
|
7680
8102
|
}
|
|
7681
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
|
+
}
|
|
7682
8320
|
async function checkLockFiles(ctx) {
|
|
7683
|
-
|
|
8321
|
+
checkBunLock(ctx);
|
|
8322
|
+
if (!existsSync(path30.join(ctx.root, LOCK_FILE))) return;
|
|
7684
8323
|
let lock;
|
|
7685
8324
|
try {
|
|
7686
8325
|
lock = readLock(ctx.root);
|
|
@@ -7708,15 +8347,44 @@ async function checkLockFiles(ctx) {
|
|
|
7708
8347
|
});
|
|
7709
8348
|
}
|
|
7710
8349
|
const local = localPackageNames(ctx.root);
|
|
8350
|
+
let home = null;
|
|
8351
|
+
try {
|
|
8352
|
+
home = databaseElsewhere(ctx.root);
|
|
8353
|
+
} catch {
|
|
8354
|
+
}
|
|
8355
|
+
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
8356
|
+
if (home && elsewhere.length) {
|
|
8357
|
+
ctx.report({
|
|
8358
|
+
rule: "lock-files",
|
|
8359
|
+
level: "info",
|
|
8360
|
+
file: LOCK_FILE,
|
|
8361
|
+
subject: "supabase/",
|
|
8362
|
+
message: `lists ${elsewhere.length} file${elsewhere.length === 1 ? "" : "s"} under supabase/, but this app's database files live ${home.app ? `in ${home.app}` : "nowhere"} (genesis.config.json supabase): genesis upgrade leaves them alone, so delete those entries`
|
|
8363
|
+
});
|
|
8364
|
+
}
|
|
7711
8365
|
for (const [rel, entry] of Object.entries(lock.files)) {
|
|
8366
|
+
if (home && isSupabasePath(rel)) continue;
|
|
7712
8367
|
if (ownedKeyProblem(rel, entry.source, local)) continue;
|
|
7713
8368
|
if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
|
|
7714
|
-
let
|
|
8369
|
+
let file;
|
|
7715
8370
|
try {
|
|
7716
|
-
|
|
8371
|
+
file = appPath(ctx.root, rel);
|
|
7717
8372
|
} catch {
|
|
7718
8373
|
continue;
|
|
7719
8374
|
}
|
|
8375
|
+
let text;
|
|
8376
|
+
try {
|
|
8377
|
+
text = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
8378
|
+
} catch (err) {
|
|
8379
|
+
ctx.report({
|
|
8380
|
+
rule: "lock-files",
|
|
8381
|
+
level: "warn",
|
|
8382
|
+
file: rel,
|
|
8383
|
+
subject: rel,
|
|
8384
|
+
message: `is in ${LOCK_FILE} (from ${entry.source}) but can't be read (${err instanceof Error ? err.message : String(err)}), so genesis upgrade can't refresh it. Make it a file again, or remove its entry from ${LOCK_FILE}`
|
|
8385
|
+
});
|
|
8386
|
+
continue;
|
|
8387
|
+
}
|
|
7720
8388
|
if (text === null) {
|
|
7721
8389
|
if (entry.deleted) continue;
|
|
7722
8390
|
ctx.report({
|
|
@@ -7749,6 +8417,71 @@ var init_lock_files = __esm({
|
|
|
7749
8417
|
init_local();
|
|
7750
8418
|
init_owned();
|
|
7751
8419
|
init_starter_features();
|
|
8420
|
+
init_database();
|
|
8421
|
+
init_bun_lock();
|
|
8422
|
+
init_pm();
|
|
8423
|
+
}
|
|
8424
|
+
});
|
|
8425
|
+
function checkDatabaseHome(ctx) {
|
|
8426
|
+
const home = databaseElsewhere(ctx.root);
|
|
8427
|
+
if (!home) return;
|
|
8428
|
+
if (home.app && !home.hasSupabase) {
|
|
8429
|
+
ctx.report({
|
|
8430
|
+
rule: "database-elsewhere",
|
|
8431
|
+
level: "warn",
|
|
8432
|
+
file: "genesis.config.json",
|
|
8433
|
+
subject: home.app,
|
|
8434
|
+
message: `supabase.app is ${home.app}, which has no supabase folder; name the app that holds this app's database (its migrations, tests and Edge Functions)`
|
|
8435
|
+
});
|
|
8436
|
+
}
|
|
8437
|
+
if (existsSync(path30.join(ctx.root, "supabase"))) {
|
|
8438
|
+
ctx.report({
|
|
8439
|
+
rule: "database-elsewhere",
|
|
8440
|
+
level: "warn",
|
|
8441
|
+
file: "supabase",
|
|
8442
|
+
subject: "supabase/",
|
|
8443
|
+
message: `is here, but genesis.config.json says this app's database files live ${home.app ? `in ${home.app}/supabase` : "nowhere"}: genesis add, migrate and upgrade never plan it, so it is a second, unused copy. Delete it`
|
|
8444
|
+
});
|
|
8445
|
+
}
|
|
8446
|
+
}
|
|
8447
|
+
var init_database2 = __esm({
|
|
8448
|
+
"src/doctor/database.ts"() {
|
|
8449
|
+
init_database();
|
|
8450
|
+
}
|
|
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();
|
|
7752
8485
|
}
|
|
7753
8486
|
});
|
|
7754
8487
|
|
|
@@ -7801,7 +8534,7 @@ __export(doctor_exports, {
|
|
|
7801
8534
|
writeAgentGuide: () => writeAgentGuide
|
|
7802
8535
|
});
|
|
7803
8536
|
async function runDoctor(options = {}) {
|
|
7804
|
-
const root =
|
|
8537
|
+
const root = path30.resolve(options.root ?? process.cwd());
|
|
7805
8538
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
7806
8539
|
const config = loaded.config;
|
|
7807
8540
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -7855,7 +8588,7 @@ async function runDoctor(options = {}) {
|
|
|
7855
8588
|
}
|
|
7856
8589
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
7857
8590
|
if (options.base && changed) {
|
|
7858
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
8591
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path30.join(root, f)) });
|
|
7859
8592
|
}
|
|
7860
8593
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
7861
8594
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -7901,6 +8634,8 @@ function builtinChecks(config, options = {}) {
|
|
|
7901
8634
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
7902
8635
|
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
7903
8636
|
{ name: "lock-files", check: checkLockFiles },
|
|
8637
|
+
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
8638
|
+
{ name: "eslint-config", check: checkEslintConfig },
|
|
7904
8639
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
7905
8640
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
7906
8641
|
];
|
|
@@ -8016,6 +8751,8 @@ var init_doctor = __esm({
|
|
|
8016
8751
|
init_primitives();
|
|
8017
8752
|
init_overlays();
|
|
8018
8753
|
init_lock_files();
|
|
8754
|
+
init_database2();
|
|
8755
|
+
init_eslint_config2();
|
|
8019
8756
|
init_config();
|
|
8020
8757
|
init_genesis();
|
|
8021
8758
|
init_patterns();
|
|
@@ -8032,7 +8769,7 @@ var init_doctor = __esm({
|
|
|
8032
8769
|
init_primitives();
|
|
8033
8770
|
init_ratchet();
|
|
8034
8771
|
init_contracts();
|
|
8035
|
-
RATCHETED_BY_DEFAULT = ["deprecated-import"];
|
|
8772
|
+
RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
|
|
8036
8773
|
}
|
|
8037
8774
|
});
|
|
8038
8775
|
|
|
@@ -8045,12 +8782,12 @@ __export(agent_rules_exports, {
|
|
|
8045
8782
|
runsOnPullRequestsInto: () => runsOnPullRequestsInto
|
|
8046
8783
|
});
|
|
8047
8784
|
function changesetBumps(root) {
|
|
8048
|
-
const dir =
|
|
8785
|
+
const dir = path30.join(root, ".changeset");
|
|
8049
8786
|
const bumps = /* @__PURE__ */ new Map();
|
|
8050
8787
|
if (!existsSync(dir)) return bumps;
|
|
8051
8788
|
for (const name of readdirSync(dir)) {
|
|
8052
8789
|
if (!name.endsWith(".md") || name === "README.md") continue;
|
|
8053
|
-
const text = readFileSync(
|
|
8790
|
+
const text = readFileSync(path30.join(dir, name), "utf8");
|
|
8054
8791
|
const front = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? "";
|
|
8055
8792
|
for (const line of front.split(/\r?\n/)) {
|
|
8056
8793
|
const m = /^\s*["']?([^"':]+)["']?\s*:\s*(major|minor|patch)\s*$/.exec(line);
|
|
@@ -8063,13 +8800,13 @@ function changesetBumps(root) {
|
|
|
8063
8800
|
return bumps;
|
|
8064
8801
|
}
|
|
8065
8802
|
function firstVersionProblems(root) {
|
|
8066
|
-
const packagesDir =
|
|
8803
|
+
const packagesDir = path30.join(root, "packages");
|
|
8067
8804
|
if (!existsSync(packagesDir)) return [];
|
|
8068
8805
|
const bumps = changesetBumps(root);
|
|
8069
8806
|
const problems = [];
|
|
8070
8807
|
for (const dir of readdirSync(packagesDir)) {
|
|
8071
|
-
const file =
|
|
8072
|
-
if (!existsSync(file) || existsSync(
|
|
8808
|
+
const file = path30.join(packagesDir, dir, "package.json");
|
|
8809
|
+
if (!existsSync(file) || existsSync(path30.join(packagesDir, dir, "CHANGELOG.md"))) continue;
|
|
8073
8810
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
8074
8811
|
if (pkg.private || !pkg.name) continue;
|
|
8075
8812
|
if (pkg.version !== FIRST_VERSION) {
|
|
@@ -8140,12 +8877,12 @@ function runsOnPullRequestsInto(workflow, branch) {
|
|
|
8140
8877
|
return ignore ? !ignore.some((p) => globMatches(p, branch)) : void 0;
|
|
8141
8878
|
}
|
|
8142
8879
|
function batchCiProblems(root, batch) {
|
|
8143
|
-
const dir =
|
|
8880
|
+
const dir = path30.join(root, ".github", "workflows");
|
|
8144
8881
|
if (!existsSync(dir)) return [];
|
|
8145
8882
|
const problems = [];
|
|
8146
8883
|
for (const name of readdirSync(dir)) {
|
|
8147
8884
|
if (!/\.ya?ml$/.test(name)) continue;
|
|
8148
|
-
const workflow = readFileSync(
|
|
8885
|
+
const workflow = readFileSync(path30.join(dir, name), "utf8");
|
|
8149
8886
|
const main = runsOnPullRequestsInto(workflow, "main");
|
|
8150
8887
|
if (main && !runsOnPullRequestsInto(workflow, sampleBranch(batch))) {
|
|
8151
8888
|
problems.push({ rule: "batch-ci", message: `.github/workflows/${name}: runs on pull requests into main but not into ${batch}; let pull_request's branch filter include it` });
|
|
@@ -8190,20 +8927,20 @@ function readObject(file, key2) {
|
|
|
8190
8927
|
}
|
|
8191
8928
|
}
|
|
8192
8929
|
function settings(root, options) {
|
|
8193
|
-
const fromPackage = readObject(
|
|
8194
|
-
const fromConfig = readObject(
|
|
8930
|
+
const fromPackage = readObject(path30.join(root, "package.json"), "genesisFeatures");
|
|
8931
|
+
const fromConfig = readObject(path30.join(root, "genesis.config.json"), "features");
|
|
8195
8932
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
8196
8933
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
8197
8934
|
}
|
|
8198
8935
|
async function loadRegistry(input) {
|
|
8199
|
-
const root =
|
|
8936
|
+
const root = path30.resolve(input.dir);
|
|
8200
8937
|
const options = settings(root, input);
|
|
8201
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
8202
|
-
if (!registry || !existsSync(
|
|
8938
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path30.join(root, p)));
|
|
8939
|
+
if (!registry || !existsSync(path30.join(root, registry))) {
|
|
8203
8940
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
8204
8941
|
}
|
|
8205
|
-
const jiti = createJiti(
|
|
8206
|
-
const load = async (file) => await jiti.import(
|
|
8942
|
+
const jiti = createJiti(path30.join(root, "package.json"), { moduleCache: false });
|
|
8943
|
+
const load = async (file) => await jiti.import(path30.join(root, file));
|
|
8207
8944
|
const mod = await load(registry);
|
|
8208
8945
|
const features2 = mod.features ?? mod.default;
|
|
8209
8946
|
if (!isObject4(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -8215,7 +8952,7 @@ async function loadRegistry(input) {
|
|
|
8215
8952
|
const project = {
|
|
8216
8953
|
...rest,
|
|
8217
8954
|
root,
|
|
8218
|
-
source: options.source ?? registry.split(
|
|
8955
|
+
source: options.source ?? registry.split(path30.sep).join("/"),
|
|
8219
8956
|
features: features2,
|
|
8220
8957
|
flags
|
|
8221
8958
|
};
|
|
@@ -8266,23 +9003,23 @@ async function runFeaturesCheck(options) {
|
|
|
8266
9003
|
function readFeaturePackages(root) {
|
|
8267
9004
|
const found = [];
|
|
8268
9005
|
const read2 = (dir, inRepo) => {
|
|
8269
|
-
const file =
|
|
9006
|
+
const file = path30.join(dir, "package.json");
|
|
8270
9007
|
if (!existsSync(file)) return;
|
|
8271
9008
|
try {
|
|
8272
9009
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
8273
9010
|
const layer = pkg.genesis?.layer;
|
|
8274
9011
|
if (typeof pkg.name !== "string" || !PACKAGE_LAYERS.includes(layer)) return;
|
|
8275
9012
|
if (found.some((p) => p.name === pkg.name)) return;
|
|
8276
|
-
found.push({ name: pkg.name, layer, ...inRepo ? { dir:
|
|
9013
|
+
found.push({ name: pkg.name, layer, ...inRepo ? { dir: path30.relative(root, dir).split(path30.sep).join("/") } : {} });
|
|
8277
9014
|
} catch {
|
|
8278
9015
|
}
|
|
8279
9016
|
};
|
|
8280
9017
|
for (const [base, inRepo] of [
|
|
8281
|
-
[
|
|
8282
|
-
[
|
|
9018
|
+
[path30.join(root, "packages"), true],
|
|
9019
|
+
[path30.join(root, "node_modules", "@marktiderman"), false]
|
|
8283
9020
|
]) {
|
|
8284
9021
|
if (!existsSync(base)) continue;
|
|
8285
|
-
for (const name of readdirSync(base)) read2(
|
|
9022
|
+
for (const name of readdirSync(base)) read2(path30.join(base, name), inRepo);
|
|
8286
9023
|
}
|
|
8287
9024
|
return found;
|
|
8288
9025
|
}
|
|
@@ -8399,7 +9136,7 @@ function readRegister(markdown) {
|
|
|
8399
9136
|
const need = at(row, "need");
|
|
8400
9137
|
if (!need || need === "-") problems.push(`${where2}: say the need in one line`);
|
|
8401
9138
|
const local = at(row, "local");
|
|
8402
|
-
if (local && local !== "-" && localPaths(local).some((p) =>
|
|
9139
|
+
if (local && local !== "-" && localPaths(local).some((p) => path30.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p) || p.split(/[\\/]/).includes(".."))) {
|
|
8403
9140
|
problems.push(`${where2}: local must be paths inside the app, relative to its root`);
|
|
8404
9141
|
}
|
|
8405
9142
|
const opt = (c) => at(row, c) && at(row, c) !== "-" ? at(row, c) : void 0;
|
|
@@ -8411,13 +9148,13 @@ function localPaths(local) {
|
|
|
8411
9148
|
return (local ?? "").split(/,\s+|<br\s*\/?>/i).map((p) => p.trim()).filter((p) => p && p !== "-");
|
|
8412
9149
|
}
|
|
8413
9150
|
function checkUpstream(root) {
|
|
8414
|
-
const found = REGISTER_PATHS.find((p) => existsSync(
|
|
9151
|
+
const found = REGISTER_PATHS.find((p) => existsSync(path30.join(root, p)));
|
|
8415
9152
|
if (!found) return { entries: [], problems: [], warnings: [`no ${REGISTER_PATHS.join(" or ")}: nothing to check (add one when the app first needs something Genesis lacks)`], missing: true };
|
|
8416
|
-
const { entries, problems } = readRegister(readFileSync(
|
|
9153
|
+
const { entries, problems } = readRegister(readFileSync(path30.join(root, found), "utf8"));
|
|
8417
9154
|
const warnings = [];
|
|
8418
9155
|
for (const e of entries) {
|
|
8419
9156
|
const paths = localPaths(e.local);
|
|
8420
|
-
const absent = paths.filter((p) => !existsSync(
|
|
9157
|
+
const absent = paths.filter((p) => !existsSync(path30.join(root, p)));
|
|
8421
9158
|
const present = paths.filter((p) => !absent.includes(p));
|
|
8422
9159
|
if (absent.length && e.status !== "promoted" && e.status !== "declined") problems.push(`${e.id}: local ${absent.join(", ")} doesn't exist`);
|
|
8423
9160
|
if (present.length && e.status === "promoted") {
|
|
@@ -8482,8 +9219,8 @@ function routeTags(source) {
|
|
|
8482
9219
|
}
|
|
8483
9220
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
8484
9221
|
const tags = routeTags(source);
|
|
8485
|
-
const
|
|
8486
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
9222
|
+
const relative17 = route.replace(/^\//, "");
|
|
9223
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative17.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
8487
9224
|
if (existing) {
|
|
8488
9225
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
8489
9226
|
}
|
|
@@ -8491,17 +9228,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
8491
9228
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
8492
9229
|
if (roots.length !== 1) {
|
|
8493
9230
|
return {
|
|
8494
|
-
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="${
|
|
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.`
|
|
8495
9232
|
};
|
|
8496
9233
|
}
|
|
8497
9234
|
const layout = roots[0];
|
|
8498
9235
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
8499
|
-
if (base && !
|
|
9236
|
+
if (base && !relative17.startsWith(`${base}/`)) {
|
|
8500
9237
|
return {
|
|
8501
9238
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
8502
9239
|
};
|
|
8503
9240
|
}
|
|
8504
|
-
const childPath = base ?
|
|
9241
|
+
const childPath = base ? relative17.slice(base.length + 1) : relative17;
|
|
8505
9242
|
const guard = GUARD.exec(source)?.[1];
|
|
8506
9243
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
8507
9244
|
const before = source.slice(0, layout.close);
|
|
@@ -8875,8 +9612,8 @@ ${indent}}`;
|
|
|
8875
9612
|
return JSON.stringify(value);
|
|
8876
9613
|
}
|
|
8877
9614
|
function featureKindField(root) {
|
|
8878
|
-
for (let dir =
|
|
8879
|
-
for (const file of [
|
|
9615
|
+
for (let dir = path30.resolve(root); ; dir = path30.dirname(dir)) {
|
|
9616
|
+
for (const file of [path30.join(dir, "node_modules/@marktiderman/genesis-features/package.json"), path30.join(dir, "packages/features/package.json")]) {
|
|
8880
9617
|
try {
|
|
8881
9618
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
8882
9619
|
if (pkg.name !== "@marktiderman/genesis-features" || !pkg.version) continue;
|
|
@@ -8885,7 +9622,7 @@ function featureKindField(root) {
|
|
|
8885
9622
|
} catch {
|
|
8886
9623
|
}
|
|
8887
9624
|
}
|
|
8888
|
-
if (
|
|
9625
|
+
if (path30.dirname(dir) === dir) return "layer";
|
|
8889
9626
|
}
|
|
8890
9627
|
}
|
|
8891
9628
|
function featureSnippet(manifest, owner, kindField = "kind") {
|
|
@@ -8963,12 +9700,12 @@ var init_registry_edit = __esm({
|
|
|
8963
9700
|
});
|
|
8964
9701
|
function routerRoot2(root) {
|
|
8965
9702
|
try {
|
|
8966
|
-
const config = JSON.parse(readFileSync(
|
|
9703
|
+
const config = JSON.parse(readFileSync(path30.join(root, "genesis.config.json"), "utf8"));
|
|
8967
9704
|
const configured = config.doctor?.native?.routerRoot;
|
|
8968
|
-
if (configured && existsSync(
|
|
9705
|
+
if (configured && existsSync(path30.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
8969
9706
|
} catch {
|
|
8970
9707
|
}
|
|
8971
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
9708
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path30.join(root, dir, "_layout.tsx"))) return dir;
|
|
8972
9709
|
return null;
|
|
8973
9710
|
}
|
|
8974
9711
|
function routeOf(file) {
|
|
@@ -9030,7 +9767,7 @@ __export(add_exports, {
|
|
|
9030
9767
|
});
|
|
9031
9768
|
function appDependencies(root) {
|
|
9032
9769
|
try {
|
|
9033
|
-
const pkg = JSON.parse(readFileSync(
|
|
9770
|
+
const pkg = JSON.parse(readFileSync(path30.join(root, "package.json"), "utf8"));
|
|
9034
9771
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
9035
9772
|
} catch {
|
|
9036
9773
|
return {};
|
|
@@ -9039,14 +9776,14 @@ function appDependencies(root) {
|
|
|
9039
9776
|
function registryFile(root) {
|
|
9040
9777
|
const read2 = (file, key2) => {
|
|
9041
9778
|
try {
|
|
9042
|
-
const v = JSON.parse(readFileSync(
|
|
9779
|
+
const v = JSON.parse(readFileSync(path30.join(root, file), "utf8"))[key2]?.registry;
|
|
9043
9780
|
return typeof v === "string" ? v : void 0;
|
|
9044
9781
|
} catch {
|
|
9045
9782
|
return void 0;
|
|
9046
9783
|
}
|
|
9047
9784
|
};
|
|
9048
9785
|
const named = read2("genesis.config.json", "features") ?? read2("package.json", "genesisFeatures");
|
|
9049
|
-
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(
|
|
9786
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path30.join(root, candidate))) return candidate;
|
|
9050
9787
|
return null;
|
|
9051
9788
|
}
|
|
9052
9789
|
async function registryIds(root, file) {
|
|
@@ -9134,23 +9871,28 @@ verify_jwt = false
|
|
|
9134
9871
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
9135
9872
|
}
|
|
9136
9873
|
async function runAdd(options) {
|
|
9137
|
-
const root =
|
|
9874
|
+
const root = path30.resolve(options.root);
|
|
9138
9875
|
const log = options.log ?? SILENT;
|
|
9139
9876
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
9140
9877
|
const warnings = [];
|
|
9141
9878
|
const install = options.install !== false;
|
|
9142
9879
|
let found = await findBlock(root, options.block, { ...options.package ? { package: options.package } : {}, warnings });
|
|
9143
9880
|
const lock = readLock(root);
|
|
9881
|
+
const home = databaseElsewhere(root);
|
|
9882
|
+
const databaseOnly = options.databaseOnly === true;
|
|
9883
|
+
if (databaseOnly && home) throw new Error(`--database-only adds a block's database files, and ${home.app ? `this app's are in ${home.app}` : "this app has none"} (genesis.config.json supabase): run it there.`);
|
|
9884
|
+
if (databaseOnly && !found.manifest.migrations.length && !found.manifest.functions.length) throw new Error(`${found.manifest.id} has no database files (migrations or Edge Functions); --database-only has nothing to add.`);
|
|
9144
9885
|
const deps = appDependencies(root);
|
|
9145
9886
|
const pm = detectPackageManager(root);
|
|
9146
9887
|
const specs = [];
|
|
9147
9888
|
const local = localPackageNames(root);
|
|
9148
|
-
|
|
9889
|
+
const needed = databaseOnly ? [.../* @__PURE__ */ new Set([...found.manifest.migrations.map((m) => m.package), ...found.manifest.functions.map((f) => f.package)])] : found.manifest.packages;
|
|
9890
|
+
for (const name of needed) {
|
|
9149
9891
|
if (deps[name] || local.has(name)) continue;
|
|
9150
9892
|
const pin = pinnedVersion2(root, name);
|
|
9151
9893
|
specs.push(pin ? `${name}@${pin.version}` : name);
|
|
9152
9894
|
}
|
|
9153
|
-
for (const spec of found.manifest.install) {
|
|
9895
|
+
for (const spec of databaseOnly ? [] : found.manifest.install) {
|
|
9154
9896
|
const name = spec.startsWith("@") ? `@${spec.slice(1).split("@")[0]}` : spec.split("@")[0];
|
|
9155
9897
|
if (!deps[name]) specs.push(spec);
|
|
9156
9898
|
}
|
|
@@ -9158,7 +9900,7 @@ async function runAdd(options) {
|
|
|
9158
9900
|
const registry = registryFile(root);
|
|
9159
9901
|
const ids = registry ? await registryIds(root, registry) : null;
|
|
9160
9902
|
const blockIds = new Set((await allBlocks(root)).map((b) => b.manifest.id));
|
|
9161
|
-
for (const req of found.manifest.requires) {
|
|
9903
|
+
for (const req of databaseOnly ? [] : found.manifest.requires) {
|
|
9162
9904
|
if (lock.blocks[req] || ids?.has(req)) continue;
|
|
9163
9905
|
warnings.push(blockIds.has(req) ? `${options.block} requires the ${req} block: add it too (genesis add ${req}), unless the app already has it.` : `${options.block} requires the ${req} feature; make sure the app has it.`);
|
|
9164
9906
|
}
|
|
@@ -9166,25 +9908,35 @@ async function runAdd(options) {
|
|
|
9166
9908
|
const kept = [];
|
|
9167
9909
|
const created = [];
|
|
9168
9910
|
const edited = [];
|
|
9169
|
-
const makePlan = (
|
|
9911
|
+
const makePlan = (full, from) => {
|
|
9170
9912
|
const planWarnings = [];
|
|
9171
|
-
const
|
|
9172
|
-
const
|
|
9173
|
-
const
|
|
9174
|
-
|
|
9175
|
-
const
|
|
9176
|
-
|
|
9913
|
+
const catalog = catalogBlocks();
|
|
9914
|
+
const providers = providingMigrations([full, ...catalog]);
|
|
9915
|
+
const migrations2 = home ? { rows: [], creates: [] } : planMigrations(root, sourceMigrations(root, full), { now, ...lock.migrations ? { copied: lock.migrations } : {}, providers });
|
|
9916
|
+
const superseded = supersededFunctions(migrations2.rows, providers);
|
|
9917
|
+
const replaced2 = full.functions.filter((fn) => superseded.has(`${fn.package}:${fn.dir}`)).map((fn) => {
|
|
9918
|
+
const by = superseded.get(`${fn.package}:${fn.dir}`);
|
|
9919
|
+
const block = providers.find((p) => p.package === by.package && p.file === by.file)?.block;
|
|
9920
|
+
const instead = (block ? catalog.find((b) => b.id === block)?.functions : void 0)?.map((f) => f.dir.split("/").pop()) ?? [];
|
|
9921
|
+
return { name: fn.dir.split("/").pop(), by, block, instead };
|
|
9922
|
+
});
|
|
9923
|
+
const manifest2 = { ...full, functions: full.functions.filter((fn) => !superseded.has(`${fn.package}:${fn.dir}`)) };
|
|
9924
|
+
const owned2 = ownedWrites(root, databaseOnly ? { ...manifest2, skills: [] } : manifest2, planWarnings).filter((w) => !home || !isSupabasePath(w.path)).map((w) => ({ ...w, content: substitute(w.content, lock.substitutions) }));
|
|
9925
|
+
const fragment2 = databaseOnly ? null : agentsFragment(root, manifest2);
|
|
9926
|
+
if (!databaseOnly && manifest2.agents && !fragment2) planWarnings.push(`${manifest2.agents.package} ${manifest2.agents.path}: can't read it; AGENTS.md wasn't changed.`);
|
|
9927
|
+
const { routerRoot: routerRoot4, stubs: stubs2 } = databaseOnly ? { routerRoot: null, stubs: [] } : planRouteStubs(root, manifest2.routes);
|
|
9928
|
+
const toml2 = home ? null : configTomlEdit(root, manifest2, planWarnings);
|
|
9177
9929
|
let snippet2;
|
|
9178
9930
|
let registryEdit2 = null;
|
|
9179
|
-
if (!ids?.has(manifest2.id)) {
|
|
9931
|
+
if (!databaseOnly && !ids?.has(manifest2.id)) {
|
|
9180
9932
|
const owner = JSON.parse(readApp(root, "package.json") ?? "{}").name ?? "app";
|
|
9181
9933
|
snippet2 = featureSnippet(manifest2, owner, featureKindField(root));
|
|
9182
9934
|
if (registry) registryEdit2 = addFeatureEntry(readApp(root, registry) ?? "", snippet2);
|
|
9183
9935
|
}
|
|
9184
9936
|
const print = (mark, p, note = "") => log.info(` ${mark} ${p}${note ? ` ${note}` : ""}`);
|
|
9185
|
-
log.info(`${manifest2.id}: from ${manifest2.package}${manifest2.version ? ` ${manifest2.version}` : ""} (${from === "local" ? "local package" : from === "installed" ? "installed" : "not installed yet: files are read after the install"})`);
|
|
9937
|
+
log.info(`${manifest2.id}${databaseOnly ? " (database only)" : ""}: from ${manifest2.package}${manifest2.version ? ` ${manifest2.version}` : ""} (${from === "local" ? "local package" : from === "installed" ? "installed" : "not installed yet: files are read after the install"})`);
|
|
9186
9938
|
if (command) log.info(` install: ${shellLine(command)}${install ? "" : " (skipped: --no-install)"}`);
|
|
9187
|
-
log.info(formatMigrationRows(migrations2.rows).replace(/^/gm, " "));
|
|
9939
|
+
log.info(` ${home ? elsewhereNote(home, addThereCommand(manifest2.id)) : formatMigrationRows(migrations2.rows).replace(/^/gm, " ").trimStart()}`);
|
|
9188
9940
|
for (const c of migrations2.creates) if (c.kind === "test") print("+", c.path, "(pgTAP test)");
|
|
9189
9941
|
for (const w of owned2) {
|
|
9190
9942
|
const existing = readApp(root, w.path);
|
|
@@ -9194,7 +9946,8 @@ async function runAdd(options) {
|
|
|
9194
9946
|
if (toml2) print("~", "supabase/config.toml", `([functions.${toml2.names.join("], [functions.")}] verify_jwt = false)`);
|
|
9195
9947
|
if (fragment2) print("~", "AGENTS.md", `(${fragmentMarkers(manifest2.id).start})`);
|
|
9196
9948
|
if (registryEdit2 && registry) print("~", registry, `(adds ${manifest2.id})`);
|
|
9197
|
-
|
|
9949
|
+
for (const r of replaced2) print("-", `supabase/functions/${r.name}`, `(superseded: ${r.by.package} ${r.by.file} provides its migration)`);
|
|
9950
|
+
return { manifest: manifest2, migrations: migrations2, owned: owned2, fragment: fragment2, routerRoot: routerRoot4, stubs: stubs2, toml: toml2, snippet: snippet2, registryEdit: registryEdit2, planWarnings, replaced: replaced2 };
|
|
9198
9951
|
};
|
|
9199
9952
|
let plan = makePlan(found.manifest, found.from);
|
|
9200
9953
|
if (!options.dryRun && !options.yes) {
|
|
@@ -9209,7 +9962,7 @@ async function runAdd(options) {
|
|
|
9209
9962
|
}
|
|
9210
9963
|
warnings.push(...plan.planWarnings);
|
|
9211
9964
|
if (found.from === "catalog") warnings.push(`${found.manifest.package} isn't installed, so its files can't be read yet: migrations, functions and skills are listed, not copied. Install it and run genesis add ${found.manifest.id} again.`);
|
|
9212
|
-
const { manifest, migrations, owned, fragment, routerRoot: routerRoot3, stubs, toml, snippet, registryEdit } = plan;
|
|
9965
|
+
const { manifest, migrations, owned, fragment, routerRoot: routerRoot3, stubs, toml, snippet, registryEdit, replaced } = plan;
|
|
9213
9966
|
for (const row of migrations.rows) {
|
|
9214
9967
|
if (needsAttention(row)) kept.push({ path: row.copy ?? row.file, why: `${row.state}: ${row.detail}. Run genesis migrate --forward to add a forward migration.` });
|
|
9215
9968
|
}
|
|
@@ -9217,14 +9970,28 @@ async function runAdd(options) {
|
|
|
9217
9970
|
if (stub.existing) continue;
|
|
9218
9971
|
if (!stub.file) steps.push(`Add a ${stub.route.path} screen to your router${stub.route.description ? ` (${stub.route.description})` : ""}${stub.route.signedIn ? ", for signed-in people only" : ""}.`);
|
|
9219
9972
|
}
|
|
9220
|
-
|
|
9973
|
+
const database = manifest.migrations.length > 0 || manifest.functions.length > 0;
|
|
9974
|
+
if (home && database) {
|
|
9975
|
+
const there = blocksMissingThere(home, [manifest.id], [manifest, ...catalogBlocks()]);
|
|
9976
|
+
if (!home.app) steps.push(`${manifest.id} ships database files (migrations or Edge Functions); ${elsewhereNote(home)}`);
|
|
9977
|
+
else if (there && !there.length) steps.push(`${manifest.id}'s database files: ${home.app} already has every one of its migrations and Edge Functions, so nothing to add there.`);
|
|
9978
|
+
else {
|
|
9979
|
+
if (!there) warnings.push(`Can't read ${home.app}'s genesis.lock.json or migrations, so whether it has ${manifest.id}'s database files is unknown.`);
|
|
9980
|
+
steps.push(`Add ${manifest.id}'s database files in ${home.app}, which holds this app's database: ${addThereCommand(manifest.id)} there (genesis.config.json supabase.app).`);
|
|
9981
|
+
}
|
|
9982
|
+
}
|
|
9983
|
+
for (const fn of home ? [] : manifest.functions) {
|
|
9221
9984
|
const name = fn.dir.split("/").pop();
|
|
9222
9985
|
if (fn.verifyJwt === false && !readApp(root, "supabase/config.toml")) steps.push(`Deploy ${name} without the gateway's JWT check: supabase functions deploy ${name} --no-verify-jwt`);
|
|
9223
9986
|
if (fn.secrets?.length) steps.push(`Set the ${name} function's secrets: supabase secrets set ${fn.secrets.map((s) => `${s}=\u2026`).join(" ")}`);
|
|
9224
9987
|
}
|
|
9988
|
+
for (const r of home ? [] : replaced) {
|
|
9989
|
+
const instead = r.instead.length ? `${r.instead.join(" and ")} (the ${r.block} block's Edge Function${r.instead.length === 1 ? "" : "s"}) sends instead: deploy ${r.instead.length === 1 ? "it" : "them"} as its steps say` : `${r.by.package}'s own functions send instead`;
|
|
9990
|
+
steps.push(`${r.name} isn't copied or deployed: ${r.by.package} ${r.by.file} is in this app and provides the migration it needs, so ${instead}.`);
|
|
9991
|
+
}
|
|
9225
9992
|
if (migrations.creates.some((c) => c.kind === "migration")) steps.push("Review the new migrations in supabase/migrations, then apply them (supabase db push, or open a pull request).");
|
|
9226
|
-
steps.push(...manifest.steps);
|
|
9227
|
-
if (manifest.privacy?.collects?.length) steps.push(`Update the App Store privacy label and Play data safety form: ${manifest.id} collects ${manifest.privacy.collects.map((c) => c.type).join(", ")}.`);
|
|
9993
|
+
if (!databaseOnly) steps.push(...manifest.steps);
|
|
9994
|
+
if (!databaseOnly && manifest.privacy?.collects?.length) steps.push(`Update the App Store privacy label and Play data safety form: ${manifest.id} collects ${manifest.privacy.collects.map((c) => c.type).join(", ")}.`);
|
|
9228
9995
|
if (snippet && registry && !registryEdit) steps.push(`Add ${manifest.id} to ${registry} (the edit wasn't safe to make automatically):
|
|
9229
9996
|
${snippet}`);
|
|
9230
9997
|
if (snippet && !registry) steps.push(`No feature registry (features.ts) here; when you add one, list ${manifest.id}:
|
|
@@ -9265,12 +10032,14 @@ ${snippet}`);
|
|
|
9265
10032
|
${snippet}`);
|
|
9266
10033
|
} else edited.push(registry);
|
|
9267
10034
|
}
|
|
9268
|
-
if (
|
|
10035
|
+
if (databaseOnly) {
|
|
10036
|
+
if (found.from === "catalog") steps.unshift(`Install ${needed.join(" and ")}, then run genesis add ${manifest.id} --database-only again to copy its files.`);
|
|
10037
|
+
} else if (found.from === "installed" || found.from === "local") lock.blocks[manifest.id] = { package: manifest.package, ...manifest.version ? { version: manifest.version } : {} };
|
|
9269
10038
|
else steps.unshift(`Install ${manifest.packages.join(" and ")}, then run genesis add ${manifest.id} again to copy its files.`);
|
|
9270
10039
|
const lockBefore = readApp(root, LOCK_FILE);
|
|
9271
10040
|
writeLock(root, lock);
|
|
9272
10041
|
if (readApp(root, LOCK_FILE) !== lockBefore) edited.push(LOCK_FILE);
|
|
9273
|
-
if (registry && options.featuresBuild !== false) {
|
|
10042
|
+
if (!databaseOnly && registry && options.featuresBuild !== false) {
|
|
9274
10043
|
try {
|
|
9275
10044
|
const { runFeaturesBuild: runFeaturesBuild2 } = await Promise.resolve().then(() => (init_features(), features_exports));
|
|
9276
10045
|
const changed = await runFeaturesBuild2({ dir: root });
|
|
@@ -9279,7 +10048,7 @@ ${snippet}`);
|
|
|
9279
10048
|
warnings.push(`features build failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
9280
10049
|
}
|
|
9281
10050
|
}
|
|
9282
|
-
if (!routerRoot3 && manifest.routes.length) warnings.push("No Expo Router root (a _layout.tsx in src/app or app), so no route stubs were written; the steps list the screens.");
|
|
10051
|
+
if (!databaseOnly && !routerRoot3 && manifest.routes.length) warnings.push("No Expo Router root (a _layout.tsx in src/app or app), so no route stubs were written; the steps list the screens.");
|
|
9283
10052
|
return { block: manifest, install: command, migrations, created, kept, edited, steps, ...snippet ? { featureSnippet: snippet } : {}, warnings };
|
|
9284
10053
|
}
|
|
9285
10054
|
function recordOwned(lock, appRel, source, content, root, pkg) {
|
|
@@ -9296,6 +10065,7 @@ var init_add = __esm({
|
|
|
9296
10065
|
init_files();
|
|
9297
10066
|
init_lock();
|
|
9298
10067
|
init_migrations();
|
|
10068
|
+
init_database();
|
|
9299
10069
|
init_owned();
|
|
9300
10070
|
init_pm();
|
|
9301
10071
|
init_registry_edit();
|
|
@@ -9339,7 +10109,7 @@ function notificationTypesSql(rows, registryFile2) {
|
|
|
9339
10109
|
}
|
|
9340
10110
|
function configuredRegistry(root) {
|
|
9341
10111
|
try {
|
|
9342
|
-
const raw = JSON.parse(readFileSync(
|
|
10112
|
+
const raw = JSON.parse(readFileSync(path30.join(root, "genesis.config.json"), "utf8"));
|
|
9343
10113
|
return typeof raw.notifications?.registry === "string" ? raw.notifications.registry : void 0;
|
|
9344
10114
|
} catch {
|
|
9345
10115
|
return void 0;
|
|
@@ -9358,14 +10128,14 @@ async function planNotificationTypes(root, options) {
|
|
|
9358
10128
|
warnings.push(`Notification types: not checked on a dry run (loading ${file} runs app code).`);
|
|
9359
10129
|
return { registry: file, warnings };
|
|
9360
10130
|
}
|
|
9361
|
-
const absolute =
|
|
10131
|
+
const absolute = path30.resolve(root, file);
|
|
9362
10132
|
if (!existsSync(absolute)) {
|
|
9363
10133
|
warnings.push(`Notification types: ${file} doesn't exist (a relative path is resolved against the app's root, ${root}).`);
|
|
9364
10134
|
return { registry: file, warnings };
|
|
9365
10135
|
}
|
|
9366
10136
|
let mod;
|
|
9367
10137
|
try {
|
|
9368
|
-
const jiti = createJiti(
|
|
10138
|
+
const jiti = createJiti(path30.join(root, "package.json"), { moduleCache: false });
|
|
9369
10139
|
mod = await jiti.import(absolute);
|
|
9370
10140
|
} catch (err) {
|
|
9371
10141
|
warnings.push(`Notification types: couldn't load ${file} (${err instanceof Error ? err.message : String(err)}).`);
|
|
@@ -9376,8 +10146,8 @@ async function planNotificationTypes(root, options) {
|
|
|
9376
10146
|
warnings.push(`Notification types: ${file} exports no defineNotifications registry (export it as \`notifications\`).`);
|
|
9377
10147
|
return { registry: file, warnings };
|
|
9378
10148
|
}
|
|
9379
|
-
const shown =
|
|
9380
|
-
const content = notificationTypesSql(found.toTypeRows(), shown.split(
|
|
10149
|
+
const shown = path30.isAbsolute(file) ? path30.relative(root, absolute) : file;
|
|
10150
|
+
const content = notificationTypesSql(found.toTypeRows(), shown.split(path30.sep).join("/"));
|
|
9381
10151
|
const app = readAppMigrations(root);
|
|
9382
10152
|
const latest = app.filter((m) => m.name.endsWith(`_${TYPES_STEM}.sql`)).sort((a, b) => a.name < b.name ? -1 : 1).pop();
|
|
9383
10153
|
if (latest && payloadOf(latest.content) === payloadOf(content)) return { registry: file, warnings };
|
|
@@ -9409,18 +10179,32 @@ __export(migrate_exports, {
|
|
|
9409
10179
|
runMigrate: () => runMigrate
|
|
9410
10180
|
});
|
|
9411
10181
|
async function runMigrate(options) {
|
|
9412
|
-
const root =
|
|
10182
|
+
const root = path30.resolve(options.root);
|
|
9413
10183
|
const lock = readLock(root);
|
|
9414
10184
|
const warnings = [];
|
|
9415
|
-
const
|
|
10185
|
+
const home = databaseElsewhere(root);
|
|
10186
|
+
const catalog = catalogBlocks();
|
|
10187
|
+
const off = appBlocksSwitchedOff(root, catalog, Object.keys(lock.blocks));
|
|
9416
10188
|
const switchedOff = Object.keys(lock.blocks).filter((id) => off.has(id) && !options.blocks?.includes(id));
|
|
10189
|
+
if (home) {
|
|
10190
|
+
const ids2 = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks).filter((id) => !switchedOff.includes(id)), ...options.blocks ?? []])];
|
|
10191
|
+
const there = blocksMissingThere(home, ids2, catalog);
|
|
10192
|
+
if (home.app && !there) warnings.push(`Can't read ${home.app}'s genesis.lock.json or migrations, so every block is listed.`);
|
|
10193
|
+
const missing = orderForAdding(there ?? ids2, catalog);
|
|
10194
|
+
if (home.app && !home.hasSupabase) warnings.push(`${home.app} has no supabase folder: genesis.config.json supabase.app should name the app that holds it.`);
|
|
10195
|
+
const line = addThereLine(home, missing);
|
|
10196
|
+
const note = [elsewhereNote(home), ...line ? [line] : []].join(" ");
|
|
10197
|
+
return { plan: { rows: [], creates: [] }, written: [], warnings, switchedOff: switchedOff.map((id) => switchedOffNote(id, off.get(id))), attention: false, elsewhere: { app: home.app, note, missing } };
|
|
10198
|
+
}
|
|
9417
10199
|
const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks).filter((id) => !switchedOff.includes(id)), ...options.blocks ?? []])];
|
|
9418
10200
|
const sources = [];
|
|
9419
10201
|
const local = localPackageNames(root);
|
|
10202
|
+
const manifests = [];
|
|
9420
10203
|
for (const id of ids) {
|
|
9421
10204
|
const pkg = lock.blocks[id]?.package;
|
|
9422
10205
|
try {
|
|
9423
10206
|
const { manifest } = await findBlock(root, id, { ...pkg ? { package: pkg } : {}, warnings });
|
|
10207
|
+
manifests.push(manifest);
|
|
9424
10208
|
sources.push(...sourceMigrations(root, manifest));
|
|
9425
10209
|
} catch (err) {
|
|
9426
10210
|
warnings.push(err instanceof Error ? err.message : String(err));
|
|
@@ -9443,7 +10227,7 @@ async function runMigrate(options) {
|
|
|
9443
10227
|
sources.push({ package: t.package, file: t.file, source });
|
|
9444
10228
|
}
|
|
9445
10229
|
if (!ids.length && !sources.length) warnings.push("No blocks in genesis.lock.json and no copied package migrations: nothing to compare. Add a block (genesis add <block>), or pass --block.");
|
|
9446
|
-
const plan = planMigrations(root, sources, { now: options.now ?? /* @__PURE__ */ new Date(), ...options.forward ? { forward: true } : {}, ...lock.migrations ? { copied: lock.migrations } : {} });
|
|
10230
|
+
const plan = planMigrations(root, sources, { now: options.now ?? /* @__PURE__ */ new Date(), ...options.forward ? { forward: true } : {}, ...lock.migrations ? { copied: lock.migrations } : {}, providers: providingMigrations([...manifests, ...catalog]) });
|
|
9447
10231
|
const attention = plan.rows.some(needsAttention);
|
|
9448
10232
|
const notifies = ids.some((id) => (lock.blocks[id]?.package ?? (id === "notifications" ? NOTIFICATIONS_PACKAGE : "")) === NOTIFICATIONS_PACKAGE);
|
|
9449
10233
|
const types = notifies ? await planNotificationTypes(root, {
|
|
@@ -9474,17 +10258,18 @@ var init_migrate = __esm({
|
|
|
9474
10258
|
init_lock();
|
|
9475
10259
|
init_manifest();
|
|
9476
10260
|
init_migrations();
|
|
10261
|
+
init_database();
|
|
9477
10262
|
init_add();
|
|
9478
10263
|
init_files();
|
|
9479
10264
|
init_notification_types();
|
|
9480
10265
|
}
|
|
9481
10266
|
});
|
|
9482
10267
|
function walk2(dir, rel = "", out = /* @__PURE__ */ new Map()) {
|
|
9483
|
-
for (const entry of readdirSync(
|
|
10268
|
+
for (const entry of readdirSync(path30.join(dir, rel), { withFileTypes: true })) {
|
|
9484
10269
|
if (SKIP.has(entry.name)) continue;
|
|
9485
10270
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
9486
10271
|
if (entry.isDirectory()) walk2(dir, child, out);
|
|
9487
|
-
else if (entry.isFile()) out.set(child, readFileSync(
|
|
10272
|
+
else if (entry.isFile()) out.set(child, readFileSync(path30.join(dir, child)));
|
|
9488
10273
|
}
|
|
9489
10274
|
return out;
|
|
9490
10275
|
}
|
|
@@ -9507,7 +10292,7 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
9507
10292
|
const tag = `${name}@${version}`;
|
|
9508
10293
|
try {
|
|
9509
10294
|
if (!clone) {
|
|
9510
|
-
clone = mkdtempSync(
|
|
10295
|
+
clone = mkdtempSync(path30.join(tmpdir(), "genesis-upstream-"));
|
|
9511
10296
|
git4(["init", "-q"]);
|
|
9512
10297
|
}
|
|
9513
10298
|
git4(["fetch", "-q", "--no-tags", "--depth", "1", repository, `+refs/tags/${tag}:refs/tags/${tag}`]);
|
|
@@ -9524,7 +10309,7 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
9524
10309
|
}
|
|
9525
10310
|
});
|
|
9526
10311
|
if (!manifest) return { error: `the tag ${tag} has no package named ${name}` };
|
|
9527
|
-
const dir =
|
|
10312
|
+
const dir = path30.posix.dirname(manifest);
|
|
9528
10313
|
const entries = git4(["ls-tree", "-r", "-z", tag, "--", `${dir}/`]).toString("utf8").split("\0").filter(Boolean).map((line) => /^\d+ blob ([0-9a-f]+)\t(.*)$/s.exec(line)).filter((m) => m !== null).map((m) => ({ sha: m[1], file: m[2].slice(dir.length + 1) })).filter((e) => !e.file.split("/").some((part) => SKIP.has(part)));
|
|
9529
10314
|
const files = /* @__PURE__ */ new Map();
|
|
9530
10315
|
if (entries.length) {
|
|
@@ -9550,10 +10335,10 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
9550
10335
|
}
|
|
9551
10336
|
function diffHunks(before, after) {
|
|
9552
10337
|
if (before === after) return [];
|
|
9553
|
-
const dir = mkdtempSync(
|
|
10338
|
+
const dir = mkdtempSync(path30.join(tmpdir(), "genesis-diff-"));
|
|
9554
10339
|
try {
|
|
9555
|
-
writeFileSync(
|
|
9556
|
-
writeFileSync(
|
|
10340
|
+
writeFileSync(path30.join(dir, "a"), before);
|
|
10341
|
+
writeFileSync(path30.join(dir, "b"), after);
|
|
9557
10342
|
let out = "";
|
|
9558
10343
|
try {
|
|
9559
10344
|
out = execFileSync("git", ["diff", "--no-index", "--no-color", "-U0", "a", "b"], { cwd: dir, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
@@ -9581,9 +10366,9 @@ function shippedBy(upstreamHunks) {
|
|
|
9581
10366
|
return (h) => upstreamHunks.some((u) => u.start === h.start && u.count === h.count && u.added.length === h.added.length && u.added.every((l, i) => l === h.added[i]));
|
|
9582
10367
|
}
|
|
9583
10368
|
function promotions(root, name) {
|
|
9584
|
-
const file = REGISTER_PATHS.find((p) => existsSync(
|
|
10369
|
+
const file = REGISTER_PATHS.find((p) => existsSync(path30.join(root, p)));
|
|
9585
10370
|
if (!file) return [];
|
|
9586
|
-
const text = readFileSync(
|
|
10371
|
+
const text = readFileSync(path30.join(root, file), "utf8");
|
|
9587
10372
|
const rows = text.split("\n");
|
|
9588
10373
|
return readRegister(text).entries.filter((e) => e.status === "promoted" && e.package === name).map((e) => {
|
|
9589
10374
|
const row = rows.find((r) => r.split("|").map((c) => c.trim())[1] === e.id) ?? "";
|
|
@@ -9617,11 +10402,11 @@ function rebasedManifest(text, name, to, released, nextText) {
|
|
|
9617
10402
|
const n = LOCAL_SUFFIX.exec(typeof json.version === "string" ? json.version : "")?.[1] ?? "1";
|
|
9618
10403
|
json.version = `${to}+local.${n}`;
|
|
9619
10404
|
if (json.genesis?.overlay) json.genesis.overlay.upstream = `${name}@${to}`;
|
|
9620
|
-
for (const
|
|
9621
|
-
const deps = json[
|
|
10405
|
+
for (const section2 of ["dependencies", "peerDependencies", "optionalDependencies"]) {
|
|
10406
|
+
const deps = json[section2];
|
|
9622
10407
|
if (!deps) continue;
|
|
9623
10408
|
for (const [dep, spec] of Object.entries(deps)) {
|
|
9624
|
-
if (!spec.startsWith("workspace:") && !next[
|
|
10409
|
+
if (!spec.startsWith("workspace:") && !next[section2]?.[dep]?.startsWith("workspace:")) continue;
|
|
9625
10410
|
const v = released(dep);
|
|
9626
10411
|
if (v && PLAIN.test(v)) deps[dep] = `^${v}`;
|
|
9627
10412
|
}
|
|
@@ -9641,7 +10426,7 @@ function planOverlays(root, wanted, upstream2, manifests = ["package.json"]) {
|
|
|
9641
10426
|
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
9642
10427
|
let json;
|
|
9643
10428
|
try {
|
|
9644
|
-
json = JSON.parse(readFileSync(
|
|
10429
|
+
json = JSON.parse(readFileSync(path30.join(pkg.dir, "package.json"), "utf8"));
|
|
9645
10430
|
} catch {
|
|
9646
10431
|
continue;
|
|
9647
10432
|
}
|
|
@@ -9750,9 +10535,9 @@ function ownManifestFields(mergedText, upstreamText) {
|
|
|
9750
10535
|
if (!Object.keys(genesis).length) delete json.genesis;
|
|
9751
10536
|
}
|
|
9752
10537
|
}
|
|
9753
|
-
for (const
|
|
9754
|
-
const ours = mine[
|
|
9755
|
-
const up = theirs[
|
|
10538
|
+
for (const section2 of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
|
|
10539
|
+
const ours = mine[section2];
|
|
10540
|
+
const up = theirs[section2];
|
|
9756
10541
|
if (!ours || !up) continue;
|
|
9757
10542
|
for (const [dep, spec] of Object.entries(up)) if (typeof spec === "string" && spec.startsWith("workspace:") && typeof ours[dep] === "string") ours[dep] = spec;
|
|
9758
10543
|
}
|
|
@@ -9767,7 +10552,7 @@ function folderReferences(root, plan) {
|
|
|
9767
10552
|
for (const file of candidates.sort()) {
|
|
9768
10553
|
let text;
|
|
9769
10554
|
try {
|
|
9770
|
-
text = readFileSync(
|
|
10555
|
+
text = readFileSync(path30.join(root, file), "utf8");
|
|
9771
10556
|
} catch {
|
|
9772
10557
|
continue;
|
|
9773
10558
|
}
|
|
@@ -9778,64 +10563,111 @@ function folderReferences(root, plan) {
|
|
|
9778
10563
|
}
|
|
9779
10564
|
function planPins(root, plan, manifests) {
|
|
9780
10565
|
const pins = /* @__PURE__ */ new Map();
|
|
9781
|
-
const overlay = path29.resolve(root, plan.rel);
|
|
9782
10566
|
for (const file of manifests) {
|
|
9783
|
-
const abs =
|
|
10567
|
+
const abs = path30.join(root, file);
|
|
9784
10568
|
if (!existsSync(abs)) continue;
|
|
9785
10569
|
const text = readFileSync(abs, "utf8");
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
json = JSON.parse(text);
|
|
9789
|
-
} catch {
|
|
10570
|
+
const pinned = pinManifest(root, plan, file, text);
|
|
10571
|
+
if (pinned === void 0) {
|
|
9790
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`;
|
|
9791
10573
|
}
|
|
9792
|
-
|
|
9793
|
-
const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) && path29.resolve(here, spec.slice(5)) === overlay);
|
|
9794
|
-
let touched2 = false;
|
|
9795
|
-
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
9796
|
-
const deps = json[section];
|
|
9797
|
-
if (deps && local(deps[plan.name])) {
|
|
9798
|
-
deps[plan.name] = plan.to;
|
|
9799
|
-
touched2 = true;
|
|
9800
|
-
}
|
|
9801
|
-
}
|
|
9802
|
-
for (const o of [json.overrides, json.resolutions, json.pnpm?.overrides]) {
|
|
9803
|
-
if (isObject5(o) && local(o[plan.name])) {
|
|
9804
|
-
delete o[plan.name];
|
|
9805
|
-
touched2 = true;
|
|
9806
|
-
}
|
|
9807
|
-
}
|
|
9808
|
-
if (!touched2) continue;
|
|
9809
|
-
const indent = /^[ \t]+(?=")/m.exec(text)?.[0] ?? " ";
|
|
9810
|
-
pins.set(file, JSON.stringify(json, null, indent) + (text.endsWith("\n") ? "\n" : ""));
|
|
10574
|
+
if (pinned !== null) pins.set(file, pinned);
|
|
9811
10575
|
}
|
|
9812
10576
|
return pins;
|
|
9813
10577
|
}
|
|
9814
|
-
function
|
|
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 = []) {
|
|
9815
10616
|
const changed = [];
|
|
10617
|
+
const removedFolders = [];
|
|
9816
10618
|
for (const plan of plans) {
|
|
9817
10619
|
if (plan.skipped || plan.conflicts.length) continue;
|
|
9818
|
-
const dir =
|
|
10620
|
+
const dir = path30.join(root, plan.rel);
|
|
9819
10621
|
if (plan.remove) {
|
|
9820
|
-
for (const
|
|
9821
|
-
|
|
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);
|
|
9822
10628
|
changed.push(file);
|
|
9823
10629
|
}
|
|
9824
10630
|
rmSync(dir, { recursive: true, force: true });
|
|
9825
10631
|
changed.push(`${plan.rel}/package.json`);
|
|
10632
|
+
removedFolders.push(dir);
|
|
9826
10633
|
continue;
|
|
9827
10634
|
}
|
|
9828
10635
|
for (const [file, bytes] of plan.writes) {
|
|
9829
|
-
const target =
|
|
10636
|
+
const target = path30.join(dir, file);
|
|
9830
10637
|
if (bytes === null) rmSync(target, { force: true });
|
|
9831
10638
|
else {
|
|
9832
|
-
mkdirSync(
|
|
10639
|
+
mkdirSync(path30.dirname(target), { recursive: true });
|
|
9833
10640
|
writeFileSync(target, bytes);
|
|
9834
10641
|
}
|
|
9835
10642
|
changed.push(`${plan.rel}/${file}`);
|
|
9836
10643
|
}
|
|
9837
10644
|
}
|
|
9838
|
-
|
|
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 };
|
|
9839
10671
|
}
|
|
9840
10672
|
function overlayChecklist(plans) {
|
|
9841
10673
|
if (!plans.length) return [];
|
|
@@ -9867,6 +10699,8 @@ var init_overlays2 = __esm({
|
|
|
9867
10699
|
init_local();
|
|
9868
10700
|
init_overlays();
|
|
9869
10701
|
init_upstream();
|
|
10702
|
+
init_bun_lock();
|
|
10703
|
+
init_pm();
|
|
9870
10704
|
init_bump_core();
|
|
9871
10705
|
GENESIS_REPOSITORY = "https://github.com/marktiderman/genesis.git";
|
|
9872
10706
|
SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage", ".turbo", ".git"]);
|
|
@@ -9885,6 +10719,21 @@ __export(upgrade_exports, {
|
|
|
9885
10719
|
releaseAgeError: () => releaseAgeError,
|
|
9886
10720
|
runUpgrade: () => runUpgrade
|
|
9887
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
|
+
}
|
|
9888
10737
|
function npm(args, cwd) {
|
|
9889
10738
|
return execFileSync("npm", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
9890
10739
|
}
|
|
@@ -9895,11 +10744,11 @@ function npmLookup(cwd) {
|
|
|
9895
10744
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
9896
10745
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
9897
10746
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
9898
|
-
const tmp = mkdtempSync(
|
|
10747
|
+
const tmp = mkdtempSync(path30.join(tmpdir(), "genesis-umbrella-"));
|
|
9899
10748
|
try {
|
|
9900
10749
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
9901
|
-
execFileSync("tar", ["-xzf",
|
|
9902
|
-
const manifest = JSON.parse(readFileSync(
|
|
10750
|
+
execFileSync("tar", ["-xzf", path30.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
10751
|
+
const manifest = JSON.parse(readFileSync(path30.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
9903
10752
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
9904
10753
|
return manifest;
|
|
9905
10754
|
} finally {
|
|
@@ -9929,8 +10778,8 @@ function readText2(file) {
|
|
|
9929
10778
|
function tidyReleaseAgeExcludes(file) {
|
|
9930
10779
|
const before = readText2(file);
|
|
9931
10780
|
if (before === null) return false;
|
|
9932
|
-
const dir =
|
|
9933
|
-
const after = normaliseReleaseAgeExcludes(before, tidyLocked(before, readText2(
|
|
10781
|
+
const dir = path30.dirname(file);
|
|
10782
|
+
const after = normaliseReleaseAgeExcludes(before, tidyLocked(before, readText2(path30.join(dir, "pnpm-lock.yaml")), readText2(path30.join(dir, ".npmrc"))));
|
|
9934
10783
|
if (after === before) return false;
|
|
9935
10784
|
writeFileSync(file, after);
|
|
9936
10785
|
return true;
|
|
@@ -9948,7 +10797,7 @@ function pnpmWorkspaceFileFor(root) {
|
|
|
9948
10797
|
const top = gitTopLevel(real2);
|
|
9949
10798
|
const lockDir = findLockfile(real2)?.dir;
|
|
9950
10799
|
const fallback = lockDir && (!top || inside2(top, lockDir)) ? lockDir : real2;
|
|
9951
|
-
return pnpmWorkspaceFile(real2, fallback, { exists: existsSync, join:
|
|
10800
|
+
return pnpmWorkspaceFile(real2, fallback, { exists: existsSync, join: path30.join, dirname: path30.dirname }, top ?? void 0);
|
|
9952
10801
|
}
|
|
9953
10802
|
function pnpmVersionIn(root) {
|
|
9954
10803
|
try {
|
|
@@ -9975,7 +10824,7 @@ function releaseAgeError(output) {
|
|
|
9975
10824
|
}
|
|
9976
10825
|
function runInstall(root, argv) {
|
|
9977
10826
|
const [cmd, ...args] = argv;
|
|
9978
|
-
return new Promise((
|
|
10827
|
+
return new Promise((resolve27, reject) => {
|
|
9979
10828
|
const child = spawn(cmd, args, { cwd: root, stdio: ["inherit", "pipe", "pipe"] });
|
|
9980
10829
|
let output = "";
|
|
9981
10830
|
const keep = (to) => (chunk) => {
|
|
@@ -9986,7 +10835,7 @@ function runInstall(root, argv) {
|
|
|
9986
10835
|
child.stderr.on("data", keep(process.stderr));
|
|
9987
10836
|
child.on("error", reject);
|
|
9988
10837
|
child.on("close", (code, signal) => {
|
|
9989
|
-
if (code === 0) return
|
|
10838
|
+
if (code === 0) return resolve27();
|
|
9990
10839
|
reject(releaseAgeError(output) ?? new Error(`${shellLine(argv)} failed (${signal ?? `exit code ${code}`})`));
|
|
9991
10840
|
});
|
|
9992
10841
|
});
|
|
@@ -9998,7 +10847,7 @@ function packageJsons(root) {
|
|
|
9998
10847
|
if (files.length) return files;
|
|
9999
10848
|
} catch {
|
|
10000
10849
|
}
|
|
10001
|
-
return existsSync(
|
|
10850
|
+
return existsSync(path30.join(root, "package.json")) ? ["package.json"] : [];
|
|
10002
10851
|
}
|
|
10003
10852
|
function sourceText(root, source, substitutions) {
|
|
10004
10853
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -10018,11 +10867,11 @@ function sourceText(root, source, substitutions) {
|
|
|
10018
10867
|
}
|
|
10019
10868
|
}
|
|
10020
10869
|
async function runUpgrade(options) {
|
|
10021
|
-
const root =
|
|
10870
|
+
const root = path30.resolve(options.root);
|
|
10022
10871
|
const log = options.log ?? (() => {
|
|
10023
10872
|
});
|
|
10024
10873
|
const lookup = options.lookup ?? npmLookup(root);
|
|
10025
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
10874
|
+
const release = options.manifest ? JSON.parse(readFileSync(path30.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
10026
10875
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
10027
10876
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
10028
10877
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -10059,6 +10908,7 @@ async function runUpgrade(options) {
|
|
|
10059
10908
|
}
|
|
10060
10909
|
for (const o of overlays) if (!o.skipped) bumped.delete(`${o.rel}/package.json`);
|
|
10061
10910
|
const lock = readLock(root);
|
|
10911
|
+
const home = databaseElsewhere(root);
|
|
10062
10912
|
checkSubstitutions(lock.substitutions);
|
|
10063
10913
|
const bases = /* @__PURE__ */ new Map();
|
|
10064
10914
|
for (const [file, entry] of Object.entries(lock.files)) {
|
|
@@ -10067,13 +10917,14 @@ async function runUpgrade(options) {
|
|
|
10067
10917
|
if (text !== null && sha256(text) === entry.sha256) bases.set(file, text);
|
|
10068
10918
|
}
|
|
10069
10919
|
const files = /* @__PURE__ */ new Set();
|
|
10920
|
+
const lockEdits = [];
|
|
10070
10921
|
const codemodRuns = [];
|
|
10071
10922
|
if (!options.dryRun) {
|
|
10072
10923
|
for (const [file, text] of bumped) {
|
|
10073
10924
|
replaceApp(root, file, text);
|
|
10074
10925
|
files.add(file);
|
|
10075
10926
|
}
|
|
10076
|
-
for (const file of applyOverlayPlans(root, overlays)) files.add(file);
|
|
10927
|
+
for (const file of applyOverlayPlans(root, overlays, lockEdits)) files.add(file);
|
|
10077
10928
|
}
|
|
10078
10929
|
for (const mod of mods) {
|
|
10079
10930
|
log(`codemod ${mod.id}: ${mod.description}`);
|
|
@@ -10081,29 +10932,51 @@ async function runUpgrade(options) {
|
|
|
10081
10932
|
codemodRuns.push({ id: mod.id, files: changed });
|
|
10082
10933
|
for (const f of changed) files.add(f);
|
|
10083
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
|
+
}
|
|
10084
10949
|
const pm = detectPackageManager(root);
|
|
10085
10950
|
let tidiedExcludes = null;
|
|
10086
10951
|
const excludeWarnings = [];
|
|
10087
|
-
if (!options.dryRun && options.install !== false && bumped.size) {
|
|
10952
|
+
if (!options.dryRun && options.install !== false && (bumped.size || bunLock)) {
|
|
10088
10953
|
const workspaceFile = pm === "pnpm" ? pnpmWorkspaceFileFor(root) : null;
|
|
10089
|
-
const relWorkspace = workspaceFile ?
|
|
10954
|
+
const relWorkspace = workspaceFile ? path30.relative(realpathSync(root), workspaceFile) : null;
|
|
10090
10955
|
const workspaceBefore = workspaceFile ? readText2(workspaceFile) : null;
|
|
10091
10956
|
const tidy = () => {
|
|
10092
10957
|
if (!workspaceFile || !tidyReleaseAgeExcludes(workspaceFile)) return;
|
|
10093
10958
|
tidiedExcludes = relWorkspace;
|
|
10094
10959
|
log(`${tidiedExcludes}: minimumReleaseAgeExclude lists each Genesis package's pinned versions in one entry, exact versions the lockfile holds`);
|
|
10095
10960
|
};
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
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));
|
|
10102
10972
|
}
|
|
10103
|
-
}
|
|
10104
|
-
|
|
10105
|
-
|
|
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();
|
|
10106
10978
|
}
|
|
10979
|
+
if (bunLock) bunLock.reinstalled = true;
|
|
10107
10980
|
tidy();
|
|
10108
10981
|
const dedupe = options.dedupe ?? (typeof options.install === "function" ? false : true);
|
|
10109
10982
|
const dedupeArgv = dedupeCommand(pm);
|
|
@@ -10145,18 +11018,27 @@ async function runUpgrade(options) {
|
|
|
10145
11018
|
try {
|
|
10146
11019
|
const { manifest } = await findBlock(root, id, { package: entry.package, warnings });
|
|
10147
11020
|
manifests.push(manifest);
|
|
10148
|
-
|
|
10149
|
-
|
|
11021
|
+
if (!home) {
|
|
11022
|
+
for (const row of planMigrations(root, sourceMigrations(root, manifest), { now: /* @__PURE__ */ new Date(), tests: false, ...lock.migrations ? { copied: lock.migrations } : {}, providers: providingMigrations(catalog) }).rows) {
|
|
11023
|
+
if (row.state === "new") newMigrations.push(`${row.package} ${row.file}`);
|
|
11024
|
+
}
|
|
10150
11025
|
}
|
|
10151
11026
|
if (manifest.version && manifest.version !== entry.version) lock.blocks[id] = { ...entry, version: manifest.version };
|
|
10152
11027
|
} catch (err) {
|
|
10153
11028
|
warnings.push(err instanceof Error ? err.message : String(err));
|
|
10154
11029
|
}
|
|
10155
11030
|
}
|
|
11031
|
+
if (home?.app) {
|
|
11032
|
+
const missing = migrationsMissingThere(home, manifests.map((m) => m.id), [...manifests, ...catalog]);
|
|
11033
|
+
if (!missing) warnings.push(`Can't read ${home.app}'s genesis.lock.json or migrations, so its new package migrations aren't listed.`);
|
|
11034
|
+
for (const m of missing ?? []) if (m.kind === "migration") newMigrations.push(`${m.what} (apply in ${home.app}: ${addThereCommand(m.block)})`);
|
|
11035
|
+
}
|
|
10156
11036
|
const refreshed = [];
|
|
11037
|
+
const elsewhereEntries = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
10157
11038
|
for (const [file, entry] of Object.entries(lock.files)) {
|
|
11039
|
+
if (home && isSupabasePath(file)) continue;
|
|
10158
11040
|
if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
|
|
10159
|
-
if (newMigrations.length && file.startsWith(`${TESTS_DIR}/`)) {
|
|
11041
|
+
if (!home && newMigrations.length && file.startsWith(`${TESTS_DIR}/`)) {
|
|
10160
11042
|
refreshed.push({ path: file, outcome: "deferred", detail: "new package migrations are waiting: run genesis migrate, then genesis upgrade again" });
|
|
10161
11043
|
continue;
|
|
10162
11044
|
}
|
|
@@ -10169,9 +11051,15 @@ async function runUpgrade(options) {
|
|
|
10169
11051
|
if (outcome.outcome === "updated" || outcome.outcome === "merged") files.add(file);
|
|
10170
11052
|
if ((outcome.outcome === "conflict" || outcome.outcome === "kept-mine") && !outcome.detail?.includes("already there")) next.add(`${file}.genesis-next`);
|
|
10171
11053
|
}
|
|
11054
|
+
const functionsLeft = [];
|
|
10172
11055
|
for (const manifest of manifests) {
|
|
10173
11056
|
for (const w of ownedWrites(root, manifest, warnings)) {
|
|
10174
|
-
if (lock.files[w.path]) continue;
|
|
11057
|
+
if (lock.files[w.path] || home && isSupabasePath(w.path)) continue;
|
|
11058
|
+
const fnDir = /^supabase\/functions\/([^/]+)\//.exec(w.path)?.[1];
|
|
11059
|
+
if (fnDir && !Object.keys(lock.files).some((f) => f.startsWith(`supabase/functions/${fnDir}/`))) {
|
|
11060
|
+
if (!functionsLeft.includes(`${fnDir} (${manifest.id})`)) functionsLeft.push(`${fnDir} (${manifest.id})`);
|
|
11061
|
+
continue;
|
|
11062
|
+
}
|
|
10175
11063
|
const outcome = copyOwned(root, lock, { ...w, content: substitute(w.content, lock.substitutions) }, options.dryRun);
|
|
10176
11064
|
if (outcome === "created") {
|
|
10177
11065
|
added.push(w.path);
|
|
@@ -10215,13 +11103,24 @@ async function runUpgrade(options) {
|
|
|
10215
11103
|
if (next.size) lines.push("", "Review and delete these before merging (not committed by --pr):", "", ...[...next].map((n) => `- ${n}`));
|
|
10216
11104
|
if (lock.substitutions && Object.keys(lock.substitutions).length) lines.push("", `Templates renamed with genesis.lock.json's substitutions: ${Object.entries(lock.substitutions).map(([a, b]) => `${a} \u2192 ${b}`).join(", ")}.`);
|
|
10217
11105
|
if (switchedOff.length) lines.push("", "Blocks switched off (left out):", "", ...switchedOff.map((s) => `- ${s}`));
|
|
10218
|
-
if (newMigrations.length) lines.push("", "New package migrations (run `genesis migrate` to copy them):", "", ...newMigrations.map((m) => `- ${m}`));
|
|
11106
|
+
if (newMigrations.length) lines.push("", home ? `New package migrations (in ${home.app ?? "the app that holds the database"}, not here):` : "New package migrations (run `genesis migrate` to copy them):", "", ...newMigrations.map((m) => `- ${m}`));
|
|
11107
|
+
if (functionsLeft.length) lines.push("", "Edge Functions the app never had, not added (genesis add <block> adds one with its config.toml section, where it isn't superseded):", "", ...functionsLeft.map((f) => `- ${f}`));
|
|
11108
|
+
if (home) {
|
|
11109
|
+
lines.push("", `Database files: ${elsewhereNote(home, "genesis upgrade (then genesis migrate)")}`);
|
|
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).`);
|
|
11111
|
+
}
|
|
10219
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
|
+
}
|
|
10220
11119
|
lines.push(...overlayChecklist(overlays));
|
|
10221
11120
|
if (warnings.length) lines.push("", "Warnings:", "", ...warnings.map((w) => `- ${w}`));
|
|
10222
11121
|
lines.push("", `\`genesis doctor\` ${doctor === "not run" ? "was not run" : doctor} after the upgrade.`);
|
|
10223
11122
|
const summary = lines.join("\n");
|
|
10224
|
-
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 } : {} };
|
|
10225
11124
|
if (options.pr && !options.dryRun && files.size) report.pr = openPullRequest(root, release.version, report, prBase);
|
|
10226
11125
|
return report;
|
|
10227
11126
|
}
|
|
@@ -10229,8 +11128,8 @@ function checkSubstitutions(substitutions) {
|
|
|
10229
11128
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
10230
11129
|
let allowed;
|
|
10231
11130
|
try {
|
|
10232
|
-
const was = starterIdentity(readFileSync(
|
|
10233
|
-
allowed = [was.name, was.slug, was.scheme, was.bundleId];
|
|
11131
|
+
const was = starterIdentity(readFileSync(path30.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
11132
|
+
allowed = [was.name, was.slug, was.scheme, was.bundleId, APP_FOLDER_PLACEHOLDER];
|
|
10234
11133
|
} catch {
|
|
10235
11134
|
allowed = [];
|
|
10236
11135
|
}
|
|
@@ -10262,17 +11161,17 @@ function openPullRequest(root, version, report, base) {
|
|
|
10262
11161
|
git4("switch", "-c", branch);
|
|
10263
11162
|
const top = git4("rev-parse", "--show-toplevel");
|
|
10264
11163
|
const lockfiles = [];
|
|
10265
|
-
for (let dir =
|
|
10266
|
-
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(
|
|
10267
|
-
if (lockfiles.length || dir === top ||
|
|
11164
|
+
for (let dir = path30.resolve(root); ; dir = path30.dirname(dir)) {
|
|
11165
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path30.join(dir, f))) lockfiles.push(path30.relative(root, path30.join(dir, f)));
|
|
11166
|
+
if (lockfiles.length || dir === top || path30.dirname(dir) === dir) break;
|
|
10268
11167
|
}
|
|
10269
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
11168
|
+
const paths = [...report.files.filter((f) => existsSync(path30.join(root, f))), ...lockfiles];
|
|
10270
11169
|
git4("add", "--", ...paths);
|
|
10271
11170
|
const overlayDirs = report.overlays.filter((o) => !o.skipped && !o.conflicts.length && (o.remove || [...o.writes.values()].includes(null))).map((o) => o.rel);
|
|
10272
11171
|
if (overlayDirs.length) git4("add", "-A", "--", ...overlayDirs);
|
|
10273
11172
|
git4("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
10274
11173
|
git4("push", "-u", "origin", branch);
|
|
10275
|
-
const body =
|
|
11174
|
+
const body = path30.join(mkdtempSync(path30.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
10276
11175
|
writeFileSync(body, `${report.summary}
|
|
10277
11176
|
|
|
10278
11177
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -10290,6 +11189,7 @@ var init_upgrade = __esm({
|
|
|
10290
11189
|
init_init_native();
|
|
10291
11190
|
init_lock();
|
|
10292
11191
|
init_migrations();
|
|
11192
|
+
init_database();
|
|
10293
11193
|
init_owned();
|
|
10294
11194
|
init_local();
|
|
10295
11195
|
init_pm();
|
|
@@ -10297,10 +11197,11 @@ var init_upgrade = __esm({
|
|
|
10297
11197
|
init_bump_core();
|
|
10298
11198
|
init_codemods();
|
|
10299
11199
|
init_overlays2();
|
|
11200
|
+
init_bun_lock();
|
|
10300
11201
|
EXACT_OR_TAG = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
|
|
10301
11202
|
inside2 = (dir, file) => {
|
|
10302
|
-
const rel =
|
|
10303
|
-
return rel === "" || rel.split(
|
|
11203
|
+
const rel = path30.relative(dir, file);
|
|
11204
|
+
return rel === "" || rel.split(path30.sep)[0] !== ".." && !path30.isAbsolute(rel);
|
|
10304
11205
|
};
|
|
10305
11206
|
NOT_MATURE = "ERR_PNPM_NO_MATURE_MATCHING_VERSION";
|
|
10306
11207
|
SUBSTITUTION_VALUE = /^[A-Za-z0-9][A-Za-z0-9 .+-]{0,59}$/;
|
|
@@ -10403,9 +11304,9 @@ async function runScaffold(opts, fs2) {
|
|
|
10403
11304
|
function joinPath(...parts) {
|
|
10404
11305
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
10405
11306
|
}
|
|
10406
|
-
function dirname(
|
|
10407
|
-
const idx =
|
|
10408
|
-
return idx === -1 ? "." :
|
|
11307
|
+
function dirname(path56) {
|
|
11308
|
+
const idx = path56.lastIndexOf("/");
|
|
11309
|
+
return idx === -1 ? "." : path56.slice(0, idx);
|
|
10409
11310
|
}
|
|
10410
11311
|
function brandPackageJson(consumer, genesisVersion) {
|
|
10411
11312
|
return JSON.stringify(
|
|
@@ -10634,7 +11535,7 @@ program.name("genesis").description("Genesis CLI \u2014 scaffolders + workspace
|
|
|
10634
11535
|
program.command("init").description("Scaffold a new Genesis consumer (brand package + tailwind + tokens), or with --template native a new Expo app from the Genesis RN starter").argument("<consumer>", "Consumer slug (lowercase, e.g., 'acme')").option("-t, --target <dir>", "Target directory (default: cwd; with --template, ./<consumer>)").option(
|
|
10635
11536
|
"--genesis-version <v>",
|
|
10636
11537
|
"Pin @marktiderman/genesis-* version (default: 'workspace:^' for monorepo)"
|
|
10637
|
-
).option("--native", "An Expo app: add NativeWind's preset and scan genesis-ui-native", false).option("--template <name>", "Make a whole app from a template: native (the Genesis RN starter)").option("--display-name <name>", "--template: the app's name on the home screen (default: from the slug)").option("--bundle-id <id>", "--template: iOS bundle id and Android package (default com.example.<slug>)").option("--scheme <scheme>", "--template: the URL scheme (default: the slug)").option("--without <switches>", "--template: starter.config.ts feature switches to turn off, comma-separated (e.g. chat,support); their blocks are left out").option(
|
|
11538
|
+
).option("--native", "An Expo app: add NativeWind's preset and scan genesis-ui-native", false).option("--template <name>", "Make a whole app from a template: native (the Genesis RN starter)").option("--display-name <name>", "--template: the app's name on the home screen (default: from the slug)").option("--bundle-id <id>", "--template: iOS bundle id and Android package (default com.example.<slug>)").option("--scheme <scheme>", "--template: the URL scheme (default: the slug)").option("--without <switches>", "--template: starter.config.ts feature switches to turn off, comma-separated (e.g. chat,support); their blocks are left out").option("--beside <web-app>", "--template: a phone app that uses this web app's database: no supabase/ here when it has one, and genesis.config.json says where it is").option(
|
|
10638
11539
|
"--emit-conflicts",
|
|
10639
11540
|
"Emit `.genesis-next` siblings for files that already exist (so you can diff)",
|
|
10640
11541
|
false
|
|
@@ -10644,19 +11545,21 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
10644
11545
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
10645
11546
|
const result2 = await runInitNative2({
|
|
10646
11547
|
name: consumer,
|
|
10647
|
-
target:
|
|
11548
|
+
target: path30.resolve(opts.target ?? consumer),
|
|
10648
11549
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
10649
11550
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
10650
11551
|
...opts.scheme ? { scheme: opts.scheme } : {},
|
|
10651
|
-
...opts.without ? { without: opts.without.split(",").map((s) => s.trim()).filter(Boolean) } : {}
|
|
11552
|
+
...opts.without ? { without: opts.without.split(",").map((s) => s.trim()).filter(Boolean) } : {},
|
|
11553
|
+
...opts.beside ? { beside: opts.beside } : {}
|
|
10652
11554
|
});
|
|
10653
11555
|
console.log(`\u2714 Wrote ${result2.files.length} files to ${result2.target}`);
|
|
10654
11556
|
if (result2.blocks.length) console.log(` blocks: ${result2.blocks.join(", ")}`);
|
|
10655
11557
|
if (result2.leftOut.length) console.log(` left out (switched off): ${result2.leftOut.join(", ")}`);
|
|
11558
|
+
if (result2.beside?.shared) console.log(` database: ${result2.beside.app}/supabase (no supabase/ here)`);
|
|
10656
11559
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
10657
11560
|
console.log("");
|
|
10658
11561
|
console.log("Next steps:");
|
|
10659
|
-
[`cd ${
|
|
11562
|
+
[`cd ${path30.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
10660
11563
|
return;
|
|
10661
11564
|
}
|
|
10662
11565
|
opts.target ??= process.cwd();
|
|
@@ -10741,7 +11644,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
10741
11644
|
});
|
|
10742
11645
|
program.command("doctor").description("Check this app against the installed Genesis: components, tokens, imports, colors, plus the app's own rules").option("--strict", "Fail on warnings too", false).option("--json", "Print the report as JSON", false).option("--build", "Also run the app's typecheck and build (doctor.build, or its typecheck/build scripts)", false).option("-c, --config <path>", 'Config file (default: genesis.config.json, then package.json "genesis")').option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--print-genesis", "Print the components, tokens and raw tags read from Genesis, and exit", false).option("--base <ref>", "The git ref change checks compare against (the packages pack's change gate, and the ratchet: newOnly rules report unchanged files as info), e.g. origin/main").action(async (opts) => {
|
|
10743
11646
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
10744
|
-
const root =
|
|
11647
|
+
const root = path30.resolve(opts.dir);
|
|
10745
11648
|
try {
|
|
10746
11649
|
if (opts.printGenesis) {
|
|
10747
11650
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -10760,7 +11663,7 @@ program.command("doctor").description("Check this app against the installed Gene
|
|
|
10760
11663
|
});
|
|
10761
11664
|
program.command("catalog").description("Print the Genesis catalog: for each need, what to use, its import and docs, from every installed Genesis package's declarations").option("--json", "Print the catalog as JSON", false).option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
10762
11665
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
10763
|
-
const packages = doctor.discoverPackages(
|
|
11666
|
+
const packages = doctor.discoverPackages(path30.resolve(opts.dir));
|
|
10764
11667
|
const rows = doctor.primitivesCatalog(packages);
|
|
10765
11668
|
const broken = packages.filter((p) => p.error);
|
|
10766
11669
|
if (opts.json) {
|
|
@@ -10775,7 +11678,7 @@ program.command("catalog").description("Print the Genesis catalog: for each need
|
|
|
10775
11678
|
program.command("primitives").description("Deprecated name of `genesis catalog` (same output; JSON keeps the `primitives` key until the next major)").option("--json", "Print the catalog as JSON", false).option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
10776
11679
|
console.error("! `genesis primitives` is now `genesis catalog`; the old name works until the next major.");
|
|
10777
11680
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
10778
|
-
const packages = doctor.discoverPackages(
|
|
11681
|
+
const packages = doctor.discoverPackages(path30.resolve(opts.dir));
|
|
10779
11682
|
const rows = doctor.primitivesCatalog(packages);
|
|
10780
11683
|
const broken = packages.filter((p) => p.error);
|
|
10781
11684
|
if (opts.json) {
|
|
@@ -10788,10 +11691,10 @@ program.command("primitives").description("Deprecated name of `genesis catalog`
|
|
|
10788
11691
|
if (broken.length) process.exitCode = 1;
|
|
10789
11692
|
});
|
|
10790
11693
|
program.command("agents").description(`Write the agent guide from the installed Genesis packages: .claude/skills/genesis/SKILL.md and a marked block in AGENTS.md`).option("--check", "Write nothing; exit 1 if either is missing or out of date (for CI)", false).option("--rules", "Check the repo against the agent rules of engagement a script can check (docs/agents/RULES.md); exit 1 on a break", false).option("--batch <pattern>", "With --rules: the branch pattern staging batches use in workflow filters", "staging/**").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
10791
|
-
const root =
|
|
11694
|
+
const root = path30.resolve(opts.dir);
|
|
10792
11695
|
if (opts.rules && opts.check) return program.error("--rules checks the repo, --check the agent guide: run them one at a time");
|
|
10793
11696
|
if (opts.rules) {
|
|
10794
|
-
if (!existsSync(
|
|
11697
|
+
if (!existsSync(path30.join(root, "packages")) && !existsSync(path30.join(root, ".github", "workflows"))) {
|
|
10795
11698
|
return program.error(`--rules checks a repository: ${root} has no packages/ or .github/workflows/. Run it from the repo root or pass --dir.`);
|
|
10796
11699
|
}
|
|
10797
11700
|
const { checkAgentRules: checkAgentRules2 } = await Promise.resolve().then(() => (init_agent_rules(), agent_rules_exports));
|
|
@@ -10869,7 +11772,7 @@ featureOptions(
|
|
|
10869
11772
|
var upstream = program.command("upstream").description("The app's register of what it needed from Genesis (docs/genesis-upstream.md)");
|
|
10870
11773
|
upstream.command("check").description("Check docs/genesis-upstream.md: kinds, statuses, local paths, and promoted entries whose local copy is still there").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
10871
11774
|
const { checkUpstream: checkUpstream2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
10872
|
-
const result = checkUpstream2(
|
|
11775
|
+
const result = checkUpstream2(path30.resolve(opts.dir));
|
|
10873
11776
|
for (const w of result.warnings) console.warn(`! ${w}`);
|
|
10874
11777
|
for (const p of result.problems) console.error(`\u2717 ${p}`);
|
|
10875
11778
|
if (result.problems.length) process.exitCode = 1;
|
|
@@ -10877,7 +11780,7 @@ upstream.command("check").description("Check docs/genesis-upstream.md: kinds, st
|
|
|
10877
11780
|
});
|
|
10878
11781
|
upstream.command("export").description("Print the link that files a register entry with Genesis through the gap form (sends nothing)").argument("<id>", "The entry's id").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (id, opts) => {
|
|
10879
11782
|
const { checkUpstream: checkUpstream2, exportIssueUrl: exportIssueUrl2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
10880
|
-
const register = checkUpstream2(
|
|
11783
|
+
const register = checkUpstream2(path30.resolve(opts.dir));
|
|
10881
11784
|
if (register.missing) return program.error("There is no docs/genesis-upstream.md or genesis-upstream.md here; add the register first (see genesis upstream check).");
|
|
10882
11785
|
const entry = register.entries.find((e) => e.id === id);
|
|
10883
11786
|
if (!entry) return program.error(`No register entry "${id}" in ${register.file}.`);
|
|
@@ -10890,9 +11793,9 @@ ${exportIssueUrl2(entry)}`);
|
|
|
10890
11793
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
10891
11794
|
studio.command("init").description("Turn the Data Studio on in this app: a server for every table, a page, and one migration to review").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--host <host>", "next, tanstack-start or supabase-function (default: detected)").option("--route <path>", "Where the page lives", "/admin/data").option("--login-role <name>", "The studio's database login", "genesis_studio_login").option("--force", "Overwrite files that already exist", false).action(async (opts) => {
|
|
10892
11795
|
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
10893
|
-
const root =
|
|
10894
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
10895
|
-
const
|
|
11796
|
+
const root = path30.resolve(opts.dir);
|
|
11797
|
+
const packageJson = JSON.parse(await fs.readFile(path30.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
11798
|
+
const existsSync43 = (await import('fs')).existsSync;
|
|
10896
11799
|
const readSync = (await import('fs')).readFileSync;
|
|
10897
11800
|
const readdirSync19 = (await import('fs')).readdirSync;
|
|
10898
11801
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
@@ -10901,13 +11804,13 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
10901
11804
|
const plan = planStudioInit2(
|
|
10902
11805
|
{
|
|
10903
11806
|
packageJson,
|
|
10904
|
-
exists: (p) =>
|
|
10905
|
-
read: (p) =>
|
|
11807
|
+
exists: (p) => existsSync43(path30.join(root, p)),
|
|
11808
|
+
read: (p) => existsSync43(path30.join(root, p)) ? readSync(path30.join(root, p), "utf-8") : null,
|
|
10906
11809
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
10907
11810
|
listDeep: (p) => {
|
|
10908
11811
|
const out = [];
|
|
10909
11812
|
const walk3 = (rel) => {
|
|
10910
|
-
for (const entry of readdirSync19(
|
|
11813
|
+
for (const entry of readdirSync19(path30.join(root, rel), { withFileTypes: true })) {
|
|
10911
11814
|
const child = `${rel}/${entry.name}`;
|
|
10912
11815
|
if (entry.isDirectory()) walk3(child);
|
|
10913
11816
|
else out.push(child);
|
|
@@ -10921,7 +11824,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
10921
11824
|
},
|
|
10922
11825
|
list: (p) => {
|
|
10923
11826
|
try {
|
|
10924
|
-
return readdirSync19(
|
|
11827
|
+
return readdirSync19(path30.join(root, p));
|
|
10925
11828
|
} catch {
|
|
10926
11829
|
return [];
|
|
10927
11830
|
}
|
|
@@ -10930,8 +11833,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
10930
11833
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
10931
11834
|
);
|
|
10932
11835
|
for (const file of plan.files) {
|
|
10933
|
-
const target =
|
|
10934
|
-
await fs.mkdir(
|
|
11836
|
+
const target = path30.join(root, file.path);
|
|
11837
|
+
await fs.mkdir(path30.dirname(target), { recursive: true });
|
|
10935
11838
|
if (file.edit) {
|
|
10936
11839
|
await fs.writeFile(target, file.content, "utf-8");
|
|
10937
11840
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -10942,14 +11845,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
10942
11845
|
console.log(`+ ${file.path} (appended)`);
|
|
10943
11846
|
continue;
|
|
10944
11847
|
}
|
|
10945
|
-
if (
|
|
11848
|
+
if (existsSync43(target) && !opts.force) {
|
|
10946
11849
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
10947
11850
|
continue;
|
|
10948
11851
|
}
|
|
10949
11852
|
await fs.writeFile(target, file.content, "utf-8");
|
|
10950
11853
|
console.log(`+ ${file.path}`);
|
|
10951
11854
|
}
|
|
10952
|
-
const pm =
|
|
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";
|
|
10953
11856
|
console.log("");
|
|
10954
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:`);
|
|
10955
11858
|
console.log(` 1. ${pm} ${plan.install.map((p) => /[\s<>|]/.test(p) ? `"${p}"` : p).join(" ")}`);
|
|
@@ -10966,8 +11869,8 @@ async function confirm(question) {
|
|
|
10966
11869
|
}
|
|
10967
11870
|
}
|
|
10968
11871
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
10969
|
-
program.command("add").description("Add a block (a feature an app adds whole) from the Genesis package that declares it: install, migrations, functions, skills, routes, registry entry").argument("[block]", "The block's id, e.g. tenant-features").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--package <name>", "The package that declares it, when two do").option("--list", "List the blocks this app can add, and exit", false).option("--dry-run", "Print the plan; write and install nothing", false).option("-y, --yes", "Don't ask before writing", false).option("--no-install", "Don't install packages (print the command instead)").option("--no-features-build", "Don't run features build after").action(async (block, opts) => {
|
|
10970
|
-
const root =
|
|
11872
|
+
program.command("add").description("Add a block (a feature an app adds whole) from the Genesis package that declares it: install, migrations, functions, skills, routes, registry entry").argument("[block]", "The block's id, e.g. tenant-features").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--package <name>", "The package that declares it, when two do").option("--list", "List the blocks this app can add, and exit", false).option("--dry-run", "Print the plan; write and install nothing", false).option("-y, --yes", "Don't ask before writing", false).option("--no-install", "Don't install packages (print the command instead)").option("--no-features-build", "Don't run features build after").option("--database-only", "Only the block's migrations, pgTAP tests, Edge Functions and config.toml sections: in the app that holds another app's database", false).action(async (block, opts) => {
|
|
11873
|
+
const root = path30.resolve(opts.dir);
|
|
10971
11874
|
if (opts.list || !block) {
|
|
10972
11875
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
10973
11876
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -10980,7 +11883,7 @@ program.command("add").description("Add a block (a feature an app adds whole) fr
|
|
|
10980
11883
|
return;
|
|
10981
11884
|
}
|
|
10982
11885
|
const { runAdd: runAdd2 } = await Promise.resolve().then(() => (init_add(), add_exports));
|
|
10983
|
-
const report = await runAdd2({ root, block, ...opts.package ? { package: opts.package } : {}, dryRun: opts.dryRun, yes: opts.yes, install: opts.install, featuresBuild: opts.featuresBuild, log: logger, confirm });
|
|
11886
|
+
const report = await runAdd2({ root, block, ...opts.package ? { package: opts.package } : {}, dryRun: opts.dryRun, yes: opts.yes, install: opts.install, featuresBuild: opts.featuresBuild, ...opts.databaseOnly ? { databaseOnly: true } : {}, log: logger, confirm });
|
|
10984
11887
|
for (const w of report.warnings) logger.warn(w);
|
|
10985
11888
|
for (const k of report.kept) logger.warn(`${k.path}: ${k.why}`);
|
|
10986
11889
|
console.log("");
|
|
@@ -10997,13 +11900,17 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
10997
11900
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
10998
11901
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
10999
11902
|
const report = await runMigrate2({
|
|
11000
|
-
root:
|
|
11903
|
+
root: path30.resolve(opts.dir),
|
|
11001
11904
|
...opts.block ? { blocks: opts.block } : {},
|
|
11002
11905
|
...opts.notifications ? { notifications: opts.notifications } : {},
|
|
11003
11906
|
dryRun: opts.dryRun,
|
|
11004
11907
|
forward: opts.forward
|
|
11005
11908
|
});
|
|
11006
11909
|
for (const w of report.warnings) logger.warn(w);
|
|
11910
|
+
if (report.elsewhere) {
|
|
11911
|
+
console.log(report.elsewhere.note);
|
|
11912
|
+
return;
|
|
11913
|
+
}
|
|
11007
11914
|
for (const s of report.switchedOff) console.log(`- skipped ${s}`);
|
|
11008
11915
|
console.log(formatMigrationRows2(report.plan.rows));
|
|
11009
11916
|
for (const c of report.plan.creates) if (c.kind !== "migration") console.log(`+ ${c.path} (${c.kind === "test" ? "pgTAP test" : "forward migration: fill it in"})`);
|
|
@@ -11019,7 +11926,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
11019
11926
|
program.command("upgrade").description("Move every @marktiderman/genesis* dependency to one Genesis release, refresh the files Genesis owns, run codemods and the doctor").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--version <v>", "The @marktiderman/genesis release: an exact version or a dist-tag", "latest").option("--manifest <file>", "Read the release from this versions.json instead of npm").option("--dry-run", "Report the bump, and owned files compared with the packages installed now; change nothing", false).option("--no-install", "Don't reinstall after the bump").option("--no-doctor", "Don't run genesis doctor after").option("--keep-mine", "Never merge an owned file you changed; write the new text to .genesis-next", false).option("--pr", "Commit to a genesis-upgrade/<version> branch, push it and open a pull request", false).option("--genesis-repo <url>", "The Genesis git repository whose <package>@<version> tags overlays are rebased from (default: the public one)").action(async (opts) => {
|
|
11020
11927
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
11021
11928
|
const report = await runUpgrade2({
|
|
11022
|
-
root:
|
|
11929
|
+
root: path30.resolve(opts.dir),
|
|
11023
11930
|
version: opts.version,
|
|
11024
11931
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
11025
11932
|
dryRun: opts.dryRun,
|
|
@@ -11046,7 +11953,7 @@ program.command("codemod [id]").description("Run one of Genesis's codemods by ha
|
|
|
11046
11953
|
}
|
|
11047
11954
|
const mod = codemodById2(id);
|
|
11048
11955
|
if (!mod) throw new Error(`No codemod "${id}". Run genesis codemod to list them.`);
|
|
11049
|
-
const changed = await mod.run({ root:
|
|
11956
|
+
const changed = await mod.run({ root: path30.resolve(opts.dir), dryRun: opts.dryRun, log: (m) => console.log(m) });
|
|
11050
11957
|
console.log(changed.length ? `${opts.dryRun ? "Would change" : "\u2714 Changed"} ${changed.length} file${changed.length === 1 ? "" : "s"}:
|
|
11051
11958
|
${changed.map((f) => ` ${f}`).join("\n")}` : "Nothing to change.");
|
|
11052
11959
|
});
|
|
@@ -11097,7 +12004,7 @@ function redactUrl(location) {
|
|
|
11097
12004
|
const url = new URL(location);
|
|
11098
12005
|
return `${url.origin}${url.pathname}`;
|
|
11099
12006
|
} catch {
|
|
11100
|
-
return
|
|
12007
|
+
return path30.basename(location);
|
|
11101
12008
|
}
|
|
11102
12009
|
}
|
|
11103
12010
|
//# sourceMappingURL=cli.js.map
|