@marktiderman/genesis-cli 1.26.1 → 1.28.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 +20 -1
- package/dist/cli.js +1129 -450
- package/dist/cli.js.map +1 -1
- package/dist/{config-ARs2YQ60.d.ts → config-BmMsEWU-.d.ts} +7 -0
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +492 -33
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +11 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +36 -12
- package/dist/index.d.ts +11 -5
- package/dist/index.js +493 -34
- package/dist/index.js.map +1 -1
- package/dist/starter/package.json +5 -5
- package/dist/starter/supabase/migrations/20261025000095_genesis_support_ticket_fixes.sql +115 -0
- package/dist/starter/supabase/tests/database/genesis_support_ticket_fixes.test.sql +121 -0
- package/dist/vite.js +490 -31
- package/dist/vite.js.map +1 -1
- package/package.json +4 -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 path62 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';
|
|
@@ -31,7 +31,7 @@ var __export = (target, all) => {
|
|
|
31
31
|
function buildCatalog(packagesDir) {
|
|
32
32
|
const packages = {};
|
|
33
33
|
for (const dir of readdirSync(packagesDir).sort()) {
|
|
34
|
-
const file =
|
|
34
|
+
const file = path62.join(packagesDir, dir, "package.json");
|
|
35
35
|
if (!existsSync(file)) continue;
|
|
36
36
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
37
37
|
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
@@ -294,14 +294,14 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
294
294
|
}
|
|
295
295
|
});
|
|
296
296
|
function inside(parent, child) {
|
|
297
|
-
const rel =
|
|
298
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
297
|
+
const rel = path62.relative(parent, child);
|
|
298
|
+
return rel === "" || !rel.startsWith("..") && !path62.isAbsolute(rel);
|
|
299
299
|
}
|
|
300
300
|
function readPackageFile(packageDir2, rel) {
|
|
301
301
|
const safe = safeRelative(rel);
|
|
302
302
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
303
303
|
const root = realpathSync(packageDir2);
|
|
304
|
-
const file =
|
|
304
|
+
const file = path62.join(root, ...safe.split("/"));
|
|
305
305
|
if (!existsSync(file)) return null;
|
|
306
306
|
const real2 = realpathSync(file);
|
|
307
307
|
if (!inside(root, real2)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
|
|
@@ -312,7 +312,7 @@ function readPackageDir(packageDir2, rel, skipped = []) {
|
|
|
312
312
|
const safe = safeRelative(rel);
|
|
313
313
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
314
314
|
const root = realpathSync(packageDir2);
|
|
315
|
-
const dir =
|
|
315
|
+
const dir = path62.join(root, ...safe.split("/"));
|
|
316
316
|
if (!existsSync(dir)) return null;
|
|
317
317
|
const real2 = realpathSync(dir);
|
|
318
318
|
if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
|
|
@@ -332,7 +332,7 @@ function appPath(root, rel) {
|
|
|
332
332
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
333
333
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
334
334
|
const realRoot = realpathSync(root);
|
|
335
|
-
const target =
|
|
335
|
+
const target = path62.join(realRoot, ...safe.split("/"));
|
|
336
336
|
const there = (p) => {
|
|
337
337
|
try {
|
|
338
338
|
lstatSync(p);
|
|
@@ -341,13 +341,13 @@ function appPath(root, rel) {
|
|
|
341
341
|
return false;
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
|
-
let probe =
|
|
345
|
-
while (!there(probe)) probe =
|
|
344
|
+
let probe = path62.dirname(target);
|
|
345
|
+
while (!there(probe)) probe = path62.dirname(probe);
|
|
346
346
|
let real2;
|
|
347
347
|
try {
|
|
348
348
|
real2 = realpathSync(probe);
|
|
349
349
|
} catch {
|
|
350
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
350
|
+
throw new Error(`${rel} goes through a broken symlink (${path62.relative(realRoot, probe)}); refused`);
|
|
351
351
|
}
|
|
352
352
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
353
353
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
@@ -359,20 +359,20 @@ function readApp(root, rel) {
|
|
|
359
359
|
}
|
|
360
360
|
function createApp(root, rel, content) {
|
|
361
361
|
const file = appPath(root, rel);
|
|
362
|
-
mkdirSync(
|
|
362
|
+
mkdirSync(path62.dirname(file), { recursive: true });
|
|
363
363
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
364
364
|
}
|
|
365
365
|
function replaceApp(root, rel, content) {
|
|
366
366
|
const file = appPath(root, rel);
|
|
367
|
-
mkdirSync(
|
|
367
|
+
mkdirSync(path62.dirname(file), { recursive: true });
|
|
368
368
|
writeFileSync(file, content, "utf8");
|
|
369
369
|
}
|
|
370
370
|
function listApp(root, rel, options = {}) {
|
|
371
|
-
const dir =
|
|
371
|
+
const dir = path62.join(root, rel);
|
|
372
372
|
if (!existsSync(dir)) return [];
|
|
373
373
|
const out = [];
|
|
374
374
|
const walk4 = (r) => {
|
|
375
|
-
for (const entry of readdirSync(
|
|
375
|
+
for (const entry of readdirSync(path62.join(root, r), { withFileTypes: true })) {
|
|
376
376
|
const child = `${r}/${entry.name}`;
|
|
377
377
|
if (entry.isDirectory()) walk4(child);
|
|
378
378
|
else if (entry.isFile() || options.symlinks && entry.isSymbolicLink()) out.push(child);
|
|
@@ -393,8 +393,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
393
393
|
return raw.map((entry, i) => {
|
|
394
394
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
395
395
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
396
|
-
if (
|
|
397
|
-
const norm =
|
|
396
|
+
if (path62.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
397
|
+
const norm = path62.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
398
398
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
399
399
|
const parts = norm.split("/");
|
|
400
400
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -405,7 +405,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
405
405
|
});
|
|
406
406
|
}
|
|
407
407
|
function localPackageGlobs(root) {
|
|
408
|
-
const file =
|
|
408
|
+
const file = path62.join(root, "genesis.config.json");
|
|
409
409
|
if (!existsSync(file)) return [];
|
|
410
410
|
let raw;
|
|
411
411
|
try {
|
|
@@ -418,14 +418,14 @@ function localPackageGlobs(root) {
|
|
|
418
418
|
}
|
|
419
419
|
function repositoryRoot(appRoot) {
|
|
420
420
|
for (let dir = appRoot; ; ) {
|
|
421
|
-
if (existsSync(
|
|
422
|
-
const parent =
|
|
421
|
+
if (existsSync(path62.join(dir, ".git"))) return dir;
|
|
422
|
+
const parent = path62.dirname(dir);
|
|
423
423
|
if (parent === dir) return appRoot;
|
|
424
424
|
dir = parent;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
function localPackages(root) {
|
|
428
|
-
const appRoot =
|
|
428
|
+
const appRoot = path62.resolve(root);
|
|
429
429
|
const globs = localPackageGlobs(appRoot);
|
|
430
430
|
const key2 = `${appRoot}
|
|
431
431
|
${globs.join("\n")}`;
|
|
@@ -434,24 +434,24 @@ ${globs.join("\n")}`;
|
|
|
434
434
|
const dirs = /* @__PURE__ */ new Set();
|
|
435
435
|
for (const glob of globs) {
|
|
436
436
|
if (glob.endsWith("/*") || glob === "*") {
|
|
437
|
-
const parent =
|
|
437
|
+
const parent = path62.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
438
438
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
439
439
|
for (const entry of readdirSync(parent).sort()) {
|
|
440
440
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
441
|
-
dirs.add(
|
|
441
|
+
dirs.add(path62.join(parent, entry));
|
|
442
442
|
}
|
|
443
443
|
} else {
|
|
444
|
-
dirs.add(
|
|
444
|
+
dirs.add(path62.join(appRoot, glob));
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
448
448
|
const out = [];
|
|
449
449
|
const byName = /* @__PURE__ */ new Map();
|
|
450
450
|
for (const dir of [...dirs].sort()) {
|
|
451
|
-
const manifest =
|
|
451
|
+
const manifest = path62.join(dir, "package.json");
|
|
452
452
|
if (!existsSync(manifest)) continue;
|
|
453
453
|
if (!inside(real2, realpathSync(dir))) {
|
|
454
|
-
throw new LocalPackagesError(`${
|
|
454
|
+
throw new LocalPackagesError(`${path62.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
455
455
|
}
|
|
456
456
|
let pkg;
|
|
457
457
|
try {
|
|
@@ -460,7 +460,7 @@ ${globs.join("\n")}`;
|
|
|
460
460
|
continue;
|
|
461
461
|
}
|
|
462
462
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
463
|
-
const rel =
|
|
463
|
+
const rel = path62.relative(appRoot, dir).split(path62.sep).join("/");
|
|
464
464
|
const other = byName.get(pkg.name);
|
|
465
465
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
466
466
|
byName.set(pkg.name, rel);
|
|
@@ -503,41 +503,41 @@ __export(discover_exports, {
|
|
|
503
503
|
workspacePackagesDir: () => workspacePackagesDir
|
|
504
504
|
});
|
|
505
505
|
function cliPackageDir() {
|
|
506
|
-
let dir =
|
|
506
|
+
let dir = path62.dirname(fileURLToPath(import.meta.url));
|
|
507
507
|
for (; ; ) {
|
|
508
|
-
const file =
|
|
508
|
+
const file = path62.join(dir, "package.json");
|
|
509
509
|
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
510
|
-
const parent =
|
|
510
|
+
const parent = path62.dirname(dir);
|
|
511
511
|
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
512
512
|
dir = parent;
|
|
513
513
|
}
|
|
514
514
|
}
|
|
515
515
|
function workspacePackagesDir() {
|
|
516
|
-
const dir =
|
|
517
|
-
return existsSync(
|
|
516
|
+
const dir = path62.resolve(cliPackageDir(), "..");
|
|
517
|
+
return existsSync(path62.join(dir, "features", "package.json")) && existsSync(path62.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
518
518
|
}
|
|
519
519
|
function readCatalog() {
|
|
520
520
|
if (catalogCache) return catalogCache;
|
|
521
521
|
const workspace = workspacePackagesDir();
|
|
522
522
|
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
523
|
-
const file =
|
|
523
|
+
const file = path62.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
524
524
|
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
525
525
|
return catalogCache;
|
|
526
526
|
}
|
|
527
527
|
function installedGenesis(root) {
|
|
528
528
|
const found = /* @__PURE__ */ new Map();
|
|
529
|
-
let dir =
|
|
529
|
+
let dir = path62.resolve(root);
|
|
530
530
|
for (; ; ) {
|
|
531
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
532
|
-
const scope =
|
|
531
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path62.join(dir, m)));
|
|
532
|
+
const scope = path62.join(dir, "node_modules", "@marktiderman");
|
|
533
533
|
if (existsSync(scope)) {
|
|
534
534
|
for (const entry of readdirSync(scope)) {
|
|
535
535
|
const name = `@marktiderman/${entry}`;
|
|
536
536
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
537
|
-
if (existsSync(
|
|
537
|
+
if (existsSync(path62.join(scope, entry, "package.json"))) found.set(name, path62.join(scope, entry));
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
const parent =
|
|
540
|
+
const parent = path62.dirname(dir);
|
|
541
541
|
if (atInstallRoot || parent === dir) return found;
|
|
542
542
|
dir = parent;
|
|
543
543
|
}
|
|
@@ -551,10 +551,10 @@ function packageDir(root, name) {
|
|
|
551
551
|
return null;
|
|
552
552
|
}
|
|
553
553
|
function packageVersion(dir) {
|
|
554
|
-
return JSON.parse(readFileSync(
|
|
554
|
+
return JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8")).version;
|
|
555
555
|
}
|
|
556
556
|
function declarationsOf(dir, warnings) {
|
|
557
|
-
const pkg = JSON.parse(readFileSync(
|
|
557
|
+
const pkg = JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8"));
|
|
558
558
|
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
559
559
|
let cached = declarationCache.get(key2);
|
|
560
560
|
if (!cached) {
|
|
@@ -564,15 +564,15 @@ function declarationsOf(dir, warnings) {
|
|
|
564
564
|
return cached;
|
|
565
565
|
}
|
|
566
566
|
async function loadDeclarations(dir, warnings) {
|
|
567
|
-
const pkg = JSON.parse(readFileSync(
|
|
567
|
+
const pkg = JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8"));
|
|
568
568
|
const entry = pkg.exports?.["./blocks"];
|
|
569
569
|
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
570
570
|
if (typeof target !== "string") return {};
|
|
571
571
|
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
572
|
-
const file = rel &&
|
|
572
|
+
const file = rel && path62.join(dir, ...rel.split("/"));
|
|
573
573
|
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
574
574
|
try {
|
|
575
|
-
const jiti = createJiti(
|
|
575
|
+
const jiti = createJiti(path62.join(dir, "package.json"), { moduleCache: false });
|
|
576
576
|
const mod = await jiti.import(file);
|
|
577
577
|
const out = {};
|
|
578
578
|
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
@@ -583,7 +583,7 @@ async function loadDeclarations(dir, warnings) {
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
586
|
-
const pkg = JSON.parse(readFileSync(
|
|
586
|
+
const pkg = JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8"));
|
|
587
587
|
const raw = rawBlocksOf(pkg);
|
|
588
588
|
const declared = await declarationsOf(dir, warnings);
|
|
589
589
|
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
@@ -677,7 +677,7 @@ function emptyLock() {
|
|
|
677
677
|
return { version: 1, blocks: {}, files: {} };
|
|
678
678
|
}
|
|
679
679
|
function readLock(root) {
|
|
680
|
-
const file =
|
|
680
|
+
const file = path62.join(root, LOCK_FILE);
|
|
681
681
|
if (!existsSync(file)) return emptyLock();
|
|
682
682
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
683
683
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -754,7 +754,7 @@ function migrationHeader(pkg, file, source) {
|
|
|
754
754
|
`;
|
|
755
755
|
}
|
|
756
756
|
function stemOrNull(file) {
|
|
757
|
-
return MIGRATION_FILE.exec(
|
|
757
|
+
return MIGRATION_FILE.exec(path62.posix.basename(file))?.[2] ?? null;
|
|
758
758
|
}
|
|
759
759
|
function stemOf(file) {
|
|
760
760
|
const stem = stemOrNull(file);
|
|
@@ -764,7 +764,7 @@ function stemOf(file) {
|
|
|
764
764
|
function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
765
765
|
return listApp(root, dir, { symlinks: true }).filter((p) => p.endsWith(".sql")).map((p) => {
|
|
766
766
|
const content = readApp(root, p) ?? "";
|
|
767
|
-
const name =
|
|
767
|
+
const name = path62.posix.basename(p);
|
|
768
768
|
const m = HEADER.exec(content);
|
|
769
769
|
if (m) return { path: p, name, content, tracked: { package: m[1], file: m[2], sha256: m[3], body: content.slice(m[0].length) } };
|
|
770
770
|
const f = FORWARD.exec(content);
|
|
@@ -935,7 +935,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
935
935
|
detail = copy.tracked ? renamed.trim() : "copied before headers; matches the package";
|
|
936
936
|
} else if (copy.tracked) {
|
|
937
937
|
state = "changed-upstream";
|
|
938
|
-
detail = `${src.package} now ships a different ${
|
|
938
|
+
detail = `${src.package} now ships a different ${path62.posix.basename(src.file)}; the applied copy is never rewritten`;
|
|
939
939
|
} else {
|
|
940
940
|
state = "differs";
|
|
941
941
|
detail = "has the package migration's name but other text and no header; treated as the app's own";
|
|
@@ -957,7 +957,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
957
957
|
row.target = target2;
|
|
958
958
|
creates.push({ path: target2, content: migrationHeader(src.package, src.file, src.source) + src.source, kind, source: { package: src.package, file: src.file } });
|
|
959
959
|
if (options.tests !== false && src.test && src.testSource != null) {
|
|
960
|
-
const test2 = `${TESTS_DIR}/${
|
|
960
|
+
const test2 = `${TESTS_DIR}/${path62.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
|
|
961
961
|
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 } });
|
|
962
962
|
}
|
|
963
963
|
return;
|
|
@@ -1042,6 +1042,7 @@ __export(config_exports, {
|
|
|
1042
1042
|
privacyDataType: () => privacyDataType,
|
|
1043
1043
|
readGenesisConfig: () => readGenesisConfig,
|
|
1044
1044
|
validateAppFolder: () => validateAppFolder,
|
|
1045
|
+
validateClient: () => validateClient,
|
|
1045
1046
|
validateConfig: () => validateConfig,
|
|
1046
1047
|
validateEnvironments: () => validateEnvironments,
|
|
1047
1048
|
validateLinks: () => validateLinks,
|
|
@@ -1071,25 +1072,25 @@ function validateEnvironments(raw, source = "config") {
|
|
|
1071
1072
|
}
|
|
1072
1073
|
function appPath2(v, where2, fail) {
|
|
1073
1074
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
1074
|
-
if (
|
|
1075
|
-
const norm =
|
|
1075
|
+
if (path62.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
1076
|
+
const norm = path62.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1076
1077
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
1077
1078
|
return norm;
|
|
1078
1079
|
}
|
|
1079
1080
|
function loadConfig(root, configPath) {
|
|
1080
1081
|
if (configPath) {
|
|
1081
|
-
const file =
|
|
1082
|
+
const file = path62.resolve(root, configPath);
|
|
1082
1083
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
1083
1084
|
const json = readJson(file);
|
|
1084
|
-
const block =
|
|
1085
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
1085
|
+
const block = path62.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
1086
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path62.dirname(file) };
|
|
1086
1087
|
}
|
|
1087
|
-
const own =
|
|
1088
|
+
const own = path62.join(root, "genesis.config.json");
|
|
1088
1089
|
if (existsSync(own)) {
|
|
1089
1090
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
1090
1091
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
1091
1092
|
}
|
|
1092
|
-
const pkg =
|
|
1093
|
+
const pkg = path62.join(root, "package.json");
|
|
1093
1094
|
if (existsSync(pkg)) {
|
|
1094
1095
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
1095
1096
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -1098,7 +1099,7 @@ function loadConfig(root, configPath) {
|
|
|
1098
1099
|
}
|
|
1099
1100
|
function doctorBlock(json, file, explicit) {
|
|
1100
1101
|
const j = json;
|
|
1101
|
-
if (
|
|
1102
|
+
if (path62.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
1102
1103
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
1103
1104
|
}
|
|
1104
1105
|
function isPackageDeclaration(block) {
|
|
@@ -1115,7 +1116,7 @@ function readJson(file) {
|
|
|
1115
1116
|
}
|
|
1116
1117
|
}
|
|
1117
1118
|
function readGenesisConfig(root) {
|
|
1118
|
-
const file =
|
|
1119
|
+
const file = path62.join(root, "genesis.config.json");
|
|
1119
1120
|
if (!existsSync(file)) return null;
|
|
1120
1121
|
const raw = readJson(file);
|
|
1121
1122
|
if (!isObject2(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -1128,6 +1129,7 @@ function readGenesisConfig(root) {
|
|
|
1128
1129
|
}
|
|
1129
1130
|
if (raw.appFolder !== void 0) out.appFolder = validateAppFolder(raw.appFolder, file);
|
|
1130
1131
|
if (raw.environments !== void 0) out.environments = validateEnvironments(raw.environments, file);
|
|
1132
|
+
if (raw.client !== void 0) out.client = validateClient(raw.client, file);
|
|
1131
1133
|
return out;
|
|
1132
1134
|
}
|
|
1133
1135
|
function isPlainFolder(value) {
|
|
@@ -1138,6 +1140,16 @@ function validateAppFolder(raw, source = "config") {
|
|
|
1138
1140
|
if (!isPlainFolder(norm)) throw new GenesisConfigError(`${source}: "appFolder" must be the app's folder from the repository root, such as "mobile" or "apps/phone" (got ${JSON.stringify(raw)})`);
|
|
1139
1141
|
return norm;
|
|
1140
1142
|
}
|
|
1143
|
+
function validateClient(raw, source = "config") {
|
|
1144
|
+
const fail = (msg) => {
|
|
1145
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
1146
|
+
};
|
|
1147
|
+
if (!isObject2(raw)) return fail(`"client" must be { "dir": "<the client layer's folder, e.g. src/client>" }`);
|
|
1148
|
+
for (const key2 of Object.keys(raw)) if (key2 !== "dir" && key2 !== "$comment") fail(`client: unknown setting "${key2}" (known: dir)`);
|
|
1149
|
+
const dir = typeof raw.dir === "string" ? raw.dir.replace(/^\.\//, "").replace(/\/+$/, "") : "";
|
|
1150
|
+
if (!isPlainFolder(dir)) return fail(`client.dir must be a folder inside the app, such as "src/client" (got ${JSON.stringify(raw.dir)})`);
|
|
1151
|
+
return { dir };
|
|
1152
|
+
}
|
|
1141
1153
|
function validateSupabase(raw, source = "config") {
|
|
1142
1154
|
const fail = (msg) => {
|
|
1143
1155
|
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
@@ -1147,8 +1159,8 @@ function validateSupabase(raw, source = "config") {
|
|
|
1147
1159
|
for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
|
|
1148
1160
|
const app = raw.app;
|
|
1149
1161
|
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")`);
|
|
1150
|
-
if (
|
|
1151
|
-
const norm =
|
|
1162
|
+
if (path62.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
|
|
1163
|
+
const norm = path62.posix.normalize(app).replace(/\/+$/, "");
|
|
1152
1164
|
if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
|
|
1153
1165
|
return { app: norm };
|
|
1154
1166
|
}
|
|
@@ -1328,7 +1340,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1328
1340
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1329
1341
|
if (contracts.out !== void 0) {
|
|
1330
1342
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1331
|
-
if (
|
|
1343
|
+
if (path62.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1332
1344
|
}
|
|
1333
1345
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1334
1346
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1475,11 +1487,11 @@ function databaseElsewhere(root) {
|
|
|
1475
1487
|
const setting = readGenesisConfig(root)?.supabase;
|
|
1476
1488
|
if (setting === void 0) return null;
|
|
1477
1489
|
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
1478
|
-
const resolved =
|
|
1490
|
+
const resolved = path62.resolve(root, setting.app);
|
|
1479
1491
|
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
1480
1492
|
const dir = real2(resolved);
|
|
1481
|
-
if (dir === real2(
|
|
1482
|
-
return { app: setting.app, dir, hasSupabase: existsSync(
|
|
1493
|
+
if (dir === real2(path62.resolve(root))) throw new GenesisConfigError(`${path62.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
|
|
1494
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path62.join(dir, "supabase")) };
|
|
1483
1495
|
}
|
|
1484
1496
|
function isSupabasePath(rel) {
|
|
1485
1497
|
return rel === "supabase" || rel.startsWith("supabase/");
|
|
@@ -1525,7 +1537,7 @@ function migrationsMissingThere(home, ids, manifests) {
|
|
|
1525
1537
|
}
|
|
1526
1538
|
for (const fn of m.functions) {
|
|
1527
1539
|
if (superseded.has(`${fn.package}:${fn.dir}`)) continue;
|
|
1528
|
-
if (!existsSync(
|
|
1540
|
+
if (!existsSync(path62.join(home.dir, "supabase", "functions", fn.dir.split("/").pop()))) out.push({ block: id, what: `${fn.package} ${fn.dir}`, kind: "function" });
|
|
1529
1541
|
}
|
|
1530
1542
|
}
|
|
1531
1543
|
return out;
|
|
@@ -1564,11 +1576,11 @@ var init_database = __esm({
|
|
|
1564
1576
|
}
|
|
1565
1577
|
});
|
|
1566
1578
|
function findPackageDir(from, name) {
|
|
1567
|
-
let dir =
|
|
1579
|
+
let dir = path62.resolve(from);
|
|
1568
1580
|
for (; ; ) {
|
|
1569
|
-
const candidate =
|
|
1570
|
-
if (existsSync(
|
|
1571
|
-
const parent =
|
|
1581
|
+
const candidate = path62.join(dir, "node_modules", name);
|
|
1582
|
+
if (existsSync(path62.join(candidate, "package.json"))) return candidate;
|
|
1583
|
+
const parent = path62.dirname(dir);
|
|
1572
1584
|
if (parent === dir) return null;
|
|
1573
1585
|
dir = parent;
|
|
1574
1586
|
}
|
|
@@ -1611,7 +1623,7 @@ function loadGenesis(root, config) {
|
|
|
1611
1623
|
function notInstalled(root, uiPackage) {
|
|
1612
1624
|
let declared = false;
|
|
1613
1625
|
try {
|
|
1614
|
-
const pkg = JSON.parse(readFileSync(
|
|
1626
|
+
const pkg = JSON.parse(readFileSync(path62.join(root, "package.json"), "utf8"));
|
|
1615
1627
|
declared = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"].some((s) => pkg[s]?.[uiPackage] !== void 0);
|
|
1616
1628
|
} catch {
|
|
1617
1629
|
}
|
|
@@ -1634,7 +1646,7 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1634
1646
|
function readPackageExports(root, uiPackage) {
|
|
1635
1647
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1636
1648
|
if (!uiDir) return null;
|
|
1637
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1649
|
+
const uiPkg = JSON.parse(readFileSync(path62.join(uiDir, "package.json"), "utf8"));
|
|
1638
1650
|
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
1639
1651
|
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1640
1652
|
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
@@ -1661,23 +1673,23 @@ function readPackageExports(root, uiPackage) {
|
|
|
1661
1673
|
}
|
|
1662
1674
|
if (fromSource) {
|
|
1663
1675
|
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
1664
|
-
const next = resolveSource(
|
|
1676
|
+
const next = resolveSource(path62.dirname(file), m[1]);
|
|
1665
1677
|
if (next) readEntry(next);
|
|
1666
1678
|
}
|
|
1667
1679
|
}
|
|
1668
1680
|
};
|
|
1669
|
-
for (const entry of typeEntries) readEntry(
|
|
1681
|
+
for (const entry of typeEntries) readEntry(path62.join(uiDir, entry));
|
|
1670
1682
|
if (!readAny) {
|
|
1671
1683
|
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
1672
1684
|
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1673
1685
|
}
|
|
1674
1686
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1675
1687
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1676
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1688
|
+
const declRoot = typeof mainTypes === "string" ? path62.dirname(path62.join(uiDir, mainTypes)) : uiDir;
|
|
1677
1689
|
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
1678
1690
|
for (const pkg of reexportedPackages) {
|
|
1679
1691
|
const dir = findPackageDir(uiDir, pkg);
|
|
1680
|
-
if (dir) walkDts(
|
|
1692
|
+
if (dir) walkDts(path62.join(dir, "dist"), declFiles);
|
|
1681
1693
|
}
|
|
1682
1694
|
for (const file of declFiles) {
|
|
1683
1695
|
const text = readFileSync(file, "utf8");
|
|
@@ -1726,11 +1738,11 @@ function themeParts(root) {
|
|
|
1726
1738
|
if (!ds) return null;
|
|
1727
1739
|
if (partsCache.has(ds)) return partsCache.get(ds);
|
|
1728
1740
|
let found = null;
|
|
1729
|
-
const dist =
|
|
1741
|
+
const dist = path62.join(ds, "dist");
|
|
1730
1742
|
try {
|
|
1731
1743
|
for (const name of existsSync(dist) ? readdirSync(dist) : []) {
|
|
1732
1744
|
if (!name.endsWith(".js")) continue;
|
|
1733
|
-
const code = readFileSync(
|
|
1745
|
+
const code = readFileSync(path62.join(dist, name), "utf8");
|
|
1734
1746
|
const at = code.indexOf("THEME_PARTS = Object.freeze([");
|
|
1735
1747
|
if (at === -1) continue;
|
|
1736
1748
|
const body = code.slice(at, code.indexOf("]);", at));
|
|
@@ -1766,13 +1778,13 @@ function exportSource(target) {
|
|
|
1766
1778
|
return void 0;
|
|
1767
1779
|
}
|
|
1768
1780
|
function resolveSource(dir, spec) {
|
|
1769
|
-
const base =
|
|
1770
|
-
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) =>
|
|
1781
|
+
const base = path62.resolve(dir, spec.replace(/\.js$/, ""));
|
|
1782
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path62.join(base, i))];
|
|
1771
1783
|
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
1772
1784
|
}
|
|
1773
1785
|
function insidePackage(dir, file) {
|
|
1774
|
-
const rel =
|
|
1775
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1786
|
+
const rel = path62.relative(path62.resolve(dir), path62.resolve(file));
|
|
1787
|
+
return rel === "" || !rel.startsWith("..") && !path62.isAbsolute(rel);
|
|
1776
1788
|
}
|
|
1777
1789
|
function stripComments(code) {
|
|
1778
1790
|
let out = "";
|
|
@@ -1808,7 +1820,7 @@ function walkSource(dir, out = []) {
|
|
|
1808
1820
|
if (!existsSync(dir)) return out;
|
|
1809
1821
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1810
1822
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
1811
|
-
const p =
|
|
1823
|
+
const p = path62.join(dir, entry.name);
|
|
1812
1824
|
if (entry.isDirectory()) walkSource(p, out);
|
|
1813
1825
|
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1814
1826
|
}
|
|
@@ -1828,7 +1840,7 @@ function walkDts(dir, out = []) {
|
|
|
1828
1840
|
if (!existsSync(dir)) return out;
|
|
1829
1841
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1830
1842
|
if (entry.name === "node_modules") continue;
|
|
1831
|
-
const p =
|
|
1843
|
+
const p = path62.join(dir, entry.name);
|
|
1832
1844
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1833
1845
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1834
1846
|
}
|
|
@@ -1845,27 +1857,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1845
1857
|
}
|
|
1846
1858
|
const files = [];
|
|
1847
1859
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1848
|
-
const themes = ds &&
|
|
1860
|
+
const themes = ds && path62.join(ds, "dist", "themes");
|
|
1849
1861
|
if (themes && existsSync(themes)) {
|
|
1850
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1862
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path62.join(themes, name));
|
|
1851
1863
|
}
|
|
1852
1864
|
if (files.length === 0) {
|
|
1853
1865
|
throw new DoctorConfigError(
|
|
1854
1866
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1855
1867
|
);
|
|
1856
1868
|
}
|
|
1857
|
-
const uiStyles =
|
|
1869
|
+
const uiStyles = path62.join(uiDir, "dist", "styles.css");
|
|
1858
1870
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1859
1871
|
return files;
|
|
1860
1872
|
}
|
|
1861
1873
|
function resolveSpec(root, spec) {
|
|
1862
|
-
const local =
|
|
1863
|
-
if (spec.startsWith(".") ||
|
|
1874
|
+
const local = path62.resolve(root, spec);
|
|
1875
|
+
if (spec.startsWith(".") || path62.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1864
1876
|
const parts = spec.split("/");
|
|
1865
1877
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1866
1878
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1867
1879
|
if (dir) {
|
|
1868
|
-
const file =
|
|
1880
|
+
const file = path62.join(dir, ...parts.slice(nameLength));
|
|
1869
1881
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1870
1882
|
}
|
|
1871
1883
|
return existsSync(local) ? local : null;
|
|
@@ -1873,7 +1885,7 @@ function resolveSpec(root, spec) {
|
|
|
1873
1885
|
function loadPalette(root) {
|
|
1874
1886
|
const names = new Set(TAILWIND_PALETTE);
|
|
1875
1887
|
try {
|
|
1876
|
-
const req = createRequire(
|
|
1888
|
+
const req = createRequire(path62.join(root, "package.json"));
|
|
1877
1889
|
const colors = req("tailwindcss/colors");
|
|
1878
1890
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1879
1891
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -2121,7 +2133,7 @@ function globToRegExp(glob) {
|
|
|
2121
2133
|
}
|
|
2122
2134
|
function globMatcher(globs) {
|
|
2123
2135
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
2124
|
-
return (
|
|
2136
|
+
return (path63) => res.some((re) => re.test(path63));
|
|
2125
2137
|
}
|
|
2126
2138
|
var init_glob = __esm({
|
|
2127
2139
|
"src/doctor/glob.ts"() {
|
|
@@ -2133,9 +2145,9 @@ function scanFiles(root, config) {
|
|
|
2133
2145
|
const files = [];
|
|
2134
2146
|
const seen = /* @__PURE__ */ new Set();
|
|
2135
2147
|
const visit = (abs) => {
|
|
2136
|
-
const rel = toPosix(
|
|
2148
|
+
const rel = toPosix(path62.relative(root, abs));
|
|
2137
2149
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2138
|
-
const ext =
|
|
2150
|
+
const ext = path62.extname(abs);
|
|
2139
2151
|
if (!extensions.has(ext)) return;
|
|
2140
2152
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2141
2153
|
seen.add(rel);
|
|
@@ -2145,14 +2157,14 @@ function scanFiles(root, config) {
|
|
|
2145
2157
|
const walk4 = (dir) => {
|
|
2146
2158
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2147
2159
|
if (entry.isDirectory()) {
|
|
2148
|
-
if (!SKIP_DIRS.has(entry.name)) walk4(
|
|
2160
|
+
if (!SKIP_DIRS.has(entry.name)) walk4(path62.join(dir, entry.name));
|
|
2149
2161
|
} else if (entry.isFile()) {
|
|
2150
|
-
visit(
|
|
2162
|
+
visit(path62.join(dir, entry.name));
|
|
2151
2163
|
}
|
|
2152
2164
|
}
|
|
2153
2165
|
};
|
|
2154
2166
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2155
|
-
const abs =
|
|
2167
|
+
const abs = path62.resolve(root, src);
|
|
2156
2168
|
if (!existsSync(abs)) continue;
|
|
2157
2169
|
if (statSync(abs).isDirectory()) walk4(abs);
|
|
2158
2170
|
else visit(abs);
|
|
@@ -2194,7 +2206,7 @@ var init_scan = __esm({
|
|
|
2194
2206
|
];
|
|
2195
2207
|
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2196
2208
|
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2197
|
-
toPosix = (p) => p.split(
|
|
2209
|
+
toPosix = (p) => p.split(path62.sep).join("/");
|
|
2198
2210
|
}
|
|
2199
2211
|
});
|
|
2200
2212
|
|
|
@@ -2332,7 +2344,7 @@ function overlayState(name, json) {
|
|
|
2332
2344
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2333
2345
|
const problems = [];
|
|
2334
2346
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2335
|
-
const rel =
|
|
2347
|
+
const rel = path62.relative(path62.resolve(root), path62.resolve(dir)).split(path62.sep).join("/");
|
|
2336
2348
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2337
2349
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2338
2350
|
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})`);
|
|
@@ -2368,7 +2380,7 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
2368
2380
|
for (const file of manifests) {
|
|
2369
2381
|
let json;
|
|
2370
2382
|
try {
|
|
2371
|
-
json = JSON.parse(readFileSync(
|
|
2383
|
+
json = JSON.parse(readFileSync(path62.join(root, file), "utf8"));
|
|
2372
2384
|
} catch {
|
|
2373
2385
|
continue;
|
|
2374
2386
|
}
|
|
@@ -2393,7 +2405,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
|
2393
2405
|
const file = `${pkg.rel}/package.json`;
|
|
2394
2406
|
let json;
|
|
2395
2407
|
try {
|
|
2396
|
-
json = JSON.parse(readFileSync(
|
|
2408
|
+
json = JSON.parse(readFileSync(path62.join(pkg.dir, "package.json"), "utf8"));
|
|
2397
2409
|
} catch {
|
|
2398
2410
|
continue;
|
|
2399
2411
|
}
|
|
@@ -2466,7 +2478,7 @@ var init_overlays = __esm({
|
|
|
2466
2478
|
});
|
|
2467
2479
|
function readReleaseManifest(root) {
|
|
2468
2480
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2469
|
-
const file = dir &&
|
|
2481
|
+
const file = dir && path62.join(dir, "dist", "versions.json");
|
|
2470
2482
|
if (!file || !existsSync(file)) return null;
|
|
2471
2483
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
2472
2484
|
}
|
|
@@ -2492,7 +2504,7 @@ function checkVersionSkew(ctx) {
|
|
|
2492
2504
|
}
|
|
2493
2505
|
const dir = findPackageDir(ctx.root, name);
|
|
2494
2506
|
if (!dir) continue;
|
|
2495
|
-
const have = JSON.parse(readFileSync(
|
|
2507
|
+
const have = JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8")).version;
|
|
2496
2508
|
if (have === want) continue;
|
|
2497
2509
|
ctx.report({
|
|
2498
2510
|
rule: "version-skew",
|
|
@@ -2513,13 +2525,13 @@ var init_versions = __esm({
|
|
|
2513
2525
|
}
|
|
2514
2526
|
});
|
|
2515
2527
|
function findLockfile(root) {
|
|
2516
|
-
let dir =
|
|
2528
|
+
let dir = path62.resolve(root);
|
|
2517
2529
|
for (; ; ) {
|
|
2518
|
-
if (existsSync(
|
|
2519
|
-
if (existsSync(
|
|
2520
|
-
if (existsSync(
|
|
2521
|
-
if (existsSync(
|
|
2522
|
-
const parent =
|
|
2530
|
+
if (existsSync(path62.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
2531
|
+
if (existsSync(path62.join(dir, "bun.lock")) || existsSync(path62.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
2532
|
+
if (existsSync(path62.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
2533
|
+
if (existsSync(path62.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
2534
|
+
const parent = path62.dirname(dir);
|
|
2523
2535
|
if (parent === dir) return null;
|
|
2524
2536
|
dir = parent;
|
|
2525
2537
|
}
|
|
@@ -2563,10 +2575,10 @@ var init_pm = __esm({
|
|
|
2563
2575
|
function walk(dir, exclude = []) {
|
|
2564
2576
|
const out = [];
|
|
2565
2577
|
const visit = (rel) => {
|
|
2566
|
-
for (const name of readdirSync(
|
|
2578
|
+
for (const name of readdirSync(path62.join(dir, rel)).sort()) {
|
|
2567
2579
|
const child = rel ? `${rel}/${name}` : name;
|
|
2568
2580
|
if (exclude.some((r) => r.test(child))) continue;
|
|
2569
|
-
const stat = statSync(
|
|
2581
|
+
const stat = statSync(path62.join(dir, child));
|
|
2570
2582
|
if (stat.isDirectory()) visit(child);
|
|
2571
2583
|
else if (stat.isFile()) out.push(child);
|
|
2572
2584
|
}
|
|
@@ -2595,17 +2607,17 @@ var init_walk = __esm({
|
|
|
2595
2607
|
});
|
|
2596
2608
|
function starterDir() {
|
|
2597
2609
|
const workspace = workspacePackagesDir();
|
|
2598
|
-
const live = workspace &&
|
|
2599
|
-
if (live && existsSync(
|
|
2600
|
-
const packaged =
|
|
2601
|
-
if (existsSync(
|
|
2610
|
+
const live = workspace && path62.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
2611
|
+
if (live && existsSync(path62.join(live, "package.json"))) return live;
|
|
2612
|
+
const packaged = path62.join(cliPackageDir(), "dist", "starter");
|
|
2613
|
+
if (existsSync(path62.join(packaged, "package.json"))) return packaged;
|
|
2602
2614
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
2603
2615
|
}
|
|
2604
2616
|
function templatesDir(cliDir = cliPackageDir()) {
|
|
2605
2617
|
const workspace = workspacePackagesDir();
|
|
2606
|
-
const live = workspace && cliDir === cliPackageDir() ?
|
|
2607
|
-
if (live && existsSync(
|
|
2608
|
-
const packaged =
|
|
2618
|
+
const live = workspace && cliDir === cliPackageDir() ? path62.join(workspace, "..", "templates") : null;
|
|
2619
|
+
if (live && existsSync(path62.join(live, "eas"))) return live;
|
|
2620
|
+
const packaged = path62.join(cliDir, "dist", "templates");
|
|
2609
2621
|
if (existsSync(packaged)) return packaged;
|
|
2610
2622
|
throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
|
|
2611
2623
|
}
|
|
@@ -2702,7 +2714,7 @@ function readText(file) {
|
|
|
2702
2714
|
}
|
|
2703
2715
|
function starterBlockMap(root) {
|
|
2704
2716
|
if (root) {
|
|
2705
|
-
const file =
|
|
2717
|
+
const file = path62.join(root, GENESIS_CONFIG);
|
|
2706
2718
|
const text2 = readText(file);
|
|
2707
2719
|
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
2708
2720
|
if (own) return own;
|
|
@@ -2713,7 +2725,7 @@ function starterBlockMap(root) {
|
|
|
2713
2725
|
} catch {
|
|
2714
2726
|
return {};
|
|
2715
2727
|
}
|
|
2716
|
-
const text = readText(
|
|
2728
|
+
const text = readText(path62.join(dir, GENESIS_CONFIG));
|
|
2717
2729
|
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
2718
2730
|
}
|
|
2719
2731
|
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
@@ -2733,10 +2745,10 @@ function blocksSwitchedOff(switches, map, manifests, present) {
|
|
|
2733
2745
|
return off;
|
|
2734
2746
|
}
|
|
2735
2747
|
function appBlocksSwitchedOff(root, manifests, present) {
|
|
2736
|
-
const text = readText(
|
|
2748
|
+
const text = readText(path62.join(root, STARTER_CONFIG));
|
|
2737
2749
|
const switches = text === null ? null : parseStarterFeatures(text);
|
|
2738
2750
|
if (!switches) return /* @__PURE__ */ new Map();
|
|
2739
|
-
return blocksSwitchedOff(switches, starterBlockMap(existsSync(
|
|
2751
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path62.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
2740
2752
|
}
|
|
2741
2753
|
function switchedOffNote(id, feature) {
|
|
2742
2754
|
return `${id}: features.${feature} is off in ${STARTER_CONFIG}, so it's left out (turn it on to have it again)`;
|
|
@@ -2856,20 +2868,20 @@ function initNative(options) {
|
|
|
2856
2868
|
if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
|
|
2857
2869
|
if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
|
|
2858
2870
|
if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
|
|
2859
|
-
const target =
|
|
2871
|
+
const target = path62.resolve(options.target);
|
|
2860
2872
|
if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
|
|
2861
2873
|
let beside;
|
|
2862
2874
|
if (options.beside !== void 0) {
|
|
2863
|
-
const dir =
|
|
2875
|
+
const dir = path62.resolve(options.beside);
|
|
2864
2876
|
if (!existsSync(dir)) throw new Error(`--beside: ${options.beside} doesn't exist; name the web app's folder.`);
|
|
2865
2877
|
if (dir === target) throw new Error("--beside names the new app's own folder; name the web app's folder.");
|
|
2866
|
-
beside = { dir, app:
|
|
2878
|
+
beside = { dir, app: path62.relative(target, dir).split(path62.sep).join("/"), shared: existsSync(path62.join(dir, "supabase")) };
|
|
2867
2879
|
}
|
|
2868
2880
|
const shared = beside?.shared === true;
|
|
2869
2881
|
const source = starterDir();
|
|
2870
|
-
const
|
|
2871
|
-
const was = starterIdentity(
|
|
2872
|
-
const switches = parseStarterFeatures(
|
|
2882
|
+
const read3 = (rel) => readFileSync(path62.join(source, rel), "utf8");
|
|
2883
|
+
const was = starterIdentity(read3(STARTER_CONFIG));
|
|
2884
|
+
const switches = parseStarterFeatures(read3(STARTER_CONFIG)) ?? {};
|
|
2873
2885
|
const without = [...new Set(options.without ?? [])];
|
|
2874
2886
|
const unknown = without.filter((w) => !(w in switches));
|
|
2875
2887
|
if (unknown.length) throw new Error(`--without: ${unknown.join(", ")} ${unknown.length > 1 ? "aren't" : "isn't"} a feature switch in ${STARTER_CONFIG} (${Object.keys(switches).join(", ")}).`);
|
|
@@ -2885,7 +2897,7 @@ function initNative(options) {
|
|
|
2885
2897
|
const files = /* @__PURE__ */ new Map();
|
|
2886
2898
|
for (const rel of walk(source, STARTER_EXCLUDE)) {
|
|
2887
2899
|
const to = rel.replace(new RegExp(`(^|/)${PACKED_GITIGNORE}$`), "$1.gitignore");
|
|
2888
|
-
files.set(to, /^supabase\/(migrations|tests)\//.test(rel) ?
|
|
2900
|
+
files.set(to, /^supabase\/(migrations|tests)\//.test(rel) ? read3(rel) : substitute(read3(rel), substitutions));
|
|
2889
2901
|
}
|
|
2890
2902
|
const versionFor = options.versionFor ?? ((name) => pinnedVersion2(target, name)?.version ?? null);
|
|
2891
2903
|
const pkg = JSON.parse(files.get("package.json"));
|
|
@@ -2910,12 +2922,12 @@ function initNative(options) {
|
|
|
2910
2922
|
files.set("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
2911
2923
|
`);
|
|
2912
2924
|
files.set("metro.config.js", METRO);
|
|
2913
|
-
const pnpmSettings = [
|
|
2925
|
+
const pnpmSettings = [path62.join(source, "pnpm-workspace.yaml"), path62.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
|
|
2914
2926
|
if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
|
|
2915
2927
|
files.set("README.md", readme(display, slug, shared ? beside.app : void 0));
|
|
2916
2928
|
if (without.length) files.set(STARTER_CONFIG, setStarterFeatures(files.get(STARTER_CONFIG), Object.fromEntries(without.map((w) => [w, false]))));
|
|
2917
2929
|
const carried = options.blocks.filter((b) => carriedBy(files, b)).map((b) => b.id);
|
|
2918
|
-
const switchedOff = blocksSwitchedOff(features2, parseStarterBlocks(
|
|
2930
|
+
const switchedOff = blocksSwitchedOff(features2, parseStarterBlocks(read3("genesis.config.json")) ?? {}, options.blocks, carried);
|
|
2919
2931
|
const leftOut = options.blocks.filter((b) => switchedOff.has(b.id)).map((b) => b.id);
|
|
2920
2932
|
if (leftOut.length) leaveOut(files, options.blocks.filter((b) => switchedOff.has(b.id)));
|
|
2921
2933
|
if (shared) {
|
|
@@ -2931,7 +2943,7 @@ function initNative(options) {
|
|
|
2931
2943
|
const templates = templatesDir();
|
|
2932
2944
|
for (const rel of walk(templates)) {
|
|
2933
2945
|
if (shared && DATABASE_TEMPLATES.has(rel)) continue;
|
|
2934
|
-
const text = substitute(readFileSync(
|
|
2946
|
+
const text = substitute(readFileSync(path62.join(templates, rel), "utf8"), substitutions);
|
|
2935
2947
|
const to = templateTarget(rel, text);
|
|
2936
2948
|
files.set(to, text);
|
|
2937
2949
|
lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
|
|
@@ -2950,14 +2962,14 @@ function initNative(options) {
|
|
|
2950
2962
|
continue;
|
|
2951
2963
|
}
|
|
2952
2964
|
const stems = block.migrations.map((m) => stemOf(m.file));
|
|
2953
|
-
const copies = stems.map((s) => migrations.find((f) =>
|
|
2965
|
+
const copies = stems.map((s) => migrations.find((f) => path62.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
|
|
2954
2966
|
if (!stems.length || copies.some((c) => !c)) continue;
|
|
2955
2967
|
blocks.push(block.id);
|
|
2956
2968
|
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
2957
2969
|
block.migrations.forEach((m, i) => {
|
|
2958
2970
|
lock.migrations = { ...lock.migrations, [migrationKey(m.package, m.file)]: copies[i] };
|
|
2959
2971
|
if (m.test) {
|
|
2960
|
-
const test2 = `${TESTS_DIR}/${
|
|
2972
|
+
const test2 = `${TESTS_DIR}/${path62.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
|
|
2961
2973
|
if (files.has(test2)) lock.files[test2] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test2)) };
|
|
2962
2974
|
}
|
|
2963
2975
|
});
|
|
@@ -2970,8 +2982,8 @@ function initNative(options) {
|
|
|
2970
2982
|
}
|
|
2971
2983
|
mkdirSync(target, { recursive: true });
|
|
2972
2984
|
for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
2973
|
-
const file =
|
|
2974
|
-
mkdirSync(
|
|
2985
|
+
const file = path62.join(target, ...rel.split("/"));
|
|
2986
|
+
mkdirSync(path62.dirname(file), { recursive: true });
|
|
2975
2987
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
2976
2988
|
}
|
|
2977
2989
|
writeLock(target, lock);
|
|
@@ -3008,11 +3020,11 @@ function besideConfig(text, app) {
|
|
|
3008
3020
|
`;
|
|
3009
3021
|
}
|
|
3010
3022
|
function carriedBy(files, block) {
|
|
3011
|
-
const names = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) =>
|
|
3023
|
+
const names = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) => path62.posix.basename(f).replace(/^\d+_/, ""));
|
|
3012
3024
|
return block.migrations.length > 0 && block.migrations.every((m) => names.includes(`${stemOf(m.file)}.sql`));
|
|
3013
3025
|
}
|
|
3014
3026
|
function sinceAfter(files) {
|
|
3015
|
-
const versions = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) => /^(\d{14})_/.exec(
|
|
3027
|
+
const versions = [...files.keys()].filter((f) => f.startsWith(`${MIGRATIONS_DIR}/`) && f.endsWith(".sql")).map((f) => /^(\d{14})_/.exec(path62.posix.basename(f))?.[1]).filter((v) => Boolean(v)).sort();
|
|
3016
3028
|
const last = versions.at(-1);
|
|
3017
3029
|
return last ? nextStamp(last) : null;
|
|
3018
3030
|
}
|
|
@@ -3027,12 +3039,12 @@ function leaveOut(files, blocks) {
|
|
|
3027
3039
|
for (const block of blocks) {
|
|
3028
3040
|
for (const m of block.migrations) {
|
|
3029
3041
|
const stem = stemOf(m.file);
|
|
3030
|
-
for (const copy of migrations.filter((f) =>
|
|
3042
|
+
for (const copy of migrations.filter((f) => path62.posix.basename(f).replace(/^\d+_/, "") === `${stem}.sql`)) {
|
|
3031
3043
|
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());
|
|
3032
3044
|
files.delete(copy);
|
|
3033
3045
|
}
|
|
3034
3046
|
files.delete(`${TESTS_DIR}/${stem}.test.sql`);
|
|
3035
|
-
if (m.test) files.delete(`${TESTS_DIR}/${
|
|
3047
|
+
if (m.test) files.delete(`${TESTS_DIR}/${path62.posix.basename(m.test).replace(/^\d{4}_/, "")}`);
|
|
3036
3048
|
}
|
|
3037
3049
|
for (const fn of block.functions) {
|
|
3038
3050
|
const name = fn.dir.split("/").pop();
|
|
@@ -3102,6 +3114,15 @@ module.exports = withNativeWind(getDefaultConfig(__dirname), { input: "./global.
|
|
|
3102
3114
|
}
|
|
3103
3115
|
});
|
|
3104
3116
|
|
|
3117
|
+
// src/regexp.ts
|
|
3118
|
+
function escapeRegExp(s) {
|
|
3119
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3120
|
+
}
|
|
3121
|
+
var init_regexp = __esm({
|
|
3122
|
+
"src/regexp.ts"() {
|
|
3123
|
+
}
|
|
3124
|
+
});
|
|
3125
|
+
|
|
3105
3126
|
// src/introspect/catalog-text.ts
|
|
3106
3127
|
function tokenize(tree) {
|
|
3107
3128
|
const tokens = [];
|
|
@@ -3231,9 +3252,6 @@ function splitTopLevel(expr, separator) {
|
|
|
3231
3252
|
parts.push(expr.slice(from));
|
|
3232
3253
|
return parts;
|
|
3233
3254
|
}
|
|
3234
|
-
function escapeRegExp(s) {
|
|
3235
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3236
|
-
}
|
|
3237
3255
|
function checkEnumValues(definition, column) {
|
|
3238
3256
|
const outer = /^CHECK \((.*)\)(?: NOT VALID)?$/s.exec(definition.trim());
|
|
3239
3257
|
if (!outer) return void 0;
|
|
@@ -3268,6 +3286,7 @@ function checkEnumValues(definition, column) {
|
|
|
3268
3286
|
var CAST, LITERAL;
|
|
3269
3287
|
var init_catalog_text = __esm({
|
|
3270
3288
|
"src/introspect/catalog-text.ts"() {
|
|
3289
|
+
init_regexp();
|
|
3271
3290
|
CAST = String.raw`::[a-z][a-z ]*(?:\(\d+(?:,\d+)?\))?`;
|
|
3272
3291
|
LITERAL = String.raw`'((?:[^']|'')*)'${CAST}`;
|
|
3273
3292
|
}
|
|
@@ -3362,8 +3381,11 @@ var init_model = __esm({
|
|
|
3362
3381
|
});
|
|
3363
3382
|
|
|
3364
3383
|
// src/introspect/postgres.ts
|
|
3365
|
-
function where(
|
|
3366
|
-
return "schemas" in scope ?
|
|
3384
|
+
function where(scope) {
|
|
3385
|
+
return "schemas" in scope ? { condition: "n.nspname = any(array(select jsonb_array_elements_text($1::text::jsonb)))", param: JSON.stringify(scope.schemas) } : { condition: "c.oid = any(array(select jsonb_array_elements_text($1::text::jsonb)::oid))", param: JSON.stringify(scope.oids) };
|
|
3386
|
+
}
|
|
3387
|
+
async function read(sql, text, param) {
|
|
3388
|
+
return [...await sql.unsafe(text, [param])];
|
|
3367
3389
|
}
|
|
3368
3390
|
function linkOf(columns, refColumns, refUnique = []) {
|
|
3369
3391
|
if (columns.length === 1) return 0;
|
|
@@ -3372,7 +3394,8 @@ function linkOf(columns, refColumns, refUnique = []) {
|
|
|
3372
3394
|
return own.length === 1 && refUnique[own[0]] === true ? own[0] : -1;
|
|
3373
3395
|
}
|
|
3374
3396
|
async function readRelations(sql, scope, into) {
|
|
3375
|
-
const
|
|
3397
|
+
const { condition, param } = where(scope);
|
|
3398
|
+
const columns = await read(sql, `
|
|
3376
3399
|
select c.oid::text as oid, c.relkind::text as relkind, n.nspname as schema, c.relname as table,
|
|
3377
3400
|
obj_description(c.oid, 'pg_class') as table_comment,
|
|
3378
3401
|
a.attnum::int as attnum,
|
|
@@ -3391,17 +3414,17 @@ async function readRelations(sql, scope, into) {
|
|
|
3391
3414
|
join pg_attribute a on a.attrelid = c.oid and a.attnum > 0 and not a.attisdropped
|
|
3392
3415
|
join pg_type t on t.oid = a.atttypid
|
|
3393
3416
|
where c.relkind in ('r', 'p', 'v', 'm', 'f')
|
|
3394
|
-
and ${
|
|
3395
|
-
order by n.nspname, c.relname, a.attnum
|
|
3396
|
-
const keys = await sql`
|
|
3417
|
+
and ${condition}
|
|
3418
|
+
order by n.nspname, c.relname, a.attnum`, param);
|
|
3419
|
+
const keys = await read(sql, `
|
|
3397
3420
|
select c.oid::text as oid, array_agg(k.attnum::int order by k.ord) as columns
|
|
3398
3421
|
from pg_constraint con
|
|
3399
3422
|
join pg_class c on c.oid = con.conrelid
|
|
3400
3423
|
join pg_namespace n on n.oid = c.relnamespace
|
|
3401
3424
|
cross join lateral unnest(con.conkey) with ordinality as k(attnum, ord)
|
|
3402
|
-
where con.contype = 'p' and ${
|
|
3403
|
-
group by c.oid
|
|
3404
|
-
const links = await sql`
|
|
3425
|
+
where con.contype = 'p' and ${condition}
|
|
3426
|
+
group by c.oid`, param);
|
|
3427
|
+
const links = await read(sql, `
|
|
3405
3428
|
select c.oid::text as oid, con.conkey::int[] as attnums,
|
|
3406
3429
|
array(select a.attname::text from unnest(con.conkey) with ordinality k(attnum, ord)
|
|
3407
3430
|
join pg_attribute a on a.attrelid = c.oid and a.attnum = k.attnum order by k.ord) as columns,
|
|
@@ -3418,9 +3441,9 @@ async function readRelations(sql, scope, into) {
|
|
|
3418
3441
|
join pg_class rc on rc.oid = con.confrelid
|
|
3419
3442
|
join pg_namespace rn on rn.oid = rc.relnamespace
|
|
3420
3443
|
where con.contype = 'f'
|
|
3421
|
-
and ${
|
|
3422
|
-
order by con.conname
|
|
3423
|
-
const checks = await sql`
|
|
3444
|
+
and ${condition}
|
|
3445
|
+
order by con.conname`, param);
|
|
3446
|
+
const checks = await read(sql, `
|
|
3424
3447
|
select c.oid::text as oid, con.conkey[1]::int as attnum, a.attname as column,
|
|
3425
3448
|
pg_get_constraintdef(con.oid) as definition
|
|
3426
3449
|
from pg_constraint con
|
|
@@ -3428,9 +3451,9 @@ async function readRelations(sql, scope, into) {
|
|
|
3428
3451
|
join pg_namespace n on n.oid = c.relnamespace
|
|
3429
3452
|
join pg_attribute a on a.attrelid = c.oid and a.attnum = con.conkey[1]
|
|
3430
3453
|
where con.contype = 'c' and array_length(con.conkey, 1) = 1
|
|
3431
|
-
and ${
|
|
3432
|
-
order by con.conname
|
|
3433
|
-
const views = await sql`
|
|
3454
|
+
and ${condition}
|
|
3455
|
+
order by con.conname`, param);
|
|
3456
|
+
const views = await read(sql, `
|
|
3434
3457
|
select c.oid::text as oid, r.ev_action::text as ev_action
|
|
3435
3458
|
from pg_class c
|
|
3436
3459
|
join pg_namespace n on n.oid = c.relnamespace
|
|
@@ -3438,7 +3461,7 @@ async function readRelations(sql, scope, into) {
|
|
|
3438
3461
|
where c.relkind = 'v'
|
|
3439
3462
|
and (pg_relation_is_updatable(c.oid, false) & 20) = 20
|
|
3440
3463
|
and not exists (select 1 from pg_rewrite o where o.ev_class = c.oid and o.rulename <> '_RETURN')
|
|
3441
|
-
and ${
|
|
3464
|
+
and ${condition}`, param);
|
|
3442
3465
|
const added = [];
|
|
3443
3466
|
for (const row of columns) {
|
|
3444
3467
|
let relation = into.get(row.oid);
|
|
@@ -3834,14 +3857,14 @@ function sourceSchemas(source) {
|
|
|
3834
3857
|
const schemas = m?.[1].split(",").map((s) => s.trim()).filter(Boolean);
|
|
3835
3858
|
return schemas?.length ? schemas : null;
|
|
3836
3859
|
}
|
|
3837
|
-
async function checkContracts(ctx,
|
|
3860
|
+
async function checkContracts(ctx, read3 = postgresContract) {
|
|
3838
3861
|
const settings2 = ctx.config.contracts;
|
|
3839
3862
|
if (!settings2) return;
|
|
3840
3863
|
const out = settings2.out ?? DEFAULT_CONTRACT_OUT;
|
|
3841
3864
|
const env = settings2.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
3842
3865
|
let current = null;
|
|
3843
3866
|
try {
|
|
3844
|
-
current = lf(readFileSync(
|
|
3867
|
+
current = lf(readFileSync(path62.join(ctx.root, out), "utf8"));
|
|
3845
3868
|
} catch {
|
|
3846
3869
|
current = null;
|
|
3847
3870
|
}
|
|
@@ -3858,14 +3881,14 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
3858
3881
|
}
|
|
3859
3882
|
let expected;
|
|
3860
3883
|
try {
|
|
3861
|
-
expected = lf((await
|
|
3884
|
+
expected = lf((await read3(url, schemas)).content);
|
|
3862
3885
|
} catch (err) {
|
|
3863
3886
|
const generation = err.name === "EmitError";
|
|
3864
3887
|
const message = err.message.split("\n")[0];
|
|
3865
3888
|
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}` });
|
|
3866
3889
|
return;
|
|
3867
3890
|
}
|
|
3868
|
-
const target =
|
|
3891
|
+
const target = path62.relative(process.cwd(), path62.join(ctx.root, out)) || out;
|
|
3869
3892
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
3870
3893
|
if (current !== expected) {
|
|
3871
3894
|
ctx.report({
|
|
@@ -3893,7 +3916,7 @@ __export(settings_exports, {
|
|
|
3893
3916
|
});
|
|
3894
3917
|
function introspectSettings(flags, root, contracts, readCurrent = () => null) {
|
|
3895
3918
|
const out = flags.out ?? contracts?.out ?? DEFAULT_CONTRACT_OUT;
|
|
3896
|
-
const target =
|
|
3919
|
+
const target = path62.resolve(root, out);
|
|
3897
3920
|
return { target, label: out, schemas: schemasFor(flags, target, contracts, readCurrent), databaseEnv: flags.databaseEnv ?? contracts?.databaseEnv ?? DEFAULT_DATABASE_ENV };
|
|
3898
3921
|
}
|
|
3899
3922
|
function schemasFor(flags, target, contracts, readCurrent) {
|
|
@@ -3909,19 +3932,19 @@ var init_settings = __esm({
|
|
|
3909
3932
|
});
|
|
3910
3933
|
function buildCommands(root, config) {
|
|
3911
3934
|
if (config.build) return config.build;
|
|
3912
|
-
const pkgFile =
|
|
3935
|
+
const pkgFile = path62.join(root, "package.json");
|
|
3913
3936
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
3914
3937
|
const pm = packageManager(root);
|
|
3915
3938
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
3916
3939
|
}
|
|
3917
3940
|
function packageManager(root) {
|
|
3918
|
-
let dir =
|
|
3941
|
+
let dir = path62.resolve(root);
|
|
3919
3942
|
for (; ; ) {
|
|
3920
|
-
if (existsSync(
|
|
3921
|
-
if (existsSync(
|
|
3922
|
-
if (existsSync(
|
|
3923
|
-
if (existsSync(
|
|
3924
|
-
const parent =
|
|
3943
|
+
if (existsSync(path62.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
3944
|
+
if (existsSync(path62.join(dir, "bun.lock")) || existsSync(path62.join(dir, "bun.lockb"))) return "bun";
|
|
3945
|
+
if (existsSync(path62.join(dir, "yarn.lock"))) return "yarn";
|
|
3946
|
+
if (existsSync(path62.join(dir, "package-lock.json"))) return "npm";
|
|
3947
|
+
const parent = path62.dirname(dir);
|
|
3925
3948
|
if (parent === dir) return "npm";
|
|
3926
3949
|
dir = parent;
|
|
3927
3950
|
}
|
|
@@ -4019,7 +4042,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
4019
4042
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
4020
4043
|
let all = compiled;
|
|
4021
4044
|
if (rulesDoc) {
|
|
4022
|
-
const file =
|
|
4045
|
+
const file = path62.resolve(root, rulesDoc);
|
|
4023
4046
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
4024
4047
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
4025
4048
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -4087,20 +4110,336 @@ async function loadPlugins(specs, configDir) {
|
|
|
4087
4110
|
}
|
|
4088
4111
|
function resolvePlugin(id, configDir) {
|
|
4089
4112
|
try {
|
|
4090
|
-
if (id.startsWith(".") ||
|
|
4113
|
+
if (id.startsWith(".") || path62.isAbsolute(id)) return resolveFrom(path62.resolve(configDir, id), configDir);
|
|
4091
4114
|
return resolveFrom(id, configDir);
|
|
4092
4115
|
} catch {
|
|
4093
4116
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
4094
4117
|
}
|
|
4095
4118
|
}
|
|
4096
4119
|
function resolveFrom(id, from) {
|
|
4097
|
-
return createRequire(
|
|
4120
|
+
return createRequire(path62.join(from, "noop.js")).resolve(id);
|
|
4098
4121
|
}
|
|
4099
4122
|
var init_plugins = __esm({
|
|
4100
4123
|
"src/doctor/plugins.ts"() {
|
|
4101
4124
|
init_config();
|
|
4102
4125
|
}
|
|
4103
4126
|
});
|
|
4127
|
+
|
|
4128
|
+
// src/doctor/js-scan.ts
|
|
4129
|
+
function scanCode(code, options = {}) {
|
|
4130
|
+
const jsx = options.jsx ?? true;
|
|
4131
|
+
const tokens = [];
|
|
4132
|
+
const push = (kind, value) => tokens.push({ kind, value, index: tokens.length });
|
|
4133
|
+
const expressionNext = (start) => {
|
|
4134
|
+
if (tokens.length <= start) return true;
|
|
4135
|
+
const t = tokens[tokens.length - 1];
|
|
4136
|
+
if (!t) return true;
|
|
4137
|
+
if (t.kind === "ident") return EXPRESSION_KEYWORDS.has(t.value);
|
|
4138
|
+
if (t.kind === "jsxTag" || t.kind === "literal") return false;
|
|
4139
|
+
return !(t.value === ")" || t.value === "]" || t.value === "}" || t.value === "<>");
|
|
4140
|
+
};
|
|
4141
|
+
const skipString2 = (i2, quote2) => {
|
|
4142
|
+
let j = i2 + 1;
|
|
4143
|
+
while (j < code.length && code[j] !== quote2) {
|
|
4144
|
+
if (code[j] === "\\") j++;
|
|
4145
|
+
else if (code[j] === "\n") return j;
|
|
4146
|
+
j++;
|
|
4147
|
+
}
|
|
4148
|
+
return j + 1;
|
|
4149
|
+
};
|
|
4150
|
+
const skipAttribute = (i2, quote2) => {
|
|
4151
|
+
const end = code.indexOf(quote2, i2 + 1);
|
|
4152
|
+
return end < 0 ? code.length : end + 1;
|
|
4153
|
+
};
|
|
4154
|
+
const skipRegex = (i2) => {
|
|
4155
|
+
let j = i2 + 1;
|
|
4156
|
+
let inClass = false;
|
|
4157
|
+
while (j < code.length && code[j] !== "\n") {
|
|
4158
|
+
const c = code[j];
|
|
4159
|
+
if (c === "\\") j++;
|
|
4160
|
+
else if (c === "[") inClass = true;
|
|
4161
|
+
else if (c === "]") inClass = false;
|
|
4162
|
+
else if (c === "/" && !inClass) {
|
|
4163
|
+
j++;
|
|
4164
|
+
while (j < code.length && IDENT.test(code[j])) j++;
|
|
4165
|
+
return j;
|
|
4166
|
+
}
|
|
4167
|
+
j++;
|
|
4168
|
+
}
|
|
4169
|
+
return j;
|
|
4170
|
+
};
|
|
4171
|
+
const skipTrivia = (i2) => {
|
|
4172
|
+
let j = i2;
|
|
4173
|
+
for (; ; ) {
|
|
4174
|
+
while (j < code.length && /\s/.test(code[j])) j++;
|
|
4175
|
+
if (code.startsWith("//", j)) {
|
|
4176
|
+
const end = code.indexOf("\n", j);
|
|
4177
|
+
j = end < 0 ? code.length : end;
|
|
4178
|
+
} else if (code.startsWith("/*", j)) {
|
|
4179
|
+
const end = code.indexOf("*/", j + 2);
|
|
4180
|
+
j = end < 0 ? code.length : end + 2;
|
|
4181
|
+
} else return j;
|
|
4182
|
+
}
|
|
4183
|
+
};
|
|
4184
|
+
const stack = [{ k: "code", depth: 0, stop: false, start: 0 }];
|
|
4185
|
+
const openCode = () => stack.push({ k: "code", depth: 0, stop: true, start: tokens.length });
|
|
4186
|
+
const openElement = (i2) => {
|
|
4187
|
+
if (code[i2 + 1] === ">") {
|
|
4188
|
+
stack.push({ k: "children" });
|
|
4189
|
+
return i2 + 2;
|
|
4190
|
+
}
|
|
4191
|
+
let j = i2 + 1;
|
|
4192
|
+
while (j < code.length && /[\w$.:-]/.test(code[j])) j++;
|
|
4193
|
+
const name = code.slice(i2 + 1, j);
|
|
4194
|
+
if (name) push("jsxTag", name.split(/[.:]/)[0]);
|
|
4195
|
+
stack.push({ k: "tag" });
|
|
4196
|
+
return j;
|
|
4197
|
+
};
|
|
4198
|
+
const closeElement = () => {
|
|
4199
|
+
stack.pop();
|
|
4200
|
+
push("punct", "<>");
|
|
4201
|
+
};
|
|
4202
|
+
let i = 0;
|
|
4203
|
+
while (i < code.length) {
|
|
4204
|
+
const top = stack[stack.length - 1];
|
|
4205
|
+
if (top.k === "code") {
|
|
4206
|
+
i = skipTrivia(i);
|
|
4207
|
+
if (i >= code.length) break;
|
|
4208
|
+
const c = code[i];
|
|
4209
|
+
if (c === '"' || c === "'") {
|
|
4210
|
+
i = skipString2(i, c);
|
|
4211
|
+
push("literal", "''");
|
|
4212
|
+
} else if (c === "`") {
|
|
4213
|
+
stack.push({ k: "template" });
|
|
4214
|
+
i++;
|
|
4215
|
+
} else if (IDENT_START.test(c)) {
|
|
4216
|
+
let j = i + 1;
|
|
4217
|
+
while (j < code.length && IDENT.test(code[j])) j++;
|
|
4218
|
+
push("ident", code.slice(i, j));
|
|
4219
|
+
i = j;
|
|
4220
|
+
} else if (/\d/.test(c) || c === "." && /\d/.test(code[i + 1] ?? "")) {
|
|
4221
|
+
let j = i + 1;
|
|
4222
|
+
while (j < code.length && /[\w.]/.test(code[j])) j++;
|
|
4223
|
+
push("literal", "0");
|
|
4224
|
+
i = j;
|
|
4225
|
+
} else if (c === "/" && expressionNext(top.start)) {
|
|
4226
|
+
i = skipRegex(i);
|
|
4227
|
+
push("literal", "//");
|
|
4228
|
+
} else if (c === "<" && jsx && expressionNext(top.start) && /[A-Za-z_$>]/.test(code[i + 1] ?? "") && !TYPE_PARAMETERS.test(code.slice(i, i + 200))) {
|
|
4229
|
+
i = openElement(i);
|
|
4230
|
+
} else if (c === "{") {
|
|
4231
|
+
top.depth++;
|
|
4232
|
+
push("punct", "{");
|
|
4233
|
+
i++;
|
|
4234
|
+
} else if (c === "}") {
|
|
4235
|
+
i++;
|
|
4236
|
+
if (top.depth === 0 && top.stop) stack.pop();
|
|
4237
|
+
else {
|
|
4238
|
+
top.depth = Math.max(0, top.depth - 1);
|
|
4239
|
+
push("punct", "}");
|
|
4240
|
+
}
|
|
4241
|
+
} else {
|
|
4242
|
+
const three = code.slice(i, i + 3);
|
|
4243
|
+
const two = code.slice(i, i + 2);
|
|
4244
|
+
const p = PUNCT3.includes(three) ? three : PUNCT2.includes(two) ? two : c;
|
|
4245
|
+
push("punct", p);
|
|
4246
|
+
i += p.length;
|
|
4247
|
+
}
|
|
4248
|
+
} else if (top.k === "template") {
|
|
4249
|
+
const c = code[i];
|
|
4250
|
+
if (c === "\\") i += 2;
|
|
4251
|
+
else if (c === "`") {
|
|
4252
|
+
stack.pop();
|
|
4253
|
+
push("literal", "``");
|
|
4254
|
+
i++;
|
|
4255
|
+
} else if (c === "$" && code[i + 1] === "{") {
|
|
4256
|
+
openCode();
|
|
4257
|
+
i += 2;
|
|
4258
|
+
} else i++;
|
|
4259
|
+
} else if (top.k === "tag") {
|
|
4260
|
+
i = skipTrivia(i);
|
|
4261
|
+
const c = code[i];
|
|
4262
|
+
if (c === void 0) break;
|
|
4263
|
+
if (c === "/" && code[i + 1] === ">") {
|
|
4264
|
+
closeElement();
|
|
4265
|
+
i += 2;
|
|
4266
|
+
} else if (c === ">") {
|
|
4267
|
+
stack[stack.length - 1] = { k: "children" };
|
|
4268
|
+
i++;
|
|
4269
|
+
} else if (c === "{") {
|
|
4270
|
+
openCode();
|
|
4271
|
+
i++;
|
|
4272
|
+
} else if (c === '"' || c === "'") i = skipAttribute(i, c);
|
|
4273
|
+
else if (c === "<") i = openElement(i);
|
|
4274
|
+
else i++;
|
|
4275
|
+
} else {
|
|
4276
|
+
const c = code[i];
|
|
4277
|
+
if (c === "<" && code[i + 1] === "/") {
|
|
4278
|
+
const end = code.indexOf(">", i);
|
|
4279
|
+
i = end < 0 ? code.length : end + 1;
|
|
4280
|
+
closeElement();
|
|
4281
|
+
} else if (c === "<" && /[A-Za-z_$>]/.test(code[i + 1] ?? "")) i = openElement(i);
|
|
4282
|
+
else if (c === "{") {
|
|
4283
|
+
openCode();
|
|
4284
|
+
i++;
|
|
4285
|
+
} else i++;
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
return tokens;
|
|
4289
|
+
}
|
|
4290
|
+
function usesAsCode(code, name, options = {}) {
|
|
4291
|
+
const tokens = scanCode(code, options);
|
|
4292
|
+
return tokens.some((t, i) => {
|
|
4293
|
+
if (t.value !== name) return false;
|
|
4294
|
+
if (t.kind === "jsxTag") return true;
|
|
4295
|
+
if (t.kind !== "ident") return false;
|
|
4296
|
+
const before = tokens[i - 1];
|
|
4297
|
+
const after = tokens[i + 1];
|
|
4298
|
+
if (before?.value === "." || before?.value === "?." || before?.value === "as" || before?.value === "import") return false;
|
|
4299
|
+
if (after?.value === ":" && (before?.value === "{" || before?.value === ",")) return false;
|
|
4300
|
+
return true;
|
|
4301
|
+
});
|
|
4302
|
+
}
|
|
4303
|
+
function boundNames(list) {
|
|
4304
|
+
const out = [];
|
|
4305
|
+
const params = [[]];
|
|
4306
|
+
let depth = 0;
|
|
4307
|
+
let angles = 0;
|
|
4308
|
+
let inType = false;
|
|
4309
|
+
for (const t of list) {
|
|
4310
|
+
if (OPENS.has(t.value)) depth++;
|
|
4311
|
+
else if (CLOSES.has(t.value)) depth--;
|
|
4312
|
+
else if (depth === 0 && t.value === ":") inType = true;
|
|
4313
|
+
else if (depth === 0 && t.value === "=") inType = false;
|
|
4314
|
+
else if (inType && t.value === "<") angles++;
|
|
4315
|
+
else if (inType && (t.value === ">" || t.value === ">>")) angles = Math.max(0, angles - t.value.length);
|
|
4316
|
+
if (depth === 0 && angles === 0 && t.value === ",") {
|
|
4317
|
+
params.push([]);
|
|
4318
|
+
inType = false;
|
|
4319
|
+
} else params[params.length - 1].push(t);
|
|
4320
|
+
}
|
|
4321
|
+
for (const param of params) {
|
|
4322
|
+
let d = 0;
|
|
4323
|
+
let end = param.length;
|
|
4324
|
+
for (let k = 0; k < param.length; k++) {
|
|
4325
|
+
const v = param[k].value;
|
|
4326
|
+
if (OPENS.has(v)) d++;
|
|
4327
|
+
else if (CLOSES.has(v)) d--;
|
|
4328
|
+
else if (d === 0 && (v === "=" || v === ":" || v === "?")) {
|
|
4329
|
+
end = k;
|
|
4330
|
+
break;
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
const pattern = param.slice(0, end);
|
|
4334
|
+
let skipping = -1;
|
|
4335
|
+
d = 0;
|
|
4336
|
+
for (let k = 0; k < pattern.length; k++) {
|
|
4337
|
+
const t = pattern[k];
|
|
4338
|
+
if (t.value === "[" && skipping < 0) {
|
|
4339
|
+
let depth2 = 0;
|
|
4340
|
+
let close = k;
|
|
4341
|
+
for (; close < pattern.length; close++) {
|
|
4342
|
+
const v = pattern[close].value;
|
|
4343
|
+
if (OPENS.has(v)) depth2++;
|
|
4344
|
+
else if (CLOSES.has(v) && --depth2 === 0) break;
|
|
4345
|
+
}
|
|
4346
|
+
if (pattern[close + 1]?.value === ":") {
|
|
4347
|
+
k = close;
|
|
4348
|
+
continue;
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4351
|
+
if (OPENS.has(t.value)) d++;
|
|
4352
|
+
else if (CLOSES.has(t.value)) {
|
|
4353
|
+
d--;
|
|
4354
|
+
if (skipping > d) skipping = -1;
|
|
4355
|
+
}
|
|
4356
|
+
if (skipping >= 0) {
|
|
4357
|
+
if (t.value === "," && d === skipping) skipping = -1;
|
|
4358
|
+
continue;
|
|
4359
|
+
}
|
|
4360
|
+
if (t.value === "=") {
|
|
4361
|
+
skipping = d;
|
|
4362
|
+
continue;
|
|
4363
|
+
}
|
|
4364
|
+
if (t.kind === "ident" && pattern[k + 1]?.value !== ":") out.push(t.value);
|
|
4365
|
+
}
|
|
4366
|
+
}
|
|
4367
|
+
return out;
|
|
4368
|
+
}
|
|
4369
|
+
function boundAsParameter(code, name, options = {}) {
|
|
4370
|
+
const tokens = scanCode(code, options);
|
|
4371
|
+
const match = new Int32Array(tokens.length).fill(-1);
|
|
4372
|
+
const open = [];
|
|
4373
|
+
tokens.forEach((t, k) => {
|
|
4374
|
+
if (t.value === "(") open.push(k);
|
|
4375
|
+
else if (t.value === ")" && open.length) match[open.pop()] = k;
|
|
4376
|
+
});
|
|
4377
|
+
const arrowAfter = (end) => {
|
|
4378
|
+
const next = tokens[end + 1];
|
|
4379
|
+
if (next?.value === "=>") return true;
|
|
4380
|
+
if (next?.value !== ":") return false;
|
|
4381
|
+
let depth = 0;
|
|
4382
|
+
for (let k = end + 2; k < Math.min(tokens.length, end + 200); k++) {
|
|
4383
|
+
const v = tokens[k].value;
|
|
4384
|
+
if (v === "(" || v === "{" || v === "[" || v === "<") depth++;
|
|
4385
|
+
else if (v === ")" || v === "}" || v === "]" || v === ">") depth--;
|
|
4386
|
+
if (depth < 0) return false;
|
|
4387
|
+
if (depth === 0 && v === "=>") return true;
|
|
4388
|
+
if (depth === 0 && (v === ";" || v === "," || v === "=")) return false;
|
|
4389
|
+
}
|
|
4390
|
+
return false;
|
|
4391
|
+
};
|
|
4392
|
+
const beforeTypeParameters = (paren) => {
|
|
4393
|
+
let k = paren - 1;
|
|
4394
|
+
if (tokens[k]?.value !== ">" && tokens[k]?.value !== ">>") return k;
|
|
4395
|
+
let depth = 0;
|
|
4396
|
+
for (const stop = Math.max(0, k - TYPE_PARAMETERS_REACH); k >= stop; k--) {
|
|
4397
|
+
const v = tokens[k].value;
|
|
4398
|
+
if (v === ">") depth++;
|
|
4399
|
+
else if (v === ">>") depth += 2;
|
|
4400
|
+
else if (v === "<" && --depth === 0) return k - 1;
|
|
4401
|
+
}
|
|
4402
|
+
return -1;
|
|
4403
|
+
};
|
|
4404
|
+
const isFunction = (paren) => {
|
|
4405
|
+
let k = beforeTypeParameters(paren);
|
|
4406
|
+
if (k < 0) return false;
|
|
4407
|
+
if (tokens[k]?.kind === "ident" && tokens[k].value !== "function") k--;
|
|
4408
|
+
if (tokens[k]?.value === "*") k--;
|
|
4409
|
+
return tokens[k]?.value === "function";
|
|
4410
|
+
};
|
|
4411
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
4412
|
+
const t = tokens[i];
|
|
4413
|
+
if (t.value === "=>" && tokens[i - 1]?.kind === "ident" && tokens[i - 1].value === name && tokens[i - 2]?.value !== ".") return true;
|
|
4414
|
+
if (t.value !== "(") continue;
|
|
4415
|
+
const end = match[i];
|
|
4416
|
+
if (end < 0) continue;
|
|
4417
|
+
const before = tokens[i - 1];
|
|
4418
|
+
const catchClause = before?.value === "catch";
|
|
4419
|
+
const nameAt = beforeTypeParameters(i);
|
|
4420
|
+
const methodName = nameAt >= 0 ? tokens[nameAt] : void 0;
|
|
4421
|
+
const typed = tokens[end + 1]?.value === ":" && !arrowAfter(end);
|
|
4422
|
+
const method = !catchClause && methodName?.kind === "ident" && !NOT_METHODS.has(methodName.value) && (tokens[end + 1]?.value === "{" || typed && (nameAt === 0 || BEFORE_METHOD.has(tokens[nameAt - 1].value)));
|
|
4423
|
+
if ((catchClause || isFunction(i) || method || arrowAfter(end)) && boundNames(tokens.slice(i + 1, end)).includes(name)) return true;
|
|
4424
|
+
}
|
|
4425
|
+
return false;
|
|
4426
|
+
}
|
|
4427
|
+
var IDENT_START, IDENT, PUNCT3, PUNCT2, EXPRESSION_KEYWORDS, TYPE_PARAMETERS, NOT_METHODS, BEFORE_METHOD, TYPE_PARAMETERS_REACH, OPENS, CLOSES;
|
|
4428
|
+
var init_js_scan = __esm({
|
|
4429
|
+
"src/doctor/js-scan.ts"() {
|
|
4430
|
+
IDENT_START = /[A-Za-z_$]/;
|
|
4431
|
+
IDENT = /[\w$]/;
|
|
4432
|
+
PUNCT3 = ["...", "===", "!==", "**=", "<<=", ">>=", "??=", "&&=", "||="];
|
|
4433
|
+
PUNCT2 = ["=>", "==", "!=", "<=", ">=", "&&", "||", "??", "?.", "++", "--", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "**", "<<", ">>"];
|
|
4434
|
+
EXPRESSION_KEYWORDS = /* @__PURE__ */ new Set(["return", "typeof", "case", "do", "else", "in", "new", "delete", "void", "throw", "yield", "await", "instanceof"]);
|
|
4435
|
+
TYPE_PARAMETERS = /^<\s*[A-Za-z_$][\w$]*\s*(?:,|extends\b)/;
|
|
4436
|
+
NOT_METHODS = /* @__PURE__ */ new Set(["if", "for", "while", "switch", "with", "function", "return", "typeof", "await", "new"]);
|
|
4437
|
+
BEFORE_METHOD = /* @__PURE__ */ new Set(["{", "}", ";", ",", "*", "async", "get", "set", "static", "public", "private", "protected", "readonly", "override", "abstract", "declare", "accessor"]);
|
|
4438
|
+
TYPE_PARAMETERS_REACH = 200;
|
|
4439
|
+
OPENS = /* @__PURE__ */ new Set(["(", "[", "{"]);
|
|
4440
|
+
CLOSES = /* @__PURE__ */ new Set([")", "]", "}"]);
|
|
4441
|
+
}
|
|
4442
|
+
});
|
|
4104
4443
|
function importSpecifiers(file) {
|
|
4105
4444
|
const out = [];
|
|
4106
4445
|
const lines = file.code.split("\n");
|
|
@@ -4112,7 +4451,7 @@ function importSpecifiers(file) {
|
|
|
4112
4451
|
}
|
|
4113
4452
|
function checkProjectLayout(ctx) {
|
|
4114
4453
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
4115
|
-
if (existsSync(
|
|
4454
|
+
if (existsSync(path62.join(ctx.root, dir))) {
|
|
4116
4455
|
ctx.report({
|
|
4117
4456
|
rule: "local-primitives",
|
|
4118
4457
|
file: dir,
|
|
@@ -4122,7 +4461,7 @@ function checkProjectLayout(ctx) {
|
|
|
4122
4461
|
}
|
|
4123
4462
|
}
|
|
4124
4463
|
for (const file of STARTER_LEFTOVERS) {
|
|
4125
|
-
if (existsSync(
|
|
4464
|
+
if (existsSync(path62.join(ctx.root, file))) {
|
|
4126
4465
|
ctx.report({
|
|
4127
4466
|
rule: "starter-leftover",
|
|
4128
4467
|
level: "warn",
|
|
@@ -4210,7 +4549,7 @@ function checkTokens(ctx) {
|
|
|
4210
4549
|
}
|
|
4211
4550
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
4212
4551
|
if (/[*?]/.test(pattern)) continue;
|
|
4213
|
-
const abs =
|
|
4552
|
+
const abs = path62.join(ctx.root, pattern);
|
|
4214
4553
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
4215
4554
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
4216
4555
|
}
|
|
@@ -4231,14 +4570,32 @@ function checkShadowedExports(ctx) {
|
|
|
4231
4570
|
const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
|
|
4232
4571
|
for (const file of ctx.files) {
|
|
4233
4572
|
if (!SCRIPT_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
4573
|
+
const wrapped = wrappedGenesisNames(file.code, ctx.genesis.uiPackage, { jsx: file.ext !== ".ts" && file.ext !== ".mts" });
|
|
4234
4574
|
file.code.split("\n").forEach((text, i) => {
|
|
4235
4575
|
for (const m of text.matchAll(re)) {
|
|
4236
4576
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
4577
|
+
if (wrapped.has(m[1])) continue;
|
|
4237
4578
|
ctx.report({ rule: "shadowed-export", file: file.path, line: i + 1, subject: m[1], message: `shadows the Genesis export '${m[1]}'; reuse or extend ${m[1]} from ${ctx.genesis.uiPackage} (or rename yours if it's a different thing)` });
|
|
4238
4579
|
}
|
|
4239
4580
|
});
|
|
4240
4581
|
}
|
|
4241
4582
|
}
|
|
4583
|
+
function wrappedGenesisNames(code, uiPackage, options = {}) {
|
|
4584
|
+
const out = /* @__PURE__ */ new Set();
|
|
4585
|
+
const pkg = uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
4586
|
+
const re = new RegExp(`\\bimport\\s+(?:type\\s+)?\\{([^}]*)\\}\\s*from\\s*["']${pkg}(?:/[^"']*)?["']`, "g");
|
|
4587
|
+
for (const m of code.matchAll(re)) {
|
|
4588
|
+
if (/^import\s+type\b/.test(m[0])) continue;
|
|
4589
|
+
for (const part of m[1].split(",")) {
|
|
4590
|
+
const spec = part.trim();
|
|
4591
|
+
if (!spec || spec.startsWith("type ")) continue;
|
|
4592
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
4593
|
+
if (!imported || !local || local === imported) continue;
|
|
4594
|
+
if (usesAsCode(code, local, options)) out.add(imported);
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
return out;
|
|
4598
|
+
}
|
|
4242
4599
|
function unusedComponents(ctx) {
|
|
4243
4600
|
const used = /* @__PURE__ */ new Set();
|
|
4244
4601
|
const pkg = ctx.genesis.uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
@@ -4259,7 +4616,9 @@ var init_rules = __esm({
|
|
|
4259
4616
|
init_color_literals();
|
|
4260
4617
|
init_glob();
|
|
4261
4618
|
init_genesis();
|
|
4619
|
+
init_js_scan();
|
|
4262
4620
|
init_overlays();
|
|
4621
|
+
init_js_scan();
|
|
4263
4622
|
BUILTIN_RULES = [
|
|
4264
4623
|
"local-primitives",
|
|
4265
4624
|
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
@@ -4347,7 +4706,10 @@ var init_rules = __esm({
|
|
|
4347
4706
|
// custom views and app parts (custom-views.ts)
|
|
4348
4707
|
"app-part-colors",
|
|
4349
4708
|
"app-part-name",
|
|
4350
|
-
"custom-view-states"
|
|
4709
|
+
"custom-view-states",
|
|
4710
|
+
// the app's client layer (client-layer.ts)
|
|
4711
|
+
"client/layer",
|
|
4712
|
+
"client/one-view-per-resource"
|
|
4351
4713
|
];
|
|
4352
4714
|
DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
4353
4715
|
STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -4432,10 +4794,10 @@ var init_expo = __esm({
|
|
|
4432
4794
|
}
|
|
4433
4795
|
});
|
|
4434
4796
|
function resolveLocal(root, fromFile, spec) {
|
|
4435
|
-
const bases = spec.startsWith(".") ? [
|
|
4797
|
+
const bases = spec.startsWith(".") ? [path62.resolve(path62.dirname(fromFile), spec)] : [path62.join(root, spec.slice(2)), path62.join(root, "src", spec.slice(2))];
|
|
4436
4798
|
for (const base of bases) {
|
|
4437
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
4438
|
-
(p) => SCRIPT_EXTS2.has(
|
|
4799
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path62.join(base, `index${e}`))].find(
|
|
4800
|
+
(p) => SCRIPT_EXTS2.has(path62.extname(p)) && existsSync(p)
|
|
4439
4801
|
);
|
|
4440
4802
|
if (hit) return hit;
|
|
4441
4803
|
}
|
|
@@ -4585,13 +4947,13 @@ function checkNativePack(ctx) {
|
|
|
4585
4947
|
}
|
|
4586
4948
|
function checkEasPlaceholders(ctx) {
|
|
4587
4949
|
const files = [];
|
|
4588
|
-
if (existsSync(
|
|
4589
|
-
const workflows =
|
|
4950
|
+
if (existsSync(path62.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
4951
|
+
const workflows = path62.join(ctx.root, ".eas", "workflows");
|
|
4590
4952
|
if (existsSync(workflows)) {
|
|
4591
4953
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
4592
4954
|
}
|
|
4593
4955
|
for (const file of files) {
|
|
4594
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
4956
|
+
for (const hit of findPlaceholders(file, readFileSync(path62.join(ctx.root, file), "utf8"))) {
|
|
4595
4957
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
4596
4958
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
4597
4959
|
ctx.report({
|
|
@@ -4669,7 +5031,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
4669
5031
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
4670
5032
|
const code = file.code;
|
|
4671
5033
|
const hidden = HIDES_HEADER.exec(code);
|
|
4672
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
5034
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path62.posix.dirname(file.path), file.path);
|
|
4673
5035
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
4674
5036
|
if (hidden && own) {
|
|
4675
5037
|
reported.add(file.path);
|
|
@@ -4697,7 +5059,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
4697
5059
|
}
|
|
4698
5060
|
for (const file of ctx.files) {
|
|
4699
5061
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
4700
|
-
const layout = hidingLayouts.get(
|
|
5062
|
+
const layout = hidingLayouts.get(path62.posix.dirname(file.path));
|
|
4701
5063
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
4702
5064
|
if (!layout || !own) continue;
|
|
4703
5065
|
ctx.report({
|
|
@@ -4718,13 +5080,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
4718
5080
|
}
|
|
4719
5081
|
function routerRoot(ctx) {
|
|
4720
5082
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
4721
|
-
return existsSync(
|
|
5083
|
+
return existsSync(path62.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
4722
5084
|
}
|
|
4723
5085
|
function checkScreenLayouts(ctx, pkg) {
|
|
4724
5086
|
const layouts = nativeLayouts(pkg);
|
|
4725
5087
|
if (layouts.length === 0) return;
|
|
4726
5088
|
const rootDir = routerRoot(ctx);
|
|
4727
|
-
if (!existsSync(
|
|
5089
|
+
if (!existsSync(path62.join(ctx.root, rootDir))) {
|
|
4728
5090
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
4729
5091
|
return;
|
|
4730
5092
|
}
|
|
@@ -4761,7 +5123,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
4761
5123
|
function readExpoConfigs(root) {
|
|
4762
5124
|
const out = [];
|
|
4763
5125
|
for (const name of EXPO_CONFIGS) {
|
|
4764
|
-
const abs =
|
|
5126
|
+
const abs = path62.join(root, name);
|
|
4765
5127
|
if (!existsSync(abs)) continue;
|
|
4766
5128
|
const text = readFileSync(abs, "utf8");
|
|
4767
5129
|
let json = null;
|
|
@@ -4795,13 +5157,13 @@ function pluginOptions(json, module) {
|
|
|
4795
5157
|
return null;
|
|
4796
5158
|
}
|
|
4797
5159
|
function dependencies(root) {
|
|
4798
|
-
const file =
|
|
5160
|
+
const file = path62.join(root, "package.json");
|
|
4799
5161
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
4800
5162
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
4801
5163
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
4802
5164
|
}
|
|
4803
5165
|
function runtimeDependencies(root) {
|
|
4804
|
-
const file =
|
|
5166
|
+
const file = path62.join(root, "package.json");
|
|
4805
5167
|
if (!existsSync(file)) return {};
|
|
4806
5168
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
4807
5169
|
}
|
|
@@ -5090,14 +5452,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
5090
5452
|
seen.add(file);
|
|
5091
5453
|
const json = readJsonc(file);
|
|
5092
5454
|
if (!json) return {};
|
|
5093
|
-
const dir =
|
|
5455
|
+
const dir = path62.dirname(file);
|
|
5094
5456
|
let merged = {};
|
|
5095
5457
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
5096
5458
|
for (const ext of parents) {
|
|
5097
5459
|
if (typeof ext !== "string") continue;
|
|
5098
5460
|
let target = null;
|
|
5099
|
-
if (ext.startsWith(".") ||
|
|
5100
|
-
const abs =
|
|
5461
|
+
if (ext.startsWith(".") || path62.isAbsolute(ext)) {
|
|
5462
|
+
const abs = path62.resolve(dir, ext);
|
|
5101
5463
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
5102
5464
|
} else {
|
|
5103
5465
|
const parts = ext.split("/");
|
|
@@ -5105,14 +5467,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
5105
5467
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
5106
5468
|
if (pkgDir) {
|
|
5107
5469
|
const sub = parts.slice(nameLength).join("/");
|
|
5108
|
-
const abs =
|
|
5470
|
+
const abs = path62.join(pkgDir, sub || "tsconfig.json");
|
|
5109
5471
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
5110
5472
|
}
|
|
5111
5473
|
}
|
|
5112
5474
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
5113
5475
|
}
|
|
5114
5476
|
const opts = json.compilerOptions ?? {};
|
|
5115
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
5477
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path62.resolve(dir, opts.baseUrl);
|
|
5116
5478
|
if (opts.paths && typeof opts.paths === "object") {
|
|
5117
5479
|
merged.paths = opts.paths;
|
|
5118
5480
|
merged.pathsDir = dir;
|
|
@@ -5123,7 +5485,7 @@ function aliases(root) {
|
|
|
5123
5485
|
const table = [];
|
|
5124
5486
|
let baseUrl = null;
|
|
5125
5487
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
5126
|
-
const file =
|
|
5488
|
+
const file = path62.join(root, name);
|
|
5127
5489
|
if (!existsSync(file)) continue;
|
|
5128
5490
|
const config = readTsconfig(root, file);
|
|
5129
5491
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -5131,22 +5493,22 @@ function aliases(root) {
|
|
|
5131
5493
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
5132
5494
|
if (!Array.isArray(targets)) continue;
|
|
5133
5495
|
const exact = !pattern.endsWith("*");
|
|
5134
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
5496
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path62.join(base, String(t).replace(/\*$/, ""))) });
|
|
5135
5497
|
}
|
|
5136
5498
|
}
|
|
5137
|
-
const pkg = readJsonc(
|
|
5499
|
+
const pkg = readJsonc(path62.join(root, "package.json"));
|
|
5138
5500
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
5139
5501
|
if (typeof target !== "string") continue;
|
|
5140
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
5502
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path62.join(root, target.replace(/\*.*$/, ""))] });
|
|
5141
5503
|
}
|
|
5142
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
5504
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path62.join(root, "src") + path62.sep, root + path62.sep] });
|
|
5143
5505
|
return { table, baseUrl };
|
|
5144
5506
|
}
|
|
5145
5507
|
function resolveFile(base) {
|
|
5146
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
5508
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path62.join(base, `index${e}`))];
|
|
5147
5509
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
5148
5510
|
for (const p of tries) {
|
|
5149
|
-
if (SCRIPT_EXTS2.has(
|
|
5511
|
+
if (SCRIPT_EXTS2.has(path62.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
5150
5512
|
}
|
|
5151
5513
|
return null;
|
|
5152
5514
|
}
|
|
@@ -5159,13 +5521,13 @@ function createTrail(ctx) {
|
|
|
5159
5521
|
const { table, baseUrl } = aliases(ctx.root);
|
|
5160
5522
|
let declared = null;
|
|
5161
5523
|
try {
|
|
5162
|
-
const pkg = JSON.parse(readFileSync(
|
|
5524
|
+
const pkg = JSON.parse(readFileSync(path62.join(ctx.root, "package.json"), "utf8"));
|
|
5163
5525
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
5164
5526
|
} catch {
|
|
5165
5527
|
declared = null;
|
|
5166
5528
|
}
|
|
5167
5529
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
5168
|
-
const
|
|
5530
|
+
const read3 = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
5169
5531
|
const importsCache = /* @__PURE__ */ new Map();
|
|
5170
5532
|
const importsOf = (file) => {
|
|
5171
5533
|
const hit = importsCache.get(file.absolutePath);
|
|
@@ -5190,17 +5552,17 @@ function createTrail(ctx) {
|
|
|
5190
5552
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
5191
5553
|
let resolved = null;
|
|
5192
5554
|
if (spec.startsWith(".")) {
|
|
5193
|
-
resolved = resolveFile(
|
|
5555
|
+
resolved = resolveFile(path62.resolve(path62.dirname(file.absolutePath), spec));
|
|
5194
5556
|
if (!resolved) lost = true;
|
|
5195
5557
|
} else {
|
|
5196
5558
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
5197
5559
|
if (alias) {
|
|
5198
5560
|
for (const t of alias.targets) {
|
|
5199
|
-
resolved = resolveFile(alias.exact ? t :
|
|
5561
|
+
resolved = resolveFile(alias.exact ? t : path62.join(t, spec.slice(alias.prefix.length)));
|
|
5200
5562
|
if (resolved) break;
|
|
5201
5563
|
}
|
|
5202
5564
|
}
|
|
5203
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
5565
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path62.join(baseUrl, spec));
|
|
5204
5566
|
if (!resolved) {
|
|
5205
5567
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
5206
5568
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -5242,7 +5604,7 @@ function createTrail(ctx) {
|
|
|
5242
5604
|
cut.add(abs);
|
|
5243
5605
|
continue;
|
|
5244
5606
|
}
|
|
5245
|
-
const target =
|
|
5607
|
+
const target = read3(abs);
|
|
5246
5608
|
if (!target) {
|
|
5247
5609
|
unknown = true;
|
|
5248
5610
|
continue;
|
|
@@ -5286,7 +5648,7 @@ var init_trail = __esm({
|
|
|
5286
5648
|
});
|
|
5287
5649
|
function routesDir(ctx) {
|
|
5288
5650
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
5289
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
5651
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path62.join(ctx.root, d))) ?? null;
|
|
5290
5652
|
}
|
|
5291
5653
|
function flavorOf(dir, rels) {
|
|
5292
5654
|
const stems = rels.map((r) => r.split("/").pop());
|
|
@@ -5427,7 +5789,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
5427
5789
|
});
|
|
5428
5790
|
if (typeof raw === "string") {
|
|
5429
5791
|
if (!packageDir2) fail(`points at ${raw}, but the package folder is unknown`);
|
|
5430
|
-
const file =
|
|
5792
|
+
const file = path62.resolve(packageDir2, raw);
|
|
5431
5793
|
if (!inside(packageDir2, file)) fail(`points outside the package (${raw})`);
|
|
5432
5794
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
5433
5795
|
let parsed;
|
|
@@ -5476,7 +5838,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
5476
5838
|
if (typeof c.plugin === "string") {
|
|
5477
5839
|
if (!packageDir2) plugin = c.plugin;
|
|
5478
5840
|
else {
|
|
5479
|
-
plugin =
|
|
5841
|
+
plugin = path62.resolve(packageDir2, c.plugin);
|
|
5480
5842
|
if (!inside(packageDir2, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
5481
5843
|
}
|
|
5482
5844
|
}
|
|
@@ -5529,7 +5891,7 @@ function checkPattern(v, where2, fail) {
|
|
|
5529
5891
|
}
|
|
5530
5892
|
}
|
|
5531
5893
|
function readDeclaringPackage(dir, local) {
|
|
5532
|
-
const file =
|
|
5894
|
+
const file = path62.join(dir, "package.json");
|
|
5533
5895
|
let stamp;
|
|
5534
5896
|
let real2;
|
|
5535
5897
|
try {
|
|
@@ -5552,7 +5914,7 @@ ${local}`;
|
|
|
5552
5914
|
const pkg = {
|
|
5553
5915
|
name: json.name,
|
|
5554
5916
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
5555
|
-
dir:
|
|
5917
|
+
dir: path62.resolve(dir),
|
|
5556
5918
|
namespace: ruleNamespace(json.name),
|
|
5557
5919
|
local,
|
|
5558
5920
|
private: json.private === true,
|
|
@@ -5566,7 +5928,7 @@ ${local}`;
|
|
|
5566
5928
|
if (raw !== void 0) {
|
|
5567
5929
|
const ignored = [];
|
|
5568
5930
|
try {
|
|
5569
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
5931
|
+
pkg.declaration = validateDeclaration(raw, json.name, path62.resolve(dir), ignored);
|
|
5570
5932
|
if (ignored.length) pkg.ignored = ignored;
|
|
5571
5933
|
} catch (err) {
|
|
5572
5934
|
pkg.error = err.message;
|
|
@@ -5585,14 +5947,14 @@ function discoverPackages(root) {
|
|
|
5585
5947
|
for (const dir of installed) {
|
|
5586
5948
|
let scope;
|
|
5587
5949
|
try {
|
|
5588
|
-
scope =
|
|
5950
|
+
scope = path62.dirname(realpathSync(dir));
|
|
5589
5951
|
} catch {
|
|
5590
5952
|
continue;
|
|
5591
5953
|
}
|
|
5592
|
-
if (
|
|
5954
|
+
if (path62.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
5593
5955
|
for (const entry of readdirSync(scope)) {
|
|
5594
5956
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
5595
|
-
const pkg = readDeclaringPackage(
|
|
5957
|
+
const pkg = readDeclaringPackage(path62.join(scope, entry), false);
|
|
5596
5958
|
if (pkg) byName.set(pkg.name, pkg);
|
|
5597
5959
|
}
|
|
5598
5960
|
}
|
|
@@ -5833,10 +6195,10 @@ var init_package_rules = __esm({
|
|
|
5833
6195
|
});
|
|
5834
6196
|
function sourceFiles(dir, rel = "") {
|
|
5835
6197
|
const out = [];
|
|
5836
|
-
for (const entry of readdirSync(
|
|
6198
|
+
for (const entry of readdirSync(path62.join(dir, rel)).sort()) {
|
|
5837
6199
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
5838
6200
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
5839
|
-
const stat = lstatSync(
|
|
6201
|
+
const stat = lstatSync(path62.join(dir, child));
|
|
5840
6202
|
if (stat.isSymbolicLink()) continue;
|
|
5841
6203
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
5842
6204
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -5859,13 +6221,13 @@ function matchPattern(pattern, spec) {
|
|
|
5859
6221
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
5860
6222
|
}
|
|
5861
6223
|
function tsconfigPaths(dir) {
|
|
5862
|
-
const file =
|
|
6224
|
+
const file = path62.join(dir, "tsconfig.json");
|
|
5863
6225
|
if (!existsSync(file)) return [];
|
|
5864
6226
|
try {
|
|
5865
6227
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
5866
6228
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
5867
|
-
const base =
|
|
5868
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
6229
|
+
const base = path62.resolve(dir, options.baseUrl ?? ".");
|
|
6230
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path62.resolve(base, t)) }));
|
|
5869
6231
|
} catch {
|
|
5870
6232
|
return [];
|
|
5871
6233
|
}
|
|
@@ -5879,8 +6241,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5879
6241
|
const hit = matchPattern(pattern, spec);
|
|
5880
6242
|
if (hit === null) continue;
|
|
5881
6243
|
return targets.some((t) => {
|
|
5882
|
-
const rel =
|
|
5883
|
-
return !rel.startsWith("..") && !
|
|
6244
|
+
const rel = path62.relative(pkg.dir, t.replace("*", hit));
|
|
6245
|
+
return !rel.startsWith("..") && !path62.isAbsolute(rel);
|
|
5884
6246
|
});
|
|
5885
6247
|
}
|
|
5886
6248
|
return null;
|
|
@@ -5893,7 +6255,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5893
6255
|
...Object.keys(json.optionalDependencies ?? {})
|
|
5894
6256
|
]);
|
|
5895
6257
|
for (const file of sourceFiles(pkg.dir)) {
|
|
5896
|
-
const code = stripForImports(readFileSync(
|
|
6258
|
+
const code = stripForImports(readFileSync(path62.join(pkg.dir, file), "utf8"));
|
|
5897
6259
|
if (code === null) continue;
|
|
5898
6260
|
const at = `${pkg.rel}/${file}`;
|
|
5899
6261
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -5918,9 +6280,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5918
6280
|
continue;
|
|
5919
6281
|
}
|
|
5920
6282
|
if (spec.startsWith(".")) {
|
|
5921
|
-
const target =
|
|
5922
|
-
const rel =
|
|
5923
|
-
if (rel.startsWith("..") ||
|
|
6283
|
+
const target = path62.resolve(pkg.dir, path62.dirname(file), spec);
|
|
6284
|
+
const rel = path62.relative(pkg.dir, target);
|
|
6285
|
+
if (rel.startsWith("..") || path62.isAbsolute(rel)) {
|
|
5924
6286
|
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` });
|
|
5925
6287
|
}
|
|
5926
6288
|
continue;
|
|
@@ -5956,12 +6318,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5956
6318
|
const from = own ? "" : ` (in ${m.package})`;
|
|
5957
6319
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
5958
6320
|
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` });
|
|
5959
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
6321
|
+
} else if (typeof m.test === "string" && !existsSync(path62.join(home, m.test))) {
|
|
5960
6322
|
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` });
|
|
5961
6323
|
}
|
|
5962
6324
|
}
|
|
5963
6325
|
}
|
|
5964
|
-
const dir =
|
|
6326
|
+
const dir = path62.join(pkg.dir, "migrations");
|
|
5965
6327
|
if (!existsSync(dir)) return;
|
|
5966
6328
|
const seen = /* @__PURE__ */ new Map();
|
|
5967
6329
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -5970,7 +6332,7 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5970
6332
|
const other = seen.get(m[1]);
|
|
5971
6333
|
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` });
|
|
5972
6334
|
else seen.set(m[1], name);
|
|
5973
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
6335
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path62.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
5974
6336
|
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")})` });
|
|
5975
6337
|
}
|
|
5976
6338
|
}
|
|
@@ -5984,7 +6346,7 @@ function checkExports(ctx, pkg, json) {
|
|
|
5984
6346
|
walk4(json.exports);
|
|
5985
6347
|
for (const t of targets) {
|
|
5986
6348
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
5987
|
-
if (!existsSync(
|
|
6349
|
+
if (!existsSync(path62.join(pkg.dir, t))) {
|
|
5988
6350
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
5989
6351
|
}
|
|
5990
6352
|
}
|
|
@@ -6002,11 +6364,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
6002
6364
|
function checkTaggedTests(ctx, pkg) {
|
|
6003
6365
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
6004
6366
|
if (!tests.length) return;
|
|
6005
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
6367
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path62.join(pkg.dir, f), "utf8")));
|
|
6006
6368
|
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>` });
|
|
6007
6369
|
}
|
|
6008
6370
|
function checkRegistered(ctx, pkg) {
|
|
6009
|
-
const file =
|
|
6371
|
+
const file = path62.join(ctx.root, "features.json");
|
|
6010
6372
|
if (!existsSync(file)) return;
|
|
6011
6373
|
let doc;
|
|
6012
6374
|
try {
|
|
@@ -6016,7 +6378,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
6016
6378
|
}
|
|
6017
6379
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
6018
6380
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
6019
|
-
if (top) forms.add(
|
|
6381
|
+
if (top) forms.add(path62.relative(top, realpathSync(pkg.dir)).split(path62.sep).join("/"));
|
|
6020
6382
|
const covered = (doc.features ?? []).some(
|
|
6021
6383
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
6022
6384
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -6046,8 +6408,8 @@ function mergeBaseOf(root, base) {
|
|
|
6046
6408
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
6047
6409
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
6048
6410
|
if (!top) return;
|
|
6049
|
-
const appRelative = (fromTop) =>
|
|
6050
|
-
const inRepo =
|
|
6411
|
+
const appRelative = (fromTop) => path62.relative(realpathSync(ctx.root), path62.join(top, fromTop)).split(path62.sep).join("/");
|
|
6412
|
+
const inRepo = path62.relative(top, realpathSync(pkg.dir)).split(path62.sep).join("/");
|
|
6051
6413
|
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");
|
|
6052
6414
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
6053
6415
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -6070,11 +6432,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
6070
6432
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
6071
6433
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
6072
6434
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
6073
|
-
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) =>
|
|
6435
|
+
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) => path62.join(top, f)) : [];
|
|
6074
6436
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
6075
6437
|
const named = naming.length > 0;
|
|
6076
6438
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
6077
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
6439
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path62.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
6078
6440
|
}
|
|
6079
6441
|
let jsonBefore = null;
|
|
6080
6442
|
try {
|
|
@@ -6084,7 +6446,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
6084
6446
|
}
|
|
6085
6447
|
const raw = json;
|
|
6086
6448
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
6087
|
-
const appInRepo =
|
|
6449
|
+
const appInRepo = path62.relative(top, realpathSync(ctx.root)).split(path62.sep).join("/");
|
|
6088
6450
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
6089
6451
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
6090
6452
|
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` });
|
|
@@ -6135,7 +6497,7 @@ function checkPackagesPack(ctx) {
|
|
|
6135
6497
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
6136
6498
|
}
|
|
6137
6499
|
for (const pkg of packages) {
|
|
6138
|
-
const json = JSON.parse(readFileSync(
|
|
6500
|
+
const json = JSON.parse(readFileSync(path62.join(pkg.dir, "package.json"), "utf8"));
|
|
6139
6501
|
checkImports2(ctx, pkg, json);
|
|
6140
6502
|
checkExports(ctx, pkg, json);
|
|
6141
6503
|
checkBlocks(ctx, pkg, json);
|
|
@@ -6334,9 +6696,9 @@ function checkSupabasePack(ctx) {
|
|
|
6334
6696
|
if (databaseElsewhere(ctx.root)) return;
|
|
6335
6697
|
const settings2 = ctx.config.supabase ?? {};
|
|
6336
6698
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
6337
|
-
const abs =
|
|
6699
|
+
const abs = path62.join(ctx.root, dir);
|
|
6338
6700
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
6339
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
6701
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path62.join(abs, n), "utf8")) }));
|
|
6340
6702
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
6341
6703
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
6342
6704
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -6353,7 +6715,7 @@ function checkSupabasePack(ctx) {
|
|
|
6353
6715
|
}
|
|
6354
6716
|
}
|
|
6355
6717
|
const since = settings2.since;
|
|
6356
|
-
const afterSince = (file) => since === void 0 ||
|
|
6718
|
+
const afterSince = (file) => since === void 0 || path62.posix.basename(file) >= since;
|
|
6357
6719
|
if ("reason" in view && since === void 0) {
|
|
6358
6720
|
ctx.report({
|
|
6359
6721
|
rule: "migration-grants",
|
|
@@ -6407,8 +6769,8 @@ function checkExposedSchemasCreatedLater(ctx, dir, migrations, configured, branc
|
|
|
6407
6769
|
if (m && m[1] !== "authorization" && !created.has(m[1])) created.set(m[1], { file, line });
|
|
6408
6770
|
}
|
|
6409
6771
|
}
|
|
6410
|
-
const tomlFile =
|
|
6411
|
-
const tomlText = existsSync(
|
|
6772
|
+
const tomlFile = path62.posix.join(path62.posix.dirname(dir), "config.toml");
|
|
6773
|
+
const tomlText = existsSync(path62.join(ctx.root, tomlFile)) ? readFileSync(path62.join(ctx.root, tomlFile), "utf8") : null;
|
|
6412
6774
|
const api2 = tomlText === null ? null : apiSchemas(tomlText);
|
|
6413
6775
|
const sources = [];
|
|
6414
6776
|
if (api2?.enabled) for (const schema of api2.schemas) sources.push({ schema, file: tomlFile, line: api2.line, where: `${tomlFile} [api] schemas` });
|
|
@@ -6715,18 +7077,18 @@ var init_supabase = __esm({
|
|
|
6715
7077
|
}
|
|
6716
7078
|
});
|
|
6717
7079
|
function nodeModulesOf(dir) {
|
|
6718
|
-
const parent =
|
|
6719
|
-
return
|
|
7080
|
+
const parent = path62.dirname(dir);
|
|
7081
|
+
return path62.basename(parent).startsWith("@") ? path62.dirname(parent) : parent;
|
|
6720
7082
|
}
|
|
6721
7083
|
function packagesIn(nodeModules) {
|
|
6722
7084
|
if (!existsSync(nodeModules)) return [];
|
|
6723
7085
|
const out = [];
|
|
6724
7086
|
for (const entry of readdirSync(nodeModules)) {
|
|
6725
7087
|
if (entry.startsWith(".")) continue;
|
|
6726
|
-
const p =
|
|
7088
|
+
const p = path62.join(nodeModules, entry);
|
|
6727
7089
|
if (entry.startsWith("@")) {
|
|
6728
7090
|
try {
|
|
6729
|
-
for (const sub of readdirSync(p)) out.push(
|
|
7091
|
+
for (const sub of readdirSync(p)) out.push(path62.join(p, sub));
|
|
6730
7092
|
} catch {
|
|
6731
7093
|
}
|
|
6732
7094
|
} else {
|
|
@@ -6738,7 +7100,7 @@ function packagesIn(nodeModules) {
|
|
|
6738
7100
|
function genesisInstalls(root) {
|
|
6739
7101
|
const copies = /* @__PURE__ */ new Map();
|
|
6740
7102
|
const realRoot = real(root);
|
|
6741
|
-
const rel = (abs) =>
|
|
7103
|
+
const rel = (abs) => path62.relative(realRoot, abs).split(path62.sep).join("/") || ".";
|
|
6742
7104
|
const via = /* @__PURE__ */ new Map();
|
|
6743
7105
|
const record = (real2, manifest, by, range, root2) => {
|
|
6744
7106
|
let copy = copies.get(real2);
|
|
@@ -6783,7 +7145,7 @@ function genesisInstalls(root) {
|
|
|
6783
7145
|
if (!dir) return null;
|
|
6784
7146
|
if (!ownInstall || name in declared) return dir;
|
|
6785
7147
|
const realDir = real(dir);
|
|
6786
|
-
if (realDir.startsWith(realRoot +
|
|
7148
|
+
if (realDir.startsWith(realRoot + path62.sep)) return dir;
|
|
6787
7149
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
6788
7150
|
};
|
|
6789
7151
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -6791,7 +7153,7 @@ function genesisInstalls(root) {
|
|
|
6791
7153
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
6792
7154
|
});
|
|
6793
7155
|
const app = readManifest(root);
|
|
6794
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
7156
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path62.join(root, f)));
|
|
6795
7157
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
6796
7158
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
6797
7159
|
const runtimeDeps = {
|
|
@@ -6802,11 +7164,11 @@ function genesisInstalls(root) {
|
|
|
6802
7164
|
};
|
|
6803
7165
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
6804
7166
|
walk4("runtime", rootsOf(runtimeDeps, "the app"));
|
|
6805
|
-
const top =
|
|
7167
|
+
const top = path62.join(root, "node_modules");
|
|
6806
7168
|
walk4(
|
|
6807
7169
|
"hoisted",
|
|
6808
7170
|
packagesIn(top).filter((dir) => {
|
|
6809
|
-
const name =
|
|
7171
|
+
const name = path62.relative(top, dir).split(path62.sep).join("/");
|
|
6810
7172
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
6811
7173
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
6812
7174
|
);
|
|
@@ -6848,7 +7210,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
6848
7210
|
}
|
|
6849
7211
|
}
|
|
6850
7212
|
function checkPeerRanges(ctx) {
|
|
6851
|
-
const rel = (abs) =>
|
|
7213
|
+
const rel = (abs) => path62.relative(ctx.root, abs).split(path62.sep).join("/");
|
|
6852
7214
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
6853
7215
|
for (const copy of copies) {
|
|
6854
7216
|
const dir = copy.absolutePath;
|
|
@@ -6881,7 +7243,7 @@ var init_installs = __esm({
|
|
|
6881
7243
|
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)$/;
|
|
6882
7244
|
readManifest = (dir) => {
|
|
6883
7245
|
try {
|
|
6884
|
-
return JSON.parse(readFileSync(
|
|
7246
|
+
return JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8"));
|
|
6885
7247
|
} catch {
|
|
6886
7248
|
return null;
|
|
6887
7249
|
}
|
|
@@ -7080,11 +7442,11 @@ function appScripts(root) {
|
|
|
7080
7442
|
const out = [];
|
|
7081
7443
|
const walk4 = (dir) => {
|
|
7082
7444
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
7083
|
-
const abs =
|
|
7445
|
+
const abs = path62.join(dir, entry.name);
|
|
7084
7446
|
if (entry.isDirectory()) {
|
|
7085
7447
|
if (!SKIP_DIRS3.has(entry.name)) walk4(abs);
|
|
7086
7448
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
7087
|
-
out.push(
|
|
7449
|
+
out.push(path62.relative(root, abs).split(path62.sep).join("/"));
|
|
7088
7450
|
}
|
|
7089
7451
|
}
|
|
7090
7452
|
};
|
|
@@ -7397,7 +7759,7 @@ var init_doctor_rule_codemods = __esm({
|
|
|
7397
7759
|
run({ root, dryRun, log }) {
|
|
7398
7760
|
const changed = [];
|
|
7399
7761
|
for (const rel of appScripts(root).filter((f) => /\.[jt]sx$/.test(f))) {
|
|
7400
|
-
const abs =
|
|
7762
|
+
const abs = path62.join(root, rel);
|
|
7401
7763
|
const text = readFileSync(abs, "utf8");
|
|
7402
7764
|
const next = rewriteOverlayHeights(text);
|
|
7403
7765
|
if (next === text) continue;
|
|
@@ -7424,7 +7786,7 @@ var init_doctor_rule_codemods = __esm({
|
|
|
7424
7786
|
const changed = [];
|
|
7425
7787
|
for (const rel of appScripts(root)) {
|
|
7426
7788
|
if (/(?:^|\/)__tests__\/|\.test\.[jt]sx?$/.test(rel)) continue;
|
|
7427
|
-
const abs =
|
|
7789
|
+
const abs = path62.join(root, rel);
|
|
7428
7790
|
const text = readFileSync(abs, "utf8");
|
|
7429
7791
|
if (!text.includes("expo-haptics")) continue;
|
|
7430
7792
|
const result = rewriteHaptics(text);
|
|
@@ -7640,11 +8002,11 @@ var init_scope_names = __esm({
|
|
|
7640
8002
|
}
|
|
7641
8003
|
});
|
|
7642
8004
|
function findEslintConfig(root) {
|
|
7643
|
-
return FLAT_CONFIG_FILES.find((name) => existsSync(
|
|
8005
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path62.join(root, name))) ?? null;
|
|
7644
8006
|
}
|
|
7645
8007
|
function readPackageJson(root) {
|
|
7646
8008
|
try {
|
|
7647
|
-
return JSON.parse(readFileSync(
|
|
8009
|
+
return JSON.parse(readFileSync(path62.join(root, "package.json"), "utf8"));
|
|
7648
8010
|
} catch {
|
|
7649
8011
|
return null;
|
|
7650
8012
|
}
|
|
@@ -7701,7 +8063,7 @@ function spreadLine(platform, local = "genesis") {
|
|
|
7701
8063
|
}
|
|
7702
8064
|
function addGenesisLint(text, platform, file = "eslint.config.js") {
|
|
7703
8065
|
const code = maskCode(text);
|
|
7704
|
-
const ext =
|
|
8066
|
+
const ext = path62.extname(file);
|
|
7705
8067
|
const exportsCjs = [...code.matchAll(/(?:^|[\n;])\s*module\.exports\s*=\s*/g)];
|
|
7706
8068
|
const exportsEsm = [...code.matchAll(/(?:^|[\n;])\s*export\s+default\s+/g)];
|
|
7707
8069
|
const kind = ext === ".cjs" || ext === ".cts" ? "cjs" : ext === ".mjs" || ext === ".mts" ? "esm" : exportsCjs.length && !exportsEsm.length ? "cjs" : "esm";
|
|
@@ -7873,7 +8235,7 @@ var init_codemods = __esm({
|
|
|
7873
8235
|
let readsId = false;
|
|
7874
8236
|
let augmented = false;
|
|
7875
8237
|
for (const rel of appScripts(root)) {
|
|
7876
|
-
const abs =
|
|
8238
|
+
const abs = path62.join(root, rel);
|
|
7877
8239
|
const text = readFileSync(abs, "utf8");
|
|
7878
8240
|
if (augmentsResourceScope(text)) augmented = true;
|
|
7879
8241
|
if (!IMPORTS_GENESIS.test(text)) continue;
|
|
@@ -7901,7 +8263,7 @@ var init_codemods = __esm({
|
|
|
7901
8263
|
const changed = [];
|
|
7902
8264
|
const pkg = readPackageJson(root);
|
|
7903
8265
|
const platform = appPlatform(pkg);
|
|
7904
|
-
const abs =
|
|
8266
|
+
const abs = path62.join(root, file);
|
|
7905
8267
|
const text = readFileSync(abs, "utf8");
|
|
7906
8268
|
if (!usesGenesisLint(text)) {
|
|
7907
8269
|
const result = addGenesisLint(text, platform, file);
|
|
@@ -7917,7 +8279,7 @@ ${manualLines(result.kind, platform).map((l) => ` ${l}`).join("\n")}`);
|
|
|
7917
8279
|
}
|
|
7918
8280
|
}
|
|
7919
8281
|
if (platform === "native" && pkg && !hasTestingLibrary(pkg)) {
|
|
7920
|
-
const pkgFile =
|
|
8282
|
+
const pkgFile = path62.join(root, "package.json");
|
|
7921
8283
|
const raw = readFileSync(pkgFile, "utf8");
|
|
7922
8284
|
const indent = /^[ \t]+(?=")/m.exec(raw)?.[0] ?? " ";
|
|
7923
8285
|
const json = JSON.parse(raw);
|
|
@@ -7940,7 +8302,7 @@ ${manualLines(result.kind, platform).map((l) => ` ${l}`).join("\n")}`);
|
|
|
7940
8302
|
run({ root, dryRun }) {
|
|
7941
8303
|
const changed = [];
|
|
7942
8304
|
for (const rel of appScripts(root)) {
|
|
7943
|
-
const abs =
|
|
8305
|
+
const abs = path62.join(root, rel);
|
|
7944
8306
|
const text = readFileSync(abs, "utf8");
|
|
7945
8307
|
if (!text.includes("NativeComposerBar")) continue;
|
|
7946
8308
|
const next = rewriteComposerBarEmpty(text);
|
|
@@ -8030,7 +8392,7 @@ function checkTreeViews(ctx) {
|
|
|
8030
8392
|
function moduleFiles(ctx) {
|
|
8031
8393
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
8032
8394
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
8033
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
8395
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path62.join(ctx.root, rel), "utf8"), true) }));
|
|
8034
8396
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
8035
8397
|
}
|
|
8036
8398
|
function checkStudioServerImports(ctx) {
|
|
@@ -8060,7 +8422,7 @@ function checkStudioServerImports(ctx) {
|
|
|
8060
8422
|
}
|
|
8061
8423
|
function checkRemovedScopeNames(ctx) {
|
|
8062
8424
|
let augmentedMemo;
|
|
8063
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
8425
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path62.join(ctx.root, rel), "utf8")));
|
|
8064
8426
|
for (const file of ctx.files) {
|
|
8065
8427
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
8066
8428
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -8181,6 +8543,116 @@ var init_custom_views = __esm({
|
|
|
8181
8543
|
VARIABLE = /var\(\s*(--[A-Za-z0-9_-]+)/g;
|
|
8182
8544
|
}
|
|
8183
8545
|
});
|
|
8546
|
+
function clientLayer(root, files) {
|
|
8547
|
+
let dir = DEFAULT_CLIENT_DIR;
|
|
8548
|
+
try {
|
|
8549
|
+
dir = readGenesisConfig(root)?.client?.dir ?? DEFAULT_CLIENT_DIR;
|
|
8550
|
+
} catch {
|
|
8551
|
+
}
|
|
8552
|
+
const inside3 = `${dir}/`;
|
|
8553
|
+
const present = files.some((f) => f.path.startsWith(inside3) && /(^|\/)resource-view\.(t|j)sx?$/.test(f.path)) || existsSync(path62.join(root, dir, "resource-view.tsx"));
|
|
8554
|
+
const recordWrapper = files.some((f) => f.path.startsWith(inside3) && /(^|\/)record-view\.(t|j)sx?$/.test(f.path)) || existsSync(path62.join(root, dir, "record-view.tsx"));
|
|
8555
|
+
return { dir, present, recordWrapper };
|
|
8556
|
+
}
|
|
8557
|
+
function genesisImports(code, uiPackage) {
|
|
8558
|
+
const out = /* @__PURE__ */ new Map();
|
|
8559
|
+
const escaped = uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
8560
|
+
const re = new RegExp(`import\\s*(?:type\\s+)?\\{([^}]*)\\}\\s*from\\s*["']${escaped}(?:/data)?["']`, "g");
|
|
8561
|
+
for (const m of code.matchAll(re)) {
|
|
8562
|
+
if (/^\s*type\s/.test(m[0].slice(6))) continue;
|
|
8563
|
+
for (const part of m[1].split(",")) {
|
|
8564
|
+
const spec = part.trim().replace(/^type\s+/, "");
|
|
8565
|
+
if (!spec || part.trim().startsWith("type ")) continue;
|
|
8566
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
8567
|
+
if (imported === "ResourceView" || imported === "RecordView") out.set(local ?? imported, imported);
|
|
8568
|
+
}
|
|
8569
|
+
}
|
|
8570
|
+
return out;
|
|
8571
|
+
}
|
|
8572
|
+
function checkClientLayer(ctx) {
|
|
8573
|
+
const layer = clientLayer(ctx.root, ctx.files);
|
|
8574
|
+
const inside3 = `${layer.dir}/`;
|
|
8575
|
+
if (layer.present) {
|
|
8576
|
+
for (const file of ctx.files) {
|
|
8577
|
+
if (!JSX_EXTS5.has(file.ext) || file.path.startsWith(inside3)) continue;
|
|
8578
|
+
const imported = genesisImports(file.code, ctx.genesis.uiPackage);
|
|
8579
|
+
for (const [local, name] of imported) {
|
|
8580
|
+
if (name === "RecordView" && !layer.recordWrapper) continue;
|
|
8581
|
+
const at = file.code.search(new RegExp(`<${local}\\b`));
|
|
8582
|
+
if (at < 0) continue;
|
|
8583
|
+
ctx.report({
|
|
8584
|
+
rule: "client/layer",
|
|
8585
|
+
level: "warn",
|
|
8586
|
+
file: file.path,
|
|
8587
|
+
line: lineAt(file.code, at),
|
|
8588
|
+
subject: name,
|
|
8589
|
+
message: `renders Genesis's <${name}> directly; the app has a client layer (${layer.dir}), so render its ${name === "ResourceView" ? "ResourceView from resource-view.tsx" : "RecordView from record-view.tsx"}, and its defaults reach this screen too (docs/adr/0020-client-layer.md)`
|
|
8590
|
+
});
|
|
8591
|
+
}
|
|
8592
|
+
}
|
|
8593
|
+
}
|
|
8594
|
+
if (!layer.present) return;
|
|
8595
|
+
const seen = /* @__PURE__ */ new Map();
|
|
8596
|
+
for (const file of ctx.files) {
|
|
8597
|
+
if (!SCRIPT_EXTS6.has(file.ext) || SHOWN_OR_TRIED.test(file.path)) continue;
|
|
8598
|
+
const imports = importedNames(file.path, file.code);
|
|
8599
|
+
for (const m of file.code.matchAll(/\bdefineView\s*(?:<[^>]*>)?\s*\(\s*([A-Za-z_$][\w$]*)((?:\s*(?:\.\s*[A-Za-z_$][\w$]*|\[\s*["'`][^"'`]+["'`]\s*\]))*)\s*[,)]/g)) {
|
|
8600
|
+
const base = m[1];
|
|
8601
|
+
const access2 = m[2].replace(/\s+/g, "").replace(/'|`/g, '"');
|
|
8602
|
+
const imported = imports.get(base);
|
|
8603
|
+
if (!imported && !declaredAtTop(file.code, base)) continue;
|
|
8604
|
+
if (boundAsParameter(file.code, base, { jsx: file.ext !== ".ts" && file.ext !== ".mts" })) continue;
|
|
8605
|
+
const identity = `${imported ?? `${file.path}#${base}`}${access2}`;
|
|
8606
|
+
const shown = `${base}${access2}`;
|
|
8607
|
+
const line = lineAt(file.code, m.index ?? 0);
|
|
8608
|
+
const first = seen.get(identity);
|
|
8609
|
+
if (!first) {
|
|
8610
|
+
seen.set(identity, { file: file.path, line });
|
|
8611
|
+
continue;
|
|
8612
|
+
}
|
|
8613
|
+
ctx.report({
|
|
8614
|
+
rule: "client/one-view-per-resource",
|
|
8615
|
+
level: "warn",
|
|
8616
|
+
file: file.path,
|
|
8617
|
+
line,
|
|
8618
|
+
subject: shown,
|
|
8619
|
+
message: `defines a second view over ${shown} (the first is in ${first.file}:${first.line}); keep one view per resource and narrow it on the screen (preset, filter, columns), so its rules can't drift (docs/adr/0020-client-layer.md)`
|
|
8620
|
+
});
|
|
8621
|
+
}
|
|
8622
|
+
}
|
|
8623
|
+
}
|
|
8624
|
+
function declaredAtTop(code, name) {
|
|
8625
|
+
const escaped = escapeRegExp(name);
|
|
8626
|
+
return new RegExp(`^(?:export\\s+)?(?:const|let|var)\\s+${escaped}\\b`, "m").test(code);
|
|
8627
|
+
}
|
|
8628
|
+
function importedNames(filePath, code) {
|
|
8629
|
+
const out = /* @__PURE__ */ new Map();
|
|
8630
|
+
const dir = path62.posix.dirname(filePath);
|
|
8631
|
+
const where2 = (spec) => spec.startsWith(".") ? path62.posix.normalize(path62.posix.join(dir, spec)).replace(/\.(t|j)sx?$/, "").replace(/\/index$/, "") : spec;
|
|
8632
|
+
for (const m of code.matchAll(/import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
8633
|
+
for (const part of m[1].split(",")) {
|
|
8634
|
+
const spec = part.trim().replace(/^type\s+/, "");
|
|
8635
|
+
if (!spec) continue;
|
|
8636
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
8637
|
+
out.set(local ?? imported, `${where2(m[2])}#${imported}`);
|
|
8638
|
+
}
|
|
8639
|
+
}
|
|
8640
|
+
for (const m of code.matchAll(/import\s+(?:\*\s+as\s+)?([A-Za-z_$][\w$]*)\s+from\s*["']([^"']+)["']/g)) out.set(m[1], `${where2(m[2])}#*`);
|
|
8641
|
+
return out;
|
|
8642
|
+
}
|
|
8643
|
+
var JSX_EXTS5, SCRIPT_EXTS6, DEFAULT_CLIENT_DIR, SHOWN_OR_TRIED;
|
|
8644
|
+
var init_client_layer = __esm({
|
|
8645
|
+
"src/doctor/client-layer.ts"() {
|
|
8646
|
+
init_config();
|
|
8647
|
+
init_scan();
|
|
8648
|
+
init_js_scan();
|
|
8649
|
+
init_regexp();
|
|
8650
|
+
JSX_EXTS5 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
8651
|
+
SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"]);
|
|
8652
|
+
DEFAULT_CLIENT_DIR = "src/client";
|
|
8653
|
+
SHOWN_OR_TRIED = /(\.stories\.|\.test\.|\.spec\.|(^|\/)__tests__\/)/;
|
|
8654
|
+
}
|
|
8655
|
+
});
|
|
8184
8656
|
function specifierParts(spec) {
|
|
8185
8657
|
return spec.trim().replace(/^type\s+/, "").split(/\s+as\s+/).map((part) => part.trim());
|
|
8186
8658
|
}
|
|
@@ -8223,16 +8695,16 @@ function genesisNamedImports(source) {
|
|
|
8223
8695
|
}
|
|
8224
8696
|
function declarationFiles(dir, out = []) {
|
|
8225
8697
|
for (const name of readdirSync(dir)) {
|
|
8226
|
-
const full =
|
|
8698
|
+
const full = path62.join(dir, name);
|
|
8227
8699
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
8228
8700
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
8229
8701
|
}
|
|
8230
8702
|
return out;
|
|
8231
8703
|
}
|
|
8232
8704
|
function readPackageTags(dir) {
|
|
8233
|
-
const pkg = JSON.parse(readFileSync(
|
|
8705
|
+
const pkg = JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8"));
|
|
8234
8706
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
8235
|
-
const dist =
|
|
8707
|
+
const dist = path62.join(dir, "dist");
|
|
8236
8708
|
if (!existsSync(dist)) return tags;
|
|
8237
8709
|
for (const file of declarationFiles(dist)) {
|
|
8238
8710
|
const text = readFileSync(file, "utf8");
|
|
@@ -8250,7 +8722,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
8250
8722
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
8251
8723
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
8252
8724
|
const types = typeof target === "object" && target ? target.types : null;
|
|
8253
|
-
return typeof types === "string" ?
|
|
8725
|
+
return typeof types === "string" ? path62.join(tags.dir, types) : null;
|
|
8254
8726
|
}
|
|
8255
8727
|
function tagFor(tags, entry, name) {
|
|
8256
8728
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -8268,7 +8740,7 @@ function checkStabilityImports(ctx) {
|
|
|
8268
8740
|
return cache2.get(pkg);
|
|
8269
8741
|
};
|
|
8270
8742
|
for (const file of ctx.files) {
|
|
8271
|
-
if (!
|
|
8743
|
+
if (!SCRIPT_EXTS7.has(file.ext)) continue;
|
|
8272
8744
|
for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
|
|
8273
8745
|
const tags = tagsOf(pkg);
|
|
8274
8746
|
if (!tags) continue;
|
|
@@ -8284,12 +8756,12 @@ function checkStabilityImports(ctx) {
|
|
|
8284
8756
|
}
|
|
8285
8757
|
}
|
|
8286
8758
|
}
|
|
8287
|
-
var
|
|
8759
|
+
var SCRIPT_EXTS7, DECLARATION, REEXPORT;
|
|
8288
8760
|
var init_stability = __esm({
|
|
8289
8761
|
"src/doctor/stability.ts"() {
|
|
8290
8762
|
init_genesis();
|
|
8291
8763
|
init_trail();
|
|
8292
|
-
|
|
8764
|
+
SCRIPT_EXTS7 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
8293
8765
|
DECLARATION = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\n(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/g;
|
|
8294
8766
|
REEXPORT = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\nexport\s+(?:type\s+)?\{([^}]*)\}/g;
|
|
8295
8767
|
}
|
|
@@ -8335,7 +8807,7 @@ function showAt(dir, rev, file) {
|
|
|
8335
8807
|
function configAtBase(root, base, explicitFile) {
|
|
8336
8808
|
const mergeBase = mergeBaseOf2(root, base);
|
|
8337
8809
|
if (!mergeBase) return null;
|
|
8338
|
-
const candidates = explicitFile ? [{ dir:
|
|
8810
|
+
const candidates = explicitFile ? [{ dir: path62.dirname(explicitFile), file: path62.basename(explicitFile), explicit: true }] : [
|
|
8339
8811
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
8340
8812
|
{ dir: root, file: "package.json", explicit: false }
|
|
8341
8813
|
];
|
|
@@ -8449,7 +8921,7 @@ function snapshotAtBase(root, base, files, changed, originOf = (f) => f) {
|
|
|
8449
8921
|
seen.add(origin);
|
|
8450
8922
|
const text = showAt(root, mergeBase, origin);
|
|
8451
8923
|
if (text === null) return null;
|
|
8452
|
-
if (text !== void 0) out.push(withText({ ...f, path: origin, absolutePath:
|
|
8924
|
+
if (text !== void 0) out.push(withText({ ...f, path: origin, absolutePath: path62.join(root, origin) }, text));
|
|
8453
8925
|
}
|
|
8454
8926
|
const cache2 = /* @__PURE__ */ new Map();
|
|
8455
8927
|
return {
|
|
@@ -8607,7 +9079,7 @@ function pathTaken(file) {
|
|
|
8607
9079
|
return true;
|
|
8608
9080
|
} catch {
|
|
8609
9081
|
try {
|
|
8610
|
-
return readdirSync(
|
|
9082
|
+
return readdirSync(path62.dirname(file)).some((n) => n.toLowerCase() === path62.basename(file).toLowerCase());
|
|
8611
9083
|
} catch {
|
|
8612
9084
|
return false;
|
|
8613
9085
|
}
|
|
@@ -8679,13 +9151,13 @@ function stableGuidePath(root, p) {
|
|
|
8679
9151
|
};
|
|
8680
9152
|
const want = real2(p.dir);
|
|
8681
9153
|
for (let dir = root, level = 0; level <= GUIDE_SEARCH_LEVELS; level++) {
|
|
8682
|
-
const found =
|
|
9154
|
+
const found = path62.join(dir, "node_modules", p.name);
|
|
8683
9155
|
if (existsSync(found)) {
|
|
8684
|
-
const file =
|
|
9156
|
+
const file = path62.join(found, "SKILL.md");
|
|
8685
9157
|
return want !== null && real2(found) === want && existsSync(file) ? file : null;
|
|
8686
9158
|
}
|
|
8687
|
-
if (existsSync(
|
|
8688
|
-
const up =
|
|
9159
|
+
if (existsSync(path62.join(dir, ".git")) || existsSync(path62.join(dir, "pnpm-workspace.yaml"))) return null;
|
|
9160
|
+
const up = path62.dirname(dir);
|
|
8689
9161
|
if (up === dir) return null;
|
|
8690
9162
|
dir = up;
|
|
8691
9163
|
}
|
|
@@ -8694,18 +9166,18 @@ function stableGuidePath(root, p) {
|
|
|
8694
9166
|
function packageGuides(root, packages) {
|
|
8695
9167
|
const guides = [];
|
|
8696
9168
|
for (const p of packages) {
|
|
8697
|
-
const stable = p.local ?
|
|
8698
|
-
const text = stable === null ? null :
|
|
9169
|
+
const stable = p.local ? path62.join(p.dir, "SKILL.md") : stableGuidePath(root, p);
|
|
9170
|
+
const text = stable === null ? null : read2(stable);
|
|
8699
9171
|
if (stable === null || text === null) continue;
|
|
8700
9172
|
const description = skillDescription(text);
|
|
8701
9173
|
const at = description.indexOf("Load before");
|
|
8702
|
-
guides.push({ package: p.name, path:
|
|
9174
|
+
guides.push({ package: p.name, path: path62.relative(root, stable).split(path62.sep).join("/"), when: at >= 0 ? description.slice(at) : description });
|
|
8703
9175
|
}
|
|
8704
9176
|
return guides.sort((a, b) => a.package.localeCompare(b.package));
|
|
8705
9177
|
}
|
|
8706
9178
|
function unlistedGuides(root, packages) {
|
|
8707
9179
|
const listed = new Set(packageGuides(root, packages).map((g) => g.package));
|
|
8708
|
-
return packages.filter((p) => !p.local && !listed.has(p.name) && existsSync(
|
|
9180
|
+
return packages.filter((p) => !p.local && !listed.has(p.name) && existsSync(path62.join(p.dir, "SKILL.md"))).map((p) => p.name).sort();
|
|
8709
9181
|
}
|
|
8710
9182
|
function guidesSection(guides) {
|
|
8711
9183
|
if (!guides.length) return [];
|
|
@@ -8786,13 +9258,13 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
8786
9258
|
const rows = primitivesCatalog(packages);
|
|
8787
9259
|
const guides = packageGuides(root, packages);
|
|
8788
9260
|
const changed = [];
|
|
8789
|
-
const agents =
|
|
8790
|
-
const before =
|
|
9261
|
+
const agents = path62.join(root, agentsFile);
|
|
9262
|
+
const before = read2(agents);
|
|
8791
9263
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows, guides));
|
|
8792
|
-
const skill =
|
|
9264
|
+
const skill = path62.join(root, SKILL_PATH);
|
|
8793
9265
|
const skillText = renderSkill(rows, guides);
|
|
8794
|
-
if (
|
|
8795
|
-
mkdirSync(
|
|
9266
|
+
if (read2(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
9267
|
+
mkdirSync(path62.dirname(skill), { recursive: true });
|
|
8796
9268
|
writeFileSync(skill, skillText);
|
|
8797
9269
|
changed.push(SKILL_PATH);
|
|
8798
9270
|
}
|
|
@@ -8800,7 +9272,7 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
8800
9272
|
writeFileSync(agents, after);
|
|
8801
9273
|
changed.push(agentsFile);
|
|
8802
9274
|
}
|
|
8803
|
-
const claude =
|
|
9275
|
+
const claude = path62.join(root, "CLAUDE.md");
|
|
8804
9276
|
if (agentsFile === "AGENTS.md" && !pathTaken(claude)) {
|
|
8805
9277
|
writeFileSync(claude, CLAUDE_IMPORT);
|
|
8806
9278
|
changed.push("CLAUDE.md");
|
|
@@ -8808,7 +9280,7 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
8808
9280
|
return changed;
|
|
8809
9281
|
}
|
|
8810
9282
|
function claudeState(root) {
|
|
8811
|
-
const file =
|
|
9283
|
+
const file = path62.join(root, "CLAUDE.md");
|
|
8812
9284
|
let names = [];
|
|
8813
9285
|
try {
|
|
8814
9286
|
names = readdirSync(root);
|
|
@@ -8823,7 +9295,7 @@ function claudeState(root) {
|
|
|
8823
9295
|
}
|
|
8824
9296
|
if (/^@AGENTS\.md\b/m.test(text)) return "ok";
|
|
8825
9297
|
try {
|
|
8826
|
-
if (realpathSync(file) === realpathSync(
|
|
9298
|
+
if (realpathSync(file) === realpathSync(path62.join(root, "AGENTS.md"))) return "ok";
|
|
8827
9299
|
} catch {
|
|
8828
9300
|
}
|
|
8829
9301
|
return "no-import";
|
|
@@ -8831,8 +9303,8 @@ function claudeState(root) {
|
|
|
8831
9303
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
8832
9304
|
const rows = primitivesCatalog(packages);
|
|
8833
9305
|
const guides = packageGuides(root, packages);
|
|
8834
|
-
const skill =
|
|
8835
|
-
const block = currentAgentsBlock(
|
|
9306
|
+
const skill = read2(path62.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
9307
|
+
const block = currentAgentsBlock(read2(path62.join(root, agentsFile)));
|
|
8836
9308
|
return {
|
|
8837
9309
|
skill: skill === null ? "missing" : skill === renderSkill(rows, guides) ? "ok" : "stale",
|
|
8838
9310
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows, guides) ? "ok" : "stale",
|
|
@@ -8869,12 +9341,12 @@ function checkAgentGuide(ctx) {
|
|
|
8869
9341
|
ctx.report({ rule: "agent-guide-stale", level: "info", file: "AGENTS.md", message: `leaves out the guide of ${unlisted.join(", ")}: it's only inside pnpm's store, under a path that changes with unrelated bumps. Add the package as a direct dependency to list its guide.` });
|
|
8870
9342
|
}
|
|
8871
9343
|
}
|
|
8872
|
-
var GENESIS_DOCS,
|
|
9344
|
+
var GENESIS_DOCS, read2, CLAUDE_IMPORT, CORE, cell, importCell, SKILL_PATH, AGENTS_START, AGENTS_END, RULES, GUIDE_SEARCH_LEVELS, BLOCKED_FIX;
|
|
8873
9345
|
var init_primitives = __esm({
|
|
8874
9346
|
"src/doctor/primitives.ts"() {
|
|
8875
9347
|
init_package_rules();
|
|
8876
9348
|
GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
|
|
8877
|
-
|
|
9349
|
+
read2 = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
8878
9350
|
CLAUDE_IMPORT = "@AGENTS.md\n";
|
|
8879
9351
|
CORE = [
|
|
8880
9352
|
{
|
|
@@ -8979,7 +9451,7 @@ function mergeAgentHooks(settings2) {
|
|
|
8979
9451
|
return out;
|
|
8980
9452
|
}
|
|
8981
9453
|
function writeAgentHooks(root) {
|
|
8982
|
-
const file =
|
|
9454
|
+
const file = path62.join(root, SETTINGS_PATH);
|
|
8983
9455
|
const before = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
8984
9456
|
let current = {};
|
|
8985
9457
|
if (before !== null) {
|
|
@@ -8993,14 +9465,14 @@ function writeAgentHooks(root) {
|
|
|
8993
9465
|
const after = `${JSON.stringify(mergeAgentHooks(current), null, 2)}
|
|
8994
9466
|
`;
|
|
8995
9467
|
if (before !== null && JSON.stringify(JSON.parse(before)) === JSON.stringify(JSON.parse(after))) return [];
|
|
8996
|
-
mkdirSync(
|
|
9468
|
+
mkdirSync(path62.dirname(file), { recursive: true });
|
|
8997
9469
|
writeFileSync(file, after);
|
|
8998
9470
|
return [SETTINGS_PATH];
|
|
8999
9471
|
}
|
|
9000
9472
|
function agentHooksState(root) {
|
|
9001
9473
|
let settings2;
|
|
9002
9474
|
try {
|
|
9003
|
-
settings2 = JSON.parse(readFileSync(
|
|
9475
|
+
settings2 = JSON.parse(readFileSync(path62.join(root, SETTINGS_PATH), "utf8"));
|
|
9004
9476
|
} catch {
|
|
9005
9477
|
return "none";
|
|
9006
9478
|
}
|
|
@@ -9043,7 +9515,7 @@ function unprefixedTemplatePaths(root, rel, mine, template, folder) {
|
|
|
9043
9515
|
const lines = new Set(mine.split("\n"));
|
|
9044
9516
|
const lockfileElsewhere = (line) => {
|
|
9045
9517
|
const name = PATH_ITEM.exec(line)?.[3];
|
|
9046
|
-
return name !== void 0 && LOCKFILES2.has(name) && !existsSync(
|
|
9518
|
+
return name !== void 0 && LOCKFILES2.has(name) && !existsSync(path62.join(root, name));
|
|
9047
9519
|
};
|
|
9048
9520
|
return template.split("\n").filter((line, i) => line !== rendered[i] && !/^\s*#/.test(line) && lines.has(line) && !lockfileElsewhere(line)).map((line) => line.trim());
|
|
9049
9521
|
}
|
|
@@ -9116,9 +9588,9 @@ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
|
9116
9588
|
return `${key2} doesn't match its source ${source}`;
|
|
9117
9589
|
}
|
|
9118
9590
|
function mergeThreeWay(mine, base, theirs) {
|
|
9119
|
-
const dir = mkdtempSync(
|
|
9591
|
+
const dir = mkdtempSync(path62.join(tmpdir(), "genesis-merge-"));
|
|
9120
9592
|
try {
|
|
9121
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
9593
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path62.join(dir, n));
|
|
9122
9594
|
writeFileSync(m, mine);
|
|
9123
9595
|
writeFileSync(b, base);
|
|
9124
9596
|
writeFileSync(t, theirs);
|
|
@@ -9382,7 +9854,7 @@ function removeBunLockEntries(text, remove) {
|
|
|
9382
9854
|
return out + text.slice(at);
|
|
9383
9855
|
}
|
|
9384
9856
|
function readBunLock(dir) {
|
|
9385
|
-
const file =
|
|
9857
|
+
const file = path62.join(dir, BUN_LOCK);
|
|
9386
9858
|
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
9387
9859
|
}
|
|
9388
9860
|
var BUN_LOCK, GENESIS_TAIL, PLAIN_VERSION;
|
|
@@ -9399,7 +9871,7 @@ function checkBunLock(ctx) {
|
|
|
9399
9871
|
if (found?.pm !== "bun") return;
|
|
9400
9872
|
const text = readBunLock(found.dir);
|
|
9401
9873
|
if (text === null) return;
|
|
9402
|
-
const file =
|
|
9874
|
+
const file = path62.relative(ctx.root, path62.join(found.dir, BUN_LOCK)).split(path62.sep).join("/");
|
|
9403
9875
|
let stale;
|
|
9404
9876
|
try {
|
|
9405
9877
|
stale = staleNestedEntries(text);
|
|
@@ -9418,7 +9890,7 @@ function checkBunLock(ctx) {
|
|
|
9418
9890
|
}
|
|
9419
9891
|
async function checkLockFiles(ctx) {
|
|
9420
9892
|
checkBunLock(ctx);
|
|
9421
|
-
if (!existsSync(
|
|
9893
|
+
if (!existsSync(path62.join(ctx.root, LOCK_FILE))) return;
|
|
9422
9894
|
let lock;
|
|
9423
9895
|
try {
|
|
9424
9896
|
lock = readLock(ctx.root);
|
|
@@ -9540,7 +10012,7 @@ function checkDatabaseHome(ctx) {
|
|
|
9540
10012
|
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)`
|
|
9541
10013
|
});
|
|
9542
10014
|
}
|
|
9543
|
-
if (existsSync(
|
|
10015
|
+
if (existsSync(path62.join(ctx.root, "supabase"))) {
|
|
9544
10016
|
ctx.report({
|
|
9545
10017
|
rule: "database-elsewhere",
|
|
9546
10018
|
level: "warn",
|
|
@@ -9563,7 +10035,7 @@ function checkEslintConfig(ctx) {
|
|
|
9563
10035
|
if (!file) return;
|
|
9564
10036
|
let text;
|
|
9565
10037
|
try {
|
|
9566
|
-
text = readFileSync(
|
|
10038
|
+
text = readFileSync(path62.join(ctx.root, file), "utf8");
|
|
9567
10039
|
} catch {
|
|
9568
10040
|
return;
|
|
9569
10041
|
}
|
|
@@ -9641,7 +10113,7 @@ function validateFigmaConfig(raw, source = "genesis.config.json") {
|
|
|
9641
10113
|
return { file: obj.file, pages: out, proposalsPage: obj.proposalsPage ?? "Proposals" };
|
|
9642
10114
|
}
|
|
9643
10115
|
function readFigmaConfig(root) {
|
|
9644
|
-
const file =
|
|
10116
|
+
const file = path62.join(root, "genesis.config.json");
|
|
9645
10117
|
if (!existsSync(file)) return null;
|
|
9646
10118
|
let raw;
|
|
9647
10119
|
try {
|
|
@@ -9655,7 +10127,7 @@ function walk2(dir, out = []) {
|
|
|
9655
10127
|
if (!existsSync(dir)) return out;
|
|
9656
10128
|
for (const name of readdirSync(dir).sort()) {
|
|
9657
10129
|
if (name === "node_modules" || name.startsWith(".")) continue;
|
|
9658
|
-
const full =
|
|
10130
|
+
const full = path62.join(dir, name);
|
|
9659
10131
|
if (statSync(full).isDirectory()) walk2(full, out);
|
|
9660
10132
|
else if (CODE.test(name) && !/\.(?:test|spec|d)\.[jt]sx?$/.test(name)) out.push(full);
|
|
9661
10133
|
}
|
|
@@ -9684,27 +10156,27 @@ function tanstackSegments(stem) {
|
|
|
9684
10156
|
return out;
|
|
9685
10157
|
}
|
|
9686
10158
|
function expoRoot(root) {
|
|
9687
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
10159
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path62.join(root, dir))) return dir;
|
|
9688
10160
|
return null;
|
|
9689
10161
|
}
|
|
9690
10162
|
function appRoutes(root) {
|
|
9691
10163
|
const out = [];
|
|
9692
|
-
const rel = (f) =>
|
|
10164
|
+
const rel = (f) => path62.relative(root, f).split(path62.sep).join("/");
|
|
9693
10165
|
const expo = expoRoot(root);
|
|
9694
10166
|
if (expo) {
|
|
9695
|
-
for (const f of walk2(
|
|
9696
|
-
const parts =
|
|
10167
|
+
for (const f of walk2(path62.join(root, expo))) {
|
|
10168
|
+
const parts = path62.relative(path62.join(root, expo), f).split(path62.sep);
|
|
9697
10169
|
const stem = parts.pop().replace(CODE, "");
|
|
9698
10170
|
if (stem === "_layout" || stem.startsWith("+")) continue;
|
|
9699
10171
|
if (stem !== "index") parts.push(stem);
|
|
9700
10172
|
out.push(withId({ route: parts.join("/") || "index", platform: "native", file: rel(f) }, f));
|
|
9701
10173
|
}
|
|
9702
10174
|
}
|
|
9703
|
-
const tanstack =
|
|
10175
|
+
const tanstack = path62.join(root, "src/routes");
|
|
9704
10176
|
if (existsSync(tanstack)) {
|
|
9705
10177
|
const seen = /* @__PURE__ */ new Set();
|
|
9706
10178
|
for (const f of walk2(tanstack)) {
|
|
9707
|
-
const parts =
|
|
10179
|
+
const parts = path62.relative(tanstack, f).split(path62.sep);
|
|
9708
10180
|
const stem = parts.pop().replace(CODE, "").replace(/\.lazy$/, "");
|
|
9709
10181
|
if (stem === "__root" || stem === "route" || stem.startsWith("-") || parts.some((p) => p.startsWith("-"))) continue;
|
|
9710
10182
|
const segs = [...parts.flatMap(tanstackSegments), ...tanstackSegments(stem)];
|
|
@@ -9769,12 +10241,12 @@ function navTargets(code, file) {
|
|
|
9769
10241
|
return out.sort((a, b) => a.line - b.line);
|
|
9770
10242
|
}
|
|
9771
10243
|
function appNavTargets(root) {
|
|
9772
|
-
const files = [.../* @__PURE__ */ new Set([...walk2(
|
|
9773
|
-
return files.flatMap((f) => navTargets(readFileSync(f, "utf8"),
|
|
10244
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path62.join(root, "src")), ...walk2(path62.join(root, "app"))])];
|
|
10245
|
+
return files.flatMap((f) => navTargets(readFileSync(f, "utf8"), path62.relative(root, f).split(path62.sep).join("/")));
|
|
9774
10246
|
}
|
|
9775
10247
|
function appDynamicNavTargets(root) {
|
|
9776
|
-
const files = [.../* @__PURE__ */ new Set([...walk2(
|
|
9777
|
-
return files.flatMap((f) => dynamicNavTargets(readFileSync(f, "utf8"),
|
|
10248
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path62.join(root, "src")), ...walk2(path62.join(root, "app"))])];
|
|
10249
|
+
return files.flatMap((f) => dynamicNavTargets(readFileSync(f, "utf8"), path62.relative(root, f).split(path62.sep).join("/")));
|
|
9778
10250
|
}
|
|
9779
10251
|
function splitName(name) {
|
|
9780
10252
|
const i = name.indexOf(" \xB7 ");
|
|
@@ -9897,7 +10369,7 @@ function compare(config, routes, targets, figma, dynamicTargets = []) {
|
|
|
9897
10369
|
}
|
|
9898
10370
|
async function checkFigmaRoutes(options) {
|
|
9899
10371
|
const config = options.config ?? readFigmaConfig(options.root);
|
|
9900
|
-
if (!config) throw new FigmaConfigError(`no "figma" block in ${
|
|
10372
|
+
if (!config) throw new FigmaConfigError(`no "figma" block in ${path62.join(options.root, "genesis.config.json")}`);
|
|
9901
10373
|
const token = options.token ?? process.env.FIGMA_ACCESS_TOKEN;
|
|
9902
10374
|
if (!token) throw new FigmaConfigError("FIGMA_ACCESS_TOKEN isn't set");
|
|
9903
10375
|
const figma = await readFigma(config, token, options.fetch);
|
|
@@ -10054,7 +10526,7 @@ __export(doctor_exports, {
|
|
|
10054
10526
|
writeAgentHooks: () => writeAgentHooks
|
|
10055
10527
|
});
|
|
10056
10528
|
async function runDoctor(options = {}) {
|
|
10057
|
-
const root =
|
|
10529
|
+
const root = path62.resolve(options.root ?? process.cwd());
|
|
10058
10530
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
10059
10531
|
const config = loaded.config;
|
|
10060
10532
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -10109,7 +10581,7 @@ async function runDoctor(options = {}) {
|
|
|
10109
10581
|
const configured = applyConfig(raw, config, packageIds);
|
|
10110
10582
|
let findings = applyExtensions(configured, extensionCtx);
|
|
10111
10583
|
if (options.base && changed) {
|
|
10112
|
-
const isAppPath = (f) => existsSync(
|
|
10584
|
+
const isAppPath = (f) => existsSync(path62.join(root, f));
|
|
10113
10585
|
const origins = options.changedFiles ? /* @__PURE__ */ new Map() : originsSince(root, options.base);
|
|
10114
10586
|
const originOf = (f) => origins.get(f) ?? f;
|
|
10115
10587
|
const dueRules = new Set(findings.filter((f) => f.level !== "info" && isRatcheted(f.rule, config, newOnly) && isAppPath(f.file) && touched(f.file, changed)).map((f) => f.rule));
|
|
@@ -10187,6 +10659,7 @@ function builtinChecks(config, options = {}) {
|
|
|
10187
10659
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
10188
10660
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
10189
10661
|
{ name: "app-parts", check: checkAppParts },
|
|
10662
|
+
{ name: "client-layer", check: checkClientLayer },
|
|
10190
10663
|
{ name: "stability-imports", check: checkStabilityImports },
|
|
10191
10664
|
{ name: "agent-guide", check: (ctx) => {
|
|
10192
10665
|
checkAgentGuide(ctx);
|
|
@@ -10311,6 +10784,7 @@ var init_doctor = __esm({
|
|
|
10311
10784
|
init_dates();
|
|
10312
10785
|
init_api_usage();
|
|
10313
10786
|
init_custom_views();
|
|
10787
|
+
init_client_layer();
|
|
10314
10788
|
init_stability();
|
|
10315
10789
|
init_package_rules();
|
|
10316
10790
|
init_ratchet();
|
|
@@ -10354,12 +10828,12 @@ __export(agent_rules_exports, {
|
|
|
10354
10828
|
runsOnPullRequestsInto: () => runsOnPullRequestsInto
|
|
10355
10829
|
});
|
|
10356
10830
|
function changesetBumps(root) {
|
|
10357
|
-
const dir =
|
|
10831
|
+
const dir = path62.join(root, ".changeset");
|
|
10358
10832
|
const bumps = /* @__PURE__ */ new Map();
|
|
10359
10833
|
if (!existsSync(dir)) return bumps;
|
|
10360
10834
|
for (const name of readdirSync(dir)) {
|
|
10361
10835
|
if (!name.endsWith(".md") || name === "README.md") continue;
|
|
10362
|
-
const text = readFileSync(
|
|
10836
|
+
const text = readFileSync(path62.join(dir, name), "utf8");
|
|
10363
10837
|
const front = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? "";
|
|
10364
10838
|
for (const line of front.split(/\r?\n/)) {
|
|
10365
10839
|
const m = /^\s*["']?([^"':]+)["']?\s*:\s*(major|minor|patch)\s*$/.exec(line);
|
|
@@ -10372,13 +10846,13 @@ function changesetBumps(root) {
|
|
|
10372
10846
|
return bumps;
|
|
10373
10847
|
}
|
|
10374
10848
|
function firstVersionProblems(root) {
|
|
10375
|
-
const packagesDir =
|
|
10849
|
+
const packagesDir = path62.join(root, "packages");
|
|
10376
10850
|
if (!existsSync(packagesDir)) return [];
|
|
10377
10851
|
const bumps = changesetBumps(root);
|
|
10378
10852
|
const problems = [];
|
|
10379
10853
|
for (const dir of readdirSync(packagesDir)) {
|
|
10380
|
-
const file =
|
|
10381
|
-
if (!existsSync(file) || existsSync(
|
|
10854
|
+
const file = path62.join(packagesDir, dir, "package.json");
|
|
10855
|
+
if (!existsSync(file) || existsSync(path62.join(packagesDir, dir, "CHANGELOG.md"))) continue;
|
|
10382
10856
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
10383
10857
|
if (pkg.private || !pkg.name) continue;
|
|
10384
10858
|
if (pkg.version !== FIRST_VERSION) {
|
|
@@ -10449,12 +10923,12 @@ function runsOnPullRequestsInto(workflow, branch) {
|
|
|
10449
10923
|
return ignore ? !ignore.some((p) => globMatches(p, branch)) : void 0;
|
|
10450
10924
|
}
|
|
10451
10925
|
function batchCiProblems(root, batch) {
|
|
10452
|
-
const dir =
|
|
10926
|
+
const dir = path62.join(root, ".github", "workflows");
|
|
10453
10927
|
if (!existsSync(dir)) return [];
|
|
10454
10928
|
const problems = [];
|
|
10455
10929
|
for (const name of readdirSync(dir)) {
|
|
10456
10930
|
if (!/\.ya?ml$/.test(name)) continue;
|
|
10457
|
-
const workflow = readFileSync(
|
|
10931
|
+
const workflow = readFileSync(path62.join(dir, name), "utf8");
|
|
10458
10932
|
const main = runsOnPullRequestsInto(workflow, "main");
|
|
10459
10933
|
if (main && !runsOnPullRequestsInto(workflow, sampleBranch(batch))) {
|
|
10460
10934
|
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` });
|
|
@@ -10499,20 +10973,20 @@ function readObject(file, key2) {
|
|
|
10499
10973
|
}
|
|
10500
10974
|
}
|
|
10501
10975
|
function settings(root, options) {
|
|
10502
|
-
const fromPackage = readObject(
|
|
10503
|
-
const fromConfig = readObject(
|
|
10976
|
+
const fromPackage = readObject(path62.join(root, "package.json"), "genesisFeatures");
|
|
10977
|
+
const fromConfig = readObject(path62.join(root, "genesis.config.json"), "features");
|
|
10504
10978
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
10505
10979
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
10506
10980
|
}
|
|
10507
10981
|
async function loadRegistry(input) {
|
|
10508
|
-
const root =
|
|
10982
|
+
const root = path62.resolve(input.dir);
|
|
10509
10983
|
const options = settings(root, input);
|
|
10510
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
10511
|
-
if (!registry || !existsSync(
|
|
10984
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path62.join(root, p)));
|
|
10985
|
+
if (!registry || !existsSync(path62.join(root, registry))) {
|
|
10512
10986
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
10513
10987
|
}
|
|
10514
|
-
const jiti = createJiti(
|
|
10515
|
-
const load = async (file) => await jiti.import(
|
|
10988
|
+
const jiti = createJiti(path62.join(root, "package.json"), { moduleCache: false });
|
|
10989
|
+
const load = async (file) => await jiti.import(path62.join(root, file));
|
|
10516
10990
|
const mod = await load(registry);
|
|
10517
10991
|
const features2 = mod.features ?? mod.default;
|
|
10518
10992
|
if (!isObject5(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -10524,7 +10998,7 @@ async function loadRegistry(input) {
|
|
|
10524
10998
|
const project = {
|
|
10525
10999
|
...rest,
|
|
10526
11000
|
root,
|
|
10527
|
-
source: options.source ?? registry.split(
|
|
11001
|
+
source: options.source ?? registry.split(path62.sep).join("/"),
|
|
10528
11002
|
features: features2,
|
|
10529
11003
|
flags
|
|
10530
11004
|
};
|
|
@@ -10574,24 +11048,24 @@ async function runFeaturesCheck(options) {
|
|
|
10574
11048
|
}
|
|
10575
11049
|
function readFeaturePackages(root) {
|
|
10576
11050
|
const found = [];
|
|
10577
|
-
const
|
|
10578
|
-
const file =
|
|
11051
|
+
const read3 = (dir, inRepo) => {
|
|
11052
|
+
const file = path62.join(dir, "package.json");
|
|
10579
11053
|
if (!existsSync(file)) return;
|
|
10580
11054
|
try {
|
|
10581
11055
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
10582
11056
|
const layer = pkg.genesis?.layer;
|
|
10583
11057
|
if (typeof pkg.name !== "string" || !PACKAGE_LAYERS.includes(layer)) return;
|
|
10584
11058
|
if (found.some((p) => p.name === pkg.name)) return;
|
|
10585
|
-
found.push({ name: pkg.name, layer, ...inRepo ? { dir:
|
|
11059
|
+
found.push({ name: pkg.name, layer, ...inRepo ? { dir: path62.relative(root, dir).split(path62.sep).join("/") } : {} });
|
|
10586
11060
|
} catch {
|
|
10587
11061
|
}
|
|
10588
11062
|
};
|
|
10589
11063
|
for (const [base, inRepo] of [
|
|
10590
|
-
[
|
|
10591
|
-
[
|
|
11064
|
+
[path62.join(root, "packages"), true],
|
|
11065
|
+
[path62.join(root, "node_modules", "@marktiderman"), false]
|
|
10592
11066
|
]) {
|
|
10593
11067
|
if (!existsSync(base)) continue;
|
|
10594
|
-
for (const name of readdirSync(base))
|
|
11068
|
+
for (const name of readdirSync(base)) read3(path62.join(base, name), inRepo);
|
|
10595
11069
|
}
|
|
10596
11070
|
return found;
|
|
10597
11071
|
}
|
|
@@ -10708,7 +11182,7 @@ function readRegister(markdown) {
|
|
|
10708
11182
|
const need = at(row, "need");
|
|
10709
11183
|
if (!need || need === "-") problems.push(`${where2}: say the need in one line`);
|
|
10710
11184
|
const local = at(row, "local");
|
|
10711
|
-
if (local && local !== "-" && localPaths(local).some((p) =>
|
|
11185
|
+
if (local && local !== "-" && localPaths(local).some((p) => path62.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p) || p.split(/[\\/]/).includes(".."))) {
|
|
10712
11186
|
problems.push(`${where2}: local must be paths inside the app, relative to its root`);
|
|
10713
11187
|
}
|
|
10714
11188
|
const opt = (c) => at(row, c) && at(row, c) !== "-" ? at(row, c) : void 0;
|
|
@@ -10720,13 +11194,13 @@ function localPaths(local) {
|
|
|
10720
11194
|
return (local ?? "").split(/,\s+|<br\s*\/?>/i).map((p) => p.trim()).filter((p) => p && p !== "-");
|
|
10721
11195
|
}
|
|
10722
11196
|
function checkUpstream(root) {
|
|
10723
|
-
const found = REGISTER_PATHS.find((p) => existsSync(
|
|
11197
|
+
const found = REGISTER_PATHS.find((p) => existsSync(path62.join(root, p)));
|
|
10724
11198
|
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 };
|
|
10725
|
-
const { entries, problems } = readRegister(readFileSync(
|
|
11199
|
+
const { entries, problems } = readRegister(readFileSync(path62.join(root, found), "utf8"));
|
|
10726
11200
|
const warnings = [];
|
|
10727
11201
|
for (const e of entries) {
|
|
10728
11202
|
const paths = localPaths(e.local);
|
|
10729
|
-
const absent = paths.filter((p) => !existsSync(
|
|
11203
|
+
const absent = paths.filter((p) => !existsSync(path62.join(root, p)));
|
|
10730
11204
|
const present = paths.filter((p) => !absent.includes(p));
|
|
10731
11205
|
if (absent.length && e.status !== "promoted" && e.status !== "declined") problems.push(`${e.id}: local ${absent.join(", ")} doesn't exist`);
|
|
10732
11206
|
if (present.length && e.status === "promoted") {
|
|
@@ -10755,6 +11229,177 @@ var init_upstream = __esm({
|
|
|
10755
11229
|
}
|
|
10756
11230
|
});
|
|
10757
11231
|
|
|
11232
|
+
// src/client/init.ts
|
|
11233
|
+
var init_exports = {};
|
|
11234
|
+
__export(init_exports, {
|
|
11235
|
+
DEFAULT_CLIENT_DIR: () => DEFAULT_CLIENT_DIR2,
|
|
11236
|
+
clientConfigChange: () => clientConfigChange,
|
|
11237
|
+
normalizeClientDir: () => normalizeClientDir,
|
|
11238
|
+
planClientInit: () => planClientInit
|
|
11239
|
+
});
|
|
11240
|
+
function normalizeClientDir(raw) {
|
|
11241
|
+
const dir = raw.trim().replace(/^(\.\/)+/, "").replace(/\/{2,}/g, "/").replace(/\/+$/, "");
|
|
11242
|
+
if (raw.includes("\\") || !isPlainFolder(dir) || dir.split("/").includes(".")) {
|
|
11243
|
+
throw new Error(`client init: "${raw}" isn't a plain folder inside the app; give one like src/client (letters, digits, dashes, dots and underscores, separated by /)`);
|
|
11244
|
+
}
|
|
11245
|
+
return dir;
|
|
11246
|
+
}
|
|
11247
|
+
function layerFile() {
|
|
11248
|
+
return `// The app's client layer (ADR 0020): one provider for what every list and record page in the
|
|
11249
|
+
// app shares. Mount <ClientLayer> once, near the root, inside GenesisProvider.
|
|
11250
|
+
import type { ReactNode } from "react";
|
|
11251
|
+
import { createLocalSavedViewStore, type SavedViewStore } from "@marktiderman/genesis-core/resource-view";
|
|
11252
|
+
import { useBrowserSearchParams } from "@marktiderman/genesis-ui";
|
|
11253
|
+
import { ResourceViewDefaultsProvider } from "@marktiderman/genesis-ui/data";
|
|
11254
|
+
|
|
11255
|
+
/**
|
|
11256
|
+
* Where saved views live. The device store keeps them in this browser; swap in a store over the
|
|
11257
|
+
* app's own table (list, save, remove, under row-level security) to share them across devices
|
|
11258
|
+
* and with a team.
|
|
11259
|
+
*/
|
|
11260
|
+
export const savedViews: SavedViewStore = createLocalSavedViewStore();
|
|
11261
|
+
|
|
11262
|
+
export function ClientLayer({ children }: { children: ReactNode }) {
|
|
11263
|
+
// The router's search-params adapter: a TanStack or React Router app passes its own hook's.
|
|
11264
|
+
const urlState = useBrowserSearchParams();
|
|
11265
|
+
return (
|
|
11266
|
+
<ResourceViewDefaultsProvider sizeColumns clipCells pagerJumps savedViews={savedViews} urlState={urlState} rowActions>
|
|
11267
|
+
{children}
|
|
11268
|
+
</ResourceViewDefaultsProvider>
|
|
11269
|
+
);
|
|
11270
|
+
}
|
|
11271
|
+
`;
|
|
11272
|
+
}
|
|
11273
|
+
function resourceViewFile() {
|
|
11274
|
+
return `// The app's ResourceView (ADR 0020): Genesis's, with the app's defaults. Screens render this one,
|
|
11275
|
+
// never Genesis's directly, so a default the app changes reaches every list at once.
|
|
11276
|
+
import { ResourceView as GenesisResourceView, type ResourceViewProps } from "@marktiderman/genesis-ui/data";
|
|
11277
|
+
|
|
11278
|
+
type Row = Record<string, unknown>;
|
|
11279
|
+
|
|
11280
|
+
export function ResourceView<T extends Row = Row>(props: ResourceViewProps<T>) {
|
|
11281
|
+
return <GenesisResourceView<T> createdToast {...props} />;
|
|
11282
|
+
}
|
|
11283
|
+
|
|
11284
|
+
export type { ResourceViewProps };
|
|
11285
|
+
`;
|
|
11286
|
+
}
|
|
11287
|
+
function recordViewFile() {
|
|
11288
|
+
return `// The app's RecordView (ADR 0020): Genesis's record page, with the app's defaults. Screens render
|
|
11289
|
+
// this one, never Genesis's directly, so a default the app changes reaches every record page at once.
|
|
11290
|
+
import { RecordView as GenesisRecordView, type RecordViewProps } from "@marktiderman/genesis-ui/data";
|
|
11291
|
+
|
|
11292
|
+
type Row = Record<string, unknown>;
|
|
11293
|
+
|
|
11294
|
+
export function RecordView<T extends Row = Row>(props: RecordViewProps<T>) {
|
|
11295
|
+
return <GenesisRecordView<T> {...props} />;
|
|
11296
|
+
}
|
|
11297
|
+
|
|
11298
|
+
export type { RecordViewProps };
|
|
11299
|
+
`;
|
|
11300
|
+
}
|
|
11301
|
+
function contractFile(type) {
|
|
11302
|
+
const name = camel(type);
|
|
11303
|
+
const table = type.replace(/-/g, "_");
|
|
11304
|
+
const Row = `${name[0].toUpperCase()}${name.slice(1)}Row`;
|
|
11305
|
+
return `// The ${type} contract: its fields and identity. A starting example so the view works today; once
|
|
11306
|
+
// the app generates its contracts, export the generated one instead:
|
|
11307
|
+
// export { contracts["public.${table}"] as ${name}Contract } \u2026 from "../../lib/resources.genesis";
|
|
11308
|
+
import { defineResource } from "@marktiderman/genesis-core";
|
|
11309
|
+
|
|
11310
|
+
export interface ${Row} {
|
|
11311
|
+
id: string;
|
|
11312
|
+
name: string;
|
|
11313
|
+
status: string;
|
|
11314
|
+
updated_at: string;
|
|
11315
|
+
[field: string]: unknown;
|
|
11316
|
+
}
|
|
11317
|
+
|
|
11318
|
+
export const ${name}Contract = defineResource<${Row}>()({
|
|
11319
|
+
name: "public.${table}",
|
|
11320
|
+
key: "id",
|
|
11321
|
+
labelField: "name",
|
|
11322
|
+
noun: "${type.replace(/-/g, " ")}",
|
|
11323
|
+
fields: [
|
|
11324
|
+
{ name: "id", type: "string", readOnly: true },
|
|
11325
|
+
{ name: "name", type: "string", label: "Name" },
|
|
11326
|
+
{ name: "status", type: "string", label: "Status" },
|
|
11327
|
+
{ name: "updated_at", type: "datetime", label: "Updated", readOnly: true },
|
|
11328
|
+
],
|
|
11329
|
+
});
|
|
11330
|
+
`;
|
|
11331
|
+
}
|
|
11332
|
+
function viewFile(type) {
|
|
11333
|
+
const name = camel(type);
|
|
11334
|
+
return `// The ${type} view (ADR 0020): what a ${type} record means to people. One view per resource; every
|
|
11335
|
+
// screen of ${type} renders this one, narrowed by its own props.
|
|
11336
|
+
import { defineView } from "@marktiderman/genesis-core/resource-view";
|
|
11337
|
+
import { ${name}Contract } from "./contract";
|
|
11338
|
+
|
|
11339
|
+
export const ${name}View = defineView(${name}Contract, {
|
|
11340
|
+
columns: { default: ["name", "status", "updated_at"] },
|
|
11341
|
+
segments: [{ id: "all", label: "All" }],
|
|
11342
|
+
filters: [{ field: "status" }],
|
|
11343
|
+
export: true,
|
|
11344
|
+
// fields: { status: { tones: { active: "success" } } },
|
|
11345
|
+
// actions: [{ name: "archive", label: "Archive", bulk: true }],
|
|
11346
|
+
});
|
|
11347
|
+
`;
|
|
11348
|
+
}
|
|
11349
|
+
function appearanceFile(type) {
|
|
11350
|
+
const name = camel(type);
|
|
11351
|
+
return `// How a ${type} record looks (ADR 0020): its own cells, its card and its record page. Keep the
|
|
11352
|
+
// rules in view.ts; this file draws.
|
|
11353
|
+
import type { ReactNode } from "react";
|
|
11354
|
+
|
|
11355
|
+
type ${name[0].toUpperCase()}${name.slice(1)}Row = Record<string, unknown>;
|
|
11356
|
+
|
|
11357
|
+
/** Cells this type draws its own way, by column key (ResourceView's \`cells\`). */
|
|
11358
|
+
export const ${name}Cells: Partial<Record<string, (row: ${name[0].toUpperCase()}${name.slice(1)}Row) => ReactNode>> = {};
|
|
11359
|
+
`;
|
|
11360
|
+
}
|
|
11361
|
+
function planClientInit(options = {}) {
|
|
11362
|
+
const dir = normalizeClientDir(options.dir ?? DEFAULT_CLIENT_DIR2);
|
|
11363
|
+
if (options.type !== void 0 && !TYPE.test(options.type)) throw new Error(`client init: the type "${options.type}" is lowercase words of letters and digits joined by single dashes, like tasks or client-notes`);
|
|
11364
|
+
const files = [
|
|
11365
|
+
{ path: `${dir}/client-layer.tsx`, content: layerFile() },
|
|
11366
|
+
{ path: `${dir}/resource-view.tsx`, content: resourceViewFile() },
|
|
11367
|
+
{ path: `${dir}/record-view.tsx`, content: recordViewFile() },
|
|
11368
|
+
{ path: `${dir}/cells/index.ts`, content: "// Cells the app draws its own way, shared by its types (ADR 0020).\nexport {};\n" },
|
|
11369
|
+
{ path: `${dir}/components/index.ts`, content: "// The app's own parts (ADR 0020): name each element's data-slot app-<name>.\nexport {};\n" },
|
|
11370
|
+
{
|
|
11371
|
+
path: `${dir}/view-types/index.ts`,
|
|
11372
|
+
content: "// View types the app registers (ADR 0021): defineViewType, then registerViewType once at start-up.\nexport {};\n"
|
|
11373
|
+
}
|
|
11374
|
+
];
|
|
11375
|
+
if (options.type) {
|
|
11376
|
+
files.push({ path: `${dir}/${options.type}/contract.ts`, content: contractFile(options.type) });
|
|
11377
|
+
files.push({ path: `${dir}/${options.type}/view.ts`, content: viewFile(options.type) });
|
|
11378
|
+
files.push({ path: `${dir}/${options.type}/appearance.tsx`, content: appearanceFile(options.type) });
|
|
11379
|
+
}
|
|
11380
|
+
const steps = [
|
|
11381
|
+
`Mount <ClientLayer> from ${dir}/client-layer.tsx once, inside GenesisProvider.`,
|
|
11382
|
+
`Render ResourceView and RecordView from ${dir}/resource-view.tsx and ${dir}/record-view.tsx in screens; genesis doctor warns (client/layer) where a screen renders Genesis's directly.`,
|
|
11383
|
+
...dir !== DEFAULT_CLIENT_DIR2 ? [`genesis.config.json now names the folder: { "client": { "dir": "${dir}" } }.`] : []
|
|
11384
|
+
];
|
|
11385
|
+
return { dir, files, steps };
|
|
11386
|
+
}
|
|
11387
|
+
function clientConfigChange(planned, configured, force = false) {
|
|
11388
|
+
if (configured === void 0) return planned === DEFAULT_CLIENT_DIR2 ? "none" : "write";
|
|
11389
|
+
if (configured === planned) return "none";
|
|
11390
|
+
if (!force) throw new Error(`client init: genesis.config.json names the client layer's folder "${configured}"; pass --force to move it to "${planned}"`);
|
|
11391
|
+
return "write";
|
|
11392
|
+
}
|
|
11393
|
+
var DEFAULT_CLIENT_DIR2, TYPE, camel;
|
|
11394
|
+
var init_init = __esm({
|
|
11395
|
+
"src/client/init.ts"() {
|
|
11396
|
+
init_config();
|
|
11397
|
+
DEFAULT_CLIENT_DIR2 = "src/client";
|
|
11398
|
+
TYPE = /^(?=.{1,40}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
11399
|
+
camel = (name) => name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
11400
|
+
}
|
|
11401
|
+
});
|
|
11402
|
+
|
|
10758
11403
|
// src/studio/wire-route.ts
|
|
10759
11404
|
function routeTags(source) {
|
|
10760
11405
|
const tags = [];
|
|
@@ -10846,8 +11491,8 @@ var init_wire_route = __esm({
|
|
|
10846
11491
|
});
|
|
10847
11492
|
|
|
10848
11493
|
// src/studio/init.ts
|
|
10849
|
-
var
|
|
10850
|
-
__export(
|
|
11494
|
+
var init_exports2 = {};
|
|
11495
|
+
__export(init_exports2, {
|
|
10851
11496
|
detectHost: () => detectHost,
|
|
10852
11497
|
planStudioInit: () => planStudioInit
|
|
10853
11498
|
});
|
|
@@ -11117,7 +11762,7 @@ ${line}
|
|
|
11117
11762
|
);
|
|
11118
11763
|
}
|
|
11119
11764
|
var SERVER_VERSION, PACKAGES, ROLE, LOVABLE_CLIENT;
|
|
11120
|
-
var
|
|
11765
|
+
var init_init2 = __esm({
|
|
11121
11766
|
"src/studio/init.ts"() {
|
|
11122
11767
|
init_wire_route();
|
|
11123
11768
|
SERVER_VERSION = createRequire(import.meta.url)("@marktiderman/genesis-studio-server/package.json").version;
|
|
@@ -11176,7 +11821,7 @@ function literal(value, indent) {
|
|
|
11176
11821
|
if (Array.isArray(value)) return `[${value.map((v) => literal(v, indent)).join(", ")}]`;
|
|
11177
11822
|
if (value && typeof value === "object") {
|
|
11178
11823
|
const inner = `${indent} `;
|
|
11179
|
-
const lines = Object.entries(value).map(([k, v]) => `${inner}${
|
|
11824
|
+
const lines = Object.entries(value).map(([k, v]) => `${inner}${IDENT2.test(k) ? k : JSON.stringify(k)}: ${literal(v, inner)},`);
|
|
11180
11825
|
return `{
|
|
11181
11826
|
${lines.join("\n")}
|
|
11182
11827
|
${indent}}`;
|
|
@@ -11184,8 +11829,8 @@ ${indent}}`;
|
|
|
11184
11829
|
return JSON.stringify(value);
|
|
11185
11830
|
}
|
|
11186
11831
|
function featureKindField(root) {
|
|
11187
|
-
for (let dir =
|
|
11188
|
-
for (const file of [
|
|
11832
|
+
for (let dir = path62.resolve(root); ; dir = path62.dirname(dir)) {
|
|
11833
|
+
for (const file of [path62.join(dir, "node_modules/@marktiderman/genesis-features/package.json"), path62.join(dir, "packages/features/package.json")]) {
|
|
11189
11834
|
try {
|
|
11190
11835
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
11191
11836
|
if (pkg.name !== "@marktiderman/genesis-features" || !pkg.version) continue;
|
|
@@ -11194,7 +11839,7 @@ function featureKindField(root) {
|
|
|
11194
11839
|
} catch {
|
|
11195
11840
|
}
|
|
11196
11841
|
}
|
|
11197
|
-
if (
|
|
11842
|
+
if (path62.dirname(dir) === dir) return "layer";
|
|
11198
11843
|
}
|
|
11199
11844
|
}
|
|
11200
11845
|
function featureSnippet(manifest, owner, kindField = "kind") {
|
|
@@ -11264,20 +11909,20 @@ function addFeatureEntry(text, snippet) {
|
|
|
11264
11909
|
return `${head.replace(/\s*$/, "")}
|
|
11265
11910
|
${snippet}${text.slice(scan.close)}`;
|
|
11266
11911
|
}
|
|
11267
|
-
var
|
|
11912
|
+
var IDENT2;
|
|
11268
11913
|
var init_registry_edit = __esm({
|
|
11269
11914
|
"src/blocks/registry-edit.ts"() {
|
|
11270
|
-
|
|
11915
|
+
IDENT2 = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
11271
11916
|
}
|
|
11272
11917
|
});
|
|
11273
11918
|
function routerRoot2(root) {
|
|
11274
11919
|
try {
|
|
11275
|
-
const config = JSON.parse(readFileSync(
|
|
11920
|
+
const config = JSON.parse(readFileSync(path62.join(root, "genesis.config.json"), "utf8"));
|
|
11276
11921
|
const configured = config.doctor?.native?.routerRoot;
|
|
11277
|
-
if (configured && existsSync(
|
|
11922
|
+
if (configured && existsSync(path62.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
11278
11923
|
} catch {
|
|
11279
11924
|
}
|
|
11280
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
11925
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path62.join(root, dir, "_layout.tsx"))) return dir;
|
|
11281
11926
|
return null;
|
|
11282
11927
|
}
|
|
11283
11928
|
function routeOf(file) {
|
|
@@ -11339,23 +11984,23 @@ __export(add_exports, {
|
|
|
11339
11984
|
});
|
|
11340
11985
|
function appDependencies(root) {
|
|
11341
11986
|
try {
|
|
11342
|
-
const pkg = JSON.parse(readFileSync(
|
|
11987
|
+
const pkg = JSON.parse(readFileSync(path62.join(root, "package.json"), "utf8"));
|
|
11343
11988
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
11344
11989
|
} catch {
|
|
11345
11990
|
return {};
|
|
11346
11991
|
}
|
|
11347
11992
|
}
|
|
11348
11993
|
function registryFile(root) {
|
|
11349
|
-
const
|
|
11994
|
+
const read3 = (file, key2) => {
|
|
11350
11995
|
try {
|
|
11351
|
-
const v = JSON.parse(readFileSync(
|
|
11996
|
+
const v = JSON.parse(readFileSync(path62.join(root, file), "utf8"))[key2]?.registry;
|
|
11352
11997
|
return typeof v === "string" ? v : void 0;
|
|
11353
11998
|
} catch {
|
|
11354
11999
|
return void 0;
|
|
11355
12000
|
}
|
|
11356
12001
|
};
|
|
11357
|
-
const named =
|
|
11358
|
-
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(
|
|
12002
|
+
const named = read3("genesis.config.json", "features") ?? read3("package.json", "genesisFeatures");
|
|
12003
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path62.join(root, candidate))) return candidate;
|
|
11359
12004
|
return null;
|
|
11360
12005
|
}
|
|
11361
12006
|
async function registryIds(root, file) {
|
|
@@ -11443,7 +12088,7 @@ verify_jwt = false
|
|
|
11443
12088
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
11444
12089
|
}
|
|
11445
12090
|
async function runAdd(options) {
|
|
11446
|
-
const root =
|
|
12091
|
+
const root = path62.resolve(options.root);
|
|
11447
12092
|
const log = options.log ?? SILENT;
|
|
11448
12093
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
11449
12094
|
const warnings = [];
|
|
@@ -11682,7 +12327,7 @@ function notificationTypesSql(rows, registryFile2) {
|
|
|
11682
12327
|
}
|
|
11683
12328
|
function configuredRegistry(root) {
|
|
11684
12329
|
try {
|
|
11685
|
-
const raw = JSON.parse(readFileSync(
|
|
12330
|
+
const raw = JSON.parse(readFileSync(path62.join(root, "genesis.config.json"), "utf8"));
|
|
11686
12331
|
return typeof raw.notifications?.registry === "string" ? raw.notifications.registry : void 0;
|
|
11687
12332
|
} catch {
|
|
11688
12333
|
return void 0;
|
|
@@ -11701,14 +12346,14 @@ async function planNotificationTypes(root, options) {
|
|
|
11701
12346
|
warnings.push(`Notification types: not checked on a dry run (loading ${file} runs app code).`);
|
|
11702
12347
|
return { registry: file, warnings };
|
|
11703
12348
|
}
|
|
11704
|
-
const absolute =
|
|
12349
|
+
const absolute = path62.resolve(root, file);
|
|
11705
12350
|
if (!existsSync(absolute)) {
|
|
11706
12351
|
warnings.push(`Notification types: ${file} doesn't exist (a relative path is resolved against the app's root, ${root}).`);
|
|
11707
12352
|
return { registry: file, warnings };
|
|
11708
12353
|
}
|
|
11709
12354
|
let mod;
|
|
11710
12355
|
try {
|
|
11711
|
-
const jiti = createJiti(
|
|
12356
|
+
const jiti = createJiti(path62.join(root, "package.json"), { moduleCache: false });
|
|
11712
12357
|
mod = await jiti.import(absolute);
|
|
11713
12358
|
} catch (err) {
|
|
11714
12359
|
warnings.push(`Notification types: couldn't load ${file} (${err instanceof Error ? err.message : String(err)}).`);
|
|
@@ -11719,8 +12364,8 @@ async function planNotificationTypes(root, options) {
|
|
|
11719
12364
|
warnings.push(`Notification types: ${file} exports no defineNotifications registry (export it as \`notifications\`).`);
|
|
11720
12365
|
return { registry: file, warnings };
|
|
11721
12366
|
}
|
|
11722
|
-
const shown =
|
|
11723
|
-
const content = notificationTypesSql(found.toTypeRows(), shown.split(
|
|
12367
|
+
const shown = path62.isAbsolute(file) ? path62.relative(root, absolute) : file;
|
|
12368
|
+
const content = notificationTypesSql(found.toTypeRows(), shown.split(path62.sep).join("/"));
|
|
11724
12369
|
const app = readAppMigrations(root);
|
|
11725
12370
|
const latest = app.filter((m) => m.name.endsWith(`_${TYPES_STEM}.sql`)).sort((a, b) => a.name < b.name ? -1 : 1).pop();
|
|
11726
12371
|
if (latest && payloadOf(latest.content) === payloadOf(content)) return { registry: file, warnings };
|
|
@@ -11752,7 +12397,7 @@ __export(migrate_exports, {
|
|
|
11752
12397
|
runMigrate: () => runMigrate
|
|
11753
12398
|
});
|
|
11754
12399
|
async function runMigrate(options) {
|
|
11755
|
-
const root =
|
|
12400
|
+
const root = path62.resolve(options.root);
|
|
11756
12401
|
const lock = readLock(root);
|
|
11757
12402
|
const warnings = [];
|
|
11758
12403
|
const home = databaseElsewhere(root);
|
|
@@ -11869,7 +12514,7 @@ function repositoryDirectory(root, name) {
|
|
|
11869
12514
|
const dir = packageDir(root, name);
|
|
11870
12515
|
if (!dir) return null;
|
|
11871
12516
|
try {
|
|
11872
|
-
const { repository } = JSON.parse(readFileSync(
|
|
12517
|
+
const { repository } = JSON.parse(readFileSync(path62.join(dir, "package.json"), "utf8"));
|
|
11873
12518
|
return typeof repository?.directory === "string" ? repository.directory : null;
|
|
11874
12519
|
} catch {
|
|
11875
12520
|
return null;
|
|
@@ -11948,11 +12593,11 @@ var init_new_exports = __esm({
|
|
|
11948
12593
|
}
|
|
11949
12594
|
});
|
|
11950
12595
|
function walk3(dir, rel = "", out = /* @__PURE__ */ new Map()) {
|
|
11951
|
-
for (const entry of readdirSync(
|
|
12596
|
+
for (const entry of readdirSync(path62.join(dir, rel), { withFileTypes: true })) {
|
|
11952
12597
|
if (SKIP.has(entry.name)) continue;
|
|
11953
12598
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
11954
12599
|
if (entry.isDirectory()) walk3(dir, child, out);
|
|
11955
|
-
else if (entry.isFile()) out.set(child, readFileSync(
|
|
12600
|
+
else if (entry.isFile()) out.set(child, readFileSync(path62.join(dir, child)));
|
|
11956
12601
|
}
|
|
11957
12602
|
return out;
|
|
11958
12603
|
}
|
|
@@ -11975,7 +12620,7 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
11975
12620
|
const tag = `${name}@${version}`;
|
|
11976
12621
|
try {
|
|
11977
12622
|
if (!clone) {
|
|
11978
|
-
clone = mkdtempSync(
|
|
12623
|
+
clone = mkdtempSync(path62.join(tmpdir(), "genesis-upstream-"));
|
|
11979
12624
|
git4(["init", "-q"]);
|
|
11980
12625
|
}
|
|
11981
12626
|
git4(["fetch", "-q", "--no-tags", "--depth", "1", repository, `+refs/tags/${tag}:refs/tags/${tag}`]);
|
|
@@ -11992,7 +12637,7 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
11992
12637
|
}
|
|
11993
12638
|
});
|
|
11994
12639
|
if (!manifest) return { error: `the tag ${tag} has no package named ${name}` };
|
|
11995
|
-
const dir =
|
|
12640
|
+
const dir = path62.posix.dirname(manifest);
|
|
11996
12641
|
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)));
|
|
11997
12642
|
const files = /* @__PURE__ */ new Map();
|
|
11998
12643
|
if (entries.length) {
|
|
@@ -12018,10 +12663,10 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
12018
12663
|
}
|
|
12019
12664
|
function diffHunks(before, after) {
|
|
12020
12665
|
if (before === after) return [];
|
|
12021
|
-
const dir = mkdtempSync(
|
|
12666
|
+
const dir = mkdtempSync(path62.join(tmpdir(), "genesis-diff-"));
|
|
12022
12667
|
try {
|
|
12023
|
-
writeFileSync(
|
|
12024
|
-
writeFileSync(
|
|
12668
|
+
writeFileSync(path62.join(dir, "a"), before);
|
|
12669
|
+
writeFileSync(path62.join(dir, "b"), after);
|
|
12025
12670
|
let out = "";
|
|
12026
12671
|
try {
|
|
12027
12672
|
out = execFileSync("git", ["diff", "--no-index", "--no-color", "-U0", "a", "b"], { cwd: dir, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
@@ -12049,9 +12694,9 @@ function shippedBy(upstreamHunks) {
|
|
|
12049
12694
|
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]));
|
|
12050
12695
|
}
|
|
12051
12696
|
function promotions(root, name) {
|
|
12052
|
-
const file = REGISTER_PATHS.find((p) => existsSync(
|
|
12697
|
+
const file = REGISTER_PATHS.find((p) => existsSync(path62.join(root, p)));
|
|
12053
12698
|
if (!file) return [];
|
|
12054
|
-
const text = readFileSync(
|
|
12699
|
+
const text = readFileSync(path62.join(root, file), "utf8");
|
|
12055
12700
|
const rows = text.split("\n");
|
|
12056
12701
|
return readRegister(text).entries.filter((e) => e.status === "promoted" && e.package === name).map((e) => {
|
|
12057
12702
|
const row = rows.find((r) => r.split("|").map((c) => c.trim())[1] === e.id) ?? "";
|
|
@@ -12109,7 +12754,7 @@ function planOverlays(root, wanted, upstream2, manifests = ["package.json"]) {
|
|
|
12109
12754
|
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
12110
12755
|
let json;
|
|
12111
12756
|
try {
|
|
12112
|
-
json = JSON.parse(readFileSync(
|
|
12757
|
+
json = JSON.parse(readFileSync(path62.join(pkg.dir, "package.json"), "utf8"));
|
|
12113
12758
|
} catch {
|
|
12114
12759
|
continue;
|
|
12115
12760
|
}
|
|
@@ -12235,7 +12880,7 @@ function folderReferences(root, plan) {
|
|
|
12235
12880
|
for (const file of candidates.sort()) {
|
|
12236
12881
|
let text;
|
|
12237
12882
|
try {
|
|
12238
|
-
text = readFileSync(
|
|
12883
|
+
text = readFileSync(path62.join(root, file), "utf8");
|
|
12239
12884
|
} catch {
|
|
12240
12885
|
continue;
|
|
12241
12886
|
}
|
|
@@ -12247,7 +12892,7 @@ function folderReferences(root, plan) {
|
|
|
12247
12892
|
function planPins(root, plan, manifests) {
|
|
12248
12893
|
const pins = /* @__PURE__ */ new Map();
|
|
12249
12894
|
for (const file of manifests) {
|
|
12250
|
-
const abs =
|
|
12895
|
+
const abs = path62.join(root, file);
|
|
12251
12896
|
if (!existsSync(abs)) continue;
|
|
12252
12897
|
const text = readFileSync(abs, "utf8");
|
|
12253
12898
|
const pinned = pinManifest(root, plan, file, text);
|
|
@@ -12265,9 +12910,9 @@ function pinManifest(root, plan, file, text) {
|
|
|
12265
12910
|
} catch {
|
|
12266
12911
|
return void 0;
|
|
12267
12912
|
}
|
|
12268
|
-
const overlay =
|
|
12269
|
-
const here =
|
|
12270
|
-
const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) &&
|
|
12913
|
+
const overlay = path62.resolve(root, plan.rel);
|
|
12914
|
+
const here = path62.dirname(path62.join(root, file));
|
|
12915
|
+
const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) && path62.resolve(here, spec.slice(5)) === overlay);
|
|
12271
12916
|
let touched2 = false;
|
|
12272
12917
|
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
12273
12918
|
const deps = json[section2];
|
|
@@ -12282,7 +12927,7 @@ function pinManifest(root, plan, file, text) {
|
|
|
12282
12927
|
touched2 = true;
|
|
12283
12928
|
}
|
|
12284
12929
|
}
|
|
12285
|
-
const names = (entry) => typeof entry === "string" &&
|
|
12930
|
+
const names = (entry) => typeof entry === "string" && path62.resolve(here, entry) === overlay;
|
|
12286
12931
|
const ws = json.workspaces;
|
|
12287
12932
|
const list = Array.isArray(ws) ? ws : isObject6(ws) && Array.isArray(ws.packages) ? ws.packages : null;
|
|
12288
12933
|
if (list?.some(names)) {
|
|
@@ -12300,10 +12945,10 @@ function applyOverlayPlans(root, plans, lockEdits = []) {
|
|
|
12300
12945
|
const removedFolders = [];
|
|
12301
12946
|
for (const plan of plans) {
|
|
12302
12947
|
if (plan.skipped || plan.conflicts.length) continue;
|
|
12303
|
-
const dir =
|
|
12948
|
+
const dir = path62.join(root, plan.rel);
|
|
12304
12949
|
if (plan.remove) {
|
|
12305
12950
|
for (const file of plan.pins.keys()) {
|
|
12306
|
-
const abs =
|
|
12951
|
+
const abs = path62.join(root, file);
|
|
12307
12952
|
const now = existsSync(abs) ? readFileSync(abs, "utf8") : null;
|
|
12308
12953
|
const text = now === null ? plan.pins.get(file) : pinManifest(root, plan, file, now);
|
|
12309
12954
|
if (typeof text !== "string") continue;
|
|
@@ -12316,10 +12961,10 @@ function applyOverlayPlans(root, plans, lockEdits = []) {
|
|
|
12316
12961
|
continue;
|
|
12317
12962
|
}
|
|
12318
12963
|
for (const [file, bytes] of plan.writes) {
|
|
12319
|
-
const target =
|
|
12964
|
+
const target = path62.join(dir, file);
|
|
12320
12965
|
if (bytes === null) rmSync(target, { force: true });
|
|
12321
12966
|
else {
|
|
12322
|
-
mkdirSync(
|
|
12967
|
+
mkdirSync(path62.dirname(target), { recursive: true });
|
|
12323
12968
|
writeFileSync(target, bytes);
|
|
12324
12969
|
}
|
|
12325
12970
|
changed.push(`${plan.rel}/${file}`);
|
|
@@ -12341,7 +12986,7 @@ function dropRemovedWorkspaces(root, folders) {
|
|
|
12341
12986
|
const packages = [];
|
|
12342
12987
|
try {
|
|
12343
12988
|
for (const folder of folders) {
|
|
12344
|
-
const entries = workspaceEntries(text,
|
|
12989
|
+
const entries = workspaceEntries(text, path62.relative(found.dir, folder).split(path62.sep).join("/"));
|
|
12345
12990
|
workspaces.push(...entries.workspaces);
|
|
12346
12991
|
packages.push(...entries.packages);
|
|
12347
12992
|
}
|
|
@@ -12349,8 +12994,8 @@ function dropRemovedWorkspaces(root, folders) {
|
|
|
12349
12994
|
return null;
|
|
12350
12995
|
}
|
|
12351
12996
|
if (!workspaces.length && !packages.length) return null;
|
|
12352
|
-
writeFileSync(
|
|
12353
|
-
return { file:
|
|
12997
|
+
writeFileSync(path62.join(found.dir, BUN_LOCK), removeBunLockEntries(text, { workspaces, packages }));
|
|
12998
|
+
return { file: path62.relative(root, path62.join(found.dir, BUN_LOCK)).split(path62.sep).join("/"), workspaces };
|
|
12354
12999
|
}
|
|
12355
13000
|
function overlayChecklist(plans) {
|
|
12356
13001
|
if (!plans.length) return [];
|
|
@@ -12415,8 +13060,8 @@ function pruneBunLock(root, want, dryRun) {
|
|
|
12415
13060
|
return null;
|
|
12416
13061
|
}
|
|
12417
13062
|
if (!pruned.length) return null;
|
|
12418
|
-
if (!dryRun) writeFileSync(
|
|
12419
|
-
return { file:
|
|
13063
|
+
if (!dryRun) writeFileSync(path62.join(found.dir, BUN_LOCK), removeBunLockEntries(text, { packages: pruned.map((p) => p.key) }));
|
|
13064
|
+
return { file: path62.relative(root, path62.join(found.dir, BUN_LOCK)).split(path62.sep).join("/"), pruned };
|
|
12420
13065
|
}
|
|
12421
13066
|
function npm(args, cwd) {
|
|
12422
13067
|
return execFileSync("npm", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
@@ -12428,11 +13073,11 @@ function npmLookup(cwd) {
|
|
|
12428
13073
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
12429
13074
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
12430
13075
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
12431
|
-
const tmp = mkdtempSync(
|
|
13076
|
+
const tmp = mkdtempSync(path62.join(tmpdir(), "genesis-umbrella-"));
|
|
12432
13077
|
try {
|
|
12433
13078
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
12434
|
-
execFileSync("tar", ["-xzf",
|
|
12435
|
-
const manifest = JSON.parse(readFileSync(
|
|
13079
|
+
execFileSync("tar", ["-xzf", path62.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
13080
|
+
const manifest = JSON.parse(readFileSync(path62.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
12436
13081
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
12437
13082
|
return manifest;
|
|
12438
13083
|
} finally {
|
|
@@ -12478,8 +13123,8 @@ function readText2(file) {
|
|
|
12478
13123
|
function tidyReleaseAgeExcludes(file) {
|
|
12479
13124
|
const before = readText2(file);
|
|
12480
13125
|
if (before === null) return false;
|
|
12481
|
-
const dir =
|
|
12482
|
-
const after = normaliseReleaseAgeExcludes(before, tidyLocked(before, readText2(
|
|
13126
|
+
const dir = path62.dirname(file);
|
|
13127
|
+
const after = normaliseReleaseAgeExcludes(before, tidyLocked(before, readText2(path62.join(dir, "pnpm-lock.yaml")), readText2(path62.join(dir, ".npmrc"))));
|
|
12483
13128
|
if (after === before) return false;
|
|
12484
13129
|
writeFileSync(file, after);
|
|
12485
13130
|
return true;
|
|
@@ -12495,14 +13140,14 @@ function gitTopLevel(root) {
|
|
|
12495
13140
|
function folderBelowTopLevel(root) {
|
|
12496
13141
|
const real2 = realpathSync(root);
|
|
12497
13142
|
const top = gitTopLevel(real2);
|
|
12498
|
-
return top === null ? null :
|
|
13143
|
+
return top === null ? null : path62.relative(top, real2).split(path62.sep).join("/");
|
|
12499
13144
|
}
|
|
12500
13145
|
function pnpmWorkspaceFileFor(root) {
|
|
12501
13146
|
const real2 = realpathSync(root);
|
|
12502
13147
|
const top = gitTopLevel(real2);
|
|
12503
13148
|
const lockDir = findLockfile(real2)?.dir;
|
|
12504
13149
|
const fallback = lockDir && (!top || inside2(top, lockDir)) ? lockDir : real2;
|
|
12505
|
-
return pnpmWorkspaceFile(real2, fallback, { exists: existsSync, join:
|
|
13150
|
+
return pnpmWorkspaceFile(real2, fallback, { exists: existsSync, join: path62.join, dirname: path62.dirname }, top ?? void 0);
|
|
12506
13151
|
}
|
|
12507
13152
|
function pnpmVersionIn(root) {
|
|
12508
13153
|
try {
|
|
@@ -12552,7 +13197,7 @@ function packageJsons(root) {
|
|
|
12552
13197
|
if (files.length) return files;
|
|
12553
13198
|
} catch {
|
|
12554
13199
|
}
|
|
12555
|
-
return existsSync(
|
|
13200
|
+
return existsSync(path62.join(root, "package.json")) ? ["package.json"] : [];
|
|
12556
13201
|
}
|
|
12557
13202
|
function sourceText(root, source, substitutions) {
|
|
12558
13203
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -12572,12 +13217,12 @@ function sourceText(root, source, substitutions) {
|
|
|
12572
13217
|
}
|
|
12573
13218
|
}
|
|
12574
13219
|
async function runUpgrade(options) {
|
|
12575
|
-
const root =
|
|
13220
|
+
const root = path62.resolve(options.root);
|
|
12576
13221
|
const log = options.log ?? (() => {
|
|
12577
13222
|
});
|
|
12578
13223
|
checkInstalled(root, options);
|
|
12579
13224
|
const lookup = options.lookup ?? npmLookup(root);
|
|
12580
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
13225
|
+
const release = options.manifest ? JSON.parse(readFileSync(path62.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
12581
13226
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
12582
13227
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
12583
13228
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -12675,7 +13320,7 @@ async function runUpgrade(options) {
|
|
|
12675
13320
|
const excludeWarnings = [];
|
|
12676
13321
|
if (!options.dryRun && options.install !== false && (bumped.size || bunLock)) {
|
|
12677
13322
|
const workspaceFile = pm === "pnpm" ? pnpmWorkspaceFileFor(root) : null;
|
|
12678
|
-
const relWorkspace = workspaceFile ?
|
|
13323
|
+
const relWorkspace = workspaceFile ? path62.relative(realpathSync(root), workspaceFile) : null;
|
|
12679
13324
|
const workspaceBefore = workspaceFile ? readText2(workspaceFile) : null;
|
|
12680
13325
|
const tidy = () => {
|
|
12681
13326
|
if (!workspaceFile || !tidyReleaseAgeExcludes(workspaceFile)) return;
|
|
@@ -12908,7 +13553,7 @@ function checkSubstitutions(substitutions) {
|
|
|
12908
13553
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
12909
13554
|
let names;
|
|
12910
13555
|
try {
|
|
12911
|
-
const was = starterIdentity(readFileSync(
|
|
13556
|
+
const was = starterIdentity(readFileSync(path62.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
12912
13557
|
names = [was.name, was.slug, was.scheme, was.bundleId];
|
|
12913
13558
|
} catch {
|
|
12914
13559
|
names = [];
|
|
@@ -12924,9 +13569,9 @@ function checkSubstitutions(substitutions) {
|
|
|
12924
13569
|
function lockfilesFor(root) {
|
|
12925
13570
|
const top = gitTopLevel(root);
|
|
12926
13571
|
const lockfiles = [];
|
|
12927
|
-
for (let dir = realpathSync(root); ; dir =
|
|
12928
|
-
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(
|
|
12929
|
-
if (lockfiles.length || dir === top ||
|
|
13572
|
+
for (let dir = realpathSync(root); ; dir = path62.dirname(dir)) {
|
|
13573
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path62.join(dir, f))) lockfiles.push(path62.relative(realpathSync(root), path62.join(dir, f)));
|
|
13574
|
+
if (lockfiles.length || dir === top || path62.dirname(dir) === dir) break;
|
|
12930
13575
|
}
|
|
12931
13576
|
return lockfiles;
|
|
12932
13577
|
}
|
|
@@ -12957,13 +13602,13 @@ function openPullRequest(root, version, report, base) {
|
|
|
12957
13602
|
git4("switch", "-c", branch);
|
|
12958
13603
|
const lockfiles = lockfilesFor(root);
|
|
12959
13604
|
const ignoredLocks = gitIgnored(root, lockfiles);
|
|
12960
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
13605
|
+
const paths = [...report.files.filter((f) => existsSync(path62.join(root, f))), ...lockfiles.filter((f) => !ignoredLocks.includes(f))];
|
|
12961
13606
|
git4("add", "--", ...paths);
|
|
12962
13607
|
const overlayDirs = report.overlays.filter((o) => !o.skipped && !o.conflicts.length && (o.remove || [...o.writes.values()].includes(null))).map((o) => o.rel);
|
|
12963
13608
|
if (overlayDirs.length) git4("add", "-A", "--", ...overlayDirs);
|
|
12964
13609
|
git4("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
12965
13610
|
git4("push", "-u", "origin", branch);
|
|
12966
|
-
const body =
|
|
13611
|
+
const body = path62.join(mkdtempSync(path62.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
12967
13612
|
writeFileSync(body, `${report.summary}
|
|
12968
13613
|
|
|
12969
13614
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -12998,8 +13643,8 @@ var init_upgrade = __esm({
|
|
|
12998
13643
|
init_bun_lock();
|
|
12999
13644
|
EXACT_OR_TAG = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
|
|
13000
13645
|
inside2 = (dir, file) => {
|
|
13001
|
-
const rel =
|
|
13002
|
-
return rel === "" || rel.split(
|
|
13646
|
+
const rel = path62.relative(dir, file);
|
|
13647
|
+
return rel === "" || rel.split(path62.sep)[0] !== ".." && !path62.isAbsolute(rel);
|
|
13003
13648
|
};
|
|
13004
13649
|
NOT_MATURE = "ERR_PNPM_NO_MATURE_MATCHING_VERSION";
|
|
13005
13650
|
SUBSTITUTION_VALUE = /^[A-Za-z0-9][A-Za-z0-9 .+-]{0,59}$/;
|
|
@@ -13102,9 +13747,9 @@ async function runScaffold(opts, fs2) {
|
|
|
13102
13747
|
function joinPath(...parts) {
|
|
13103
13748
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
13104
13749
|
}
|
|
13105
|
-
function dirname(
|
|
13106
|
-
const idx =
|
|
13107
|
-
return idx === -1 ? "." :
|
|
13750
|
+
function dirname(path63) {
|
|
13751
|
+
const idx = path63.lastIndexOf("/");
|
|
13752
|
+
return idx === -1 ? "." : path63.slice(0, idx);
|
|
13108
13753
|
}
|
|
13109
13754
|
function brandPackageJson(consumer, genesisVersion) {
|
|
13110
13755
|
return JSON.stringify(
|
|
@@ -13343,7 +13988,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
13343
13988
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
13344
13989
|
const result2 = await runInitNative2({
|
|
13345
13990
|
name: consumer,
|
|
13346
|
-
target:
|
|
13991
|
+
target: path62.resolve(opts.target ?? consumer),
|
|
13347
13992
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
13348
13993
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
13349
13994
|
...opts.scheme ? { scheme: opts.scheme } : {},
|
|
@@ -13357,7 +14002,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
13357
14002
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
13358
14003
|
console.log("");
|
|
13359
14004
|
console.log("Next steps:");
|
|
13360
|
-
[`cd ${
|
|
14005
|
+
[`cd ${path62.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
13361
14006
|
return;
|
|
13362
14007
|
}
|
|
13363
14008
|
opts.target ??= process.cwd();
|
|
@@ -13442,7 +14087,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
13442
14087
|
});
|
|
13443
14088
|
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("--verbose", "List the Genesis components no file imports (otherwise only their count)", 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) => {
|
|
13444
14089
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
13445
|
-
const root =
|
|
14090
|
+
const root = path62.resolve(opts.dir);
|
|
13446
14091
|
try {
|
|
13447
14092
|
if (opts.printGenesis) {
|
|
13448
14093
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -13461,7 +14106,7 @@ program.command("doctor").description("Check this app against the installed Gene
|
|
|
13461
14106
|
});
|
|
13462
14107
|
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) => {
|
|
13463
14108
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
13464
|
-
const packages = doctor.discoverPackages(
|
|
14109
|
+
const packages = doctor.discoverPackages(path62.resolve(opts.dir));
|
|
13465
14110
|
const rows = doctor.primitivesCatalog(packages);
|
|
13466
14111
|
const broken = packages.filter((p) => p.error);
|
|
13467
14112
|
if (opts.json) {
|
|
@@ -13476,7 +14121,7 @@ program.command("catalog").description("Print the Genesis catalog: for each need
|
|
|
13476
14121
|
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) => {
|
|
13477
14122
|
console.error("! `genesis primitives` is now `genesis catalog`; the old name works until the next major.");
|
|
13478
14123
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
13479
|
-
const packages = doctor.discoverPackages(
|
|
14124
|
+
const packages = doctor.discoverPackages(path62.resolve(opts.dir));
|
|
13480
14125
|
const rows = doctor.primitivesCatalog(packages);
|
|
13481
14126
|
const broken = packages.filter((p) => p.error);
|
|
13482
14127
|
if (opts.json) {
|
|
@@ -13489,7 +14134,7 @@ program.command("primitives").description("Deprecated name of `genesis catalog`
|
|
|
13489
14134
|
if (broken.length) process.exitCode = 1;
|
|
13490
14135
|
});
|
|
13491
14136
|
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("--hooks", "Also write the agent hooks into .claude/settings.json: the Genesis rules for Explore and Plan subagents, and deny rules for secret files", false).option("--hook <name>", "Run as a Claude Code hook and print its output (subagent-start); never fails").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
13492
|
-
const root =
|
|
14137
|
+
const root = path62.resolve(opts.dir);
|
|
13493
14138
|
if (opts.hook) {
|
|
13494
14139
|
try {
|
|
13495
14140
|
if (opts.hook === "subagent-start") {
|
|
@@ -13502,7 +14147,7 @@ program.command("agents").description(`Write the agent guide from the installed
|
|
|
13502
14147
|
}
|
|
13503
14148
|
if (opts.rules && opts.check) return program.error("--rules checks the repo, --check the agent guide: run them one at a time");
|
|
13504
14149
|
if (opts.rules) {
|
|
13505
|
-
if (!existsSync(
|
|
14150
|
+
if (!existsSync(path62.join(root, "packages")) && !existsSync(path62.join(root, ".github", "workflows"))) {
|
|
13506
14151
|
return program.error(`--rules checks a repository: ${root} has no packages/ or .github/workflows/. Run it from the repo root or pass --dir.`);
|
|
13507
14152
|
}
|
|
13508
14153
|
const { checkAgentRules: checkAgentRules2 } = await Promise.resolve().then(() => (init_agent_rules(), agent_rules_exports));
|
|
@@ -13587,7 +14232,7 @@ featureOptions(
|
|
|
13587
14232
|
program.command("figma:routes").description("Report drift between this app's routes and its Figma app file (read-only; genesis.config.json figma block, FIGMA_ACCESS_TOKEN)").option("--json", "Print the report as JSON", false).option("--strict", "Exit 1 when a route, hotspot or figma: id is missing", false).option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
13588
14233
|
const figma = await Promise.resolve().then(() => (init_routes2(), routes_exports));
|
|
13589
14234
|
try {
|
|
13590
|
-
const report = await figma.checkFigmaRoutes({ root:
|
|
14235
|
+
const report = await figma.checkFigmaRoutes({ root: path62.resolve(opts.dir) });
|
|
13591
14236
|
console.log(opts.json ? JSON.stringify(report, null, 2) : figma.formatCoverage(report));
|
|
13592
14237
|
process.exitCode = opts.strict && report.summary.missing > 0 ? 1 : 0;
|
|
13593
14238
|
} catch (err) {
|
|
@@ -13599,7 +14244,7 @@ program.command("figma:routes").description("Report drift between this app's rou
|
|
|
13599
14244
|
var upstream = program.command("upstream").description("The app's register of what it needed from Genesis (docs/genesis-upstream.md)");
|
|
13600
14245
|
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) => {
|
|
13601
14246
|
const { checkUpstream: checkUpstream2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
13602
|
-
const result = checkUpstream2(
|
|
14247
|
+
const result = checkUpstream2(path62.resolve(opts.dir));
|
|
13603
14248
|
for (const w of result.warnings) console.warn(`! ${w}`);
|
|
13604
14249
|
for (const p of result.problems) console.error(`\u2717 ${p}`);
|
|
13605
14250
|
if (result.problems.length) process.exitCode = 1;
|
|
@@ -13607,7 +14252,7 @@ upstream.command("check").description("Check docs/genesis-upstream.md: kinds, st
|
|
|
13607
14252
|
});
|
|
13608
14253
|
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) => {
|
|
13609
14254
|
const { checkUpstream: checkUpstream2, exportIssueUrl: exportIssueUrl2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
13610
|
-
const register = checkUpstream2(
|
|
14255
|
+
const register = checkUpstream2(path62.resolve(opts.dir));
|
|
13611
14256
|
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).");
|
|
13612
14257
|
const entry = register.entries.find((e) => e.id === id);
|
|
13613
14258
|
if (!entry) return program.error(`No register entry "${id}" in ${register.file}.`);
|
|
@@ -13617,12 +14262,46 @@ ${own.map((p) => ` ${p}`).join("\n")}`);
|
|
|
13617
14262
|
console.log(`Open this to file it (check it names no app or customer; Genesis is public), then set its status to proposed:
|
|
13618
14263
|
${exportIssueUrl2(entry)}`);
|
|
13619
14264
|
});
|
|
14265
|
+
var client = program.command("client").description("The app's client layer: its own layer over Genesis (ADR 0020)");
|
|
14266
|
+
client.command("init").description("Start the app's client layer: the provider and defaults, its ResourceView wrapper, and a folder per record type").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--folder <folder>", "The layer's folder (default: genesis.config.json's client.dir, else src/client)").option("--type <name>", "A record type to start: <folder>/<type>/view.ts and appearance.tsx").option("--force", "Overwrite files that already exist", false).action(async (opts) => {
|
|
14267
|
+
const { planClientInit: planClientInit2, clientConfigChange: clientConfigChange2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
14268
|
+
const { readGenesisConfig: readGenesisConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
14269
|
+
const root = path62.resolve(opts.dir);
|
|
14270
|
+
const configured = readGenesisConfig2(root);
|
|
14271
|
+
const folder = opts.folder ?? configured?.client?.dir;
|
|
14272
|
+
let plan;
|
|
14273
|
+
let change;
|
|
14274
|
+
try {
|
|
14275
|
+
plan = planClientInit2({ ...folder ? { dir: folder } : {}, ...opts.type ? { type: opts.type } : {} });
|
|
14276
|
+
change = clientConfigChange2(plan.dir, configured?.client?.dir, opts.force);
|
|
14277
|
+
} catch (err) {
|
|
14278
|
+
return program.error(err.message);
|
|
14279
|
+
}
|
|
14280
|
+
for (const file of plan.files) {
|
|
14281
|
+
const target = path62.join(root, file.path);
|
|
14282
|
+
if (existsSync(target) && !opts.force) {
|
|
14283
|
+
console.log(`\xB7 ${file.path} (kept)`);
|
|
14284
|
+
continue;
|
|
14285
|
+
}
|
|
14286
|
+
await fs.mkdir(path62.dirname(target), { recursive: true });
|
|
14287
|
+
await fs.writeFile(target, file.content);
|
|
14288
|
+
console.log(`\u2714 ${file.path}`);
|
|
14289
|
+
}
|
|
14290
|
+
if (change === "write") {
|
|
14291
|
+
const configPath = path62.join(root, "genesis.config.json");
|
|
14292
|
+
const raw = configured?.raw ?? {};
|
|
14293
|
+
await fs.writeFile(configPath, `${JSON.stringify({ ...raw, client: { dir: plan.dir } }, null, 2)}
|
|
14294
|
+
`);
|
|
14295
|
+
console.log("\u2714 genesis.config.json (client.dir)");
|
|
14296
|
+
}
|
|
14297
|
+
for (const step of plan.steps) console.log(`\u2192 ${step}`);
|
|
14298
|
+
});
|
|
13620
14299
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
13621
14300
|
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) => {
|
|
13622
|
-
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (
|
|
13623
|
-
const root =
|
|
13624
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
13625
|
-
const
|
|
14301
|
+
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init2(), init_exports2));
|
|
14302
|
+
const root = path62.resolve(opts.dir);
|
|
14303
|
+
const packageJson = JSON.parse(await fs.readFile(path62.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
14304
|
+
const existsSync47 = (await import('fs')).existsSync;
|
|
13626
14305
|
const readSync = (await import('fs')).readFileSync;
|
|
13627
14306
|
const readdirSync21 = (await import('fs')).readdirSync;
|
|
13628
14307
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
@@ -13631,13 +14310,13 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13631
14310
|
const plan = planStudioInit2(
|
|
13632
14311
|
{
|
|
13633
14312
|
packageJson,
|
|
13634
|
-
exists: (p) =>
|
|
13635
|
-
read: (p) =>
|
|
14313
|
+
exists: (p) => existsSync47(path62.join(root, p)),
|
|
14314
|
+
read: (p) => existsSync47(path62.join(root, p)) ? readSync(path62.join(root, p), "utf-8") : null,
|
|
13636
14315
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
13637
14316
|
listDeep: (p) => {
|
|
13638
14317
|
const out = [];
|
|
13639
14318
|
const walk4 = (rel) => {
|
|
13640
|
-
for (const entry of readdirSync21(
|
|
14319
|
+
for (const entry of readdirSync21(path62.join(root, rel), { withFileTypes: true })) {
|
|
13641
14320
|
const child = `${rel}/${entry.name}`;
|
|
13642
14321
|
if (entry.isDirectory()) walk4(child);
|
|
13643
14322
|
else out.push(child);
|
|
@@ -13651,7 +14330,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13651
14330
|
},
|
|
13652
14331
|
list: (p) => {
|
|
13653
14332
|
try {
|
|
13654
|
-
return readdirSync21(
|
|
14333
|
+
return readdirSync21(path62.join(root, p));
|
|
13655
14334
|
} catch {
|
|
13656
14335
|
return [];
|
|
13657
14336
|
}
|
|
@@ -13660,8 +14339,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13660
14339
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
13661
14340
|
);
|
|
13662
14341
|
for (const file of plan.files) {
|
|
13663
|
-
const target =
|
|
13664
|
-
await fs.mkdir(
|
|
14342
|
+
const target = path62.join(root, file.path);
|
|
14343
|
+
await fs.mkdir(path62.dirname(target), { recursive: true });
|
|
13665
14344
|
if (file.edit) {
|
|
13666
14345
|
await fs.writeFile(target, file.content, "utf-8");
|
|
13667
14346
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -13672,14 +14351,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13672
14351
|
console.log(`+ ${file.path} (appended)`);
|
|
13673
14352
|
continue;
|
|
13674
14353
|
}
|
|
13675
|
-
if (
|
|
14354
|
+
if (existsSync47(target) && !opts.force) {
|
|
13676
14355
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
13677
14356
|
continue;
|
|
13678
14357
|
}
|
|
13679
14358
|
await fs.writeFile(target, file.content, "utf-8");
|
|
13680
14359
|
console.log(`+ ${file.path}`);
|
|
13681
14360
|
}
|
|
13682
|
-
const pm =
|
|
14361
|
+
const pm = existsSync47(path62.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync47(path62.join(root, "yarn.lock")) ? "yarn add" : existsSync47(path62.join(root, "bun.lock")) || existsSync47(path62.join(root, "bun.lockb")) ? "bun add" : "npm install";
|
|
13683
14362
|
console.log("");
|
|
13684
14363
|
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:`);
|
|
13685
14364
|
console.log(` 1. ${pm} ${plan.install.map((p) => /[\s<>|]/.test(p) ? `"${p}"` : p).join(" ")}`);
|
|
@@ -13697,7 +14376,7 @@ async function confirm(question) {
|
|
|
13697
14376
|
}
|
|
13698
14377
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
13699
14378
|
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) => {
|
|
13700
|
-
const root =
|
|
14379
|
+
const root = path62.resolve(opts.dir);
|
|
13701
14380
|
if (opts.list || !block) {
|
|
13702
14381
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
13703
14382
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -13727,7 +14406,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
13727
14406
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
13728
14407
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
13729
14408
|
const report = await runMigrate2({
|
|
13730
|
-
root:
|
|
14409
|
+
root: path62.resolve(opts.dir),
|
|
13731
14410
|
...opts.block ? { blocks: opts.block } : {},
|
|
13732
14411
|
...opts.notifications ? { notifications: opts.notifications } : {},
|
|
13733
14412
|
dryRun: opts.dryRun,
|
|
@@ -13753,7 +14432,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
13753
14432
|
program.command("upgrade").description("Move every @marktiderman/genesis* dependency to one Genesis release, refresh the files Genesis owns and what's generated, 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("--no-agents", "Don't regenerate the agent guide (genesis agents) after").option("--no-features-build", "Don't run features build 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) => {
|
|
13754
14433
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
13755
14434
|
const report = await runUpgrade2({
|
|
13756
|
-
root:
|
|
14435
|
+
root: path62.resolve(opts.dir),
|
|
13757
14436
|
version: opts.version,
|
|
13758
14437
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
13759
14438
|
dryRun: opts.dryRun,
|
|
@@ -13782,10 +14461,10 @@ program.command("codemod [id]").description("Run one of Genesis's codemods by ha
|
|
|
13782
14461
|
}
|
|
13783
14462
|
const mod = codemodById2(id);
|
|
13784
14463
|
if (!mod) throw new Error(`No codemod "${id}". Run genesis codemod to list them.`);
|
|
13785
|
-
const changed = await mod.run({ root:
|
|
14464
|
+
const changed = await mod.run({ root: path62.resolve(opts.dir), dryRun: opts.dryRun, log: (m) => console.log(m) });
|
|
13786
14465
|
console.log(changed.length ? `${opts.dryRun ? "Would change" : "\u2714 Changed"} ${changed.length} file${changed.length === 1 ? "" : "s"}:
|
|
13787
14466
|
${changed.map((f) => ` ${f}`).join("\n")}` : "Nothing to change.");
|
|
13788
|
-
const note = codemodInstallNote2(
|
|
14467
|
+
const note = codemodInstallNote2(path62.resolve(opts.dir), changed, opts.dryRun);
|
|
13789
14468
|
if (note) console.log(`! ${note}`);
|
|
13790
14469
|
});
|
|
13791
14470
|
program.parseAsync(process.argv).catch((err) => {
|
|
@@ -13835,7 +14514,7 @@ function redactUrl(location) {
|
|
|
13835
14514
|
const url = new URL(location);
|
|
13836
14515
|
return `${url.origin}${url.pathname}`;
|
|
13837
14516
|
} catch {
|
|
13838
|
-
return
|
|
14517
|
+
return path62.basename(location);
|
|
13839
14518
|
}
|
|
13840
14519
|
}
|
|
13841
14520
|
//# sourceMappingURL=cli.js.map
|