@marktiderman/genesis-cli 1.9.0 → 1.10.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 +32 -5
- package/dist/cli.js +649 -256
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +30 -3
- package/dist/doctor.js +529 -143
- package/dist/doctor.js.map +1 -1
- package/dist/genesis-catalog.json +46 -15
- package/dist/index.js +532 -146
- package/dist/index.js.map +1 -1
- package/dist/vite.js +533 -147
- 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 path32 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 = path32.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;
|
|
@@ -234,14 +234,14 @@ ${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 = path32.relative(parent, child);
|
|
238
|
+
return rel === "" || !rel.startsWith("..") && !path32.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 = path32.join(root, ...safe.split("/"));
|
|
245
245
|
if (!existsSync(file)) return null;
|
|
246
246
|
const real2 = realpathSync(file);
|
|
247
247
|
if (!inside(root, real2)) throw new Error(`${rel} in ${packageDir2} points outside the package`);
|
|
@@ -252,7 +252,7 @@ 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 = path32.join(root, ...safe.split("/"));
|
|
256
256
|
if (!existsSync(dir)) return null;
|
|
257
257
|
const real2 = realpathSync(dir);
|
|
258
258
|
if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${packageDir2} is not a folder inside the package`);
|
|
@@ -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 = path32.join(realRoot, ...safe.split("/"));
|
|
276
276
|
const there = (p) => {
|
|
277
277
|
try {
|
|
278
278
|
lstatSync(p);
|
|
@@ -281,13 +281,13 @@ function appPath(root, rel) {
|
|
|
281
281
|
return false;
|
|
282
282
|
}
|
|
283
283
|
};
|
|
284
|
-
let probe =
|
|
285
|
-
while (!there(probe)) probe =
|
|
284
|
+
let probe = path32.dirname(target);
|
|
285
|
+
while (!there(probe)) probe = path32.dirname(probe);
|
|
286
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 (${path32.relative(realRoot, probe)}); refused`);
|
|
291
291
|
}
|
|
292
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`);
|
|
@@ -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(path32.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(path32.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 = path32.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(path32.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 = path32.dirname(fileURLToPath(import.meta.url));
|
|
349
349
|
for (; ; ) {
|
|
350
|
-
const file =
|
|
350
|
+
const file = path32.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 = path32.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 = path32.resolve(cliPackageDir(), "..");
|
|
359
|
+
return existsSync(path32.join(dir, "features", "package.json")) && existsSync(path32.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 = path32.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 = path32.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(path32.join(dir, m)));
|
|
374
|
+
const scope = path32.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(path32.join(scope, entry, "package.json"))) found.set(name, path32.join(scope, entry));
|
|
380
380
|
}
|
|
381
381
|
}
|
|
382
|
-
const parent =
|
|
382
|
+
const parent = path32.dirname(dir);
|
|
383
383
|
if (atInstallRoot || parent === dir) return found;
|
|
384
384
|
dir = parent;
|
|
385
385
|
}
|
|
@@ -391,10 +391,10 @@ 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(path32.join(dir, "package.json"), "utf8")).version;
|
|
395
395
|
}
|
|
396
396
|
function declarationsOf(dir, warnings) {
|
|
397
|
-
const pkg = JSON.parse(readFileSync(
|
|
397
|
+
const pkg = JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
|
|
398
398
|
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
399
399
|
let cached = declarationCache.get(key2);
|
|
400
400
|
if (!cached) {
|
|
@@ -404,15 +404,15 @@ function declarationsOf(dir, warnings) {
|
|
|
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(path32.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 && path32.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(path32.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(path32.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 = path32.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(path32.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 = path32.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);
|
|
@@ -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 ${path32.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,7 +671,7 @@ 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 test2 = `${TESTS_DIR}/${
|
|
674
|
+
const test2 = `${TESTS_DIR}/${path32.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
|
|
675
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;
|
|
@@ -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 (path32.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
735
|
+
const norm = path32.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 = path32.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 = path32.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
745
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path32.dirname(file) };
|
|
746
746
|
}
|
|
747
|
-
const own =
|
|
747
|
+
const own = path32.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 = path32.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 = path32.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`);
|
|
@@ -1023,11 +1023,11 @@ var init_config = __esm({
|
|
|
1023
1023
|
}
|
|
1024
1024
|
});
|
|
1025
1025
|
function findPackageDir(from, name) {
|
|
1026
|
-
let dir =
|
|
1026
|
+
let dir = path32.resolve(from);
|
|
1027
1027
|
for (; ; ) {
|
|
1028
|
-
const candidate =
|
|
1029
|
-
if (existsSync(
|
|
1030
|
-
const parent =
|
|
1028
|
+
const candidate = path32.join(dir, "node_modules", name);
|
|
1029
|
+
if (existsSync(path32.join(candidate, "package.json"))) return candidate;
|
|
1030
|
+
const parent = path32.dirname(dir);
|
|
1031
1031
|
if (parent === dir) return null;
|
|
1032
1032
|
dir = parent;
|
|
1033
1033
|
}
|
|
@@ -1079,7 +1079,7 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1079
1079
|
function readPackageExports(root, uiPackage) {
|
|
1080
1080
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1081
1081
|
if (!uiDir) return null;
|
|
1082
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1082
|
+
const uiPkg = JSON.parse(readFileSync(path32.join(uiDir, "package.json"), "utf8"));
|
|
1083
1083
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
1084
1084
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1085
1085
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
@@ -1091,7 +1091,7 @@ function readPackageExports(root, uiPackage) {
|
|
|
1091
1091
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1092
1092
|
let readAny = false;
|
|
1093
1093
|
for (const entry of typeEntries) {
|
|
1094
|
-
const file =
|
|
1094
|
+
const file = path32.join(uiDir, entry);
|
|
1095
1095
|
if (!existsSync(file)) continue;
|
|
1096
1096
|
readAny = true;
|
|
1097
1097
|
const dts = readFileSync(file, "utf8");
|
|
@@ -1105,11 +1105,11 @@ function readPackageExports(root, uiPackage) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1107
1107
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1108
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1108
|
+
const declRoot = typeof mainTypes === "string" ? path32.dirname(path32.join(uiDir, mainTypes)) : uiDir;
|
|
1109
1109
|
const declFiles = walkDts(declRoot);
|
|
1110
1110
|
for (const pkg of reexportedPackages) {
|
|
1111
1111
|
const dir = findPackageDir(uiDir, pkg);
|
|
1112
|
-
if (dir) walkDts(
|
|
1112
|
+
if (dir) walkDts(path32.join(dir, "dist"), declFiles);
|
|
1113
1113
|
}
|
|
1114
1114
|
for (const file of declFiles) {
|
|
1115
1115
|
const text = readFileSync(file, "utf8");
|
|
@@ -1155,7 +1155,7 @@ function walkDts(dir, out = []) {
|
|
|
1155
1155
|
if (!existsSync(dir)) return out;
|
|
1156
1156
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1157
1157
|
if (entry.name === "node_modules") continue;
|
|
1158
|
-
const p =
|
|
1158
|
+
const p = path32.join(dir, entry.name);
|
|
1159
1159
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1160
1160
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1161
1161
|
}
|
|
@@ -1172,27 +1172,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
const files = [];
|
|
1174
1174
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1175
|
-
const themes = ds &&
|
|
1175
|
+
const themes = ds && path32.join(ds, "dist", "themes");
|
|
1176
1176
|
if (themes && existsSync(themes)) {
|
|
1177
|
-
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(path32.join(themes, name));
|
|
1178
1178
|
}
|
|
1179
1179
|
if (files.length === 0) {
|
|
1180
1180
|
throw new DoctorConfigError(
|
|
1181
1181
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1182
1182
|
);
|
|
1183
1183
|
}
|
|
1184
|
-
const uiStyles =
|
|
1184
|
+
const uiStyles = path32.join(uiDir, "dist", "styles.css");
|
|
1185
1185
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1186
1186
|
return files;
|
|
1187
1187
|
}
|
|
1188
1188
|
function resolveSpec(root, spec) {
|
|
1189
|
-
const local =
|
|
1190
|
-
if (spec.startsWith(".") ||
|
|
1189
|
+
const local = path32.resolve(root, spec);
|
|
1190
|
+
if (spec.startsWith(".") || path32.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1191
1191
|
const parts = spec.split("/");
|
|
1192
1192
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1193
1193
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1194
1194
|
if (dir) {
|
|
1195
|
-
const file =
|
|
1195
|
+
const file = path32.join(dir, ...parts.slice(nameLength));
|
|
1196
1196
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1197
1197
|
}
|
|
1198
1198
|
return existsSync(local) ? local : null;
|
|
@@ -1200,7 +1200,7 @@ function resolveSpec(root, spec) {
|
|
|
1200
1200
|
function loadPalette(root) {
|
|
1201
1201
|
const names = new Set(TAILWIND_PALETTE);
|
|
1202
1202
|
try {
|
|
1203
|
-
const req = createRequire(
|
|
1203
|
+
const req = createRequire(path32.join(root, "package.json"));
|
|
1204
1204
|
const colors = req("tailwindcss/colors");
|
|
1205
1205
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1206
1206
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -1254,7 +1254,7 @@ var init_genesis = __esm({
|
|
|
1254
1254
|
});
|
|
1255
1255
|
function readReleaseManifest(root) {
|
|
1256
1256
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
1257
|
-
const file = dir &&
|
|
1257
|
+
const file = dir && path32.join(dir, "dist", "versions.json");
|
|
1258
1258
|
if (!file || !existsSync(file)) return null;
|
|
1259
1259
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
1260
1260
|
}
|
|
@@ -1264,7 +1264,7 @@ function checkVersionSkew(ctx) {
|
|
|
1264
1264
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
1265
1265
|
const dir = findPackageDir(ctx.root, name);
|
|
1266
1266
|
if (!dir) continue;
|
|
1267
|
-
const have = JSON.parse(readFileSync(
|
|
1267
|
+
const have = JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8")).version;
|
|
1268
1268
|
if (have === want) continue;
|
|
1269
1269
|
ctx.report({
|
|
1270
1270
|
rule: "version-skew",
|
|
@@ -1283,13 +1283,13 @@ var init_versions = __esm({
|
|
|
1283
1283
|
}
|
|
1284
1284
|
});
|
|
1285
1285
|
function detectPackageManager(root) {
|
|
1286
|
-
let dir =
|
|
1286
|
+
let dir = path32.resolve(root);
|
|
1287
1287
|
for (; ; ) {
|
|
1288
|
-
if (existsSync(
|
|
1289
|
-
if (existsSync(
|
|
1290
|
-
if (existsSync(
|
|
1291
|
-
if (existsSync(
|
|
1292
|
-
const parent =
|
|
1288
|
+
if (existsSync(path32.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1289
|
+
if (existsSync(path32.join(dir, "bun.lock")) || existsSync(path32.join(dir, "bun.lockb"))) return "bun";
|
|
1290
|
+
if (existsSync(path32.join(dir, "yarn.lock"))) return "yarn";
|
|
1291
|
+
if (existsSync(path32.join(dir, "package-lock.json"))) return "npm";
|
|
1292
|
+
const parent = path32.dirname(dir);
|
|
1293
1293
|
if (parent === dir) return "npm";
|
|
1294
1294
|
dir = parent;
|
|
1295
1295
|
}
|
|
@@ -1325,10 +1325,10 @@ var init_pm = __esm({
|
|
|
1325
1325
|
function walk(dir, exclude = []) {
|
|
1326
1326
|
const out = [];
|
|
1327
1327
|
const visit = (rel) => {
|
|
1328
|
-
for (const name of readdirSync(
|
|
1328
|
+
for (const name of readdirSync(path32.join(dir, rel)).sort()) {
|
|
1329
1329
|
const child = rel ? `${rel}/${name}` : name;
|
|
1330
1330
|
if (exclude.some((r) => r.test(child))) continue;
|
|
1331
|
-
const stat = statSync(
|
|
1331
|
+
const stat = statSync(path32.join(dir, child));
|
|
1332
1332
|
if (stat.isDirectory()) visit(child);
|
|
1333
1333
|
else if (stat.isFile()) out.push(child);
|
|
1334
1334
|
}
|
|
@@ -1357,17 +1357,17 @@ var init_walk = __esm({
|
|
|
1357
1357
|
});
|
|
1358
1358
|
function starterDir() {
|
|
1359
1359
|
const workspace = workspacePackagesDir();
|
|
1360
|
-
const live = workspace &&
|
|
1361
|
-
if (live && existsSync(
|
|
1362
|
-
const packaged =
|
|
1363
|
-
if (existsSync(
|
|
1360
|
+
const live = workspace && path32.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
1361
|
+
if (live && existsSync(path32.join(live, "package.json"))) return live;
|
|
1362
|
+
const packaged = path32.join(cliPackageDir(), "dist", "starter");
|
|
1363
|
+
if (existsSync(path32.join(packaged, "package.json"))) return packaged;
|
|
1364
1364
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
1365
1365
|
}
|
|
1366
1366
|
function templatesDir(cliDir = cliPackageDir()) {
|
|
1367
1367
|
const workspace = workspacePackagesDir();
|
|
1368
|
-
const live = workspace && cliDir === cliPackageDir() ?
|
|
1369
|
-
if (live && existsSync(
|
|
1370
|
-
const packaged =
|
|
1368
|
+
const live = workspace && cliDir === cliPackageDir() ? path32.join(workspace, "..", "templates") : null;
|
|
1369
|
+
if (live && existsSync(path32.join(live, "eas"))) return live;
|
|
1370
|
+
const packaged = path32.join(cliDir, "dist", "templates");
|
|
1371
1371
|
if (existsSync(packaged)) return packaged;
|
|
1372
1372
|
throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
|
|
1373
1373
|
}
|
|
@@ -1448,10 +1448,10 @@ function initNative(options) {
|
|
|
1448
1448
|
if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
|
|
1449
1449
|
if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
|
|
1450
1450
|
if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
|
|
1451
|
-
const target =
|
|
1451
|
+
const target = path32.resolve(options.target);
|
|
1452
1452
|
if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
|
|
1453
1453
|
const source = starterDir();
|
|
1454
|
-
const read = (rel) => readFileSync(
|
|
1454
|
+
const read = (rel) => readFileSync(path32.join(source, rel), "utf8");
|
|
1455
1455
|
const was = starterIdentity(read("starter.config.ts"));
|
|
1456
1456
|
const substitutions = { [was.bundleId]: bundleId, [was.slug]: slug, [was.scheme]: scheme, [was.name]: display };
|
|
1457
1457
|
const files = /* @__PURE__ */ new Map();
|
|
@@ -1482,14 +1482,14 @@ function initNative(options) {
|
|
|
1482
1482
|
files.set("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
1483
1483
|
`);
|
|
1484
1484
|
files.set("metro.config.js", METRO);
|
|
1485
|
-
const pnpmSettings = [
|
|
1485
|
+
const pnpmSettings = [path32.join(source, "pnpm-workspace.yaml"), path32.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
|
|
1486
1486
|
if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
|
|
1487
1487
|
files.set("README.md", readme(display, slug));
|
|
1488
1488
|
const lock = { ...emptyLock(), substitutions };
|
|
1489
1489
|
const cliVersion2 = pinnedVersion(target, CLI_PACKAGE)?.version;
|
|
1490
1490
|
const templates = templatesDir();
|
|
1491
1491
|
for (const rel of walk(templates)) {
|
|
1492
|
-
const text = substitute(readFileSync(
|
|
1492
|
+
const text = substitute(readFileSync(path32.join(templates, rel), "utf8"), substitutions);
|
|
1493
1493
|
const to = templateTarget(rel, text);
|
|
1494
1494
|
files.set(to, text);
|
|
1495
1495
|
lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
|
|
@@ -1500,13 +1500,13 @@ function initNative(options) {
|
|
|
1500
1500
|
const blocks = [];
|
|
1501
1501
|
for (const block of options.blocks) {
|
|
1502
1502
|
const stems = block.migrations.map((m) => stemOf(m.file));
|
|
1503
|
-
const copies = stems.map((s) => migrations.find((f) =>
|
|
1503
|
+
const copies = stems.map((s) => migrations.find((f) => path32.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
|
|
1504
1504
|
if (!stems.length || copies.some((c) => !c)) continue;
|
|
1505
1505
|
blocks.push(block.id);
|
|
1506
1506
|
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
1507
1507
|
block.migrations.forEach((m) => {
|
|
1508
1508
|
if (m.test) {
|
|
1509
|
-
const test2 = `${TESTS_DIR}/${
|
|
1509
|
+
const test2 = `${TESTS_DIR}/${path32.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
|
|
1510
1510
|
if (files.has(test2)) lock.files[test2] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test2)) };
|
|
1511
1511
|
}
|
|
1512
1512
|
});
|
|
@@ -1519,8 +1519,8 @@ function initNative(options) {
|
|
|
1519
1519
|
}
|
|
1520
1520
|
mkdirSync(target, { recursive: true });
|
|
1521
1521
|
for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1522
|
-
const file =
|
|
1523
|
-
mkdirSync(
|
|
1522
|
+
const file = path32.join(target, ...rel.split("/"));
|
|
1523
|
+
mkdirSync(path32.dirname(file), { recursive: true });
|
|
1524
1524
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
1525
1525
|
}
|
|
1526
1526
|
writeLock(target, lock);
|
|
@@ -1874,19 +1874,19 @@ var init_introspect = __esm({
|
|
|
1874
1874
|
});
|
|
1875
1875
|
function buildCommands(root, config) {
|
|
1876
1876
|
if (config.build) return config.build;
|
|
1877
|
-
const pkgFile =
|
|
1877
|
+
const pkgFile = path32.join(root, "package.json");
|
|
1878
1878
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
1879
1879
|
const pm = packageManager(root);
|
|
1880
1880
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
1881
1881
|
}
|
|
1882
1882
|
function packageManager(root) {
|
|
1883
|
-
let dir =
|
|
1883
|
+
let dir = path32.resolve(root);
|
|
1884
1884
|
for (; ; ) {
|
|
1885
|
-
if (existsSync(
|
|
1886
|
-
if (existsSync(
|
|
1887
|
-
if (existsSync(
|
|
1888
|
-
if (existsSync(
|
|
1889
|
-
const parent =
|
|
1885
|
+
if (existsSync(path32.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1886
|
+
if (existsSync(path32.join(dir, "bun.lock")) || existsSync(path32.join(dir, "bun.lockb"))) return "bun";
|
|
1887
|
+
if (existsSync(path32.join(dir, "yarn.lock"))) return "yarn";
|
|
1888
|
+
if (existsSync(path32.join(dir, "package-lock.json"))) return "npm";
|
|
1889
|
+
const parent = path32.dirname(dir);
|
|
1890
1890
|
if (parent === dir) return "npm";
|
|
1891
1891
|
dir = parent;
|
|
1892
1892
|
}
|
|
@@ -1943,7 +1943,7 @@ function globToRegExp(glob) {
|
|
|
1943
1943
|
}
|
|
1944
1944
|
function globMatcher(globs) {
|
|
1945
1945
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1946
|
-
return (
|
|
1946
|
+
return (path33) => res.some((re) => re.test(path33));
|
|
1947
1947
|
}
|
|
1948
1948
|
var init_glob = __esm({
|
|
1949
1949
|
"src/doctor/glob.ts"() {
|
|
@@ -2120,9 +2120,9 @@ function scanFiles(root, config) {
|
|
|
2120
2120
|
const files = [];
|
|
2121
2121
|
const seen = /* @__PURE__ */ new Set();
|
|
2122
2122
|
const visit = (abs) => {
|
|
2123
|
-
const rel = toPosix(
|
|
2123
|
+
const rel = toPosix(path32.relative(root, abs));
|
|
2124
2124
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2125
|
-
const ext =
|
|
2125
|
+
const ext = path32.extname(abs);
|
|
2126
2126
|
if (!extensions.has(ext)) return;
|
|
2127
2127
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2128
2128
|
seen.add(rel);
|
|
@@ -2132,14 +2132,14 @@ function scanFiles(root, config) {
|
|
|
2132
2132
|
const walk2 = (dir) => {
|
|
2133
2133
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2134
2134
|
if (entry.isDirectory()) {
|
|
2135
|
-
if (!SKIP_DIRS.has(entry.name)) walk2(
|
|
2135
|
+
if (!SKIP_DIRS.has(entry.name)) walk2(path32.join(dir, entry.name));
|
|
2136
2136
|
} else if (entry.isFile()) {
|
|
2137
|
-
visit(
|
|
2137
|
+
visit(path32.join(dir, entry.name));
|
|
2138
2138
|
}
|
|
2139
2139
|
}
|
|
2140
2140
|
};
|
|
2141
2141
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2142
|
-
const abs =
|
|
2142
|
+
const abs = path32.resolve(root, src);
|
|
2143
2143
|
if (!existsSync(abs)) continue;
|
|
2144
2144
|
if (statSync(abs).isDirectory()) walk2(abs);
|
|
2145
2145
|
else visit(abs);
|
|
@@ -2170,7 +2170,7 @@ var init_scan = __esm({
|
|
|
2170
2170
|
];
|
|
2171
2171
|
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2172
2172
|
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2173
|
-
toPosix = (p) => p.split(
|
|
2173
|
+
toPosix = (p) => p.split(path32.sep).join("/");
|
|
2174
2174
|
}
|
|
2175
2175
|
});
|
|
2176
2176
|
function parseRulesMarkdown(markdown) {
|
|
@@ -2236,7 +2236,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
2236
2236
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2237
2237
|
let all = compiled;
|
|
2238
2238
|
if (rulesDoc) {
|
|
2239
|
-
const file =
|
|
2239
|
+
const file = path32.resolve(root, rulesDoc);
|
|
2240
2240
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2241
2241
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2242
2242
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -2302,14 +2302,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
2302
2302
|
}
|
|
2303
2303
|
function resolvePlugin(id, configDir) {
|
|
2304
2304
|
try {
|
|
2305
|
-
if (id.startsWith(".") ||
|
|
2305
|
+
if (id.startsWith(".") || path32.isAbsolute(id)) return resolveFrom(path32.resolve(configDir, id), configDir);
|
|
2306
2306
|
return resolveFrom(id, configDir);
|
|
2307
2307
|
} catch {
|
|
2308
2308
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2309
2309
|
}
|
|
2310
2310
|
}
|
|
2311
2311
|
function resolveFrom(id, from) {
|
|
2312
|
-
return createRequire(
|
|
2312
|
+
return createRequire(path32.join(from, "noop.js")).resolve(id);
|
|
2313
2313
|
}
|
|
2314
2314
|
var init_plugins = __esm({
|
|
2315
2315
|
"src/doctor/plugins.ts"() {
|
|
@@ -2327,7 +2327,7 @@ function importSpecifiers(file) {
|
|
|
2327
2327
|
}
|
|
2328
2328
|
function checkProjectLayout(ctx) {
|
|
2329
2329
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2330
|
-
if (existsSync(
|
|
2330
|
+
if (existsSync(path32.join(ctx.root, dir))) {
|
|
2331
2331
|
ctx.report({
|
|
2332
2332
|
rule: "local-primitives",
|
|
2333
2333
|
file: dir,
|
|
@@ -2337,7 +2337,7 @@ function checkProjectLayout(ctx) {
|
|
|
2337
2337
|
}
|
|
2338
2338
|
}
|
|
2339
2339
|
for (const file of STARTER_LEFTOVERS) {
|
|
2340
|
-
if (existsSync(
|
|
2340
|
+
if (existsSync(path32.join(ctx.root, file))) {
|
|
2341
2341
|
ctx.report({
|
|
2342
2342
|
rule: "starter-leftover",
|
|
2343
2343
|
level: "warn",
|
|
@@ -2424,7 +2424,7 @@ function checkTokens(ctx) {
|
|
|
2424
2424
|
}
|
|
2425
2425
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2426
2426
|
if (/[*?]/.test(pattern)) continue;
|
|
2427
|
-
const abs =
|
|
2427
|
+
const abs = path32.join(ctx.root, pattern);
|
|
2428
2428
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2429
2429
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2430
2430
|
}
|
|
@@ -2591,10 +2591,10 @@ function localImports(root, file) {
|
|
|
2591
2591
|
const out = [];
|
|
2592
2592
|
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
2593
2593
|
const spec = m[1];
|
|
2594
|
-
const bases = spec.startsWith(".") ? [
|
|
2594
|
+
const bases = spec.startsWith(".") ? [path32.resolve(path32.dirname(file.absolutePath), spec)] : [path32.join(root, spec.slice(2)), path32.join(root, "src", spec.slice(2))];
|
|
2595
2595
|
for (const base of bases) {
|
|
2596
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2597
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2596
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path32.join(base, `index${e}`))].find(
|
|
2597
|
+
(p) => SCRIPT_EXTS2.has(path32.extname(p)) && existsSync(p)
|
|
2598
2598
|
);
|
|
2599
2599
|
if (hit) {
|
|
2600
2600
|
out.push(hit);
|
|
@@ -2611,14 +2611,6 @@ function readSource(abs) {
|
|
|
2611
2611
|
return null;
|
|
2612
2612
|
}
|
|
2613
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
2614
|
function tagEnd(code, start) {
|
|
2623
2615
|
let depth = 0;
|
|
2624
2616
|
let quote2 = null;
|
|
@@ -2765,7 +2757,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2765
2757
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2766
2758
|
const code = file.code;
|
|
2767
2759
|
const hidden = HIDES_HEADER.exec(code);
|
|
2768
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2760
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path32.posix.dirname(file.path), file.path);
|
|
2769
2761
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2770
2762
|
if (hidden && own) {
|
|
2771
2763
|
reported.add(file.path);
|
|
@@ -2793,7 +2785,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2793
2785
|
}
|
|
2794
2786
|
for (const file of ctx.files) {
|
|
2795
2787
|
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(
|
|
2788
|
+
const layout = hidingLayouts.get(path32.posix.dirname(file.path));
|
|
2797
2789
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2798
2790
|
if (!layout || !own) continue;
|
|
2799
2791
|
ctx.report({
|
|
@@ -2808,13 +2800,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2808
2800
|
}
|
|
2809
2801
|
function routerRoot(ctx) {
|
|
2810
2802
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2811
|
-
return existsSync(
|
|
2803
|
+
return existsSync(path32.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2812
2804
|
}
|
|
2813
2805
|
function checkScreenLayouts(ctx, pkg) {
|
|
2814
2806
|
const layouts = nativeLayouts(pkg);
|
|
2815
2807
|
if (layouts.length === 0) return;
|
|
2816
2808
|
const rootDir = routerRoot(ctx);
|
|
2817
|
-
if (!existsSync(
|
|
2809
|
+
if (!existsSync(path32.join(ctx.root, rootDir))) {
|
|
2818
2810
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2819
2811
|
return;
|
|
2820
2812
|
}
|
|
@@ -2828,15 +2820,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2828
2820
|
});
|
|
2829
2821
|
return;
|
|
2830
2822
|
}
|
|
2831
|
-
const
|
|
2823
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
2832
2824
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2833
2825
|
for (const file of routes) {
|
|
2834
2826
|
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2835
2827
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
2836
|
-
if (
|
|
2828
|
+
if (renders2.test(file.code)) continue;
|
|
2837
2829
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
2838
2830
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
2839
|
-
return target !== null &&
|
|
2831
|
+
return target !== null && renders2.test(target.code);
|
|
2840
2832
|
});
|
|
2841
2833
|
if (viaImport) continue;
|
|
2842
2834
|
ctx.report({
|
|
@@ -2850,7 +2842,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2850
2842
|
function readExpoConfigs(root) {
|
|
2851
2843
|
const out = [];
|
|
2852
2844
|
for (const name of EXPO_CONFIGS) {
|
|
2853
|
-
const abs =
|
|
2845
|
+
const abs = path32.join(root, name);
|
|
2854
2846
|
if (!existsSync(abs)) continue;
|
|
2855
2847
|
const text = readFileSync(abs, "utf8");
|
|
2856
2848
|
let json = null;
|
|
@@ -2884,13 +2876,13 @@ function pluginOptions(json, module) {
|
|
|
2884
2876
|
return null;
|
|
2885
2877
|
}
|
|
2886
2878
|
function dependencies(root) {
|
|
2887
|
-
const file =
|
|
2879
|
+
const file = path32.join(root, "package.json");
|
|
2888
2880
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2889
2881
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2890
2882
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2891
2883
|
}
|
|
2892
2884
|
function runtimeDependencies(root) {
|
|
2893
|
-
const file =
|
|
2885
|
+
const file = path32.join(root, "package.json");
|
|
2894
2886
|
if (!existsSync(file)) return {};
|
|
2895
2887
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2896
2888
|
}
|
|
@@ -3175,9 +3167,9 @@ function gitView(root, dir, base) {
|
|
|
3175
3167
|
function checkSupabasePack(ctx) {
|
|
3176
3168
|
const settings2 = ctx.config.supabase ?? {};
|
|
3177
3169
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
3178
|
-
const abs =
|
|
3170
|
+
const abs = path32.join(ctx.root, dir);
|
|
3179
3171
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
3180
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
3172
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path32.join(abs, n), "utf8")) }));
|
|
3181
3173
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
3182
3174
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
3183
3175
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -3194,7 +3186,7 @@ function checkSupabasePack(ctx) {
|
|
|
3194
3186
|
}
|
|
3195
3187
|
}
|
|
3196
3188
|
const since = settings2.since;
|
|
3197
|
-
const afterSince = (file) => since === void 0 ||
|
|
3189
|
+
const afterSince = (file) => since === void 0 || path32.posix.basename(file) >= since;
|
|
3198
3190
|
if ("reason" in view && since === void 0) {
|
|
3199
3191
|
ctx.report({
|
|
3200
3192
|
rule: "migration-grants",
|
|
@@ -3549,10 +3541,10 @@ function packagesIn(nodeModules) {
|
|
|
3549
3541
|
const out = [];
|
|
3550
3542
|
for (const entry of readdirSync(nodeModules)) {
|
|
3551
3543
|
if (entry.startsWith(".")) continue;
|
|
3552
|
-
const p =
|
|
3544
|
+
const p = path32.join(nodeModules, entry);
|
|
3553
3545
|
if (entry.startsWith("@")) {
|
|
3554
3546
|
try {
|
|
3555
|
-
for (const sub of readdirSync(p)) out.push(
|
|
3547
|
+
for (const sub of readdirSync(p)) out.push(path32.join(p, sub));
|
|
3556
3548
|
} catch {
|
|
3557
3549
|
}
|
|
3558
3550
|
} else {
|
|
@@ -3564,44 +3556,68 @@ function packagesIn(nodeModules) {
|
|
|
3564
3556
|
function genesisInstalls(root) {
|
|
3565
3557
|
const copies = /* @__PURE__ */ new Map();
|
|
3566
3558
|
const realRoot = real(root);
|
|
3567
|
-
const rel = (abs) =>
|
|
3568
|
-
const
|
|
3559
|
+
const rel = (abs) => path32.relative(realRoot, abs).split(path32.sep).join("/") || ".";
|
|
3560
|
+
const via = /* @__PURE__ */ new Map();
|
|
3561
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
3569
3562
|
let copy = copies.get(real2);
|
|
3570
3563
|
if (!copy) {
|
|
3571
|
-
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
|
|
3564
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
3572
3565
|
copies.set(real2, copy);
|
|
3566
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
3573
3567
|
}
|
|
3568
|
+
via.get(real2).add(root2);
|
|
3574
3569
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
3575
3570
|
};
|
|
3576
|
-
const
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
const
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3571
|
+
const walk2 = (kind, roots) => {
|
|
3572
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
3573
|
+
const queue = [];
|
|
3574
|
+
const visit = (dir, by, range) => {
|
|
3575
|
+
const manifest = readManifest(dir);
|
|
3576
|
+
if (!manifest?.name) return;
|
|
3577
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
3578
|
+
const realDir = real(dir);
|
|
3579
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
3580
|
+
if (expanded.has(realDir)) return;
|
|
3581
|
+
expanded.add(realDir);
|
|
3582
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
3583
|
+
};
|
|
3584
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
3585
|
+
while (queue.length) {
|
|
3586
|
+
const { real: from, manifest, label } = queue.shift();
|
|
3587
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
3588
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
3589
|
+
const dir = findPackageDir(from, name);
|
|
3590
|
+
if (dir) visit(dir, label, range);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3586
3593
|
};
|
|
3587
|
-
const
|
|
3588
|
-
const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
3589
|
-
for (const name of Object.keys(appDeps)) {
|
|
3594
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
3590
3595
|
const dir = findPackageDir(root, name);
|
|
3591
|
-
|
|
3592
|
-
}
|
|
3593
|
-
const
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3596
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
3597
|
+
});
|
|
3598
|
+
const app = readManifest(root);
|
|
3599
|
+
let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
3600
|
+
let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
|
|
3601
|
+
if (Object.keys(runtimeDeps).length === 0) {
|
|
3602
|
+
runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
|
|
3603
|
+
devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
|
|
3604
|
+
}
|
|
3605
|
+
walk2("runtime", rootsOf(runtimeDeps, "the app"));
|
|
3606
|
+
const top = path32.join(root, "node_modules");
|
|
3607
|
+
walk2(
|
|
3608
|
+
"hoisted",
|
|
3609
|
+
packagesIn(top).filter((dir) => {
|
|
3610
|
+
const name = path32.relative(top, dir).split(path32.sep).join("/");
|
|
3611
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
3612
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
3613
|
+
);
|
|
3614
|
+
const devRoots = { ...devDeps };
|
|
3615
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
3616
|
+
walk2("dev", rootsOf(devRoots, "the app (dev)"));
|
|
3617
|
+
for (const [key2, copy] of copies) {
|
|
3618
|
+
const kinds = via.get(key2);
|
|
3619
|
+
copy.runtime = kinds.has("runtime");
|
|
3620
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
3605
3621
|
}
|
|
3606
3622
|
const byName = /* @__PURE__ */ new Map();
|
|
3607
3623
|
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
@@ -3609,20 +3625,31 @@ function genesisInstalls(root) {
|
|
|
3609
3625
|
return byName;
|
|
3610
3626
|
}
|
|
3611
3627
|
function checkDuplicatePackages(ctx) {
|
|
3628
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
3612
3629
|
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
3613
3630
|
if (copies.length < 2) continue;
|
|
3614
|
-
const
|
|
3631
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
3632
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
3633
|
+
ctx.report({
|
|
3634
|
+
rule: "duplicate-genesis-package",
|
|
3635
|
+
level: "warn",
|
|
3636
|
+
file: "package.json",
|
|
3637
|
+
subject: name,
|
|
3638
|
+
message: `${name} is installed ${copies.length} times: ${copies.map((c) => `${describe(c)}${c.devOnly ? " [dev only]" : ""}`).join(", ")}. 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`
|
|
3639
|
+
});
|
|
3640
|
+
continue;
|
|
3641
|
+
}
|
|
3615
3642
|
ctx.report({
|
|
3616
3643
|
rule: "duplicate-genesis-package",
|
|
3617
|
-
level: "
|
|
3644
|
+
level: "info",
|
|
3618
3645
|
file: "package.json",
|
|
3619
3646
|
subject: name,
|
|
3620
|
-
message: `${name}
|
|
3647
|
+
message: `${name} has dev-only copies beside the one the app loads: ${copies.filter((c) => c.devOnly).map(describe).join(", ")}. They run in tooling, not the app, so they can't split its contexts; upgrade the tool to drop them`
|
|
3621
3648
|
});
|
|
3622
3649
|
}
|
|
3623
3650
|
}
|
|
3624
3651
|
function checkPeerRanges(ctx) {
|
|
3625
|
-
const rel = (abs) =>
|
|
3652
|
+
const rel = (abs) => path32.relative(ctx.root, abs).split(path32.sep).join("/");
|
|
3626
3653
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
3627
3654
|
for (const copy of copies) {
|
|
3628
3655
|
const dir = copy.absolutePath;
|
|
@@ -3635,7 +3662,8 @@ function checkPeerRanges(ctx) {
|
|
|
3635
3662
|
if (satisfies(installed, range) !== false) continue;
|
|
3636
3663
|
ctx.report({
|
|
3637
3664
|
rule: "peer-range-mismatch",
|
|
3638
|
-
|
|
3665
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
3666
|
+
level: copy.devOnly ? "info" : "warn",
|
|
3639
3667
|
file: "package.json",
|
|
3640
3668
|
subject: `${copy.name}>${peer}`,
|
|
3641
3669
|
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}`
|
|
@@ -3644,15 +3672,16 @@ function checkPeerRanges(ctx) {
|
|
|
3644
3672
|
}
|
|
3645
3673
|
}
|
|
3646
3674
|
}
|
|
3647
|
-
var GENESIS, readManifest, real;
|
|
3675
|
+
var GENESIS, DEV_TOOLS, readManifest, real;
|
|
3648
3676
|
var init_installs = __esm({
|
|
3649
3677
|
"src/doctor/installs.ts"() {
|
|
3650
3678
|
init_genesis();
|
|
3651
3679
|
init_semver();
|
|
3652
3680
|
GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
3681
|
+
DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
3653
3682
|
readManifest = (dir) => {
|
|
3654
3683
|
try {
|
|
3655
|
-
return JSON.parse(readFileSync(
|
|
3684
|
+
return JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
|
|
3656
3685
|
} catch {
|
|
3657
3686
|
return null;
|
|
3658
3687
|
}
|
|
@@ -3666,68 +3695,430 @@ var init_installs = __esm({
|
|
|
3666
3695
|
};
|
|
3667
3696
|
}
|
|
3668
3697
|
});
|
|
3698
|
+
function stripForImports(code) {
|
|
3699
|
+
const out = [];
|
|
3700
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
3701
|
+
const n = code.length;
|
|
3702
|
+
const templates = [];
|
|
3703
|
+
let depth = 0;
|
|
3704
|
+
let i = 0;
|
|
3705
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
3706
|
+
const opensString = () => {
|
|
3707
|
+
const before = out.slice(-12).join("");
|
|
3708
|
+
if (!/[\w$]$/.test(before)) return true;
|
|
3709
|
+
return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
|
|
3710
|
+
};
|
|
3711
|
+
const templateBody = () => {
|
|
3712
|
+
while (i < n) {
|
|
3713
|
+
const ch = code[i];
|
|
3714
|
+
if (ch === "\\") {
|
|
3715
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
3716
|
+
i += 2;
|
|
3717
|
+
} else if (ch === "`") {
|
|
3718
|
+
out.push("`");
|
|
3719
|
+
i++;
|
|
3720
|
+
return;
|
|
3721
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
3722
|
+
out.push("${");
|
|
3723
|
+
i += 2;
|
|
3724
|
+
templates.push(depth);
|
|
3725
|
+
depth++;
|
|
3726
|
+
return;
|
|
3727
|
+
} else {
|
|
3728
|
+
out.push(blank(ch));
|
|
3729
|
+
i++;
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
};
|
|
3733
|
+
while (i < n) {
|
|
3734
|
+
const ch = code[i];
|
|
3735
|
+
const next = code[i + 1];
|
|
3736
|
+
if (ch === "/" && next === "/") {
|
|
3737
|
+
while (i < n && code[i] !== "\n") {
|
|
3738
|
+
out.push(" ");
|
|
3739
|
+
i++;
|
|
3740
|
+
}
|
|
3741
|
+
} else if (ch === "/" && next === "*") {
|
|
3742
|
+
out.push(" ");
|
|
3743
|
+
i += 2;
|
|
3744
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
3745
|
+
out.push(blank(code[i]));
|
|
3746
|
+
i++;
|
|
3747
|
+
}
|
|
3748
|
+
if (i < n) {
|
|
3749
|
+
out.push(" ");
|
|
3750
|
+
i += 2;
|
|
3751
|
+
}
|
|
3752
|
+
} else if ((ch === '"' || ch === "'") && opensString()) {
|
|
3753
|
+
const keep = isSpecifier();
|
|
3754
|
+
out.push(ch);
|
|
3755
|
+
i++;
|
|
3756
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
3757
|
+
if (code[i] === "\\") {
|
|
3758
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
3759
|
+
i += 2;
|
|
3760
|
+
} else {
|
|
3761
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
3762
|
+
i++;
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
if (i < n) {
|
|
3766
|
+
out.push(code[i]);
|
|
3767
|
+
i++;
|
|
3768
|
+
}
|
|
3769
|
+
} else if (ch === "`") {
|
|
3770
|
+
out.push("`");
|
|
3771
|
+
i++;
|
|
3772
|
+
templateBody();
|
|
3773
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
3774
|
+
templates.pop();
|
|
3775
|
+
depth--;
|
|
3776
|
+
out.push("}");
|
|
3777
|
+
i++;
|
|
3778
|
+
templateBody();
|
|
3779
|
+
} else {
|
|
3780
|
+
if (ch === "{") depth++;
|
|
3781
|
+
else if (ch === "}") depth--;
|
|
3782
|
+
out.push(ch);
|
|
3783
|
+
i++;
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
return out.join("");
|
|
3787
|
+
}
|
|
3788
|
+
function bindings(clause) {
|
|
3789
|
+
const out = [];
|
|
3790
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
3791
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
3792
|
+
const p = part.trim();
|
|
3793
|
+
if (!p || p.startsWith("type ")) continue;
|
|
3794
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
3795
|
+
}
|
|
3796
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
3797
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
3798
|
+
if (ns) out.push(ns[1]);
|
|
3799
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
3800
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
3801
|
+
return out;
|
|
3802
|
+
}
|
|
3803
|
+
function readJsonc(file) {
|
|
3804
|
+
try {
|
|
3805
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
3806
|
+
return JSON.parse(text);
|
|
3807
|
+
} catch {
|
|
3808
|
+
return null;
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
3812
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
3813
|
+
seen.add(file);
|
|
3814
|
+
const json = readJsonc(file);
|
|
3815
|
+
if (!json) return {};
|
|
3816
|
+
const dir = path32.dirname(file);
|
|
3817
|
+
let merged = {};
|
|
3818
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3819
|
+
for (const ext of parents) {
|
|
3820
|
+
if (typeof ext !== "string") continue;
|
|
3821
|
+
let target = null;
|
|
3822
|
+
if (ext.startsWith(".") || path32.isAbsolute(ext)) {
|
|
3823
|
+
const abs = path32.resolve(dir, ext);
|
|
3824
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3825
|
+
} else {
|
|
3826
|
+
const parts = ext.split("/");
|
|
3827
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
3828
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3829
|
+
if (pkgDir) {
|
|
3830
|
+
const sub = parts.slice(nameLength).join("/");
|
|
3831
|
+
const abs = path32.join(pkgDir, sub || "tsconfig.json");
|
|
3832
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3836
|
+
}
|
|
3837
|
+
const opts = json.compilerOptions ?? {};
|
|
3838
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path32.resolve(dir, opts.baseUrl);
|
|
3839
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
3840
|
+
merged.paths = opts.paths;
|
|
3841
|
+
merged.pathsDir = dir;
|
|
3842
|
+
}
|
|
3843
|
+
return merged;
|
|
3844
|
+
}
|
|
3845
|
+
function aliases(root) {
|
|
3846
|
+
const table = [];
|
|
3847
|
+
let baseUrl = null;
|
|
3848
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3849
|
+
const file = path32.join(root, name);
|
|
3850
|
+
if (!existsSync(file)) continue;
|
|
3851
|
+
const config = readTsconfig(root, file);
|
|
3852
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
3853
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
3854
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3855
|
+
if (!Array.isArray(targets)) continue;
|
|
3856
|
+
const exact = !pattern.endsWith("*");
|
|
3857
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path32.join(base, String(t).replace(/\*$/, ""))) });
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
const pkg = readJsonc(path32.join(root, "package.json"));
|
|
3861
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3862
|
+
if (typeof target !== "string") continue;
|
|
3863
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path32.join(root, target.replace(/\*.*$/, ""))] });
|
|
3864
|
+
}
|
|
3865
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path32.join(root, "src") + path32.sep, root + path32.sep] });
|
|
3866
|
+
return { table, baseUrl };
|
|
3867
|
+
}
|
|
3868
|
+
function resolveFile(base) {
|
|
3869
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path32.join(base, `index${e}`))];
|
|
3870
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3871
|
+
for (const p of tries) {
|
|
3872
|
+
if (SCRIPT_EXTS2.has(path32.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3873
|
+
}
|
|
3874
|
+
return null;
|
|
3875
|
+
}
|
|
3876
|
+
function trailFor(ctx) {
|
|
3877
|
+
let t = trails.get(ctx.files);
|
|
3878
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
3879
|
+
return t;
|
|
3880
|
+
}
|
|
3881
|
+
function createTrail(ctx) {
|
|
3882
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
3883
|
+
let declared = null;
|
|
3884
|
+
try {
|
|
3885
|
+
const pkg = JSON.parse(readFileSync(path32.join(ctx.root, "package.json"), "utf8"));
|
|
3886
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3887
|
+
} catch {
|
|
3888
|
+
declared = null;
|
|
3889
|
+
}
|
|
3890
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
3891
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
3892
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
3893
|
+
const importsOf = (file) => {
|
|
3894
|
+
const hit = importsCache.get(file.absolutePath);
|
|
3895
|
+
if (hit) return hit;
|
|
3896
|
+
const files = [];
|
|
3897
|
+
let lost = false;
|
|
3898
|
+
const code = stripped(file);
|
|
3899
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
3900
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
3901
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
3902
|
+
for (const m of code.matchAll(/\bexport\s*\{([^}]*)\}\s*;/g)) for (const n of m[1].split(",")) used.add(n.trim().split(/\s+as\s+/)[0]);
|
|
3903
|
+
const specs = [];
|
|
3904
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
3905
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
3906
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
3907
|
+
for (const spec of specs) {
|
|
3908
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3909
|
+
let resolved = null;
|
|
3910
|
+
if (spec.startsWith(".")) {
|
|
3911
|
+
resolved = resolveFile(path32.resolve(path32.dirname(file.absolutePath), spec));
|
|
3912
|
+
if (!resolved) lost = true;
|
|
3913
|
+
} else {
|
|
3914
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3915
|
+
if (alias) {
|
|
3916
|
+
for (const t of alias.targets) {
|
|
3917
|
+
resolved = resolveFile(alias.exact ? t : path32.join(t, spec.slice(alias.prefix.length)));
|
|
3918
|
+
if (resolved) break;
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path32.join(baseUrl, spec));
|
|
3922
|
+
if (!resolved) {
|
|
3923
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3924
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
3928
|
+
}
|
|
3929
|
+
const out = { files, lost };
|
|
3930
|
+
importsCache.set(file.absolutePath, out);
|
|
3931
|
+
return out;
|
|
3932
|
+
};
|
|
3933
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
3934
|
+
const stripped = (file) => {
|
|
3935
|
+
let c = strippedCache.get(file.absolutePath);
|
|
3936
|
+
if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
|
|
3937
|
+
return c;
|
|
3938
|
+
};
|
|
3939
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
3940
|
+
const reach = (file, test2, depth, seen) => {
|
|
3941
|
+
let cache = memo.get(test2);
|
|
3942
|
+
if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
|
|
3943
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
3944
|
+
const cached = cache.get(k);
|
|
3945
|
+
if (cached) return [cached, false];
|
|
3946
|
+
let result;
|
|
3947
|
+
let cut = false;
|
|
3948
|
+
if (test2(stripped(file))) result = "yes";
|
|
3949
|
+
else {
|
|
3950
|
+
const { files, lost } = importsOf(file);
|
|
3951
|
+
let unknown = lost && depth > 0;
|
|
3952
|
+
result = "no";
|
|
3953
|
+
if (depth > 0) {
|
|
3954
|
+
seen.add(file.absolutePath);
|
|
3955
|
+
for (const abs of files) {
|
|
3956
|
+
if (seen.has(abs)) {
|
|
3957
|
+
cut = true;
|
|
3958
|
+
continue;
|
|
3959
|
+
}
|
|
3960
|
+
const target = read(abs);
|
|
3961
|
+
if (!target) {
|
|
3962
|
+
unknown = true;
|
|
3963
|
+
continue;
|
|
3964
|
+
}
|
|
3965
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
3966
|
+
if (c) cut = true;
|
|
3967
|
+
if (r === "yes") {
|
|
3968
|
+
result = "yes";
|
|
3969
|
+
break;
|
|
3970
|
+
}
|
|
3971
|
+
if (r === "unknown") unknown = true;
|
|
3972
|
+
}
|
|
3973
|
+
seen.delete(file.absolutePath);
|
|
3974
|
+
}
|
|
3975
|
+
if (result === "no" && unknown) result = "unknown";
|
|
3976
|
+
}
|
|
3977
|
+
if (result === "yes" || !cut) cache.set(k, result);
|
|
3978
|
+
return [result, cut && result !== "yes"];
|
|
3979
|
+
};
|
|
3980
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3981
|
+
}
|
|
3982
|
+
var TRAIL_DEPTH, RESOLVE_EXTS2, IMPORT_FROM, EXPORT_FROM, DYNAMIC, trails;
|
|
3983
|
+
var init_trail = __esm({
|
|
3984
|
+
"src/doctor/trail.ts"() {
|
|
3985
|
+
init_genesis();
|
|
3986
|
+
init_source();
|
|
3987
|
+
TRAIL_DEPTH = 6;
|
|
3988
|
+
RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
3989
|
+
IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
3990
|
+
EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
3991
|
+
DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
3992
|
+
trails = /* @__PURE__ */ new WeakMap();
|
|
3993
|
+
}
|
|
3994
|
+
});
|
|
3669
3995
|
function routesDir(ctx) {
|
|
3670
3996
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3671
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
3997
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path32.join(ctx.root, d))) ?? null;
|
|
3998
|
+
}
|
|
3999
|
+
function flavorOf(dir, rels) {
|
|
4000
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
4001
|
+
if (stems.includes("__root")) return "tanstack";
|
|
4002
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
4003
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
4004
|
+
return "tanstack";
|
|
4005
|
+
}
|
|
4006
|
+
function renders(code) {
|
|
4007
|
+
const elements = renderedElements(code);
|
|
4008
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
4009
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
4010
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
4011
|
+
if (named && !definedHere(named)) return true;
|
|
4012
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
4013
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
4014
|
+
return exported !== void 0 && !definedHere(exported);
|
|
3672
4015
|
}
|
|
3673
4016
|
function webRoutes(ctx) {
|
|
3674
4017
|
const dir = routesDir(ctx);
|
|
3675
4018
|
if (!dir) return [];
|
|
3676
|
-
const
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
4019
|
+
const candidates = ctx.files.filter((f) => JSX_EXTS2.has(f.ext) && f.path.startsWith(`${dir}/`)).map((file) => ({ file, rel: file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "") }));
|
|
4020
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
4021
|
+
const stems = STEMS[flavor];
|
|
4022
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4023
|
+
for (const { file, rel } of candidates) {
|
|
3680
4024
|
const parts = rel.split("/");
|
|
3681
4025
|
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
4026
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
4027
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
4028
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
4029
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
4030
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
4031
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
4032
|
+
}
|
|
4033
|
+
const trail = trailFor(ctx);
|
|
4034
|
+
const routes = [];
|
|
4035
|
+
for (const [id, files] of groups) {
|
|
4036
|
+
const parts = id.split("/");
|
|
3682
4037
|
const stem = parts.pop();
|
|
3683
|
-
const
|
|
3684
|
-
|
|
3685
|
-
|
|
4038
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
4039
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
4040
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
4041
|
+
const segments = [...folders, ...own];
|
|
4042
|
+
const tree = [...parts, ...own];
|
|
4043
|
+
let index = stems.index.has(stem);
|
|
4044
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
3686
4045
|
segments.pop();
|
|
4046
|
+
tree.pop();
|
|
3687
4047
|
index = true;
|
|
3688
4048
|
}
|
|
3689
|
-
const
|
|
3690
|
-
const
|
|
4049
|
+
const code = files.map((f) => f.code).join("\n");
|
|
4050
|
+
const elements = renderedElements(code);
|
|
4051
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
4052
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
4053
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
4054
|
+
const rendering = renders(code);
|
|
4055
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
4056
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
4057
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
3691
4058
|
routes.push({
|
|
3692
|
-
file,
|
|
4059
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
4060
|
+
files,
|
|
3693
4061
|
segments,
|
|
4062
|
+
tree,
|
|
3694
4063
|
index,
|
|
3695
4064
|
layout,
|
|
3696
|
-
|
|
3697
|
-
|
|
4065
|
+
page,
|
|
4066
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
4067
|
+
redirectOnly: !rendering,
|
|
3698
4068
|
parents: []
|
|
3699
4069
|
});
|
|
3700
4070
|
}
|
|
3701
4071
|
for (const r of routes) {
|
|
3702
|
-
const own = r.
|
|
4072
|
+
const own = r.tree;
|
|
3703
4073
|
for (const p of routes) {
|
|
3704
4074
|
if (p === r || !p.layout) continue;
|
|
3705
|
-
const n = p.
|
|
4075
|
+
const n = p.tree.length;
|
|
3706
4076
|
if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
|
|
3707
|
-
if (key(own.slice(0, n)) !== key(p.
|
|
3708
|
-
if (n > 0 && own[n - 1].endsWith("_") && !p.
|
|
4077
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
4078
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
3709
4079
|
r.parents.push(p);
|
|
3710
4080
|
}
|
|
3711
|
-
r.parents.sort((a, b) => b.
|
|
4081
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
3712
4082
|
}
|
|
3713
4083
|
return routes;
|
|
3714
4084
|
}
|
|
3715
|
-
var ROUTES_DIR_CANDIDATES,
|
|
4085
|
+
var ROUTES_DIR_CANDIDATES, STEMS, NON_PAGE_ELEMENTS, HTML_ELEMENT, COMPONENT_OPTION, RENDERS_OUTLET, OWN_CONTENT, key;
|
|
3716
4086
|
var init_routes = __esm({
|
|
3717
4087
|
"src/doctor/routes.ts"() {
|
|
3718
4088
|
init_source();
|
|
4089
|
+
init_trail();
|
|
3719
4090
|
ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3720
|
-
|
|
3721
|
-
|
|
4091
|
+
STEMS = {
|
|
4092
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
4093
|
+
"next-app": {
|
|
4094
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
4095
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
4096
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
4097
|
+
},
|
|
4098
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
4099
|
+
};
|
|
3722
4100
|
NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
3723
4101
|
HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
4102
|
+
COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
4103
|
+
RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
4104
|
+
OWN_CONTENT = /(?<![=-])>\s*[A-Za-z][^<>{}]*</.source + "|" + /(?<![\w$.])<(?:h[1-6]|ul|ol|table|dl|H[1-6]|[A-Z]\w*(?:Heading|Title|Table|List|Grid))(?=[\s>/])/.source;
|
|
3724
4105
|
key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3725
4106
|
}
|
|
3726
4107
|
});
|
|
3727
4108
|
|
|
3728
4109
|
// src/doctor/structure.ts
|
|
4110
|
+
function routeReach(ctx, r, test2) {
|
|
4111
|
+
const trail = trailFor(ctx);
|
|
4112
|
+
let unknown = false;
|
|
4113
|
+
for (const f of r.files) {
|
|
4114
|
+
const got = trail.reach(f, test2);
|
|
4115
|
+
if (got === "yes") return "yes";
|
|
4116
|
+
if (got === "unknown") unknown = true;
|
|
4117
|
+
}
|
|
4118
|
+
return unknown ? "unknown" : "no";
|
|
4119
|
+
}
|
|
3729
4120
|
function insideShell(ctx, routes) {
|
|
3730
|
-
const shell = new Set(routes.filter((r) =>
|
|
4121
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
3731
4122
|
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
3732
4123
|
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
3733
4124
|
}
|
|
@@ -3738,20 +4129,19 @@ function checkHandRolledSubNav(ctx) {
|
|
|
3738
4129
|
const inShell = insideShell(ctx, routes);
|
|
3739
4130
|
const ui = ctx.genesis.uiPackage;
|
|
3740
4131
|
for (const r of routes) {
|
|
3741
|
-
if (!inShell(r)) continue;
|
|
3742
|
-
const
|
|
3743
|
-
if (
|
|
3744
|
-
|
|
3745
|
-
|
|
4132
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
4133
|
+
const hit = r.files.flatMap((f) => [...f.code.matchAll(SWITCHER)].map((m) => ({ f, m }))).find(({ f, m }) => openElementsAt(f.code, m.index, (n) => CONTAINER.test(n)).length === 0);
|
|
4134
|
+
if (hit) {
|
|
4135
|
+
const { f, m } = hit;
|
|
4136
|
+
const code = f.code;
|
|
3746
4137
|
ctx.report({
|
|
3747
4138
|
rule: "hand-rolled-sub-nav",
|
|
3748
4139
|
level: "warn",
|
|
3749
|
-
file:
|
|
4140
|
+
file: f.path,
|
|
3750
4141
|
line: lineAt(code, m.index),
|
|
3751
4142
|
subject: m[1],
|
|
3752
4143
|
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
4144
|
});
|
|
3754
|
-
break;
|
|
3755
4145
|
}
|
|
3756
4146
|
}
|
|
3757
4147
|
}
|
|
@@ -3799,11 +4189,12 @@ function checkResourceWorkspaces(ctx) {
|
|
|
3799
4189
|
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
3800
4190
|
}
|
|
3801
4191
|
for (const [dir, routes] of byFolder) {
|
|
3802
|
-
const
|
|
4192
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
4193
|
+
const has2 = routes.filter((r) => reach.get(r) === "yes");
|
|
3803
4194
|
if (has2.length === 0) continue;
|
|
3804
4195
|
const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
3805
4196
|
for (const r of routes) {
|
|
3806
|
-
if (
|
|
4197
|
+
if (reach.get(r) !== "no") continue;
|
|
3807
4198
|
ctx.report({
|
|
3808
4199
|
rule: "resource-workspace",
|
|
3809
4200
|
level: "info",
|
|
@@ -3827,14 +4218,14 @@ function checkPageLayouts(ctx) {
|
|
|
3827
4218
|
};
|
|
3828
4219
|
const cache = /* @__PURE__ */ new Map();
|
|
3829
4220
|
const provides = (r) => {
|
|
3830
|
-
if (!cache.has(r)) cache.set(r,
|
|
4221
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
3831
4222
|
return cache.get(r);
|
|
3832
4223
|
};
|
|
3833
4224
|
const list = [...layouts].sort();
|
|
3834
4225
|
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
3835
4226
|
for (const r of routes) {
|
|
3836
|
-
if (r.
|
|
3837
|
-
if (provides(r) || r.parents.some(provides)) continue;
|
|
4227
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
4228
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
3838
4229
|
ctx.report({
|
|
3839
4230
|
rule: "page-layout",
|
|
3840
4231
|
level: "warn",
|
|
@@ -3843,12 +4234,13 @@ function checkPageLayouts(ctx) {
|
|
|
3843
4234
|
});
|
|
3844
4235
|
}
|
|
3845
4236
|
}
|
|
3846
|
-
var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, PACKAGE_SCREEN, isNative, rendersRe;
|
|
4237
|
+
var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, PACKAGE_SCREEN, isNative, rendersRe, routeVia;
|
|
3847
4238
|
var init_structure = __esm({
|
|
3848
4239
|
"src/doctor/structure.ts"() {
|
|
3849
4240
|
init_scan();
|
|
3850
4241
|
init_routes();
|
|
3851
4242
|
init_source();
|
|
4243
|
+
init_trail();
|
|
3852
4244
|
SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
|
|
3853
4245
|
CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
|
|
3854
4246
|
SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
@@ -3861,6 +4253,7 @@ var init_structure = __esm({
|
|
|
3861
4253
|
const list = [...names];
|
|
3862
4254
|
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
3863
4255
|
};
|
|
4256
|
+
routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
3864
4257
|
}
|
|
3865
4258
|
});
|
|
3866
4259
|
|
|
@@ -3920,7 +4313,7 @@ __export(doctor_exports, {
|
|
|
3920
4313
|
webRoutes: () => webRoutes
|
|
3921
4314
|
});
|
|
3922
4315
|
async function runDoctor(options = {}) {
|
|
3923
|
-
const root =
|
|
4316
|
+
const root = path32.resolve(options.root ?? process.cwd());
|
|
3924
4317
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
3925
4318
|
const config = loaded.config;
|
|
3926
4319
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -4108,20 +4501,20 @@ function readObject(file, key2) {
|
|
|
4108
4501
|
}
|
|
4109
4502
|
}
|
|
4110
4503
|
function settings(root, options) {
|
|
4111
|
-
const fromPackage = readObject(
|
|
4112
|
-
const fromConfig = readObject(
|
|
4504
|
+
const fromPackage = readObject(path32.join(root, "package.json"), "genesisFeatures");
|
|
4505
|
+
const fromConfig = readObject(path32.join(root, "genesis.config.json"), "features");
|
|
4113
4506
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
4114
4507
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
4115
4508
|
}
|
|
4116
4509
|
async function loadRegistry(input) {
|
|
4117
|
-
const root =
|
|
4510
|
+
const root = path32.resolve(input.dir);
|
|
4118
4511
|
const options = settings(root, input);
|
|
4119
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
4120
|
-
if (!registry || !existsSync(
|
|
4512
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path32.join(root, p)));
|
|
4513
|
+
if (!registry || !existsSync(path32.join(root, registry))) {
|
|
4121
4514
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
4122
4515
|
}
|
|
4123
|
-
const jiti = createJiti(
|
|
4124
|
-
const load = async (file) => await jiti.import(
|
|
4516
|
+
const jiti = createJiti(path32.join(root, "package.json"), { moduleCache: false });
|
|
4517
|
+
const load = async (file) => await jiti.import(path32.join(root, file));
|
|
4125
4518
|
const mod = await load(registry);
|
|
4126
4519
|
const features2 = mod.features ?? mod.default;
|
|
4127
4520
|
if (!isObject3(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -4133,7 +4526,7 @@ async function loadRegistry(input) {
|
|
|
4133
4526
|
const project = {
|
|
4134
4527
|
...rest,
|
|
4135
4528
|
root,
|
|
4136
|
-
source: options.source ?? registry.split(
|
|
4529
|
+
source: options.source ?? registry.split(path32.sep).join("/"),
|
|
4137
4530
|
features: features2,
|
|
4138
4531
|
flags
|
|
4139
4532
|
};
|
|
@@ -4662,9 +5055,9 @@ function ownedKeyProblem(key2, source) {
|
|
|
4662
5055
|
return `${key2} doesn't match its source ${source}`;
|
|
4663
5056
|
}
|
|
4664
5057
|
function mergeThreeWay(mine, base, theirs) {
|
|
4665
|
-
const dir = mkdtempSync(
|
|
5058
|
+
const dir = mkdtempSync(path32.join(tmpdir(), "genesis-merge-"));
|
|
4666
5059
|
try {
|
|
4667
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
5060
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path32.join(dir, n));
|
|
4668
5061
|
writeFileSync(m, mine);
|
|
4669
5062
|
writeFileSync(b, base);
|
|
4670
5063
|
writeFileSync(t, theirs);
|
|
@@ -4833,12 +5226,12 @@ var init_registry_edit = __esm({
|
|
|
4833
5226
|
});
|
|
4834
5227
|
function routerRoot2(root) {
|
|
4835
5228
|
try {
|
|
4836
|
-
const config = JSON.parse(readFileSync(
|
|
5229
|
+
const config = JSON.parse(readFileSync(path32.join(root, "genesis.config.json"), "utf8"));
|
|
4837
5230
|
const configured = config.doctor?.native?.routerRoot;
|
|
4838
|
-
if (configured && existsSync(
|
|
5231
|
+
if (configured && existsSync(path32.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
4839
5232
|
} catch {
|
|
4840
5233
|
}
|
|
4841
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
5234
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path32.join(root, dir, "_layout.tsx"))) return dir;
|
|
4842
5235
|
return null;
|
|
4843
5236
|
}
|
|
4844
5237
|
function routeOf(file) {
|
|
@@ -4899,7 +5292,7 @@ __export(add_exports, {
|
|
|
4899
5292
|
});
|
|
4900
5293
|
function appDependencies(root) {
|
|
4901
5294
|
try {
|
|
4902
|
-
const pkg = JSON.parse(readFileSync(
|
|
5295
|
+
const pkg = JSON.parse(readFileSync(path32.join(root, "package.json"), "utf8"));
|
|
4903
5296
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
4904
5297
|
} catch {
|
|
4905
5298
|
return {};
|
|
@@ -4908,14 +5301,14 @@ function appDependencies(root) {
|
|
|
4908
5301
|
function registryFile(root) {
|
|
4909
5302
|
const read = (file, key2) => {
|
|
4910
5303
|
try {
|
|
4911
|
-
const v = JSON.parse(readFileSync(
|
|
5304
|
+
const v = JSON.parse(readFileSync(path32.join(root, file), "utf8"))[key2]?.registry;
|
|
4912
5305
|
return typeof v === "string" ? v : void 0;
|
|
4913
5306
|
} catch {
|
|
4914
5307
|
return void 0;
|
|
4915
5308
|
}
|
|
4916
5309
|
};
|
|
4917
5310
|
const named = read("genesis.config.json", "features") ?? read("package.json", "genesisFeatures");
|
|
4918
|
-
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(
|
|
5311
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path32.join(root, candidate))) return candidate;
|
|
4919
5312
|
return null;
|
|
4920
5313
|
}
|
|
4921
5314
|
async function registryIds(root, file) {
|
|
@@ -4992,7 +5385,7 @@ verify_jwt = false
|
|
|
4992
5385
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
4993
5386
|
}
|
|
4994
5387
|
async function runAdd(options) {
|
|
4995
|
-
const root =
|
|
5388
|
+
const root = path32.resolve(options.root);
|
|
4996
5389
|
const log = options.log ?? SILENT;
|
|
4997
5390
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
4998
5391
|
const warnings = [];
|
|
@@ -5167,7 +5560,7 @@ __export(migrate_exports, {
|
|
|
5167
5560
|
runMigrate: () => runMigrate
|
|
5168
5561
|
});
|
|
5169
5562
|
async function runMigrate(options) {
|
|
5170
|
-
const root =
|
|
5563
|
+
const root = path32.resolve(options.root);
|
|
5171
5564
|
const lock = readLock(root);
|
|
5172
5565
|
const warnings = [];
|
|
5173
5566
|
const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks), ...options.blocks ?? []])];
|
|
@@ -5327,11 +5720,11 @@ function npmLookup(cwd) {
|
|
|
5327
5720
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
5328
5721
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
5329
5722
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
5330
|
-
const tmp = mkdtempSync(
|
|
5723
|
+
const tmp = mkdtempSync(path32.join(tmpdir(), "genesis-umbrella-"));
|
|
5331
5724
|
try {
|
|
5332
5725
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
5333
|
-
execFileSync("tar", ["-xzf",
|
|
5334
|
-
const manifest = JSON.parse(readFileSync(
|
|
5726
|
+
execFileSync("tar", ["-xzf", path32.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
5727
|
+
const manifest = JSON.parse(readFileSync(path32.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
5335
5728
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
5336
5729
|
return manifest;
|
|
5337
5730
|
} finally {
|
|
@@ -5358,7 +5751,7 @@ function packageJsons(root) {
|
|
|
5358
5751
|
if (files.length) return files;
|
|
5359
5752
|
} catch {
|
|
5360
5753
|
}
|
|
5361
|
-
return existsSync(
|
|
5754
|
+
return existsSync(path32.join(root, "package.json")) ? ["package.json"] : [];
|
|
5362
5755
|
}
|
|
5363
5756
|
function sourceText(root, source, substitutions) {
|
|
5364
5757
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -5377,11 +5770,11 @@ function sourceText(root, source, substitutions) {
|
|
|
5377
5770
|
}
|
|
5378
5771
|
}
|
|
5379
5772
|
async function runUpgrade(options) {
|
|
5380
|
-
const root =
|
|
5773
|
+
const root = path32.resolve(options.root);
|
|
5381
5774
|
const log = options.log ?? (() => {
|
|
5382
5775
|
});
|
|
5383
5776
|
const lookup = options.lookup ?? npmLookup(root);
|
|
5384
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
5777
|
+
const release = options.manifest ? JSON.parse(readFileSync(path32.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
5385
5778
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
5386
5779
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
5387
5780
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -5517,7 +5910,7 @@ function checkSubstitutions(substitutions) {
|
|
|
5517
5910
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
5518
5911
|
let allowed;
|
|
5519
5912
|
try {
|
|
5520
|
-
const was = starterIdentity(readFileSync(
|
|
5913
|
+
const was = starterIdentity(readFileSync(path32.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
5521
5914
|
allowed = [was.name, was.slug, was.scheme, was.bundleId];
|
|
5522
5915
|
} catch {
|
|
5523
5916
|
allowed = [];
|
|
@@ -5550,15 +5943,15 @@ function openPullRequest(root, version, report, base) {
|
|
|
5550
5943
|
git2("switch", "-c", branch);
|
|
5551
5944
|
const top = git2("rev-parse", "--show-toplevel");
|
|
5552
5945
|
const lockfiles = [];
|
|
5553
|
-
for (let dir =
|
|
5554
|
-
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(
|
|
5555
|
-
if (lockfiles.length || dir === top ||
|
|
5946
|
+
for (let dir = path32.resolve(root); ; dir = path32.dirname(dir)) {
|
|
5947
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path32.join(dir, f))) lockfiles.push(path32.relative(root, path32.join(dir, f)));
|
|
5948
|
+
if (lockfiles.length || dir === top || path32.dirname(dir) === dir) break;
|
|
5556
5949
|
}
|
|
5557
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
5950
|
+
const paths = [...report.files.filter((f) => existsSync(path32.join(root, f))), ...lockfiles];
|
|
5558
5951
|
git2("add", "--", ...paths);
|
|
5559
5952
|
git2("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
5560
5953
|
git2("push", "-u", "origin", branch);
|
|
5561
|
-
const body =
|
|
5954
|
+
const body = path32.join(mkdtempSync(path32.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
5562
5955
|
writeFileSync(body, `${report.summary}
|
|
5563
5956
|
|
|
5564
5957
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -5681,9 +6074,9 @@ async function runScaffold(opts, fs2) {
|
|
|
5681
6074
|
function joinPath(...parts) {
|
|
5682
6075
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
5683
6076
|
}
|
|
5684
|
-
function dirname(
|
|
5685
|
-
const idx =
|
|
5686
|
-
return idx === -1 ? "." :
|
|
6077
|
+
function dirname(path33) {
|
|
6078
|
+
const idx = path33.lastIndexOf("/");
|
|
6079
|
+
return idx === -1 ? "." : path33.slice(0, idx);
|
|
5687
6080
|
}
|
|
5688
6081
|
function brandPackageJson(consumer, genesisVersion) {
|
|
5689
6082
|
return JSON.stringify(
|
|
@@ -5922,7 +6315,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
5922
6315
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
5923
6316
|
const result2 = await runInitNative2({
|
|
5924
6317
|
name: consumer,
|
|
5925
|
-
target:
|
|
6318
|
+
target: path32.resolve(opts.target ?? consumer),
|
|
5926
6319
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
5927
6320
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
5928
6321
|
...opts.scheme ? { scheme: opts.scheme } : {}
|
|
@@ -5932,7 +6325,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
5932
6325
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
5933
6326
|
console.log("");
|
|
5934
6327
|
console.log("Next steps:");
|
|
5935
|
-
[`cd ${
|
|
6328
|
+
[`cd ${path32.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
5936
6329
|
return;
|
|
5937
6330
|
}
|
|
5938
6331
|
opts.target ??= process.cwd();
|
|
@@ -5998,7 +6391,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
5998
6391
|
source = `Postgres (${schemas.join(", ")})`;
|
|
5999
6392
|
}
|
|
6000
6393
|
const content = emitContracts2(tables, { source });
|
|
6001
|
-
const target =
|
|
6394
|
+
const target = path32.resolve(opts.out);
|
|
6002
6395
|
if (opts.check) {
|
|
6003
6396
|
const current = await fs.readFile(target, "utf-8").catch(() => null);
|
|
6004
6397
|
if (current !== content) {
|
|
@@ -6013,7 +6406,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
6013
6406
|
});
|
|
6014
6407
|
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) => {
|
|
6015
6408
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
6016
|
-
const root =
|
|
6409
|
+
const root = path32.resolve(opts.dir);
|
|
6017
6410
|
try {
|
|
6018
6411
|
if (opts.printGenesis) {
|
|
6019
6412
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -6078,9 +6471,9 @@ featureOptions(
|
|
|
6078
6471
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
6079
6472
|
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) => {
|
|
6080
6473
|
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
6081
|
-
const root =
|
|
6082
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
6083
|
-
const
|
|
6474
|
+
const root = path32.resolve(opts.dir);
|
|
6475
|
+
const packageJson = JSON.parse(await fs.readFile(path32.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
6476
|
+
const existsSync26 = (await import('fs')).existsSync;
|
|
6084
6477
|
const readSync = (await import('fs')).readFileSync;
|
|
6085
6478
|
const readdirSync10 = (await import('fs')).readdirSync;
|
|
6086
6479
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
@@ -6089,13 +6482,13 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6089
6482
|
const plan = planStudioInit2(
|
|
6090
6483
|
{
|
|
6091
6484
|
packageJson,
|
|
6092
|
-
exists: (p) =>
|
|
6093
|
-
read: (p) =>
|
|
6485
|
+
exists: (p) => existsSync26(path32.join(root, p)),
|
|
6486
|
+
read: (p) => existsSync26(path32.join(root, p)) ? readSync(path32.join(root, p), "utf-8") : null,
|
|
6094
6487
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
6095
6488
|
listDeep: (p) => {
|
|
6096
6489
|
const out = [];
|
|
6097
6490
|
const walk2 = (rel) => {
|
|
6098
|
-
for (const entry of readdirSync10(
|
|
6491
|
+
for (const entry of readdirSync10(path32.join(root, rel), { withFileTypes: true })) {
|
|
6099
6492
|
const child = `${rel}/${entry.name}`;
|
|
6100
6493
|
if (entry.isDirectory()) walk2(child);
|
|
6101
6494
|
else out.push(child);
|
|
@@ -6109,7 +6502,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6109
6502
|
},
|
|
6110
6503
|
list: (p) => {
|
|
6111
6504
|
try {
|
|
6112
|
-
return readdirSync10(
|
|
6505
|
+
return readdirSync10(path32.join(root, p));
|
|
6113
6506
|
} catch {
|
|
6114
6507
|
return [];
|
|
6115
6508
|
}
|
|
@@ -6118,8 +6511,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6118
6511
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
6119
6512
|
);
|
|
6120
6513
|
for (const file of plan.files) {
|
|
6121
|
-
const target =
|
|
6122
|
-
await fs.mkdir(
|
|
6514
|
+
const target = path32.join(root, file.path);
|
|
6515
|
+
await fs.mkdir(path32.dirname(target), { recursive: true });
|
|
6123
6516
|
if (file.edit) {
|
|
6124
6517
|
await fs.writeFile(target, file.content, "utf-8");
|
|
6125
6518
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -6130,14 +6523,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6130
6523
|
console.log(`+ ${file.path} (appended)`);
|
|
6131
6524
|
continue;
|
|
6132
6525
|
}
|
|
6133
|
-
if (
|
|
6526
|
+
if (existsSync26(target) && !opts.force) {
|
|
6134
6527
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
6135
6528
|
continue;
|
|
6136
6529
|
}
|
|
6137
6530
|
await fs.writeFile(target, file.content, "utf-8");
|
|
6138
6531
|
console.log(`+ ${file.path}`);
|
|
6139
6532
|
}
|
|
6140
|
-
const pm =
|
|
6533
|
+
const pm = existsSync26(path32.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync26(path32.join(root, "yarn.lock")) ? "yarn add" : existsSync26(path32.join(root, "bun.lock")) || existsSync26(path32.join(root, "bun.lockb")) ? "bun add" : "npm install";
|
|
6141
6534
|
console.log("");
|
|
6142
6535
|
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:`);
|
|
6143
6536
|
console.log(` 1. ${pm} ${plan.install.join(" ")}`);
|
|
@@ -6155,7 +6548,7 @@ async function confirm(question) {
|
|
|
6155
6548
|
}
|
|
6156
6549
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
6157
6550
|
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) => {
|
|
6158
|
-
const root =
|
|
6551
|
+
const root = path32.resolve(opts.dir);
|
|
6159
6552
|
if (opts.list || !block) {
|
|
6160
6553
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
6161
6554
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -6184,7 +6577,7 @@ program.command("add").description("Add a block (a feature an app adds whole) fr
|
|
|
6184
6577
|
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) => {
|
|
6185
6578
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
6186
6579
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
6187
|
-
const report = await runMigrate2({ root:
|
|
6580
|
+
const report = await runMigrate2({ root: path32.resolve(opts.dir), ...opts.block ? { blocks: opts.block } : {}, dryRun: opts.dryRun, forward: opts.forward });
|
|
6188
6581
|
for (const w of report.warnings) logger.warn(w);
|
|
6189
6582
|
console.log(formatMigrationRows2(report.plan.rows));
|
|
6190
6583
|
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"})`);
|
|
@@ -6199,7 +6592,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
6199
6592
|
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) => {
|
|
6200
6593
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
6201
6594
|
const report = await runUpgrade2({
|
|
6202
|
-
root:
|
|
6595
|
+
root: path32.resolve(opts.dir),
|
|
6203
6596
|
version: opts.version,
|
|
6204
6597
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
6205
6598
|
dryRun: opts.dryRun,
|
|
@@ -6263,7 +6656,7 @@ function redactUrl(location) {
|
|
|
6263
6656
|
const url = new URL(location);
|
|
6264
6657
|
return `${url.origin}${url.pathname}`;
|
|
6265
6658
|
} catch {
|
|
6266
|
-
return
|
|
6659
|
+
return path32.basename(location);
|
|
6267
6660
|
}
|
|
6268
6661
|
}
|
|
6269
6662
|
//# sourceMappingURL=cli.js.map
|