@marktiderman/genesis-cli 1.27.0 → 1.29.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 +67 -1
- package/dist/cli.js +1274 -424
- 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 +628 -7
- 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 +41 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +636 -15
- package/dist/index.js.map +1 -1
- package/dist/starter/__tests__/starter.test.ts +8 -0
- package/dist/starter/fingerprint.config.js +18 -0
- 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/verify.d.ts +209 -0
- package/dist/verify.js +549 -0
- package/dist/verify.js.map +1 -0
- package/dist/vite.js +628 -7
- package/dist/vite.js.map +1 -1
- package/package.json +18 -4
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync, readdirSync, mkdirSync, writeFileSync, mkdtempSync, rmSync, realpathSync, statSync, lstatSync } from 'fs';
|
|
3
|
-
import * as
|
|
3
|
+
import * as path63 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 = path63.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 = path63.relative(parent, child);
|
|
298
|
+
return rel === "" || !rel.startsWith("..") && !path63.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 = path63.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 = path63.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 = path63.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 = path63.dirname(target);
|
|
345
|
+
while (!there(probe)) probe = path63.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 (${path63.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(path63.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(path63.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 = path63.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(path63.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 (path63.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
397
|
+
const norm = path63.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 = path63.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(path63.join(dir, ".git"))) return dir;
|
|
422
|
+
const parent = path63.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 = path63.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 = path63.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(path63.join(parent, entry));
|
|
442
442
|
}
|
|
443
443
|
} else {
|
|
444
|
-
dirs.add(
|
|
444
|
+
dirs.add(path63.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 = path63.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(`${path63.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 = path63.relative(appRoot, dir).split(path63.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 = path63.dirname(fileURLToPath(import.meta.url));
|
|
507
507
|
for (; ; ) {
|
|
508
|
-
const file =
|
|
508
|
+
const file = path63.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 = path63.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 = path63.resolve(cliPackageDir(), "..");
|
|
517
|
+
return existsSync(path63.join(dir, "features", "package.json")) && existsSync(path63.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 = path63.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 = path63.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(path63.join(dir, m)));
|
|
532
|
+
const scope = path63.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(path63.join(scope, entry, "package.json"))) found.set(name, path63.join(scope, entry));
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
const parent =
|
|
540
|
+
const parent = path63.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(path63.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(path63.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(path63.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 && path63.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(path63.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(path63.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 = path63.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(path63.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 = path63.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 ${path63.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}/${path63.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 (path63.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
1076
|
+
const norm = path63.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 = path63.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 = path63.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
1086
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path63.dirname(file) };
|
|
1086
1087
|
}
|
|
1087
|
-
const own =
|
|
1088
|
+
const own = path63.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 = path63.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 (path63.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 = path63.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 (path63.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 = path63.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 (path63.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 = path63.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(path63.resolve(root))) throw new GenesisConfigError(`${path63.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(path63.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(path63.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 = path63.resolve(from);
|
|
1568
1580
|
for (; ; ) {
|
|
1569
|
-
const candidate =
|
|
1570
|
-
if (existsSync(
|
|
1571
|
-
const parent =
|
|
1581
|
+
const candidate = path63.join(dir, "node_modules", name);
|
|
1582
|
+
if (existsSync(path63.join(candidate, "package.json"))) return candidate;
|
|
1583
|
+
const parent = path63.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(path63.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(path63.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(path63.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(path63.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" ? path63.dirname(path63.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(path63.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 = path63.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(path63.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 = path63.resolve(dir, spec.replace(/\.js$/, ""));
|
|
1782
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path63.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 = path63.relative(path63.resolve(dir), path63.resolve(file));
|
|
1787
|
+
return rel === "" || !rel.startsWith("..") && !path63.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 = path63.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 = path63.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 && path63.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(path63.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 = path63.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 = path63.resolve(root, spec);
|
|
1875
|
+
if (spec.startsWith(".") || path63.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 = path63.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(path63.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 (path64) => res.some((re) => re.test(path64));
|
|
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(path63.relative(root, abs));
|
|
2137
2149
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2138
|
-
const ext =
|
|
2150
|
+
const ext = path63.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(path63.join(dir, entry.name));
|
|
2149
2161
|
} else if (entry.isFile()) {
|
|
2150
|
-
visit(
|
|
2162
|
+
visit(path63.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 = path63.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(path63.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 = path63.relative(path63.resolve(root), path63.resolve(dir)).split(path63.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(path63.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(path63.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 && path63.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(path63.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 = path63.resolve(root);
|
|
2517
2529
|
for (; ; ) {
|
|
2518
|
-
if (existsSync(
|
|
2519
|
-
if (existsSync(
|
|
2520
|
-
if (existsSync(
|
|
2521
|
-
if (existsSync(
|
|
2522
|
-
const parent =
|
|
2530
|
+
if (existsSync(path63.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
2531
|
+
if (existsSync(path63.join(dir, "bun.lock")) || existsSync(path63.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
2532
|
+
if (existsSync(path63.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
2533
|
+
if (existsSync(path63.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
2534
|
+
const parent = path63.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(path63.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(path63.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 && path63.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
2611
|
+
if (live && existsSync(path63.join(live, "package.json"))) return live;
|
|
2612
|
+
const packaged = path63.join(cliPackageDir(), "dist", "starter");
|
|
2613
|
+
if (existsSync(path63.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() ? path63.join(workspace, "..", "templates") : null;
|
|
2619
|
+
if (live && existsSync(path63.join(live, "eas"))) return live;
|
|
2620
|
+
const packaged = path63.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 = path63.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(path63.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(path63.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(path63.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,18 +2868,18 @@ 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 = path63.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 = path63.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: path63.relative(target, dir).split(path63.sep).join("/"), shared: existsSync(path63.join(dir, "supabase")) };
|
|
2867
2879
|
}
|
|
2868
2880
|
const shared = beside?.shared === true;
|
|
2869
2881
|
const source = starterDir();
|
|
2870
|
-
const read3 = (rel) => readFileSync(
|
|
2882
|
+
const read3 = (rel) => readFileSync(path63.join(source, rel), "utf8");
|
|
2871
2883
|
const was = starterIdentity(read3(STARTER_CONFIG));
|
|
2872
2884
|
const switches = parseStarterFeatures(read3(STARTER_CONFIG)) ?? {};
|
|
2873
2885
|
const without = [...new Set(options.without ?? [])];
|
|
@@ -2910,7 +2922,7 @@ 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 = [path63.join(source, "pnpm-workspace.yaml"), path63.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]))));
|
|
@@ -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(path63.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) => path63.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}/${path63.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 = path63.join(target, ...rel.split("/"));
|
|
2986
|
+
mkdirSync(path63.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) => path63.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(path63.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) => path63.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}/${path63.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
|
}
|
|
@@ -3845,7 +3864,7 @@ async function checkContracts(ctx, read3 = postgresContract) {
|
|
|
3845
3864
|
const env = settings2.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
3846
3865
|
let current = null;
|
|
3847
3866
|
try {
|
|
3848
|
-
current = lf(readFileSync(
|
|
3867
|
+
current = lf(readFileSync(path63.join(ctx.root, out), "utf8"));
|
|
3849
3868
|
} catch {
|
|
3850
3869
|
current = null;
|
|
3851
3870
|
}
|
|
@@ -3869,7 +3888,7 @@ async function checkContracts(ctx, read3 = postgresContract) {
|
|
|
3869
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}` });
|
|
3870
3889
|
return;
|
|
3871
3890
|
}
|
|
3872
|
-
const target =
|
|
3891
|
+
const target = path63.relative(process.cwd(), path63.join(ctx.root, out)) || out;
|
|
3873
3892
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
3874
3893
|
if (current !== expected) {
|
|
3875
3894
|
ctx.report({
|
|
@@ -3897,7 +3916,7 @@ __export(settings_exports, {
|
|
|
3897
3916
|
});
|
|
3898
3917
|
function introspectSettings(flags, root, contracts, readCurrent = () => null) {
|
|
3899
3918
|
const out = flags.out ?? contracts?.out ?? DEFAULT_CONTRACT_OUT;
|
|
3900
|
-
const target =
|
|
3919
|
+
const target = path63.resolve(root, out);
|
|
3901
3920
|
return { target, label: out, schemas: schemasFor(flags, target, contracts, readCurrent), databaseEnv: flags.databaseEnv ?? contracts?.databaseEnv ?? DEFAULT_DATABASE_ENV };
|
|
3902
3921
|
}
|
|
3903
3922
|
function schemasFor(flags, target, contracts, readCurrent) {
|
|
@@ -3913,19 +3932,19 @@ var init_settings = __esm({
|
|
|
3913
3932
|
});
|
|
3914
3933
|
function buildCommands(root, config) {
|
|
3915
3934
|
if (config.build) return config.build;
|
|
3916
|
-
const pkgFile =
|
|
3935
|
+
const pkgFile = path63.join(root, "package.json");
|
|
3917
3936
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
3918
3937
|
const pm = packageManager(root);
|
|
3919
3938
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
3920
3939
|
}
|
|
3921
3940
|
function packageManager(root) {
|
|
3922
|
-
let dir =
|
|
3941
|
+
let dir = path63.resolve(root);
|
|
3923
3942
|
for (; ; ) {
|
|
3924
|
-
if (existsSync(
|
|
3925
|
-
if (existsSync(
|
|
3926
|
-
if (existsSync(
|
|
3927
|
-
if (existsSync(
|
|
3928
|
-
const parent =
|
|
3943
|
+
if (existsSync(path63.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
3944
|
+
if (existsSync(path63.join(dir, "bun.lock")) || existsSync(path63.join(dir, "bun.lockb"))) return "bun";
|
|
3945
|
+
if (existsSync(path63.join(dir, "yarn.lock"))) return "yarn";
|
|
3946
|
+
if (existsSync(path63.join(dir, "package-lock.json"))) return "npm";
|
|
3947
|
+
const parent = path63.dirname(dir);
|
|
3929
3948
|
if (parent === dir) return "npm";
|
|
3930
3949
|
dir = parent;
|
|
3931
3950
|
}
|
|
@@ -4023,7 +4042,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
4023
4042
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
4024
4043
|
let all = compiled;
|
|
4025
4044
|
if (rulesDoc) {
|
|
4026
|
-
const file =
|
|
4045
|
+
const file = path63.resolve(root, rulesDoc);
|
|
4027
4046
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
4028
4047
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
4029
4048
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -4091,20 +4110,336 @@ async function loadPlugins(specs, configDir) {
|
|
|
4091
4110
|
}
|
|
4092
4111
|
function resolvePlugin(id, configDir) {
|
|
4093
4112
|
try {
|
|
4094
|
-
if (id.startsWith(".") ||
|
|
4113
|
+
if (id.startsWith(".") || path63.isAbsolute(id)) return resolveFrom(path63.resolve(configDir, id), configDir);
|
|
4095
4114
|
return resolveFrom(id, configDir);
|
|
4096
4115
|
} catch {
|
|
4097
4116
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
4098
4117
|
}
|
|
4099
4118
|
}
|
|
4100
4119
|
function resolveFrom(id, from) {
|
|
4101
|
-
return createRequire(
|
|
4120
|
+
return createRequire(path63.join(from, "noop.js")).resolve(id);
|
|
4102
4121
|
}
|
|
4103
4122
|
var init_plugins = __esm({
|
|
4104
4123
|
"src/doctor/plugins.ts"() {
|
|
4105
4124
|
init_config();
|
|
4106
4125
|
}
|
|
4107
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
|
+
});
|
|
4108
4443
|
function importSpecifiers(file) {
|
|
4109
4444
|
const out = [];
|
|
4110
4445
|
const lines = file.code.split("\n");
|
|
@@ -4116,7 +4451,7 @@ function importSpecifiers(file) {
|
|
|
4116
4451
|
}
|
|
4117
4452
|
function checkProjectLayout(ctx) {
|
|
4118
4453
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
4119
|
-
if (existsSync(
|
|
4454
|
+
if (existsSync(path63.join(ctx.root, dir))) {
|
|
4120
4455
|
ctx.report({
|
|
4121
4456
|
rule: "local-primitives",
|
|
4122
4457
|
file: dir,
|
|
@@ -4126,7 +4461,7 @@ function checkProjectLayout(ctx) {
|
|
|
4126
4461
|
}
|
|
4127
4462
|
}
|
|
4128
4463
|
for (const file of STARTER_LEFTOVERS) {
|
|
4129
|
-
if (existsSync(
|
|
4464
|
+
if (existsSync(path63.join(ctx.root, file))) {
|
|
4130
4465
|
ctx.report({
|
|
4131
4466
|
rule: "starter-leftover",
|
|
4132
4467
|
level: "warn",
|
|
@@ -4214,7 +4549,7 @@ function checkTokens(ctx) {
|
|
|
4214
4549
|
}
|
|
4215
4550
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
4216
4551
|
if (/[*?]/.test(pattern)) continue;
|
|
4217
|
-
const abs =
|
|
4552
|
+
const abs = path63.join(ctx.root, pattern);
|
|
4218
4553
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
4219
4554
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
4220
4555
|
}
|
|
@@ -4235,14 +4570,32 @@ function checkShadowedExports(ctx) {
|
|
|
4235
4570
|
const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
|
|
4236
4571
|
for (const file of ctx.files) {
|
|
4237
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" });
|
|
4238
4574
|
file.code.split("\n").forEach((text, i) => {
|
|
4239
4575
|
for (const m of text.matchAll(re)) {
|
|
4240
4576
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
4577
|
+
if (wrapped.has(m[1])) continue;
|
|
4241
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)` });
|
|
4242
4579
|
}
|
|
4243
4580
|
});
|
|
4244
4581
|
}
|
|
4245
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
|
+
}
|
|
4246
4599
|
function unusedComponents(ctx) {
|
|
4247
4600
|
const used = /* @__PURE__ */ new Set();
|
|
4248
4601
|
const pkg = ctx.genesis.uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
@@ -4263,7 +4616,9 @@ var init_rules = __esm({
|
|
|
4263
4616
|
init_color_literals();
|
|
4264
4617
|
init_glob();
|
|
4265
4618
|
init_genesis();
|
|
4619
|
+
init_js_scan();
|
|
4266
4620
|
init_overlays();
|
|
4621
|
+
init_js_scan();
|
|
4267
4622
|
BUILTIN_RULES = [
|
|
4268
4623
|
"local-primitives",
|
|
4269
4624
|
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
@@ -4351,7 +4706,13 @@ var init_rules = __esm({
|
|
|
4351
4706
|
// custom views and app parts (custom-views.ts)
|
|
4352
4707
|
"app-part-colors",
|
|
4353
4708
|
"app-part-name",
|
|
4354
|
-
"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",
|
|
4713
|
+
// how the app reaches its database (data-access.ts)
|
|
4714
|
+
"data/declared-access",
|
|
4715
|
+
"data/access-rule-tests"
|
|
4355
4716
|
];
|
|
4356
4717
|
DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
4357
4718
|
STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -4436,10 +4797,10 @@ var init_expo = __esm({
|
|
|
4436
4797
|
}
|
|
4437
4798
|
});
|
|
4438
4799
|
function resolveLocal(root, fromFile, spec) {
|
|
4439
|
-
const bases = spec.startsWith(".") ? [
|
|
4800
|
+
const bases = spec.startsWith(".") ? [path63.resolve(path63.dirname(fromFile), spec)] : [path63.join(root, spec.slice(2)), path63.join(root, "src", spec.slice(2))];
|
|
4440
4801
|
for (const base of bases) {
|
|
4441
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
4442
|
-
(p) => SCRIPT_EXTS2.has(
|
|
4802
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path63.join(base, `index${e}`))].find(
|
|
4803
|
+
(p) => SCRIPT_EXTS2.has(path63.extname(p)) && existsSync(p)
|
|
4443
4804
|
);
|
|
4444
4805
|
if (hit) return hit;
|
|
4445
4806
|
}
|
|
@@ -4589,13 +4950,13 @@ function checkNativePack(ctx) {
|
|
|
4589
4950
|
}
|
|
4590
4951
|
function checkEasPlaceholders(ctx) {
|
|
4591
4952
|
const files = [];
|
|
4592
|
-
if (existsSync(
|
|
4593
|
-
const workflows =
|
|
4953
|
+
if (existsSync(path63.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
4954
|
+
const workflows = path63.join(ctx.root, ".eas", "workflows");
|
|
4594
4955
|
if (existsSync(workflows)) {
|
|
4595
4956
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
4596
4957
|
}
|
|
4597
4958
|
for (const file of files) {
|
|
4598
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
4959
|
+
for (const hit of findPlaceholders(file, readFileSync(path63.join(ctx.root, file), "utf8"))) {
|
|
4599
4960
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
4600
4961
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
4601
4962
|
ctx.report({
|
|
@@ -4673,7 +5034,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
4673
5034
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
4674
5035
|
const code = file.code;
|
|
4675
5036
|
const hidden = HIDES_HEADER.exec(code);
|
|
4676
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
5037
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path63.posix.dirname(file.path), file.path);
|
|
4677
5038
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
4678
5039
|
if (hidden && own) {
|
|
4679
5040
|
reported.add(file.path);
|
|
@@ -4701,7 +5062,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
4701
5062
|
}
|
|
4702
5063
|
for (const file of ctx.files) {
|
|
4703
5064
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
4704
|
-
const layout = hidingLayouts.get(
|
|
5065
|
+
const layout = hidingLayouts.get(path63.posix.dirname(file.path));
|
|
4705
5066
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
4706
5067
|
if (!layout || !own) continue;
|
|
4707
5068
|
ctx.report({
|
|
@@ -4722,13 +5083,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
4722
5083
|
}
|
|
4723
5084
|
function routerRoot(ctx) {
|
|
4724
5085
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
4725
|
-
return existsSync(
|
|
5086
|
+
return existsSync(path63.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
4726
5087
|
}
|
|
4727
5088
|
function checkScreenLayouts(ctx, pkg) {
|
|
4728
5089
|
const layouts = nativeLayouts(pkg);
|
|
4729
5090
|
if (layouts.length === 0) return;
|
|
4730
5091
|
const rootDir = routerRoot(ctx);
|
|
4731
|
-
if (!existsSync(
|
|
5092
|
+
if (!existsSync(path63.join(ctx.root, rootDir))) {
|
|
4732
5093
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
4733
5094
|
return;
|
|
4734
5095
|
}
|
|
@@ -4765,7 +5126,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
4765
5126
|
function readExpoConfigs(root) {
|
|
4766
5127
|
const out = [];
|
|
4767
5128
|
for (const name of EXPO_CONFIGS) {
|
|
4768
|
-
const abs =
|
|
5129
|
+
const abs = path63.join(root, name);
|
|
4769
5130
|
if (!existsSync(abs)) continue;
|
|
4770
5131
|
const text = readFileSync(abs, "utf8");
|
|
4771
5132
|
let json = null;
|
|
@@ -4799,13 +5160,13 @@ function pluginOptions(json, module) {
|
|
|
4799
5160
|
return null;
|
|
4800
5161
|
}
|
|
4801
5162
|
function dependencies(root) {
|
|
4802
|
-
const file =
|
|
5163
|
+
const file = path63.join(root, "package.json");
|
|
4803
5164
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
4804
5165
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
4805
5166
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
4806
5167
|
}
|
|
4807
5168
|
function runtimeDependencies(root) {
|
|
4808
|
-
const file =
|
|
5169
|
+
const file = path63.join(root, "package.json");
|
|
4809
5170
|
if (!existsSync(file)) return {};
|
|
4810
5171
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
4811
5172
|
}
|
|
@@ -5094,14 +5455,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
5094
5455
|
seen.add(file);
|
|
5095
5456
|
const json = readJsonc(file);
|
|
5096
5457
|
if (!json) return {};
|
|
5097
|
-
const dir =
|
|
5458
|
+
const dir = path63.dirname(file);
|
|
5098
5459
|
let merged = {};
|
|
5099
5460
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
5100
5461
|
for (const ext of parents) {
|
|
5101
5462
|
if (typeof ext !== "string") continue;
|
|
5102
5463
|
let target = null;
|
|
5103
|
-
if (ext.startsWith(".") ||
|
|
5104
|
-
const abs =
|
|
5464
|
+
if (ext.startsWith(".") || path63.isAbsolute(ext)) {
|
|
5465
|
+
const abs = path63.resolve(dir, ext);
|
|
5105
5466
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
5106
5467
|
} else {
|
|
5107
5468
|
const parts = ext.split("/");
|
|
@@ -5109,14 +5470,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
5109
5470
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
5110
5471
|
if (pkgDir) {
|
|
5111
5472
|
const sub = parts.slice(nameLength).join("/");
|
|
5112
|
-
const abs =
|
|
5473
|
+
const abs = path63.join(pkgDir, sub || "tsconfig.json");
|
|
5113
5474
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
5114
5475
|
}
|
|
5115
5476
|
}
|
|
5116
5477
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
5117
5478
|
}
|
|
5118
5479
|
const opts = json.compilerOptions ?? {};
|
|
5119
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
5480
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path63.resolve(dir, opts.baseUrl);
|
|
5120
5481
|
if (opts.paths && typeof opts.paths === "object") {
|
|
5121
5482
|
merged.paths = opts.paths;
|
|
5122
5483
|
merged.pathsDir = dir;
|
|
@@ -5127,7 +5488,7 @@ function aliases(root) {
|
|
|
5127
5488
|
const table = [];
|
|
5128
5489
|
let baseUrl = null;
|
|
5129
5490
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
5130
|
-
const file =
|
|
5491
|
+
const file = path63.join(root, name);
|
|
5131
5492
|
if (!existsSync(file)) continue;
|
|
5132
5493
|
const config = readTsconfig(root, file);
|
|
5133
5494
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -5135,22 +5496,22 @@ function aliases(root) {
|
|
|
5135
5496
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
5136
5497
|
if (!Array.isArray(targets)) continue;
|
|
5137
5498
|
const exact = !pattern.endsWith("*");
|
|
5138
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
5499
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path63.join(base, String(t).replace(/\*$/, ""))) });
|
|
5139
5500
|
}
|
|
5140
5501
|
}
|
|
5141
|
-
const pkg = readJsonc(
|
|
5502
|
+
const pkg = readJsonc(path63.join(root, "package.json"));
|
|
5142
5503
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
5143
5504
|
if (typeof target !== "string") continue;
|
|
5144
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
5505
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path63.join(root, target.replace(/\*.*$/, ""))] });
|
|
5145
5506
|
}
|
|
5146
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
5507
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path63.join(root, "src") + path63.sep, root + path63.sep] });
|
|
5147
5508
|
return { table, baseUrl };
|
|
5148
5509
|
}
|
|
5149
5510
|
function resolveFile(base) {
|
|
5150
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
5511
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path63.join(base, `index${e}`))];
|
|
5151
5512
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
5152
5513
|
for (const p of tries) {
|
|
5153
|
-
if (SCRIPT_EXTS2.has(
|
|
5514
|
+
if (SCRIPT_EXTS2.has(path63.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
5154
5515
|
}
|
|
5155
5516
|
return null;
|
|
5156
5517
|
}
|
|
@@ -5163,7 +5524,7 @@ function createTrail(ctx) {
|
|
|
5163
5524
|
const { table, baseUrl } = aliases(ctx.root);
|
|
5164
5525
|
let declared = null;
|
|
5165
5526
|
try {
|
|
5166
|
-
const pkg = JSON.parse(readFileSync(
|
|
5527
|
+
const pkg = JSON.parse(readFileSync(path63.join(ctx.root, "package.json"), "utf8"));
|
|
5167
5528
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
5168
5529
|
} catch {
|
|
5169
5530
|
declared = null;
|
|
@@ -5194,17 +5555,17 @@ function createTrail(ctx) {
|
|
|
5194
5555
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
5195
5556
|
let resolved = null;
|
|
5196
5557
|
if (spec.startsWith(".")) {
|
|
5197
|
-
resolved = resolveFile(
|
|
5558
|
+
resolved = resolveFile(path63.resolve(path63.dirname(file.absolutePath), spec));
|
|
5198
5559
|
if (!resolved) lost = true;
|
|
5199
5560
|
} else {
|
|
5200
5561
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
5201
5562
|
if (alias) {
|
|
5202
5563
|
for (const t of alias.targets) {
|
|
5203
|
-
resolved = resolveFile(alias.exact ? t :
|
|
5564
|
+
resolved = resolveFile(alias.exact ? t : path63.join(t, spec.slice(alias.prefix.length)));
|
|
5204
5565
|
if (resolved) break;
|
|
5205
5566
|
}
|
|
5206
5567
|
}
|
|
5207
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
5568
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path63.join(baseUrl, spec));
|
|
5208
5569
|
if (!resolved) {
|
|
5209
5570
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
5210
5571
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -5290,7 +5651,7 @@ var init_trail = __esm({
|
|
|
5290
5651
|
});
|
|
5291
5652
|
function routesDir(ctx) {
|
|
5292
5653
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
5293
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
5654
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path63.join(ctx.root, d))) ?? null;
|
|
5294
5655
|
}
|
|
5295
5656
|
function flavorOf(dir, rels) {
|
|
5296
5657
|
const stems = rels.map((r) => r.split("/").pop());
|
|
@@ -5431,7 +5792,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
5431
5792
|
});
|
|
5432
5793
|
if (typeof raw === "string") {
|
|
5433
5794
|
if (!packageDir2) fail(`points at ${raw}, but the package folder is unknown`);
|
|
5434
|
-
const file =
|
|
5795
|
+
const file = path63.resolve(packageDir2, raw);
|
|
5435
5796
|
if (!inside(packageDir2, file)) fail(`points outside the package (${raw})`);
|
|
5436
5797
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
5437
5798
|
let parsed;
|
|
@@ -5480,7 +5841,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
5480
5841
|
if (typeof c.plugin === "string") {
|
|
5481
5842
|
if (!packageDir2) plugin = c.plugin;
|
|
5482
5843
|
else {
|
|
5483
|
-
plugin =
|
|
5844
|
+
plugin = path63.resolve(packageDir2, c.plugin);
|
|
5484
5845
|
if (!inside(packageDir2, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
5485
5846
|
}
|
|
5486
5847
|
}
|
|
@@ -5533,7 +5894,7 @@ function checkPattern(v, where2, fail) {
|
|
|
5533
5894
|
}
|
|
5534
5895
|
}
|
|
5535
5896
|
function readDeclaringPackage(dir, local) {
|
|
5536
|
-
const file =
|
|
5897
|
+
const file = path63.join(dir, "package.json");
|
|
5537
5898
|
let stamp;
|
|
5538
5899
|
let real2;
|
|
5539
5900
|
try {
|
|
@@ -5556,7 +5917,7 @@ ${local}`;
|
|
|
5556
5917
|
const pkg = {
|
|
5557
5918
|
name: json.name,
|
|
5558
5919
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
5559
|
-
dir:
|
|
5920
|
+
dir: path63.resolve(dir),
|
|
5560
5921
|
namespace: ruleNamespace(json.name),
|
|
5561
5922
|
local,
|
|
5562
5923
|
private: json.private === true,
|
|
@@ -5570,7 +5931,7 @@ ${local}`;
|
|
|
5570
5931
|
if (raw !== void 0) {
|
|
5571
5932
|
const ignored = [];
|
|
5572
5933
|
try {
|
|
5573
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
5934
|
+
pkg.declaration = validateDeclaration(raw, json.name, path63.resolve(dir), ignored);
|
|
5574
5935
|
if (ignored.length) pkg.ignored = ignored;
|
|
5575
5936
|
} catch (err) {
|
|
5576
5937
|
pkg.error = err.message;
|
|
@@ -5589,14 +5950,14 @@ function discoverPackages(root) {
|
|
|
5589
5950
|
for (const dir of installed) {
|
|
5590
5951
|
let scope;
|
|
5591
5952
|
try {
|
|
5592
|
-
scope =
|
|
5953
|
+
scope = path63.dirname(realpathSync(dir));
|
|
5593
5954
|
} catch {
|
|
5594
5955
|
continue;
|
|
5595
5956
|
}
|
|
5596
|
-
if (
|
|
5957
|
+
if (path63.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
5597
5958
|
for (const entry of readdirSync(scope)) {
|
|
5598
5959
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
5599
|
-
const pkg = readDeclaringPackage(
|
|
5960
|
+
const pkg = readDeclaringPackage(path63.join(scope, entry), false);
|
|
5600
5961
|
if (pkg) byName.set(pkg.name, pkg);
|
|
5601
5962
|
}
|
|
5602
5963
|
}
|
|
@@ -5837,10 +6198,10 @@ var init_package_rules = __esm({
|
|
|
5837
6198
|
});
|
|
5838
6199
|
function sourceFiles(dir, rel = "") {
|
|
5839
6200
|
const out = [];
|
|
5840
|
-
for (const entry of readdirSync(
|
|
6201
|
+
for (const entry of readdirSync(path63.join(dir, rel)).sort()) {
|
|
5841
6202
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
5842
6203
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
5843
|
-
const stat = lstatSync(
|
|
6204
|
+
const stat = lstatSync(path63.join(dir, child));
|
|
5844
6205
|
if (stat.isSymbolicLink()) continue;
|
|
5845
6206
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
5846
6207
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -5863,13 +6224,13 @@ function matchPattern(pattern, spec) {
|
|
|
5863
6224
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
5864
6225
|
}
|
|
5865
6226
|
function tsconfigPaths(dir) {
|
|
5866
|
-
const file =
|
|
6227
|
+
const file = path63.join(dir, "tsconfig.json");
|
|
5867
6228
|
if (!existsSync(file)) return [];
|
|
5868
6229
|
try {
|
|
5869
6230
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
5870
6231
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
5871
|
-
const base =
|
|
5872
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
6232
|
+
const base = path63.resolve(dir, options.baseUrl ?? ".");
|
|
6233
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path63.resolve(base, t)) }));
|
|
5873
6234
|
} catch {
|
|
5874
6235
|
return [];
|
|
5875
6236
|
}
|
|
@@ -5883,8 +6244,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5883
6244
|
const hit = matchPattern(pattern, spec);
|
|
5884
6245
|
if (hit === null) continue;
|
|
5885
6246
|
return targets.some((t) => {
|
|
5886
|
-
const rel =
|
|
5887
|
-
return !rel.startsWith("..") && !
|
|
6247
|
+
const rel = path63.relative(pkg.dir, t.replace("*", hit));
|
|
6248
|
+
return !rel.startsWith("..") && !path63.isAbsolute(rel);
|
|
5888
6249
|
});
|
|
5889
6250
|
}
|
|
5890
6251
|
return null;
|
|
@@ -5897,7 +6258,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5897
6258
|
...Object.keys(json.optionalDependencies ?? {})
|
|
5898
6259
|
]);
|
|
5899
6260
|
for (const file of sourceFiles(pkg.dir)) {
|
|
5900
|
-
const code = stripForImports(readFileSync(
|
|
6261
|
+
const code = stripForImports(readFileSync(path63.join(pkg.dir, file), "utf8"));
|
|
5901
6262
|
if (code === null) continue;
|
|
5902
6263
|
const at = `${pkg.rel}/${file}`;
|
|
5903
6264
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -5922,9 +6283,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
5922
6283
|
continue;
|
|
5923
6284
|
}
|
|
5924
6285
|
if (spec.startsWith(".")) {
|
|
5925
|
-
const target =
|
|
5926
|
-
const rel =
|
|
5927
|
-
if (rel.startsWith("..") ||
|
|
6286
|
+
const target = path63.resolve(pkg.dir, path63.dirname(file), spec);
|
|
6287
|
+
const rel = path63.relative(pkg.dir, target);
|
|
6288
|
+
if (rel.startsWith("..") || path63.isAbsolute(rel)) {
|
|
5928
6289
|
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` });
|
|
5929
6290
|
}
|
|
5930
6291
|
continue;
|
|
@@ -5960,12 +6321,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5960
6321
|
const from = own ? "" : ` (in ${m.package})`;
|
|
5961
6322
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
5962
6323
|
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` });
|
|
5963
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
6324
|
+
} else if (typeof m.test === "string" && !existsSync(path63.join(home, m.test))) {
|
|
5964
6325
|
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` });
|
|
5965
6326
|
}
|
|
5966
6327
|
}
|
|
5967
6328
|
}
|
|
5968
|
-
const dir =
|
|
6329
|
+
const dir = path63.join(pkg.dir, "migrations");
|
|
5969
6330
|
if (!existsSync(dir)) return;
|
|
5970
6331
|
const seen = /* @__PURE__ */ new Map();
|
|
5971
6332
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -5974,7 +6335,7 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
5974
6335
|
const other = seen.get(m[1]);
|
|
5975
6336
|
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` });
|
|
5976
6337
|
else seen.set(m[1], name);
|
|
5977
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
6338
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path63.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
5978
6339
|
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")})` });
|
|
5979
6340
|
}
|
|
5980
6341
|
}
|
|
@@ -5988,7 +6349,7 @@ function checkExports(ctx, pkg, json) {
|
|
|
5988
6349
|
walk4(json.exports);
|
|
5989
6350
|
for (const t of targets) {
|
|
5990
6351
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
5991
|
-
if (!existsSync(
|
|
6352
|
+
if (!existsSync(path63.join(pkg.dir, t))) {
|
|
5992
6353
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
5993
6354
|
}
|
|
5994
6355
|
}
|
|
@@ -6006,11 +6367,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
6006
6367
|
function checkTaggedTests(ctx, pkg) {
|
|
6007
6368
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
6008
6369
|
if (!tests.length) return;
|
|
6009
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
6370
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path63.join(pkg.dir, f), "utf8")));
|
|
6010
6371
|
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>` });
|
|
6011
6372
|
}
|
|
6012
6373
|
function checkRegistered(ctx, pkg) {
|
|
6013
|
-
const file =
|
|
6374
|
+
const file = path63.join(ctx.root, "features.json");
|
|
6014
6375
|
if (!existsSync(file)) return;
|
|
6015
6376
|
let doc;
|
|
6016
6377
|
try {
|
|
@@ -6020,7 +6381,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
6020
6381
|
}
|
|
6021
6382
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
6022
6383
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
6023
|
-
if (top) forms.add(
|
|
6384
|
+
if (top) forms.add(path63.relative(top, realpathSync(pkg.dir)).split(path63.sep).join("/"));
|
|
6024
6385
|
const covered = (doc.features ?? []).some(
|
|
6025
6386
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
6026
6387
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -6050,8 +6411,8 @@ function mergeBaseOf(root, base) {
|
|
|
6050
6411
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
6051
6412
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
6052
6413
|
if (!top) return;
|
|
6053
|
-
const appRelative = (fromTop) =>
|
|
6054
|
-
const inRepo =
|
|
6414
|
+
const appRelative = (fromTop) => path63.relative(realpathSync(ctx.root), path63.join(top, fromTop)).split(path63.sep).join("/");
|
|
6415
|
+
const inRepo = path63.relative(top, realpathSync(pkg.dir)).split(path63.sep).join("/");
|
|
6055
6416
|
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");
|
|
6056
6417
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
6057
6418
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -6074,11 +6435,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
6074
6435
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
6075
6436
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
6076
6437
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
6077
|
-
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) =>
|
|
6438
|
+
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) => path63.join(top, f)) : [];
|
|
6078
6439
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
6079
6440
|
const named = naming.length > 0;
|
|
6080
6441
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
6081
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
6442
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path63.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
6082
6443
|
}
|
|
6083
6444
|
let jsonBefore = null;
|
|
6084
6445
|
try {
|
|
@@ -6088,7 +6449,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
6088
6449
|
}
|
|
6089
6450
|
const raw = json;
|
|
6090
6451
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
6091
|
-
const appInRepo =
|
|
6452
|
+
const appInRepo = path63.relative(top, realpathSync(ctx.root)).split(path63.sep).join("/");
|
|
6092
6453
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
6093
6454
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
6094
6455
|
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` });
|
|
@@ -6139,7 +6500,7 @@ function checkPackagesPack(ctx) {
|
|
|
6139
6500
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
6140
6501
|
}
|
|
6141
6502
|
for (const pkg of packages) {
|
|
6142
|
-
const json = JSON.parse(readFileSync(
|
|
6503
|
+
const json = JSON.parse(readFileSync(path63.join(pkg.dir, "package.json"), "utf8"));
|
|
6143
6504
|
checkImports2(ctx, pkg, json);
|
|
6144
6505
|
checkExports(ctx, pkg, json);
|
|
6145
6506
|
checkBlocks(ctx, pkg, json);
|
|
@@ -6338,9 +6699,9 @@ function checkSupabasePack(ctx) {
|
|
|
6338
6699
|
if (databaseElsewhere(ctx.root)) return;
|
|
6339
6700
|
const settings2 = ctx.config.supabase ?? {};
|
|
6340
6701
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
6341
|
-
const abs =
|
|
6702
|
+
const abs = path63.join(ctx.root, dir);
|
|
6342
6703
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
6343
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
6704
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path63.join(abs, n), "utf8")) }));
|
|
6344
6705
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
6345
6706
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
6346
6707
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -6357,7 +6718,7 @@ function checkSupabasePack(ctx) {
|
|
|
6357
6718
|
}
|
|
6358
6719
|
}
|
|
6359
6720
|
const since = settings2.since;
|
|
6360
|
-
const afterSince = (file) => since === void 0 ||
|
|
6721
|
+
const afterSince = (file) => since === void 0 || path63.posix.basename(file) >= since;
|
|
6361
6722
|
if ("reason" in view && since === void 0) {
|
|
6362
6723
|
ctx.report({
|
|
6363
6724
|
rule: "migration-grants",
|
|
@@ -6411,8 +6772,8 @@ function checkExposedSchemasCreatedLater(ctx, dir, migrations, configured, branc
|
|
|
6411
6772
|
if (m && m[1] !== "authorization" && !created.has(m[1])) created.set(m[1], { file, line });
|
|
6412
6773
|
}
|
|
6413
6774
|
}
|
|
6414
|
-
const tomlFile =
|
|
6415
|
-
const tomlText = existsSync(
|
|
6775
|
+
const tomlFile = path63.posix.join(path63.posix.dirname(dir), "config.toml");
|
|
6776
|
+
const tomlText = existsSync(path63.join(ctx.root, tomlFile)) ? readFileSync(path63.join(ctx.root, tomlFile), "utf8") : null;
|
|
6416
6777
|
const api2 = tomlText === null ? null : apiSchemas(tomlText);
|
|
6417
6778
|
const sources = [];
|
|
6418
6779
|
if (api2?.enabled) for (const schema of api2.schemas) sources.push({ schema, file: tomlFile, line: api2.line, where: `${tomlFile} [api] schemas` });
|
|
@@ -6719,18 +7080,18 @@ var init_supabase = __esm({
|
|
|
6719
7080
|
}
|
|
6720
7081
|
});
|
|
6721
7082
|
function nodeModulesOf(dir) {
|
|
6722
|
-
const parent =
|
|
6723
|
-
return
|
|
7083
|
+
const parent = path63.dirname(dir);
|
|
7084
|
+
return path63.basename(parent).startsWith("@") ? path63.dirname(parent) : parent;
|
|
6724
7085
|
}
|
|
6725
7086
|
function packagesIn(nodeModules) {
|
|
6726
7087
|
if (!existsSync(nodeModules)) return [];
|
|
6727
7088
|
const out = [];
|
|
6728
7089
|
for (const entry of readdirSync(nodeModules)) {
|
|
6729
7090
|
if (entry.startsWith(".")) continue;
|
|
6730
|
-
const p =
|
|
7091
|
+
const p = path63.join(nodeModules, entry);
|
|
6731
7092
|
if (entry.startsWith("@")) {
|
|
6732
7093
|
try {
|
|
6733
|
-
for (const sub of readdirSync(p)) out.push(
|
|
7094
|
+
for (const sub of readdirSync(p)) out.push(path63.join(p, sub));
|
|
6734
7095
|
} catch {
|
|
6735
7096
|
}
|
|
6736
7097
|
} else {
|
|
@@ -6742,7 +7103,7 @@ function packagesIn(nodeModules) {
|
|
|
6742
7103
|
function genesisInstalls(root) {
|
|
6743
7104
|
const copies = /* @__PURE__ */ new Map();
|
|
6744
7105
|
const realRoot = real(root);
|
|
6745
|
-
const rel = (abs) =>
|
|
7106
|
+
const rel = (abs) => path63.relative(realRoot, abs).split(path63.sep).join("/") || ".";
|
|
6746
7107
|
const via = /* @__PURE__ */ new Map();
|
|
6747
7108
|
const record = (real2, manifest, by, range, root2) => {
|
|
6748
7109
|
let copy = copies.get(real2);
|
|
@@ -6787,7 +7148,7 @@ function genesisInstalls(root) {
|
|
|
6787
7148
|
if (!dir) return null;
|
|
6788
7149
|
if (!ownInstall || name in declared) return dir;
|
|
6789
7150
|
const realDir = real(dir);
|
|
6790
|
-
if (realDir.startsWith(realRoot +
|
|
7151
|
+
if (realDir.startsWith(realRoot + path63.sep)) return dir;
|
|
6791
7152
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
6792
7153
|
};
|
|
6793
7154
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -6795,7 +7156,7 @@ function genesisInstalls(root) {
|
|
|
6795
7156
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
6796
7157
|
});
|
|
6797
7158
|
const app = readManifest(root);
|
|
6798
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
7159
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path63.join(root, f)));
|
|
6799
7160
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
6800
7161
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
6801
7162
|
const runtimeDeps = {
|
|
@@ -6806,11 +7167,11 @@ function genesisInstalls(root) {
|
|
|
6806
7167
|
};
|
|
6807
7168
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
6808
7169
|
walk4("runtime", rootsOf(runtimeDeps, "the app"));
|
|
6809
|
-
const top =
|
|
7170
|
+
const top = path63.join(root, "node_modules");
|
|
6810
7171
|
walk4(
|
|
6811
7172
|
"hoisted",
|
|
6812
7173
|
packagesIn(top).filter((dir) => {
|
|
6813
|
-
const name =
|
|
7174
|
+
const name = path63.relative(top, dir).split(path63.sep).join("/");
|
|
6814
7175
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
6815
7176
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
6816
7177
|
);
|
|
@@ -6852,7 +7213,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
6852
7213
|
}
|
|
6853
7214
|
}
|
|
6854
7215
|
function checkPeerRanges(ctx) {
|
|
6855
|
-
const rel = (abs) =>
|
|
7216
|
+
const rel = (abs) => path63.relative(ctx.root, abs).split(path63.sep).join("/");
|
|
6856
7217
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
6857
7218
|
for (const copy of copies) {
|
|
6858
7219
|
const dir = copy.absolutePath;
|
|
@@ -6885,7 +7246,7 @@ var init_installs = __esm({
|
|
|
6885
7246
|
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)$/;
|
|
6886
7247
|
readManifest = (dir) => {
|
|
6887
7248
|
try {
|
|
6888
|
-
return JSON.parse(readFileSync(
|
|
7249
|
+
return JSON.parse(readFileSync(path63.join(dir, "package.json"), "utf8"));
|
|
6889
7250
|
} catch {
|
|
6890
7251
|
return null;
|
|
6891
7252
|
}
|
|
@@ -7084,11 +7445,11 @@ function appScripts(root) {
|
|
|
7084
7445
|
const out = [];
|
|
7085
7446
|
const walk4 = (dir) => {
|
|
7086
7447
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
7087
|
-
const abs =
|
|
7448
|
+
const abs = path63.join(dir, entry.name);
|
|
7088
7449
|
if (entry.isDirectory()) {
|
|
7089
7450
|
if (!SKIP_DIRS3.has(entry.name)) walk4(abs);
|
|
7090
7451
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
7091
|
-
out.push(
|
|
7452
|
+
out.push(path63.relative(root, abs).split(path63.sep).join("/"));
|
|
7092
7453
|
}
|
|
7093
7454
|
}
|
|
7094
7455
|
};
|
|
@@ -7401,7 +7762,7 @@ var init_doctor_rule_codemods = __esm({
|
|
|
7401
7762
|
run({ root, dryRun, log }) {
|
|
7402
7763
|
const changed = [];
|
|
7403
7764
|
for (const rel of appScripts(root).filter((f) => /\.[jt]sx$/.test(f))) {
|
|
7404
|
-
const abs =
|
|
7765
|
+
const abs = path63.join(root, rel);
|
|
7405
7766
|
const text = readFileSync(abs, "utf8");
|
|
7406
7767
|
const next = rewriteOverlayHeights(text);
|
|
7407
7768
|
if (next === text) continue;
|
|
@@ -7428,7 +7789,7 @@ var init_doctor_rule_codemods = __esm({
|
|
|
7428
7789
|
const changed = [];
|
|
7429
7790
|
for (const rel of appScripts(root)) {
|
|
7430
7791
|
if (/(?:^|\/)__tests__\/|\.test\.[jt]sx?$/.test(rel)) continue;
|
|
7431
|
-
const abs =
|
|
7792
|
+
const abs = path63.join(root, rel);
|
|
7432
7793
|
const text = readFileSync(abs, "utf8");
|
|
7433
7794
|
if (!text.includes("expo-haptics")) continue;
|
|
7434
7795
|
const result = rewriteHaptics(text);
|
|
@@ -7644,11 +8005,11 @@ var init_scope_names = __esm({
|
|
|
7644
8005
|
}
|
|
7645
8006
|
});
|
|
7646
8007
|
function findEslintConfig(root) {
|
|
7647
|
-
return FLAT_CONFIG_FILES.find((name) => existsSync(
|
|
8008
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path63.join(root, name))) ?? null;
|
|
7648
8009
|
}
|
|
7649
8010
|
function readPackageJson(root) {
|
|
7650
8011
|
try {
|
|
7651
|
-
return JSON.parse(readFileSync(
|
|
8012
|
+
return JSON.parse(readFileSync(path63.join(root, "package.json"), "utf8"));
|
|
7652
8013
|
} catch {
|
|
7653
8014
|
return null;
|
|
7654
8015
|
}
|
|
@@ -7705,7 +8066,7 @@ function spreadLine(platform, local = "genesis") {
|
|
|
7705
8066
|
}
|
|
7706
8067
|
function addGenesisLint(text, platform, file = "eslint.config.js") {
|
|
7707
8068
|
const code = maskCode(text);
|
|
7708
|
-
const ext =
|
|
8069
|
+
const ext = path63.extname(file);
|
|
7709
8070
|
const exportsCjs = [...code.matchAll(/(?:^|[\n;])\s*module\.exports\s*=\s*/g)];
|
|
7710
8071
|
const exportsEsm = [...code.matchAll(/(?:^|[\n;])\s*export\s+default\s+/g)];
|
|
7711
8072
|
const kind = ext === ".cjs" || ext === ".cts" ? "cjs" : ext === ".mjs" || ext === ".mts" ? "esm" : exportsCjs.length && !exportsEsm.length ? "cjs" : "esm";
|
|
@@ -7877,7 +8238,7 @@ var init_codemods = __esm({
|
|
|
7877
8238
|
let readsId = false;
|
|
7878
8239
|
let augmented = false;
|
|
7879
8240
|
for (const rel of appScripts(root)) {
|
|
7880
|
-
const abs =
|
|
8241
|
+
const abs = path63.join(root, rel);
|
|
7881
8242
|
const text = readFileSync(abs, "utf8");
|
|
7882
8243
|
if (augmentsResourceScope(text)) augmented = true;
|
|
7883
8244
|
if (!IMPORTS_GENESIS.test(text)) continue;
|
|
@@ -7905,7 +8266,7 @@ var init_codemods = __esm({
|
|
|
7905
8266
|
const changed = [];
|
|
7906
8267
|
const pkg = readPackageJson(root);
|
|
7907
8268
|
const platform = appPlatform(pkg);
|
|
7908
|
-
const abs =
|
|
8269
|
+
const abs = path63.join(root, file);
|
|
7909
8270
|
const text = readFileSync(abs, "utf8");
|
|
7910
8271
|
if (!usesGenesisLint(text)) {
|
|
7911
8272
|
const result = addGenesisLint(text, platform, file);
|
|
@@ -7921,7 +8282,7 @@ ${manualLines(result.kind, platform).map((l) => ` ${l}`).join("\n")}`);
|
|
|
7921
8282
|
}
|
|
7922
8283
|
}
|
|
7923
8284
|
if (platform === "native" && pkg && !hasTestingLibrary(pkg)) {
|
|
7924
|
-
const pkgFile =
|
|
8285
|
+
const pkgFile = path63.join(root, "package.json");
|
|
7925
8286
|
const raw = readFileSync(pkgFile, "utf8");
|
|
7926
8287
|
const indent = /^[ \t]+(?=")/m.exec(raw)?.[0] ?? " ";
|
|
7927
8288
|
const json = JSON.parse(raw);
|
|
@@ -7944,7 +8305,7 @@ ${manualLines(result.kind, platform).map((l) => ` ${l}`).join("\n")}`);
|
|
|
7944
8305
|
run({ root, dryRun }) {
|
|
7945
8306
|
const changed = [];
|
|
7946
8307
|
for (const rel of appScripts(root)) {
|
|
7947
|
-
const abs =
|
|
8308
|
+
const abs = path63.join(root, rel);
|
|
7948
8309
|
const text = readFileSync(abs, "utf8");
|
|
7949
8310
|
if (!text.includes("NativeComposerBar")) continue;
|
|
7950
8311
|
const next = rewriteComposerBarEmpty(text);
|
|
@@ -8034,7 +8395,7 @@ function checkTreeViews(ctx) {
|
|
|
8034
8395
|
function moduleFiles(ctx) {
|
|
8035
8396
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
8036
8397
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
8037
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
8398
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path63.join(ctx.root, rel), "utf8"), true) }));
|
|
8038
8399
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
8039
8400
|
}
|
|
8040
8401
|
function checkStudioServerImports(ctx) {
|
|
@@ -8064,7 +8425,7 @@ function checkStudioServerImports(ctx) {
|
|
|
8064
8425
|
}
|
|
8065
8426
|
function checkRemovedScopeNames(ctx) {
|
|
8066
8427
|
let augmentedMemo;
|
|
8067
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
8428
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path63.join(ctx.root, rel), "utf8")));
|
|
8068
8429
|
for (const file of ctx.files) {
|
|
8069
8430
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
8070
8431
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -8185,6 +8546,285 @@ var init_custom_views = __esm({
|
|
|
8185
8546
|
VARIABLE = /var\(\s*(--[A-Za-z0-9_-]+)/g;
|
|
8186
8547
|
}
|
|
8187
8548
|
});
|
|
8549
|
+
function clientLayer(root, files) {
|
|
8550
|
+
let dir = DEFAULT_CLIENT_DIR;
|
|
8551
|
+
try {
|
|
8552
|
+
dir = readGenesisConfig(root)?.client?.dir ?? DEFAULT_CLIENT_DIR;
|
|
8553
|
+
} catch {
|
|
8554
|
+
}
|
|
8555
|
+
const inside3 = `${dir}/`;
|
|
8556
|
+
const present = files.some((f) => f.path.startsWith(inside3) && /(^|\/)resource-view\.(t|j)sx?$/.test(f.path)) || existsSync(path63.join(root, dir, "resource-view.tsx"));
|
|
8557
|
+
const recordWrapper = files.some((f) => f.path.startsWith(inside3) && /(^|\/)record-view\.(t|j)sx?$/.test(f.path)) || existsSync(path63.join(root, dir, "record-view.tsx"));
|
|
8558
|
+
return { dir, present, recordWrapper };
|
|
8559
|
+
}
|
|
8560
|
+
function genesisImports(code, uiPackage) {
|
|
8561
|
+
const out = /* @__PURE__ */ new Map();
|
|
8562
|
+
const escaped = uiPackage.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
8563
|
+
const re = new RegExp(`import\\s*(?:type\\s+)?\\{([^}]*)\\}\\s*from\\s*["']${escaped}(?:/data)?["']`, "g");
|
|
8564
|
+
for (const m of code.matchAll(re)) {
|
|
8565
|
+
if (/^\s*type\s/.test(m[0].slice(6))) continue;
|
|
8566
|
+
for (const part of m[1].split(",")) {
|
|
8567
|
+
const spec = part.trim().replace(/^type\s+/, "");
|
|
8568
|
+
if (!spec || part.trim().startsWith("type ")) continue;
|
|
8569
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
8570
|
+
if (imported === "ResourceView" || imported === "RecordView") out.set(local ?? imported, imported);
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
return out;
|
|
8574
|
+
}
|
|
8575
|
+
function checkClientLayer(ctx) {
|
|
8576
|
+
const layer = clientLayer(ctx.root, ctx.files);
|
|
8577
|
+
const inside3 = `${layer.dir}/`;
|
|
8578
|
+
if (layer.present) {
|
|
8579
|
+
for (const file of ctx.files) {
|
|
8580
|
+
if (!JSX_EXTS5.has(file.ext) || file.path.startsWith(inside3)) continue;
|
|
8581
|
+
const imported = genesisImports(file.code, ctx.genesis.uiPackage);
|
|
8582
|
+
for (const [local, name] of imported) {
|
|
8583
|
+
if (name === "RecordView" && !layer.recordWrapper) continue;
|
|
8584
|
+
const at = file.code.search(new RegExp(`<${local}\\b`));
|
|
8585
|
+
if (at < 0) continue;
|
|
8586
|
+
ctx.report({
|
|
8587
|
+
rule: "client/layer",
|
|
8588
|
+
level: "warn",
|
|
8589
|
+
file: file.path,
|
|
8590
|
+
line: lineAt(file.code, at),
|
|
8591
|
+
subject: name,
|
|
8592
|
+
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)`
|
|
8593
|
+
});
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8596
|
+
}
|
|
8597
|
+
if (!layer.present) return;
|
|
8598
|
+
const seen = /* @__PURE__ */ new Map();
|
|
8599
|
+
for (const file of ctx.files) {
|
|
8600
|
+
if (!SCRIPT_EXTS6.has(file.ext) || SHOWN_OR_TRIED.test(file.path)) continue;
|
|
8601
|
+
const imports = importedNames(file.path, file.code);
|
|
8602
|
+
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)) {
|
|
8603
|
+
const base = m[1];
|
|
8604
|
+
const access2 = m[2].replace(/\s+/g, "").replace(/'|`/g, '"');
|
|
8605
|
+
const imported = imports.get(base);
|
|
8606
|
+
if (!imported && !declaredAtTop(file.code, base)) continue;
|
|
8607
|
+
if (boundAsParameter(file.code, base, { jsx: file.ext !== ".ts" && file.ext !== ".mts" })) continue;
|
|
8608
|
+
const identity = `${imported ?? `${file.path}#${base}`}${access2}`;
|
|
8609
|
+
const shown = `${base}${access2}`;
|
|
8610
|
+
const line = lineAt(file.code, m.index ?? 0);
|
|
8611
|
+
const first = seen.get(identity);
|
|
8612
|
+
if (!first) {
|
|
8613
|
+
seen.set(identity, { file: file.path, line });
|
|
8614
|
+
continue;
|
|
8615
|
+
}
|
|
8616
|
+
ctx.report({
|
|
8617
|
+
rule: "client/one-view-per-resource",
|
|
8618
|
+
level: "warn",
|
|
8619
|
+
file: file.path,
|
|
8620
|
+
line,
|
|
8621
|
+
subject: shown,
|
|
8622
|
+
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)`
|
|
8623
|
+
});
|
|
8624
|
+
}
|
|
8625
|
+
}
|
|
8626
|
+
}
|
|
8627
|
+
function declaredAtTop(code, name) {
|
|
8628
|
+
const escaped = escapeRegExp(name);
|
|
8629
|
+
return new RegExp(`^(?:export\\s+)?(?:const|let|var)\\s+${escaped}\\b`, "m").test(code);
|
|
8630
|
+
}
|
|
8631
|
+
function importedNames(filePath, code) {
|
|
8632
|
+
const out = /* @__PURE__ */ new Map();
|
|
8633
|
+
const dir = path63.posix.dirname(filePath);
|
|
8634
|
+
const where2 = (spec) => spec.startsWith(".") ? path63.posix.normalize(path63.posix.join(dir, spec)).replace(/\.(t|j)sx?$/, "").replace(/\/index$/, "") : spec;
|
|
8635
|
+
for (const m of code.matchAll(/import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
8636
|
+
for (const part of m[1].split(",")) {
|
|
8637
|
+
const spec = part.trim().replace(/^type\s+/, "");
|
|
8638
|
+
if (!spec) continue;
|
|
8639
|
+
const [imported, local] = spec.split(/\s+as\s+/).map((x) => x.trim());
|
|
8640
|
+
out.set(local ?? imported, `${where2(m[2])}#${imported}`);
|
|
8641
|
+
}
|
|
8642
|
+
}
|
|
8643
|
+
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])}#*`);
|
|
8644
|
+
return out;
|
|
8645
|
+
}
|
|
8646
|
+
var JSX_EXTS5, SCRIPT_EXTS6, DEFAULT_CLIENT_DIR, SHOWN_OR_TRIED;
|
|
8647
|
+
var init_client_layer = __esm({
|
|
8648
|
+
"src/doctor/client-layer.ts"() {
|
|
8649
|
+
init_config();
|
|
8650
|
+
init_scan();
|
|
8651
|
+
init_js_scan();
|
|
8652
|
+
init_regexp();
|
|
8653
|
+
JSX_EXTS5 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
8654
|
+
SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"]);
|
|
8655
|
+
DEFAULT_CLIENT_DIR = "src/client";
|
|
8656
|
+
SHOWN_OR_TRIED = /(\.stories\.|\.test\.|\.spec\.|(^|\/)__tests__\/)/;
|
|
8657
|
+
}
|
|
8658
|
+
});
|
|
8659
|
+
function balanced(code, start) {
|
|
8660
|
+
const open = code[start];
|
|
8661
|
+
const close = open === "{" ? "}" : open === "(" ? ")" : open === "[" ? "]" : "";
|
|
8662
|
+
if (!close) return "";
|
|
8663
|
+
const blank = blankStrings(code);
|
|
8664
|
+
let depth = 0;
|
|
8665
|
+
for (let i = start; i < blank.length; i++) {
|
|
8666
|
+
const ch = blank[i];
|
|
8667
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
8668
|
+
else if (ch === "}" || ch === ")" || ch === "]") {
|
|
8669
|
+
depth--;
|
|
8670
|
+
if (depth === 0) return ch === close ? code.slice(start, i + 1) : "";
|
|
8671
|
+
}
|
|
8672
|
+
}
|
|
8673
|
+
return "";
|
|
8674
|
+
}
|
|
8675
|
+
function testFiles(root) {
|
|
8676
|
+
const out = [];
|
|
8677
|
+
const walk4 = (dir) => {
|
|
8678
|
+
let entries;
|
|
8679
|
+
try {
|
|
8680
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
8681
|
+
} catch {
|
|
8682
|
+
return;
|
|
8683
|
+
}
|
|
8684
|
+
for (const entry of entries) {
|
|
8685
|
+
if (entry.isDirectory()) {
|
|
8686
|
+
if (!SKIP_DIRS4.has(entry.name) && !entry.name.startsWith(".")) walk4(path63.join(dir, entry.name));
|
|
8687
|
+
continue;
|
|
8688
|
+
}
|
|
8689
|
+
const abs = path63.join(dir, entry.name);
|
|
8690
|
+
const rel = path63.relative(root, abs).split(path63.sep).join("/");
|
|
8691
|
+
if (SCRIPT_EXTS7.has(path63.extname(entry.name)) && TEST_FILE.test(rel)) out.push(abs);
|
|
8692
|
+
}
|
|
8693
|
+
};
|
|
8694
|
+
walk4(root);
|
|
8695
|
+
return out;
|
|
8696
|
+
}
|
|
8697
|
+
function initializer(code, blank, name) {
|
|
8698
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8699
|
+
const decl = new RegExp(`\\b(const|let|var)\\s+${escaped}(?![\\w$])[^=;]*=\\s*\\{`).exec(blank);
|
|
8700
|
+
if (!decl) return null;
|
|
8701
|
+
const text = balanced(code, decl.index + decl[0].length - 1);
|
|
8702
|
+
return text ? { text, keyword: decl[1], at: decl.index } : null;
|
|
8703
|
+
}
|
|
8704
|
+
function objectDeclares(object) {
|
|
8705
|
+
const blank = blankStrings(object);
|
|
8706
|
+
let depth = 0;
|
|
8707
|
+
let declaredAt = -1;
|
|
8708
|
+
let lastAccess = -1;
|
|
8709
|
+
let lastSpread = -1;
|
|
8710
|
+
for (let i = 0; i < blank.length; i++) {
|
|
8711
|
+
const ch = blank[i];
|
|
8712
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
8713
|
+
else if (ch === "}" || ch === ")" || ch === "]") depth--;
|
|
8714
|
+
else if (depth === 1 && blank.startsWith("...", i)) lastSpread = i;
|
|
8715
|
+
else if (depth === 1 && blank[i] === object[i] && /[\s{,]/.test(blank[i - 1] ?? " ") && /^(["'`]?)access\1\s*:/.test(object.slice(i))) {
|
|
8716
|
+
lastAccess = i;
|
|
8717
|
+
const value = /^(["'`]?)access\1\s*:\s*(["'`])([^"'`]*)\2/.exec(object.slice(i));
|
|
8718
|
+
declaredAt = value?.[3] === "declared" ? i : -1;
|
|
8719
|
+
}
|
|
8720
|
+
}
|
|
8721
|
+
return declaredAt !== -1 && declaredAt === lastAccess && lastSpread < declaredAt;
|
|
8722
|
+
}
|
|
8723
|
+
function inlineDeclares(call) {
|
|
8724
|
+
const blank = blankStrings(call);
|
|
8725
|
+
let depth = 0;
|
|
8726
|
+
for (let i = 0; i < blank.length; i++) {
|
|
8727
|
+
const ch = blank[i];
|
|
8728
|
+
if (ch === "{" && depth === 1 && objectDeclares(balanced(call, i))) return true;
|
|
8729
|
+
if (ch === "{" || ch === "(" || ch === "[") depth++;
|
|
8730
|
+
else if (ch === "}" || ch === ")" || ch === "]") depth--;
|
|
8731
|
+
}
|
|
8732
|
+
return false;
|
|
8733
|
+
}
|
|
8734
|
+
function optionsConstDeclares(code, blank, call) {
|
|
8735
|
+
const args = blankStrings(call).slice(1, -1);
|
|
8736
|
+
for (const [, name] of args.matchAll(/(?:^|,)\s*([A-Za-z_$][\w$]*)\s*(?=,|$)/g)) {
|
|
8737
|
+
const found = initializer(code, blank, name);
|
|
8738
|
+
if (!found || !objectDeclares(found.text)) continue;
|
|
8739
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8740
|
+
const reassigned = found.keyword !== "const" && new RegExp(`(?<![\\w$.])${escaped}\\s*=(?!=)`, "g").test(blank.slice(found.at + found.keyword.length + 1 + name.length));
|
|
8741
|
+
const changed = new RegExp(
|
|
8742
|
+
`(?<![\\w$.])${escaped}\\s*(?:\\.\\s*access|\\[[^\\]]*\\])\\s*=(?!=)|\\bdelete\\s+${escaped}\\s*(?:\\.\\s*access|\\[)|Object\\.assign\\(\\s*${escaped}(?![\\w$])`
|
|
8743
|
+
).test(blank);
|
|
8744
|
+
if (!reassigned && !changed) return true;
|
|
8745
|
+
}
|
|
8746
|
+
return false;
|
|
8747
|
+
}
|
|
8748
|
+
function coverageTested(root) {
|
|
8749
|
+
for (const abs of testFiles(root)) {
|
|
8750
|
+
let code;
|
|
8751
|
+
try {
|
|
8752
|
+
code = stripBlockComments(readFileSync(abs, "utf8"), true);
|
|
8753
|
+
} catch {
|
|
8754
|
+
continue;
|
|
8755
|
+
}
|
|
8756
|
+
if (!code.includes("expectAccessRulesCover")) continue;
|
|
8757
|
+
if (/\bexpectAccessRulesCover\s*\(/.test(blankStrings(code))) return true;
|
|
8758
|
+
}
|
|
8759
|
+
return false;
|
|
8760
|
+
}
|
|
8761
|
+
function checkDataAccess(ctx) {
|
|
8762
|
+
for (const file of ctx.files) {
|
|
8763
|
+
if (!SCRIPT_EXTS7.has(file.ext)) continue;
|
|
8764
|
+
const blank = blankStrings(file.code);
|
|
8765
|
+
for (const m of blank.matchAll(/\bcreateSupabaseProvider\s*\(/g)) {
|
|
8766
|
+
const call = balanced(file.code, (m.index ?? 0) + m[0].length - 1);
|
|
8767
|
+
if (inlineDeclares(call) || optionsConstDeclares(file.code, blank, call)) continue;
|
|
8768
|
+
ctx.report({
|
|
8769
|
+
rule: "data/declared-access",
|
|
8770
|
+
level: "warn",
|
|
8771
|
+
file: file.path,
|
|
8772
|
+
line: lineAt(file.code, m.index ?? 0),
|
|
8773
|
+
subject: "createSupabaseProvider",
|
|
8774
|
+
message: `leaves its resources free to read and write their tables undeclared. Pass access: "declared", give each resource its read (source: a view or a function) and its writes (writes: named database functions), and opt a table in only with table: { \u2026, why } (${DOCS})`
|
|
8775
|
+
});
|
|
8776
|
+
}
|
|
8777
|
+
if (file.path.startsWith("supabase/") || file.path.includes("/supabase/functions/")) continue;
|
|
8778
|
+
for (const m of file.code.matchAll(TABLE_WRITE)) {
|
|
8779
|
+
const at = m.index ?? 0;
|
|
8780
|
+
if (blank[at] !== ".") continue;
|
|
8781
|
+
if (STORAGE_BEFORE.test(blank.slice(Math.max(0, at - 40), at))) continue;
|
|
8782
|
+
ctx.report({
|
|
8783
|
+
rule: "data/declared-access",
|
|
8784
|
+
level: "warn",
|
|
8785
|
+
file: file.path,
|
|
8786
|
+
line: lineAt(file.code, at),
|
|
8787
|
+
subject: `${m[2]}.${m[3]}`,
|
|
8788
|
+
message: `writes the ${m[2]} table directly (${m[3]}). Write through a named database function (the resource's writes, or a call to it), which holds the access rule; a write that must stay on the table is an allow entry for data/declared-access with its reason (${DOCS})`
|
|
8789
|
+
});
|
|
8790
|
+
}
|
|
8791
|
+
}
|
|
8792
|
+
const providers = providerCalls(ctx.files);
|
|
8793
|
+
if (providers.length === 0 || coverageTested(ctx.root)) return;
|
|
8794
|
+
const first = providers[0];
|
|
8795
|
+
ctx.report({
|
|
8796
|
+
rule: "data/access-rule-tests",
|
|
8797
|
+
level: "warn",
|
|
8798
|
+
file: first.file,
|
|
8799
|
+
line: first.line,
|
|
8800
|
+
subject: "expectAccessRulesCover",
|
|
8801
|
+
message: `no test checks that every database function the provider declares has an access-rule test. Add expectAccessRulesCover(providerOptions, [/* each accessRules spec */]) (@marktiderman/genesis-core/testing) to a test file: it fails for each declared function without one (${DOCS})`
|
|
8802
|
+
});
|
|
8803
|
+
}
|
|
8804
|
+
function providerCalls(files) {
|
|
8805
|
+
const out = [];
|
|
8806
|
+
for (const file of files) {
|
|
8807
|
+
if (!SCRIPT_EXTS7.has(file.ext)) continue;
|
|
8808
|
+
for (const m of blankStrings(file.code).matchAll(/\bcreateSupabaseProvider\s*\(/g)) {
|
|
8809
|
+
out.push({ file: file.path, line: lineAt(file.code, m.index ?? 0) });
|
|
8810
|
+
}
|
|
8811
|
+
}
|
|
8812
|
+
return out;
|
|
8813
|
+
}
|
|
8814
|
+
var SCRIPT_EXTS7, SKIP_DIRS4, TEST_FILE, DOCS, TABLE_WRITE, STORAGE_BEFORE;
|
|
8815
|
+
var init_data_access = __esm({
|
|
8816
|
+
"src/doctor/data-access.ts"() {
|
|
8817
|
+
init_color_literals();
|
|
8818
|
+
init_scan();
|
|
8819
|
+
init_source();
|
|
8820
|
+
SCRIPT_EXTS7 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
8821
|
+
SKIP_DIRS4 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage", ".expo"]);
|
|
8822
|
+
TEST_FILE = /(^|\/)(__tests__\/|[^/]+\.(test|spec)\.[cm]?[jt]sx?$)/;
|
|
8823
|
+
DOCS = "docs/DATA-ACCESS.md";
|
|
8824
|
+
TABLE_WRITE = /\.from\(\s*(["'`])([\w.]+)\1\s*\)\s*\.\s*(insert|update|upsert|delete)\s*\(/g;
|
|
8825
|
+
STORAGE_BEFORE = /\bstorage\s*\??\.?\s*$/;
|
|
8826
|
+
}
|
|
8827
|
+
});
|
|
8188
8828
|
function specifierParts(spec) {
|
|
8189
8829
|
return spec.trim().replace(/^type\s+/, "").split(/\s+as\s+/).map((part) => part.trim());
|
|
8190
8830
|
}
|
|
@@ -8227,16 +8867,16 @@ function genesisNamedImports(source) {
|
|
|
8227
8867
|
}
|
|
8228
8868
|
function declarationFiles(dir, out = []) {
|
|
8229
8869
|
for (const name of readdirSync(dir)) {
|
|
8230
|
-
const full =
|
|
8870
|
+
const full = path63.join(dir, name);
|
|
8231
8871
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
8232
8872
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
8233
8873
|
}
|
|
8234
8874
|
return out;
|
|
8235
8875
|
}
|
|
8236
8876
|
function readPackageTags(dir) {
|
|
8237
|
-
const pkg = JSON.parse(readFileSync(
|
|
8877
|
+
const pkg = JSON.parse(readFileSync(path63.join(dir, "package.json"), "utf8"));
|
|
8238
8878
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
8239
|
-
const dist =
|
|
8879
|
+
const dist = path63.join(dir, "dist");
|
|
8240
8880
|
if (!existsSync(dist)) return tags;
|
|
8241
8881
|
for (const file of declarationFiles(dist)) {
|
|
8242
8882
|
const text = readFileSync(file, "utf8");
|
|
@@ -8254,7 +8894,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
8254
8894
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
8255
8895
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
8256
8896
|
const types = typeof target === "object" && target ? target.types : null;
|
|
8257
|
-
return typeof types === "string" ?
|
|
8897
|
+
return typeof types === "string" ? path63.join(tags.dir, types) : null;
|
|
8258
8898
|
}
|
|
8259
8899
|
function tagFor(tags, entry, name) {
|
|
8260
8900
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -8272,7 +8912,7 @@ function checkStabilityImports(ctx) {
|
|
|
8272
8912
|
return cache2.get(pkg);
|
|
8273
8913
|
};
|
|
8274
8914
|
for (const file of ctx.files) {
|
|
8275
|
-
if (!
|
|
8915
|
+
if (!SCRIPT_EXTS8.has(file.ext)) continue;
|
|
8276
8916
|
for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
|
|
8277
8917
|
const tags = tagsOf(pkg);
|
|
8278
8918
|
if (!tags) continue;
|
|
@@ -8288,12 +8928,12 @@ function checkStabilityImports(ctx) {
|
|
|
8288
8928
|
}
|
|
8289
8929
|
}
|
|
8290
8930
|
}
|
|
8291
|
-
var
|
|
8931
|
+
var SCRIPT_EXTS8, DECLARATION, REEXPORT;
|
|
8292
8932
|
var init_stability = __esm({
|
|
8293
8933
|
"src/doctor/stability.ts"() {
|
|
8294
8934
|
init_genesis();
|
|
8295
8935
|
init_trail();
|
|
8296
|
-
|
|
8936
|
+
SCRIPT_EXTS8 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
8297
8937
|
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;
|
|
8298
8938
|
REEXPORT = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\nexport\s+(?:type\s+)?\{([^}]*)\}/g;
|
|
8299
8939
|
}
|
|
@@ -8339,7 +8979,7 @@ function showAt(dir, rev, file) {
|
|
|
8339
8979
|
function configAtBase(root, base, explicitFile) {
|
|
8340
8980
|
const mergeBase = mergeBaseOf2(root, base);
|
|
8341
8981
|
if (!mergeBase) return null;
|
|
8342
|
-
const candidates = explicitFile ? [{ dir:
|
|
8982
|
+
const candidates = explicitFile ? [{ dir: path63.dirname(explicitFile), file: path63.basename(explicitFile), explicit: true }] : [
|
|
8343
8983
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
8344
8984
|
{ dir: root, file: "package.json", explicit: false }
|
|
8345
8985
|
];
|
|
@@ -8453,7 +9093,7 @@ function snapshotAtBase(root, base, files, changed, originOf = (f) => f) {
|
|
|
8453
9093
|
seen.add(origin);
|
|
8454
9094
|
const text = showAt(root, mergeBase, origin);
|
|
8455
9095
|
if (text === null) return null;
|
|
8456
|
-
if (text !== void 0) out.push(withText({ ...f, path: origin, absolutePath:
|
|
9096
|
+
if (text !== void 0) out.push(withText({ ...f, path: origin, absolutePath: path63.join(root, origin) }, text));
|
|
8457
9097
|
}
|
|
8458
9098
|
const cache2 = /* @__PURE__ */ new Map();
|
|
8459
9099
|
return {
|
|
@@ -8611,7 +9251,7 @@ function pathTaken(file) {
|
|
|
8611
9251
|
return true;
|
|
8612
9252
|
} catch {
|
|
8613
9253
|
try {
|
|
8614
|
-
return readdirSync(
|
|
9254
|
+
return readdirSync(path63.dirname(file)).some((n) => n.toLowerCase() === path63.basename(file).toLowerCase());
|
|
8615
9255
|
} catch {
|
|
8616
9256
|
return false;
|
|
8617
9257
|
}
|
|
@@ -8683,13 +9323,13 @@ function stableGuidePath(root, p) {
|
|
|
8683
9323
|
};
|
|
8684
9324
|
const want = real2(p.dir);
|
|
8685
9325
|
for (let dir = root, level = 0; level <= GUIDE_SEARCH_LEVELS; level++) {
|
|
8686
|
-
const found =
|
|
9326
|
+
const found = path63.join(dir, "node_modules", p.name);
|
|
8687
9327
|
if (existsSync(found)) {
|
|
8688
|
-
const file =
|
|
9328
|
+
const file = path63.join(found, "SKILL.md");
|
|
8689
9329
|
return want !== null && real2(found) === want && existsSync(file) ? file : null;
|
|
8690
9330
|
}
|
|
8691
|
-
if (existsSync(
|
|
8692
|
-
const up =
|
|
9331
|
+
if (existsSync(path63.join(dir, ".git")) || existsSync(path63.join(dir, "pnpm-workspace.yaml"))) return null;
|
|
9332
|
+
const up = path63.dirname(dir);
|
|
8693
9333
|
if (up === dir) return null;
|
|
8694
9334
|
dir = up;
|
|
8695
9335
|
}
|
|
@@ -8698,18 +9338,18 @@ function stableGuidePath(root, p) {
|
|
|
8698
9338
|
function packageGuides(root, packages) {
|
|
8699
9339
|
const guides = [];
|
|
8700
9340
|
for (const p of packages) {
|
|
8701
|
-
const stable = p.local ?
|
|
9341
|
+
const stable = p.local ? path63.join(p.dir, "SKILL.md") : stableGuidePath(root, p);
|
|
8702
9342
|
const text = stable === null ? null : read2(stable);
|
|
8703
9343
|
if (stable === null || text === null) continue;
|
|
8704
9344
|
const description = skillDescription(text);
|
|
8705
9345
|
const at = description.indexOf("Load before");
|
|
8706
|
-
guides.push({ package: p.name, path:
|
|
9346
|
+
guides.push({ package: p.name, path: path63.relative(root, stable).split(path63.sep).join("/"), when: at >= 0 ? description.slice(at) : description });
|
|
8707
9347
|
}
|
|
8708
9348
|
return guides.sort((a, b) => a.package.localeCompare(b.package));
|
|
8709
9349
|
}
|
|
8710
9350
|
function unlistedGuides(root, packages) {
|
|
8711
9351
|
const listed = new Set(packageGuides(root, packages).map((g) => g.package));
|
|
8712
|
-
return packages.filter((p) => !p.local && !listed.has(p.name) && existsSync(
|
|
9352
|
+
return packages.filter((p) => !p.local && !listed.has(p.name) && existsSync(path63.join(p.dir, "SKILL.md"))).map((p) => p.name).sort();
|
|
8713
9353
|
}
|
|
8714
9354
|
function guidesSection(guides) {
|
|
8715
9355
|
if (!guides.length) return [];
|
|
@@ -8790,13 +9430,13 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
8790
9430
|
const rows = primitivesCatalog(packages);
|
|
8791
9431
|
const guides = packageGuides(root, packages);
|
|
8792
9432
|
const changed = [];
|
|
8793
|
-
const agents =
|
|
9433
|
+
const agents = path63.join(root, agentsFile);
|
|
8794
9434
|
const before = read2(agents);
|
|
8795
9435
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows, guides));
|
|
8796
|
-
const skill =
|
|
9436
|
+
const skill = path63.join(root, SKILL_PATH);
|
|
8797
9437
|
const skillText = renderSkill(rows, guides);
|
|
8798
9438
|
if (read2(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
8799
|
-
mkdirSync(
|
|
9439
|
+
mkdirSync(path63.dirname(skill), { recursive: true });
|
|
8800
9440
|
writeFileSync(skill, skillText);
|
|
8801
9441
|
changed.push(SKILL_PATH);
|
|
8802
9442
|
}
|
|
@@ -8804,7 +9444,7 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
8804
9444
|
writeFileSync(agents, after);
|
|
8805
9445
|
changed.push(agentsFile);
|
|
8806
9446
|
}
|
|
8807
|
-
const claude =
|
|
9447
|
+
const claude = path63.join(root, "CLAUDE.md");
|
|
8808
9448
|
if (agentsFile === "AGENTS.md" && !pathTaken(claude)) {
|
|
8809
9449
|
writeFileSync(claude, CLAUDE_IMPORT);
|
|
8810
9450
|
changed.push("CLAUDE.md");
|
|
@@ -8812,7 +9452,7 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
8812
9452
|
return changed;
|
|
8813
9453
|
}
|
|
8814
9454
|
function claudeState(root) {
|
|
8815
|
-
const file =
|
|
9455
|
+
const file = path63.join(root, "CLAUDE.md");
|
|
8816
9456
|
let names = [];
|
|
8817
9457
|
try {
|
|
8818
9458
|
names = readdirSync(root);
|
|
@@ -8827,7 +9467,7 @@ function claudeState(root) {
|
|
|
8827
9467
|
}
|
|
8828
9468
|
if (/^@AGENTS\.md\b/m.test(text)) return "ok";
|
|
8829
9469
|
try {
|
|
8830
|
-
if (realpathSync(file) === realpathSync(
|
|
9470
|
+
if (realpathSync(file) === realpathSync(path63.join(root, "AGENTS.md"))) return "ok";
|
|
8831
9471
|
} catch {
|
|
8832
9472
|
}
|
|
8833
9473
|
return "no-import";
|
|
@@ -8835,8 +9475,8 @@ function claudeState(root) {
|
|
|
8835
9475
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
8836
9476
|
const rows = primitivesCatalog(packages);
|
|
8837
9477
|
const guides = packageGuides(root, packages);
|
|
8838
|
-
const skill = read2(
|
|
8839
|
-
const block = currentAgentsBlock(read2(
|
|
9478
|
+
const skill = read2(path63.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
9479
|
+
const block = currentAgentsBlock(read2(path63.join(root, agentsFile)));
|
|
8840
9480
|
return {
|
|
8841
9481
|
skill: skill === null ? "missing" : skill === renderSkill(rows, guides) ? "ok" : "stale",
|
|
8842
9482
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows, guides) ? "ok" : "stale",
|
|
@@ -8932,6 +9572,7 @@ var init_primitives = __esm({
|
|
|
8932
9572
|
"Never copy an older screen as a template. Old screens predate the primitives; the doctor flags what they did.",
|
|
8933
9573
|
"A list screen is a view (`defineView`) rendered by `ResourceView`; a record view is `RecordView`; on the phone, `NativeResourceView`.",
|
|
8934
9574
|
"Screens never call the database client (`supabase.from`, `.rpc`) directly: reads go through a view or a named data function, writes through the resource's provider rules.",
|
|
9575
|
+
`Data access is declared: the Supabase provider runs with \`access: "declared"\`; each resource reads through a view or a function (\`source\`) and writes through named database functions (\`writes\`, \`actions\`) that hold the access rule; a table is touched only with \`table: { \u2026, why }\`. Every declared function gets an access-rule test (\`accessRules\`), and one test (\`expectAccessRulesCover\`) fails for any declared function whose name no spec carries: it compares names only, so give it the same specs the cases are registered from. See ${GENESIS_DOCS}/DATA-ACCESS.md.`,
|
|
8935
9576
|
"When a Genesis piece is close and does the same job, extend it: a prop, a variant, a slot, or your own component that wraps it. Never build a parallel copy beside it.",
|
|
8936
9577
|
"When no Genesis piece does the job, invent it in the app: your own screens and components, on Genesis tokens and primitives. Genesis asks for no write-up or approval first (your app's own design review still applies); you may add it to `docs/genesis-upstream.md` if you think Genesis should have it.",
|
|
8937
9578
|
"Run `genesis doctor` before you finish; it enforces these rules."
|
|
@@ -8983,7 +9624,7 @@ function mergeAgentHooks(settings2) {
|
|
|
8983
9624
|
return out;
|
|
8984
9625
|
}
|
|
8985
9626
|
function writeAgentHooks(root) {
|
|
8986
|
-
const file =
|
|
9627
|
+
const file = path63.join(root, SETTINGS_PATH);
|
|
8987
9628
|
const before = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
8988
9629
|
let current = {};
|
|
8989
9630
|
if (before !== null) {
|
|
@@ -8997,14 +9638,14 @@ function writeAgentHooks(root) {
|
|
|
8997
9638
|
const after = `${JSON.stringify(mergeAgentHooks(current), null, 2)}
|
|
8998
9639
|
`;
|
|
8999
9640
|
if (before !== null && JSON.stringify(JSON.parse(before)) === JSON.stringify(JSON.parse(after))) return [];
|
|
9000
|
-
mkdirSync(
|
|
9641
|
+
mkdirSync(path63.dirname(file), { recursive: true });
|
|
9001
9642
|
writeFileSync(file, after);
|
|
9002
9643
|
return [SETTINGS_PATH];
|
|
9003
9644
|
}
|
|
9004
9645
|
function agentHooksState(root) {
|
|
9005
9646
|
let settings2;
|
|
9006
9647
|
try {
|
|
9007
|
-
settings2 = JSON.parse(readFileSync(
|
|
9648
|
+
settings2 = JSON.parse(readFileSync(path63.join(root, SETTINGS_PATH), "utf8"));
|
|
9008
9649
|
} catch {
|
|
9009
9650
|
return "none";
|
|
9010
9651
|
}
|
|
@@ -9047,7 +9688,7 @@ function unprefixedTemplatePaths(root, rel, mine, template, folder) {
|
|
|
9047
9688
|
const lines = new Set(mine.split("\n"));
|
|
9048
9689
|
const lockfileElsewhere = (line) => {
|
|
9049
9690
|
const name = PATH_ITEM.exec(line)?.[3];
|
|
9050
|
-
return name !== void 0 && LOCKFILES2.has(name) && !existsSync(
|
|
9691
|
+
return name !== void 0 && LOCKFILES2.has(name) && !existsSync(path63.join(root, name));
|
|
9051
9692
|
};
|
|
9052
9693
|
return template.split("\n").filter((line, i) => line !== rendered[i] && !/^\s*#/.test(line) && lines.has(line) && !lockfileElsewhere(line)).map((line) => line.trim());
|
|
9053
9694
|
}
|
|
@@ -9120,9 +9761,9 @@ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
|
9120
9761
|
return `${key2} doesn't match its source ${source}`;
|
|
9121
9762
|
}
|
|
9122
9763
|
function mergeThreeWay(mine, base, theirs) {
|
|
9123
|
-
const dir = mkdtempSync(
|
|
9764
|
+
const dir = mkdtempSync(path63.join(tmpdir(), "genesis-merge-"));
|
|
9124
9765
|
try {
|
|
9125
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
9766
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path63.join(dir, n));
|
|
9126
9767
|
writeFileSync(m, mine);
|
|
9127
9768
|
writeFileSync(b, base);
|
|
9128
9769
|
writeFileSync(t, theirs);
|
|
@@ -9386,7 +10027,7 @@ function removeBunLockEntries(text, remove) {
|
|
|
9386
10027
|
return out + text.slice(at);
|
|
9387
10028
|
}
|
|
9388
10029
|
function readBunLock(dir) {
|
|
9389
|
-
const file =
|
|
10030
|
+
const file = path63.join(dir, BUN_LOCK);
|
|
9390
10031
|
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
9391
10032
|
}
|
|
9392
10033
|
var BUN_LOCK, GENESIS_TAIL, PLAIN_VERSION;
|
|
@@ -9403,7 +10044,7 @@ function checkBunLock(ctx) {
|
|
|
9403
10044
|
if (found?.pm !== "bun") return;
|
|
9404
10045
|
const text = readBunLock(found.dir);
|
|
9405
10046
|
if (text === null) return;
|
|
9406
|
-
const file =
|
|
10047
|
+
const file = path63.relative(ctx.root, path63.join(found.dir, BUN_LOCK)).split(path63.sep).join("/");
|
|
9407
10048
|
let stale;
|
|
9408
10049
|
try {
|
|
9409
10050
|
stale = staleNestedEntries(text);
|
|
@@ -9422,7 +10063,7 @@ function checkBunLock(ctx) {
|
|
|
9422
10063
|
}
|
|
9423
10064
|
async function checkLockFiles(ctx) {
|
|
9424
10065
|
checkBunLock(ctx);
|
|
9425
|
-
if (!existsSync(
|
|
10066
|
+
if (!existsSync(path63.join(ctx.root, LOCK_FILE))) return;
|
|
9426
10067
|
let lock;
|
|
9427
10068
|
try {
|
|
9428
10069
|
lock = readLock(ctx.root);
|
|
@@ -9544,7 +10185,7 @@ function checkDatabaseHome(ctx) {
|
|
|
9544
10185
|
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)`
|
|
9545
10186
|
});
|
|
9546
10187
|
}
|
|
9547
|
-
if (existsSync(
|
|
10188
|
+
if (existsSync(path63.join(ctx.root, "supabase"))) {
|
|
9548
10189
|
ctx.report({
|
|
9549
10190
|
rule: "database-elsewhere",
|
|
9550
10191
|
level: "warn",
|
|
@@ -9567,7 +10208,7 @@ function checkEslintConfig(ctx) {
|
|
|
9567
10208
|
if (!file) return;
|
|
9568
10209
|
let text;
|
|
9569
10210
|
try {
|
|
9570
|
-
text = readFileSync(
|
|
10211
|
+
text = readFileSync(path63.join(ctx.root, file), "utf8");
|
|
9571
10212
|
} catch {
|
|
9572
10213
|
return;
|
|
9573
10214
|
}
|
|
@@ -9645,7 +10286,7 @@ function validateFigmaConfig(raw, source = "genesis.config.json") {
|
|
|
9645
10286
|
return { file: obj.file, pages: out, proposalsPage: obj.proposalsPage ?? "Proposals" };
|
|
9646
10287
|
}
|
|
9647
10288
|
function readFigmaConfig(root) {
|
|
9648
|
-
const file =
|
|
10289
|
+
const file = path63.join(root, "genesis.config.json");
|
|
9649
10290
|
if (!existsSync(file)) return null;
|
|
9650
10291
|
let raw;
|
|
9651
10292
|
try {
|
|
@@ -9659,7 +10300,7 @@ function walk2(dir, out = []) {
|
|
|
9659
10300
|
if (!existsSync(dir)) return out;
|
|
9660
10301
|
for (const name of readdirSync(dir).sort()) {
|
|
9661
10302
|
if (name === "node_modules" || name.startsWith(".")) continue;
|
|
9662
|
-
const full =
|
|
10303
|
+
const full = path63.join(dir, name);
|
|
9663
10304
|
if (statSync(full).isDirectory()) walk2(full, out);
|
|
9664
10305
|
else if (CODE.test(name) && !/\.(?:test|spec|d)\.[jt]sx?$/.test(name)) out.push(full);
|
|
9665
10306
|
}
|
|
@@ -9688,27 +10329,27 @@ function tanstackSegments(stem) {
|
|
|
9688
10329
|
return out;
|
|
9689
10330
|
}
|
|
9690
10331
|
function expoRoot(root) {
|
|
9691
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
10332
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path63.join(root, dir))) return dir;
|
|
9692
10333
|
return null;
|
|
9693
10334
|
}
|
|
9694
10335
|
function appRoutes(root) {
|
|
9695
10336
|
const out = [];
|
|
9696
|
-
const rel = (f) =>
|
|
10337
|
+
const rel = (f) => path63.relative(root, f).split(path63.sep).join("/");
|
|
9697
10338
|
const expo = expoRoot(root);
|
|
9698
10339
|
if (expo) {
|
|
9699
|
-
for (const f of walk2(
|
|
9700
|
-
const parts =
|
|
10340
|
+
for (const f of walk2(path63.join(root, expo))) {
|
|
10341
|
+
const parts = path63.relative(path63.join(root, expo), f).split(path63.sep);
|
|
9701
10342
|
const stem = parts.pop().replace(CODE, "");
|
|
9702
10343
|
if (stem === "_layout" || stem.startsWith("+")) continue;
|
|
9703
10344
|
if (stem !== "index") parts.push(stem);
|
|
9704
10345
|
out.push(withId({ route: parts.join("/") || "index", platform: "native", file: rel(f) }, f));
|
|
9705
10346
|
}
|
|
9706
10347
|
}
|
|
9707
|
-
const tanstack =
|
|
10348
|
+
const tanstack = path63.join(root, "src/routes");
|
|
9708
10349
|
if (existsSync(tanstack)) {
|
|
9709
10350
|
const seen = /* @__PURE__ */ new Set();
|
|
9710
10351
|
for (const f of walk2(tanstack)) {
|
|
9711
|
-
const parts =
|
|
10352
|
+
const parts = path63.relative(tanstack, f).split(path63.sep);
|
|
9712
10353
|
const stem = parts.pop().replace(CODE, "").replace(/\.lazy$/, "");
|
|
9713
10354
|
if (stem === "__root" || stem === "route" || stem.startsWith("-") || parts.some((p) => p.startsWith("-"))) continue;
|
|
9714
10355
|
const segs = [...parts.flatMap(tanstackSegments), ...tanstackSegments(stem)];
|
|
@@ -9773,12 +10414,12 @@ function navTargets(code, file) {
|
|
|
9773
10414
|
return out.sort((a, b) => a.line - b.line);
|
|
9774
10415
|
}
|
|
9775
10416
|
function appNavTargets(root) {
|
|
9776
|
-
const files = [.../* @__PURE__ */ new Set([...walk2(
|
|
9777
|
-
return files.flatMap((f) => navTargets(readFileSync(f, "utf8"),
|
|
10417
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path63.join(root, "src")), ...walk2(path63.join(root, "app"))])];
|
|
10418
|
+
return files.flatMap((f) => navTargets(readFileSync(f, "utf8"), path63.relative(root, f).split(path63.sep).join("/")));
|
|
9778
10419
|
}
|
|
9779
10420
|
function appDynamicNavTargets(root) {
|
|
9780
|
-
const files = [.../* @__PURE__ */ new Set([...walk2(
|
|
9781
|
-
return files.flatMap((f) => dynamicNavTargets(readFileSync(f, "utf8"),
|
|
10421
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path63.join(root, "src")), ...walk2(path63.join(root, "app"))])];
|
|
10422
|
+
return files.flatMap((f) => dynamicNavTargets(readFileSync(f, "utf8"), path63.relative(root, f).split(path63.sep).join("/")));
|
|
9782
10423
|
}
|
|
9783
10424
|
function splitName(name) {
|
|
9784
10425
|
const i = name.indexOf(" \xB7 ");
|
|
@@ -9901,7 +10542,7 @@ function compare(config, routes, targets, figma, dynamicTargets = []) {
|
|
|
9901
10542
|
}
|
|
9902
10543
|
async function checkFigmaRoutes(options) {
|
|
9903
10544
|
const config = options.config ?? readFigmaConfig(options.root);
|
|
9904
|
-
if (!config) throw new FigmaConfigError(`no "figma" block in ${
|
|
10545
|
+
if (!config) throw new FigmaConfigError(`no "figma" block in ${path63.join(options.root, "genesis.config.json")}`);
|
|
9905
10546
|
const token = options.token ?? process.env.FIGMA_ACCESS_TOKEN;
|
|
9906
10547
|
if (!token) throw new FigmaConfigError("FIGMA_ACCESS_TOKEN isn't set");
|
|
9907
10548
|
const figma = await readFigma(config, token, options.fetch);
|
|
@@ -10058,7 +10699,7 @@ __export(doctor_exports, {
|
|
|
10058
10699
|
writeAgentHooks: () => writeAgentHooks
|
|
10059
10700
|
});
|
|
10060
10701
|
async function runDoctor(options = {}) {
|
|
10061
|
-
const root =
|
|
10702
|
+
const root = path63.resolve(options.root ?? process.cwd());
|
|
10062
10703
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
10063
10704
|
const config = loaded.config;
|
|
10064
10705
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -10113,7 +10754,7 @@ async function runDoctor(options = {}) {
|
|
|
10113
10754
|
const configured = applyConfig(raw, config, packageIds);
|
|
10114
10755
|
let findings = applyExtensions(configured, extensionCtx);
|
|
10115
10756
|
if (options.base && changed) {
|
|
10116
|
-
const isAppPath = (f) => existsSync(
|
|
10757
|
+
const isAppPath = (f) => existsSync(path63.join(root, f));
|
|
10117
10758
|
const origins = options.changedFiles ? /* @__PURE__ */ new Map() : originsSince(root, options.base);
|
|
10118
10759
|
const originOf = (f) => origins.get(f) ?? f;
|
|
10119
10760
|
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));
|
|
@@ -10191,6 +10832,8 @@ function builtinChecks(config, options = {}) {
|
|
|
10191
10832
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
10192
10833
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
10193
10834
|
{ name: "app-parts", check: checkAppParts },
|
|
10835
|
+
{ name: "client-layer", check: checkClientLayer },
|
|
10836
|
+
{ name: "data-access", check: checkDataAccess },
|
|
10194
10837
|
{ name: "stability-imports", check: checkStabilityImports },
|
|
10195
10838
|
{ name: "agent-guide", check: (ctx) => {
|
|
10196
10839
|
checkAgentGuide(ctx);
|
|
@@ -10315,6 +10958,8 @@ var init_doctor = __esm({
|
|
|
10315
10958
|
init_dates();
|
|
10316
10959
|
init_api_usage();
|
|
10317
10960
|
init_custom_views();
|
|
10961
|
+
init_client_layer();
|
|
10962
|
+
init_data_access();
|
|
10318
10963
|
init_stability();
|
|
10319
10964
|
init_package_rules();
|
|
10320
10965
|
init_ratchet();
|
|
@@ -10358,12 +11003,12 @@ __export(agent_rules_exports, {
|
|
|
10358
11003
|
runsOnPullRequestsInto: () => runsOnPullRequestsInto
|
|
10359
11004
|
});
|
|
10360
11005
|
function changesetBumps(root) {
|
|
10361
|
-
const dir =
|
|
11006
|
+
const dir = path63.join(root, ".changeset");
|
|
10362
11007
|
const bumps = /* @__PURE__ */ new Map();
|
|
10363
11008
|
if (!existsSync(dir)) return bumps;
|
|
10364
11009
|
for (const name of readdirSync(dir)) {
|
|
10365
11010
|
if (!name.endsWith(".md") || name === "README.md") continue;
|
|
10366
|
-
const text = readFileSync(
|
|
11011
|
+
const text = readFileSync(path63.join(dir, name), "utf8");
|
|
10367
11012
|
const front = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? "";
|
|
10368
11013
|
for (const line of front.split(/\r?\n/)) {
|
|
10369
11014
|
const m = /^\s*["']?([^"':]+)["']?\s*:\s*(major|minor|patch)\s*$/.exec(line);
|
|
@@ -10376,13 +11021,13 @@ function changesetBumps(root) {
|
|
|
10376
11021
|
return bumps;
|
|
10377
11022
|
}
|
|
10378
11023
|
function firstVersionProblems(root) {
|
|
10379
|
-
const packagesDir =
|
|
11024
|
+
const packagesDir = path63.join(root, "packages");
|
|
10380
11025
|
if (!existsSync(packagesDir)) return [];
|
|
10381
11026
|
const bumps = changesetBumps(root);
|
|
10382
11027
|
const problems = [];
|
|
10383
11028
|
for (const dir of readdirSync(packagesDir)) {
|
|
10384
|
-
const file =
|
|
10385
|
-
if (!existsSync(file) || existsSync(
|
|
11029
|
+
const file = path63.join(packagesDir, dir, "package.json");
|
|
11030
|
+
if (!existsSync(file) || existsSync(path63.join(packagesDir, dir, "CHANGELOG.md"))) continue;
|
|
10386
11031
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
10387
11032
|
if (pkg.private || !pkg.name) continue;
|
|
10388
11033
|
if (pkg.version !== FIRST_VERSION) {
|
|
@@ -10453,12 +11098,12 @@ function runsOnPullRequestsInto(workflow, branch) {
|
|
|
10453
11098
|
return ignore ? !ignore.some((p) => globMatches(p, branch)) : void 0;
|
|
10454
11099
|
}
|
|
10455
11100
|
function batchCiProblems(root, batch) {
|
|
10456
|
-
const dir =
|
|
11101
|
+
const dir = path63.join(root, ".github", "workflows");
|
|
10457
11102
|
if (!existsSync(dir)) return [];
|
|
10458
11103
|
const problems = [];
|
|
10459
11104
|
for (const name of readdirSync(dir)) {
|
|
10460
11105
|
if (!/\.ya?ml$/.test(name)) continue;
|
|
10461
|
-
const workflow = readFileSync(
|
|
11106
|
+
const workflow = readFileSync(path63.join(dir, name), "utf8");
|
|
10462
11107
|
const main = runsOnPullRequestsInto(workflow, "main");
|
|
10463
11108
|
if (main && !runsOnPullRequestsInto(workflow, sampleBranch(batch))) {
|
|
10464
11109
|
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` });
|
|
@@ -10503,20 +11148,20 @@ function readObject(file, key2) {
|
|
|
10503
11148
|
}
|
|
10504
11149
|
}
|
|
10505
11150
|
function settings(root, options) {
|
|
10506
|
-
const fromPackage = readObject(
|
|
10507
|
-
const fromConfig = readObject(
|
|
11151
|
+
const fromPackage = readObject(path63.join(root, "package.json"), "genesisFeatures");
|
|
11152
|
+
const fromConfig = readObject(path63.join(root, "genesis.config.json"), "features");
|
|
10508
11153
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
10509
11154
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
10510
11155
|
}
|
|
10511
11156
|
async function loadRegistry(input) {
|
|
10512
|
-
const root =
|
|
11157
|
+
const root = path63.resolve(input.dir);
|
|
10513
11158
|
const options = settings(root, input);
|
|
10514
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
10515
|
-
if (!registry || !existsSync(
|
|
11159
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path63.join(root, p)));
|
|
11160
|
+
if (!registry || !existsSync(path63.join(root, registry))) {
|
|
10516
11161
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
10517
11162
|
}
|
|
10518
|
-
const jiti = createJiti(
|
|
10519
|
-
const load = async (file) => await jiti.import(
|
|
11163
|
+
const jiti = createJiti(path63.join(root, "package.json"), { moduleCache: false });
|
|
11164
|
+
const load = async (file) => await jiti.import(path63.join(root, file));
|
|
10520
11165
|
const mod = await load(registry);
|
|
10521
11166
|
const features2 = mod.features ?? mod.default;
|
|
10522
11167
|
if (!isObject5(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -10528,7 +11173,7 @@ async function loadRegistry(input) {
|
|
|
10528
11173
|
const project = {
|
|
10529
11174
|
...rest,
|
|
10530
11175
|
root,
|
|
10531
|
-
source: options.source ?? registry.split(
|
|
11176
|
+
source: options.source ?? registry.split(path63.sep).join("/"),
|
|
10532
11177
|
features: features2,
|
|
10533
11178
|
flags
|
|
10534
11179
|
};
|
|
@@ -10579,23 +11224,23 @@ async function runFeaturesCheck(options) {
|
|
|
10579
11224
|
function readFeaturePackages(root) {
|
|
10580
11225
|
const found = [];
|
|
10581
11226
|
const read3 = (dir, inRepo) => {
|
|
10582
|
-
const file =
|
|
11227
|
+
const file = path63.join(dir, "package.json");
|
|
10583
11228
|
if (!existsSync(file)) return;
|
|
10584
11229
|
try {
|
|
10585
11230
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
10586
11231
|
const layer = pkg.genesis?.layer;
|
|
10587
11232
|
if (typeof pkg.name !== "string" || !PACKAGE_LAYERS.includes(layer)) return;
|
|
10588
11233
|
if (found.some((p) => p.name === pkg.name)) return;
|
|
10589
|
-
found.push({ name: pkg.name, layer, ...inRepo ? { dir:
|
|
11234
|
+
found.push({ name: pkg.name, layer, ...inRepo ? { dir: path63.relative(root, dir).split(path63.sep).join("/") } : {} });
|
|
10590
11235
|
} catch {
|
|
10591
11236
|
}
|
|
10592
11237
|
};
|
|
10593
11238
|
for (const [base, inRepo] of [
|
|
10594
|
-
[
|
|
10595
|
-
[
|
|
11239
|
+
[path63.join(root, "packages"), true],
|
|
11240
|
+
[path63.join(root, "node_modules", "@marktiderman"), false]
|
|
10596
11241
|
]) {
|
|
10597
11242
|
if (!existsSync(base)) continue;
|
|
10598
|
-
for (const name of readdirSync(base)) read3(
|
|
11243
|
+
for (const name of readdirSync(base)) read3(path63.join(base, name), inRepo);
|
|
10599
11244
|
}
|
|
10600
11245
|
return found;
|
|
10601
11246
|
}
|
|
@@ -10712,7 +11357,7 @@ function readRegister(markdown) {
|
|
|
10712
11357
|
const need = at(row, "need");
|
|
10713
11358
|
if (!need || need === "-") problems.push(`${where2}: say the need in one line`);
|
|
10714
11359
|
const local = at(row, "local");
|
|
10715
|
-
if (local && local !== "-" && localPaths(local).some((p) =>
|
|
11360
|
+
if (local && local !== "-" && localPaths(local).some((p) => path63.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p) || p.split(/[\\/]/).includes(".."))) {
|
|
10716
11361
|
problems.push(`${where2}: local must be paths inside the app, relative to its root`);
|
|
10717
11362
|
}
|
|
10718
11363
|
const opt = (c) => at(row, c) && at(row, c) !== "-" ? at(row, c) : void 0;
|
|
@@ -10724,13 +11369,13 @@ function localPaths(local) {
|
|
|
10724
11369
|
return (local ?? "").split(/,\s+|<br\s*\/?>/i).map((p) => p.trim()).filter((p) => p && p !== "-");
|
|
10725
11370
|
}
|
|
10726
11371
|
function checkUpstream(root) {
|
|
10727
|
-
const found = REGISTER_PATHS.find((p) => existsSync(
|
|
11372
|
+
const found = REGISTER_PATHS.find((p) => existsSync(path63.join(root, p)));
|
|
10728
11373
|
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 };
|
|
10729
|
-
const { entries, problems } = readRegister(readFileSync(
|
|
11374
|
+
const { entries, problems } = readRegister(readFileSync(path63.join(root, found), "utf8"));
|
|
10730
11375
|
const warnings = [];
|
|
10731
11376
|
for (const e of entries) {
|
|
10732
11377
|
const paths = localPaths(e.local);
|
|
10733
|
-
const absent = paths.filter((p) => !existsSync(
|
|
11378
|
+
const absent = paths.filter((p) => !existsSync(path63.join(root, p)));
|
|
10734
11379
|
const present = paths.filter((p) => !absent.includes(p));
|
|
10735
11380
|
if (absent.length && e.status !== "promoted" && e.status !== "declined") problems.push(`${e.id}: local ${absent.join(", ")} doesn't exist`);
|
|
10736
11381
|
if (present.length && e.status === "promoted") {
|
|
@@ -10759,6 +11404,177 @@ var init_upstream = __esm({
|
|
|
10759
11404
|
}
|
|
10760
11405
|
});
|
|
10761
11406
|
|
|
11407
|
+
// src/client/init.ts
|
|
11408
|
+
var init_exports = {};
|
|
11409
|
+
__export(init_exports, {
|
|
11410
|
+
DEFAULT_CLIENT_DIR: () => DEFAULT_CLIENT_DIR2,
|
|
11411
|
+
clientConfigChange: () => clientConfigChange,
|
|
11412
|
+
normalizeClientDir: () => normalizeClientDir,
|
|
11413
|
+
planClientInit: () => planClientInit
|
|
11414
|
+
});
|
|
11415
|
+
function normalizeClientDir(raw) {
|
|
11416
|
+
const dir = raw.trim().replace(/^(\.\/)+/, "").replace(/\/{2,}/g, "/").replace(/\/+$/, "");
|
|
11417
|
+
if (raw.includes("\\") || !isPlainFolder(dir) || dir.split("/").includes(".")) {
|
|
11418
|
+
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 /)`);
|
|
11419
|
+
}
|
|
11420
|
+
return dir;
|
|
11421
|
+
}
|
|
11422
|
+
function layerFile() {
|
|
11423
|
+
return `// The app's client layer (ADR 0020): one provider for what every list and record page in the
|
|
11424
|
+
// app shares. Mount <ClientLayer> once, near the root, inside GenesisProvider.
|
|
11425
|
+
import type { ReactNode } from "react";
|
|
11426
|
+
import { createLocalSavedViewStore, type SavedViewStore } from "@marktiderman/genesis-core/resource-view";
|
|
11427
|
+
import { useBrowserSearchParams } from "@marktiderman/genesis-ui";
|
|
11428
|
+
import { ResourceViewDefaultsProvider } from "@marktiderman/genesis-ui/data";
|
|
11429
|
+
|
|
11430
|
+
/**
|
|
11431
|
+
* Where saved views live. The device store keeps them in this browser; swap in a store over the
|
|
11432
|
+
* app's own table (list, save, remove, under row-level security) to share them across devices
|
|
11433
|
+
* and with a team.
|
|
11434
|
+
*/
|
|
11435
|
+
export const savedViews: SavedViewStore = createLocalSavedViewStore();
|
|
11436
|
+
|
|
11437
|
+
export function ClientLayer({ children }: { children: ReactNode }) {
|
|
11438
|
+
// The router's search-params adapter: a TanStack or React Router app passes its own hook's.
|
|
11439
|
+
const urlState = useBrowserSearchParams();
|
|
11440
|
+
return (
|
|
11441
|
+
<ResourceViewDefaultsProvider sizeColumns clipCells pagerJumps savedViews={savedViews} urlState={urlState} rowActions>
|
|
11442
|
+
{children}
|
|
11443
|
+
</ResourceViewDefaultsProvider>
|
|
11444
|
+
);
|
|
11445
|
+
}
|
|
11446
|
+
`;
|
|
11447
|
+
}
|
|
11448
|
+
function resourceViewFile() {
|
|
11449
|
+
return `// The app's ResourceView (ADR 0020): Genesis's, with the app's defaults. Screens render this one,
|
|
11450
|
+
// never Genesis's directly, so a default the app changes reaches every list at once.
|
|
11451
|
+
import { ResourceView as GenesisResourceView, type ResourceViewProps } from "@marktiderman/genesis-ui/data";
|
|
11452
|
+
|
|
11453
|
+
type Row = Record<string, unknown>;
|
|
11454
|
+
|
|
11455
|
+
export function ResourceView<T extends Row = Row>(props: ResourceViewProps<T>) {
|
|
11456
|
+
return <GenesisResourceView<T> createdToast {...props} />;
|
|
11457
|
+
}
|
|
11458
|
+
|
|
11459
|
+
export type { ResourceViewProps };
|
|
11460
|
+
`;
|
|
11461
|
+
}
|
|
11462
|
+
function recordViewFile() {
|
|
11463
|
+
return `// The app's RecordView (ADR 0020): Genesis's record page, with the app's defaults. Screens render
|
|
11464
|
+
// this one, never Genesis's directly, so a default the app changes reaches every record page at once.
|
|
11465
|
+
import { RecordView as GenesisRecordView, type RecordViewProps } from "@marktiderman/genesis-ui/data";
|
|
11466
|
+
|
|
11467
|
+
type Row = Record<string, unknown>;
|
|
11468
|
+
|
|
11469
|
+
export function RecordView<T extends Row = Row>(props: RecordViewProps<T>) {
|
|
11470
|
+
return <GenesisRecordView<T> {...props} />;
|
|
11471
|
+
}
|
|
11472
|
+
|
|
11473
|
+
export type { RecordViewProps };
|
|
11474
|
+
`;
|
|
11475
|
+
}
|
|
11476
|
+
function contractFile(type) {
|
|
11477
|
+
const name = camel(type);
|
|
11478
|
+
const table = type.replace(/-/g, "_");
|
|
11479
|
+
const Row = `${name[0].toUpperCase()}${name.slice(1)}Row`;
|
|
11480
|
+
return `// The ${type} contract: its fields and identity. A starting example so the view works today; once
|
|
11481
|
+
// the app generates its contracts, export the generated one instead:
|
|
11482
|
+
// export { contracts["public.${table}"] as ${name}Contract } \u2026 from "../../lib/resources.genesis";
|
|
11483
|
+
import { defineResource } from "@marktiderman/genesis-core";
|
|
11484
|
+
|
|
11485
|
+
export interface ${Row} {
|
|
11486
|
+
id: string;
|
|
11487
|
+
name: string;
|
|
11488
|
+
status: string;
|
|
11489
|
+
updated_at: string;
|
|
11490
|
+
[field: string]: unknown;
|
|
11491
|
+
}
|
|
11492
|
+
|
|
11493
|
+
export const ${name}Contract = defineResource<${Row}>()({
|
|
11494
|
+
name: "public.${table}",
|
|
11495
|
+
key: "id",
|
|
11496
|
+
labelField: "name",
|
|
11497
|
+
noun: "${type.replace(/-/g, " ")}",
|
|
11498
|
+
fields: [
|
|
11499
|
+
{ name: "id", type: "string", readOnly: true },
|
|
11500
|
+
{ name: "name", type: "string", label: "Name" },
|
|
11501
|
+
{ name: "status", type: "string", label: "Status" },
|
|
11502
|
+
{ name: "updated_at", type: "datetime", label: "Updated", readOnly: true },
|
|
11503
|
+
],
|
|
11504
|
+
});
|
|
11505
|
+
`;
|
|
11506
|
+
}
|
|
11507
|
+
function viewFile(type) {
|
|
11508
|
+
const name = camel(type);
|
|
11509
|
+
return `// The ${type} view (ADR 0020): what a ${type} record means to people. One view per resource; every
|
|
11510
|
+
// screen of ${type} renders this one, narrowed by its own props.
|
|
11511
|
+
import { defineView } from "@marktiderman/genesis-core/resource-view";
|
|
11512
|
+
import { ${name}Contract } from "./contract";
|
|
11513
|
+
|
|
11514
|
+
export const ${name}View = defineView(${name}Contract, {
|
|
11515
|
+
columns: { default: ["name", "status", "updated_at"] },
|
|
11516
|
+
segments: [{ id: "all", label: "All" }],
|
|
11517
|
+
filters: [{ field: "status" }],
|
|
11518
|
+
export: true,
|
|
11519
|
+
// fields: { status: { tones: { active: "success" } } },
|
|
11520
|
+
// actions: [{ name: "archive", label: "Archive", bulk: true }],
|
|
11521
|
+
});
|
|
11522
|
+
`;
|
|
11523
|
+
}
|
|
11524
|
+
function appearanceFile(type) {
|
|
11525
|
+
const name = camel(type);
|
|
11526
|
+
return `// How a ${type} record looks (ADR 0020): its own cells, its card and its record page. Keep the
|
|
11527
|
+
// rules in view.ts; this file draws.
|
|
11528
|
+
import type { ReactNode } from "react";
|
|
11529
|
+
|
|
11530
|
+
type ${name[0].toUpperCase()}${name.slice(1)}Row = Record<string, unknown>;
|
|
11531
|
+
|
|
11532
|
+
/** Cells this type draws its own way, by column key (ResourceView's \`cells\`). */
|
|
11533
|
+
export const ${name}Cells: Partial<Record<string, (row: ${name[0].toUpperCase()}${name.slice(1)}Row) => ReactNode>> = {};
|
|
11534
|
+
`;
|
|
11535
|
+
}
|
|
11536
|
+
function planClientInit(options = {}) {
|
|
11537
|
+
const dir = normalizeClientDir(options.dir ?? DEFAULT_CLIENT_DIR2);
|
|
11538
|
+
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`);
|
|
11539
|
+
const files = [
|
|
11540
|
+
{ path: `${dir}/client-layer.tsx`, content: layerFile() },
|
|
11541
|
+
{ path: `${dir}/resource-view.tsx`, content: resourceViewFile() },
|
|
11542
|
+
{ path: `${dir}/record-view.tsx`, content: recordViewFile() },
|
|
11543
|
+
{ path: `${dir}/cells/index.ts`, content: "// Cells the app draws its own way, shared by its types (ADR 0020).\nexport {};\n" },
|
|
11544
|
+
{ path: `${dir}/components/index.ts`, content: "// The app's own parts (ADR 0020): name each element's data-slot app-<name>.\nexport {};\n" },
|
|
11545
|
+
{
|
|
11546
|
+
path: `${dir}/view-types/index.ts`,
|
|
11547
|
+
content: "// View types the app registers (ADR 0021): defineViewType, then registerViewType once at start-up.\nexport {};\n"
|
|
11548
|
+
}
|
|
11549
|
+
];
|
|
11550
|
+
if (options.type) {
|
|
11551
|
+
files.push({ path: `${dir}/${options.type}/contract.ts`, content: contractFile(options.type) });
|
|
11552
|
+
files.push({ path: `${dir}/${options.type}/view.ts`, content: viewFile(options.type) });
|
|
11553
|
+
files.push({ path: `${dir}/${options.type}/appearance.tsx`, content: appearanceFile(options.type) });
|
|
11554
|
+
}
|
|
11555
|
+
const steps = [
|
|
11556
|
+
`Mount <ClientLayer> from ${dir}/client-layer.tsx once, inside GenesisProvider.`,
|
|
11557
|
+
`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.`,
|
|
11558
|
+
...dir !== DEFAULT_CLIENT_DIR2 ? [`genesis.config.json now names the folder: { "client": { "dir": "${dir}" } }.`] : []
|
|
11559
|
+
];
|
|
11560
|
+
return { dir, files, steps };
|
|
11561
|
+
}
|
|
11562
|
+
function clientConfigChange(planned, configured, force = false) {
|
|
11563
|
+
if (configured === void 0) return planned === DEFAULT_CLIENT_DIR2 ? "none" : "write";
|
|
11564
|
+
if (configured === planned) return "none";
|
|
11565
|
+
if (!force) throw new Error(`client init: genesis.config.json names the client layer's folder "${configured}"; pass --force to move it to "${planned}"`);
|
|
11566
|
+
return "write";
|
|
11567
|
+
}
|
|
11568
|
+
var DEFAULT_CLIENT_DIR2, TYPE, camel;
|
|
11569
|
+
var init_init = __esm({
|
|
11570
|
+
"src/client/init.ts"() {
|
|
11571
|
+
init_config();
|
|
11572
|
+
DEFAULT_CLIENT_DIR2 = "src/client";
|
|
11573
|
+
TYPE = /^(?=.{1,40}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
11574
|
+
camel = (name) => name.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
11575
|
+
}
|
|
11576
|
+
});
|
|
11577
|
+
|
|
10762
11578
|
// src/studio/wire-route.ts
|
|
10763
11579
|
function routeTags(source) {
|
|
10764
11580
|
const tags = [];
|
|
@@ -10795,8 +11611,8 @@ function routeTags(source) {
|
|
|
10795
11611
|
}
|
|
10796
11612
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
10797
11613
|
const tags = routeTags(source);
|
|
10798
|
-
const
|
|
10799
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
11614
|
+
const relative20 = route.replace(/^\//, "");
|
|
11615
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative20.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
10800
11616
|
if (existing) {
|
|
10801
11617
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
10802
11618
|
}
|
|
@@ -10804,17 +11620,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
10804
11620
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
10805
11621
|
if (roots.length !== 1) {
|
|
10806
11622
|
return {
|
|
10807
|
-
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${
|
|
11623
|
+
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative20}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
10808
11624
|
};
|
|
10809
11625
|
}
|
|
10810
11626
|
const layout = roots[0];
|
|
10811
11627
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
10812
|
-
if (base && !
|
|
11628
|
+
if (base && !relative20.startsWith(`${base}/`)) {
|
|
10813
11629
|
return {
|
|
10814
11630
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
10815
11631
|
};
|
|
10816
11632
|
}
|
|
10817
|
-
const childPath = base ?
|
|
11633
|
+
const childPath = base ? relative20.slice(base.length + 1) : relative20;
|
|
10818
11634
|
const guard = GUARD.exec(source)?.[1];
|
|
10819
11635
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
10820
11636
|
const before = source.slice(0, layout.close);
|
|
@@ -10850,8 +11666,8 @@ var init_wire_route = __esm({
|
|
|
10850
11666
|
});
|
|
10851
11667
|
|
|
10852
11668
|
// src/studio/init.ts
|
|
10853
|
-
var
|
|
10854
|
-
__export(
|
|
11669
|
+
var init_exports2 = {};
|
|
11670
|
+
__export(init_exports2, {
|
|
10855
11671
|
detectHost: () => detectHost,
|
|
10856
11672
|
planStudioInit: () => planStudioInit
|
|
10857
11673
|
});
|
|
@@ -11121,7 +11937,7 @@ ${line}
|
|
|
11121
11937
|
);
|
|
11122
11938
|
}
|
|
11123
11939
|
var SERVER_VERSION, PACKAGES, ROLE, LOVABLE_CLIENT;
|
|
11124
|
-
var
|
|
11940
|
+
var init_init2 = __esm({
|
|
11125
11941
|
"src/studio/init.ts"() {
|
|
11126
11942
|
init_wire_route();
|
|
11127
11943
|
SERVER_VERSION = createRequire(import.meta.url)("@marktiderman/genesis-studio-server/package.json").version;
|
|
@@ -11180,7 +11996,7 @@ function literal(value, indent) {
|
|
|
11180
11996
|
if (Array.isArray(value)) return `[${value.map((v) => literal(v, indent)).join(", ")}]`;
|
|
11181
11997
|
if (value && typeof value === "object") {
|
|
11182
11998
|
const inner = `${indent} `;
|
|
11183
|
-
const lines = Object.entries(value).map(([k, v]) => `${inner}${
|
|
11999
|
+
const lines = Object.entries(value).map(([k, v]) => `${inner}${IDENT2.test(k) ? k : JSON.stringify(k)}: ${literal(v, inner)},`);
|
|
11184
12000
|
return `{
|
|
11185
12001
|
${lines.join("\n")}
|
|
11186
12002
|
${indent}}`;
|
|
@@ -11188,8 +12004,8 @@ ${indent}}`;
|
|
|
11188
12004
|
return JSON.stringify(value);
|
|
11189
12005
|
}
|
|
11190
12006
|
function featureKindField(root) {
|
|
11191
|
-
for (let dir =
|
|
11192
|
-
for (const file of [
|
|
12007
|
+
for (let dir = path63.resolve(root); ; dir = path63.dirname(dir)) {
|
|
12008
|
+
for (const file of [path63.join(dir, "node_modules/@marktiderman/genesis-features/package.json"), path63.join(dir, "packages/features/package.json")]) {
|
|
11193
12009
|
try {
|
|
11194
12010
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
11195
12011
|
if (pkg.name !== "@marktiderman/genesis-features" || !pkg.version) continue;
|
|
@@ -11198,7 +12014,7 @@ function featureKindField(root) {
|
|
|
11198
12014
|
} catch {
|
|
11199
12015
|
}
|
|
11200
12016
|
}
|
|
11201
|
-
if (
|
|
12017
|
+
if (path63.dirname(dir) === dir) return "layer";
|
|
11202
12018
|
}
|
|
11203
12019
|
}
|
|
11204
12020
|
function featureSnippet(manifest, owner, kindField = "kind") {
|
|
@@ -11268,20 +12084,20 @@ function addFeatureEntry(text, snippet) {
|
|
|
11268
12084
|
return `${head.replace(/\s*$/, "")}
|
|
11269
12085
|
${snippet}${text.slice(scan.close)}`;
|
|
11270
12086
|
}
|
|
11271
|
-
var
|
|
12087
|
+
var IDENT2;
|
|
11272
12088
|
var init_registry_edit = __esm({
|
|
11273
12089
|
"src/blocks/registry-edit.ts"() {
|
|
11274
|
-
|
|
12090
|
+
IDENT2 = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
11275
12091
|
}
|
|
11276
12092
|
});
|
|
11277
12093
|
function routerRoot2(root) {
|
|
11278
12094
|
try {
|
|
11279
|
-
const config = JSON.parse(readFileSync(
|
|
12095
|
+
const config = JSON.parse(readFileSync(path63.join(root, "genesis.config.json"), "utf8"));
|
|
11280
12096
|
const configured = config.doctor?.native?.routerRoot;
|
|
11281
|
-
if (configured && existsSync(
|
|
12097
|
+
if (configured && existsSync(path63.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
11282
12098
|
} catch {
|
|
11283
12099
|
}
|
|
11284
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
12100
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path63.join(root, dir, "_layout.tsx"))) return dir;
|
|
11285
12101
|
return null;
|
|
11286
12102
|
}
|
|
11287
12103
|
function routeOf(file) {
|
|
@@ -11343,7 +12159,7 @@ __export(add_exports, {
|
|
|
11343
12159
|
});
|
|
11344
12160
|
function appDependencies(root) {
|
|
11345
12161
|
try {
|
|
11346
|
-
const pkg = JSON.parse(readFileSync(
|
|
12162
|
+
const pkg = JSON.parse(readFileSync(path63.join(root, "package.json"), "utf8"));
|
|
11347
12163
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
11348
12164
|
} catch {
|
|
11349
12165
|
return {};
|
|
@@ -11352,14 +12168,14 @@ function appDependencies(root) {
|
|
|
11352
12168
|
function registryFile(root) {
|
|
11353
12169
|
const read3 = (file, key2) => {
|
|
11354
12170
|
try {
|
|
11355
|
-
const v = JSON.parse(readFileSync(
|
|
12171
|
+
const v = JSON.parse(readFileSync(path63.join(root, file), "utf8"))[key2]?.registry;
|
|
11356
12172
|
return typeof v === "string" ? v : void 0;
|
|
11357
12173
|
} catch {
|
|
11358
12174
|
return void 0;
|
|
11359
12175
|
}
|
|
11360
12176
|
};
|
|
11361
12177
|
const named = read3("genesis.config.json", "features") ?? read3("package.json", "genesisFeatures");
|
|
11362
|
-
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(
|
|
12178
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path63.join(root, candidate))) return candidate;
|
|
11363
12179
|
return null;
|
|
11364
12180
|
}
|
|
11365
12181
|
async function registryIds(root, file) {
|
|
@@ -11447,7 +12263,7 @@ verify_jwt = false
|
|
|
11447
12263
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
11448
12264
|
}
|
|
11449
12265
|
async function runAdd(options) {
|
|
11450
|
-
const root =
|
|
12266
|
+
const root = path63.resolve(options.root);
|
|
11451
12267
|
const log = options.log ?? SILENT;
|
|
11452
12268
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
11453
12269
|
const warnings = [];
|
|
@@ -11686,7 +12502,7 @@ function notificationTypesSql(rows, registryFile2) {
|
|
|
11686
12502
|
}
|
|
11687
12503
|
function configuredRegistry(root) {
|
|
11688
12504
|
try {
|
|
11689
|
-
const raw = JSON.parse(readFileSync(
|
|
12505
|
+
const raw = JSON.parse(readFileSync(path63.join(root, "genesis.config.json"), "utf8"));
|
|
11690
12506
|
return typeof raw.notifications?.registry === "string" ? raw.notifications.registry : void 0;
|
|
11691
12507
|
} catch {
|
|
11692
12508
|
return void 0;
|
|
@@ -11705,14 +12521,14 @@ async function planNotificationTypes(root, options) {
|
|
|
11705
12521
|
warnings.push(`Notification types: not checked on a dry run (loading ${file} runs app code).`);
|
|
11706
12522
|
return { registry: file, warnings };
|
|
11707
12523
|
}
|
|
11708
|
-
const absolute =
|
|
12524
|
+
const absolute = path63.resolve(root, file);
|
|
11709
12525
|
if (!existsSync(absolute)) {
|
|
11710
12526
|
warnings.push(`Notification types: ${file} doesn't exist (a relative path is resolved against the app's root, ${root}).`);
|
|
11711
12527
|
return { registry: file, warnings };
|
|
11712
12528
|
}
|
|
11713
12529
|
let mod;
|
|
11714
12530
|
try {
|
|
11715
|
-
const jiti = createJiti(
|
|
12531
|
+
const jiti = createJiti(path63.join(root, "package.json"), { moduleCache: false });
|
|
11716
12532
|
mod = await jiti.import(absolute);
|
|
11717
12533
|
} catch (err) {
|
|
11718
12534
|
warnings.push(`Notification types: couldn't load ${file} (${err instanceof Error ? err.message : String(err)}).`);
|
|
@@ -11723,8 +12539,8 @@ async function planNotificationTypes(root, options) {
|
|
|
11723
12539
|
warnings.push(`Notification types: ${file} exports no defineNotifications registry (export it as \`notifications\`).`);
|
|
11724
12540
|
return { registry: file, warnings };
|
|
11725
12541
|
}
|
|
11726
|
-
const shown =
|
|
11727
|
-
const content = notificationTypesSql(found.toTypeRows(), shown.split(
|
|
12542
|
+
const shown = path63.isAbsolute(file) ? path63.relative(root, absolute) : file;
|
|
12543
|
+
const content = notificationTypesSql(found.toTypeRows(), shown.split(path63.sep).join("/"));
|
|
11728
12544
|
const app = readAppMigrations(root);
|
|
11729
12545
|
const latest = app.filter((m) => m.name.endsWith(`_${TYPES_STEM}.sql`)).sort((a, b) => a.name < b.name ? -1 : 1).pop();
|
|
11730
12546
|
if (latest && payloadOf(latest.content) === payloadOf(content)) return { registry: file, warnings };
|
|
@@ -11756,7 +12572,7 @@ __export(migrate_exports, {
|
|
|
11756
12572
|
runMigrate: () => runMigrate
|
|
11757
12573
|
});
|
|
11758
12574
|
async function runMigrate(options) {
|
|
11759
|
-
const root =
|
|
12575
|
+
const root = path63.resolve(options.root);
|
|
11760
12576
|
const lock = readLock(root);
|
|
11761
12577
|
const warnings = [];
|
|
11762
12578
|
const home = databaseElsewhere(root);
|
|
@@ -11873,7 +12689,7 @@ function repositoryDirectory(root, name) {
|
|
|
11873
12689
|
const dir = packageDir(root, name);
|
|
11874
12690
|
if (!dir) return null;
|
|
11875
12691
|
try {
|
|
11876
|
-
const { repository } = JSON.parse(readFileSync(
|
|
12692
|
+
const { repository } = JSON.parse(readFileSync(path63.join(dir, "package.json"), "utf8"));
|
|
11877
12693
|
return typeof repository?.directory === "string" ? repository.directory : null;
|
|
11878
12694
|
} catch {
|
|
11879
12695
|
return null;
|
|
@@ -11952,11 +12768,11 @@ var init_new_exports = __esm({
|
|
|
11952
12768
|
}
|
|
11953
12769
|
});
|
|
11954
12770
|
function walk3(dir, rel = "", out = /* @__PURE__ */ new Map()) {
|
|
11955
|
-
for (const entry of readdirSync(
|
|
12771
|
+
for (const entry of readdirSync(path63.join(dir, rel), { withFileTypes: true })) {
|
|
11956
12772
|
if (SKIP.has(entry.name)) continue;
|
|
11957
12773
|
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
11958
12774
|
if (entry.isDirectory()) walk3(dir, child, out);
|
|
11959
|
-
else if (entry.isFile()) out.set(child, readFileSync(
|
|
12775
|
+
else if (entry.isFile()) out.set(child, readFileSync(path63.join(dir, child)));
|
|
11960
12776
|
}
|
|
11961
12777
|
return out;
|
|
11962
12778
|
}
|
|
@@ -11979,7 +12795,7 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
11979
12795
|
const tag = `${name}@${version}`;
|
|
11980
12796
|
try {
|
|
11981
12797
|
if (!clone) {
|
|
11982
|
-
clone = mkdtempSync(
|
|
12798
|
+
clone = mkdtempSync(path63.join(tmpdir(), "genesis-upstream-"));
|
|
11983
12799
|
git4(["init", "-q"]);
|
|
11984
12800
|
}
|
|
11985
12801
|
git4(["fetch", "-q", "--no-tags", "--depth", "1", repository, `+refs/tags/${tag}:refs/tags/${tag}`]);
|
|
@@ -11996,7 +12812,7 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
11996
12812
|
}
|
|
11997
12813
|
});
|
|
11998
12814
|
if (!manifest) return { error: `the tag ${tag} has no package named ${name}` };
|
|
11999
|
-
const dir =
|
|
12815
|
+
const dir = path63.posix.dirname(manifest);
|
|
12000
12816
|
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)));
|
|
12001
12817
|
const files = /* @__PURE__ */ new Map();
|
|
12002
12818
|
if (entries.length) {
|
|
@@ -12022,10 +12838,10 @@ function gitUpstream(repository = GENESIS_REPOSITORY) {
|
|
|
12022
12838
|
}
|
|
12023
12839
|
function diffHunks(before, after) {
|
|
12024
12840
|
if (before === after) return [];
|
|
12025
|
-
const dir = mkdtempSync(
|
|
12841
|
+
const dir = mkdtempSync(path63.join(tmpdir(), "genesis-diff-"));
|
|
12026
12842
|
try {
|
|
12027
|
-
writeFileSync(
|
|
12028
|
-
writeFileSync(
|
|
12843
|
+
writeFileSync(path63.join(dir, "a"), before);
|
|
12844
|
+
writeFileSync(path63.join(dir, "b"), after);
|
|
12029
12845
|
let out = "";
|
|
12030
12846
|
try {
|
|
12031
12847
|
out = execFileSync("git", ["diff", "--no-index", "--no-color", "-U0", "a", "b"], { cwd: dir, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
@@ -12053,9 +12869,9 @@ function shippedBy(upstreamHunks) {
|
|
|
12053
12869
|
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]));
|
|
12054
12870
|
}
|
|
12055
12871
|
function promotions(root, name) {
|
|
12056
|
-
const file = REGISTER_PATHS.find((p) => existsSync(
|
|
12872
|
+
const file = REGISTER_PATHS.find((p) => existsSync(path63.join(root, p)));
|
|
12057
12873
|
if (!file) return [];
|
|
12058
|
-
const text = readFileSync(
|
|
12874
|
+
const text = readFileSync(path63.join(root, file), "utf8");
|
|
12059
12875
|
const rows = text.split("\n");
|
|
12060
12876
|
return readRegister(text).entries.filter((e) => e.status === "promoted" && e.package === name).map((e) => {
|
|
12061
12877
|
const row = rows.find((r) => r.split("|").map((c) => c.trim())[1] === e.id) ?? "";
|
|
@@ -12113,7 +12929,7 @@ function planOverlays(root, wanted, upstream2, manifests = ["package.json"]) {
|
|
|
12113
12929
|
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
12114
12930
|
let json;
|
|
12115
12931
|
try {
|
|
12116
|
-
json = JSON.parse(readFileSync(
|
|
12932
|
+
json = JSON.parse(readFileSync(path63.join(pkg.dir, "package.json"), "utf8"));
|
|
12117
12933
|
} catch {
|
|
12118
12934
|
continue;
|
|
12119
12935
|
}
|
|
@@ -12239,7 +13055,7 @@ function folderReferences(root, plan) {
|
|
|
12239
13055
|
for (const file of candidates.sort()) {
|
|
12240
13056
|
let text;
|
|
12241
13057
|
try {
|
|
12242
|
-
text = readFileSync(
|
|
13058
|
+
text = readFileSync(path63.join(root, file), "utf8");
|
|
12243
13059
|
} catch {
|
|
12244
13060
|
continue;
|
|
12245
13061
|
}
|
|
@@ -12251,7 +13067,7 @@ function folderReferences(root, plan) {
|
|
|
12251
13067
|
function planPins(root, plan, manifests) {
|
|
12252
13068
|
const pins = /* @__PURE__ */ new Map();
|
|
12253
13069
|
for (const file of manifests) {
|
|
12254
|
-
const abs =
|
|
13070
|
+
const abs = path63.join(root, file);
|
|
12255
13071
|
if (!existsSync(abs)) continue;
|
|
12256
13072
|
const text = readFileSync(abs, "utf8");
|
|
12257
13073
|
const pinned = pinManifest(root, plan, file, text);
|
|
@@ -12269,9 +13085,9 @@ function pinManifest(root, plan, file, text) {
|
|
|
12269
13085
|
} catch {
|
|
12270
13086
|
return void 0;
|
|
12271
13087
|
}
|
|
12272
|
-
const overlay =
|
|
12273
|
-
const here =
|
|
12274
|
-
const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) &&
|
|
13088
|
+
const overlay = path63.resolve(root, plan.rel);
|
|
13089
|
+
const here = path63.dirname(path63.join(root, file));
|
|
13090
|
+
const local = (spec) => typeof spec === "string" && (spec.startsWith("workspace:") || /^(file|link):/.test(spec) && path63.resolve(here, spec.slice(5)) === overlay);
|
|
12275
13091
|
let touched2 = false;
|
|
12276
13092
|
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
12277
13093
|
const deps = json[section2];
|
|
@@ -12286,7 +13102,7 @@ function pinManifest(root, plan, file, text) {
|
|
|
12286
13102
|
touched2 = true;
|
|
12287
13103
|
}
|
|
12288
13104
|
}
|
|
12289
|
-
const names = (entry) => typeof entry === "string" &&
|
|
13105
|
+
const names = (entry) => typeof entry === "string" && path63.resolve(here, entry) === overlay;
|
|
12290
13106
|
const ws = json.workspaces;
|
|
12291
13107
|
const list = Array.isArray(ws) ? ws : isObject6(ws) && Array.isArray(ws.packages) ? ws.packages : null;
|
|
12292
13108
|
if (list?.some(names)) {
|
|
@@ -12304,10 +13120,10 @@ function applyOverlayPlans(root, plans, lockEdits = []) {
|
|
|
12304
13120
|
const removedFolders = [];
|
|
12305
13121
|
for (const plan of plans) {
|
|
12306
13122
|
if (plan.skipped || plan.conflicts.length) continue;
|
|
12307
|
-
const dir =
|
|
13123
|
+
const dir = path63.join(root, plan.rel);
|
|
12308
13124
|
if (plan.remove) {
|
|
12309
13125
|
for (const file of plan.pins.keys()) {
|
|
12310
|
-
const abs =
|
|
13126
|
+
const abs = path63.join(root, file);
|
|
12311
13127
|
const now = existsSync(abs) ? readFileSync(abs, "utf8") : null;
|
|
12312
13128
|
const text = now === null ? plan.pins.get(file) : pinManifest(root, plan, file, now);
|
|
12313
13129
|
if (typeof text !== "string") continue;
|
|
@@ -12320,10 +13136,10 @@ function applyOverlayPlans(root, plans, lockEdits = []) {
|
|
|
12320
13136
|
continue;
|
|
12321
13137
|
}
|
|
12322
13138
|
for (const [file, bytes] of plan.writes) {
|
|
12323
|
-
const target =
|
|
13139
|
+
const target = path63.join(dir, file);
|
|
12324
13140
|
if (bytes === null) rmSync(target, { force: true });
|
|
12325
13141
|
else {
|
|
12326
|
-
mkdirSync(
|
|
13142
|
+
mkdirSync(path63.dirname(target), { recursive: true });
|
|
12327
13143
|
writeFileSync(target, bytes);
|
|
12328
13144
|
}
|
|
12329
13145
|
changed.push(`${plan.rel}/${file}`);
|
|
@@ -12345,7 +13161,7 @@ function dropRemovedWorkspaces(root, folders) {
|
|
|
12345
13161
|
const packages = [];
|
|
12346
13162
|
try {
|
|
12347
13163
|
for (const folder of folders) {
|
|
12348
|
-
const entries = workspaceEntries(text,
|
|
13164
|
+
const entries = workspaceEntries(text, path63.relative(found.dir, folder).split(path63.sep).join("/"));
|
|
12349
13165
|
workspaces.push(...entries.workspaces);
|
|
12350
13166
|
packages.push(...entries.packages);
|
|
12351
13167
|
}
|
|
@@ -12353,8 +13169,8 @@ function dropRemovedWorkspaces(root, folders) {
|
|
|
12353
13169
|
return null;
|
|
12354
13170
|
}
|
|
12355
13171
|
if (!workspaces.length && !packages.length) return null;
|
|
12356
|
-
writeFileSync(
|
|
12357
|
-
return { file:
|
|
13172
|
+
writeFileSync(path63.join(found.dir, BUN_LOCK), removeBunLockEntries(text, { workspaces, packages }));
|
|
13173
|
+
return { file: path63.relative(root, path63.join(found.dir, BUN_LOCK)).split(path63.sep).join("/"), workspaces };
|
|
12358
13174
|
}
|
|
12359
13175
|
function overlayChecklist(plans) {
|
|
12360
13176
|
if (!plans.length) return [];
|
|
@@ -12419,8 +13235,8 @@ function pruneBunLock(root, want, dryRun) {
|
|
|
12419
13235
|
return null;
|
|
12420
13236
|
}
|
|
12421
13237
|
if (!pruned.length) return null;
|
|
12422
|
-
if (!dryRun) writeFileSync(
|
|
12423
|
-
return { file:
|
|
13238
|
+
if (!dryRun) writeFileSync(path63.join(found.dir, BUN_LOCK), removeBunLockEntries(text, { packages: pruned.map((p) => p.key) }));
|
|
13239
|
+
return { file: path63.relative(root, path63.join(found.dir, BUN_LOCK)).split(path63.sep).join("/"), pruned };
|
|
12424
13240
|
}
|
|
12425
13241
|
function npm(args, cwd) {
|
|
12426
13242
|
return execFileSync("npm", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
@@ -12432,11 +13248,11 @@ function npmLookup(cwd) {
|
|
|
12432
13248
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
12433
13249
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
12434
13250
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
12435
|
-
const tmp = mkdtempSync(
|
|
13251
|
+
const tmp = mkdtempSync(path63.join(tmpdir(), "genesis-umbrella-"));
|
|
12436
13252
|
try {
|
|
12437
13253
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
12438
|
-
execFileSync("tar", ["-xzf",
|
|
12439
|
-
const manifest = JSON.parse(readFileSync(
|
|
13254
|
+
execFileSync("tar", ["-xzf", path63.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
13255
|
+
const manifest = JSON.parse(readFileSync(path63.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
12440
13256
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
12441
13257
|
return manifest;
|
|
12442
13258
|
} finally {
|
|
@@ -12482,8 +13298,8 @@ function readText2(file) {
|
|
|
12482
13298
|
function tidyReleaseAgeExcludes(file) {
|
|
12483
13299
|
const before = readText2(file);
|
|
12484
13300
|
if (before === null) return false;
|
|
12485
|
-
const dir =
|
|
12486
|
-
const after = normaliseReleaseAgeExcludes(before, tidyLocked(before, readText2(
|
|
13301
|
+
const dir = path63.dirname(file);
|
|
13302
|
+
const after = normaliseReleaseAgeExcludes(before, tidyLocked(before, readText2(path63.join(dir, "pnpm-lock.yaml")), readText2(path63.join(dir, ".npmrc"))));
|
|
12487
13303
|
if (after === before) return false;
|
|
12488
13304
|
writeFileSync(file, after);
|
|
12489
13305
|
return true;
|
|
@@ -12499,14 +13315,14 @@ function gitTopLevel(root) {
|
|
|
12499
13315
|
function folderBelowTopLevel(root) {
|
|
12500
13316
|
const real2 = realpathSync(root);
|
|
12501
13317
|
const top = gitTopLevel(real2);
|
|
12502
|
-
return top === null ? null :
|
|
13318
|
+
return top === null ? null : path63.relative(top, real2).split(path63.sep).join("/");
|
|
12503
13319
|
}
|
|
12504
13320
|
function pnpmWorkspaceFileFor(root) {
|
|
12505
13321
|
const real2 = realpathSync(root);
|
|
12506
13322
|
const top = gitTopLevel(real2);
|
|
12507
13323
|
const lockDir = findLockfile(real2)?.dir;
|
|
12508
13324
|
const fallback = lockDir && (!top || inside2(top, lockDir)) ? lockDir : real2;
|
|
12509
|
-
return pnpmWorkspaceFile(real2, fallback, { exists: existsSync, join:
|
|
13325
|
+
return pnpmWorkspaceFile(real2, fallback, { exists: existsSync, join: path63.join, dirname: path63.dirname }, top ?? void 0);
|
|
12510
13326
|
}
|
|
12511
13327
|
function pnpmVersionIn(root) {
|
|
12512
13328
|
try {
|
|
@@ -12556,7 +13372,7 @@ function packageJsons(root) {
|
|
|
12556
13372
|
if (files.length) return files;
|
|
12557
13373
|
} catch {
|
|
12558
13374
|
}
|
|
12559
|
-
return existsSync(
|
|
13375
|
+
return existsSync(path63.join(root, "package.json")) ? ["package.json"] : [];
|
|
12560
13376
|
}
|
|
12561
13377
|
function sourceText(root, source, substitutions) {
|
|
12562
13378
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -12576,12 +13392,12 @@ function sourceText(root, source, substitutions) {
|
|
|
12576
13392
|
}
|
|
12577
13393
|
}
|
|
12578
13394
|
async function runUpgrade(options) {
|
|
12579
|
-
const root =
|
|
13395
|
+
const root = path63.resolve(options.root);
|
|
12580
13396
|
const log = options.log ?? (() => {
|
|
12581
13397
|
});
|
|
12582
13398
|
checkInstalled(root, options);
|
|
12583
13399
|
const lookup = options.lookup ?? npmLookup(root);
|
|
12584
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
13400
|
+
const release = options.manifest ? JSON.parse(readFileSync(path63.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
12585
13401
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
12586
13402
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
12587
13403
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -12679,7 +13495,7 @@ async function runUpgrade(options) {
|
|
|
12679
13495
|
const excludeWarnings = [];
|
|
12680
13496
|
if (!options.dryRun && options.install !== false && (bumped.size || bunLock)) {
|
|
12681
13497
|
const workspaceFile = pm === "pnpm" ? pnpmWorkspaceFileFor(root) : null;
|
|
12682
|
-
const relWorkspace = workspaceFile ?
|
|
13498
|
+
const relWorkspace = workspaceFile ? path63.relative(realpathSync(root), workspaceFile) : null;
|
|
12683
13499
|
const workspaceBefore = workspaceFile ? readText2(workspaceFile) : null;
|
|
12684
13500
|
const tidy = () => {
|
|
12685
13501
|
if (!workspaceFile || !tidyReleaseAgeExcludes(workspaceFile)) return;
|
|
@@ -12912,7 +13728,7 @@ function checkSubstitutions(substitutions) {
|
|
|
12912
13728
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
12913
13729
|
let names;
|
|
12914
13730
|
try {
|
|
12915
|
-
const was = starterIdentity(readFileSync(
|
|
13731
|
+
const was = starterIdentity(readFileSync(path63.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
12916
13732
|
names = [was.name, was.slug, was.scheme, was.bundleId];
|
|
12917
13733
|
} catch {
|
|
12918
13734
|
names = [];
|
|
@@ -12928,9 +13744,9 @@ function checkSubstitutions(substitutions) {
|
|
|
12928
13744
|
function lockfilesFor(root) {
|
|
12929
13745
|
const top = gitTopLevel(root);
|
|
12930
13746
|
const lockfiles = [];
|
|
12931
|
-
for (let dir = realpathSync(root); ; dir =
|
|
12932
|
-
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(
|
|
12933
|
-
if (lockfiles.length || dir === top ||
|
|
13747
|
+
for (let dir = realpathSync(root); ; dir = path63.dirname(dir)) {
|
|
13748
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path63.join(dir, f))) lockfiles.push(path63.relative(realpathSync(root), path63.join(dir, f)));
|
|
13749
|
+
if (lockfiles.length || dir === top || path63.dirname(dir) === dir) break;
|
|
12934
13750
|
}
|
|
12935
13751
|
return lockfiles;
|
|
12936
13752
|
}
|
|
@@ -12961,13 +13777,13 @@ function openPullRequest(root, version, report, base) {
|
|
|
12961
13777
|
git4("switch", "-c", branch);
|
|
12962
13778
|
const lockfiles = lockfilesFor(root);
|
|
12963
13779
|
const ignoredLocks = gitIgnored(root, lockfiles);
|
|
12964
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
13780
|
+
const paths = [...report.files.filter((f) => existsSync(path63.join(root, f))), ...lockfiles.filter((f) => !ignoredLocks.includes(f))];
|
|
12965
13781
|
git4("add", "--", ...paths);
|
|
12966
13782
|
const overlayDirs = report.overlays.filter((o) => !o.skipped && !o.conflicts.length && (o.remove || [...o.writes.values()].includes(null))).map((o) => o.rel);
|
|
12967
13783
|
if (overlayDirs.length) git4("add", "-A", "--", ...overlayDirs);
|
|
12968
13784
|
git4("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
12969
13785
|
git4("push", "-u", "origin", branch);
|
|
12970
|
-
const body =
|
|
13786
|
+
const body = path63.join(mkdtempSync(path63.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
12971
13787
|
writeFileSync(body, `${report.summary}
|
|
12972
13788
|
|
|
12973
13789
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -13002,8 +13818,8 @@ var init_upgrade = __esm({
|
|
|
13002
13818
|
init_bun_lock();
|
|
13003
13819
|
EXACT_OR_TAG = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
|
|
13004
13820
|
inside2 = (dir, file) => {
|
|
13005
|
-
const rel =
|
|
13006
|
-
return rel === "" || rel.split(
|
|
13821
|
+
const rel = path63.relative(dir, file);
|
|
13822
|
+
return rel === "" || rel.split(path63.sep)[0] !== ".." && !path63.isAbsolute(rel);
|
|
13007
13823
|
};
|
|
13008
13824
|
NOT_MATURE = "ERR_PNPM_NO_MATURE_MATCHING_VERSION";
|
|
13009
13825
|
SUBSTITUTION_VALUE = /^[A-Za-z0-9][A-Za-z0-9 .+-]{0,59}$/;
|
|
@@ -13106,9 +13922,9 @@ async function runScaffold(opts, fs2) {
|
|
|
13106
13922
|
function joinPath(...parts) {
|
|
13107
13923
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
13108
13924
|
}
|
|
13109
|
-
function dirname(
|
|
13110
|
-
const idx =
|
|
13111
|
-
return idx === -1 ? "." :
|
|
13925
|
+
function dirname(path64) {
|
|
13926
|
+
const idx = path64.lastIndexOf("/");
|
|
13927
|
+
return idx === -1 ? "." : path64.slice(0, idx);
|
|
13112
13928
|
}
|
|
13113
13929
|
function brandPackageJson(consumer, genesisVersion) {
|
|
13114
13930
|
return JSON.stringify(
|
|
@@ -13347,7 +14163,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
13347
14163
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
13348
14164
|
const result2 = await runInitNative2({
|
|
13349
14165
|
name: consumer,
|
|
13350
|
-
target:
|
|
14166
|
+
target: path63.resolve(opts.target ?? consumer),
|
|
13351
14167
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
13352
14168
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
13353
14169
|
...opts.scheme ? { scheme: opts.scheme } : {},
|
|
@@ -13361,7 +14177,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
13361
14177
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
13362
14178
|
console.log("");
|
|
13363
14179
|
console.log("Next steps:");
|
|
13364
|
-
[`cd ${
|
|
14180
|
+
[`cd ${path63.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
13365
14181
|
return;
|
|
13366
14182
|
}
|
|
13367
14183
|
opts.target ??= process.cwd();
|
|
@@ -13446,7 +14262,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
13446
14262
|
});
|
|
13447
14263
|
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) => {
|
|
13448
14264
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
13449
|
-
const root =
|
|
14265
|
+
const root = path63.resolve(opts.dir);
|
|
13450
14266
|
try {
|
|
13451
14267
|
if (opts.printGenesis) {
|
|
13452
14268
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -13465,7 +14281,7 @@ program.command("doctor").description("Check this app against the installed Gene
|
|
|
13465
14281
|
});
|
|
13466
14282
|
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) => {
|
|
13467
14283
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
13468
|
-
const packages = doctor.discoverPackages(
|
|
14284
|
+
const packages = doctor.discoverPackages(path63.resolve(opts.dir));
|
|
13469
14285
|
const rows = doctor.primitivesCatalog(packages);
|
|
13470
14286
|
const broken = packages.filter((p) => p.error);
|
|
13471
14287
|
if (opts.json) {
|
|
@@ -13480,7 +14296,7 @@ program.command("catalog").description("Print the Genesis catalog: for each need
|
|
|
13480
14296
|
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) => {
|
|
13481
14297
|
console.error("! `genesis primitives` is now `genesis catalog`; the old name works until the next major.");
|
|
13482
14298
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
13483
|
-
const packages = doctor.discoverPackages(
|
|
14299
|
+
const packages = doctor.discoverPackages(path63.resolve(opts.dir));
|
|
13484
14300
|
const rows = doctor.primitivesCatalog(packages);
|
|
13485
14301
|
const broken = packages.filter((p) => p.error);
|
|
13486
14302
|
if (opts.json) {
|
|
@@ -13493,7 +14309,7 @@ program.command("primitives").description("Deprecated name of `genesis catalog`
|
|
|
13493
14309
|
if (broken.length) process.exitCode = 1;
|
|
13494
14310
|
});
|
|
13495
14311
|
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) => {
|
|
13496
|
-
const root =
|
|
14312
|
+
const root = path63.resolve(opts.dir);
|
|
13497
14313
|
if (opts.hook) {
|
|
13498
14314
|
try {
|
|
13499
14315
|
if (opts.hook === "subagent-start") {
|
|
@@ -13506,7 +14322,7 @@ program.command("agents").description(`Write the agent guide from the installed
|
|
|
13506
14322
|
}
|
|
13507
14323
|
if (opts.rules && opts.check) return program.error("--rules checks the repo, --check the agent guide: run them one at a time");
|
|
13508
14324
|
if (opts.rules) {
|
|
13509
|
-
if (!existsSync(
|
|
14325
|
+
if (!existsSync(path63.join(root, "packages")) && !existsSync(path63.join(root, ".github", "workflows"))) {
|
|
13510
14326
|
return program.error(`--rules checks a repository: ${root} has no packages/ or .github/workflows/. Run it from the repo root or pass --dir.`);
|
|
13511
14327
|
}
|
|
13512
14328
|
const { checkAgentRules: checkAgentRules2 } = await Promise.resolve().then(() => (init_agent_rules(), agent_rules_exports));
|
|
@@ -13591,7 +14407,7 @@ featureOptions(
|
|
|
13591
14407
|
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) => {
|
|
13592
14408
|
const figma = await Promise.resolve().then(() => (init_routes2(), routes_exports));
|
|
13593
14409
|
try {
|
|
13594
|
-
const report = await figma.checkFigmaRoutes({ root:
|
|
14410
|
+
const report = await figma.checkFigmaRoutes({ root: path63.resolve(opts.dir) });
|
|
13595
14411
|
console.log(opts.json ? JSON.stringify(report, null, 2) : figma.formatCoverage(report));
|
|
13596
14412
|
process.exitCode = opts.strict && report.summary.missing > 0 ? 1 : 0;
|
|
13597
14413
|
} catch (err) {
|
|
@@ -13603,7 +14419,7 @@ program.command("figma:routes").description("Report drift between this app's rou
|
|
|
13603
14419
|
var upstream = program.command("upstream").description("The app's register of what it needed from Genesis (docs/genesis-upstream.md)");
|
|
13604
14420
|
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) => {
|
|
13605
14421
|
const { checkUpstream: checkUpstream2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
13606
|
-
const result = checkUpstream2(
|
|
14422
|
+
const result = checkUpstream2(path63.resolve(opts.dir));
|
|
13607
14423
|
for (const w of result.warnings) console.warn(`! ${w}`);
|
|
13608
14424
|
for (const p of result.problems) console.error(`\u2717 ${p}`);
|
|
13609
14425
|
if (result.problems.length) process.exitCode = 1;
|
|
@@ -13611,7 +14427,7 @@ upstream.command("check").description("Check docs/genesis-upstream.md: kinds, st
|
|
|
13611
14427
|
});
|
|
13612
14428
|
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) => {
|
|
13613
14429
|
const { checkUpstream: checkUpstream2, exportIssueUrl: exportIssueUrl2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
13614
|
-
const register = checkUpstream2(
|
|
14430
|
+
const register = checkUpstream2(path63.resolve(opts.dir));
|
|
13615
14431
|
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).");
|
|
13616
14432
|
const entry = register.entries.find((e) => e.id === id);
|
|
13617
14433
|
if (!entry) return program.error(`No register entry "${id}" in ${register.file}.`);
|
|
@@ -13621,27 +14437,61 @@ ${own.map((p) => ` ${p}`).join("\n")}`);
|
|
|
13621
14437
|
console.log(`Open this to file it (check it names no app or customer; Genesis is public), then set its status to proposed:
|
|
13622
14438
|
${exportIssueUrl2(entry)}`);
|
|
13623
14439
|
});
|
|
14440
|
+
var client = program.command("client").description("The app's client layer: its own layer over Genesis (ADR 0020)");
|
|
14441
|
+
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) => {
|
|
14442
|
+
const { planClientInit: planClientInit2, clientConfigChange: clientConfigChange2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
14443
|
+
const { readGenesisConfig: readGenesisConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
14444
|
+
const root = path63.resolve(opts.dir);
|
|
14445
|
+
const configured = readGenesisConfig2(root);
|
|
14446
|
+
const folder = opts.folder ?? configured?.client?.dir;
|
|
14447
|
+
let plan;
|
|
14448
|
+
let change;
|
|
14449
|
+
try {
|
|
14450
|
+
plan = planClientInit2({ ...folder ? { dir: folder } : {}, ...opts.type ? { type: opts.type } : {} });
|
|
14451
|
+
change = clientConfigChange2(plan.dir, configured?.client?.dir, opts.force);
|
|
14452
|
+
} catch (err) {
|
|
14453
|
+
return program.error(err.message);
|
|
14454
|
+
}
|
|
14455
|
+
for (const file of plan.files) {
|
|
14456
|
+
const target = path63.join(root, file.path);
|
|
14457
|
+
if (existsSync(target) && !opts.force) {
|
|
14458
|
+
console.log(`\xB7 ${file.path} (kept)`);
|
|
14459
|
+
continue;
|
|
14460
|
+
}
|
|
14461
|
+
await fs.mkdir(path63.dirname(target), { recursive: true });
|
|
14462
|
+
await fs.writeFile(target, file.content);
|
|
14463
|
+
console.log(`\u2714 ${file.path}`);
|
|
14464
|
+
}
|
|
14465
|
+
if (change === "write") {
|
|
14466
|
+
const configPath = path63.join(root, "genesis.config.json");
|
|
14467
|
+
const raw = configured?.raw ?? {};
|
|
14468
|
+
await fs.writeFile(configPath, `${JSON.stringify({ ...raw, client: { dir: plan.dir } }, null, 2)}
|
|
14469
|
+
`);
|
|
14470
|
+
console.log("\u2714 genesis.config.json (client.dir)");
|
|
14471
|
+
}
|
|
14472
|
+
for (const step of plan.steps) console.log(`\u2192 ${step}`);
|
|
14473
|
+
});
|
|
13624
14474
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
13625
14475
|
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) => {
|
|
13626
|
-
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (
|
|
13627
|
-
const root =
|
|
13628
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
13629
|
-
const
|
|
14476
|
+
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init2(), init_exports2));
|
|
14477
|
+
const root = path63.resolve(opts.dir);
|
|
14478
|
+
const packageJson = JSON.parse(await fs.readFile(path63.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
14479
|
+
const existsSync47 = (await import('fs')).existsSync;
|
|
13630
14480
|
const readSync = (await import('fs')).readFileSync;
|
|
13631
|
-
const
|
|
14481
|
+
const readdirSync22 = (await import('fs')).readdirSync;
|
|
13632
14482
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
13633
14483
|
throw new Error("--host must be next, tanstack-start or supabase-function.");
|
|
13634
14484
|
}
|
|
13635
14485
|
const plan = planStudioInit2(
|
|
13636
14486
|
{
|
|
13637
14487
|
packageJson,
|
|
13638
|
-
exists: (p) =>
|
|
13639
|
-
read: (p) =>
|
|
14488
|
+
exists: (p) => existsSync47(path63.join(root, p)),
|
|
14489
|
+
read: (p) => existsSync47(path63.join(root, p)) ? readSync(path63.join(root, p), "utf-8") : null,
|
|
13640
14490
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
13641
14491
|
listDeep: (p) => {
|
|
13642
14492
|
const out = [];
|
|
13643
14493
|
const walk4 = (rel) => {
|
|
13644
|
-
for (const entry of
|
|
14494
|
+
for (const entry of readdirSync22(path63.join(root, rel), { withFileTypes: true })) {
|
|
13645
14495
|
const child = `${rel}/${entry.name}`;
|
|
13646
14496
|
if (entry.isDirectory()) walk4(child);
|
|
13647
14497
|
else out.push(child);
|
|
@@ -13655,7 +14505,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13655
14505
|
},
|
|
13656
14506
|
list: (p) => {
|
|
13657
14507
|
try {
|
|
13658
|
-
return
|
|
14508
|
+
return readdirSync22(path63.join(root, p));
|
|
13659
14509
|
} catch {
|
|
13660
14510
|
return [];
|
|
13661
14511
|
}
|
|
@@ -13664,8 +14514,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13664
14514
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
13665
14515
|
);
|
|
13666
14516
|
for (const file of plan.files) {
|
|
13667
|
-
const target =
|
|
13668
|
-
await fs.mkdir(
|
|
14517
|
+
const target = path63.join(root, file.path);
|
|
14518
|
+
await fs.mkdir(path63.dirname(target), { recursive: true });
|
|
13669
14519
|
if (file.edit) {
|
|
13670
14520
|
await fs.writeFile(target, file.content, "utf-8");
|
|
13671
14521
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -13676,14 +14526,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
13676
14526
|
console.log(`+ ${file.path} (appended)`);
|
|
13677
14527
|
continue;
|
|
13678
14528
|
}
|
|
13679
|
-
if (
|
|
14529
|
+
if (existsSync47(target) && !opts.force) {
|
|
13680
14530
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
13681
14531
|
continue;
|
|
13682
14532
|
}
|
|
13683
14533
|
await fs.writeFile(target, file.content, "utf-8");
|
|
13684
14534
|
console.log(`+ ${file.path}`);
|
|
13685
14535
|
}
|
|
13686
|
-
const pm =
|
|
14536
|
+
const pm = existsSync47(path63.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync47(path63.join(root, "yarn.lock")) ? "yarn add" : existsSync47(path63.join(root, "bun.lock")) || existsSync47(path63.join(root, "bun.lockb")) ? "bun add" : "npm install";
|
|
13687
14537
|
console.log("");
|
|
13688
14538
|
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:`);
|
|
13689
14539
|
console.log(` 1. ${pm} ${plan.install.map((p) => /[\s<>|]/.test(p) ? `"${p}"` : p).join(" ")}`);
|
|
@@ -13701,7 +14551,7 @@ async function confirm(question) {
|
|
|
13701
14551
|
}
|
|
13702
14552
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
13703
14553
|
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) => {
|
|
13704
|
-
const root =
|
|
14554
|
+
const root = path63.resolve(opts.dir);
|
|
13705
14555
|
if (opts.list || !block) {
|
|
13706
14556
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
13707
14557
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -13731,7 +14581,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
13731
14581
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
13732
14582
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
13733
14583
|
const report = await runMigrate2({
|
|
13734
|
-
root:
|
|
14584
|
+
root: path63.resolve(opts.dir),
|
|
13735
14585
|
...opts.block ? { blocks: opts.block } : {},
|
|
13736
14586
|
...opts.notifications ? { notifications: opts.notifications } : {},
|
|
13737
14587
|
dryRun: opts.dryRun,
|
|
@@ -13757,7 +14607,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
13757
14607
|
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) => {
|
|
13758
14608
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
13759
14609
|
const report = await runUpgrade2({
|
|
13760
|
-
root:
|
|
14610
|
+
root: path63.resolve(opts.dir),
|
|
13761
14611
|
version: opts.version,
|
|
13762
14612
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
13763
14613
|
dryRun: opts.dryRun,
|
|
@@ -13786,10 +14636,10 @@ program.command("codemod [id]").description("Run one of Genesis's codemods by ha
|
|
|
13786
14636
|
}
|
|
13787
14637
|
const mod = codemodById2(id);
|
|
13788
14638
|
if (!mod) throw new Error(`No codemod "${id}". Run genesis codemod to list them.`);
|
|
13789
|
-
const changed = await mod.run({ root:
|
|
14639
|
+
const changed = await mod.run({ root: path63.resolve(opts.dir), dryRun: opts.dryRun, log: (m) => console.log(m) });
|
|
13790
14640
|
console.log(changed.length ? `${opts.dryRun ? "Would change" : "\u2714 Changed"} ${changed.length} file${changed.length === 1 ? "" : "s"}:
|
|
13791
14641
|
${changed.map((f) => ` ${f}`).join("\n")}` : "Nothing to change.");
|
|
13792
|
-
const note = codemodInstallNote2(
|
|
14642
|
+
const note = codemodInstallNote2(path63.resolve(opts.dir), changed, opts.dryRun);
|
|
13793
14643
|
if (note) console.log(`! ${note}`);
|
|
13794
14644
|
});
|
|
13795
14645
|
program.parseAsync(process.argv).catch((err) => {
|
|
@@ -13839,7 +14689,7 @@ function redactUrl(location) {
|
|
|
13839
14689
|
const url = new URL(location);
|
|
13840
14690
|
return `${url.origin}${url.pathname}`;
|
|
13841
14691
|
} catch {
|
|
13842
|
-
return
|
|
14692
|
+
return path63.basename(location);
|
|
13843
14693
|
}
|
|
13844
14694
|
}
|
|
13845
14695
|
//# sourceMappingURL=cli.js.map
|