@marktiderman/genesis-cli 1.8.0 → 1.9.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 +26 -4
- package/dist/cli.js +933 -319
- package/dist/cli.js.map +1 -1
- package/dist/{config-CrZbM3jD.d.ts → config-QC_Ewwwp.d.ts} +27 -3
- package/dist/doctor.d.ts +68 -4
- package/dist/doctor.js +654 -87
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +14 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +666 -101
- package/dist/index.js.map +1 -1
- package/dist/starter/__tests__/check-in-photos.test.ts +1 -1
- package/dist/starter/__tests__/components/messages.test.tsx +33 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +4 -38
- package/dist/starter/src/app/(app)/messages/[id].tsx +14 -5
- package/dist/starter/src/app/(app)/messages/check-in.tsx +9 -0
- package/dist/starter/src/app/(app)/messages/search.tsx +13 -1
- package/dist/starter/src/copy.ts +2 -0
- package/dist/starter/src/lib/chat.tsx +31 -8
- package/dist/starter/src/lib/check-in-screen.tsx +43 -0
- package/dist/starter/supabase/migrations/20261025000060_genesis_chat_search_threads.sql +85 -0
- package/dist/starter/supabase/tests/database/genesis_chat_coaching.test.sql +7 -3
- package/dist/starter/supabase/tests/database/genesis_chat_search_threads.test.sql +50 -0
- package/dist/vite.js +651 -86
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync, existsSync, readdirSync, mkdirSync, writeFileSync, mkdtempSync, rmSync, realpathSync, statSync, lstatSync } from 'fs';
|
|
3
|
-
import * as
|
|
3
|
+
import * as path31 from 'path';
|
|
4
4
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
@@ -26,7 +26,7 @@ var __export = (target, all) => {
|
|
|
26
26
|
function buildCatalog(packagesDir) {
|
|
27
27
|
const packages = {};
|
|
28
28
|
for (const dir of readdirSync(packagesDir).sort()) {
|
|
29
|
-
const file =
|
|
29
|
+
const file = path31.join(packagesDir, dir, "package.json");
|
|
30
30
|
if (!existsSync(file)) continue;
|
|
31
31
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
32
32
|
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
@@ -64,11 +64,11 @@ function parseManifest(home, id, raw, version) {
|
|
|
64
64
|
if (!safe) problems.push(`${where}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
65
65
|
return safe ?? "";
|
|
66
66
|
};
|
|
67
|
-
const list = (
|
|
68
|
-
const v = raw[
|
|
67
|
+
const list = (key2) => {
|
|
68
|
+
const v = raw[key2];
|
|
69
69
|
if (v === void 0) return [];
|
|
70
70
|
if (!Array.isArray(v)) {
|
|
71
|
-
problems.push(`${at}.${
|
|
71
|
+
problems.push(`${at}.${key2}: must be a list`);
|
|
72
72
|
return [];
|
|
73
73
|
}
|
|
74
74
|
return v;
|
|
@@ -234,30 +234,30 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
function inside(parent, child) {
|
|
237
|
-
const rel =
|
|
238
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
237
|
+
const rel = path31.relative(parent, child);
|
|
238
|
+
return rel === "" || !rel.startsWith("..") && !path31.isAbsolute(rel);
|
|
239
239
|
}
|
|
240
240
|
function readPackageFile(packageDir2, rel) {
|
|
241
241
|
const safe = safeRelative(rel);
|
|
242
242
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
243
243
|
const root = realpathSync(packageDir2);
|
|
244
|
-
const file =
|
|
244
|
+
const file = path31.join(root, ...safe.split("/"));
|
|
245
245
|
if (!existsSync(file)) return null;
|
|
246
|
-
const
|
|
247
|
-
if (!inside(root,
|
|
248
|
-
if (!statSync(
|
|
249
|
-
return readFileSync(
|
|
246
|
+
const real2 = realpathSync(file);
|
|
247
|
+
if (!inside(root, real2)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
|
|
248
|
+
if (!statSync(real2).isFile()) return null;
|
|
249
|
+
return readFileSync(real2, "utf8");
|
|
250
250
|
}
|
|
251
251
|
function readPackageDir(packageDir2, rel, skipped = []) {
|
|
252
252
|
const safe = safeRelative(rel);
|
|
253
253
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
254
254
|
const root = realpathSync(packageDir2);
|
|
255
|
-
const dir =
|
|
255
|
+
const dir = path31.join(root, ...safe.split("/"));
|
|
256
256
|
if (!existsSync(dir)) return null;
|
|
257
|
-
const
|
|
258
|
-
if (!inside(root,
|
|
257
|
+
const real2 = realpathSync(dir);
|
|
258
|
+
if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
|
|
259
259
|
const out = [];
|
|
260
|
-
for (const entry of readdirSync(
|
|
260
|
+
for (const entry of readdirSync(real2, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261
261
|
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(entry.name) || entry.isDirectory()) {
|
|
262
262
|
skipped.push(`${safe}/${entry.name}`);
|
|
263
263
|
continue;
|
|
@@ -272,7 +272,7 @@ function appPath(root, rel) {
|
|
|
272
272
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
273
273
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
274
274
|
const realRoot = realpathSync(root);
|
|
275
|
-
const target =
|
|
275
|
+
const target = path31.join(realRoot, ...safe.split("/"));
|
|
276
276
|
const there = (p) => {
|
|
277
277
|
try {
|
|
278
278
|
lstatSync(p);
|
|
@@ -281,15 +281,15 @@ function appPath(root, rel) {
|
|
|
281
281
|
return false;
|
|
282
282
|
}
|
|
283
283
|
};
|
|
284
|
-
let probe =
|
|
285
|
-
while (!there(probe)) probe =
|
|
286
|
-
let
|
|
284
|
+
let probe = path31.dirname(target);
|
|
285
|
+
while (!there(probe)) probe = path31.dirname(probe);
|
|
286
|
+
let real2;
|
|
287
287
|
try {
|
|
288
|
-
|
|
288
|
+
real2 = realpathSync(probe);
|
|
289
289
|
} catch {
|
|
290
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
290
|
+
throw new Error(`${rel} goes through a broken symlink (${path31.relative(realRoot, probe)}); refused`);
|
|
291
291
|
}
|
|
292
|
-
if (!inside(realRoot,
|
|
292
|
+
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
293
293
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
294
294
|
return target;
|
|
295
295
|
}
|
|
@@ -299,20 +299,20 @@ function readApp(root, rel) {
|
|
|
299
299
|
}
|
|
300
300
|
function createApp(root, rel, content) {
|
|
301
301
|
const file = appPath(root, rel);
|
|
302
|
-
mkdirSync(
|
|
302
|
+
mkdirSync(path31.dirname(file), { recursive: true });
|
|
303
303
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
304
304
|
}
|
|
305
305
|
function replaceApp(root, rel, content) {
|
|
306
306
|
const file = appPath(root, rel);
|
|
307
|
-
mkdirSync(
|
|
307
|
+
mkdirSync(path31.dirname(file), { recursive: true });
|
|
308
308
|
writeFileSync(file, content, "utf8");
|
|
309
309
|
}
|
|
310
310
|
function listApp(root, rel, options = {}) {
|
|
311
|
-
const dir =
|
|
311
|
+
const dir = path31.join(root, rel);
|
|
312
312
|
if (!existsSync(dir)) return [];
|
|
313
313
|
const out = [];
|
|
314
314
|
const walk2 = (r) => {
|
|
315
|
-
for (const entry of readdirSync(
|
|
315
|
+
for (const entry of readdirSync(path31.join(root, r), { withFileTypes: true })) {
|
|
316
316
|
const child = `${r}/${entry.name}`;
|
|
317
317
|
if (entry.isDirectory()) walk2(child);
|
|
318
318
|
else if (entry.isFile() || options.symlinks && entry.isSymbolicLink()) out.push(child);
|
|
@@ -345,41 +345,41 @@ __export(discover_exports, {
|
|
|
345
345
|
workspacePackagesDir: () => workspacePackagesDir
|
|
346
346
|
});
|
|
347
347
|
function cliPackageDir() {
|
|
348
|
-
let dir =
|
|
348
|
+
let dir = path31.dirname(fileURLToPath(import.meta.url));
|
|
349
349
|
for (; ; ) {
|
|
350
|
-
const file =
|
|
350
|
+
const file = path31.join(dir, "package.json");
|
|
351
351
|
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
352
|
-
const parent =
|
|
352
|
+
const parent = path31.dirname(dir);
|
|
353
353
|
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
354
354
|
dir = parent;
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
function workspacePackagesDir() {
|
|
358
|
-
const dir =
|
|
359
|
-
return existsSync(
|
|
358
|
+
const dir = path31.resolve(cliPackageDir(), "..");
|
|
359
|
+
return existsSync(path31.join(dir, "features", "package.json")) && existsSync(path31.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
360
360
|
}
|
|
361
361
|
function readCatalog() {
|
|
362
362
|
if (catalogCache) return catalogCache;
|
|
363
363
|
const workspace = workspacePackagesDir();
|
|
364
364
|
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
365
|
-
const file =
|
|
365
|
+
const file = path31.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
366
366
|
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
367
367
|
return catalogCache;
|
|
368
368
|
}
|
|
369
369
|
function installedGenesis(root) {
|
|
370
370
|
const found = /* @__PURE__ */ new Map();
|
|
371
|
-
let dir =
|
|
371
|
+
let dir = path31.resolve(root);
|
|
372
372
|
for (; ; ) {
|
|
373
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
374
|
-
const scope =
|
|
373
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path31.join(dir, m)));
|
|
374
|
+
const scope = path31.join(dir, "node_modules", "@marktiderman");
|
|
375
375
|
if (existsSync(scope)) {
|
|
376
376
|
for (const entry of readdirSync(scope)) {
|
|
377
377
|
const name = `@marktiderman/${entry}`;
|
|
378
378
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
379
|
-
if (existsSync(
|
|
379
|
+
if (existsSync(path31.join(scope, entry, "package.json"))) found.set(name, path31.join(scope, entry));
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
const parent =
|
|
382
|
+
const parent = path31.dirname(dir);
|
|
383
383
|
if (atInstallRoot || parent === dir) return found;
|
|
384
384
|
dir = parent;
|
|
385
385
|
}
|
|
@@ -391,28 +391,28 @@ function packageDir(root, name) {
|
|
|
391
391
|
return null;
|
|
392
392
|
}
|
|
393
393
|
function packageVersion(dir) {
|
|
394
|
-
return JSON.parse(readFileSync(
|
|
394
|
+
return JSON.parse(readFileSync(path31.join(dir, "package.json"), "utf8")).version;
|
|
395
395
|
}
|
|
396
396
|
function declarationsOf(dir, warnings) {
|
|
397
|
-
const pkg = JSON.parse(readFileSync(
|
|
398
|
-
const
|
|
399
|
-
let cached = declarationCache.get(
|
|
397
|
+
const pkg = JSON.parse(readFileSync(path31.join(dir, "package.json"), "utf8"));
|
|
398
|
+
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
399
|
+
let cached = declarationCache.get(key2);
|
|
400
400
|
if (!cached) {
|
|
401
401
|
cached = loadDeclarations(dir, warnings);
|
|
402
|
-
declarationCache.set(
|
|
402
|
+
declarationCache.set(key2, cached);
|
|
403
403
|
}
|
|
404
404
|
return cached;
|
|
405
405
|
}
|
|
406
406
|
async function loadDeclarations(dir, warnings) {
|
|
407
|
-
const pkg = JSON.parse(readFileSync(
|
|
407
|
+
const pkg = JSON.parse(readFileSync(path31.join(dir, "package.json"), "utf8"));
|
|
408
408
|
const entry = pkg.exports?.["./blocks"];
|
|
409
409
|
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
410
410
|
if (typeof target !== "string") return {};
|
|
411
411
|
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
412
|
-
const file = rel &&
|
|
412
|
+
const file = rel && path31.join(dir, ...rel.split("/"));
|
|
413
413
|
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
414
414
|
try {
|
|
415
|
-
const jiti = createJiti(
|
|
415
|
+
const jiti = createJiti(path31.join(dir, "package.json"), { moduleCache: false });
|
|
416
416
|
const mod = await jiti.import(file);
|
|
417
417
|
const out = {};
|
|
418
418
|
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
@@ -423,7 +423,7 @@ async function loadDeclarations(dir, warnings) {
|
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
async function blocksOfInstalled(dir, warnings = []) {
|
|
426
|
-
const pkg = JSON.parse(readFileSync(
|
|
426
|
+
const pkg = JSON.parse(readFileSync(path31.join(dir, "package.json"), "utf8"));
|
|
427
427
|
const raw = rawBlocksOf(pkg);
|
|
428
428
|
const declared = await declarationsOf(dir, warnings);
|
|
429
429
|
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
@@ -502,7 +502,7 @@ function emptyLock() {
|
|
|
502
502
|
return { version: 1, blocks: {}, files: {} };
|
|
503
503
|
}
|
|
504
504
|
function readLock(root) {
|
|
505
|
-
const file =
|
|
505
|
+
const file = path31.join(root, LOCK_FILE);
|
|
506
506
|
if (!existsSync(file)) return emptyLock();
|
|
507
507
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
508
508
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -557,7 +557,7 @@ function migrationHeader(pkg, file, source) {
|
|
|
557
557
|
`;
|
|
558
558
|
}
|
|
559
559
|
function stemOrNull(file) {
|
|
560
|
-
return MIGRATION_FILE.exec(
|
|
560
|
+
return MIGRATION_FILE.exec(path31.posix.basename(file))?.[2] ?? null;
|
|
561
561
|
}
|
|
562
562
|
function stemOf(file) {
|
|
563
563
|
const stem = stemOrNull(file);
|
|
@@ -567,7 +567,7 @@ function stemOf(file) {
|
|
|
567
567
|
function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
568
568
|
return listApp(root, dir, { symlinks: true }).filter((p) => p.endsWith(".sql")).map((p) => {
|
|
569
569
|
const content = readApp(root, p) ?? "";
|
|
570
|
-
const name =
|
|
570
|
+
const name = path31.posix.basename(p);
|
|
571
571
|
const m = HEADER.exec(content);
|
|
572
572
|
if (m) return { path: p, name, content, tracked: { package: m[1], file: m[2], sha256: m[3], body: content.slice(m[0].length) } };
|
|
573
573
|
const f = FORWARD.exec(content);
|
|
@@ -583,8 +583,8 @@ function timestampOf(date) {
|
|
|
583
583
|
}
|
|
584
584
|
function nextStamp(ts) {
|
|
585
585
|
const d = new Date(Date.UTC(+ts.slice(0, 4), +ts.slice(4, 6) - 1, +ts.slice(6, 8), +ts.slice(8, 10), +ts.slice(10, 12), +ts.slice(12, 14)));
|
|
586
|
-
const
|
|
587
|
-
const next =
|
|
586
|
+
const real2 = !Number.isNaN(d.getTime()) && d.getUTCFullYear() >= 1e3 && timestampOf(d) === ts;
|
|
587
|
+
const next = real2 ? timestampOf(new Date(d.getTime() + 1e3)) : (BigInt(ts) + 1n).toString().padStart(14, "0");
|
|
588
588
|
if (next.length !== 14 || next <= ts) throw new Error(`No 14-digit timestamp follows ${ts}.`);
|
|
589
589
|
return next;
|
|
590
590
|
}
|
|
@@ -612,9 +612,9 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
612
612
|
const pending = [];
|
|
613
613
|
const seen = /* @__PURE__ */ new Set();
|
|
614
614
|
for (const src of sources) {
|
|
615
|
-
const
|
|
616
|
-
if (seen.has(
|
|
617
|
-
seen.add(
|
|
615
|
+
const key2 = `${src.package} ${src.file}`;
|
|
616
|
+
if (seen.has(key2)) continue;
|
|
617
|
+
seen.add(key2);
|
|
618
618
|
const stem = stemOf(src.file);
|
|
619
619
|
const base = { ...src.block ? { block: src.block } : {}, package: src.package, file: src.file, state: "current" };
|
|
620
620
|
const sourceSha = src.source === null ? null : textSha(src.source);
|
|
@@ -649,7 +649,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
649
649
|
detail = copy.tracked ? renamed.trim() : "copied before headers; matches the package";
|
|
650
650
|
} else if (copy.tracked) {
|
|
651
651
|
state = "changed-upstream";
|
|
652
|
-
detail = `${src.package} now ships a different ${
|
|
652
|
+
detail = `${src.package} now ships a different ${path31.posix.basename(src.file)}; the applied copy is never rewritten`;
|
|
653
653
|
} else {
|
|
654
654
|
state = "differs";
|
|
655
655
|
detail = "has the package migration's name but other text and no header; treated as the app's own";
|
|
@@ -671,8 +671,8 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
671
671
|
row.target = target2;
|
|
672
672
|
creates.push({ path: target2, content: migrationHeader(src.package, src.file, src.source) + src.source, kind, source: { package: src.package, file: src.file } });
|
|
673
673
|
if (options.tests !== false && src.test && src.testSource != null) {
|
|
674
|
-
const
|
|
675
|
-
if (readApp(root,
|
|
674
|
+
const test2 = `${TESTS_DIR}/${path31.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
|
|
675
|
+
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 } });
|
|
676
676
|
}
|
|
677
677
|
return;
|
|
678
678
|
}
|
|
@@ -731,25 +731,25 @@ function privacyDataType(type) {
|
|
|
731
731
|
}
|
|
732
732
|
function appPath2(v, where, fail) {
|
|
733
733
|
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
734
|
-
if (
|
|
735
|
-
const norm =
|
|
734
|
+
if (path31.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
735
|
+
const norm = path31.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
736
736
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
737
737
|
return norm;
|
|
738
738
|
}
|
|
739
739
|
function loadConfig(root, configPath) {
|
|
740
740
|
if (configPath) {
|
|
741
|
-
const file =
|
|
741
|
+
const file = path31.resolve(root, configPath);
|
|
742
742
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
743
743
|
const json = readJson(file);
|
|
744
|
-
const block =
|
|
745
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
744
|
+
const block = path31.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
745
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path31.dirname(file) };
|
|
746
746
|
}
|
|
747
|
-
const own =
|
|
747
|
+
const own = path31.join(root, "genesis.config.json");
|
|
748
748
|
if (existsSync(own)) {
|
|
749
749
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
750
750
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
751
751
|
}
|
|
752
|
-
const pkg =
|
|
752
|
+
const pkg = path31.join(root, "package.json");
|
|
753
753
|
if (existsSync(pkg)) {
|
|
754
754
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
755
755
|
if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -764,7 +764,7 @@ function readJson(file) {
|
|
|
764
764
|
}
|
|
765
765
|
}
|
|
766
766
|
function readGenesisConfig(root) {
|
|
767
|
-
const file =
|
|
767
|
+
const file = path31.join(root, "genesis.config.json");
|
|
768
768
|
if (!existsSync(file)) return null;
|
|
769
769
|
const raw = readJson(file);
|
|
770
770
|
if (!isObject2(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -779,7 +779,7 @@ function validatePrivacy(raw, source = "config") {
|
|
|
779
779
|
};
|
|
780
780
|
if (!isObject2(raw)) fail(`"privacy" must be an object`);
|
|
781
781
|
const c = raw;
|
|
782
|
-
for (const
|
|
782
|
+
for (const key2 of Object.keys(c)) if (!PRIVACY_KEYS.has(key2)) fail(`privacy: unknown setting "${key2}"`);
|
|
783
783
|
const out = {};
|
|
784
784
|
if (c.blocks !== void 0) {
|
|
785
785
|
if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
|
|
@@ -794,7 +794,7 @@ function validatePrivacy(raw, source = "config") {
|
|
|
794
794
|
out.collects = c.collects.map((entry, i) => {
|
|
795
795
|
const where = `privacy.collects[${i}]`;
|
|
796
796
|
if (!isObject2(entry)) return fail(`${where} must be an object`);
|
|
797
|
-
for (const
|
|
797
|
+
for (const key2 of Object.keys(entry)) if (!DATA_USE_KEYS.has(key2)) fail(`${where}: unknown setting "${key2}"`);
|
|
798
798
|
if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
|
|
799
799
|
fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
|
|
800
800
|
}
|
|
@@ -815,7 +815,7 @@ function validateLinks(raw, source = "config") {
|
|
|
815
815
|
};
|
|
816
816
|
if (!isObject2(raw)) fail(`"links" must be an object`);
|
|
817
817
|
const c = raw;
|
|
818
|
-
for (const
|
|
818
|
+
for (const key2 of Object.keys(c)) if (!LINK_KEYS.has(key2)) fail(`links: unknown setting "${key2}"`);
|
|
819
819
|
if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
|
|
820
820
|
for (const host of c.hosts) {
|
|
821
821
|
if (!HOST.test(host)) {
|
|
@@ -842,15 +842,16 @@ function validateConfig(raw, source = "config") {
|
|
|
842
842
|
};
|
|
843
843
|
if (!isObject2(raw)) fail("the doctor settings must be an object");
|
|
844
844
|
const c = raw;
|
|
845
|
-
for (const
|
|
845
|
+
for (const key2 of Object.keys(c)) if (!KNOWN.has(key2)) fail(`unknown setting "${key2}"`);
|
|
846
846
|
if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
|
|
847
847
|
if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
|
|
848
|
-
for (const
|
|
849
|
-
if (c[
|
|
848
|
+
for (const key2 of STRING_LISTS) {
|
|
849
|
+
if (c[key2] !== void 0 && !isStringList(c[key2])) fail(`"${key2}" must be a list of strings`);
|
|
850
850
|
}
|
|
851
|
-
for (const
|
|
852
|
-
if (c[
|
|
851
|
+
for (const key2 of STRINGS) {
|
|
852
|
+
if (c[key2] !== void 0 && typeof c[key2] !== "string") fail(`"${key2}" must be a string`);
|
|
853
853
|
}
|
|
854
|
+
if (c.routesDir !== void 0) c.routesDir = appPath2(c.routesDir, `"routesDir"`, fail);
|
|
854
855
|
if (c.rawTags !== void 0) {
|
|
855
856
|
if (!isObject2(c.rawTags)) fail(`"rawTags" must be an object`);
|
|
856
857
|
for (const [tag, v] of Object.entries(c.rawTags)) {
|
|
@@ -868,7 +869,7 @@ function validateConfig(raw, source = "config") {
|
|
|
868
869
|
if (c.rules !== void 0) {
|
|
869
870
|
if (!isObject2(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
|
|
870
871
|
for (const [rule, level] of Object.entries(c.rules)) {
|
|
871
|
-
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
|
|
872
|
+
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn", "info" or "off"`);
|
|
872
873
|
}
|
|
873
874
|
}
|
|
874
875
|
if (c.allow !== void 0) {
|
|
@@ -989,7 +990,7 @@ var init_config = __esm({
|
|
|
989
990
|
"third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
|
|
990
991
|
other: "NSPrivacyCollectedDataTypePurposeOther"
|
|
991
992
|
};
|
|
992
|
-
STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
993
|
+
STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
|
|
993
994
|
STRINGS = ["uiPackage", "rulesDoc"];
|
|
994
995
|
KNOWN = /* @__PURE__ */ new Set([
|
|
995
996
|
...STRING_LISTS,
|
|
@@ -1004,10 +1005,11 @@ var init_config = __esm({
|
|
|
1004
1005
|
"packs",
|
|
1005
1006
|
"native",
|
|
1006
1007
|
"supabase",
|
|
1008
|
+
"routesDir",
|
|
1007
1009
|
"$schema",
|
|
1008
1010
|
"$comment"
|
|
1009
1011
|
]);
|
|
1010
|
-
LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
1012
|
+
LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
|
|
1011
1013
|
PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
1012
1014
|
PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
1013
1015
|
PACK_KEYS = {
|
|
@@ -1021,11 +1023,11 @@ var init_config = __esm({
|
|
|
1021
1023
|
}
|
|
1022
1024
|
});
|
|
1023
1025
|
function findPackageDir(from, name) {
|
|
1024
|
-
let dir =
|
|
1026
|
+
let dir = path31.resolve(from);
|
|
1025
1027
|
for (; ; ) {
|
|
1026
|
-
const candidate =
|
|
1027
|
-
if (existsSync(
|
|
1028
|
-
const parent =
|
|
1028
|
+
const candidate = path31.join(dir, "node_modules", name);
|
|
1029
|
+
if (existsSync(path31.join(candidate, "package.json"))) return candidate;
|
|
1030
|
+
const parent = path31.dirname(dir);
|
|
1029
1031
|
if (parent === dir) return null;
|
|
1030
1032
|
dir = parent;
|
|
1031
1033
|
}
|
|
@@ -1057,13 +1059,27 @@ function loadGenesis(root, config) {
|
|
|
1057
1059
|
components,
|
|
1058
1060
|
tokens,
|
|
1059
1061
|
rawTags,
|
|
1060
|
-
palette: loadPalette(root)
|
|
1062
|
+
palette: loadPalette(root),
|
|
1063
|
+
companions: loadCompanions(root, config, uiPackage)
|
|
1061
1064
|
};
|
|
1062
1065
|
}
|
|
1066
|
+
function loadCompanions(root, config, uiPackage) {
|
|
1067
|
+
const out = [];
|
|
1068
|
+
for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
|
|
1069
|
+
if (name === uiPackage) continue;
|
|
1070
|
+
try {
|
|
1071
|
+
const pkg = readPackageExports(root, name);
|
|
1072
|
+
if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
|
|
1073
|
+
} catch (err) {
|
|
1074
|
+
if (!(err instanceof DoctorConfigError)) throw err;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
return out;
|
|
1078
|
+
}
|
|
1063
1079
|
function readPackageExports(root, uiPackage) {
|
|
1064
1080
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1065
1081
|
if (!uiDir) return null;
|
|
1066
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1082
|
+
const uiPkg = JSON.parse(readFileSync(path31.join(uiDir, "package.json"), "utf8"));
|
|
1067
1083
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
1068
1084
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1069
1085
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
@@ -1075,7 +1091,7 @@ function readPackageExports(root, uiPackage) {
|
|
|
1075
1091
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1076
1092
|
let readAny = false;
|
|
1077
1093
|
for (const entry of typeEntries) {
|
|
1078
|
-
const file =
|
|
1094
|
+
const file = path31.join(uiDir, entry);
|
|
1079
1095
|
if (!existsSync(file)) continue;
|
|
1080
1096
|
readAny = true;
|
|
1081
1097
|
const dts = readFileSync(file, "utf8");
|
|
@@ -1089,11 +1105,11 @@ function readPackageExports(root, uiPackage) {
|
|
|
1089
1105
|
}
|
|
1090
1106
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1091
1107
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1092
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1108
|
+
const declRoot = typeof mainTypes === "string" ? path31.dirname(path31.join(uiDir, mainTypes)) : uiDir;
|
|
1093
1109
|
const declFiles = walkDts(declRoot);
|
|
1094
1110
|
for (const pkg of reexportedPackages) {
|
|
1095
1111
|
const dir = findPackageDir(uiDir, pkg);
|
|
1096
|
-
if (dir) walkDts(
|
|
1112
|
+
if (dir) walkDts(path31.join(dir, "dist"), declFiles);
|
|
1097
1113
|
}
|
|
1098
1114
|
for (const file of declFiles) {
|
|
1099
1115
|
const text = readFileSync(file, "utf8");
|
|
@@ -1129,8 +1145,8 @@ function exportTypes(target) {
|
|
|
1129
1145
|
if (!target || typeof target !== "object") return void 0;
|
|
1130
1146
|
const t = target;
|
|
1131
1147
|
if (typeof t.types === "string") return t.types;
|
|
1132
|
-
for (const
|
|
1133
|
-
const nested = exportTypes(t[
|
|
1148
|
+
for (const key2 of ["import", "default", "require"]) {
|
|
1149
|
+
const nested = exportTypes(t[key2]);
|
|
1134
1150
|
if (nested) return nested;
|
|
1135
1151
|
}
|
|
1136
1152
|
return void 0;
|
|
@@ -1139,7 +1155,7 @@ function walkDts(dir, out = []) {
|
|
|
1139
1155
|
if (!existsSync(dir)) return out;
|
|
1140
1156
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1141
1157
|
if (entry.name === "node_modules") continue;
|
|
1142
|
-
const p =
|
|
1158
|
+
const p = path31.join(dir, entry.name);
|
|
1143
1159
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1144
1160
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1145
1161
|
}
|
|
@@ -1156,27 +1172,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1156
1172
|
}
|
|
1157
1173
|
const files = [];
|
|
1158
1174
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1159
|
-
const themes = ds &&
|
|
1175
|
+
const themes = ds && path31.join(ds, "dist", "themes");
|
|
1160
1176
|
if (themes && existsSync(themes)) {
|
|
1161
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1177
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path31.join(themes, name));
|
|
1162
1178
|
}
|
|
1163
1179
|
if (files.length === 0) {
|
|
1164
1180
|
throw new DoctorConfigError(
|
|
1165
1181
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1166
1182
|
);
|
|
1167
1183
|
}
|
|
1168
|
-
const uiStyles =
|
|
1184
|
+
const uiStyles = path31.join(uiDir, "dist", "styles.css");
|
|
1169
1185
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1170
1186
|
return files;
|
|
1171
1187
|
}
|
|
1172
1188
|
function resolveSpec(root, spec) {
|
|
1173
|
-
const local =
|
|
1174
|
-
if (spec.startsWith(".") ||
|
|
1189
|
+
const local = path31.resolve(root, spec);
|
|
1190
|
+
if (spec.startsWith(".") || path31.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1175
1191
|
const parts = spec.split("/");
|
|
1176
1192
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1177
1193
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1178
1194
|
if (dir) {
|
|
1179
|
-
const file =
|
|
1195
|
+
const file = path31.join(dir, ...parts.slice(nameLength));
|
|
1180
1196
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1181
1197
|
}
|
|
1182
1198
|
return existsSync(local) ? local : null;
|
|
@@ -1184,22 +1200,23 @@ function resolveSpec(root, spec) {
|
|
|
1184
1200
|
function loadPalette(root) {
|
|
1185
1201
|
const names = new Set(TAILWIND_PALETTE);
|
|
1186
1202
|
try {
|
|
1187
|
-
const req = createRequire(
|
|
1203
|
+
const req = createRequire(path31.join(root, "package.json"));
|
|
1188
1204
|
const colors = req("tailwindcss/colors");
|
|
1189
|
-
for (const
|
|
1190
|
-
if (/^[a-z]+$/.test(
|
|
1205
|
+
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1206
|
+
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
1191
1207
|
}
|
|
1192
1208
|
} catch {
|
|
1193
1209
|
}
|
|
1194
1210
|
return [...names].sort();
|
|
1195
1211
|
}
|
|
1196
|
-
var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
|
|
1212
|
+
var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, DEFAULT_COMPONENT_PACKAGES, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
|
|
1197
1213
|
var init_genesis = __esm({
|
|
1198
1214
|
"src/doctor/genesis.ts"() {
|
|
1199
1215
|
init_config();
|
|
1200
1216
|
DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1201
1217
|
NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
1202
1218
|
DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
1219
|
+
DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
|
|
1203
1220
|
TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
1204
1221
|
TAG_ALIASES = { hr: "Separator" };
|
|
1205
1222
|
NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
@@ -1237,7 +1254,7 @@ var init_genesis = __esm({
|
|
|
1237
1254
|
});
|
|
1238
1255
|
function readReleaseManifest(root) {
|
|
1239
1256
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
1240
|
-
const file = dir &&
|
|
1257
|
+
const file = dir && path31.join(dir, "dist", "versions.json");
|
|
1241
1258
|
if (!file || !existsSync(file)) return null;
|
|
1242
1259
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
1243
1260
|
}
|
|
@@ -1247,7 +1264,7 @@ function checkVersionSkew(ctx) {
|
|
|
1247
1264
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
1248
1265
|
const dir = findPackageDir(ctx.root, name);
|
|
1249
1266
|
if (!dir) continue;
|
|
1250
|
-
const have = JSON.parse(readFileSync(
|
|
1267
|
+
const have = JSON.parse(readFileSync(path31.join(dir, "package.json"), "utf8")).version;
|
|
1251
1268
|
if (have === want) continue;
|
|
1252
1269
|
ctx.report({
|
|
1253
1270
|
rule: "version-skew",
|
|
@@ -1266,13 +1283,13 @@ var init_versions = __esm({
|
|
|
1266
1283
|
}
|
|
1267
1284
|
});
|
|
1268
1285
|
function detectPackageManager(root) {
|
|
1269
|
-
let dir =
|
|
1286
|
+
let dir = path31.resolve(root);
|
|
1270
1287
|
for (; ; ) {
|
|
1271
|
-
if (existsSync(
|
|
1272
|
-
if (existsSync(
|
|
1273
|
-
if (existsSync(
|
|
1274
|
-
if (existsSync(
|
|
1275
|
-
const parent =
|
|
1288
|
+
if (existsSync(path31.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1289
|
+
if (existsSync(path31.join(dir, "bun.lock")) || existsSync(path31.join(dir, "bun.lockb"))) return "bun";
|
|
1290
|
+
if (existsSync(path31.join(dir, "yarn.lock"))) return "yarn";
|
|
1291
|
+
if (existsSync(path31.join(dir, "package-lock.json"))) return "npm";
|
|
1292
|
+
const parent = path31.dirname(dir);
|
|
1276
1293
|
if (parent === dir) return "npm";
|
|
1277
1294
|
dir = parent;
|
|
1278
1295
|
}
|
|
@@ -1308,10 +1325,10 @@ var init_pm = __esm({
|
|
|
1308
1325
|
function walk(dir, exclude = []) {
|
|
1309
1326
|
const out = [];
|
|
1310
1327
|
const visit = (rel) => {
|
|
1311
|
-
for (const name of readdirSync(
|
|
1328
|
+
for (const name of readdirSync(path31.join(dir, rel)).sort()) {
|
|
1312
1329
|
const child = rel ? `${rel}/${name}` : name;
|
|
1313
1330
|
if (exclude.some((r) => r.test(child))) continue;
|
|
1314
|
-
const stat = statSync(
|
|
1331
|
+
const stat = statSync(path31.join(dir, child));
|
|
1315
1332
|
if (stat.isDirectory()) visit(child);
|
|
1316
1333
|
else if (stat.isFile()) out.push(child);
|
|
1317
1334
|
}
|
|
@@ -1340,17 +1357,17 @@ var init_walk = __esm({
|
|
|
1340
1357
|
});
|
|
1341
1358
|
function starterDir() {
|
|
1342
1359
|
const workspace = workspacePackagesDir();
|
|
1343
|
-
const live = workspace &&
|
|
1344
|
-
if (live && existsSync(
|
|
1345
|
-
const packaged =
|
|
1346
|
-
if (existsSync(
|
|
1360
|
+
const live = workspace && path31.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
1361
|
+
if (live && existsSync(path31.join(live, "package.json"))) return live;
|
|
1362
|
+
const packaged = path31.join(cliPackageDir(), "dist", "starter");
|
|
1363
|
+
if (existsSync(path31.join(packaged, "package.json"))) return packaged;
|
|
1347
1364
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
1348
1365
|
}
|
|
1349
1366
|
function templatesDir(cliDir = cliPackageDir()) {
|
|
1350
1367
|
const workspace = workspacePackagesDir();
|
|
1351
|
-
const live = workspace && cliDir === cliPackageDir() ?
|
|
1352
|
-
if (live && existsSync(
|
|
1353
|
-
const packaged =
|
|
1368
|
+
const live = workspace && cliDir === cliPackageDir() ? path31.join(workspace, "..", "templates") : null;
|
|
1369
|
+
if (live && existsSync(path31.join(live, "eas"))) return live;
|
|
1370
|
+
const packaged = path31.join(cliDir, "dist", "templates");
|
|
1354
1371
|
if (existsSync(packaged)) return packaged;
|
|
1355
1372
|
throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
|
|
1356
1373
|
}
|
|
@@ -1381,9 +1398,9 @@ __export(init_native_exports, {
|
|
|
1381
1398
|
starterIdentity: () => starterIdentity
|
|
1382
1399
|
});
|
|
1383
1400
|
function starterIdentity(config) {
|
|
1384
|
-
const field2 = (
|
|
1385
|
-
const m = new RegExp(`\\b${
|
|
1386
|
-
if (!m) throw new Error(`starter.config.ts has no app.${
|
|
1401
|
+
const field2 = (key2) => {
|
|
1402
|
+
const m = new RegExp(`\\b${key2}:\\s*"([^"]+)"`).exec(config);
|
|
1403
|
+
if (!m) throw new Error(`starter.config.ts has no app.${key2}`);
|
|
1387
1404
|
return m[1];
|
|
1388
1405
|
};
|
|
1389
1406
|
return { name: field2("name"), slug: field2("slug"), scheme: field2("scheme"), bundleId: field2("bundleId") };
|
|
@@ -1431,10 +1448,10 @@ function initNative(options) {
|
|
|
1431
1448
|
if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
|
|
1432
1449
|
if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
|
|
1433
1450
|
if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
|
|
1434
|
-
const target =
|
|
1451
|
+
const target = path31.resolve(options.target);
|
|
1435
1452
|
if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
|
|
1436
1453
|
const source = starterDir();
|
|
1437
|
-
const read = (rel) => readFileSync(
|
|
1454
|
+
const read = (rel) => readFileSync(path31.join(source, rel), "utf8");
|
|
1438
1455
|
const was = starterIdentity(read("starter.config.ts"));
|
|
1439
1456
|
const substitutions = { [was.bundleId]: bundleId, [was.slug]: slug, [was.scheme]: scheme, [was.name]: display };
|
|
1440
1457
|
const files = /* @__PURE__ */ new Map();
|
|
@@ -1465,14 +1482,14 @@ function initNative(options) {
|
|
|
1465
1482
|
files.set("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
1466
1483
|
`);
|
|
1467
1484
|
files.set("metro.config.js", METRO);
|
|
1468
|
-
const pnpmSettings = [
|
|
1485
|
+
const pnpmSettings = [path31.join(source, "pnpm-workspace.yaml"), path31.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
|
|
1469
1486
|
if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
|
|
1470
1487
|
files.set("README.md", readme(display, slug));
|
|
1471
1488
|
const lock = { ...emptyLock(), substitutions };
|
|
1472
1489
|
const cliVersion2 = pinnedVersion(target, CLI_PACKAGE)?.version;
|
|
1473
1490
|
const templates = templatesDir();
|
|
1474
1491
|
for (const rel of walk(templates)) {
|
|
1475
|
-
const text = substitute(readFileSync(
|
|
1492
|
+
const text = substitute(readFileSync(path31.join(templates, rel), "utf8"), substitutions);
|
|
1476
1493
|
const to = templateTarget(rel, text);
|
|
1477
1494
|
files.set(to, text);
|
|
1478
1495
|
lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
|
|
@@ -1483,14 +1500,14 @@ function initNative(options) {
|
|
|
1483
1500
|
const blocks = [];
|
|
1484
1501
|
for (const block of options.blocks) {
|
|
1485
1502
|
const stems = block.migrations.map((m) => stemOf(m.file));
|
|
1486
|
-
const copies = stems.map((s) => migrations.find((f) =>
|
|
1503
|
+
const copies = stems.map((s) => migrations.find((f) => path31.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
|
|
1487
1504
|
if (!stems.length || copies.some((c) => !c)) continue;
|
|
1488
1505
|
blocks.push(block.id);
|
|
1489
1506
|
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
1490
1507
|
block.migrations.forEach((m) => {
|
|
1491
1508
|
if (m.test) {
|
|
1492
|
-
const
|
|
1493
|
-
if (files.has(
|
|
1509
|
+
const test2 = `${TESTS_DIR}/${path31.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
|
|
1510
|
+
if (files.has(test2)) lock.files[test2] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test2)) };
|
|
1494
1511
|
}
|
|
1495
1512
|
});
|
|
1496
1513
|
for (const fn of block.functions) {
|
|
@@ -1502,8 +1519,8 @@ function initNative(options) {
|
|
|
1502
1519
|
}
|
|
1503
1520
|
mkdirSync(target, { recursive: true });
|
|
1504
1521
|
for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1505
|
-
const file =
|
|
1506
|
-
mkdirSync(
|
|
1522
|
+
const file = path31.join(target, ...rel.split("/"));
|
|
1523
|
+
mkdirSync(path31.dirname(file), { recursive: true });
|
|
1507
1524
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
1508
1525
|
}
|
|
1509
1526
|
writeLock(target, lock);
|
|
@@ -1558,12 +1575,12 @@ function parse(comment, keys, where) {
|
|
|
1558
1575
|
throw new CommentSettingsError(`${where}: the text after ${MARKER} must be one JSON object.`);
|
|
1559
1576
|
}
|
|
1560
1577
|
const settings2 = {};
|
|
1561
|
-
for (const [
|
|
1562
|
-
if (!keys.includes(
|
|
1563
|
-
throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${
|
|
1578
|
+
for (const [key2, v] of Object.entries(value)) {
|
|
1579
|
+
if (!keys.includes(key2)) {
|
|
1580
|
+
throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${key2}". Allowed: ${keys.join(", ")}.`);
|
|
1564
1581
|
}
|
|
1565
|
-
if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${
|
|
1566
|
-
settings2[
|
|
1582
|
+
if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${key2}" must be a string.`);
|
|
1583
|
+
settings2[key2] = v;
|
|
1567
1584
|
}
|
|
1568
1585
|
return { ...description ? { description } : {}, ...Object.keys(settings2).length ? { settings: settings2 } : {} };
|
|
1569
1586
|
}
|
|
@@ -1700,9 +1717,9 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
1700
1717
|
const def = definitions[tableName];
|
|
1701
1718
|
const name = `${schema}.${tableName}`;
|
|
1702
1719
|
const required = new Set(def.required ?? []);
|
|
1703
|
-
const
|
|
1720
|
+
const key2 = [];
|
|
1704
1721
|
const columns = Object.entries(def.properties ?? {}).map(([column, prop]) => {
|
|
1705
|
-
if (PK.test(prop.description ?? ""))
|
|
1722
|
+
if (PK.test(prop.description ?? "")) key2.push(column);
|
|
1706
1723
|
const fk = FK.exec(prop.description ?? "");
|
|
1707
1724
|
const isArray = prop.type === "array";
|
|
1708
1725
|
const format = (isArray ? prop.items?.format : prop.format) ?? prop.type ?? "text";
|
|
@@ -1729,7 +1746,7 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
1729
1746
|
name,
|
|
1730
1747
|
schema,
|
|
1731
1748
|
table: tableName,
|
|
1732
|
-
key,
|
|
1749
|
+
key: key2,
|
|
1733
1750
|
columns,
|
|
1734
1751
|
...comment.description ? { description: comment.description } : {},
|
|
1735
1752
|
...comment.settings ? { settings: comment.settings } : {}
|
|
@@ -1857,19 +1874,19 @@ var init_introspect = __esm({
|
|
|
1857
1874
|
});
|
|
1858
1875
|
function buildCommands(root, config) {
|
|
1859
1876
|
if (config.build) return config.build;
|
|
1860
|
-
const pkgFile =
|
|
1877
|
+
const pkgFile = path31.join(root, "package.json");
|
|
1861
1878
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
1862
1879
|
const pm = packageManager(root);
|
|
1863
1880
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
1864
1881
|
}
|
|
1865
1882
|
function packageManager(root) {
|
|
1866
|
-
let dir =
|
|
1883
|
+
let dir = path31.resolve(root);
|
|
1867
1884
|
for (; ; ) {
|
|
1868
|
-
if (existsSync(
|
|
1869
|
-
if (existsSync(
|
|
1870
|
-
if (existsSync(
|
|
1871
|
-
if (existsSync(
|
|
1872
|
-
const parent =
|
|
1885
|
+
if (existsSync(path31.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1886
|
+
if (existsSync(path31.join(dir, "bun.lock")) || existsSync(path31.join(dir, "bun.lockb"))) return "bun";
|
|
1887
|
+
if (existsSync(path31.join(dir, "yarn.lock"))) return "yarn";
|
|
1888
|
+
if (existsSync(path31.join(dir, "package-lock.json"))) return "npm";
|
|
1889
|
+
const parent = path31.dirname(dir);
|
|
1873
1890
|
if (parent === dir) return "npm";
|
|
1874
1891
|
dir = parent;
|
|
1875
1892
|
}
|
|
@@ -1926,7 +1943,7 @@ function globToRegExp(glob) {
|
|
|
1926
1943
|
}
|
|
1927
1944
|
function globMatcher(globs) {
|
|
1928
1945
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1929
|
-
return (
|
|
1946
|
+
return (path32) => res.some((re) => re.test(path32));
|
|
1930
1947
|
}
|
|
1931
1948
|
var init_glob = __esm({
|
|
1932
1949
|
"src/doctor/glob.ts"() {
|
|
@@ -2103,9 +2120,9 @@ function scanFiles(root, config) {
|
|
|
2103
2120
|
const files = [];
|
|
2104
2121
|
const seen = /* @__PURE__ */ new Set();
|
|
2105
2122
|
const visit = (abs) => {
|
|
2106
|
-
const rel = toPosix(
|
|
2123
|
+
const rel = toPosix(path31.relative(root, abs));
|
|
2107
2124
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2108
|
-
const ext =
|
|
2125
|
+
const ext = path31.extname(abs);
|
|
2109
2126
|
if (!extensions.has(ext)) return;
|
|
2110
2127
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2111
2128
|
seen.add(rel);
|
|
@@ -2115,14 +2132,14 @@ function scanFiles(root, config) {
|
|
|
2115
2132
|
const walk2 = (dir) => {
|
|
2116
2133
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2117
2134
|
if (entry.isDirectory()) {
|
|
2118
|
-
if (!SKIP_DIRS.has(entry.name)) walk2(
|
|
2135
|
+
if (!SKIP_DIRS.has(entry.name)) walk2(path31.join(dir, entry.name));
|
|
2119
2136
|
} else if (entry.isFile()) {
|
|
2120
|
-
visit(
|
|
2137
|
+
visit(path31.join(dir, entry.name));
|
|
2121
2138
|
}
|
|
2122
2139
|
}
|
|
2123
2140
|
};
|
|
2124
2141
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2125
|
-
const abs =
|
|
2142
|
+
const abs = path31.resolve(root, src);
|
|
2126
2143
|
if (!existsSync(abs)) continue;
|
|
2127
2144
|
if (statSync(abs).isDirectory()) walk2(abs);
|
|
2128
2145
|
else visit(abs);
|
|
@@ -2153,7 +2170,7 @@ var init_scan = __esm({
|
|
|
2153
2170
|
];
|
|
2154
2171
|
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2155
2172
|
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2156
|
-
toPosix = (p) => p.split(
|
|
2173
|
+
toPosix = (p) => p.split(path31.sep).join("/");
|
|
2157
2174
|
}
|
|
2158
2175
|
});
|
|
2159
2176
|
function parseRulesMarkdown(markdown) {
|
|
@@ -2172,11 +2189,11 @@ function parseRulesMarkdown(markdown) {
|
|
|
2172
2189
|
}
|
|
2173
2190
|
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message):\s*(.*)$/);
|
|
2174
2191
|
if (!current || !kv) continue;
|
|
2175
|
-
const [,
|
|
2192
|
+
const [, key2, raw] = kv;
|
|
2176
2193
|
const value = raw.trim();
|
|
2177
|
-
if (
|
|
2178
|
-
else if (
|
|
2179
|
-
else current[
|
|
2194
|
+
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2195
|
+
else if (key2 === "level") current.level = value;
|
|
2196
|
+
else current[key2] = value;
|
|
2180
2197
|
}
|
|
2181
2198
|
return rules;
|
|
2182
2199
|
}
|
|
@@ -2191,8 +2208,8 @@ function compilePatternRules(rules, source) {
|
|
|
2191
2208
|
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
2192
2209
|
ids.add(rule.id);
|
|
2193
2210
|
const level = rule.level ?? "error";
|
|
2194
|
-
if (!["error", "warn", "guide"].includes(level)) {
|
|
2195
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn or guide)`);
|
|
2211
|
+
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
2212
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
2196
2213
|
}
|
|
2197
2214
|
if (level === "guide") continue;
|
|
2198
2215
|
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
@@ -2219,7 +2236,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
2219
2236
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2220
2237
|
let all = compiled;
|
|
2221
2238
|
if (rulesDoc) {
|
|
2222
|
-
const file =
|
|
2239
|
+
const file = path31.resolve(root, rulesDoc);
|
|
2223
2240
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2224
2241
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2225
2242
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -2285,14 +2302,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
2285
2302
|
}
|
|
2286
2303
|
function resolvePlugin(id, configDir) {
|
|
2287
2304
|
try {
|
|
2288
|
-
if (id.startsWith(".") ||
|
|
2305
|
+
if (id.startsWith(".") || path31.isAbsolute(id)) return resolveFrom(path31.resolve(configDir, id), configDir);
|
|
2289
2306
|
return resolveFrom(id, configDir);
|
|
2290
2307
|
} catch {
|
|
2291
2308
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2292
2309
|
}
|
|
2293
2310
|
}
|
|
2294
2311
|
function resolveFrom(id, from) {
|
|
2295
|
-
return createRequire(
|
|
2312
|
+
return createRequire(path31.join(from, "noop.js")).resolve(id);
|
|
2296
2313
|
}
|
|
2297
2314
|
var init_plugins = __esm({
|
|
2298
2315
|
"src/doctor/plugins.ts"() {
|
|
@@ -2310,7 +2327,7 @@ function importSpecifiers(file) {
|
|
|
2310
2327
|
}
|
|
2311
2328
|
function checkProjectLayout(ctx) {
|
|
2312
2329
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2313
|
-
if (existsSync(
|
|
2330
|
+
if (existsSync(path31.join(ctx.root, dir))) {
|
|
2314
2331
|
ctx.report({
|
|
2315
2332
|
rule: "local-primitives",
|
|
2316
2333
|
file: dir,
|
|
@@ -2320,7 +2337,7 @@ function checkProjectLayout(ctx) {
|
|
|
2320
2337
|
}
|
|
2321
2338
|
}
|
|
2322
2339
|
for (const file of STARTER_LEFTOVERS) {
|
|
2323
|
-
if (existsSync(
|
|
2340
|
+
if (existsSync(path31.join(ctx.root, file))) {
|
|
2324
2341
|
ctx.report({
|
|
2325
2342
|
rule: "starter-leftover",
|
|
2326
2343
|
level: "warn",
|
|
@@ -2407,7 +2424,7 @@ function checkTokens(ctx) {
|
|
|
2407
2424
|
}
|
|
2408
2425
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2409
2426
|
if (/[*?]/.test(pattern)) continue;
|
|
2410
|
-
const abs =
|
|
2427
|
+
const abs = path31.join(ctx.root, pattern);
|
|
2411
2428
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2412
2429
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2413
2430
|
}
|
|
@@ -2466,6 +2483,15 @@ var init_rules = __esm({
|
|
|
2466
2483
|
"undefined-token",
|
|
2467
2484
|
"shadowed-export",
|
|
2468
2485
|
"version-skew",
|
|
2486
|
+
"duplicate-genesis-package",
|
|
2487
|
+
"peer-range-mismatch",
|
|
2488
|
+
// structure
|
|
2489
|
+
"hand-rolled-sub-nav",
|
|
2490
|
+
"local-genesis-copy",
|
|
2491
|
+
"resource-workspace",
|
|
2492
|
+
"page-layout",
|
|
2493
|
+
// dates
|
|
2494
|
+
"iso-date-slice",
|
|
2469
2495
|
// native pack
|
|
2470
2496
|
"native-raw-primitive",
|
|
2471
2497
|
"native-literal-color",
|
|
@@ -2476,7 +2502,8 @@ var init_rules = __esm({
|
|
|
2476
2502
|
"migration-grants",
|
|
2477
2503
|
"migration-rls",
|
|
2478
2504
|
"migration-definer-search-path",
|
|
2479
|
-
"migration-edited"
|
|
2505
|
+
"migration-edited",
|
|
2506
|
+
"migration-testing-kit"
|
|
2480
2507
|
];
|
|
2481
2508
|
DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
2482
2509
|
STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -2560,6 +2587,106 @@ var init_expo = __esm({
|
|
|
2560
2587
|
});
|
|
2561
2588
|
}
|
|
2562
2589
|
});
|
|
2590
|
+
function localImports(root, file) {
|
|
2591
|
+
const out = [];
|
|
2592
|
+
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
2593
|
+
const spec = m[1];
|
|
2594
|
+
const bases = spec.startsWith(".") ? [path31.resolve(path31.dirname(file.absolutePath), spec)] : [path31.join(root, spec.slice(2)), path31.join(root, "src", spec.slice(2))];
|
|
2595
|
+
for (const base of bases) {
|
|
2596
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path31.join(base, `index${e}`))].find(
|
|
2597
|
+
(p) => SCRIPT_EXTS2.has(path31.extname(p)) && existsSync(p)
|
|
2598
|
+
);
|
|
2599
|
+
if (hit) {
|
|
2600
|
+
out.push(hit);
|
|
2601
|
+
break;
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
return out;
|
|
2606
|
+
}
|
|
2607
|
+
function readSource(abs) {
|
|
2608
|
+
try {
|
|
2609
|
+
return { absolutePath: abs, code: readFileSync(abs, "utf8") };
|
|
2610
|
+
} catch {
|
|
2611
|
+
return null;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
function viaOneImport(root, files, file, test2) {
|
|
2615
|
+
if (test2(file.code)) return true;
|
|
2616
|
+
const byPath = new Map(files.map((f) => [f.absolutePath, f]));
|
|
2617
|
+
return localImports(root, file).some((abs) => {
|
|
2618
|
+
const target = byPath.get(abs) ?? readSource(abs);
|
|
2619
|
+
return target !== null && test2(target.code);
|
|
2620
|
+
});
|
|
2621
|
+
}
|
|
2622
|
+
function tagEnd(code, start) {
|
|
2623
|
+
let depth = 0;
|
|
2624
|
+
let quote2 = null;
|
|
2625
|
+
for (let i = start + 1; i < code.length; i++) {
|
|
2626
|
+
const ch = code[i];
|
|
2627
|
+
if (quote2) {
|
|
2628
|
+
if (ch === "\\") i++;
|
|
2629
|
+
else if (ch === quote2) quote2 = null;
|
|
2630
|
+
continue;
|
|
2631
|
+
}
|
|
2632
|
+
if (ch === '"' || ch === "'" || ch === "`") quote2 = ch;
|
|
2633
|
+
else if (ch === "{") depth++;
|
|
2634
|
+
else if (ch === "}") depth--;
|
|
2635
|
+
else if (ch === ">" && depth === 0) {
|
|
2636
|
+
let j = i - 1;
|
|
2637
|
+
while (j > start && /\s/.test(code[j])) j--;
|
|
2638
|
+
return { end: i + 1, selfClosing: code[j] === "/" };
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
return { end: code.length, selfClosing: false };
|
|
2642
|
+
}
|
|
2643
|
+
function openElementsAt(code, index, track) {
|
|
2644
|
+
const open = [];
|
|
2645
|
+
const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
|
|
2646
|
+
for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
|
|
2647
|
+
const name = m[2];
|
|
2648
|
+
if (!track(name)) continue;
|
|
2649
|
+
if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
|
|
2650
|
+
if (m[1]) {
|
|
2651
|
+
const at = open.lastIndexOf(name);
|
|
2652
|
+
if (at !== -1) open.splice(at, 1);
|
|
2653
|
+
continue;
|
|
2654
|
+
}
|
|
2655
|
+
const { end, selfClosing } = tagEnd(code, m.index);
|
|
2656
|
+
if (end > index) break;
|
|
2657
|
+
if (!selfClosing) open.push(name);
|
|
2658
|
+
}
|
|
2659
|
+
return open;
|
|
2660
|
+
}
|
|
2661
|
+
function renderedElements(code) {
|
|
2662
|
+
const out = [];
|
|
2663
|
+
for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
|
|
2664
|
+
return out;
|
|
2665
|
+
}
|
|
2666
|
+
function rendersJsx(code) {
|
|
2667
|
+
return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
|
|
2668
|
+
}
|
|
2669
|
+
function namedImportsFrom(code, pkg) {
|
|
2670
|
+
const out = [];
|
|
2671
|
+
for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
2672
|
+
if (!pkg.test(m[2])) continue;
|
|
2673
|
+
for (const part of m[1].split(",")) {
|
|
2674
|
+
const p = part.trim();
|
|
2675
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2676
|
+
const local = p.split(/\s+as\s+/).pop()?.trim();
|
|
2677
|
+
if (local) out.push(local);
|
|
2678
|
+
}
|
|
2679
|
+
}
|
|
2680
|
+
return out;
|
|
2681
|
+
}
|
|
2682
|
+
var SCRIPT_EXTS2, JSX_EXTS2, RESOLVE_EXTS;
|
|
2683
|
+
var init_source = __esm({
|
|
2684
|
+
"src/doctor/source.ts"() {
|
|
2685
|
+
SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
2686
|
+
JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2687
|
+
RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2688
|
+
}
|
|
2689
|
+
});
|
|
2563
2690
|
function nativePackage(ctx) {
|
|
2564
2691
|
const pkg = readPackageExports(ctx.root, NATIVE_UI_PACKAGE);
|
|
2565
2692
|
if (!pkg) throw new DoctorConfigError(`the native pack needs ${NATIVE_UI_PACKAGE}; install it, or remove "native" from doctor.packs`);
|
|
@@ -2589,7 +2716,7 @@ function checkRawPrimitives(ctx, pkg) {
|
|
|
2589
2716
|
];
|
|
2590
2717
|
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
2591
2718
|
for (const file of ctx.files) {
|
|
2592
|
-
if (!
|
|
2719
|
+
if (!SCRIPT_EXTS3.has(file.ext)) continue;
|
|
2593
2720
|
const code = file.code;
|
|
2594
2721
|
const report = (name, at) => {
|
|
2595
2722
|
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
@@ -2635,10 +2762,10 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2635
2762
|
const reported = /* @__PURE__ */ new Set();
|
|
2636
2763
|
const hidingLayouts = /* @__PURE__ */ new Map();
|
|
2637
2764
|
for (const file of ctx.files) {
|
|
2638
|
-
if (!
|
|
2765
|
+
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2639
2766
|
const code = file.code;
|
|
2640
2767
|
const hidden = HIDES_HEADER.exec(code);
|
|
2641
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2768
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path31.posix.dirname(file.path), file.path);
|
|
2642
2769
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2643
2770
|
if (hidden && own) {
|
|
2644
2771
|
reported.add(file.path);
|
|
@@ -2665,8 +2792,8 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2665
2792
|
}
|
|
2666
2793
|
}
|
|
2667
2794
|
for (const file of ctx.files) {
|
|
2668
|
-
if (!
|
|
2669
|
-
const layout = hidingLayouts.get(
|
|
2795
|
+
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2796
|
+
const layout = hidingLayouts.get(path31.posix.dirname(file.path));
|
|
2670
2797
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2671
2798
|
if (!layout || !own) continue;
|
|
2672
2799
|
ctx.report({
|
|
@@ -2681,13 +2808,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2681
2808
|
}
|
|
2682
2809
|
function routerRoot(ctx) {
|
|
2683
2810
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2684
|
-
return existsSync(
|
|
2811
|
+
return existsSync(path31.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2685
2812
|
}
|
|
2686
2813
|
function checkScreenLayouts(ctx, pkg) {
|
|
2687
2814
|
const layouts = nativeLayouts(pkg);
|
|
2688
2815
|
if (layouts.length === 0) return;
|
|
2689
2816
|
const rootDir = routerRoot(ctx);
|
|
2690
|
-
if (!existsSync(
|
|
2817
|
+
if (!existsSync(path31.join(ctx.root, rootDir))) {
|
|
2691
2818
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2692
2819
|
return;
|
|
2693
2820
|
}
|
|
@@ -2704,7 +2831,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2704
2831
|
const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
2705
2832
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2706
2833
|
for (const file of routes) {
|
|
2707
|
-
if (!
|
|
2834
|
+
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2708
2835
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
2709
2836
|
if (renders.test(file.code)) continue;
|
|
2710
2837
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
@@ -2720,34 +2847,10 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2720
2847
|
});
|
|
2721
2848
|
}
|
|
2722
2849
|
}
|
|
2723
|
-
function localImports(root, file) {
|
|
2724
|
-
const out = [];
|
|
2725
|
-
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
2726
|
-
const spec = m[1];
|
|
2727
|
-
const bases = spec.startsWith(".") ? [path28.resolve(path28.dirname(file.absolutePath), spec)] : [path28.join(root, spec.slice(2)), path28.join(root, "src", spec.slice(2))];
|
|
2728
|
-
for (const base of bases) {
|
|
2729
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path28.join(base, `index${e}`))].find(
|
|
2730
|
-
(p) => SCRIPT_EXTS2.has(path28.extname(p)) && existsSync(p)
|
|
2731
|
-
);
|
|
2732
|
-
if (hit) {
|
|
2733
|
-
out.push(hit);
|
|
2734
|
-
break;
|
|
2735
|
-
}
|
|
2736
|
-
}
|
|
2737
|
-
}
|
|
2738
|
-
return out;
|
|
2739
|
-
}
|
|
2740
|
-
function readSource(abs) {
|
|
2741
|
-
try {
|
|
2742
|
-
return { code: readFileSync(abs, "utf8") };
|
|
2743
|
-
} catch {
|
|
2744
|
-
return null;
|
|
2745
|
-
}
|
|
2746
|
-
}
|
|
2747
2850
|
function readExpoConfigs(root) {
|
|
2748
2851
|
const out = [];
|
|
2749
2852
|
for (const name of EXPO_CONFIGS) {
|
|
2750
|
-
const abs =
|
|
2853
|
+
const abs = path31.join(root, name);
|
|
2751
2854
|
if (!existsSync(abs)) continue;
|
|
2752
2855
|
const text = readFileSync(abs, "utf8");
|
|
2753
2856
|
let json = null;
|
|
@@ -2781,13 +2884,13 @@ function pluginOptions(json, module) {
|
|
|
2781
2884
|
return null;
|
|
2782
2885
|
}
|
|
2783
2886
|
function dependencies(root) {
|
|
2784
|
-
const file =
|
|
2887
|
+
const file = path31.join(root, "package.json");
|
|
2785
2888
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2786
2889
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2787
2890
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2788
2891
|
}
|
|
2789
2892
|
function runtimeDependencies(root) {
|
|
2790
|
-
const file =
|
|
2893
|
+
const file = path31.join(root, "package.json");
|
|
2791
2894
|
if (!existsSync(file)) return {};
|
|
2792
2895
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2793
2896
|
}
|
|
@@ -2847,14 +2950,14 @@ function checkStoreReadiness(ctx) {
|
|
|
2847
2950
|
});
|
|
2848
2951
|
if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
|
|
2849
2952
|
}
|
|
2850
|
-
for (const [
|
|
2851
|
-
const opt = PERMISSIONS.find((p) => p.key ===
|
|
2953
|
+
for (const [key2, modules] of generic) {
|
|
2954
|
+
const opt = PERMISSIONS.find((p) => p.key === key2).option;
|
|
2852
2955
|
ctx.report({
|
|
2853
2956
|
rule: "store-readiness",
|
|
2854
2957
|
level: "warn",
|
|
2855
2958
|
file,
|
|
2856
|
-
subject:
|
|
2857
|
-
message: `leaves ${
|
|
2959
|
+
subject: key2,
|
|
2960
|
+
message: `leaves ${key2} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key2}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
|
|
2858
2961
|
});
|
|
2859
2962
|
}
|
|
2860
2963
|
const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
|
|
@@ -2868,7 +2971,7 @@ function checkStoreReadiness(ctx) {
|
|
|
2868
2971
|
});
|
|
2869
2972
|
}
|
|
2870
2973
|
}
|
|
2871
|
-
var
|
|
2974
|
+
var SCRIPT_EXTS3, JSX_EXTS3, LAYOUT_NAME, NON_SCREEN_ROUTE, PART_HEADER, HIDES_HEADER, RN, PERMISSIONS, SOCIAL_SIGN_IN, WEAK_SOCIAL_SIGN_IN, APPLE_SIGN_IN, EXPO_CONFIGS, SUPABASE_SIGN_IN, GENESIS_PLUGIN, GENESIS_PLUGIN_TEXT, GENESIS_PLUGIN_IMPORT;
|
|
2872
2975
|
var init_native = __esm({
|
|
2873
2976
|
"src/doctor/native.ts"() {
|
|
2874
2977
|
init_native_primitives();
|
|
@@ -2876,9 +2979,9 @@ var init_native = __esm({
|
|
|
2876
2979
|
init_config();
|
|
2877
2980
|
init_genesis();
|
|
2878
2981
|
init_scan();
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2982
|
+
init_source();
|
|
2983
|
+
SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
2984
|
+
JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2882
2985
|
LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
|
|
2883
2986
|
NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
|
|
2884
2987
|
PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
|
|
@@ -3072,9 +3175,9 @@ function gitView(root, dir, base) {
|
|
|
3072
3175
|
function checkSupabasePack(ctx) {
|
|
3073
3176
|
const settings2 = ctx.config.supabase ?? {};
|
|
3074
3177
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
3075
|
-
const abs =
|
|
3178
|
+
const abs = path31.join(ctx.root, dir);
|
|
3076
3179
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
3077
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
3180
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path31.join(abs, n), "utf8")) }));
|
|
3078
3181
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
3079
3182
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
3080
3183
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -3091,7 +3194,7 @@ function checkSupabasePack(ctx) {
|
|
|
3091
3194
|
}
|
|
3092
3195
|
}
|
|
3093
3196
|
const since = settings2.since;
|
|
3094
|
-
const afterSince = (file) => since === void 0 ||
|
|
3197
|
+
const afterSince = (file) => since === void 0 || path31.posix.basename(file) >= since;
|
|
3095
3198
|
if ("reason" in view && since === void 0) {
|
|
3096
3199
|
ctx.report({
|
|
3097
3200
|
rule: "migration-grants",
|
|
@@ -3105,6 +3208,20 @@ function checkSupabasePack(ctx) {
|
|
|
3105
3208
|
}
|
|
3106
3209
|
checkRls(ctx, migrations, exposed);
|
|
3107
3210
|
checkDefinerSearchPath(ctx, migrations);
|
|
3211
|
+
checkTestingKit(ctx, migrations);
|
|
3212
|
+
}
|
|
3213
|
+
function checkTestingKit(ctx, migrations) {
|
|
3214
|
+
for (const { file, statements } of migrations) {
|
|
3215
|
+
const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
|
|
3216
|
+
if (!hit) continue;
|
|
3217
|
+
ctx.report({
|
|
3218
|
+
rule: "migration-testing-kit",
|
|
3219
|
+
file,
|
|
3220
|
+
line: hit.line,
|
|
3221
|
+
subject: "genesis_testing",
|
|
3222
|
+
message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3108
3225
|
}
|
|
3109
3226
|
function granteesOf(s) {
|
|
3110
3227
|
return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
|
|
@@ -3233,8 +3350,8 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
3233
3350
|
for (const { sql, line } of statements) {
|
|
3234
3351
|
const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
|
|
3235
3352
|
if (create) {
|
|
3236
|
-
const [
|
|
3237
|
-
fns.set(
|
|
3353
|
+
const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
|
|
3354
|
+
fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
|
|
3238
3355
|
continue;
|
|
3239
3356
|
}
|
|
3240
3357
|
const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
|
|
@@ -3243,13 +3360,13 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
3243
3360
|
const keys = keysFor(sql, alter[0].length, fnName);
|
|
3244
3361
|
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
3245
3362
|
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
3246
|
-
for (const
|
|
3247
|
-
const state = fns.get(
|
|
3363
|
+
for (const key2 of keys) {
|
|
3364
|
+
const state = fns.get(key2);
|
|
3248
3365
|
if (rename || move) {
|
|
3249
3366
|
if (!state) continue;
|
|
3250
|
-
fns.delete(
|
|
3367
|
+
fns.delete(key2);
|
|
3251
3368
|
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
3252
|
-
fns.set(newName +
|
|
3369
|
+
fns.set(newName + key2.slice(fnName.length), state);
|
|
3253
3370
|
continue;
|
|
3254
3371
|
}
|
|
3255
3372
|
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
@@ -3257,7 +3374,7 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
3257
3374
|
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
3258
3375
|
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
3259
3376
|
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
3260
|
-
fns.set(
|
|
3377
|
+
fns.set(key2, next);
|
|
3261
3378
|
}
|
|
3262
3379
|
continue;
|
|
3263
3380
|
}
|
|
@@ -3265,19 +3382,19 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
3265
3382
|
if (drop) {
|
|
3266
3383
|
for (const part of splitTop(drop[1])) {
|
|
3267
3384
|
const m = /^([\w$.]+)\s*/.exec(part);
|
|
3268
|
-
if (m) for (const
|
|
3385
|
+
if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
|
|
3269
3386
|
}
|
|
3270
3387
|
}
|
|
3271
3388
|
}
|
|
3272
3389
|
}
|
|
3273
|
-
for (const [
|
|
3390
|
+
for (const [key2, at] of fns) {
|
|
3274
3391
|
if (!at.definer || at.searchPath) continue;
|
|
3275
3392
|
ctx.report({
|
|
3276
3393
|
rule: "migration-definer-search-path",
|
|
3277
3394
|
file: at.file,
|
|
3278
3395
|
line: at.line,
|
|
3279
|
-
subject:
|
|
3280
|
-
message: `${
|
|
3396
|
+
subject: key2,
|
|
3397
|
+
message: `${key2} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
|
|
3281
3398
|
});
|
|
3282
3399
|
}
|
|
3283
3400
|
}
|
|
@@ -3303,15 +3420,486 @@ var init_supabase = __esm({
|
|
|
3303
3420
|
}
|
|
3304
3421
|
});
|
|
3305
3422
|
|
|
3423
|
+
// src/doctor/semver.ts
|
|
3424
|
+
function parseVersion(v) {
|
|
3425
|
+
const m = VERSION.exec(v.trim());
|
|
3426
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
3427
|
+
}
|
|
3428
|
+
function compareVersions(a, b) {
|
|
3429
|
+
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
3430
|
+
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
3431
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
3432
|
+
const x = a.pre[i];
|
|
3433
|
+
const y = b.pre[i];
|
|
3434
|
+
if (x === void 0) return -1;
|
|
3435
|
+
if (y === void 0) return 1;
|
|
3436
|
+
if (x === y) continue;
|
|
3437
|
+
const nx = /^\d+$/.test(x);
|
|
3438
|
+
const ny = /^\d+$/.test(y);
|
|
3439
|
+
if (nx && ny) return +x < +y ? -1 : 1;
|
|
3440
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
3441
|
+
return x < y ? -1 : 1;
|
|
3442
|
+
}
|
|
3443
|
+
return 0;
|
|
3444
|
+
}
|
|
3445
|
+
function partial(s) {
|
|
3446
|
+
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
3447
|
+
if (!m) return null;
|
|
3448
|
+
const nums = [];
|
|
3449
|
+
let wild = false;
|
|
3450
|
+
for (const part of [m[1], m[2], m[3]]) {
|
|
3451
|
+
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
3452
|
+
wild = true;
|
|
3453
|
+
nums.push(null);
|
|
3454
|
+
} else nums.push(+part);
|
|
3455
|
+
}
|
|
3456
|
+
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
3457
|
+
}
|
|
3458
|
+
function comparators(token) {
|
|
3459
|
+
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
3460
|
+
if (!m) return null;
|
|
3461
|
+
const op = m[1] ?? "";
|
|
3462
|
+
const p = partial(m[2]);
|
|
3463
|
+
if (!p) return null;
|
|
3464
|
+
const [major, mi, pa] = p.nums;
|
|
3465
|
+
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
3466
|
+
const M = major;
|
|
3467
|
+
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
3468
|
+
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
3469
|
+
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
3470
|
+
const out = switchOp();
|
|
3471
|
+
if (p.pre.length) {
|
|
3472
|
+
for (const c of out) if (c.v === lo) c.pre = true;
|
|
3473
|
+
}
|
|
3474
|
+
return out;
|
|
3475
|
+
function switchOp() {
|
|
3476
|
+
switch (op) {
|
|
3477
|
+
case "^": {
|
|
3478
|
+
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
3479
|
+
return [
|
|
3480
|
+
{ op: ">=", v: lo },
|
|
3481
|
+
{ op: "<", v: bound }
|
|
3482
|
+
];
|
|
3483
|
+
}
|
|
3484
|
+
case "~":
|
|
3485
|
+
case "~>":
|
|
3486
|
+
return [
|
|
3487
|
+
{ op: ">=", v: lo },
|
|
3488
|
+
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
3489
|
+
];
|
|
3490
|
+
case ">":
|
|
3491
|
+
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
3492
|
+
case ">=":
|
|
3493
|
+
return [{ op: ">=", v: lo }];
|
|
3494
|
+
case "<":
|
|
3495
|
+
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
3496
|
+
case "<=":
|
|
3497
|
+
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
3498
|
+
default:
|
|
3499
|
+
return upper ? [
|
|
3500
|
+
{ op: ">=", v: lo },
|
|
3501
|
+
{ op: "<", v: upper }
|
|
3502
|
+
] : [{ op: "=", v: lo }];
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
function test(c, v) {
|
|
3507
|
+
const d = compareVersions(v, c.v);
|
|
3508
|
+
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
3509
|
+
}
|
|
3510
|
+
function parseRange(range) {
|
|
3511
|
+
const alts = [];
|
|
3512
|
+
for (const raw of range.trim().split("||")) {
|
|
3513
|
+
const alt = raw.trim();
|
|
3514
|
+
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
3515
|
+
if (hyphen) {
|
|
3516
|
+
const from = comparators(`>=${hyphen[1]}`);
|
|
3517
|
+
const to = comparators(`<=${hyphen[2]}`);
|
|
3518
|
+
if (!from || !to) return null;
|
|
3519
|
+
alts.push([...from, ...to]);
|
|
3520
|
+
continue;
|
|
3521
|
+
}
|
|
3522
|
+
const set = [];
|
|
3523
|
+
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
3524
|
+
const cs = comparators(token);
|
|
3525
|
+
if (!cs) return null;
|
|
3526
|
+
set.push(...cs);
|
|
3527
|
+
}
|
|
3528
|
+
alts.push(set);
|
|
3529
|
+
}
|
|
3530
|
+
return alts;
|
|
3531
|
+
}
|
|
3532
|
+
function satisfies(version, range) {
|
|
3533
|
+
const v = parseVersion(version);
|
|
3534
|
+
const alts = parseRange(range);
|
|
3535
|
+
if (!v || !alts) return null;
|
|
3536
|
+
return alts.some(
|
|
3537
|
+
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
3538
|
+
);
|
|
3539
|
+
}
|
|
3540
|
+
var VERSION, ver;
|
|
3541
|
+
var init_semver = __esm({
|
|
3542
|
+
"src/doctor/semver.ts"() {
|
|
3543
|
+
VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
3544
|
+
ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
3545
|
+
}
|
|
3546
|
+
});
|
|
3547
|
+
function packagesIn(nodeModules) {
|
|
3548
|
+
if (!existsSync(nodeModules)) return [];
|
|
3549
|
+
const out = [];
|
|
3550
|
+
for (const entry of readdirSync(nodeModules)) {
|
|
3551
|
+
if (entry.startsWith(".")) continue;
|
|
3552
|
+
const p = path31.join(nodeModules, entry);
|
|
3553
|
+
if (entry.startsWith("@")) {
|
|
3554
|
+
try {
|
|
3555
|
+
for (const sub of readdirSync(p)) out.push(path31.join(p, sub));
|
|
3556
|
+
} catch {
|
|
3557
|
+
}
|
|
3558
|
+
} else {
|
|
3559
|
+
out.push(p);
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
return out;
|
|
3563
|
+
}
|
|
3564
|
+
function genesisInstalls(root) {
|
|
3565
|
+
const copies = /* @__PURE__ */ new Map();
|
|
3566
|
+
const realRoot = real(root);
|
|
3567
|
+
const rel = (abs) => path31.relative(realRoot, abs).split(path31.sep).join("/") || ".";
|
|
3568
|
+
const record = (real2, manifest, by, range) => {
|
|
3569
|
+
let copy = copies.get(real2);
|
|
3570
|
+
if (!copy) {
|
|
3571
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
|
|
3572
|
+
copies.set(real2, copy);
|
|
3573
|
+
}
|
|
3574
|
+
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
3575
|
+
};
|
|
3576
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
3577
|
+
const queue = [];
|
|
3578
|
+
const visit = (dir, by, range) => {
|
|
3579
|
+
const manifest = readManifest(dir);
|
|
3580
|
+
if (!manifest?.name) return;
|
|
3581
|
+
const realDir = real(dir);
|
|
3582
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range);
|
|
3583
|
+
if (expanded.has(realDir)) return;
|
|
3584
|
+
expanded.add(realDir);
|
|
3585
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
3586
|
+
};
|
|
3587
|
+
const app = readManifest(root);
|
|
3588
|
+
const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
3589
|
+
for (const name of Object.keys(appDeps)) {
|
|
3590
|
+
const dir = findPackageDir(root, name);
|
|
3591
|
+
if (dir) visit(dir, "the app", appDeps[name]);
|
|
3592
|
+
}
|
|
3593
|
+
const top = path31.join(root, "node_modules");
|
|
3594
|
+
for (const dir of packagesIn(top)) {
|
|
3595
|
+
const name = path31.relative(top, dir).split(path31.sep).join("/");
|
|
3596
|
+
if (!(name in appDeps)) visit(dir, "hoisted, not a direct dependency", void 0);
|
|
3597
|
+
}
|
|
3598
|
+
while (queue.length) {
|
|
3599
|
+
const { real: from, manifest, label } = queue.shift();
|
|
3600
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
3601
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
3602
|
+
const dir = findPackageDir(from, name);
|
|
3603
|
+
if (dir) visit(dir, label, range);
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3607
|
+
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
3608
|
+
for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
|
|
3609
|
+
return byName;
|
|
3610
|
+
}
|
|
3611
|
+
function checkDuplicatePackages(ctx) {
|
|
3612
|
+
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
3613
|
+
if (copies.length < 2) continue;
|
|
3614
|
+
const where = copies.map((c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`).join(", ");
|
|
3615
|
+
ctx.report({
|
|
3616
|
+
rule: "duplicate-genesis-package",
|
|
3617
|
+
level: "warn",
|
|
3618
|
+
file: "package.json",
|
|
3619
|
+
subject: name,
|
|
3620
|
+
message: `${name} is installed ${copies.length} times: ${where}. Each copy is its own module, so a provider from one (DataProvider, the shell's contexts) is invisible to hooks from another. Align the ranges so one copy satisfies them all, or add an override/resolution`
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
function checkPeerRanges(ctx) {
|
|
3625
|
+
const rel = (abs) => path31.relative(ctx.root, abs).split(path31.sep).join("/");
|
|
3626
|
+
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
3627
|
+
for (const copy of copies) {
|
|
3628
|
+
const dir = copy.absolutePath;
|
|
3629
|
+
const peers = readManifest(dir)?.peerDependencies ?? {};
|
|
3630
|
+
for (const [peer, range] of Object.entries(peers)) {
|
|
3631
|
+
if (!GENESIS.test(peer)) continue;
|
|
3632
|
+
const peerDir = findPackageDir(dir, peer);
|
|
3633
|
+
const installed = peerDir && readManifest(peerDir)?.version;
|
|
3634
|
+
if (!peerDir || !installed) continue;
|
|
3635
|
+
if (satisfies(installed, range) !== false) continue;
|
|
3636
|
+
ctx.report({
|
|
3637
|
+
rule: "peer-range-mismatch",
|
|
3638
|
+
level: "warn",
|
|
3639
|
+
file: "package.json",
|
|
3640
|
+
subject: `${copy.name}>${peer}`,
|
|
3641
|
+
message: `${copy.name}@${copy.version} (${copy.dir}) wants ${peer} ${range}, but ${installed} is installed (${rel(peerDir)}). Install a ${peer} in that range, or a ${copy.name} release built against ${installed}`
|
|
3642
|
+
});
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
}
|
|
3647
|
+
var GENESIS, readManifest, real;
|
|
3648
|
+
var init_installs = __esm({
|
|
3649
|
+
"src/doctor/installs.ts"() {
|
|
3650
|
+
init_genesis();
|
|
3651
|
+
init_semver();
|
|
3652
|
+
GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
3653
|
+
readManifest = (dir) => {
|
|
3654
|
+
try {
|
|
3655
|
+
return JSON.parse(readFileSync(path31.join(dir, "package.json"), "utf8"));
|
|
3656
|
+
} catch {
|
|
3657
|
+
return null;
|
|
3658
|
+
}
|
|
3659
|
+
};
|
|
3660
|
+
real = (p) => {
|
|
3661
|
+
try {
|
|
3662
|
+
return realpathSync(p);
|
|
3663
|
+
} catch {
|
|
3664
|
+
return p;
|
|
3665
|
+
}
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3668
|
+
});
|
|
3669
|
+
function routesDir(ctx) {
|
|
3670
|
+
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3671
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path31.join(ctx.root, d))) ?? null;
|
|
3672
|
+
}
|
|
3673
|
+
function webRoutes(ctx) {
|
|
3674
|
+
const dir = routesDir(ctx);
|
|
3675
|
+
if (!dir) return [];
|
|
3676
|
+
const routes = [];
|
|
3677
|
+
for (const file of ctx.files) {
|
|
3678
|
+
if (!JSX_EXTS2.has(file.ext) || !file.path.startsWith(`${dir}/`)) continue;
|
|
3679
|
+
const rel = file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "");
|
|
3680
|
+
const parts = rel.split("/");
|
|
3681
|
+
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
3682
|
+
const stem = parts.pop();
|
|
3683
|
+
const segments = [...parts, ...LAYOUT_STEMS.has(stem) || INDEX_STEMS.has(stem) ? [] : stem.split(".")];
|
|
3684
|
+
let index = INDEX_STEMS.has(stem);
|
|
3685
|
+
if (!index && !LAYOUT_STEMS.has(stem) && INDEX_STEMS.has(segments.at(-1) ?? "")) {
|
|
3686
|
+
segments.pop();
|
|
3687
|
+
index = true;
|
|
3688
|
+
}
|
|
3689
|
+
const elements = renderedElements(file.code);
|
|
3690
|
+
const layout = LAYOUT_STEMS.has(stem) || elements.includes("Outlet");
|
|
3691
|
+
routes.push({
|
|
3692
|
+
file,
|
|
3693
|
+
segments,
|
|
3694
|
+
index,
|
|
3695
|
+
layout,
|
|
3696
|
+
detail: !index && !layout && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
3697
|
+
redirectOnly: elements.every((e) => NON_PAGE_ELEMENTS.has(e)) && !HTML_ELEMENT.test(file.code),
|
|
3698
|
+
parents: []
|
|
3699
|
+
});
|
|
3700
|
+
}
|
|
3701
|
+
for (const r of routes) {
|
|
3702
|
+
const own = r.segments;
|
|
3703
|
+
for (const p of routes) {
|
|
3704
|
+
if (p === r || !p.layout) continue;
|
|
3705
|
+
const n = p.segments.length;
|
|
3706
|
+
if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
|
|
3707
|
+
if (key(own.slice(0, n)) !== key(p.segments)) continue;
|
|
3708
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.segments[n - 1].endsWith("_")) continue;
|
|
3709
|
+
r.parents.push(p);
|
|
3710
|
+
}
|
|
3711
|
+
r.parents.sort((a, b) => b.segments.length - a.segments.length);
|
|
3712
|
+
}
|
|
3713
|
+
return routes;
|
|
3714
|
+
}
|
|
3715
|
+
var ROUTES_DIR_CANDIDATES, LAYOUT_STEMS, INDEX_STEMS, NON_PAGE_ELEMENTS, HTML_ELEMENT, key;
|
|
3716
|
+
var init_routes = __esm({
|
|
3717
|
+
"src/doctor/routes.ts"() {
|
|
3718
|
+
init_source();
|
|
3719
|
+
ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3720
|
+
LAYOUT_STEMS = /* @__PURE__ */ new Set(["route", "layout", "_layout", "__root", "_app"]);
|
|
3721
|
+
INDEX_STEMS = /* @__PURE__ */ new Set(["index", "page"]);
|
|
3722
|
+
NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
3723
|
+
HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
3724
|
+
key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3725
|
+
}
|
|
3726
|
+
});
|
|
3727
|
+
|
|
3728
|
+
// src/doctor/structure.ts
|
|
3729
|
+
function insideShell(ctx, routes) {
|
|
3730
|
+
const shell = new Set(routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => SHELL.test(code))));
|
|
3731
|
+
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
3732
|
+
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
3733
|
+
}
|
|
3734
|
+
function checkHandRolledSubNav(ctx) {
|
|
3735
|
+
if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
|
|
3736
|
+
const routes = webRoutes(ctx);
|
|
3737
|
+
if (routes.length === 0) return;
|
|
3738
|
+
const inShell = insideShell(ctx, routes);
|
|
3739
|
+
const ui = ctx.genesis.uiPackage;
|
|
3740
|
+
for (const r of routes) {
|
|
3741
|
+
if (!inShell(r)) continue;
|
|
3742
|
+
const code = r.file.code;
|
|
3743
|
+
if (/\buseAppShellSubNav\s*\(/.test(code)) continue;
|
|
3744
|
+
for (const m of code.matchAll(SWITCHER)) {
|
|
3745
|
+
if (openElementsAt(code, m.index, (n) => CONTAINER.test(n)).length > 0) continue;
|
|
3746
|
+
ctx.report({
|
|
3747
|
+
rule: "hand-rolled-sub-nav",
|
|
3748
|
+
level: "warn",
|
|
3749
|
+
file: r.file.path,
|
|
3750
|
+
line: lineAt(code, m.index),
|
|
3751
|
+
subject: m[1],
|
|
3752
|
+
message: `switches the page's sections with its own <${m[1]}>; hand them to the shell with useAppShellSubNav(items, { mode: "tabs" }) and put the header in AppShellPageHeader (chips in AppShellSubNavEnd), from ${ui}/layout, so the sections are the shell's tab row and the phone's bottom bar. See ${SUB_NAV_DOCS}`
|
|
3753
|
+
});
|
|
3754
|
+
break;
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
}
|
|
3758
|
+
function checkLocalGenesisCopies(ctx) {
|
|
3759
|
+
const owner = /* @__PURE__ */ new Map();
|
|
3760
|
+
for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
|
|
3761
|
+
for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
|
|
3762
|
+
if (owner.size === 0) return;
|
|
3763
|
+
const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
|
|
3764
|
+
const routes = routesDir(ctx);
|
|
3765
|
+
for (const file of ctx.files) {
|
|
3766
|
+
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
3767
|
+
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
|
|
3768
|
+
const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
|
|
3769
|
+
const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
|
|
3770
|
+
const decls = [...file.code.matchAll(decl)];
|
|
3771
|
+
decls.forEach((m, i) => {
|
|
3772
|
+
const [, exported, name] = m;
|
|
3773
|
+
const pkg = owner.get(name);
|
|
3774
|
+
if (!pkg || imported.has(name) || routeComponents.has(name)) return;
|
|
3775
|
+
if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
|
|
3776
|
+
const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
|
|
3777
|
+
if (!rendersJsx(body)) return;
|
|
3778
|
+
if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
|
|
3779
|
+
const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
|
|
3780
|
+
if (/["']@marktiderman\/genesis/.test(init)) return;
|
|
3781
|
+
ctx.report({
|
|
3782
|
+
rule: "local-genesis-copy",
|
|
3783
|
+
level: "warn",
|
|
3784
|
+
file: file.path,
|
|
3785
|
+
line: lineAt(file.code, m.index),
|
|
3786
|
+
subject: name,
|
|
3787
|
+
message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
|
|
3788
|
+
});
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
function checkResourceWorkspaces(ctx) {
|
|
3793
|
+
if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
|
|
3794
|
+
const header = /<AppShellPageHeader(?=[\s>/])/;
|
|
3795
|
+
const byFolder = /* @__PURE__ */ new Map();
|
|
3796
|
+
for (const r of webRoutes(ctx)) {
|
|
3797
|
+
if (!r.detail || r.redirectOnly) continue;
|
|
3798
|
+
const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
|
|
3799
|
+
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
3800
|
+
}
|
|
3801
|
+
for (const [dir, routes] of byFolder) {
|
|
3802
|
+
const has2 = routes.filter((r) => viaOneImport(ctx.root, ctx.files, r.file, (code) => header.test(code)));
|
|
3803
|
+
if (has2.length === 0) continue;
|
|
3804
|
+
const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
3805
|
+
for (const r of routes) {
|
|
3806
|
+
if (has2.includes(r)) continue;
|
|
3807
|
+
ctx.report({
|
|
3808
|
+
rule: "resource-workspace",
|
|
3809
|
+
level: "info",
|
|
3810
|
+
file: r.file.path,
|
|
3811
|
+
message: `is a detail page without AppShellPageHeader, unlike ${ref} beside it; put its header in AppShellPageHeader and its sections in useAppShellSubNav so every workspace in ${dir} has the same header, tabs and phone bar`
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
}
|
|
3816
|
+
function checkPageLayouts(ctx) {
|
|
3817
|
+
if (isNative(ctx)) return;
|
|
3818
|
+
const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
|
|
3819
|
+
for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
|
|
3820
|
+
if (layouts.size === 0) return;
|
|
3821
|
+
const routes = webRoutes(ctx);
|
|
3822
|
+
const inShell = insideShell(ctx, routes);
|
|
3823
|
+
const rendersLayout = (code) => {
|
|
3824
|
+
const names = new Set(layouts);
|
|
3825
|
+
for (const n of namedImportsFrom(code, GENESIS_PACKAGE2)) if (PACKAGE_SCREEN.test(n)) names.add(n);
|
|
3826
|
+
return rendersRe(names)?.test(code) ?? false;
|
|
3827
|
+
};
|
|
3828
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3829
|
+
const provides = (r) => {
|
|
3830
|
+
if (!cache.has(r)) cache.set(r, viaOneImport(ctx.root, ctx.files, r.file, rendersLayout));
|
|
3831
|
+
return cache.get(r);
|
|
3832
|
+
};
|
|
3833
|
+
const list = [...layouts].sort();
|
|
3834
|
+
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
3835
|
+
for (const r of routes) {
|
|
3836
|
+
if (r.layout || r.redirectOnly || !inShell(r)) continue;
|
|
3837
|
+
if (provides(r) || r.parents.some(provides)) continue;
|
|
3838
|
+
ctx.report({
|
|
3839
|
+
rule: "page-layout",
|
|
3840
|
+
level: "warn",
|
|
3841
|
+
file: r.file.path,
|
|
3842
|
+
message: `renders no Genesis page layout (${named}) itself, through one local import, or from a layout route around it; wrap it in one so the header, width and spacing match every other page`
|
|
3843
|
+
});
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, PACKAGE_SCREEN, isNative, rendersRe;
|
|
3847
|
+
var init_structure = __esm({
|
|
3848
|
+
"src/doctor/structure.ts"() {
|
|
3849
|
+
init_scan();
|
|
3850
|
+
init_routes();
|
|
3851
|
+
init_source();
|
|
3852
|
+
SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
|
|
3853
|
+
CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
|
|
3854
|
+
SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
3855
|
+
SHELL = /<AppShell(?=[\s>/])/;
|
|
3856
|
+
GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
3857
|
+
PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
|
|
3858
|
+
PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
|
|
3859
|
+
isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
3860
|
+
rendersRe = (names) => {
|
|
3861
|
+
const list = [...names];
|
|
3862
|
+
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
});
|
|
3866
|
+
|
|
3867
|
+
// src/doctor/dates.ts
|
|
3868
|
+
function checkIsoDateSlices(ctx) {
|
|
3869
|
+
for (const file of ctx.files) {
|
|
3870
|
+
if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
|
|
3871
|
+
for (const m of file.code.matchAll(ISO_DAY_CUT)) {
|
|
3872
|
+
ctx.report({
|
|
3873
|
+
rule: "iso-date-slice",
|
|
3874
|
+
level: "warn",
|
|
3875
|
+
file: file.path,
|
|
3876
|
+
line: lineAt(file.code, m.index ?? 0),
|
|
3877
|
+
subject: "toISOString",
|
|
3878
|
+
message: "cuts a day from an ISO timestamp, which is the day in UTC, not the person's; use personDay(person) or dayIn(zone) from @marktiderman/genesis-core/dates (allow it with a reason where UTC is meant)"
|
|
3879
|
+
});
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
var SCRIPT_EXTS4, ISO_DAY_CUT;
|
|
3884
|
+
var init_dates = __esm({
|
|
3885
|
+
"src/doctor/dates.ts"() {
|
|
3886
|
+
init_scan();
|
|
3887
|
+
SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
3888
|
+
ISO_DAY_CUT = /\.toISOString\(\)\s*\.\s*(?:slice\(\s*0\s*,\s*10\s*\)|substring\(\s*0\s*,\s*10\s*\)|substr\(\s*0\s*,\s*10\s*\)|split\(\s*(["'`])T\1\s*\)\s*\[\s*0\s*\]|split\(\s*(["'`])T\2\s*\)\s*\.\s*at\(\s*0\s*\))/g;
|
|
3889
|
+
}
|
|
3890
|
+
});
|
|
3891
|
+
|
|
3306
3892
|
// src/doctor/index.ts
|
|
3307
3893
|
var doctor_exports = {};
|
|
3308
3894
|
__export(doctor_exports, {
|
|
3309
3895
|
BUILTIN_RULES: () => BUILTIN_RULES,
|
|
3310
3896
|
DoctorConfigError: () => DoctorConfigError,
|
|
3311
3897
|
GenesisConfigError: () => GenesisConfigError,
|
|
3898
|
+
builtinChecks: () => builtinChecks,
|
|
3312
3899
|
defineDoctorPlugin: () => defineDoctorPlugin,
|
|
3313
3900
|
findPackageDir: () => findPackageDir,
|
|
3314
3901
|
formatReport: () => formatReport,
|
|
3902
|
+
genesisInstalls: () => genesisInstalls,
|
|
3315
3903
|
genesisSummary: () => genesisSummary,
|
|
3316
3904
|
globToRegExp: () => globToRegExp,
|
|
3317
3905
|
loadConfig: () => loadConfig,
|
|
@@ -3322,14 +3910,17 @@ __export(doctor_exports, {
|
|
|
3322
3910
|
readGenesisConfig: () => readGenesisConfig,
|
|
3323
3911
|
readPackageExports: () => readPackageExports,
|
|
3324
3912
|
readReleaseManifest: () => readReleaseManifest,
|
|
3913
|
+
routesDir: () => routesDir,
|
|
3325
3914
|
runDoctor: () => runDoctor,
|
|
3915
|
+
satisfies: () => satisfies,
|
|
3326
3916
|
sqlStatements: () => sqlStatements,
|
|
3327
3917
|
toJson: () => toJson,
|
|
3328
3918
|
validateConfig: () => validateConfig,
|
|
3329
|
-
validateLinks: () => validateLinks
|
|
3919
|
+
validateLinks: () => validateLinks,
|
|
3920
|
+
webRoutes: () => webRoutes
|
|
3330
3921
|
});
|
|
3331
3922
|
async function runDoctor(options = {}) {
|
|
3332
|
-
const root =
|
|
3923
|
+
const root = path31.resolve(options.root ?? process.cwd());
|
|
3333
3924
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
3334
3925
|
const config = loaded.config;
|
|
3335
3926
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -3342,18 +3933,7 @@ async function runDoctor(options = {}) {
|
|
|
3342
3933
|
}
|
|
3343
3934
|
const raw = [];
|
|
3344
3935
|
const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
|
|
3345
|
-
const
|
|
3346
|
-
{ name: "layout", check: checkProjectLayout },
|
|
3347
|
-
{ name: "imports", check: checkImports },
|
|
3348
|
-
{ name: "raw-tags", check: checkRawTags },
|
|
3349
|
-
{ name: "colors", check: checkColors },
|
|
3350
|
-
{ name: "tokens", check: checkTokens },
|
|
3351
|
-
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
3352
|
-
{ name: "version-skew", check: checkVersionSkew },
|
|
3353
|
-
...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
|
|
3354
|
-
...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
|
|
3355
|
-
];
|
|
3356
|
-
for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
3936
|
+
for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
3357
3937
|
try {
|
|
3358
3938
|
await plugin.check(ctx);
|
|
3359
3939
|
} catch (err) {
|
|
@@ -3367,7 +3947,8 @@ async function runDoctor(options = {}) {
|
|
|
3367
3947
|
}
|
|
3368
3948
|
const findings = applyConfig(raw, config);
|
|
3369
3949
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
3370
|
-
const warnings = findings.
|
|
3950
|
+
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
3951
|
+
const infos = findings.length - errors - warnings;
|
|
3371
3952
|
return {
|
|
3372
3953
|
ok: errors === 0 && !(options.strict && warnings > 0),
|
|
3373
3954
|
root,
|
|
@@ -3376,9 +3957,33 @@ async function runDoctor(options = {}) {
|
|
|
3376
3957
|
unused: unusedComponents(ctx),
|
|
3377
3958
|
ruleCount: (patterns?.count ?? 0) + plugins.length,
|
|
3378
3959
|
errors,
|
|
3379
|
-
warnings
|
|
3960
|
+
warnings,
|
|
3961
|
+
infos
|
|
3380
3962
|
};
|
|
3381
3963
|
}
|
|
3964
|
+
function builtinChecks(config) {
|
|
3965
|
+
const packs = {
|
|
3966
|
+
native: { name: "native", check: checkNativePack },
|
|
3967
|
+
supabase: { name: "supabase", check: checkSupabasePack }
|
|
3968
|
+
};
|
|
3969
|
+
return [
|
|
3970
|
+
{ name: "layout", check: checkProjectLayout },
|
|
3971
|
+
{ name: "imports", check: checkImports },
|
|
3972
|
+
{ name: "raw-tags", check: checkRawTags },
|
|
3973
|
+
{ name: "colors", check: checkColors },
|
|
3974
|
+
{ name: "tokens", check: checkTokens },
|
|
3975
|
+
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
3976
|
+
{ name: "version-skew", check: checkVersionSkew },
|
|
3977
|
+
{ name: "duplicate-packages", check: checkDuplicatePackages },
|
|
3978
|
+
{ name: "peer-ranges", check: checkPeerRanges },
|
|
3979
|
+
{ name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
|
|
3980
|
+
{ name: "local-genesis-copies", check: checkLocalGenesisCopies },
|
|
3981
|
+
{ name: "resource-workspaces", check: checkResourceWorkspaces },
|
|
3982
|
+
{ name: "page-layouts", check: checkPageLayouts },
|
|
3983
|
+
{ name: "iso-date-slices", check: checkIsoDateSlices },
|
|
3984
|
+
...(config.packs ?? []).map((p) => packs[p])
|
|
3985
|
+
];
|
|
3986
|
+
}
|
|
3382
3987
|
function applyConfig(raw, config) {
|
|
3383
3988
|
const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
|
|
3384
3989
|
const out = [];
|
|
@@ -3425,7 +4030,8 @@ function formatReport(result) {
|
|
|
3425
4030
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
3426
4031
|
}
|
|
3427
4032
|
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
3428
|
-
|
|
4033
|
+
const info = result.infos ? `, ${result.infos} info` : "";
|
|
4034
|
+
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
3429
4035
|
return lines.join("\n");
|
|
3430
4036
|
}
|
|
3431
4037
|
function toJson(result) {
|
|
@@ -3434,6 +4040,7 @@ function toJson(result) {
|
|
|
3434
4040
|
genesis: `${result.genesis.uiPackage}@${result.genesis.uiVersion}`,
|
|
3435
4041
|
errors: result.errors,
|
|
3436
4042
|
warnings: result.warnings,
|
|
4043
|
+
infos: result.infos,
|
|
3437
4044
|
findings: result.findings,
|
|
3438
4045
|
unused: result.unused
|
|
3439
4046
|
};
|
|
@@ -3444,7 +4051,8 @@ function genesisSummary(g) {
|
|
|
3444
4051
|
components: g.components,
|
|
3445
4052
|
tokens: [...g.tokens].sort(),
|
|
3446
4053
|
rawTags: Object.fromEntries(g.rawTags),
|
|
3447
|
-
palette: g.palette
|
|
4054
|
+
palette: g.palette,
|
|
4055
|
+
companions: Object.fromEntries(g.companions.map((c) => [`${c.package}@${c.version}`, c.components]))
|
|
3448
4056
|
};
|
|
3449
4057
|
}
|
|
3450
4058
|
var init_doctor = __esm({
|
|
@@ -3460,6 +4068,9 @@ var init_doctor = __esm({
|
|
|
3460
4068
|
init_scan();
|
|
3461
4069
|
init_supabase();
|
|
3462
4070
|
init_versions();
|
|
4071
|
+
init_installs();
|
|
4072
|
+
init_structure();
|
|
4073
|
+
init_dates();
|
|
3463
4074
|
init_config();
|
|
3464
4075
|
init_genesis();
|
|
3465
4076
|
init_patterns();
|
|
@@ -3469,6 +4080,9 @@ var init_doctor = __esm({
|
|
|
3469
4080
|
init_native();
|
|
3470
4081
|
init_supabase();
|
|
3471
4082
|
init_versions();
|
|
4083
|
+
init_installs();
|
|
4084
|
+
init_semver();
|
|
4085
|
+
init_routes();
|
|
3472
4086
|
}
|
|
3473
4087
|
});
|
|
3474
4088
|
|
|
@@ -3485,29 +4099,29 @@ __export(features_exports, {
|
|
|
3485
4099
|
function isObject3(value) {
|
|
3486
4100
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3487
4101
|
}
|
|
3488
|
-
function readObject(file,
|
|
4102
|
+
function readObject(file, key2) {
|
|
3489
4103
|
try {
|
|
3490
4104
|
const json = JSON.parse(readFileSync(file, "utf-8"));
|
|
3491
|
-
return isObject3(json[
|
|
4105
|
+
return isObject3(json[key2]) ? json[key2] : {};
|
|
3492
4106
|
} catch {
|
|
3493
4107
|
return {};
|
|
3494
4108
|
}
|
|
3495
4109
|
}
|
|
3496
4110
|
function settings(root, options) {
|
|
3497
|
-
const fromPackage = readObject(
|
|
3498
|
-
const fromConfig = readObject(
|
|
4111
|
+
const fromPackage = readObject(path31.join(root, "package.json"), "genesisFeatures");
|
|
4112
|
+
const fromConfig = readObject(path31.join(root, "genesis.config.json"), "features");
|
|
3499
4113
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
3500
4114
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
3501
4115
|
}
|
|
3502
4116
|
async function loadRegistry(input) {
|
|
3503
|
-
const root =
|
|
4117
|
+
const root = path31.resolve(input.dir);
|
|
3504
4118
|
const options = settings(root, input);
|
|
3505
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
3506
|
-
if (!registry || !existsSync(
|
|
4119
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path31.join(root, p)));
|
|
4120
|
+
if (!registry || !existsSync(path31.join(root, registry))) {
|
|
3507
4121
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
3508
4122
|
}
|
|
3509
|
-
const jiti = createJiti(
|
|
3510
|
-
const load = async (file) => await jiti.import(
|
|
4123
|
+
const jiti = createJiti(path31.join(root, "package.json"), { moduleCache: false });
|
|
4124
|
+
const load = async (file) => await jiti.import(path31.join(root, file));
|
|
3511
4125
|
const mod = await load(registry);
|
|
3512
4126
|
const features2 = mod.features ?? mod.default;
|
|
3513
4127
|
if (!isObject3(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -3519,7 +4133,7 @@ async function loadRegistry(input) {
|
|
|
3519
4133
|
const project = {
|
|
3520
4134
|
...rest,
|
|
3521
4135
|
root,
|
|
3522
|
-
source: options.source ?? registry.split(
|
|
4136
|
+
source: options.source ?? registry.split(path31.sep).join("/"),
|
|
3523
4137
|
features: features2,
|
|
3524
4138
|
flags
|
|
3525
4139
|
};
|
|
@@ -3629,8 +4243,8 @@ function routeTags(source) {
|
|
|
3629
4243
|
}
|
|
3630
4244
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
3631
4245
|
const tags = routeTags(source);
|
|
3632
|
-
const
|
|
3633
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
4246
|
+
const relative6 = route.replace(/^\//, "");
|
|
4247
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative6.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
3634
4248
|
if (existing) {
|
|
3635
4249
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
3636
4250
|
}
|
|
@@ -3638,17 +4252,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
3638
4252
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
3639
4253
|
if (roots.length !== 1) {
|
|
3640
4254
|
return {
|
|
3641
|
-
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="${
|
|
4255
|
+
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="${relative6}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
3642
4256
|
};
|
|
3643
4257
|
}
|
|
3644
4258
|
const layout = roots[0];
|
|
3645
4259
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
3646
|
-
if (base && !
|
|
4260
|
+
if (base && !relative6.startsWith(`${base}/`)) {
|
|
3647
4261
|
return {
|
|
3648
4262
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
3649
4263
|
};
|
|
3650
4264
|
}
|
|
3651
|
-
const childPath = base ?
|
|
4265
|
+
const childPath = base ? relative6.slice(base.length + 1) : relative6;
|
|
3652
4266
|
const guard = GUARD.exec(source)?.[1];
|
|
3653
4267
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
3654
4268
|
const before = source.slice(0, layout.close);
|
|
@@ -4026,7 +4640,7 @@ function copyOwned(root, lock, write, dryRun = false) {
|
|
|
4026
4640
|
}
|
|
4027
4641
|
return "kept";
|
|
4028
4642
|
}
|
|
4029
|
-
function ownedKeyProblem(
|
|
4643
|
+
function ownedKeyProblem(key2, source) {
|
|
4030
4644
|
let parsed;
|
|
4031
4645
|
try {
|
|
4032
4646
|
parsed = parseSource(source);
|
|
@@ -4034,23 +4648,23 @@ function ownedKeyProblem(key, source) {
|
|
|
4034
4648
|
return err instanceof Error ? err.message : String(err);
|
|
4035
4649
|
}
|
|
4036
4650
|
const { package: pkg, path: rel } = parsed;
|
|
4037
|
-
if (!GENESIS_PACKAGE.test(pkg)) return `${
|
|
4038
|
-
if (!safeRelative(rel) || !safeRelative(
|
|
4039
|
-
if (
|
|
4651
|
+
if (!GENESIS_PACKAGE.test(pkg)) return `${key2}'s source ${pkg} isn't a Genesis package`;
|
|
4652
|
+
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
4653
|
+
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
4040
4654
|
const base = rel.split("/").pop();
|
|
4041
4655
|
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
4042
|
-
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(
|
|
4656
|
+
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
4043
4657
|
}
|
|
4044
4658
|
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
4045
|
-
if (fn) return
|
|
4046
|
-
if (/\.test\.sql$/.test(base)) return
|
|
4047
|
-
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(
|
|
4048
|
-
return `${
|
|
4659
|
+
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
4660
|
+
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
4661
|
+
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
4662
|
+
return `${key2} doesn't match its source ${source}`;
|
|
4049
4663
|
}
|
|
4050
4664
|
function mergeThreeWay(mine, base, theirs) {
|
|
4051
|
-
const dir = mkdtempSync(
|
|
4665
|
+
const dir = mkdtempSync(path31.join(tmpdir(), "genesis-merge-"));
|
|
4052
4666
|
try {
|
|
4053
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
4667
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path31.join(dir, n));
|
|
4054
4668
|
writeFileSync(m, mine);
|
|
4055
4669
|
writeFileSync(b, base);
|
|
4056
4670
|
writeFileSync(t, theirs);
|
|
@@ -4219,12 +4833,12 @@ var init_registry_edit = __esm({
|
|
|
4219
4833
|
});
|
|
4220
4834
|
function routerRoot2(root) {
|
|
4221
4835
|
try {
|
|
4222
|
-
const config = JSON.parse(readFileSync(
|
|
4836
|
+
const config = JSON.parse(readFileSync(path31.join(root, "genesis.config.json"), "utf8"));
|
|
4223
4837
|
const configured = config.doctor?.native?.routerRoot;
|
|
4224
|
-
if (configured && existsSync(
|
|
4838
|
+
if (configured && existsSync(path31.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
4225
4839
|
} catch {
|
|
4226
4840
|
}
|
|
4227
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
4841
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path31.join(root, dir, "_layout.tsx"))) return dir;
|
|
4228
4842
|
return null;
|
|
4229
4843
|
}
|
|
4230
4844
|
function routeOf(file) {
|
|
@@ -4267,7 +4881,7 @@ export default function Screen() {
|
|
|
4267
4881
|
}
|
|
4268
4882
|
`;
|
|
4269
4883
|
}
|
|
4270
|
-
var
|
|
4884
|
+
var init_routes2 = __esm({
|
|
4271
4885
|
"src/blocks/routes.ts"() {
|
|
4272
4886
|
init_files();
|
|
4273
4887
|
}
|
|
@@ -4285,23 +4899,23 @@ __export(add_exports, {
|
|
|
4285
4899
|
});
|
|
4286
4900
|
function appDependencies(root) {
|
|
4287
4901
|
try {
|
|
4288
|
-
const pkg = JSON.parse(readFileSync(
|
|
4902
|
+
const pkg = JSON.parse(readFileSync(path31.join(root, "package.json"), "utf8"));
|
|
4289
4903
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
4290
4904
|
} catch {
|
|
4291
4905
|
return {};
|
|
4292
4906
|
}
|
|
4293
4907
|
}
|
|
4294
4908
|
function registryFile(root) {
|
|
4295
|
-
const read = (file,
|
|
4909
|
+
const read = (file, key2) => {
|
|
4296
4910
|
try {
|
|
4297
|
-
const v = JSON.parse(readFileSync(
|
|
4911
|
+
const v = JSON.parse(readFileSync(path31.join(root, file), "utf8"))[key2]?.registry;
|
|
4298
4912
|
return typeof v === "string" ? v : void 0;
|
|
4299
4913
|
} catch {
|
|
4300
4914
|
return void 0;
|
|
4301
4915
|
}
|
|
4302
4916
|
};
|
|
4303
4917
|
const named = read("genesis.config.json", "features") ?? read("package.json", "genesisFeatures");
|
|
4304
|
-
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(
|
|
4918
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path31.join(root, candidate))) return candidate;
|
|
4305
4919
|
return null;
|
|
4306
4920
|
}
|
|
4307
4921
|
async function registryIds(root, file) {
|
|
@@ -4378,7 +4992,7 @@ verify_jwt = false
|
|
|
4378
4992
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
4379
4993
|
}
|
|
4380
4994
|
async function runAdd(options) {
|
|
4381
|
-
const root =
|
|
4995
|
+
const root = path31.resolve(options.root);
|
|
4382
4996
|
const log = options.log ?? SILENT;
|
|
4383
4997
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
4384
4998
|
const warnings = [];
|
|
@@ -4540,7 +5154,7 @@ var init_add = __esm({
|
|
|
4540
5154
|
init_owned();
|
|
4541
5155
|
init_pm();
|
|
4542
5156
|
init_registry_edit();
|
|
4543
|
-
|
|
5157
|
+
init_routes2();
|
|
4544
5158
|
SILENT = { info() {
|
|
4545
5159
|
}, warn() {
|
|
4546
5160
|
} };
|
|
@@ -4553,7 +5167,7 @@ __export(migrate_exports, {
|
|
|
4553
5167
|
runMigrate: () => runMigrate
|
|
4554
5168
|
});
|
|
4555
5169
|
async function runMigrate(options) {
|
|
4556
|
-
const root =
|
|
5170
|
+
const root = path31.resolve(options.root);
|
|
4557
5171
|
const lock = readLock(root);
|
|
4558
5172
|
const warnings = [];
|
|
4559
5173
|
const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks), ...options.blocks ?? []])];
|
|
@@ -4604,7 +5218,7 @@ var init_migrate = __esm({
|
|
|
4604
5218
|
});
|
|
4605
5219
|
|
|
4606
5220
|
// src/upgrade/bump-core.mjs
|
|
4607
|
-
function
|
|
5221
|
+
function compareVersions2(a, b) {
|
|
4608
5222
|
const [ca, pa = ""] = a.split(/-(.*)/s);
|
|
4609
5223
|
const [cb, pb = ""] = b.split(/-(.*)/s);
|
|
4610
5224
|
const x = ca.split(".").map(Number), y = cb.split(".").map(Number);
|
|
@@ -4626,7 +5240,7 @@ function bumpPackageJson(file, text, wanted) {
|
|
|
4626
5240
|
const changes = [], skipped = [];
|
|
4627
5241
|
for (const section of SECTIONS) {
|
|
4628
5242
|
for (const [name, spec] of Object.entries(pkg[section] ?? {})) {
|
|
4629
|
-
if (!
|
|
5243
|
+
if (!GENESIS2.test(name)) continue;
|
|
4630
5244
|
const m = EXACT.exec(spec);
|
|
4631
5245
|
if (!m) {
|
|
4632
5246
|
skipped.push({ file, name, spec, why: "not a plain version" });
|
|
@@ -4641,7 +5255,7 @@ function bumpPackageJson(file, text, wanted) {
|
|
|
4641
5255
|
skipped.push({ file, name, spec, why: `the release names ${JSON.stringify(want)}, not a version` });
|
|
4642
5256
|
continue;
|
|
4643
5257
|
}
|
|
4644
|
-
const cmp =
|
|
5258
|
+
const cmp = compareVersions2(want, m[2]);
|
|
4645
5259
|
if (cmp === 0) continue;
|
|
4646
5260
|
if (cmp < 0) {
|
|
4647
5261
|
skipped.push({ file, name, spec, why: `newer than ${want}` });
|
|
@@ -4664,11 +5278,11 @@ function bumpSummary(version, changes, skipped) {
|
|
|
4664
5278
|
...skipped.length ? ["", "Left alone:", "", ...skipped.map((s) => `- \`${s.name}\` ${s.spec} in ${s.file}: ${s.why}`)] : []
|
|
4665
5279
|
].join("\n");
|
|
4666
5280
|
}
|
|
4667
|
-
var UMBRELLA,
|
|
5281
|
+
var UMBRELLA, GENESIS2, EXACT, PLAIN, SECTIONS;
|
|
4668
5282
|
var init_bump_core = __esm({
|
|
4669
5283
|
"src/upgrade/bump-core.mjs"() {
|
|
4670
5284
|
UMBRELLA = "@marktiderman/genesis";
|
|
4671
|
-
|
|
5285
|
+
GENESIS2 = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
4672
5286
|
EXACT = /^(\^|~|=)?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/;
|
|
4673
5287
|
PLAIN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
4674
5288
|
SECTIONS = ["dependencies", "devDependencies", "optionalDependencies"];
|
|
@@ -4678,7 +5292,7 @@ var init_bump_core = __esm({
|
|
|
4678
5292
|
// src/upgrade/codemods.ts
|
|
4679
5293
|
function codemodsFor(changes, registry = CODEMODS) {
|
|
4680
5294
|
return registry.filter(
|
|
4681
|
-
(mod) => changes.some((c) => c.name === mod.package &&
|
|
5295
|
+
(mod) => changes.some((c) => c.name === mod.package && compareVersions2(bare(c.from), mod.version) < 0 && compareVersions2(bare(c.to), mod.version) >= 0)
|
|
4682
5296
|
);
|
|
4683
5297
|
}
|
|
4684
5298
|
function uncoveredBreaks(changes, registry = CODEMODS) {
|
|
@@ -4713,11 +5327,11 @@ function npmLookup(cwd) {
|
|
|
4713
5327
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
4714
5328
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
4715
5329
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
4716
|
-
const tmp = mkdtempSync(
|
|
5330
|
+
const tmp = mkdtempSync(path31.join(tmpdir(), "genesis-umbrella-"));
|
|
4717
5331
|
try {
|
|
4718
5332
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
4719
|
-
execFileSync("tar", ["-xzf",
|
|
4720
|
-
const manifest = JSON.parse(readFileSync(
|
|
5333
|
+
execFileSync("tar", ["-xzf", path31.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
5334
|
+
const manifest = JSON.parse(readFileSync(path31.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
4721
5335
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
4722
5336
|
return manifest;
|
|
4723
5337
|
} finally {
|
|
@@ -4744,7 +5358,7 @@ function packageJsons(root) {
|
|
|
4744
5358
|
if (files.length) return files;
|
|
4745
5359
|
} catch {
|
|
4746
5360
|
}
|
|
4747
|
-
return existsSync(
|
|
5361
|
+
return existsSync(path31.join(root, "package.json")) ? ["package.json"] : [];
|
|
4748
5362
|
}
|
|
4749
5363
|
function sourceText(root, source, substitutions) {
|
|
4750
5364
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -4763,11 +5377,11 @@ function sourceText(root, source, substitutions) {
|
|
|
4763
5377
|
}
|
|
4764
5378
|
}
|
|
4765
5379
|
async function runUpgrade(options) {
|
|
4766
|
-
const root =
|
|
5380
|
+
const root = path31.resolve(options.root);
|
|
4767
5381
|
const log = options.log ?? (() => {
|
|
4768
5382
|
});
|
|
4769
5383
|
const lookup = options.lookup ?? npmLookup(root);
|
|
4770
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
5384
|
+
const release = options.manifest ? JSON.parse(readFileSync(path31.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
4771
5385
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
4772
5386
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
4773
5387
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -4903,7 +5517,7 @@ function checkSubstitutions(substitutions) {
|
|
|
4903
5517
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
4904
5518
|
let allowed;
|
|
4905
5519
|
try {
|
|
4906
|
-
const was = starterIdentity(readFileSync(
|
|
5520
|
+
const was = starterIdentity(readFileSync(path31.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
4907
5521
|
allowed = [was.name, was.slug, was.scheme, was.bundleId];
|
|
4908
5522
|
} catch {
|
|
4909
5523
|
allowed = [];
|
|
@@ -4936,15 +5550,15 @@ function openPullRequest(root, version, report, base) {
|
|
|
4936
5550
|
git2("switch", "-c", branch);
|
|
4937
5551
|
const top = git2("rev-parse", "--show-toplevel");
|
|
4938
5552
|
const lockfiles = [];
|
|
4939
|
-
for (let dir =
|
|
4940
|
-
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(
|
|
4941
|
-
if (lockfiles.length || dir === top ||
|
|
5553
|
+
for (let dir = path31.resolve(root); ; dir = path31.dirname(dir)) {
|
|
5554
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path31.join(dir, f))) lockfiles.push(path31.relative(root, path31.join(dir, f)));
|
|
5555
|
+
if (lockfiles.length || dir === top || path31.dirname(dir) === dir) break;
|
|
4942
5556
|
}
|
|
4943
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
5557
|
+
const paths = [...report.files.filter((f) => existsSync(path31.join(root, f))), ...lockfiles];
|
|
4944
5558
|
git2("add", "--", ...paths);
|
|
4945
5559
|
git2("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
4946
5560
|
git2("push", "-u", "origin", branch);
|
|
4947
|
-
const body =
|
|
5561
|
+
const body = path31.join(mkdtempSync(path31.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
4948
5562
|
writeFileSync(body, `${report.summary}
|
|
4949
5563
|
|
|
4950
5564
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -5067,9 +5681,9 @@ async function runScaffold(opts, fs2) {
|
|
|
5067
5681
|
function joinPath(...parts) {
|
|
5068
5682
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
5069
5683
|
}
|
|
5070
|
-
function dirname(
|
|
5071
|
-
const idx =
|
|
5072
|
-
return idx === -1 ? "." :
|
|
5684
|
+
function dirname(path32) {
|
|
5685
|
+
const idx = path32.lastIndexOf("/");
|
|
5686
|
+
return idx === -1 ? "." : path32.slice(0, idx);
|
|
5073
5687
|
}
|
|
5074
5688
|
function brandPackageJson(consumer, genesisVersion) {
|
|
5075
5689
|
return JSON.stringify(
|
|
@@ -5308,7 +5922,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
5308
5922
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
5309
5923
|
const result2 = await runInitNative2({
|
|
5310
5924
|
name: consumer,
|
|
5311
|
-
target:
|
|
5925
|
+
target: path31.resolve(opts.target ?? consumer),
|
|
5312
5926
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
5313
5927
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
5314
5928
|
...opts.scheme ? { scheme: opts.scheme } : {}
|
|
@@ -5318,7 +5932,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
5318
5932
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
5319
5933
|
console.log("");
|
|
5320
5934
|
console.log("Next steps:");
|
|
5321
|
-
[`cd ${
|
|
5935
|
+
[`cd ${path31.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
5322
5936
|
return;
|
|
5323
5937
|
}
|
|
5324
5938
|
opts.target ??= process.cwd();
|
|
@@ -5363,9 +5977,9 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
5363
5977
|
if (schemas.length !== 1) throw new Error("--openapi reads one schema at a time; pass a single --schema.");
|
|
5364
5978
|
const headers = [...opts.header ?? []];
|
|
5365
5979
|
if (opts.apikeyEnv) {
|
|
5366
|
-
const
|
|
5367
|
-
if (!
|
|
5368
|
-
headers.push(`apikey: ${
|
|
5980
|
+
const key2 = process.env[opts.apikeyEnv];
|
|
5981
|
+
if (!key2) throw new Error(`Set ${opts.apikeyEnv} to the API key.`);
|
|
5982
|
+
headers.push(`apikey: ${key2}`, `Authorization: Bearer ${key2}`);
|
|
5369
5983
|
}
|
|
5370
5984
|
const doc = await readOpenApi(opts.openapi, headers);
|
|
5371
5985
|
tables = introspectOpenApi2(doc, schemas[0]);
|
|
@@ -5384,7 +5998,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
5384
5998
|
source = `Postgres (${schemas.join(", ")})`;
|
|
5385
5999
|
}
|
|
5386
6000
|
const content = emitContracts2(tables, { source });
|
|
5387
|
-
const target =
|
|
6001
|
+
const target = path31.resolve(opts.out);
|
|
5388
6002
|
if (opts.check) {
|
|
5389
6003
|
const current = await fs.readFile(target, "utf-8").catch(() => null);
|
|
5390
6004
|
if (current !== content) {
|
|
@@ -5399,7 +6013,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
5399
6013
|
});
|
|
5400
6014
|
program.command("doctor").description("Check this app against the installed Genesis: components, tokens, imports, colors, plus the app's own rules").option("--strict", "Fail on warnings too", false).option("--json", "Print the report as JSON", false).option("--build", "Also run the app's typecheck and build (doctor.build, or its typecheck/build scripts)", false).option("-c, --config <path>", 'Config file (default: genesis.config.json, then package.json "genesis")').option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--print-genesis", "Print the components, tokens and raw tags read from Genesis, and exit", false).action(async (opts) => {
|
|
5401
6015
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
5402
|
-
const root =
|
|
6016
|
+
const root = path31.resolve(opts.dir);
|
|
5403
6017
|
try {
|
|
5404
6018
|
if (opts.printGenesis) {
|
|
5405
6019
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -5464,24 +6078,24 @@ featureOptions(
|
|
|
5464
6078
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
5465
6079
|
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) => {
|
|
5466
6080
|
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
5467
|
-
const root =
|
|
5468
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
5469
|
-
const
|
|
6081
|
+
const root = path31.resolve(opts.dir);
|
|
6082
|
+
const packageJson = JSON.parse(await fs.readFile(path31.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
6083
|
+
const existsSync25 = (await import('fs')).existsSync;
|
|
5470
6084
|
const readSync = (await import('fs')).readFileSync;
|
|
5471
|
-
const
|
|
6085
|
+
const readdirSync10 = (await import('fs')).readdirSync;
|
|
5472
6086
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
5473
6087
|
throw new Error("--host must be next, tanstack-start or supabase-function.");
|
|
5474
6088
|
}
|
|
5475
6089
|
const plan = planStudioInit2(
|
|
5476
6090
|
{
|
|
5477
6091
|
packageJson,
|
|
5478
|
-
exists: (p) =>
|
|
5479
|
-
read: (p) =>
|
|
6092
|
+
exists: (p) => existsSync25(path31.join(root, p)),
|
|
6093
|
+
read: (p) => existsSync25(path31.join(root, p)) ? readSync(path31.join(root, p), "utf-8") : null,
|
|
5480
6094
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
5481
6095
|
listDeep: (p) => {
|
|
5482
6096
|
const out = [];
|
|
5483
6097
|
const walk2 = (rel) => {
|
|
5484
|
-
for (const entry of
|
|
6098
|
+
for (const entry of readdirSync10(path31.join(root, rel), { withFileTypes: true })) {
|
|
5485
6099
|
const child = `${rel}/${entry.name}`;
|
|
5486
6100
|
if (entry.isDirectory()) walk2(child);
|
|
5487
6101
|
else out.push(child);
|
|
@@ -5495,7 +6109,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
5495
6109
|
},
|
|
5496
6110
|
list: (p) => {
|
|
5497
6111
|
try {
|
|
5498
|
-
return
|
|
6112
|
+
return readdirSync10(path31.join(root, p));
|
|
5499
6113
|
} catch {
|
|
5500
6114
|
return [];
|
|
5501
6115
|
}
|
|
@@ -5504,8 +6118,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
5504
6118
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
5505
6119
|
);
|
|
5506
6120
|
for (const file of plan.files) {
|
|
5507
|
-
const target =
|
|
5508
|
-
await fs.mkdir(
|
|
6121
|
+
const target = path31.join(root, file.path);
|
|
6122
|
+
await fs.mkdir(path31.dirname(target), { recursive: true });
|
|
5509
6123
|
if (file.edit) {
|
|
5510
6124
|
await fs.writeFile(target, file.content, "utf-8");
|
|
5511
6125
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -5516,14 +6130,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
5516
6130
|
console.log(`+ ${file.path} (appended)`);
|
|
5517
6131
|
continue;
|
|
5518
6132
|
}
|
|
5519
|
-
if (
|
|
6133
|
+
if (existsSync25(target) && !opts.force) {
|
|
5520
6134
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
5521
6135
|
continue;
|
|
5522
6136
|
}
|
|
5523
6137
|
await fs.writeFile(target, file.content, "utf-8");
|
|
5524
6138
|
console.log(`+ ${file.path}`);
|
|
5525
6139
|
}
|
|
5526
|
-
const pm =
|
|
6140
|
+
const pm = existsSync25(path31.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync25(path31.join(root, "yarn.lock")) ? "yarn add" : existsSync25(path31.join(root, "bun.lock")) || existsSync25(path31.join(root, "bun.lockb")) ? "bun add" : "npm install";
|
|
5527
6141
|
console.log("");
|
|
5528
6142
|
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:`);
|
|
5529
6143
|
console.log(` 1. ${pm} ${plan.install.join(" ")}`);
|
|
@@ -5541,7 +6155,7 @@ async function confirm(question) {
|
|
|
5541
6155
|
}
|
|
5542
6156
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
5543
6157
|
program.command("add").description("Add a block (a feature an app adds whole) from the Genesis package that declares it: install, migrations, functions, skills, routes, registry entry").argument("[block]", "The block's id, e.g. tenant-features").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--package <name>", "The package that declares it, when two do").option("--list", "List the blocks this app can add, and exit", false).option("--dry-run", "Print the plan; write and install nothing", false).option("-y, --yes", "Don't ask before writing", false).option("--no-install", "Don't install packages (print the command instead)").option("--no-features-build", "Don't run features build after").action(async (block, opts) => {
|
|
5544
|
-
const root =
|
|
6158
|
+
const root = path31.resolve(opts.dir);
|
|
5545
6159
|
if (opts.list || !block) {
|
|
5546
6160
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
5547
6161
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -5570,7 +6184,7 @@ program.command("add").description("Add a block (a feature an app adds whole) fr
|
|
|
5570
6184
|
program.command("migrate").description("Copy new package migrations of the app's blocks in as new timestamped files; report edited or changed ones (never rewritten)").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--block <id...>", "Also check these blocks (beyond genesis.lock.json's)").option("--dry-run", "Report only", false).option("--forward", "Write a forward migration stub for each edited or changed migration", false).action(async (opts) => {
|
|
5571
6185
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
5572
6186
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
5573
|
-
const report = await runMigrate2({ root:
|
|
6187
|
+
const report = await runMigrate2({ root: path31.resolve(opts.dir), ...opts.block ? { blocks: opts.block } : {}, dryRun: opts.dryRun, forward: opts.forward });
|
|
5574
6188
|
for (const w of report.warnings) logger.warn(w);
|
|
5575
6189
|
console.log(formatMigrationRows2(report.plan.rows));
|
|
5576
6190
|
for (const c of report.plan.creates) if (c.kind !== "migration") console.log(`+ ${c.path} (${c.kind === "test" ? "pgTAP test" : "forward migration: fill it in"})`);
|
|
@@ -5585,7 +6199,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
5585
6199
|
program.command("upgrade").description("Move every @marktiderman/genesis* dependency to one Genesis release, refresh the files Genesis owns, run codemods and the doctor").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--version <v>", "The @marktiderman/genesis release: an exact version or a dist-tag", "latest").option("--manifest <file>", "Read the release from this versions.json instead of npm").option("--dry-run", "Report the bump, and owned files compared with the packages installed now; change nothing", false).option("--no-install", "Don't reinstall after the bump").option("--no-doctor", "Don't run genesis doctor after").option("--keep-mine", "Never merge an owned file you changed; write the new text to .genesis-next", false).option("--pr", "Commit to a genesis-upgrade/<version> branch, push it and open a pull request", false).action(async (opts) => {
|
|
5586
6200
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
5587
6201
|
const report = await runUpgrade2({
|
|
5588
|
-
root:
|
|
6202
|
+
root: path31.resolve(opts.dir),
|
|
5589
6203
|
version: opts.version,
|
|
5590
6204
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
5591
6205
|
dryRun: opts.dryRun,
|
|
@@ -5649,7 +6263,7 @@ function redactUrl(location) {
|
|
|
5649
6263
|
const url = new URL(location);
|
|
5650
6264
|
return `${url.origin}${url.pathname}`;
|
|
5651
6265
|
} catch {
|
|
5652
|
-
return
|
|
6266
|
+
return path31.basename(location);
|
|
5653
6267
|
}
|
|
5654
6268
|
}
|
|
5655
6269
|
//# sourceMappingURL=cli.js.map
|