@marktiderman/genesis-cli 1.9.0 → 1.11.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 +35 -5
- package/dist/cli.js +764 -257
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +31 -4
- package/dist/doctor.js +644 -144
- package/dist/doctor.js.map +1 -1
- package/dist/genesis-catalog.json +73 -15
- package/dist/index.js +647 -147
- package/dist/index.js.map +1 -1
- package/dist/vite.js +648 -148
- 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
|
}
|
|
@@ -2503,7 +2503,8 @@ var init_rules = __esm({
|
|
|
2503
2503
|
"migration-rls",
|
|
2504
2504
|
"migration-definer-search-path",
|
|
2505
2505
|
"migration-edited",
|
|
2506
|
-
"migration-testing-kit"
|
|
2506
|
+
"migration-testing-kit",
|
|
2507
|
+
"migration-view-rls"
|
|
2507
2508
|
];
|
|
2508
2509
|
DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
2509
2510
|
STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -2591,10 +2592,10 @@ function localImports(root, file) {
|
|
|
2591
2592
|
const out = [];
|
|
2592
2593
|
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
2593
2594
|
const spec = m[1];
|
|
2594
|
-
const bases = spec.startsWith(".") ? [
|
|
2595
|
+
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
2596
|
for (const base of bases) {
|
|
2596
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2597
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2597
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path32.join(base, `index${e}`))].find(
|
|
2598
|
+
(p) => SCRIPT_EXTS2.has(path32.extname(p)) && existsSync(p)
|
|
2598
2599
|
);
|
|
2599
2600
|
if (hit) {
|
|
2600
2601
|
out.push(hit);
|
|
@@ -2611,14 +2612,6 @@ function readSource(abs) {
|
|
|
2611
2612
|
return null;
|
|
2612
2613
|
}
|
|
2613
2614
|
}
|
|
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
2615
|
function tagEnd(code, start) {
|
|
2623
2616
|
let depth = 0;
|
|
2624
2617
|
let quote2 = null;
|
|
@@ -2765,7 +2758,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2765
2758
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2766
2759
|
const code = file.code;
|
|
2767
2760
|
const hidden = HIDES_HEADER.exec(code);
|
|
2768
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2761
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path32.posix.dirname(file.path), file.path);
|
|
2769
2762
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2770
2763
|
if (hidden && own) {
|
|
2771
2764
|
reported.add(file.path);
|
|
@@ -2793,7 +2786,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2793
2786
|
}
|
|
2794
2787
|
for (const file of ctx.files) {
|
|
2795
2788
|
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(
|
|
2789
|
+
const layout = hidingLayouts.get(path32.posix.dirname(file.path));
|
|
2797
2790
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2798
2791
|
if (!layout || !own) continue;
|
|
2799
2792
|
ctx.report({
|
|
@@ -2808,13 +2801,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2808
2801
|
}
|
|
2809
2802
|
function routerRoot(ctx) {
|
|
2810
2803
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2811
|
-
return existsSync(
|
|
2804
|
+
return existsSync(path32.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2812
2805
|
}
|
|
2813
2806
|
function checkScreenLayouts(ctx, pkg) {
|
|
2814
2807
|
const layouts = nativeLayouts(pkg);
|
|
2815
2808
|
if (layouts.length === 0) return;
|
|
2816
2809
|
const rootDir = routerRoot(ctx);
|
|
2817
|
-
if (!existsSync(
|
|
2810
|
+
if (!existsSync(path32.join(ctx.root, rootDir))) {
|
|
2818
2811
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2819
2812
|
return;
|
|
2820
2813
|
}
|
|
@@ -2828,15 +2821,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2828
2821
|
});
|
|
2829
2822
|
return;
|
|
2830
2823
|
}
|
|
2831
|
-
const
|
|
2824
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
2832
2825
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2833
2826
|
for (const file of routes) {
|
|
2834
2827
|
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2835
2828
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
2836
|
-
if (
|
|
2829
|
+
if (renders2.test(file.code)) continue;
|
|
2837
2830
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
2838
2831
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
2839
|
-
return target !== null &&
|
|
2832
|
+
return target !== null && renders2.test(target.code);
|
|
2840
2833
|
});
|
|
2841
2834
|
if (viaImport) continue;
|
|
2842
2835
|
ctx.report({
|
|
@@ -2850,7 +2843,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2850
2843
|
function readExpoConfigs(root) {
|
|
2851
2844
|
const out = [];
|
|
2852
2845
|
for (const name of EXPO_CONFIGS) {
|
|
2853
|
-
const abs =
|
|
2846
|
+
const abs = path32.join(root, name);
|
|
2854
2847
|
if (!existsSync(abs)) continue;
|
|
2855
2848
|
const text = readFileSync(abs, "utf8");
|
|
2856
2849
|
let json = null;
|
|
@@ -2884,13 +2877,13 @@ function pluginOptions(json, module) {
|
|
|
2884
2877
|
return null;
|
|
2885
2878
|
}
|
|
2886
2879
|
function dependencies(root) {
|
|
2887
|
-
const file =
|
|
2880
|
+
const file = path32.join(root, "package.json");
|
|
2888
2881
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2889
2882
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2890
2883
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2891
2884
|
}
|
|
2892
2885
|
function runtimeDependencies(root) {
|
|
2893
|
-
const file =
|
|
2886
|
+
const file = path32.join(root, "package.json");
|
|
2894
2887
|
if (!existsSync(file)) return {};
|
|
2895
2888
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2896
2889
|
}
|
|
@@ -3175,9 +3168,9 @@ function gitView(root, dir, base) {
|
|
|
3175
3168
|
function checkSupabasePack(ctx) {
|
|
3176
3169
|
const settings2 = ctx.config.supabase ?? {};
|
|
3177
3170
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
3178
|
-
const abs =
|
|
3171
|
+
const abs = path32.join(ctx.root, dir);
|
|
3179
3172
|
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(
|
|
3173
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path32.join(abs, n), "utf8")) }));
|
|
3181
3174
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
3182
3175
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
3183
3176
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -3194,7 +3187,7 @@ function checkSupabasePack(ctx) {
|
|
|
3194
3187
|
}
|
|
3195
3188
|
}
|
|
3196
3189
|
const since = settings2.since;
|
|
3197
|
-
const afterSince = (file) => since === void 0 ||
|
|
3190
|
+
const afterSince = (file) => since === void 0 || path32.posix.basename(file) >= since;
|
|
3198
3191
|
if ("reason" in view && since === void 0) {
|
|
3199
3192
|
ctx.report({
|
|
3200
3193
|
rule: "migration-grants",
|
|
@@ -3207,6 +3200,7 @@ function checkSupabasePack(ctx) {
|
|
|
3207
3200
|
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
3208
3201
|
}
|
|
3209
3202
|
checkRls(ctx, migrations, exposed);
|
|
3203
|
+
checkViewInvoker(ctx, migrations, exposed);
|
|
3210
3204
|
checkDefinerSearchPath(ctx, migrations);
|
|
3211
3205
|
checkTestingKit(ctx, migrations);
|
|
3212
3206
|
}
|
|
@@ -3336,6 +3330,50 @@ function checkRls(ctx, migrations, exposed) {
|
|
|
3336
3330
|
});
|
|
3337
3331
|
}
|
|
3338
3332
|
}
|
|
3333
|
+
function checkViewInvoker(ctx, migrations, exposed) {
|
|
3334
|
+
const views = /* @__PURE__ */ new Map();
|
|
3335
|
+
const name = String.raw`([\w$.]+)`;
|
|
3336
|
+
const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
|
|
3337
|
+
for (const { file, statements } of migrations) {
|
|
3338
|
+
for (const { sql, line } of statements) {
|
|
3339
|
+
const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
|
|
3340
|
+
if (create) {
|
|
3341
|
+
if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
|
|
3342
|
+
const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
|
|
3343
|
+
views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
|
|
3344
|
+
continue;
|
|
3345
|
+
}
|
|
3346
|
+
const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
|
|
3347
|
+
if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
|
|
3348
|
+
const state = views.get(qualify(alter[1]));
|
|
3349
|
+
if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
|
|
3350
|
+
continue;
|
|
3351
|
+
}
|
|
3352
|
+
const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
|
|
3353
|
+
if (rename) {
|
|
3354
|
+
const from = qualify(rename[1]);
|
|
3355
|
+
const state = views.get(from);
|
|
3356
|
+
if (state) {
|
|
3357
|
+
views.delete(from);
|
|
3358
|
+
views.set(`${schemaOf(from)}.${rename[2]}`, state);
|
|
3359
|
+
}
|
|
3360
|
+
continue;
|
|
3361
|
+
}
|
|
3362
|
+
const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
3363
|
+
if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
for (const [v, at] of views) {
|
|
3367
|
+
if (at.invoker || !exposed.has(schemaOf(v))) continue;
|
|
3368
|
+
ctx.report({
|
|
3369
|
+
rule: "migration-view-rls",
|
|
3370
|
+
file: at.file,
|
|
3371
|
+
line: at.line,
|
|
3372
|
+
subject: v,
|
|
3373
|
+
message: `${v} runs as its owner, so it reads past row level security; create it "with (security_invoker = true)" or add "alter view ${v} set (security_invoker = true);"`
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3339
3377
|
function checkDefinerSearchPath(ctx, migrations) {
|
|
3340
3378
|
const fns = /* @__PURE__ */ new Map();
|
|
3341
3379
|
const keysFor = (sql, nameEnd, fnName) => {
|
|
@@ -3549,10 +3587,10 @@ function packagesIn(nodeModules) {
|
|
|
3549
3587
|
const out = [];
|
|
3550
3588
|
for (const entry of readdirSync(nodeModules)) {
|
|
3551
3589
|
if (entry.startsWith(".")) continue;
|
|
3552
|
-
const p =
|
|
3590
|
+
const p = path32.join(nodeModules, entry);
|
|
3553
3591
|
if (entry.startsWith("@")) {
|
|
3554
3592
|
try {
|
|
3555
|
-
for (const sub of readdirSync(p)) out.push(
|
|
3593
|
+
for (const sub of readdirSync(p)) out.push(path32.join(p, sub));
|
|
3556
3594
|
} catch {
|
|
3557
3595
|
}
|
|
3558
3596
|
} else {
|
|
@@ -3564,44 +3602,70 @@ function packagesIn(nodeModules) {
|
|
|
3564
3602
|
function genesisInstalls(root) {
|
|
3565
3603
|
const copies = /* @__PURE__ */ new Map();
|
|
3566
3604
|
const realRoot = real(root);
|
|
3567
|
-
const rel = (abs) =>
|
|
3568
|
-
const
|
|
3605
|
+
const rel = (abs) => path32.relative(realRoot, abs).split(path32.sep).join("/") || ".";
|
|
3606
|
+
const via = /* @__PURE__ */ new Map();
|
|
3607
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
3569
3608
|
let copy = copies.get(real2);
|
|
3570
3609
|
if (!copy) {
|
|
3571
|
-
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
|
|
3610
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
3572
3611
|
copies.set(real2, copy);
|
|
3612
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
3573
3613
|
}
|
|
3614
|
+
via.get(real2).add(root2);
|
|
3574
3615
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
3575
3616
|
};
|
|
3576
|
-
const
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
const
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3617
|
+
const walk2 = (kind, roots) => {
|
|
3618
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
3619
|
+
const queue = [];
|
|
3620
|
+
const visit = (dir, by, range) => {
|
|
3621
|
+
const manifest = readManifest(dir);
|
|
3622
|
+
if (!manifest?.name) return;
|
|
3623
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
3624
|
+
const realDir = real(dir);
|
|
3625
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
3626
|
+
if (expanded.has(realDir)) return;
|
|
3627
|
+
expanded.add(realDir);
|
|
3628
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
3629
|
+
};
|
|
3630
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
3631
|
+
while (queue.length) {
|
|
3632
|
+
const { real: from, manifest, label } = queue.shift();
|
|
3633
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
3634
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
3635
|
+
const dir = findPackageDir(from, name);
|
|
3636
|
+
if (dir) visit(dir, label, range);
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3586
3639
|
};
|
|
3587
|
-
const
|
|
3588
|
-
const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
3589
|
-
for (const name of Object.keys(appDeps)) {
|
|
3640
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
3590
3641
|
const dir = findPackageDir(root, name);
|
|
3591
|
-
|
|
3592
|
-
}
|
|
3593
|
-
const
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3642
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
3643
|
+
});
|
|
3644
|
+
const app = readManifest(root);
|
|
3645
|
+
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
3646
|
+
const runtimeDeps = {
|
|
3647
|
+
...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
|
|
3648
|
+
...app?.peerDependencies,
|
|
3649
|
+
...app?.optionalDependencies,
|
|
3650
|
+
...app?.dependencies
|
|
3651
|
+
};
|
|
3652
|
+
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
3653
|
+
walk2("runtime", rootsOf(runtimeDeps, "the app"));
|
|
3654
|
+
const top = path32.join(root, "node_modules");
|
|
3655
|
+
walk2(
|
|
3656
|
+
"hoisted",
|
|
3657
|
+
packagesIn(top).filter((dir) => {
|
|
3658
|
+
const name = path32.relative(top, dir).split(path32.sep).join("/");
|
|
3659
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
3660
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
3661
|
+
);
|
|
3662
|
+
const devRoots = { ...devDeps };
|
|
3663
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
3664
|
+
walk2("dev", rootsOf(devRoots, "the app (dev)"));
|
|
3665
|
+
for (const [key2, copy] of copies) {
|
|
3666
|
+
const kinds = via.get(key2);
|
|
3667
|
+
copy.runtime = kinds.has("runtime");
|
|
3668
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
3605
3669
|
}
|
|
3606
3670
|
const byName = /* @__PURE__ */ new Map();
|
|
3607
3671
|
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
@@ -3609,20 +3673,31 @@ function genesisInstalls(root) {
|
|
|
3609
3673
|
return byName;
|
|
3610
3674
|
}
|
|
3611
3675
|
function checkDuplicatePackages(ctx) {
|
|
3676
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
3612
3677
|
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
3613
3678
|
if (copies.length < 2) continue;
|
|
3614
|
-
const
|
|
3679
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
3680
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
3681
|
+
ctx.report({
|
|
3682
|
+
rule: "duplicate-genesis-package",
|
|
3683
|
+
level: "warn",
|
|
3684
|
+
file: "package.json",
|
|
3685
|
+
subject: name,
|
|
3686
|
+
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`
|
|
3687
|
+
});
|
|
3688
|
+
continue;
|
|
3689
|
+
}
|
|
3615
3690
|
ctx.report({
|
|
3616
3691
|
rule: "duplicate-genesis-package",
|
|
3617
|
-
level: "
|
|
3692
|
+
level: "info",
|
|
3618
3693
|
file: "package.json",
|
|
3619
3694
|
subject: name,
|
|
3620
|
-
message: `${name}
|
|
3695
|
+
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
3696
|
});
|
|
3622
3697
|
}
|
|
3623
3698
|
}
|
|
3624
3699
|
function checkPeerRanges(ctx) {
|
|
3625
|
-
const rel = (abs) =>
|
|
3700
|
+
const rel = (abs) => path32.relative(ctx.root, abs).split(path32.sep).join("/");
|
|
3626
3701
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
3627
3702
|
for (const copy of copies) {
|
|
3628
3703
|
const dir = copy.absolutePath;
|
|
@@ -3635,7 +3710,8 @@ function checkPeerRanges(ctx) {
|
|
|
3635
3710
|
if (satisfies(installed, range) !== false) continue;
|
|
3636
3711
|
ctx.report({
|
|
3637
3712
|
rule: "peer-range-mismatch",
|
|
3638
|
-
|
|
3713
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
3714
|
+
level: copy.devOnly ? "info" : "warn",
|
|
3639
3715
|
file: "package.json",
|
|
3640
3716
|
subject: `${copy.name}>${peer}`,
|
|
3641
3717
|
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 +3720,17 @@ function checkPeerRanges(ctx) {
|
|
|
3644
3720
|
}
|
|
3645
3721
|
}
|
|
3646
3722
|
}
|
|
3647
|
-
var GENESIS, readManifest, real;
|
|
3723
|
+
var GENESIS, DEV_TOOLS, NON_SHIPPING, readManifest, real;
|
|
3648
3724
|
var init_installs = __esm({
|
|
3649
3725
|
"src/doctor/installs.ts"() {
|
|
3650
3726
|
init_genesis();
|
|
3651
3727
|
init_semver();
|
|
3652
3728
|
GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
3729
|
+
DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
3730
|
+
NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
3653
3731
|
readManifest = (dir) => {
|
|
3654
3732
|
try {
|
|
3655
|
-
return JSON.parse(readFileSync(
|
|
3733
|
+
return JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
|
|
3656
3734
|
} catch {
|
|
3657
3735
|
return null;
|
|
3658
3736
|
}
|
|
@@ -3666,68 +3744,495 @@ var init_installs = __esm({
|
|
|
3666
3744
|
};
|
|
3667
3745
|
}
|
|
3668
3746
|
});
|
|
3747
|
+
function stripForImports(code) {
|
|
3748
|
+
const out = [];
|
|
3749
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
3750
|
+
const n = code.length;
|
|
3751
|
+
const templates = [];
|
|
3752
|
+
let depth = 0;
|
|
3753
|
+
let i = 0;
|
|
3754
|
+
let sure = true;
|
|
3755
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
3756
|
+
const before = () => out.slice(-24).join("");
|
|
3757
|
+
const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
|
|
3758
|
+
const startsExpression = (b) => {
|
|
3759
|
+
const t = b.replace(/\s+$/, "");
|
|
3760
|
+
if (!t) return true;
|
|
3761
|
+
if (KEYWORD.test(b)) return true;
|
|
3762
|
+
return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
|
|
3763
|
+
};
|
|
3764
|
+
const exprStart = () => startsExpression(before());
|
|
3765
|
+
const taggedTemplate = () => {
|
|
3766
|
+
const b = out.slice(-48).join("");
|
|
3767
|
+
const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
|
|
3768
|
+
return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
|
|
3769
|
+
};
|
|
3770
|
+
const templateBody = () => {
|
|
3771
|
+
while (i < n) {
|
|
3772
|
+
const ch = code[i];
|
|
3773
|
+
if (ch === "\\") {
|
|
3774
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
3775
|
+
i += 2;
|
|
3776
|
+
} else if (ch === "`") {
|
|
3777
|
+
out.push("`");
|
|
3778
|
+
i++;
|
|
3779
|
+
return;
|
|
3780
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
3781
|
+
out.push("${");
|
|
3782
|
+
i += 2;
|
|
3783
|
+
templates.push(depth);
|
|
3784
|
+
depth++;
|
|
3785
|
+
return;
|
|
3786
|
+
} else {
|
|
3787
|
+
out.push(blank(ch));
|
|
3788
|
+
i++;
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3791
|
+
sure = false;
|
|
3792
|
+
};
|
|
3793
|
+
while (i < n && sure) {
|
|
3794
|
+
const ch = code[i];
|
|
3795
|
+
const next = code[i + 1];
|
|
3796
|
+
if (ch === "/" && next === "/") {
|
|
3797
|
+
while (i < n && code[i] !== "\n") {
|
|
3798
|
+
out.push(" ");
|
|
3799
|
+
i++;
|
|
3800
|
+
}
|
|
3801
|
+
} else if (ch === "/" && next === "*") {
|
|
3802
|
+
out.push(" ");
|
|
3803
|
+
i += 2;
|
|
3804
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
3805
|
+
out.push(blank(code[i]));
|
|
3806
|
+
i++;
|
|
3807
|
+
}
|
|
3808
|
+
if (i < n) {
|
|
3809
|
+
out.push(" ");
|
|
3810
|
+
i += 2;
|
|
3811
|
+
}
|
|
3812
|
+
} else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
|
|
3813
|
+
const afterBrace = /[}>]\s*$/.test(before());
|
|
3814
|
+
const start = i;
|
|
3815
|
+
const mark = out.length;
|
|
3816
|
+
out.push("/");
|
|
3817
|
+
i++;
|
|
3818
|
+
let inClass = false;
|
|
3819
|
+
for (; ; ) {
|
|
3820
|
+
const c = code[i];
|
|
3821
|
+
if (c === void 0 || c === "\n") {
|
|
3822
|
+
if (afterBrace) {
|
|
3823
|
+
out.length = mark;
|
|
3824
|
+
out.push("/");
|
|
3825
|
+
i = start + 1;
|
|
3826
|
+
} else sure = false;
|
|
3827
|
+
break;
|
|
3828
|
+
}
|
|
3829
|
+
if (c === "\\") {
|
|
3830
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
3831
|
+
i += 2;
|
|
3832
|
+
continue;
|
|
3833
|
+
}
|
|
3834
|
+
i++;
|
|
3835
|
+
if (c === "[") inClass = true;
|
|
3836
|
+
else if (c === "]") inClass = false;
|
|
3837
|
+
else if (c === "/" && !inClass) {
|
|
3838
|
+
if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
|
|
3839
|
+
out.length = mark;
|
|
3840
|
+
out.push("/");
|
|
3841
|
+
i = start + 1;
|
|
3842
|
+
break;
|
|
3843
|
+
}
|
|
3844
|
+
out.push("/");
|
|
3845
|
+
break;
|
|
3846
|
+
}
|
|
3847
|
+
out.push(" ");
|
|
3848
|
+
}
|
|
3849
|
+
if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
|
|
3850
|
+
} else if ((ch === '"' || ch === "'") && exprStart()) {
|
|
3851
|
+
const keep = isSpecifier();
|
|
3852
|
+
out.push(ch);
|
|
3853
|
+
i++;
|
|
3854
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
3855
|
+
if (code[i] === "\\") {
|
|
3856
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
3857
|
+
i += 2;
|
|
3858
|
+
} else {
|
|
3859
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
3860
|
+
i++;
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
if (code[i] !== ch) sure = false;
|
|
3864
|
+
else {
|
|
3865
|
+
out.push(code[i]);
|
|
3866
|
+
i++;
|
|
3867
|
+
}
|
|
3868
|
+
} else if (ch === "`" && (exprStart() || taggedTemplate())) {
|
|
3869
|
+
out.push("`");
|
|
3870
|
+
i++;
|
|
3871
|
+
templateBody();
|
|
3872
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
3873
|
+
templates.pop();
|
|
3874
|
+
depth--;
|
|
3875
|
+
out.push("}");
|
|
3876
|
+
i++;
|
|
3877
|
+
templateBody();
|
|
3878
|
+
} else {
|
|
3879
|
+
if (ch === "{") depth++;
|
|
3880
|
+
else if (ch === "}") depth--;
|
|
3881
|
+
out.push(ch);
|
|
3882
|
+
i++;
|
|
3883
|
+
}
|
|
3884
|
+
}
|
|
3885
|
+
return sure && templates.length === 0 ? out.join("") : null;
|
|
3886
|
+
}
|
|
3887
|
+
function bindings(clause) {
|
|
3888
|
+
const out = [];
|
|
3889
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
3890
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
3891
|
+
const p = part.trim();
|
|
3892
|
+
if (!p || p.startsWith("type ")) continue;
|
|
3893
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
3894
|
+
}
|
|
3895
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
3896
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
3897
|
+
if (ns) out.push(ns[1]);
|
|
3898
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
3899
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
3900
|
+
return out;
|
|
3901
|
+
}
|
|
3902
|
+
function readJsonc(file) {
|
|
3903
|
+
try {
|
|
3904
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
3905
|
+
return JSON.parse(text);
|
|
3906
|
+
} catch {
|
|
3907
|
+
return null;
|
|
3908
|
+
}
|
|
3909
|
+
}
|
|
3910
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
3911
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
3912
|
+
seen.add(file);
|
|
3913
|
+
const json = readJsonc(file);
|
|
3914
|
+
if (!json) return {};
|
|
3915
|
+
const dir = path32.dirname(file);
|
|
3916
|
+
let merged = {};
|
|
3917
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3918
|
+
for (const ext of parents) {
|
|
3919
|
+
if (typeof ext !== "string") continue;
|
|
3920
|
+
let target = null;
|
|
3921
|
+
if (ext.startsWith(".") || path32.isAbsolute(ext)) {
|
|
3922
|
+
const abs = path32.resolve(dir, ext);
|
|
3923
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3924
|
+
} else {
|
|
3925
|
+
const parts = ext.split("/");
|
|
3926
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
3927
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3928
|
+
if (pkgDir) {
|
|
3929
|
+
const sub = parts.slice(nameLength).join("/");
|
|
3930
|
+
const abs = path32.join(pkgDir, sub || "tsconfig.json");
|
|
3931
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3935
|
+
}
|
|
3936
|
+
const opts = json.compilerOptions ?? {};
|
|
3937
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path32.resolve(dir, opts.baseUrl);
|
|
3938
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
3939
|
+
merged.paths = opts.paths;
|
|
3940
|
+
merged.pathsDir = dir;
|
|
3941
|
+
}
|
|
3942
|
+
return merged;
|
|
3943
|
+
}
|
|
3944
|
+
function aliases(root) {
|
|
3945
|
+
const table = [];
|
|
3946
|
+
let baseUrl = null;
|
|
3947
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3948
|
+
const file = path32.join(root, name);
|
|
3949
|
+
if (!existsSync(file)) continue;
|
|
3950
|
+
const config = readTsconfig(root, file);
|
|
3951
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
3952
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
3953
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3954
|
+
if (!Array.isArray(targets)) continue;
|
|
3955
|
+
const exact = !pattern.endsWith("*");
|
|
3956
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path32.join(base, String(t).replace(/\*$/, ""))) });
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
const pkg = readJsonc(path32.join(root, "package.json"));
|
|
3960
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3961
|
+
if (typeof target !== "string") continue;
|
|
3962
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path32.join(root, target.replace(/\*.*$/, ""))] });
|
|
3963
|
+
}
|
|
3964
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path32.join(root, "src") + path32.sep, root + path32.sep] });
|
|
3965
|
+
return { table, baseUrl };
|
|
3966
|
+
}
|
|
3967
|
+
function resolveFile(base) {
|
|
3968
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path32.join(base, `index${e}`))];
|
|
3969
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3970
|
+
for (const p of tries) {
|
|
3971
|
+
if (SCRIPT_EXTS2.has(path32.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3972
|
+
}
|
|
3973
|
+
return null;
|
|
3974
|
+
}
|
|
3975
|
+
function trailFor(ctx) {
|
|
3976
|
+
let t = trails.get(ctx.files);
|
|
3977
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
3978
|
+
return t;
|
|
3979
|
+
}
|
|
3980
|
+
function createTrail(ctx) {
|
|
3981
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
3982
|
+
let declared = null;
|
|
3983
|
+
try {
|
|
3984
|
+
const pkg = JSON.parse(readFileSync(path32.join(ctx.root, "package.json"), "utf8"));
|
|
3985
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3986
|
+
} catch {
|
|
3987
|
+
declared = null;
|
|
3988
|
+
}
|
|
3989
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
3990
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
3991
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
3992
|
+
const importsOf = (file) => {
|
|
3993
|
+
const hit = importsCache.get(file.absolutePath);
|
|
3994
|
+
if (hit) return hit;
|
|
3995
|
+
const files = [];
|
|
3996
|
+
let lost = false;
|
|
3997
|
+
const code = stripped(file);
|
|
3998
|
+
if (code === null) {
|
|
3999
|
+
const out2 = { files: [], lost: true };
|
|
4000
|
+
importsCache.set(file.absolutePath, out2);
|
|
4001
|
+
return out2;
|
|
4002
|
+
}
|
|
4003
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
4004
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
4005
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
4006
|
+
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]);
|
|
4007
|
+
const specs = [];
|
|
4008
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
4009
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
4010
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
4011
|
+
for (const spec of specs) {
|
|
4012
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
4013
|
+
let resolved = null;
|
|
4014
|
+
if (spec.startsWith(".")) {
|
|
4015
|
+
resolved = resolveFile(path32.resolve(path32.dirname(file.absolutePath), spec));
|
|
4016
|
+
if (!resolved) lost = true;
|
|
4017
|
+
} else {
|
|
4018
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
4019
|
+
if (alias) {
|
|
4020
|
+
for (const t of alias.targets) {
|
|
4021
|
+
resolved = resolveFile(alias.exact ? t : path32.join(t, spec.slice(alias.prefix.length)));
|
|
4022
|
+
if (resolved) break;
|
|
4023
|
+
}
|
|
4024
|
+
}
|
|
4025
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path32.join(baseUrl, spec));
|
|
4026
|
+
if (!resolved) {
|
|
4027
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
4028
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
4032
|
+
}
|
|
4033
|
+
const out = { files, lost };
|
|
4034
|
+
importsCache.set(file.absolutePath, out);
|
|
4035
|
+
return out;
|
|
4036
|
+
};
|
|
4037
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
4038
|
+
const stripped = (file) => {
|
|
4039
|
+
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
4040
|
+
return strippedCache.get(file.absolutePath);
|
|
4041
|
+
};
|
|
4042
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
4043
|
+
const reach = (file, test2, depth, seen) => {
|
|
4044
|
+
let cache = memo.get(test2);
|
|
4045
|
+
if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
4046
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
4047
|
+
const free = cache.free.get(k);
|
|
4048
|
+
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
4049
|
+
const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
4050
|
+
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
4051
|
+
let result;
|
|
4052
|
+
const cut = /* @__PURE__ */ new Set();
|
|
4053
|
+
const code = stripped(file);
|
|
4054
|
+
if (code === null) result = "unknown";
|
|
4055
|
+
else if (test2(code)) result = "yes";
|
|
4056
|
+
else {
|
|
4057
|
+
const { files, lost } = importsOf(file);
|
|
4058
|
+
let unknown = lost && depth > 0;
|
|
4059
|
+
result = "no";
|
|
4060
|
+
if (depth > 0) {
|
|
4061
|
+
seen.add(file.absolutePath);
|
|
4062
|
+
for (const abs of files) {
|
|
4063
|
+
if (seen.has(abs)) {
|
|
4064
|
+
cut.add(abs);
|
|
4065
|
+
continue;
|
|
4066
|
+
}
|
|
4067
|
+
const target = read(abs);
|
|
4068
|
+
if (!target) {
|
|
4069
|
+
unknown = true;
|
|
4070
|
+
continue;
|
|
4071
|
+
}
|
|
4072
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
4073
|
+
for (const m of c) cut.add(m);
|
|
4074
|
+
if (r === "yes") {
|
|
4075
|
+
result = "yes";
|
|
4076
|
+
break;
|
|
4077
|
+
}
|
|
4078
|
+
if (r === "unknown") unknown = true;
|
|
4079
|
+
}
|
|
4080
|
+
seen.delete(file.absolutePath);
|
|
4081
|
+
cut.delete(file.absolutePath);
|
|
4082
|
+
}
|
|
4083
|
+
if (result === "no" && unknown) result = "unknown";
|
|
4084
|
+
}
|
|
4085
|
+
if (result === "yes" || cut.size === 0) {
|
|
4086
|
+
cache.free.set(k, result);
|
|
4087
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
4088
|
+
}
|
|
4089
|
+
const entries = cache.cut.get(k) ?? [];
|
|
4090
|
+
entries.push({ cut: [...cut], result });
|
|
4091
|
+
cache.cut.set(k, entries);
|
|
4092
|
+
return [result, cut];
|
|
4093
|
+
};
|
|
4094
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
4095
|
+
}
|
|
4096
|
+
var TRAIL_DEPTH, RESOLVE_EXTS2, IMPORT_FROM, EXPORT_FROM, DYNAMIC, trails;
|
|
4097
|
+
var init_trail = __esm({
|
|
4098
|
+
"src/doctor/trail.ts"() {
|
|
4099
|
+
init_genesis();
|
|
4100
|
+
init_source();
|
|
4101
|
+
TRAIL_DEPTH = 6;
|
|
4102
|
+
RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
4103
|
+
IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
4104
|
+
EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
4105
|
+
DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
4106
|
+
trails = /* @__PURE__ */ new WeakMap();
|
|
4107
|
+
}
|
|
4108
|
+
});
|
|
3669
4109
|
function routesDir(ctx) {
|
|
3670
4110
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3671
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
4111
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path32.join(ctx.root, d))) ?? null;
|
|
4112
|
+
}
|
|
4113
|
+
function flavorOf(dir, rels) {
|
|
4114
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
4115
|
+
if (stems.includes("__root")) return "tanstack";
|
|
4116
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
4117
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
4118
|
+
return "tanstack";
|
|
4119
|
+
}
|
|
4120
|
+
function renders(code) {
|
|
4121
|
+
const elements = renderedElements(code);
|
|
4122
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
4123
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
4124
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
4125
|
+
if (named && !definedHere(named)) return true;
|
|
4126
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
4127
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
4128
|
+
return exported !== void 0 && !definedHere(exported);
|
|
3672
4129
|
}
|
|
3673
4130
|
function webRoutes(ctx) {
|
|
3674
4131
|
const dir = routesDir(ctx);
|
|
3675
4132
|
if (!dir) return [];
|
|
3676
|
-
const
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
4133
|
+
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(/\.[^.]+$/, "") }));
|
|
4134
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
4135
|
+
const stems = STEMS[flavor];
|
|
4136
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4137
|
+
for (const { file, rel } of candidates) {
|
|
3680
4138
|
const parts = rel.split("/");
|
|
3681
4139
|
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
4140
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
4141
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
4142
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
4143
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
4144
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
4145
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
4146
|
+
}
|
|
4147
|
+
const trail = trailFor(ctx);
|
|
4148
|
+
const routes = [];
|
|
4149
|
+
for (const [id, files] of groups) {
|
|
4150
|
+
const parts = id.split("/");
|
|
3682
4151
|
const stem = parts.pop();
|
|
3683
|
-
const
|
|
3684
|
-
|
|
3685
|
-
|
|
4152
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
4153
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
4154
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
4155
|
+
const segments = [...folders, ...own];
|
|
4156
|
+
const tree = [...parts, ...own];
|
|
4157
|
+
let index = stems.index.has(stem);
|
|
4158
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
3686
4159
|
segments.pop();
|
|
4160
|
+
tree.pop();
|
|
3687
4161
|
index = true;
|
|
3688
4162
|
}
|
|
3689
|
-
const
|
|
3690
|
-
const
|
|
4163
|
+
const code = files.map((f) => f.code).join("\n");
|
|
4164
|
+
const elements = renderedElements(code);
|
|
4165
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
4166
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
4167
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
4168
|
+
const rendering = renders(code);
|
|
4169
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
4170
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
4171
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
3691
4172
|
routes.push({
|
|
3692
|
-
file,
|
|
4173
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
4174
|
+
files,
|
|
3693
4175
|
segments,
|
|
4176
|
+
tree,
|
|
3694
4177
|
index,
|
|
3695
4178
|
layout,
|
|
3696
|
-
|
|
3697
|
-
|
|
4179
|
+
page,
|
|
4180
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
4181
|
+
redirectOnly: !rendering,
|
|
3698
4182
|
parents: []
|
|
3699
4183
|
});
|
|
3700
4184
|
}
|
|
3701
4185
|
for (const r of routes) {
|
|
3702
|
-
const own = r.
|
|
4186
|
+
const own = r.tree;
|
|
3703
4187
|
for (const p of routes) {
|
|
3704
4188
|
if (p === r || !p.layout) continue;
|
|
3705
|
-
const n = p.
|
|
4189
|
+
const n = p.tree.length;
|
|
3706
4190
|
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.
|
|
4191
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
4192
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
3709
4193
|
r.parents.push(p);
|
|
3710
4194
|
}
|
|
3711
|
-
r.parents.sort((a, b) => b.
|
|
4195
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
3712
4196
|
}
|
|
3713
4197
|
return routes;
|
|
3714
4198
|
}
|
|
3715
|
-
var ROUTES_DIR_CANDIDATES,
|
|
4199
|
+
var ROUTES_DIR_CANDIDATES, STEMS, NON_PAGE_ELEMENTS, HTML_ELEMENT, COMPONENT_OPTION, RENDERS_OUTLET, OWN_CONTENT, key;
|
|
3716
4200
|
var init_routes = __esm({
|
|
3717
4201
|
"src/doctor/routes.ts"() {
|
|
3718
4202
|
init_source();
|
|
4203
|
+
init_trail();
|
|
3719
4204
|
ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3720
|
-
|
|
3721
|
-
|
|
4205
|
+
STEMS = {
|
|
4206
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
4207
|
+
"next-app": {
|
|
4208
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
4209
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
4210
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
4211
|
+
},
|
|
4212
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
4213
|
+
};
|
|
3722
4214
|
NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
3723
4215
|
HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
4216
|
+
COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
4217
|
+
RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
4218
|
+
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
4219
|
key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3725
4220
|
}
|
|
3726
4221
|
});
|
|
3727
4222
|
|
|
3728
4223
|
// src/doctor/structure.ts
|
|
4224
|
+
function routeReach(ctx, r, test2) {
|
|
4225
|
+
const trail = trailFor(ctx);
|
|
4226
|
+
let unknown = false;
|
|
4227
|
+
for (const f of r.files) {
|
|
4228
|
+
const got = trail.reach(f, test2);
|
|
4229
|
+
if (got === "yes") return "yes";
|
|
4230
|
+
if (got === "unknown") unknown = true;
|
|
4231
|
+
}
|
|
4232
|
+
return unknown ? "unknown" : "no";
|
|
4233
|
+
}
|
|
3729
4234
|
function insideShell(ctx, routes) {
|
|
3730
|
-
const shell = new Set(routes.filter((r) =>
|
|
4235
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
3731
4236
|
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
3732
4237
|
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
3733
4238
|
}
|
|
@@ -3738,20 +4243,19 @@ function checkHandRolledSubNav(ctx) {
|
|
|
3738
4243
|
const inShell = insideShell(ctx, routes);
|
|
3739
4244
|
const ui = ctx.genesis.uiPackage;
|
|
3740
4245
|
for (const r of routes) {
|
|
3741
|
-
if (!inShell(r)) continue;
|
|
3742
|
-
const
|
|
3743
|
-
if (
|
|
3744
|
-
|
|
3745
|
-
|
|
4246
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
4247
|
+
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);
|
|
4248
|
+
if (hit) {
|
|
4249
|
+
const { f, m } = hit;
|
|
4250
|
+
const code = f.code;
|
|
3746
4251
|
ctx.report({
|
|
3747
4252
|
rule: "hand-rolled-sub-nav",
|
|
3748
4253
|
level: "warn",
|
|
3749
|
-
file:
|
|
4254
|
+
file: f.path,
|
|
3750
4255
|
line: lineAt(code, m.index),
|
|
3751
4256
|
subject: m[1],
|
|
3752
4257
|
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
4258
|
});
|
|
3754
|
-
break;
|
|
3755
4259
|
}
|
|
3756
4260
|
}
|
|
3757
4261
|
}
|
|
@@ -3799,11 +4303,12 @@ function checkResourceWorkspaces(ctx) {
|
|
|
3799
4303
|
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
3800
4304
|
}
|
|
3801
4305
|
for (const [dir, routes] of byFolder) {
|
|
3802
|
-
const
|
|
4306
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
4307
|
+
const has2 = routes.filter((r) => reach.get(r) === "yes");
|
|
3803
4308
|
if (has2.length === 0) continue;
|
|
3804
4309
|
const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
3805
4310
|
for (const r of routes) {
|
|
3806
|
-
if (
|
|
4311
|
+
if (reach.get(r) !== "no") continue;
|
|
3807
4312
|
ctx.report({
|
|
3808
4313
|
rule: "resource-workspace",
|
|
3809
4314
|
level: "info",
|
|
@@ -3827,14 +4332,14 @@ function checkPageLayouts(ctx) {
|
|
|
3827
4332
|
};
|
|
3828
4333
|
const cache = /* @__PURE__ */ new Map();
|
|
3829
4334
|
const provides = (r) => {
|
|
3830
|
-
if (!cache.has(r)) cache.set(r,
|
|
4335
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
3831
4336
|
return cache.get(r);
|
|
3832
4337
|
};
|
|
3833
4338
|
const list = [...layouts].sort();
|
|
3834
4339
|
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
3835
4340
|
for (const r of routes) {
|
|
3836
|
-
if (r.
|
|
3837
|
-
if (provides(r) || r.parents.some(provides)) continue;
|
|
4341
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
4342
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
3838
4343
|
ctx.report({
|
|
3839
4344
|
rule: "page-layout",
|
|
3840
4345
|
level: "warn",
|
|
@@ -3843,12 +4348,13 @@ function checkPageLayouts(ctx) {
|
|
|
3843
4348
|
});
|
|
3844
4349
|
}
|
|
3845
4350
|
}
|
|
3846
|
-
var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, PACKAGE_SCREEN, isNative, rendersRe;
|
|
4351
|
+
var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, PACKAGE_SCREEN, isNative, rendersRe, routeVia;
|
|
3847
4352
|
var init_structure = __esm({
|
|
3848
4353
|
"src/doctor/structure.ts"() {
|
|
3849
4354
|
init_scan();
|
|
3850
4355
|
init_routes();
|
|
3851
4356
|
init_source();
|
|
4357
|
+
init_trail();
|
|
3852
4358
|
SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
|
|
3853
4359
|
CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
|
|
3854
4360
|
SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
@@ -3861,6 +4367,7 @@ var init_structure = __esm({
|
|
|
3861
4367
|
const list = [...names];
|
|
3862
4368
|
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
3863
4369
|
};
|
|
4370
|
+
routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
3864
4371
|
}
|
|
3865
4372
|
});
|
|
3866
4373
|
|
|
@@ -3920,7 +4427,7 @@ __export(doctor_exports, {
|
|
|
3920
4427
|
webRoutes: () => webRoutes
|
|
3921
4428
|
});
|
|
3922
4429
|
async function runDoctor(options = {}) {
|
|
3923
|
-
const root =
|
|
4430
|
+
const root = path32.resolve(options.root ?? process.cwd());
|
|
3924
4431
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
3925
4432
|
const config = loaded.config;
|
|
3926
4433
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -4108,20 +4615,20 @@ function readObject(file, key2) {
|
|
|
4108
4615
|
}
|
|
4109
4616
|
}
|
|
4110
4617
|
function settings(root, options) {
|
|
4111
|
-
const fromPackage = readObject(
|
|
4112
|
-
const fromConfig = readObject(
|
|
4618
|
+
const fromPackage = readObject(path32.join(root, "package.json"), "genesisFeatures");
|
|
4619
|
+
const fromConfig = readObject(path32.join(root, "genesis.config.json"), "features");
|
|
4113
4620
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
4114
4621
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
4115
4622
|
}
|
|
4116
4623
|
async function loadRegistry(input) {
|
|
4117
|
-
const root =
|
|
4624
|
+
const root = path32.resolve(input.dir);
|
|
4118
4625
|
const options = settings(root, input);
|
|
4119
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
4120
|
-
if (!registry || !existsSync(
|
|
4626
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path32.join(root, p)));
|
|
4627
|
+
if (!registry || !existsSync(path32.join(root, registry))) {
|
|
4121
4628
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
4122
4629
|
}
|
|
4123
|
-
const jiti = createJiti(
|
|
4124
|
-
const load = async (file) => await jiti.import(
|
|
4630
|
+
const jiti = createJiti(path32.join(root, "package.json"), { moduleCache: false });
|
|
4631
|
+
const load = async (file) => await jiti.import(path32.join(root, file));
|
|
4125
4632
|
const mod = await load(registry);
|
|
4126
4633
|
const features2 = mod.features ?? mod.default;
|
|
4127
4634
|
if (!isObject3(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -4133,7 +4640,7 @@ async function loadRegistry(input) {
|
|
|
4133
4640
|
const project = {
|
|
4134
4641
|
...rest,
|
|
4135
4642
|
root,
|
|
4136
|
-
source: options.source ?? registry.split(
|
|
4643
|
+
source: options.source ?? registry.split(path32.sep).join("/"),
|
|
4137
4644
|
features: features2,
|
|
4138
4645
|
flags
|
|
4139
4646
|
};
|
|
@@ -4662,9 +5169,9 @@ function ownedKeyProblem(key2, source) {
|
|
|
4662
5169
|
return `${key2} doesn't match its source ${source}`;
|
|
4663
5170
|
}
|
|
4664
5171
|
function mergeThreeWay(mine, base, theirs) {
|
|
4665
|
-
const dir = mkdtempSync(
|
|
5172
|
+
const dir = mkdtempSync(path32.join(tmpdir(), "genesis-merge-"));
|
|
4666
5173
|
try {
|
|
4667
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
5174
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path32.join(dir, n));
|
|
4668
5175
|
writeFileSync(m, mine);
|
|
4669
5176
|
writeFileSync(b, base);
|
|
4670
5177
|
writeFileSync(t, theirs);
|
|
@@ -4833,12 +5340,12 @@ var init_registry_edit = __esm({
|
|
|
4833
5340
|
});
|
|
4834
5341
|
function routerRoot2(root) {
|
|
4835
5342
|
try {
|
|
4836
|
-
const config = JSON.parse(readFileSync(
|
|
5343
|
+
const config = JSON.parse(readFileSync(path32.join(root, "genesis.config.json"), "utf8"));
|
|
4837
5344
|
const configured = config.doctor?.native?.routerRoot;
|
|
4838
|
-
if (configured && existsSync(
|
|
5345
|
+
if (configured && existsSync(path32.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
4839
5346
|
} catch {
|
|
4840
5347
|
}
|
|
4841
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
5348
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path32.join(root, dir, "_layout.tsx"))) return dir;
|
|
4842
5349
|
return null;
|
|
4843
5350
|
}
|
|
4844
5351
|
function routeOf(file) {
|
|
@@ -4899,7 +5406,7 @@ __export(add_exports, {
|
|
|
4899
5406
|
});
|
|
4900
5407
|
function appDependencies(root) {
|
|
4901
5408
|
try {
|
|
4902
|
-
const pkg = JSON.parse(readFileSync(
|
|
5409
|
+
const pkg = JSON.parse(readFileSync(path32.join(root, "package.json"), "utf8"));
|
|
4903
5410
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
4904
5411
|
} catch {
|
|
4905
5412
|
return {};
|
|
@@ -4908,14 +5415,14 @@ function appDependencies(root) {
|
|
|
4908
5415
|
function registryFile(root) {
|
|
4909
5416
|
const read = (file, key2) => {
|
|
4910
5417
|
try {
|
|
4911
|
-
const v = JSON.parse(readFileSync(
|
|
5418
|
+
const v = JSON.parse(readFileSync(path32.join(root, file), "utf8"))[key2]?.registry;
|
|
4912
5419
|
return typeof v === "string" ? v : void 0;
|
|
4913
5420
|
} catch {
|
|
4914
5421
|
return void 0;
|
|
4915
5422
|
}
|
|
4916
5423
|
};
|
|
4917
5424
|
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(
|
|
5425
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path32.join(root, candidate))) return candidate;
|
|
4919
5426
|
return null;
|
|
4920
5427
|
}
|
|
4921
5428
|
async function registryIds(root, file) {
|
|
@@ -4992,7 +5499,7 @@ verify_jwt = false
|
|
|
4992
5499
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
4993
5500
|
}
|
|
4994
5501
|
async function runAdd(options) {
|
|
4995
|
-
const root =
|
|
5502
|
+
const root = path32.resolve(options.root);
|
|
4996
5503
|
const log = options.log ?? SILENT;
|
|
4997
5504
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
4998
5505
|
const warnings = [];
|
|
@@ -5167,7 +5674,7 @@ __export(migrate_exports, {
|
|
|
5167
5674
|
runMigrate: () => runMigrate
|
|
5168
5675
|
});
|
|
5169
5676
|
async function runMigrate(options) {
|
|
5170
|
-
const root =
|
|
5677
|
+
const root = path32.resolve(options.root);
|
|
5171
5678
|
const lock = readLock(root);
|
|
5172
5679
|
const warnings = [];
|
|
5173
5680
|
const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks), ...options.blocks ?? []])];
|
|
@@ -5327,11 +5834,11 @@ function npmLookup(cwd) {
|
|
|
5327
5834
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
5328
5835
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
5329
5836
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
5330
|
-
const tmp = mkdtempSync(
|
|
5837
|
+
const tmp = mkdtempSync(path32.join(tmpdir(), "genesis-umbrella-"));
|
|
5331
5838
|
try {
|
|
5332
5839
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
5333
|
-
execFileSync("tar", ["-xzf",
|
|
5334
|
-
const manifest = JSON.parse(readFileSync(
|
|
5840
|
+
execFileSync("tar", ["-xzf", path32.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
5841
|
+
const manifest = JSON.parse(readFileSync(path32.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
5335
5842
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
5336
5843
|
return manifest;
|
|
5337
5844
|
} finally {
|
|
@@ -5358,7 +5865,7 @@ function packageJsons(root) {
|
|
|
5358
5865
|
if (files.length) return files;
|
|
5359
5866
|
} catch {
|
|
5360
5867
|
}
|
|
5361
|
-
return existsSync(
|
|
5868
|
+
return existsSync(path32.join(root, "package.json")) ? ["package.json"] : [];
|
|
5362
5869
|
}
|
|
5363
5870
|
function sourceText(root, source, substitutions) {
|
|
5364
5871
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -5377,11 +5884,11 @@ function sourceText(root, source, substitutions) {
|
|
|
5377
5884
|
}
|
|
5378
5885
|
}
|
|
5379
5886
|
async function runUpgrade(options) {
|
|
5380
|
-
const root =
|
|
5887
|
+
const root = path32.resolve(options.root);
|
|
5381
5888
|
const log = options.log ?? (() => {
|
|
5382
5889
|
});
|
|
5383
5890
|
const lookup = options.lookup ?? npmLookup(root);
|
|
5384
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
5891
|
+
const release = options.manifest ? JSON.parse(readFileSync(path32.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
5385
5892
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
5386
5893
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
5387
5894
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -5517,7 +6024,7 @@ function checkSubstitutions(substitutions) {
|
|
|
5517
6024
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
5518
6025
|
let allowed;
|
|
5519
6026
|
try {
|
|
5520
|
-
const was = starterIdentity(readFileSync(
|
|
6027
|
+
const was = starterIdentity(readFileSync(path32.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
5521
6028
|
allowed = [was.name, was.slug, was.scheme, was.bundleId];
|
|
5522
6029
|
} catch {
|
|
5523
6030
|
allowed = [];
|
|
@@ -5550,15 +6057,15 @@ function openPullRequest(root, version, report, base) {
|
|
|
5550
6057
|
git2("switch", "-c", branch);
|
|
5551
6058
|
const top = git2("rev-parse", "--show-toplevel");
|
|
5552
6059
|
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 ||
|
|
6060
|
+
for (let dir = path32.resolve(root); ; dir = path32.dirname(dir)) {
|
|
6061
|
+
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)));
|
|
6062
|
+
if (lockfiles.length || dir === top || path32.dirname(dir) === dir) break;
|
|
5556
6063
|
}
|
|
5557
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
6064
|
+
const paths = [...report.files.filter((f) => existsSync(path32.join(root, f))), ...lockfiles];
|
|
5558
6065
|
git2("add", "--", ...paths);
|
|
5559
6066
|
git2("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
5560
6067
|
git2("push", "-u", "origin", branch);
|
|
5561
|
-
const body =
|
|
6068
|
+
const body = path32.join(mkdtempSync(path32.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
5562
6069
|
writeFileSync(body, `${report.summary}
|
|
5563
6070
|
|
|
5564
6071
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -5681,9 +6188,9 @@ async function runScaffold(opts, fs2) {
|
|
|
5681
6188
|
function joinPath(...parts) {
|
|
5682
6189
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
5683
6190
|
}
|
|
5684
|
-
function dirname(
|
|
5685
|
-
const idx =
|
|
5686
|
-
return idx === -1 ? "." :
|
|
6191
|
+
function dirname(path33) {
|
|
6192
|
+
const idx = path33.lastIndexOf("/");
|
|
6193
|
+
return idx === -1 ? "." : path33.slice(0, idx);
|
|
5687
6194
|
}
|
|
5688
6195
|
function brandPackageJson(consumer, genesisVersion) {
|
|
5689
6196
|
return JSON.stringify(
|
|
@@ -5922,7 +6429,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
5922
6429
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
5923
6430
|
const result2 = await runInitNative2({
|
|
5924
6431
|
name: consumer,
|
|
5925
|
-
target:
|
|
6432
|
+
target: path32.resolve(opts.target ?? consumer),
|
|
5926
6433
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
5927
6434
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
5928
6435
|
...opts.scheme ? { scheme: opts.scheme } : {}
|
|
@@ -5932,7 +6439,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
5932
6439
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
5933
6440
|
console.log("");
|
|
5934
6441
|
console.log("Next steps:");
|
|
5935
|
-
[`cd ${
|
|
6442
|
+
[`cd ${path32.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
5936
6443
|
return;
|
|
5937
6444
|
}
|
|
5938
6445
|
opts.target ??= process.cwd();
|
|
@@ -5998,7 +6505,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
5998
6505
|
source = `Postgres (${schemas.join(", ")})`;
|
|
5999
6506
|
}
|
|
6000
6507
|
const content = emitContracts2(tables, { source });
|
|
6001
|
-
const target =
|
|
6508
|
+
const target = path32.resolve(opts.out);
|
|
6002
6509
|
if (opts.check) {
|
|
6003
6510
|
const current = await fs.readFile(target, "utf-8").catch(() => null);
|
|
6004
6511
|
if (current !== content) {
|
|
@@ -6013,7 +6520,7 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
6013
6520
|
});
|
|
6014
6521
|
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
6522
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
6016
|
-
const root =
|
|
6523
|
+
const root = path32.resolve(opts.dir);
|
|
6017
6524
|
try {
|
|
6018
6525
|
if (opts.printGenesis) {
|
|
6019
6526
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -6078,9 +6585,9 @@ featureOptions(
|
|
|
6078
6585
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
6079
6586
|
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
6587
|
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
6081
|
-
const root =
|
|
6082
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
6083
|
-
const
|
|
6588
|
+
const root = path32.resolve(opts.dir);
|
|
6589
|
+
const packageJson = JSON.parse(await fs.readFile(path32.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
6590
|
+
const existsSync26 = (await import('fs')).existsSync;
|
|
6084
6591
|
const readSync = (await import('fs')).readFileSync;
|
|
6085
6592
|
const readdirSync10 = (await import('fs')).readdirSync;
|
|
6086
6593
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
@@ -6089,13 +6596,13 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6089
6596
|
const plan = planStudioInit2(
|
|
6090
6597
|
{
|
|
6091
6598
|
packageJson,
|
|
6092
|
-
exists: (p) =>
|
|
6093
|
-
read: (p) =>
|
|
6599
|
+
exists: (p) => existsSync26(path32.join(root, p)),
|
|
6600
|
+
read: (p) => existsSync26(path32.join(root, p)) ? readSync(path32.join(root, p), "utf-8") : null,
|
|
6094
6601
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
6095
6602
|
listDeep: (p) => {
|
|
6096
6603
|
const out = [];
|
|
6097
6604
|
const walk2 = (rel) => {
|
|
6098
|
-
for (const entry of readdirSync10(
|
|
6605
|
+
for (const entry of readdirSync10(path32.join(root, rel), { withFileTypes: true })) {
|
|
6099
6606
|
const child = `${rel}/${entry.name}`;
|
|
6100
6607
|
if (entry.isDirectory()) walk2(child);
|
|
6101
6608
|
else out.push(child);
|
|
@@ -6109,7 +6616,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6109
6616
|
},
|
|
6110
6617
|
list: (p) => {
|
|
6111
6618
|
try {
|
|
6112
|
-
return readdirSync10(
|
|
6619
|
+
return readdirSync10(path32.join(root, p));
|
|
6113
6620
|
} catch {
|
|
6114
6621
|
return [];
|
|
6115
6622
|
}
|
|
@@ -6118,8 +6625,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6118
6625
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
6119
6626
|
);
|
|
6120
6627
|
for (const file of plan.files) {
|
|
6121
|
-
const target =
|
|
6122
|
-
await fs.mkdir(
|
|
6628
|
+
const target = path32.join(root, file.path);
|
|
6629
|
+
await fs.mkdir(path32.dirname(target), { recursive: true });
|
|
6123
6630
|
if (file.edit) {
|
|
6124
6631
|
await fs.writeFile(target, file.content, "utf-8");
|
|
6125
6632
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -6130,14 +6637,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
6130
6637
|
console.log(`+ ${file.path} (appended)`);
|
|
6131
6638
|
continue;
|
|
6132
6639
|
}
|
|
6133
|
-
if (
|
|
6640
|
+
if (existsSync26(target) && !opts.force) {
|
|
6134
6641
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
6135
6642
|
continue;
|
|
6136
6643
|
}
|
|
6137
6644
|
await fs.writeFile(target, file.content, "utf-8");
|
|
6138
6645
|
console.log(`+ ${file.path}`);
|
|
6139
6646
|
}
|
|
6140
|
-
const pm =
|
|
6647
|
+
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
6648
|
console.log("");
|
|
6142
6649
|
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
6650
|
console.log(` 1. ${pm} ${plan.install.join(" ")}`);
|
|
@@ -6155,7 +6662,7 @@ async function confirm(question) {
|
|
|
6155
6662
|
}
|
|
6156
6663
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
6157
6664
|
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 =
|
|
6665
|
+
const root = path32.resolve(opts.dir);
|
|
6159
6666
|
if (opts.list || !block) {
|
|
6160
6667
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
6161
6668
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -6184,7 +6691,7 @@ program.command("add").description("Add a block (a feature an app adds whole) fr
|
|
|
6184
6691
|
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
6692
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
6186
6693
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
6187
|
-
const report = await runMigrate2({ root:
|
|
6694
|
+
const report = await runMigrate2({ root: path32.resolve(opts.dir), ...opts.block ? { blocks: opts.block } : {}, dryRun: opts.dryRun, forward: opts.forward });
|
|
6188
6695
|
for (const w of report.warnings) logger.warn(w);
|
|
6189
6696
|
console.log(formatMigrationRows2(report.plan.rows));
|
|
6190
6697
|
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 +6706,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
6199
6706
|
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
6707
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
6201
6708
|
const report = await runUpgrade2({
|
|
6202
|
-
root:
|
|
6709
|
+
root: path32.resolve(opts.dir),
|
|
6203
6710
|
version: opts.version,
|
|
6204
6711
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
6205
6712
|
dryRun: opts.dryRun,
|
|
@@ -6263,7 +6770,7 @@ function redactUrl(location) {
|
|
|
6263
6770
|
const url = new URL(location);
|
|
6264
6771
|
return `${url.origin}${url.pathname}`;
|
|
6265
6772
|
} catch {
|
|
6266
|
-
return
|
|
6773
|
+
return path32.basename(location);
|
|
6267
6774
|
}
|
|
6268
6775
|
}
|
|
6269
6776
|
//# sourceMappingURL=cli.js.map
|