@marktiderman/genesis-cli 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -5
- package/dist/cli.js +649 -256
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +30 -3
- package/dist/doctor.js +529 -143
- package/dist/doctor.js.map +1 -1
- package/dist/genesis-catalog.json +46 -15
- package/dist/index.js +532 -146
- package/dist/index.js.map +1 -1
- package/dist/vite.js +533 -147
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as path14 from 'path';
|
|
2
2
|
import { spawnSync } from 'child_process';
|
|
3
3
|
import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
|
|
4
4
|
import { createRequire } from 'module';
|
|
@@ -8,19 +8,19 @@ import { pathToFileURL } from 'url';
|
|
|
8
8
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
9
9
|
function buildCommands(root, config) {
|
|
10
10
|
if (config.build) return config.build;
|
|
11
|
-
const pkgFile =
|
|
11
|
+
const pkgFile = path14.join(root, "package.json");
|
|
12
12
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
13
13
|
const pm = packageManager(root);
|
|
14
14
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
15
15
|
}
|
|
16
16
|
function packageManager(root) {
|
|
17
|
-
let dir =
|
|
17
|
+
let dir = path14.resolve(root);
|
|
18
18
|
for (; ; ) {
|
|
19
|
-
if (existsSync(
|
|
20
|
-
if (existsSync(
|
|
21
|
-
if (existsSync(
|
|
22
|
-
if (existsSync(
|
|
23
|
-
const parent =
|
|
19
|
+
if (existsSync(path14.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
20
|
+
if (existsSync(path14.join(dir, "bun.lock")) || existsSync(path14.join(dir, "bun.lockb"))) return "bun";
|
|
21
|
+
if (existsSync(path14.join(dir, "yarn.lock"))) return "yarn";
|
|
22
|
+
if (existsSync(path14.join(dir, "package-lock.json"))) return "npm";
|
|
23
|
+
const parent = path14.dirname(dir);
|
|
24
24
|
if (parent === dir) return "npm";
|
|
25
25
|
dir = parent;
|
|
26
26
|
}
|
|
@@ -127,25 +127,25 @@ var PACK_KEYS = {
|
|
|
127
127
|
};
|
|
128
128
|
function appPath(v, where, fail) {
|
|
129
129
|
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
130
|
-
if (
|
|
131
|
-
const norm =
|
|
130
|
+
if (path14.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
131
|
+
const norm = path14.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
132
132
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
133
133
|
return norm;
|
|
134
134
|
}
|
|
135
135
|
function loadConfig(root, configPath) {
|
|
136
136
|
if (configPath) {
|
|
137
|
-
const file =
|
|
137
|
+
const file = path14.resolve(root, configPath);
|
|
138
138
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
139
139
|
const json = readJson(file);
|
|
140
|
-
const block =
|
|
141
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
140
|
+
const block = path14.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
141
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path14.dirname(file) };
|
|
142
142
|
}
|
|
143
|
-
const own =
|
|
143
|
+
const own = path14.join(root, "genesis.config.json");
|
|
144
144
|
if (existsSync(own)) {
|
|
145
145
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
146
146
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
147
147
|
}
|
|
148
|
-
const pkg =
|
|
148
|
+
const pkg = path14.join(root, "package.json");
|
|
149
149
|
if (existsSync(pkg)) {
|
|
150
150
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
151
151
|
if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -160,7 +160,7 @@ function readJson(file) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
function readGenesisConfig(root) {
|
|
163
|
-
const file =
|
|
163
|
+
const file = path14.join(root, "genesis.config.json");
|
|
164
164
|
if (!existsSync(file)) return null;
|
|
165
165
|
const raw = readJson(file);
|
|
166
166
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -362,7 +362,7 @@ function globToRegExp(glob) {
|
|
|
362
362
|
}
|
|
363
363
|
function globMatcher(globs) {
|
|
364
364
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
365
|
-
return (
|
|
365
|
+
return (path18) => res.some((re) => re.test(path18));
|
|
366
366
|
}
|
|
367
367
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
368
368
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
@@ -402,11 +402,11 @@ var TAILWIND_PALETTE = [
|
|
|
402
402
|
"olive"
|
|
403
403
|
];
|
|
404
404
|
function findPackageDir(from, name) {
|
|
405
|
-
let dir =
|
|
405
|
+
let dir = path14.resolve(from);
|
|
406
406
|
for (; ; ) {
|
|
407
|
-
const candidate =
|
|
408
|
-
if (existsSync(
|
|
409
|
-
const parent =
|
|
407
|
+
const candidate = path14.join(dir, "node_modules", name);
|
|
408
|
+
if (existsSync(path14.join(candidate, "package.json"))) return candidate;
|
|
409
|
+
const parent = path14.dirname(dir);
|
|
410
410
|
if (parent === dir) return null;
|
|
411
411
|
dir = parent;
|
|
412
412
|
}
|
|
@@ -458,7 +458,7 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
458
458
|
function readPackageExports(root, uiPackage) {
|
|
459
459
|
const uiDir = findPackageDir(root, uiPackage);
|
|
460
460
|
if (!uiDir) return null;
|
|
461
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
461
|
+
const uiPkg = JSON.parse(readFileSync(path14.join(uiDir, "package.json"), "utf8"));
|
|
462
462
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
463
463
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
464
464
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
@@ -470,7 +470,7 @@ function readPackageExports(root, uiPackage) {
|
|
|
470
470
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
471
471
|
let readAny = false;
|
|
472
472
|
for (const entry of typeEntries) {
|
|
473
|
-
const file =
|
|
473
|
+
const file = path14.join(uiDir, entry);
|
|
474
474
|
if (!existsSync(file)) continue;
|
|
475
475
|
readAny = true;
|
|
476
476
|
const dts = readFileSync(file, "utf8");
|
|
@@ -484,11 +484,11 @@ function readPackageExports(root, uiPackage) {
|
|
|
484
484
|
}
|
|
485
485
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
486
486
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
487
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
487
|
+
const declRoot = typeof mainTypes === "string" ? path14.dirname(path14.join(uiDir, mainTypes)) : uiDir;
|
|
488
488
|
const declFiles = walkDts(declRoot);
|
|
489
489
|
for (const pkg of reexportedPackages) {
|
|
490
490
|
const dir = findPackageDir(uiDir, pkg);
|
|
491
|
-
if (dir) walkDts(
|
|
491
|
+
if (dir) walkDts(path14.join(dir, "dist"), declFiles);
|
|
492
492
|
}
|
|
493
493
|
for (const file of declFiles) {
|
|
494
494
|
const text = readFileSync(file, "utf8");
|
|
@@ -534,7 +534,7 @@ function walkDts(dir, out = []) {
|
|
|
534
534
|
if (!existsSync(dir)) return out;
|
|
535
535
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
536
536
|
if (entry.name === "node_modules") continue;
|
|
537
|
-
const p =
|
|
537
|
+
const p = path14.join(dir, entry.name);
|
|
538
538
|
if (entry.isDirectory()) walkDts(p, out);
|
|
539
539
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
540
540
|
}
|
|
@@ -551,27 +551,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
551
551
|
}
|
|
552
552
|
const files = [];
|
|
553
553
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
554
|
-
const themes = ds &&
|
|
554
|
+
const themes = ds && path14.join(ds, "dist", "themes");
|
|
555
555
|
if (themes && existsSync(themes)) {
|
|
556
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
556
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path14.join(themes, name));
|
|
557
557
|
}
|
|
558
558
|
if (files.length === 0) {
|
|
559
559
|
throw new DoctorConfigError(
|
|
560
560
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
561
561
|
);
|
|
562
562
|
}
|
|
563
|
-
const uiStyles =
|
|
563
|
+
const uiStyles = path14.join(uiDir, "dist", "styles.css");
|
|
564
564
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
565
565
|
return files;
|
|
566
566
|
}
|
|
567
567
|
function resolveSpec(root, spec) {
|
|
568
|
-
const local =
|
|
569
|
-
if (spec.startsWith(".") ||
|
|
568
|
+
const local = path14.resolve(root, spec);
|
|
569
|
+
if (spec.startsWith(".") || path14.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
570
570
|
const parts = spec.split("/");
|
|
571
571
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
572
572
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
573
573
|
if (dir) {
|
|
574
|
-
const file =
|
|
574
|
+
const file = path14.join(dir, ...parts.slice(nameLength));
|
|
575
575
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
576
576
|
}
|
|
577
577
|
return existsSync(local) ? local : null;
|
|
@@ -579,7 +579,7 @@ function resolveSpec(root, spec) {
|
|
|
579
579
|
function loadPalette(root) {
|
|
580
580
|
const names = new Set(TAILWIND_PALETTE);
|
|
581
581
|
try {
|
|
582
|
-
const req = createRequire(
|
|
582
|
+
const req = createRequire(path14.join(root, "package.json"));
|
|
583
583
|
const colors = req("tailwindcss/colors");
|
|
584
584
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
585
585
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -764,16 +764,16 @@ var DEFAULT_IGNORE = [
|
|
|
764
764
|
];
|
|
765
765
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
766
766
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
767
|
-
var toPosix = (p) => p.split(
|
|
767
|
+
var toPosix = (p) => p.split(path14.sep).join("/");
|
|
768
768
|
function scanFiles(root, config) {
|
|
769
769
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
770
770
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
771
771
|
const files = [];
|
|
772
772
|
const seen = /* @__PURE__ */ new Set();
|
|
773
773
|
const visit = (abs) => {
|
|
774
|
-
const rel = toPosix(
|
|
774
|
+
const rel = toPosix(path14.relative(root, abs));
|
|
775
775
|
if (seen.has(rel) || ignored(rel)) return;
|
|
776
|
-
const ext =
|
|
776
|
+
const ext = path14.extname(abs);
|
|
777
777
|
if (!extensions.has(ext)) return;
|
|
778
778
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
779
779
|
seen.add(rel);
|
|
@@ -783,14 +783,14 @@ function scanFiles(root, config) {
|
|
|
783
783
|
const walk = (dir) => {
|
|
784
784
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
785
785
|
if (entry.isDirectory()) {
|
|
786
|
-
if (!SKIP_DIRS.has(entry.name)) walk(
|
|
786
|
+
if (!SKIP_DIRS.has(entry.name)) walk(path14.join(dir, entry.name));
|
|
787
787
|
} else if (entry.isFile()) {
|
|
788
|
-
visit(
|
|
788
|
+
visit(path14.join(dir, entry.name));
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
792
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
793
|
-
const abs =
|
|
793
|
+
const abs = path14.resolve(root, src);
|
|
794
794
|
if (!existsSync(abs)) continue;
|
|
795
795
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
796
796
|
else visit(abs);
|
|
@@ -867,7 +867,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
867
867
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
868
868
|
let all = compiled;
|
|
869
869
|
if (rulesDoc) {
|
|
870
|
-
const file =
|
|
870
|
+
const file = path14.resolve(root, rulesDoc);
|
|
871
871
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
872
872
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
873
873
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -923,14 +923,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
923
923
|
}
|
|
924
924
|
function resolvePlugin(id, configDir) {
|
|
925
925
|
try {
|
|
926
|
-
if (id.startsWith(".") ||
|
|
926
|
+
if (id.startsWith(".") || path14.isAbsolute(id)) return resolveFrom(path14.resolve(configDir, id), configDir);
|
|
927
927
|
return resolveFrom(id, configDir);
|
|
928
928
|
} catch {
|
|
929
929
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
function resolveFrom(id, from) {
|
|
933
|
-
return createRequire(
|
|
933
|
+
return createRequire(path14.join(from, "noop.js")).resolve(id);
|
|
934
934
|
}
|
|
935
935
|
var BUILTIN_RULES = [
|
|
936
936
|
"local-primitives",
|
|
@@ -981,7 +981,7 @@ function importSpecifiers(file) {
|
|
|
981
981
|
}
|
|
982
982
|
function checkProjectLayout(ctx) {
|
|
983
983
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
984
|
-
if (existsSync(
|
|
984
|
+
if (existsSync(path14.join(ctx.root, dir))) {
|
|
985
985
|
ctx.report({
|
|
986
986
|
rule: "local-primitives",
|
|
987
987
|
file: dir,
|
|
@@ -991,7 +991,7 @@ function checkProjectLayout(ctx) {
|
|
|
991
991
|
}
|
|
992
992
|
}
|
|
993
993
|
for (const file of STARTER_LEFTOVERS) {
|
|
994
|
-
if (existsSync(
|
|
994
|
+
if (existsSync(path14.join(ctx.root, file))) {
|
|
995
995
|
ctx.report({
|
|
996
996
|
rule: "starter-leftover",
|
|
997
997
|
level: "warn",
|
|
@@ -1080,7 +1080,7 @@ function checkTokens(ctx) {
|
|
|
1080
1080
|
}
|
|
1081
1081
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
1082
1082
|
if (/[*?]/.test(pattern)) continue;
|
|
1083
|
-
const abs =
|
|
1083
|
+
const abs = path14.join(ctx.root, pattern);
|
|
1084
1084
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
1085
1085
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
1086
1086
|
}
|
|
@@ -1186,10 +1186,10 @@ function localImports(root, file) {
|
|
|
1186
1186
|
const out = [];
|
|
1187
1187
|
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1188
1188
|
const spec = m[1];
|
|
1189
|
-
const bases = spec.startsWith(".") ? [
|
|
1189
|
+
const bases = spec.startsWith(".") ? [path14.resolve(path14.dirname(file.absolutePath), spec)] : [path14.join(root, spec.slice(2)), path14.join(root, "src", spec.slice(2))];
|
|
1190
1190
|
for (const base of bases) {
|
|
1191
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
1192
|
-
(p) => SCRIPT_EXTS2.has(
|
|
1191
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
|
|
1192
|
+
(p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
|
|
1193
1193
|
);
|
|
1194
1194
|
if (hit) {
|
|
1195
1195
|
out.push(hit);
|
|
@@ -1206,14 +1206,6 @@ function readSource(abs) {
|
|
|
1206
1206
|
return null;
|
|
1207
1207
|
}
|
|
1208
1208
|
}
|
|
1209
|
-
function viaOneImport(root, files, file, test2) {
|
|
1210
|
-
if (test2(file.code)) return true;
|
|
1211
|
-
const byPath = new Map(files.map((f) => [f.absolutePath, f]));
|
|
1212
|
-
return localImports(root, file).some((abs) => {
|
|
1213
|
-
const target = byPath.get(abs) ?? readSource(abs);
|
|
1214
|
-
return target !== null && test2(target.code);
|
|
1215
|
-
});
|
|
1216
|
-
}
|
|
1217
1209
|
function tagEnd(code, start) {
|
|
1218
1210
|
let depth = 0;
|
|
1219
1211
|
let quote = null;
|
|
@@ -1361,7 +1353,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1361
1353
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
1362
1354
|
const code = file.code;
|
|
1363
1355
|
const hidden = HIDES_HEADER.exec(code);
|
|
1364
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
1356
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
|
|
1365
1357
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1366
1358
|
if (hidden && own) {
|
|
1367
1359
|
reported.add(file.path);
|
|
@@ -1389,7 +1381,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1389
1381
|
}
|
|
1390
1382
|
for (const file of ctx.files) {
|
|
1391
1383
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1392
|
-
const layout = hidingLayouts.get(
|
|
1384
|
+
const layout = hidingLayouts.get(path14.posix.dirname(file.path));
|
|
1393
1385
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1394
1386
|
if (!layout || !own) continue;
|
|
1395
1387
|
ctx.report({
|
|
@@ -1404,13 +1396,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1404
1396
|
}
|
|
1405
1397
|
function routerRoot(ctx) {
|
|
1406
1398
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1407
|
-
return existsSync(
|
|
1399
|
+
return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1408
1400
|
}
|
|
1409
1401
|
function checkScreenLayouts(ctx, pkg) {
|
|
1410
1402
|
const layouts = nativeLayouts(pkg);
|
|
1411
1403
|
if (layouts.length === 0) return;
|
|
1412
1404
|
const rootDir = routerRoot(ctx);
|
|
1413
|
-
if (!existsSync(
|
|
1405
|
+
if (!existsSync(path14.join(ctx.root, rootDir))) {
|
|
1414
1406
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1415
1407
|
return;
|
|
1416
1408
|
}
|
|
@@ -1424,15 +1416,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
1424
1416
|
});
|
|
1425
1417
|
return;
|
|
1426
1418
|
}
|
|
1427
|
-
const
|
|
1419
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
1428
1420
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
1429
1421
|
for (const file of routes) {
|
|
1430
1422
|
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1431
1423
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
1432
|
-
if (
|
|
1424
|
+
if (renders2.test(file.code)) continue;
|
|
1433
1425
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
1434
1426
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
1435
|
-
return target !== null &&
|
|
1427
|
+
return target !== null && renders2.test(target.code);
|
|
1436
1428
|
});
|
|
1437
1429
|
if (viaImport) continue;
|
|
1438
1430
|
ctx.report({
|
|
@@ -1465,7 +1457,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
1465
1457
|
function readExpoConfigs(root) {
|
|
1466
1458
|
const out = [];
|
|
1467
1459
|
for (const name of EXPO_CONFIGS) {
|
|
1468
|
-
const abs =
|
|
1460
|
+
const abs = path14.join(root, name);
|
|
1469
1461
|
if (!existsSync(abs)) continue;
|
|
1470
1462
|
const text = readFileSync(abs, "utf8");
|
|
1471
1463
|
let json = null;
|
|
@@ -1499,13 +1491,13 @@ function pluginOptions(json, module) {
|
|
|
1499
1491
|
return null;
|
|
1500
1492
|
}
|
|
1501
1493
|
function dependencies(root) {
|
|
1502
|
-
const file =
|
|
1494
|
+
const file = path14.join(root, "package.json");
|
|
1503
1495
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1504
1496
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1505
1497
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1506
1498
|
}
|
|
1507
1499
|
function runtimeDependencies(root) {
|
|
1508
|
-
const file =
|
|
1500
|
+
const file = path14.join(root, "package.json");
|
|
1509
1501
|
if (!existsSync(file)) return {};
|
|
1510
1502
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1511
1503
|
}
|
|
@@ -1768,9 +1760,9 @@ function gitView(root, dir, base) {
|
|
|
1768
1760
|
function checkSupabasePack(ctx) {
|
|
1769
1761
|
const settings = ctx.config.supabase ?? {};
|
|
1770
1762
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1771
|
-
const abs =
|
|
1763
|
+
const abs = path14.join(ctx.root, dir);
|
|
1772
1764
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1773
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
1765
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
1774
1766
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1775
1767
|
const base = settings.base ?? DEFAULT_BASE;
|
|
1776
1768
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -1787,7 +1779,7 @@ function checkSupabasePack(ctx) {
|
|
|
1787
1779
|
}
|
|
1788
1780
|
}
|
|
1789
1781
|
const since = settings.since;
|
|
1790
|
-
const afterSince = (file) => since === void 0 ||
|
|
1782
|
+
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
1791
1783
|
if ("reason" in view && since === void 0) {
|
|
1792
1784
|
ctx.report({
|
|
1793
1785
|
rule: "migration-grants",
|
|
@@ -1994,7 +1986,7 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1994
1986
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
1995
1987
|
function readReleaseManifest(root) {
|
|
1996
1988
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
1997
|
-
const file = dir &&
|
|
1989
|
+
const file = dir && path14.join(dir, "dist", "versions.json");
|
|
1998
1990
|
if (!file || !existsSync(file)) return null;
|
|
1999
1991
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
2000
1992
|
}
|
|
@@ -2004,7 +1996,7 @@ function checkVersionSkew(ctx) {
|
|
|
2004
1996
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2005
1997
|
const dir = findPackageDir(ctx.root, name);
|
|
2006
1998
|
if (!dir) continue;
|
|
2007
|
-
const have = JSON.parse(readFileSync(
|
|
1999
|
+
const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
|
|
2008
2000
|
if (have === want) continue;
|
|
2009
2001
|
ctx.report({
|
|
2010
2002
|
rule: "version-skew",
|
|
@@ -2138,9 +2130,10 @@ function satisfies(version, range) {
|
|
|
2138
2130
|
|
|
2139
2131
|
// src/doctor/installs.ts
|
|
2140
2132
|
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
2133
|
+
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
2141
2134
|
var readManifest = (dir) => {
|
|
2142
2135
|
try {
|
|
2143
|
-
return JSON.parse(readFileSync(
|
|
2136
|
+
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
2144
2137
|
} catch {
|
|
2145
2138
|
return null;
|
|
2146
2139
|
}
|
|
@@ -2157,10 +2150,10 @@ function packagesIn(nodeModules) {
|
|
|
2157
2150
|
const out = [];
|
|
2158
2151
|
for (const entry of readdirSync(nodeModules)) {
|
|
2159
2152
|
if (entry.startsWith(".")) continue;
|
|
2160
|
-
const p =
|
|
2153
|
+
const p = path14.join(nodeModules, entry);
|
|
2161
2154
|
if (entry.startsWith("@")) {
|
|
2162
2155
|
try {
|
|
2163
|
-
for (const sub of readdirSync(p)) out.push(
|
|
2156
|
+
for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
|
|
2164
2157
|
} catch {
|
|
2165
2158
|
}
|
|
2166
2159
|
} else {
|
|
@@ -2172,44 +2165,68 @@ function packagesIn(nodeModules) {
|
|
|
2172
2165
|
function genesisInstalls(root) {
|
|
2173
2166
|
const copies = /* @__PURE__ */ new Map();
|
|
2174
2167
|
const realRoot = real(root);
|
|
2175
|
-
const rel = (abs) =>
|
|
2176
|
-
const
|
|
2168
|
+
const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
|
|
2169
|
+
const via = /* @__PURE__ */ new Map();
|
|
2170
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
2177
2171
|
let copy = copies.get(real2);
|
|
2178
2172
|
if (!copy) {
|
|
2179
|
-
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
|
|
2173
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
2180
2174
|
copies.set(real2, copy);
|
|
2175
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
2181
2176
|
}
|
|
2177
|
+
via.get(real2).add(root2);
|
|
2182
2178
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
2183
2179
|
};
|
|
2184
|
-
const
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
const
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2180
|
+
const walk = (kind, roots) => {
|
|
2181
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
2182
|
+
const queue = [];
|
|
2183
|
+
const visit = (dir, by, range) => {
|
|
2184
|
+
const manifest = readManifest(dir);
|
|
2185
|
+
if (!manifest?.name) return;
|
|
2186
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
2187
|
+
const realDir = real(dir);
|
|
2188
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
2189
|
+
if (expanded.has(realDir)) return;
|
|
2190
|
+
expanded.add(realDir);
|
|
2191
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
2192
|
+
};
|
|
2193
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
2194
|
+
while (queue.length) {
|
|
2195
|
+
const { real: from, manifest, label } = queue.shift();
|
|
2196
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
2197
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
2198
|
+
const dir = findPackageDir(from, name);
|
|
2199
|
+
if (dir) visit(dir, label, range);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2194
2202
|
};
|
|
2195
|
-
const
|
|
2196
|
-
const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
2197
|
-
for (const name of Object.keys(appDeps)) {
|
|
2203
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
2198
2204
|
const dir = findPackageDir(root, name);
|
|
2199
|
-
|
|
2200
|
-
}
|
|
2201
|
-
const
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2205
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
2206
|
+
});
|
|
2207
|
+
const app = readManifest(root);
|
|
2208
|
+
let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
2209
|
+
let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
|
|
2210
|
+
if (Object.keys(runtimeDeps).length === 0) {
|
|
2211
|
+
runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
|
|
2212
|
+
devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
|
|
2213
|
+
}
|
|
2214
|
+
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
2215
|
+
const top = path14.join(root, "node_modules");
|
|
2216
|
+
walk(
|
|
2217
|
+
"hoisted",
|
|
2218
|
+
packagesIn(top).filter((dir) => {
|
|
2219
|
+
const name = path14.relative(top, dir).split(path14.sep).join("/");
|
|
2220
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
2221
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
2222
|
+
);
|
|
2223
|
+
const devRoots = { ...devDeps };
|
|
2224
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
2225
|
+
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
2226
|
+
for (const [key2, copy] of copies) {
|
|
2227
|
+
const kinds = via.get(key2);
|
|
2228
|
+
copy.runtime = kinds.has("runtime");
|
|
2229
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
2213
2230
|
}
|
|
2214
2231
|
const byName = /* @__PURE__ */ new Map();
|
|
2215
2232
|
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
@@ -2217,20 +2234,31 @@ function genesisInstalls(root) {
|
|
|
2217
2234
|
return byName;
|
|
2218
2235
|
}
|
|
2219
2236
|
function checkDuplicatePackages(ctx) {
|
|
2237
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
2220
2238
|
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
2221
2239
|
if (copies.length < 2) continue;
|
|
2222
|
-
const
|
|
2240
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
2241
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
2242
|
+
ctx.report({
|
|
2243
|
+
rule: "duplicate-genesis-package",
|
|
2244
|
+
level: "warn",
|
|
2245
|
+
file: "package.json",
|
|
2246
|
+
subject: name,
|
|
2247
|
+
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`
|
|
2248
|
+
});
|
|
2249
|
+
continue;
|
|
2250
|
+
}
|
|
2223
2251
|
ctx.report({
|
|
2224
2252
|
rule: "duplicate-genesis-package",
|
|
2225
|
-
level: "
|
|
2253
|
+
level: "info",
|
|
2226
2254
|
file: "package.json",
|
|
2227
2255
|
subject: name,
|
|
2228
|
-
message: `${name}
|
|
2256
|
+
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`
|
|
2229
2257
|
});
|
|
2230
2258
|
}
|
|
2231
2259
|
}
|
|
2232
2260
|
function checkPeerRanges(ctx) {
|
|
2233
|
-
const rel = (abs) =>
|
|
2261
|
+
const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
|
|
2234
2262
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
2235
2263
|
for (const copy of copies) {
|
|
2236
2264
|
const dir = copy.absolutePath;
|
|
@@ -2243,7 +2271,8 @@ function checkPeerRanges(ctx) {
|
|
|
2243
2271
|
if (satisfies(installed, range) !== false) continue;
|
|
2244
2272
|
ctx.report({
|
|
2245
2273
|
rule: "peer-range-mismatch",
|
|
2246
|
-
|
|
2274
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
2275
|
+
level: copy.devOnly ? "info" : "warn",
|
|
2247
2276
|
file: "package.json",
|
|
2248
2277
|
subject: `${copy.name}>${peer}`,
|
|
2249
2278
|
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}`
|
|
@@ -2252,55 +2281,401 @@ function checkPeerRanges(ctx) {
|
|
|
2252
2281
|
}
|
|
2253
2282
|
}
|
|
2254
2283
|
}
|
|
2284
|
+
var TRAIL_DEPTH = 6;
|
|
2285
|
+
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
2286
|
+
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
2287
|
+
var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
2288
|
+
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
2289
|
+
function stripForImports(code) {
|
|
2290
|
+
const out = [];
|
|
2291
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
2292
|
+
const n = code.length;
|
|
2293
|
+
const templates = [];
|
|
2294
|
+
let depth = 0;
|
|
2295
|
+
let i = 0;
|
|
2296
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
2297
|
+
const opensString = () => {
|
|
2298
|
+
const before = out.slice(-12).join("");
|
|
2299
|
+
if (!/[\w$]$/.test(before)) return true;
|
|
2300
|
+
return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
|
|
2301
|
+
};
|
|
2302
|
+
const templateBody = () => {
|
|
2303
|
+
while (i < n) {
|
|
2304
|
+
const ch = code[i];
|
|
2305
|
+
if (ch === "\\") {
|
|
2306
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2307
|
+
i += 2;
|
|
2308
|
+
} else if (ch === "`") {
|
|
2309
|
+
out.push("`");
|
|
2310
|
+
i++;
|
|
2311
|
+
return;
|
|
2312
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
2313
|
+
out.push("${");
|
|
2314
|
+
i += 2;
|
|
2315
|
+
templates.push(depth);
|
|
2316
|
+
depth++;
|
|
2317
|
+
return;
|
|
2318
|
+
} else {
|
|
2319
|
+
out.push(blank(ch));
|
|
2320
|
+
i++;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
};
|
|
2324
|
+
while (i < n) {
|
|
2325
|
+
const ch = code[i];
|
|
2326
|
+
const next = code[i + 1];
|
|
2327
|
+
if (ch === "/" && next === "/") {
|
|
2328
|
+
while (i < n && code[i] !== "\n") {
|
|
2329
|
+
out.push(" ");
|
|
2330
|
+
i++;
|
|
2331
|
+
}
|
|
2332
|
+
} else if (ch === "/" && next === "*") {
|
|
2333
|
+
out.push(" ");
|
|
2334
|
+
i += 2;
|
|
2335
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
2336
|
+
out.push(blank(code[i]));
|
|
2337
|
+
i++;
|
|
2338
|
+
}
|
|
2339
|
+
if (i < n) {
|
|
2340
|
+
out.push(" ");
|
|
2341
|
+
i += 2;
|
|
2342
|
+
}
|
|
2343
|
+
} else if ((ch === '"' || ch === "'") && opensString()) {
|
|
2344
|
+
const keep = isSpecifier();
|
|
2345
|
+
out.push(ch);
|
|
2346
|
+
i++;
|
|
2347
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
2348
|
+
if (code[i] === "\\") {
|
|
2349
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
2350
|
+
i += 2;
|
|
2351
|
+
} else {
|
|
2352
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
2353
|
+
i++;
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
if (i < n) {
|
|
2357
|
+
out.push(code[i]);
|
|
2358
|
+
i++;
|
|
2359
|
+
}
|
|
2360
|
+
} else if (ch === "`") {
|
|
2361
|
+
out.push("`");
|
|
2362
|
+
i++;
|
|
2363
|
+
templateBody();
|
|
2364
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
2365
|
+
templates.pop();
|
|
2366
|
+
depth--;
|
|
2367
|
+
out.push("}");
|
|
2368
|
+
i++;
|
|
2369
|
+
templateBody();
|
|
2370
|
+
} else {
|
|
2371
|
+
if (ch === "{") depth++;
|
|
2372
|
+
else if (ch === "}") depth--;
|
|
2373
|
+
out.push(ch);
|
|
2374
|
+
i++;
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
return out.join("");
|
|
2378
|
+
}
|
|
2379
|
+
function bindings(clause) {
|
|
2380
|
+
const out = [];
|
|
2381
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
2382
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
2383
|
+
const p = part.trim();
|
|
2384
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2385
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
2386
|
+
}
|
|
2387
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
2388
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
2389
|
+
if (ns) out.push(ns[1]);
|
|
2390
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
2391
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
2392
|
+
return out;
|
|
2393
|
+
}
|
|
2394
|
+
function readJsonc(file) {
|
|
2395
|
+
try {
|
|
2396
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
2397
|
+
return JSON.parse(text);
|
|
2398
|
+
} catch {
|
|
2399
|
+
return null;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
2403
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
2404
|
+
seen.add(file);
|
|
2405
|
+
const json = readJsonc(file);
|
|
2406
|
+
if (!json) return {};
|
|
2407
|
+
const dir = path14.dirname(file);
|
|
2408
|
+
let merged = {};
|
|
2409
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2410
|
+
for (const ext of parents) {
|
|
2411
|
+
if (typeof ext !== "string") continue;
|
|
2412
|
+
let target = null;
|
|
2413
|
+
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
2414
|
+
const abs = path14.resolve(dir, ext);
|
|
2415
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2416
|
+
} else {
|
|
2417
|
+
const parts = ext.split("/");
|
|
2418
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
2419
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2420
|
+
if (pkgDir) {
|
|
2421
|
+
const sub = parts.slice(nameLength).join("/");
|
|
2422
|
+
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
2423
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2427
|
+
}
|
|
2428
|
+
const opts = json.compilerOptions ?? {};
|
|
2429
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
2430
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
2431
|
+
merged.paths = opts.paths;
|
|
2432
|
+
merged.pathsDir = dir;
|
|
2433
|
+
}
|
|
2434
|
+
return merged;
|
|
2435
|
+
}
|
|
2436
|
+
function aliases(root) {
|
|
2437
|
+
const table = [];
|
|
2438
|
+
let baseUrl = null;
|
|
2439
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2440
|
+
const file = path14.join(root, name);
|
|
2441
|
+
if (!existsSync(file)) continue;
|
|
2442
|
+
const config = readTsconfig(root, file);
|
|
2443
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
2444
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
2445
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2446
|
+
if (!Array.isArray(targets)) continue;
|
|
2447
|
+
const exact = !pattern.endsWith("*");
|
|
2448
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
2452
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2453
|
+
if (typeof target !== "string") continue;
|
|
2454
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
2455
|
+
}
|
|
2456
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
|
|
2457
|
+
return { table, baseUrl };
|
|
2458
|
+
}
|
|
2459
|
+
function resolveFile(base) {
|
|
2460
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
|
|
2461
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2462
|
+
for (const p of tries) {
|
|
2463
|
+
if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2464
|
+
}
|
|
2465
|
+
return null;
|
|
2466
|
+
}
|
|
2467
|
+
var trails = /* @__PURE__ */ new WeakMap();
|
|
2468
|
+
function trailFor(ctx) {
|
|
2469
|
+
let t = trails.get(ctx.files);
|
|
2470
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
2471
|
+
return t;
|
|
2472
|
+
}
|
|
2473
|
+
function createTrail(ctx) {
|
|
2474
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
2475
|
+
let declared = null;
|
|
2476
|
+
try {
|
|
2477
|
+
const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
|
|
2478
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
2479
|
+
} catch {
|
|
2480
|
+
declared = null;
|
|
2481
|
+
}
|
|
2482
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2483
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
2484
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
2485
|
+
const importsOf = (file) => {
|
|
2486
|
+
const hit = importsCache.get(file.absolutePath);
|
|
2487
|
+
if (hit) return hit;
|
|
2488
|
+
const files = [];
|
|
2489
|
+
let lost = false;
|
|
2490
|
+
const code = stripped(file);
|
|
2491
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
2492
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2493
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2494
|
+
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]);
|
|
2495
|
+
const specs = [];
|
|
2496
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
2497
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
2498
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
2499
|
+
for (const spec of specs) {
|
|
2500
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
2501
|
+
let resolved = null;
|
|
2502
|
+
if (spec.startsWith(".")) {
|
|
2503
|
+
resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
|
|
2504
|
+
if (!resolved) lost = true;
|
|
2505
|
+
} else {
|
|
2506
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
2507
|
+
if (alias) {
|
|
2508
|
+
for (const t of alias.targets) {
|
|
2509
|
+
resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
|
|
2510
|
+
if (resolved) break;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
|
|
2514
|
+
if (!resolved) {
|
|
2515
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
2516
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
2520
|
+
}
|
|
2521
|
+
const out = { files, lost };
|
|
2522
|
+
importsCache.set(file.absolutePath, out);
|
|
2523
|
+
return out;
|
|
2524
|
+
};
|
|
2525
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
2526
|
+
const stripped = (file) => {
|
|
2527
|
+
let c = strippedCache.get(file.absolutePath);
|
|
2528
|
+
if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
|
|
2529
|
+
return c;
|
|
2530
|
+
};
|
|
2531
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
2532
|
+
const reach = (file, test2, depth, seen) => {
|
|
2533
|
+
let cache = memo.get(test2);
|
|
2534
|
+
if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
|
|
2535
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
2536
|
+
const cached = cache.get(k);
|
|
2537
|
+
if (cached) return [cached, false];
|
|
2538
|
+
let result;
|
|
2539
|
+
let cut = false;
|
|
2540
|
+
if (test2(stripped(file))) result = "yes";
|
|
2541
|
+
else {
|
|
2542
|
+
const { files, lost } = importsOf(file);
|
|
2543
|
+
let unknown = lost && depth > 0;
|
|
2544
|
+
result = "no";
|
|
2545
|
+
if (depth > 0) {
|
|
2546
|
+
seen.add(file.absolutePath);
|
|
2547
|
+
for (const abs of files) {
|
|
2548
|
+
if (seen.has(abs)) {
|
|
2549
|
+
cut = true;
|
|
2550
|
+
continue;
|
|
2551
|
+
}
|
|
2552
|
+
const target = read(abs);
|
|
2553
|
+
if (!target) {
|
|
2554
|
+
unknown = true;
|
|
2555
|
+
continue;
|
|
2556
|
+
}
|
|
2557
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
2558
|
+
if (c) cut = true;
|
|
2559
|
+
if (r === "yes") {
|
|
2560
|
+
result = "yes";
|
|
2561
|
+
break;
|
|
2562
|
+
}
|
|
2563
|
+
if (r === "unknown") unknown = true;
|
|
2564
|
+
}
|
|
2565
|
+
seen.delete(file.absolutePath);
|
|
2566
|
+
}
|
|
2567
|
+
if (result === "no" && unknown) result = "unknown";
|
|
2568
|
+
}
|
|
2569
|
+
if (result === "yes" || !cut) cache.set(k, result);
|
|
2570
|
+
return [result, cut && result !== "yes"];
|
|
2571
|
+
};
|
|
2572
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
// src/doctor/routes.ts
|
|
2255
2576
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
2256
|
-
var
|
|
2257
|
-
|
|
2577
|
+
var STEMS = {
|
|
2578
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
2579
|
+
"next-app": {
|
|
2580
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
2581
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
2582
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
2583
|
+
},
|
|
2584
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
2585
|
+
};
|
|
2258
2586
|
var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
2259
2587
|
var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
2588
|
+
var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
2589
|
+
var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
2590
|
+
var 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;
|
|
2260
2591
|
function routesDir(ctx) {
|
|
2261
2592
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
2262
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
2593
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
|
|
2263
2594
|
}
|
|
2264
2595
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
2596
|
+
function flavorOf(dir, rels) {
|
|
2597
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
2598
|
+
if (stems.includes("__root")) return "tanstack";
|
|
2599
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
2600
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
2601
|
+
return "tanstack";
|
|
2602
|
+
}
|
|
2603
|
+
function renders(code) {
|
|
2604
|
+
const elements = renderedElements(code);
|
|
2605
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
2606
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
2607
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
2608
|
+
if (named && !definedHere(named)) return true;
|
|
2609
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
2610
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
2611
|
+
return exported !== void 0 && !definedHere(exported);
|
|
2612
|
+
}
|
|
2265
2613
|
function webRoutes(ctx) {
|
|
2266
2614
|
const dir = routesDir(ctx);
|
|
2267
2615
|
if (!dir) return [];
|
|
2268
|
-
const
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2616
|
+
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(/\.[^.]+$/, "") }));
|
|
2617
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
2618
|
+
const stems = STEMS[flavor];
|
|
2619
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2620
|
+
for (const { file, rel } of candidates) {
|
|
2272
2621
|
const parts = rel.split("/");
|
|
2273
2622
|
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
2623
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
2624
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
2625
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
2626
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
2627
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
2628
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
2629
|
+
}
|
|
2630
|
+
const trail = trailFor(ctx);
|
|
2631
|
+
const routes = [];
|
|
2632
|
+
for (const [id, files] of groups) {
|
|
2633
|
+
const parts = id.split("/");
|
|
2274
2634
|
const stem = parts.pop();
|
|
2275
|
-
const
|
|
2276
|
-
|
|
2277
|
-
|
|
2635
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
2636
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
2637
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
2638
|
+
const segments = [...folders, ...own];
|
|
2639
|
+
const tree = [...parts, ...own];
|
|
2640
|
+
let index = stems.index.has(stem);
|
|
2641
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
2278
2642
|
segments.pop();
|
|
2643
|
+
tree.pop();
|
|
2279
2644
|
index = true;
|
|
2280
2645
|
}
|
|
2281
|
-
const
|
|
2282
|
-
const
|
|
2646
|
+
const code = files.map((f) => f.code).join("\n");
|
|
2647
|
+
const elements = renderedElements(code);
|
|
2648
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
2649
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
2650
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
2651
|
+
const rendering = renders(code);
|
|
2652
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
2653
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
2654
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
2283
2655
|
routes.push({
|
|
2284
|
-
file,
|
|
2656
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
2657
|
+
files,
|
|
2285
2658
|
segments,
|
|
2659
|
+
tree,
|
|
2286
2660
|
index,
|
|
2287
2661
|
layout,
|
|
2288
|
-
|
|
2289
|
-
|
|
2662
|
+
page,
|
|
2663
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
2664
|
+
redirectOnly: !rendering,
|
|
2290
2665
|
parents: []
|
|
2291
2666
|
});
|
|
2292
2667
|
}
|
|
2293
2668
|
for (const r of routes) {
|
|
2294
|
-
const own = r.
|
|
2669
|
+
const own = r.tree;
|
|
2295
2670
|
for (const p of routes) {
|
|
2296
2671
|
if (p === r || !p.layout) continue;
|
|
2297
|
-
const n = p.
|
|
2672
|
+
const n = p.tree.length;
|
|
2298
2673
|
if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
|
|
2299
|
-
if (key(own.slice(0, n)) !== key(p.
|
|
2300
|
-
if (n > 0 && own[n - 1].endsWith("_") && !p.
|
|
2674
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
2675
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
2301
2676
|
r.parents.push(p);
|
|
2302
2677
|
}
|
|
2303
|
-
r.parents.sort((a, b) => b.
|
|
2678
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
2304
2679
|
}
|
|
2305
2680
|
return routes;
|
|
2306
2681
|
}
|
|
@@ -2318,8 +2693,19 @@ var rendersRe = (names) => {
|
|
|
2318
2693
|
const list = [...names];
|
|
2319
2694
|
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
2320
2695
|
};
|
|
2696
|
+
function routeReach(ctx, r, test2) {
|
|
2697
|
+
const trail = trailFor(ctx);
|
|
2698
|
+
let unknown = false;
|
|
2699
|
+
for (const f of r.files) {
|
|
2700
|
+
const got = trail.reach(f, test2);
|
|
2701
|
+
if (got === "yes") return "yes";
|
|
2702
|
+
if (got === "unknown") unknown = true;
|
|
2703
|
+
}
|
|
2704
|
+
return unknown ? "unknown" : "no";
|
|
2705
|
+
}
|
|
2706
|
+
var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
2321
2707
|
function insideShell(ctx, routes) {
|
|
2322
|
-
const shell = new Set(routes.filter((r) =>
|
|
2708
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
2323
2709
|
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
2324
2710
|
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
2325
2711
|
}
|
|
@@ -2330,20 +2716,19 @@ function checkHandRolledSubNav(ctx) {
|
|
|
2330
2716
|
const inShell = insideShell(ctx, routes);
|
|
2331
2717
|
const ui = ctx.genesis.uiPackage;
|
|
2332
2718
|
for (const r of routes) {
|
|
2333
|
-
if (!inShell(r)) continue;
|
|
2334
|
-
const
|
|
2335
|
-
if (
|
|
2336
|
-
|
|
2337
|
-
|
|
2719
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
2720
|
+
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);
|
|
2721
|
+
if (hit) {
|
|
2722
|
+
const { f, m } = hit;
|
|
2723
|
+
const code = f.code;
|
|
2338
2724
|
ctx.report({
|
|
2339
2725
|
rule: "hand-rolled-sub-nav",
|
|
2340
2726
|
level: "warn",
|
|
2341
|
-
file:
|
|
2727
|
+
file: f.path,
|
|
2342
2728
|
line: lineAt(code, m.index),
|
|
2343
2729
|
subject: m[1],
|
|
2344
2730
|
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}`
|
|
2345
2731
|
});
|
|
2346
|
-
break;
|
|
2347
2732
|
}
|
|
2348
2733
|
}
|
|
2349
2734
|
}
|
|
@@ -2391,11 +2776,12 @@ function checkResourceWorkspaces(ctx) {
|
|
|
2391
2776
|
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
2392
2777
|
}
|
|
2393
2778
|
for (const [dir, routes] of byFolder) {
|
|
2394
|
-
const
|
|
2779
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
2780
|
+
const has = routes.filter((r) => reach.get(r) === "yes");
|
|
2395
2781
|
if (has.length === 0) continue;
|
|
2396
2782
|
const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
2397
2783
|
for (const r of routes) {
|
|
2398
|
-
if (
|
|
2784
|
+
if (reach.get(r) !== "no") continue;
|
|
2399
2785
|
ctx.report({
|
|
2400
2786
|
rule: "resource-workspace",
|
|
2401
2787
|
level: "info",
|
|
@@ -2419,14 +2805,14 @@ function checkPageLayouts(ctx) {
|
|
|
2419
2805
|
};
|
|
2420
2806
|
const cache = /* @__PURE__ */ new Map();
|
|
2421
2807
|
const provides = (r) => {
|
|
2422
|
-
if (!cache.has(r)) cache.set(r,
|
|
2808
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
2423
2809
|
return cache.get(r);
|
|
2424
2810
|
};
|
|
2425
2811
|
const list = [...layouts].sort();
|
|
2426
2812
|
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
2427
2813
|
for (const r of routes) {
|
|
2428
|
-
if (r.
|
|
2429
|
-
if (provides(r) || r.parents.some(provides)) continue;
|
|
2814
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
2815
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
2430
2816
|
ctx.report({
|
|
2431
2817
|
rule: "page-layout",
|
|
2432
2818
|
level: "warn",
|
|
@@ -2457,7 +2843,7 @@ function checkIsoDateSlices(ctx) {
|
|
|
2457
2843
|
|
|
2458
2844
|
// src/doctor/index.ts
|
|
2459
2845
|
async function runDoctor(options = {}) {
|
|
2460
|
-
const root =
|
|
2846
|
+
const root = path14.resolve(options.root ?? process.cwd());
|
|
2461
2847
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
2462
2848
|
const config = loaded.config;
|
|
2463
2849
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -2637,15 +3023,15 @@ ${formatProblems(result)}`);
|
|
|
2637
3023
|
}
|
|
2638
3024
|
}
|
|
2639
3025
|
};
|
|
2640
|
-
const explicit = /* @__PURE__ */ new Set([
|
|
3026
|
+
const explicit = /* @__PURE__ */ new Set([path14.join(root, "genesis.config.json"), ...options.configPath ? [path14.resolve(root, options.configPath)] : []]);
|
|
2641
3027
|
try {
|
|
2642
3028
|
const { config } = loadConfig(root, options.configPath);
|
|
2643
|
-
if (config.rulesDoc) explicit.add(
|
|
3029
|
+
if (config.rulesDoc) explicit.add(path14.resolve(root, config.rulesDoc));
|
|
2644
3030
|
} catch {
|
|
2645
3031
|
}
|
|
2646
3032
|
const schedule = (file) => {
|
|
2647
|
-
if (!explicit.has(
|
|
2648
|
-
const rel =
|
|
3033
|
+
if (!explicit.has(path14.resolve(file))) {
|
|
3034
|
+
const rel = path14.relative(root, file).split(path14.sep).join("/");
|
|
2649
3035
|
if (rel.startsWith("..") || rel.includes("node_modules/")) return;
|
|
2650
3036
|
}
|
|
2651
3037
|
clearTimeout(timer);
|