@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/doctor.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, readdirSync, statSync, 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 (path17) => res.some((re) => re.test(path17));
|
|
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));
|
|
@@ -926,14 +926,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
926
926
|
}
|
|
927
927
|
function resolvePlugin(id, configDir) {
|
|
928
928
|
try {
|
|
929
|
-
if (id.startsWith(".") ||
|
|
929
|
+
if (id.startsWith(".") || path14.isAbsolute(id)) return resolveFrom(path14.resolve(configDir, id), configDir);
|
|
930
930
|
return resolveFrom(id, configDir);
|
|
931
931
|
} catch {
|
|
932
932
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
933
933
|
}
|
|
934
934
|
}
|
|
935
935
|
function resolveFrom(id, from) {
|
|
936
|
-
return createRequire(
|
|
936
|
+
return createRequire(path14.join(from, "noop.js")).resolve(id);
|
|
937
937
|
}
|
|
938
938
|
var BUILTIN_RULES = [
|
|
939
939
|
"local-primitives",
|
|
@@ -984,7 +984,7 @@ function importSpecifiers(file) {
|
|
|
984
984
|
}
|
|
985
985
|
function checkProjectLayout(ctx) {
|
|
986
986
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
987
|
-
if (existsSync(
|
|
987
|
+
if (existsSync(path14.join(ctx.root, dir))) {
|
|
988
988
|
ctx.report({
|
|
989
989
|
rule: "local-primitives",
|
|
990
990
|
file: dir,
|
|
@@ -994,7 +994,7 @@ function checkProjectLayout(ctx) {
|
|
|
994
994
|
}
|
|
995
995
|
}
|
|
996
996
|
for (const file of STARTER_LEFTOVERS) {
|
|
997
|
-
if (existsSync(
|
|
997
|
+
if (existsSync(path14.join(ctx.root, file))) {
|
|
998
998
|
ctx.report({
|
|
999
999
|
rule: "starter-leftover",
|
|
1000
1000
|
level: "warn",
|
|
@@ -1083,7 +1083,7 @@ function checkTokens(ctx) {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
1085
1085
|
if (/[*?]/.test(pattern)) continue;
|
|
1086
|
-
const abs =
|
|
1086
|
+
const abs = path14.join(ctx.root, pattern);
|
|
1087
1087
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
1088
1088
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
1089
1089
|
}
|
|
@@ -1189,10 +1189,10 @@ function localImports(root, file) {
|
|
|
1189
1189
|
const out = [];
|
|
1190
1190
|
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1191
1191
|
const spec = m[1];
|
|
1192
|
-
const bases = spec.startsWith(".") ? [
|
|
1192
|
+
const bases = spec.startsWith(".") ? [path14.resolve(path14.dirname(file.absolutePath), spec)] : [path14.join(root, spec.slice(2)), path14.join(root, "src", spec.slice(2))];
|
|
1193
1193
|
for (const base of bases) {
|
|
1194
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
1195
|
-
(p) => SCRIPT_EXTS2.has(
|
|
1194
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
|
|
1195
|
+
(p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
|
|
1196
1196
|
);
|
|
1197
1197
|
if (hit) {
|
|
1198
1198
|
out.push(hit);
|
|
@@ -1209,14 +1209,6 @@ function readSource(abs) {
|
|
|
1209
1209
|
return null;
|
|
1210
1210
|
}
|
|
1211
1211
|
}
|
|
1212
|
-
function viaOneImport(root, files, file, test2) {
|
|
1213
|
-
if (test2(file.code)) return true;
|
|
1214
|
-
const byPath = new Map(files.map((f) => [f.absolutePath, f]));
|
|
1215
|
-
return localImports(root, file).some((abs) => {
|
|
1216
|
-
const target = byPath.get(abs) ?? readSource(abs);
|
|
1217
|
-
return target !== null && test2(target.code);
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
1212
|
function tagEnd(code, start) {
|
|
1221
1213
|
let depth = 0;
|
|
1222
1214
|
let quote = null;
|
|
@@ -1364,7 +1356,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1364
1356
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
1365
1357
|
const code = file.code;
|
|
1366
1358
|
const hidden = HIDES_HEADER.exec(code);
|
|
1367
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
1359
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
|
|
1368
1360
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1369
1361
|
if (hidden && own) {
|
|
1370
1362
|
reported.add(file.path);
|
|
@@ -1392,7 +1384,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1392
1384
|
}
|
|
1393
1385
|
for (const file of ctx.files) {
|
|
1394
1386
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1395
|
-
const layout = hidingLayouts.get(
|
|
1387
|
+
const layout = hidingLayouts.get(path14.posix.dirname(file.path));
|
|
1396
1388
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1397
1389
|
if (!layout || !own) continue;
|
|
1398
1390
|
ctx.report({
|
|
@@ -1407,13 +1399,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1407
1399
|
}
|
|
1408
1400
|
function routerRoot(ctx) {
|
|
1409
1401
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1410
|
-
return existsSync(
|
|
1402
|
+
return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1411
1403
|
}
|
|
1412
1404
|
function checkScreenLayouts(ctx, pkg) {
|
|
1413
1405
|
const layouts = nativeLayouts(pkg);
|
|
1414
1406
|
if (layouts.length === 0) return;
|
|
1415
1407
|
const rootDir = routerRoot(ctx);
|
|
1416
|
-
if (!existsSync(
|
|
1408
|
+
if (!existsSync(path14.join(ctx.root, rootDir))) {
|
|
1417
1409
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1418
1410
|
return;
|
|
1419
1411
|
}
|
|
@@ -1427,15 +1419,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
1427
1419
|
});
|
|
1428
1420
|
return;
|
|
1429
1421
|
}
|
|
1430
|
-
const
|
|
1422
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
1431
1423
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
1432
1424
|
for (const file of routes) {
|
|
1433
1425
|
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1434
1426
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
1435
|
-
if (
|
|
1427
|
+
if (renders2.test(file.code)) continue;
|
|
1436
1428
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
1437
1429
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
1438
|
-
return target !== null &&
|
|
1430
|
+
return target !== null && renders2.test(target.code);
|
|
1439
1431
|
});
|
|
1440
1432
|
if (viaImport) continue;
|
|
1441
1433
|
ctx.report({
|
|
@@ -1468,7 +1460,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
1468
1460
|
function readExpoConfigs(root) {
|
|
1469
1461
|
const out = [];
|
|
1470
1462
|
for (const name of EXPO_CONFIGS) {
|
|
1471
|
-
const abs =
|
|
1463
|
+
const abs = path14.join(root, name);
|
|
1472
1464
|
if (!existsSync(abs)) continue;
|
|
1473
1465
|
const text = readFileSync(abs, "utf8");
|
|
1474
1466
|
let json = null;
|
|
@@ -1502,13 +1494,13 @@ function pluginOptions(json, module) {
|
|
|
1502
1494
|
return null;
|
|
1503
1495
|
}
|
|
1504
1496
|
function dependencies(root) {
|
|
1505
|
-
const file =
|
|
1497
|
+
const file = path14.join(root, "package.json");
|
|
1506
1498
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1507
1499
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1508
1500
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1509
1501
|
}
|
|
1510
1502
|
function runtimeDependencies(root) {
|
|
1511
|
-
const file =
|
|
1503
|
+
const file = path14.join(root, "package.json");
|
|
1512
1504
|
if (!existsSync(file)) return {};
|
|
1513
1505
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1514
1506
|
}
|
|
@@ -1771,9 +1763,9 @@ function gitView(root, dir, base) {
|
|
|
1771
1763
|
function checkSupabasePack(ctx) {
|
|
1772
1764
|
const settings = ctx.config.supabase ?? {};
|
|
1773
1765
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1774
|
-
const abs =
|
|
1766
|
+
const abs = path14.join(ctx.root, dir);
|
|
1775
1767
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1776
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
1768
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
1777
1769
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1778
1770
|
const base = settings.base ?? DEFAULT_BASE;
|
|
1779
1771
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -1790,7 +1782,7 @@ function checkSupabasePack(ctx) {
|
|
|
1790
1782
|
}
|
|
1791
1783
|
}
|
|
1792
1784
|
const since = settings.since;
|
|
1793
|
-
const afterSince = (file) => since === void 0 ||
|
|
1785
|
+
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
1794
1786
|
if ("reason" in view && since === void 0) {
|
|
1795
1787
|
ctx.report({
|
|
1796
1788
|
rule: "migration-grants",
|
|
@@ -1997,7 +1989,7 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1997
1989
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
1998
1990
|
function readReleaseManifest(root) {
|
|
1999
1991
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2000
|
-
const file = dir &&
|
|
1992
|
+
const file = dir && path14.join(dir, "dist", "versions.json");
|
|
2001
1993
|
if (!file || !existsSync(file)) return null;
|
|
2002
1994
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
2003
1995
|
}
|
|
@@ -2007,7 +1999,7 @@ function checkVersionSkew(ctx) {
|
|
|
2007
1999
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2008
2000
|
const dir = findPackageDir(ctx.root, name);
|
|
2009
2001
|
if (!dir) continue;
|
|
2010
|
-
const have = JSON.parse(readFileSync(
|
|
2002
|
+
const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
|
|
2011
2003
|
if (have === want) continue;
|
|
2012
2004
|
ctx.report({
|
|
2013
2005
|
rule: "version-skew",
|
|
@@ -2141,9 +2133,10 @@ function satisfies(version, range) {
|
|
|
2141
2133
|
|
|
2142
2134
|
// src/doctor/installs.ts
|
|
2143
2135
|
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
2136
|
+
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
2144
2137
|
var readManifest = (dir) => {
|
|
2145
2138
|
try {
|
|
2146
|
-
return JSON.parse(readFileSync(
|
|
2139
|
+
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
2147
2140
|
} catch {
|
|
2148
2141
|
return null;
|
|
2149
2142
|
}
|
|
@@ -2160,10 +2153,10 @@ function packagesIn(nodeModules) {
|
|
|
2160
2153
|
const out = [];
|
|
2161
2154
|
for (const entry of readdirSync(nodeModules)) {
|
|
2162
2155
|
if (entry.startsWith(".")) continue;
|
|
2163
|
-
const p =
|
|
2156
|
+
const p = path14.join(nodeModules, entry);
|
|
2164
2157
|
if (entry.startsWith("@")) {
|
|
2165
2158
|
try {
|
|
2166
|
-
for (const sub of readdirSync(p)) out.push(
|
|
2159
|
+
for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
|
|
2167
2160
|
} catch {
|
|
2168
2161
|
}
|
|
2169
2162
|
} else {
|
|
@@ -2175,44 +2168,68 @@ function packagesIn(nodeModules) {
|
|
|
2175
2168
|
function genesisInstalls(root) {
|
|
2176
2169
|
const copies = /* @__PURE__ */ new Map();
|
|
2177
2170
|
const realRoot = real(root);
|
|
2178
|
-
const rel = (abs) =>
|
|
2179
|
-
const
|
|
2171
|
+
const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
|
|
2172
|
+
const via = /* @__PURE__ */ new Map();
|
|
2173
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
2180
2174
|
let copy = copies.get(real2);
|
|
2181
2175
|
if (!copy) {
|
|
2182
|
-
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
|
|
2176
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
2183
2177
|
copies.set(real2, copy);
|
|
2178
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
2184
2179
|
}
|
|
2180
|
+
via.get(real2).add(root2);
|
|
2185
2181
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
2186
2182
|
};
|
|
2187
|
-
const
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2183
|
+
const walk = (kind, roots) => {
|
|
2184
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
2185
|
+
const queue = [];
|
|
2186
|
+
const visit = (dir, by, range) => {
|
|
2187
|
+
const manifest = readManifest(dir);
|
|
2188
|
+
if (!manifest?.name) return;
|
|
2189
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
2190
|
+
const realDir = real(dir);
|
|
2191
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
2192
|
+
if (expanded.has(realDir)) return;
|
|
2193
|
+
expanded.add(realDir);
|
|
2194
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
2195
|
+
};
|
|
2196
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
2197
|
+
while (queue.length) {
|
|
2198
|
+
const { real: from, manifest, label } = queue.shift();
|
|
2199
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
2200
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
2201
|
+
const dir = findPackageDir(from, name);
|
|
2202
|
+
if (dir) visit(dir, label, range);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2197
2205
|
};
|
|
2198
|
-
const
|
|
2199
|
-
const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
2200
|
-
for (const name of Object.keys(appDeps)) {
|
|
2206
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
2201
2207
|
const dir = findPackageDir(root, name);
|
|
2202
|
-
|
|
2203
|
-
}
|
|
2204
|
-
const
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2208
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
2209
|
+
});
|
|
2210
|
+
const app = readManifest(root);
|
|
2211
|
+
let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
2212
|
+
let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
|
|
2213
|
+
if (Object.keys(runtimeDeps).length === 0) {
|
|
2214
|
+
runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
|
|
2215
|
+
devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
|
|
2216
|
+
}
|
|
2217
|
+
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
2218
|
+
const top = path14.join(root, "node_modules");
|
|
2219
|
+
walk(
|
|
2220
|
+
"hoisted",
|
|
2221
|
+
packagesIn(top).filter((dir) => {
|
|
2222
|
+
const name = path14.relative(top, dir).split(path14.sep).join("/");
|
|
2223
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
2224
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
2225
|
+
);
|
|
2226
|
+
const devRoots = { ...devDeps };
|
|
2227
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
2228
|
+
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
2229
|
+
for (const [key2, copy] of copies) {
|
|
2230
|
+
const kinds = via.get(key2);
|
|
2231
|
+
copy.runtime = kinds.has("runtime");
|
|
2232
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
2216
2233
|
}
|
|
2217
2234
|
const byName = /* @__PURE__ */ new Map();
|
|
2218
2235
|
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
@@ -2220,20 +2237,31 @@ function genesisInstalls(root) {
|
|
|
2220
2237
|
return byName;
|
|
2221
2238
|
}
|
|
2222
2239
|
function checkDuplicatePackages(ctx) {
|
|
2240
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
2223
2241
|
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
2224
2242
|
if (copies.length < 2) continue;
|
|
2225
|
-
const
|
|
2243
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
2244
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
2245
|
+
ctx.report({
|
|
2246
|
+
rule: "duplicate-genesis-package",
|
|
2247
|
+
level: "warn",
|
|
2248
|
+
file: "package.json",
|
|
2249
|
+
subject: name,
|
|
2250
|
+
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`
|
|
2251
|
+
});
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2226
2254
|
ctx.report({
|
|
2227
2255
|
rule: "duplicate-genesis-package",
|
|
2228
|
-
level: "
|
|
2256
|
+
level: "info",
|
|
2229
2257
|
file: "package.json",
|
|
2230
2258
|
subject: name,
|
|
2231
|
-
message: `${name}
|
|
2259
|
+
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`
|
|
2232
2260
|
});
|
|
2233
2261
|
}
|
|
2234
2262
|
}
|
|
2235
2263
|
function checkPeerRanges(ctx) {
|
|
2236
|
-
const rel = (abs) =>
|
|
2264
|
+
const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
|
|
2237
2265
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
2238
2266
|
for (const copy of copies) {
|
|
2239
2267
|
const dir = copy.absolutePath;
|
|
@@ -2246,7 +2274,8 @@ function checkPeerRanges(ctx) {
|
|
|
2246
2274
|
if (satisfies(installed, range) !== false) continue;
|
|
2247
2275
|
ctx.report({
|
|
2248
2276
|
rule: "peer-range-mismatch",
|
|
2249
|
-
|
|
2277
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
2278
|
+
level: copy.devOnly ? "info" : "warn",
|
|
2250
2279
|
file: "package.json",
|
|
2251
2280
|
subject: `${copy.name}>${peer}`,
|
|
2252
2281
|
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}`
|
|
@@ -2255,55 +2284,401 @@ function checkPeerRanges(ctx) {
|
|
|
2255
2284
|
}
|
|
2256
2285
|
}
|
|
2257
2286
|
}
|
|
2287
|
+
var TRAIL_DEPTH = 6;
|
|
2288
|
+
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
2289
|
+
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
2290
|
+
var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
2291
|
+
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
2292
|
+
function stripForImports(code) {
|
|
2293
|
+
const out = [];
|
|
2294
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
2295
|
+
const n = code.length;
|
|
2296
|
+
const templates = [];
|
|
2297
|
+
let depth = 0;
|
|
2298
|
+
let i = 0;
|
|
2299
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
2300
|
+
const opensString = () => {
|
|
2301
|
+
const before = out.slice(-12).join("");
|
|
2302
|
+
if (!/[\w$]$/.test(before)) return true;
|
|
2303
|
+
return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
|
|
2304
|
+
};
|
|
2305
|
+
const templateBody = () => {
|
|
2306
|
+
while (i < n) {
|
|
2307
|
+
const ch = code[i];
|
|
2308
|
+
if (ch === "\\") {
|
|
2309
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2310
|
+
i += 2;
|
|
2311
|
+
} else if (ch === "`") {
|
|
2312
|
+
out.push("`");
|
|
2313
|
+
i++;
|
|
2314
|
+
return;
|
|
2315
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
2316
|
+
out.push("${");
|
|
2317
|
+
i += 2;
|
|
2318
|
+
templates.push(depth);
|
|
2319
|
+
depth++;
|
|
2320
|
+
return;
|
|
2321
|
+
} else {
|
|
2322
|
+
out.push(blank(ch));
|
|
2323
|
+
i++;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
while (i < n) {
|
|
2328
|
+
const ch = code[i];
|
|
2329
|
+
const next = code[i + 1];
|
|
2330
|
+
if (ch === "/" && next === "/") {
|
|
2331
|
+
while (i < n && code[i] !== "\n") {
|
|
2332
|
+
out.push(" ");
|
|
2333
|
+
i++;
|
|
2334
|
+
}
|
|
2335
|
+
} else if (ch === "/" && next === "*") {
|
|
2336
|
+
out.push(" ");
|
|
2337
|
+
i += 2;
|
|
2338
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
2339
|
+
out.push(blank(code[i]));
|
|
2340
|
+
i++;
|
|
2341
|
+
}
|
|
2342
|
+
if (i < n) {
|
|
2343
|
+
out.push(" ");
|
|
2344
|
+
i += 2;
|
|
2345
|
+
}
|
|
2346
|
+
} else if ((ch === '"' || ch === "'") && opensString()) {
|
|
2347
|
+
const keep = isSpecifier();
|
|
2348
|
+
out.push(ch);
|
|
2349
|
+
i++;
|
|
2350
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
2351
|
+
if (code[i] === "\\") {
|
|
2352
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
2353
|
+
i += 2;
|
|
2354
|
+
} else {
|
|
2355
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
2356
|
+
i++;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
if (i < n) {
|
|
2360
|
+
out.push(code[i]);
|
|
2361
|
+
i++;
|
|
2362
|
+
}
|
|
2363
|
+
} else if (ch === "`") {
|
|
2364
|
+
out.push("`");
|
|
2365
|
+
i++;
|
|
2366
|
+
templateBody();
|
|
2367
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
2368
|
+
templates.pop();
|
|
2369
|
+
depth--;
|
|
2370
|
+
out.push("}");
|
|
2371
|
+
i++;
|
|
2372
|
+
templateBody();
|
|
2373
|
+
} else {
|
|
2374
|
+
if (ch === "{") depth++;
|
|
2375
|
+
else if (ch === "}") depth--;
|
|
2376
|
+
out.push(ch);
|
|
2377
|
+
i++;
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
return out.join("");
|
|
2381
|
+
}
|
|
2382
|
+
function bindings(clause) {
|
|
2383
|
+
const out = [];
|
|
2384
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
2385
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
2386
|
+
const p = part.trim();
|
|
2387
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2388
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
2389
|
+
}
|
|
2390
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
2391
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
2392
|
+
if (ns) out.push(ns[1]);
|
|
2393
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
2394
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
2395
|
+
return out;
|
|
2396
|
+
}
|
|
2397
|
+
function readJsonc(file) {
|
|
2398
|
+
try {
|
|
2399
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
2400
|
+
return JSON.parse(text);
|
|
2401
|
+
} catch {
|
|
2402
|
+
return null;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
2406
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
2407
|
+
seen.add(file);
|
|
2408
|
+
const json = readJsonc(file);
|
|
2409
|
+
if (!json) return {};
|
|
2410
|
+
const dir = path14.dirname(file);
|
|
2411
|
+
let merged = {};
|
|
2412
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2413
|
+
for (const ext of parents) {
|
|
2414
|
+
if (typeof ext !== "string") continue;
|
|
2415
|
+
let target = null;
|
|
2416
|
+
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
2417
|
+
const abs = path14.resolve(dir, ext);
|
|
2418
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2419
|
+
} else {
|
|
2420
|
+
const parts = ext.split("/");
|
|
2421
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
2422
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2423
|
+
if (pkgDir) {
|
|
2424
|
+
const sub = parts.slice(nameLength).join("/");
|
|
2425
|
+
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
2426
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2430
|
+
}
|
|
2431
|
+
const opts = json.compilerOptions ?? {};
|
|
2432
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
2433
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
2434
|
+
merged.paths = opts.paths;
|
|
2435
|
+
merged.pathsDir = dir;
|
|
2436
|
+
}
|
|
2437
|
+
return merged;
|
|
2438
|
+
}
|
|
2439
|
+
function aliases(root) {
|
|
2440
|
+
const table = [];
|
|
2441
|
+
let baseUrl = null;
|
|
2442
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2443
|
+
const file = path14.join(root, name);
|
|
2444
|
+
if (!existsSync(file)) continue;
|
|
2445
|
+
const config = readTsconfig(root, file);
|
|
2446
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
2447
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
2448
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2449
|
+
if (!Array.isArray(targets)) continue;
|
|
2450
|
+
const exact = !pattern.endsWith("*");
|
|
2451
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
2455
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2456
|
+
if (typeof target !== "string") continue;
|
|
2457
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
2458
|
+
}
|
|
2459
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
|
|
2460
|
+
return { table, baseUrl };
|
|
2461
|
+
}
|
|
2462
|
+
function resolveFile(base) {
|
|
2463
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
|
|
2464
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2465
|
+
for (const p of tries) {
|
|
2466
|
+
if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2467
|
+
}
|
|
2468
|
+
return null;
|
|
2469
|
+
}
|
|
2470
|
+
var trails = /* @__PURE__ */ new WeakMap();
|
|
2471
|
+
function trailFor(ctx) {
|
|
2472
|
+
let t = trails.get(ctx.files);
|
|
2473
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
2474
|
+
return t;
|
|
2475
|
+
}
|
|
2476
|
+
function createTrail(ctx) {
|
|
2477
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
2478
|
+
let declared = null;
|
|
2479
|
+
try {
|
|
2480
|
+
const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
|
|
2481
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
2482
|
+
} catch {
|
|
2483
|
+
declared = null;
|
|
2484
|
+
}
|
|
2485
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2486
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
2487
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
2488
|
+
const importsOf = (file) => {
|
|
2489
|
+
const hit = importsCache.get(file.absolutePath);
|
|
2490
|
+
if (hit) return hit;
|
|
2491
|
+
const files = [];
|
|
2492
|
+
let lost = false;
|
|
2493
|
+
const code = stripped(file);
|
|
2494
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
2495
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2496
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2497
|
+
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]);
|
|
2498
|
+
const specs = [];
|
|
2499
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
2500
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
2501
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
2502
|
+
for (const spec of specs) {
|
|
2503
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
2504
|
+
let resolved = null;
|
|
2505
|
+
if (spec.startsWith(".")) {
|
|
2506
|
+
resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
|
|
2507
|
+
if (!resolved) lost = true;
|
|
2508
|
+
} else {
|
|
2509
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
2510
|
+
if (alias) {
|
|
2511
|
+
for (const t of alias.targets) {
|
|
2512
|
+
resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
|
|
2513
|
+
if (resolved) break;
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
|
|
2517
|
+
if (!resolved) {
|
|
2518
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
2519
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
2523
|
+
}
|
|
2524
|
+
const out = { files, lost };
|
|
2525
|
+
importsCache.set(file.absolutePath, out);
|
|
2526
|
+
return out;
|
|
2527
|
+
};
|
|
2528
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
2529
|
+
const stripped = (file) => {
|
|
2530
|
+
let c = strippedCache.get(file.absolutePath);
|
|
2531
|
+
if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
|
|
2532
|
+
return c;
|
|
2533
|
+
};
|
|
2534
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
2535
|
+
const reach = (file, test2, depth, seen) => {
|
|
2536
|
+
let cache = memo.get(test2);
|
|
2537
|
+
if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
|
|
2538
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
2539
|
+
const cached = cache.get(k);
|
|
2540
|
+
if (cached) return [cached, false];
|
|
2541
|
+
let result;
|
|
2542
|
+
let cut = false;
|
|
2543
|
+
if (test2(stripped(file))) result = "yes";
|
|
2544
|
+
else {
|
|
2545
|
+
const { files, lost } = importsOf(file);
|
|
2546
|
+
let unknown = lost && depth > 0;
|
|
2547
|
+
result = "no";
|
|
2548
|
+
if (depth > 0) {
|
|
2549
|
+
seen.add(file.absolutePath);
|
|
2550
|
+
for (const abs of files) {
|
|
2551
|
+
if (seen.has(abs)) {
|
|
2552
|
+
cut = true;
|
|
2553
|
+
continue;
|
|
2554
|
+
}
|
|
2555
|
+
const target = read(abs);
|
|
2556
|
+
if (!target) {
|
|
2557
|
+
unknown = true;
|
|
2558
|
+
continue;
|
|
2559
|
+
}
|
|
2560
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
2561
|
+
if (c) cut = true;
|
|
2562
|
+
if (r === "yes") {
|
|
2563
|
+
result = "yes";
|
|
2564
|
+
break;
|
|
2565
|
+
}
|
|
2566
|
+
if (r === "unknown") unknown = true;
|
|
2567
|
+
}
|
|
2568
|
+
seen.delete(file.absolutePath);
|
|
2569
|
+
}
|
|
2570
|
+
if (result === "no" && unknown) result = "unknown";
|
|
2571
|
+
}
|
|
2572
|
+
if (result === "yes" || !cut) cache.set(k, result);
|
|
2573
|
+
return [result, cut && result !== "yes"];
|
|
2574
|
+
};
|
|
2575
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
// src/doctor/routes.ts
|
|
2258
2579
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
2259
|
-
var
|
|
2260
|
-
|
|
2580
|
+
var STEMS = {
|
|
2581
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
2582
|
+
"next-app": {
|
|
2583
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
2584
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
2585
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
2586
|
+
},
|
|
2587
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
2588
|
+
};
|
|
2261
2589
|
var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
2262
2590
|
var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
2591
|
+
var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
2592
|
+
var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
2593
|
+
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;
|
|
2263
2594
|
function routesDir(ctx) {
|
|
2264
2595
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
2265
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
2596
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
|
|
2266
2597
|
}
|
|
2267
2598
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
2599
|
+
function flavorOf(dir, rels) {
|
|
2600
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
2601
|
+
if (stems.includes("__root")) return "tanstack";
|
|
2602
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
2603
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
2604
|
+
return "tanstack";
|
|
2605
|
+
}
|
|
2606
|
+
function renders(code) {
|
|
2607
|
+
const elements = renderedElements(code);
|
|
2608
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
2609
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
2610
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
2611
|
+
if (named && !definedHere(named)) return true;
|
|
2612
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
2613
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
2614
|
+
return exported !== void 0 && !definedHere(exported);
|
|
2615
|
+
}
|
|
2268
2616
|
function webRoutes(ctx) {
|
|
2269
2617
|
const dir = routesDir(ctx);
|
|
2270
2618
|
if (!dir) return [];
|
|
2271
|
-
const
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2619
|
+
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(/\.[^.]+$/, "") }));
|
|
2620
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
2621
|
+
const stems = STEMS[flavor];
|
|
2622
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2623
|
+
for (const { file, rel } of candidates) {
|
|
2275
2624
|
const parts = rel.split("/");
|
|
2276
2625
|
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
2626
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
2627
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
2628
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
2629
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
2630
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
2631
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
2632
|
+
}
|
|
2633
|
+
const trail = trailFor(ctx);
|
|
2634
|
+
const routes = [];
|
|
2635
|
+
for (const [id, files] of groups) {
|
|
2636
|
+
const parts = id.split("/");
|
|
2277
2637
|
const stem = parts.pop();
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2280
|
-
|
|
2638
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
2639
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
2640
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
2641
|
+
const segments = [...folders, ...own];
|
|
2642
|
+
const tree = [...parts, ...own];
|
|
2643
|
+
let index = stems.index.has(stem);
|
|
2644
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
2281
2645
|
segments.pop();
|
|
2646
|
+
tree.pop();
|
|
2282
2647
|
index = true;
|
|
2283
2648
|
}
|
|
2284
|
-
const
|
|
2285
|
-
const
|
|
2649
|
+
const code = files.map((f) => f.code).join("\n");
|
|
2650
|
+
const elements = renderedElements(code);
|
|
2651
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
2652
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
2653
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
2654
|
+
const rendering = renders(code);
|
|
2655
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
2656
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
2657
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
2286
2658
|
routes.push({
|
|
2287
|
-
file,
|
|
2659
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
2660
|
+
files,
|
|
2288
2661
|
segments,
|
|
2662
|
+
tree,
|
|
2289
2663
|
index,
|
|
2290
2664
|
layout,
|
|
2291
|
-
|
|
2292
|
-
|
|
2665
|
+
page,
|
|
2666
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
2667
|
+
redirectOnly: !rendering,
|
|
2293
2668
|
parents: []
|
|
2294
2669
|
});
|
|
2295
2670
|
}
|
|
2296
2671
|
for (const r of routes) {
|
|
2297
|
-
const own = r.
|
|
2672
|
+
const own = r.tree;
|
|
2298
2673
|
for (const p of routes) {
|
|
2299
2674
|
if (p === r || !p.layout) continue;
|
|
2300
|
-
const n = p.
|
|
2675
|
+
const n = p.tree.length;
|
|
2301
2676
|
if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
|
|
2302
|
-
if (key(own.slice(0, n)) !== key(p.
|
|
2303
|
-
if (n > 0 && own[n - 1].endsWith("_") && !p.
|
|
2677
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
2678
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
2304
2679
|
r.parents.push(p);
|
|
2305
2680
|
}
|
|
2306
|
-
r.parents.sort((a, b) => b.
|
|
2681
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
2307
2682
|
}
|
|
2308
2683
|
return routes;
|
|
2309
2684
|
}
|
|
@@ -2321,8 +2696,19 @@ var rendersRe = (names) => {
|
|
|
2321
2696
|
const list = [...names];
|
|
2322
2697
|
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
2323
2698
|
};
|
|
2699
|
+
function routeReach(ctx, r, test2) {
|
|
2700
|
+
const trail = trailFor(ctx);
|
|
2701
|
+
let unknown = false;
|
|
2702
|
+
for (const f of r.files) {
|
|
2703
|
+
const got = trail.reach(f, test2);
|
|
2704
|
+
if (got === "yes") return "yes";
|
|
2705
|
+
if (got === "unknown") unknown = true;
|
|
2706
|
+
}
|
|
2707
|
+
return unknown ? "unknown" : "no";
|
|
2708
|
+
}
|
|
2709
|
+
var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
2324
2710
|
function insideShell(ctx, routes) {
|
|
2325
|
-
const shell = new Set(routes.filter((r) =>
|
|
2711
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
2326
2712
|
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
2327
2713
|
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
2328
2714
|
}
|
|
@@ -2333,20 +2719,19 @@ function checkHandRolledSubNav(ctx) {
|
|
|
2333
2719
|
const inShell = insideShell(ctx, routes);
|
|
2334
2720
|
const ui = ctx.genesis.uiPackage;
|
|
2335
2721
|
for (const r of routes) {
|
|
2336
|
-
if (!inShell(r)) continue;
|
|
2337
|
-
const
|
|
2338
|
-
if (
|
|
2339
|
-
|
|
2340
|
-
|
|
2722
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
2723
|
+
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);
|
|
2724
|
+
if (hit) {
|
|
2725
|
+
const { f, m } = hit;
|
|
2726
|
+
const code = f.code;
|
|
2341
2727
|
ctx.report({
|
|
2342
2728
|
rule: "hand-rolled-sub-nav",
|
|
2343
2729
|
level: "warn",
|
|
2344
|
-
file:
|
|
2730
|
+
file: f.path,
|
|
2345
2731
|
line: lineAt(code, m.index),
|
|
2346
2732
|
subject: m[1],
|
|
2347
2733
|
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}`
|
|
2348
2734
|
});
|
|
2349
|
-
break;
|
|
2350
2735
|
}
|
|
2351
2736
|
}
|
|
2352
2737
|
}
|
|
@@ -2394,11 +2779,12 @@ function checkResourceWorkspaces(ctx) {
|
|
|
2394
2779
|
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
2395
2780
|
}
|
|
2396
2781
|
for (const [dir, routes] of byFolder) {
|
|
2397
|
-
const
|
|
2782
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
2783
|
+
const has = routes.filter((r) => reach.get(r) === "yes");
|
|
2398
2784
|
if (has.length === 0) continue;
|
|
2399
2785
|
const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
2400
2786
|
for (const r of routes) {
|
|
2401
|
-
if (
|
|
2787
|
+
if (reach.get(r) !== "no") continue;
|
|
2402
2788
|
ctx.report({
|
|
2403
2789
|
rule: "resource-workspace",
|
|
2404
2790
|
level: "info",
|
|
@@ -2422,14 +2808,14 @@ function checkPageLayouts(ctx) {
|
|
|
2422
2808
|
};
|
|
2423
2809
|
const cache = /* @__PURE__ */ new Map();
|
|
2424
2810
|
const provides = (r) => {
|
|
2425
|
-
if (!cache.has(r)) cache.set(r,
|
|
2811
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
2426
2812
|
return cache.get(r);
|
|
2427
2813
|
};
|
|
2428
2814
|
const list = [...layouts].sort();
|
|
2429
2815
|
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
2430
2816
|
for (const r of routes) {
|
|
2431
|
-
if (r.
|
|
2432
|
-
if (provides(r) || r.parents.some(provides)) continue;
|
|
2817
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
2818
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
2433
2819
|
ctx.report({
|
|
2434
2820
|
rule: "page-layout",
|
|
2435
2821
|
level: "warn",
|
|
@@ -2460,7 +2846,7 @@ function checkIsoDateSlices(ctx) {
|
|
|
2460
2846
|
|
|
2461
2847
|
// src/doctor/index.ts
|
|
2462
2848
|
async function runDoctor(options = {}) {
|
|
2463
|
-
const root =
|
|
2849
|
+
const root = path14.resolve(options.root ?? process.cwd());
|
|
2464
2850
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
2465
2851
|
const config = loaded.config;
|
|
2466
2852
|
const genesis = options.genesis ?? loadGenesis(root, config);
|