@marktiderman/genesis-cli 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -5
- package/dist/cli.js +764 -257
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +31 -4
- package/dist/doctor.js +644 -144
- package/dist/doctor.js.map +1 -1
- package/dist/genesis-catalog.json +73 -15
- package/dist/index.js +647 -147
- package/dist/index.js.map +1 -1
- package/dist/vite.js +648 -148
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/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",
|
|
@@ -966,7 +966,8 @@ var BUILTIN_RULES = [
|
|
|
966
966
|
"migration-rls",
|
|
967
967
|
"migration-definer-search-path",
|
|
968
968
|
"migration-edited",
|
|
969
|
-
"migration-testing-kit"
|
|
969
|
+
"migration-testing-kit",
|
|
970
|
+
"migration-view-rls"
|
|
970
971
|
];
|
|
971
972
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
972
973
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -984,7 +985,7 @@ function importSpecifiers(file) {
|
|
|
984
985
|
}
|
|
985
986
|
function checkProjectLayout(ctx) {
|
|
986
987
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
987
|
-
if (existsSync(
|
|
988
|
+
if (existsSync(path14.join(ctx.root, dir))) {
|
|
988
989
|
ctx.report({
|
|
989
990
|
rule: "local-primitives",
|
|
990
991
|
file: dir,
|
|
@@ -994,7 +995,7 @@ function checkProjectLayout(ctx) {
|
|
|
994
995
|
}
|
|
995
996
|
}
|
|
996
997
|
for (const file of STARTER_LEFTOVERS) {
|
|
997
|
-
if (existsSync(
|
|
998
|
+
if (existsSync(path14.join(ctx.root, file))) {
|
|
998
999
|
ctx.report({
|
|
999
1000
|
rule: "starter-leftover",
|
|
1000
1001
|
level: "warn",
|
|
@@ -1083,7 +1084,7 @@ function checkTokens(ctx) {
|
|
|
1083
1084
|
}
|
|
1084
1085
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
1085
1086
|
if (/[*?]/.test(pattern)) continue;
|
|
1086
|
-
const abs =
|
|
1087
|
+
const abs = path14.join(ctx.root, pattern);
|
|
1087
1088
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
1088
1089
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
1089
1090
|
}
|
|
@@ -1189,10 +1190,10 @@ function localImports(root, file) {
|
|
|
1189
1190
|
const out = [];
|
|
1190
1191
|
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1191
1192
|
const spec = m[1];
|
|
1192
|
-
const bases = spec.startsWith(".") ? [
|
|
1193
|
+
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
1194
|
for (const base of bases) {
|
|
1194
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
1195
|
-
(p) => SCRIPT_EXTS2.has(
|
|
1195
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
|
|
1196
|
+
(p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
|
|
1196
1197
|
);
|
|
1197
1198
|
if (hit) {
|
|
1198
1199
|
out.push(hit);
|
|
@@ -1209,14 +1210,6 @@ function readSource(abs) {
|
|
|
1209
1210
|
return null;
|
|
1210
1211
|
}
|
|
1211
1212
|
}
|
|
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
1213
|
function tagEnd(code, start) {
|
|
1221
1214
|
let depth = 0;
|
|
1222
1215
|
let quote = null;
|
|
@@ -1364,7 +1357,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1364
1357
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
1365
1358
|
const code = file.code;
|
|
1366
1359
|
const hidden = HIDES_HEADER.exec(code);
|
|
1367
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
1360
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
|
|
1368
1361
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1369
1362
|
if (hidden && own) {
|
|
1370
1363
|
reported.add(file.path);
|
|
@@ -1392,7 +1385,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1392
1385
|
}
|
|
1393
1386
|
for (const file of ctx.files) {
|
|
1394
1387
|
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(
|
|
1388
|
+
const layout = hidingLayouts.get(path14.posix.dirname(file.path));
|
|
1396
1389
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1397
1390
|
if (!layout || !own) continue;
|
|
1398
1391
|
ctx.report({
|
|
@@ -1407,13 +1400,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1407
1400
|
}
|
|
1408
1401
|
function routerRoot(ctx) {
|
|
1409
1402
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1410
|
-
return existsSync(
|
|
1403
|
+
return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1411
1404
|
}
|
|
1412
1405
|
function checkScreenLayouts(ctx, pkg) {
|
|
1413
1406
|
const layouts = nativeLayouts(pkg);
|
|
1414
1407
|
if (layouts.length === 0) return;
|
|
1415
1408
|
const rootDir = routerRoot(ctx);
|
|
1416
|
-
if (!existsSync(
|
|
1409
|
+
if (!existsSync(path14.join(ctx.root, rootDir))) {
|
|
1417
1410
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1418
1411
|
return;
|
|
1419
1412
|
}
|
|
@@ -1427,15 +1420,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
1427
1420
|
});
|
|
1428
1421
|
return;
|
|
1429
1422
|
}
|
|
1430
|
-
const
|
|
1423
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
1431
1424
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
1432
1425
|
for (const file of routes) {
|
|
1433
1426
|
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1434
1427
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
1435
|
-
if (
|
|
1428
|
+
if (renders2.test(file.code)) continue;
|
|
1436
1429
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
1437
1430
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
1438
|
-
return target !== null &&
|
|
1431
|
+
return target !== null && renders2.test(target.code);
|
|
1439
1432
|
});
|
|
1440
1433
|
if (viaImport) continue;
|
|
1441
1434
|
ctx.report({
|
|
@@ -1468,7 +1461,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
1468
1461
|
function readExpoConfigs(root) {
|
|
1469
1462
|
const out = [];
|
|
1470
1463
|
for (const name of EXPO_CONFIGS) {
|
|
1471
|
-
const abs =
|
|
1464
|
+
const abs = path14.join(root, name);
|
|
1472
1465
|
if (!existsSync(abs)) continue;
|
|
1473
1466
|
const text = readFileSync(abs, "utf8");
|
|
1474
1467
|
let json = null;
|
|
@@ -1502,13 +1495,13 @@ function pluginOptions(json, module) {
|
|
|
1502
1495
|
return null;
|
|
1503
1496
|
}
|
|
1504
1497
|
function dependencies(root) {
|
|
1505
|
-
const file =
|
|
1498
|
+
const file = path14.join(root, "package.json");
|
|
1506
1499
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1507
1500
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1508
1501
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1509
1502
|
}
|
|
1510
1503
|
function runtimeDependencies(root) {
|
|
1511
|
-
const file =
|
|
1504
|
+
const file = path14.join(root, "package.json");
|
|
1512
1505
|
if (!existsSync(file)) return {};
|
|
1513
1506
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1514
1507
|
}
|
|
@@ -1771,9 +1764,9 @@ function gitView(root, dir, base) {
|
|
|
1771
1764
|
function checkSupabasePack(ctx) {
|
|
1772
1765
|
const settings = ctx.config.supabase ?? {};
|
|
1773
1766
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1774
|
-
const abs =
|
|
1767
|
+
const abs = path14.join(ctx.root, dir);
|
|
1775
1768
|
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(
|
|
1769
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
1777
1770
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1778
1771
|
const base = settings.base ?? DEFAULT_BASE;
|
|
1779
1772
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -1790,7 +1783,7 @@ function checkSupabasePack(ctx) {
|
|
|
1790
1783
|
}
|
|
1791
1784
|
}
|
|
1792
1785
|
const since = settings.since;
|
|
1793
|
-
const afterSince = (file) => since === void 0 ||
|
|
1786
|
+
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
1794
1787
|
if ("reason" in view && since === void 0) {
|
|
1795
1788
|
ctx.report({
|
|
1796
1789
|
rule: "migration-grants",
|
|
@@ -1803,6 +1796,7 @@ function checkSupabasePack(ctx) {
|
|
|
1803
1796
|
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
1804
1797
|
}
|
|
1805
1798
|
checkRls(ctx, migrations, exposed);
|
|
1799
|
+
checkViewInvoker(ctx, migrations, exposed);
|
|
1806
1800
|
checkDefinerSearchPath(ctx, migrations);
|
|
1807
1801
|
checkTestingKit(ctx, migrations);
|
|
1808
1802
|
}
|
|
@@ -1932,6 +1926,50 @@ function checkRls(ctx, migrations, exposed) {
|
|
|
1932
1926
|
});
|
|
1933
1927
|
}
|
|
1934
1928
|
}
|
|
1929
|
+
function checkViewInvoker(ctx, migrations, exposed) {
|
|
1930
|
+
const views = /* @__PURE__ */ new Map();
|
|
1931
|
+
const name = String.raw`([\w$.]+)`;
|
|
1932
|
+
const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
|
|
1933
|
+
for (const { file, statements } of migrations) {
|
|
1934
|
+
for (const { sql, line } of statements) {
|
|
1935
|
+
const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
|
|
1936
|
+
if (create) {
|
|
1937
|
+
if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
|
|
1938
|
+
const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
|
|
1939
|
+
views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
|
|
1943
|
+
if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
|
|
1944
|
+
const state = views.get(qualify(alter[1]));
|
|
1945
|
+
if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
|
|
1946
|
+
continue;
|
|
1947
|
+
}
|
|
1948
|
+
const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
|
|
1949
|
+
if (rename) {
|
|
1950
|
+
const from = qualify(rename[1]);
|
|
1951
|
+
const state = views.get(from);
|
|
1952
|
+
if (state) {
|
|
1953
|
+
views.delete(from);
|
|
1954
|
+
views.set(`${schemaOf(from)}.${rename[2]}`, state);
|
|
1955
|
+
}
|
|
1956
|
+
continue;
|
|
1957
|
+
}
|
|
1958
|
+
const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1959
|
+
if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
for (const [v, at] of views) {
|
|
1963
|
+
if (at.invoker || !exposed.has(schemaOf(v))) continue;
|
|
1964
|
+
ctx.report({
|
|
1965
|
+
rule: "migration-view-rls",
|
|
1966
|
+
file: at.file,
|
|
1967
|
+
line: at.line,
|
|
1968
|
+
subject: v,
|
|
1969
|
+
message: `${v} runs as its owner, so it reads past row level security; create it "with (security_invoker = true)" or add "alter view ${v} set (security_invoker = true);"`
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1935
1973
|
function checkDefinerSearchPath(ctx, migrations) {
|
|
1936
1974
|
const fns = /* @__PURE__ */ new Map();
|
|
1937
1975
|
const keysFor = (sql, nameEnd, fnName) => {
|
|
@@ -1997,7 +2035,7 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1997
2035
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
1998
2036
|
function readReleaseManifest(root) {
|
|
1999
2037
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2000
|
-
const file = dir &&
|
|
2038
|
+
const file = dir && path14.join(dir, "dist", "versions.json");
|
|
2001
2039
|
if (!file || !existsSync(file)) return null;
|
|
2002
2040
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
2003
2041
|
}
|
|
@@ -2007,7 +2045,7 @@ function checkVersionSkew(ctx) {
|
|
|
2007
2045
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2008
2046
|
const dir = findPackageDir(ctx.root, name);
|
|
2009
2047
|
if (!dir) continue;
|
|
2010
|
-
const have = JSON.parse(readFileSync(
|
|
2048
|
+
const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
|
|
2011
2049
|
if (have === want) continue;
|
|
2012
2050
|
ctx.report({
|
|
2013
2051
|
rule: "version-skew",
|
|
@@ -2141,9 +2179,11 @@ function satisfies(version, range) {
|
|
|
2141
2179
|
|
|
2142
2180
|
// src/doctor/installs.ts
|
|
2143
2181
|
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
2182
|
+
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
2183
|
+
var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
2144
2184
|
var readManifest = (dir) => {
|
|
2145
2185
|
try {
|
|
2146
|
-
return JSON.parse(readFileSync(
|
|
2186
|
+
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
2147
2187
|
} catch {
|
|
2148
2188
|
return null;
|
|
2149
2189
|
}
|
|
@@ -2160,10 +2200,10 @@ function packagesIn(nodeModules) {
|
|
|
2160
2200
|
const out = [];
|
|
2161
2201
|
for (const entry of readdirSync(nodeModules)) {
|
|
2162
2202
|
if (entry.startsWith(".")) continue;
|
|
2163
|
-
const p =
|
|
2203
|
+
const p = path14.join(nodeModules, entry);
|
|
2164
2204
|
if (entry.startsWith("@")) {
|
|
2165
2205
|
try {
|
|
2166
|
-
for (const sub of readdirSync(p)) out.push(
|
|
2206
|
+
for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
|
|
2167
2207
|
} catch {
|
|
2168
2208
|
}
|
|
2169
2209
|
} else {
|
|
@@ -2175,44 +2215,70 @@ function packagesIn(nodeModules) {
|
|
|
2175
2215
|
function genesisInstalls(root) {
|
|
2176
2216
|
const copies = /* @__PURE__ */ new Map();
|
|
2177
2217
|
const realRoot = real(root);
|
|
2178
|
-
const rel = (abs) =>
|
|
2179
|
-
const
|
|
2218
|
+
const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
|
|
2219
|
+
const via = /* @__PURE__ */ new Map();
|
|
2220
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
2180
2221
|
let copy = copies.get(real2);
|
|
2181
2222
|
if (!copy) {
|
|
2182
|
-
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [] };
|
|
2223
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
2183
2224
|
copies.set(real2, copy);
|
|
2225
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
2184
2226
|
}
|
|
2227
|
+
via.get(real2).add(root2);
|
|
2185
2228
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
2186
2229
|
};
|
|
2187
|
-
const
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2230
|
+
const walk = (kind, roots) => {
|
|
2231
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
2232
|
+
const queue = [];
|
|
2233
|
+
const visit = (dir, by, range) => {
|
|
2234
|
+
const manifest = readManifest(dir);
|
|
2235
|
+
if (!manifest?.name) return;
|
|
2236
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
2237
|
+
const realDir = real(dir);
|
|
2238
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
2239
|
+
if (expanded.has(realDir)) return;
|
|
2240
|
+
expanded.add(realDir);
|
|
2241
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
2242
|
+
};
|
|
2243
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
2244
|
+
while (queue.length) {
|
|
2245
|
+
const { real: from, manifest, label } = queue.shift();
|
|
2246
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
2247
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
2248
|
+
const dir = findPackageDir(from, name);
|
|
2249
|
+
if (dir) visit(dir, label, range);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2197
2252
|
};
|
|
2198
|
-
const
|
|
2199
|
-
const appDeps = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
2200
|
-
for (const name of Object.keys(appDeps)) {
|
|
2253
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
2201
2254
|
const dir = findPackageDir(root, name);
|
|
2202
|
-
|
|
2203
|
-
}
|
|
2204
|
-
const
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2255
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
2256
|
+
});
|
|
2257
|
+
const app = readManifest(root);
|
|
2258
|
+
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
2259
|
+
const runtimeDeps = {
|
|
2260
|
+
...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
|
|
2261
|
+
...app?.peerDependencies,
|
|
2262
|
+
...app?.optionalDependencies,
|
|
2263
|
+
...app?.dependencies
|
|
2264
|
+
};
|
|
2265
|
+
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
2266
|
+
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
2267
|
+
const top = path14.join(root, "node_modules");
|
|
2268
|
+
walk(
|
|
2269
|
+
"hoisted",
|
|
2270
|
+
packagesIn(top).filter((dir) => {
|
|
2271
|
+
const name = path14.relative(top, dir).split(path14.sep).join("/");
|
|
2272
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
2273
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
2274
|
+
);
|
|
2275
|
+
const devRoots = { ...devDeps };
|
|
2276
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
2277
|
+
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
2278
|
+
for (const [key2, copy] of copies) {
|
|
2279
|
+
const kinds = via.get(key2);
|
|
2280
|
+
copy.runtime = kinds.has("runtime");
|
|
2281
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
2216
2282
|
}
|
|
2217
2283
|
const byName = /* @__PURE__ */ new Map();
|
|
2218
2284
|
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
@@ -2220,20 +2286,31 @@ function genesisInstalls(root) {
|
|
|
2220
2286
|
return byName;
|
|
2221
2287
|
}
|
|
2222
2288
|
function checkDuplicatePackages(ctx) {
|
|
2289
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
2223
2290
|
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
2224
2291
|
if (copies.length < 2) continue;
|
|
2225
|
-
const
|
|
2292
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
2293
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
2294
|
+
ctx.report({
|
|
2295
|
+
rule: "duplicate-genesis-package",
|
|
2296
|
+
level: "warn",
|
|
2297
|
+
file: "package.json",
|
|
2298
|
+
subject: name,
|
|
2299
|
+
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`
|
|
2300
|
+
});
|
|
2301
|
+
continue;
|
|
2302
|
+
}
|
|
2226
2303
|
ctx.report({
|
|
2227
2304
|
rule: "duplicate-genesis-package",
|
|
2228
|
-
level: "
|
|
2305
|
+
level: "info",
|
|
2229
2306
|
file: "package.json",
|
|
2230
2307
|
subject: name,
|
|
2231
|
-
message: `${name}
|
|
2308
|
+
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
2309
|
});
|
|
2233
2310
|
}
|
|
2234
2311
|
}
|
|
2235
2312
|
function checkPeerRanges(ctx) {
|
|
2236
|
-
const rel = (abs) =>
|
|
2313
|
+
const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
|
|
2237
2314
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
2238
2315
|
for (const copy of copies) {
|
|
2239
2316
|
const dir = copy.absolutePath;
|
|
@@ -2246,7 +2323,8 @@ function checkPeerRanges(ctx) {
|
|
|
2246
2323
|
if (satisfies(installed, range) !== false) continue;
|
|
2247
2324
|
ctx.report({
|
|
2248
2325
|
rule: "peer-range-mismatch",
|
|
2249
|
-
|
|
2326
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
2327
|
+
level: copy.devOnly ? "info" : "warn",
|
|
2250
2328
|
file: "package.json",
|
|
2251
2329
|
subject: `${copy.name}>${peer}`,
|
|
2252
2330
|
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 +2333,466 @@ function checkPeerRanges(ctx) {
|
|
|
2255
2333
|
}
|
|
2256
2334
|
}
|
|
2257
2335
|
}
|
|
2336
|
+
var TRAIL_DEPTH = 6;
|
|
2337
|
+
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
2338
|
+
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
2339
|
+
var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
2340
|
+
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
2341
|
+
function stripForImports(code) {
|
|
2342
|
+
const out = [];
|
|
2343
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
2344
|
+
const n = code.length;
|
|
2345
|
+
const templates = [];
|
|
2346
|
+
let depth = 0;
|
|
2347
|
+
let i = 0;
|
|
2348
|
+
let sure = true;
|
|
2349
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
2350
|
+
const before = () => out.slice(-24).join("");
|
|
2351
|
+
const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
|
|
2352
|
+
const startsExpression = (b) => {
|
|
2353
|
+
const t = b.replace(/\s+$/, "");
|
|
2354
|
+
if (!t) return true;
|
|
2355
|
+
if (KEYWORD.test(b)) return true;
|
|
2356
|
+
return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
|
|
2357
|
+
};
|
|
2358
|
+
const exprStart = () => startsExpression(before());
|
|
2359
|
+
const taggedTemplate = () => {
|
|
2360
|
+
const b = out.slice(-48).join("");
|
|
2361
|
+
const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
|
|
2362
|
+
return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
|
|
2363
|
+
};
|
|
2364
|
+
const templateBody = () => {
|
|
2365
|
+
while (i < n) {
|
|
2366
|
+
const ch = code[i];
|
|
2367
|
+
if (ch === "\\") {
|
|
2368
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2369
|
+
i += 2;
|
|
2370
|
+
} else if (ch === "`") {
|
|
2371
|
+
out.push("`");
|
|
2372
|
+
i++;
|
|
2373
|
+
return;
|
|
2374
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
2375
|
+
out.push("${");
|
|
2376
|
+
i += 2;
|
|
2377
|
+
templates.push(depth);
|
|
2378
|
+
depth++;
|
|
2379
|
+
return;
|
|
2380
|
+
} else {
|
|
2381
|
+
out.push(blank(ch));
|
|
2382
|
+
i++;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
sure = false;
|
|
2386
|
+
};
|
|
2387
|
+
while (i < n && sure) {
|
|
2388
|
+
const ch = code[i];
|
|
2389
|
+
const next = code[i + 1];
|
|
2390
|
+
if (ch === "/" && next === "/") {
|
|
2391
|
+
while (i < n && code[i] !== "\n") {
|
|
2392
|
+
out.push(" ");
|
|
2393
|
+
i++;
|
|
2394
|
+
}
|
|
2395
|
+
} else if (ch === "/" && next === "*") {
|
|
2396
|
+
out.push(" ");
|
|
2397
|
+
i += 2;
|
|
2398
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
2399
|
+
out.push(blank(code[i]));
|
|
2400
|
+
i++;
|
|
2401
|
+
}
|
|
2402
|
+
if (i < n) {
|
|
2403
|
+
out.push(" ");
|
|
2404
|
+
i += 2;
|
|
2405
|
+
}
|
|
2406
|
+
} else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
|
|
2407
|
+
const afterBrace = /[}>]\s*$/.test(before());
|
|
2408
|
+
const start = i;
|
|
2409
|
+
const mark = out.length;
|
|
2410
|
+
out.push("/");
|
|
2411
|
+
i++;
|
|
2412
|
+
let inClass = false;
|
|
2413
|
+
for (; ; ) {
|
|
2414
|
+
const c = code[i];
|
|
2415
|
+
if (c === void 0 || c === "\n") {
|
|
2416
|
+
if (afterBrace) {
|
|
2417
|
+
out.length = mark;
|
|
2418
|
+
out.push("/");
|
|
2419
|
+
i = start + 1;
|
|
2420
|
+
} else sure = false;
|
|
2421
|
+
break;
|
|
2422
|
+
}
|
|
2423
|
+
if (c === "\\") {
|
|
2424
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2425
|
+
i += 2;
|
|
2426
|
+
continue;
|
|
2427
|
+
}
|
|
2428
|
+
i++;
|
|
2429
|
+
if (c === "[") inClass = true;
|
|
2430
|
+
else if (c === "]") inClass = false;
|
|
2431
|
+
else if (c === "/" && !inClass) {
|
|
2432
|
+
if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
|
|
2433
|
+
out.length = mark;
|
|
2434
|
+
out.push("/");
|
|
2435
|
+
i = start + 1;
|
|
2436
|
+
break;
|
|
2437
|
+
}
|
|
2438
|
+
out.push("/");
|
|
2439
|
+
break;
|
|
2440
|
+
}
|
|
2441
|
+
out.push(" ");
|
|
2442
|
+
}
|
|
2443
|
+
if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
|
|
2444
|
+
} else if ((ch === '"' || ch === "'") && exprStart()) {
|
|
2445
|
+
const keep = isSpecifier();
|
|
2446
|
+
out.push(ch);
|
|
2447
|
+
i++;
|
|
2448
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
2449
|
+
if (code[i] === "\\") {
|
|
2450
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
2451
|
+
i += 2;
|
|
2452
|
+
} else {
|
|
2453
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
2454
|
+
i++;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
if (code[i] !== ch) sure = false;
|
|
2458
|
+
else {
|
|
2459
|
+
out.push(code[i]);
|
|
2460
|
+
i++;
|
|
2461
|
+
}
|
|
2462
|
+
} else if (ch === "`" && (exprStart() || taggedTemplate())) {
|
|
2463
|
+
out.push("`");
|
|
2464
|
+
i++;
|
|
2465
|
+
templateBody();
|
|
2466
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
2467
|
+
templates.pop();
|
|
2468
|
+
depth--;
|
|
2469
|
+
out.push("}");
|
|
2470
|
+
i++;
|
|
2471
|
+
templateBody();
|
|
2472
|
+
} else {
|
|
2473
|
+
if (ch === "{") depth++;
|
|
2474
|
+
else if (ch === "}") depth--;
|
|
2475
|
+
out.push(ch);
|
|
2476
|
+
i++;
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
return sure && templates.length === 0 ? out.join("") : null;
|
|
2480
|
+
}
|
|
2481
|
+
function bindings(clause) {
|
|
2482
|
+
const out = [];
|
|
2483
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
2484
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
2485
|
+
const p = part.trim();
|
|
2486
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2487
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
2488
|
+
}
|
|
2489
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
2490
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
2491
|
+
if (ns) out.push(ns[1]);
|
|
2492
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
2493
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
2494
|
+
return out;
|
|
2495
|
+
}
|
|
2496
|
+
function readJsonc(file) {
|
|
2497
|
+
try {
|
|
2498
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
2499
|
+
return JSON.parse(text);
|
|
2500
|
+
} catch {
|
|
2501
|
+
return null;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
2505
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
2506
|
+
seen.add(file);
|
|
2507
|
+
const json = readJsonc(file);
|
|
2508
|
+
if (!json) return {};
|
|
2509
|
+
const dir = path14.dirname(file);
|
|
2510
|
+
let merged = {};
|
|
2511
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2512
|
+
for (const ext of parents) {
|
|
2513
|
+
if (typeof ext !== "string") continue;
|
|
2514
|
+
let target = null;
|
|
2515
|
+
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
2516
|
+
const abs = path14.resolve(dir, ext);
|
|
2517
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2518
|
+
} else {
|
|
2519
|
+
const parts = ext.split("/");
|
|
2520
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
2521
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2522
|
+
if (pkgDir) {
|
|
2523
|
+
const sub = parts.slice(nameLength).join("/");
|
|
2524
|
+
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
2525
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2529
|
+
}
|
|
2530
|
+
const opts = json.compilerOptions ?? {};
|
|
2531
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
2532
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
2533
|
+
merged.paths = opts.paths;
|
|
2534
|
+
merged.pathsDir = dir;
|
|
2535
|
+
}
|
|
2536
|
+
return merged;
|
|
2537
|
+
}
|
|
2538
|
+
function aliases(root) {
|
|
2539
|
+
const table = [];
|
|
2540
|
+
let baseUrl = null;
|
|
2541
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2542
|
+
const file = path14.join(root, name);
|
|
2543
|
+
if (!existsSync(file)) continue;
|
|
2544
|
+
const config = readTsconfig(root, file);
|
|
2545
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
2546
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
2547
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2548
|
+
if (!Array.isArray(targets)) continue;
|
|
2549
|
+
const exact = !pattern.endsWith("*");
|
|
2550
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
2554
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2555
|
+
if (typeof target !== "string") continue;
|
|
2556
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
2557
|
+
}
|
|
2558
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
|
|
2559
|
+
return { table, baseUrl };
|
|
2560
|
+
}
|
|
2561
|
+
function resolveFile(base) {
|
|
2562
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
|
|
2563
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2564
|
+
for (const p of tries) {
|
|
2565
|
+
if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2566
|
+
}
|
|
2567
|
+
return null;
|
|
2568
|
+
}
|
|
2569
|
+
var trails = /* @__PURE__ */ new WeakMap();
|
|
2570
|
+
function trailFor(ctx) {
|
|
2571
|
+
let t = trails.get(ctx.files);
|
|
2572
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
2573
|
+
return t;
|
|
2574
|
+
}
|
|
2575
|
+
function createTrail(ctx) {
|
|
2576
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
2577
|
+
let declared = null;
|
|
2578
|
+
try {
|
|
2579
|
+
const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
|
|
2580
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
2581
|
+
} catch {
|
|
2582
|
+
declared = null;
|
|
2583
|
+
}
|
|
2584
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2585
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
2586
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
2587
|
+
const importsOf = (file) => {
|
|
2588
|
+
const hit = importsCache.get(file.absolutePath);
|
|
2589
|
+
if (hit) return hit;
|
|
2590
|
+
const files = [];
|
|
2591
|
+
let lost = false;
|
|
2592
|
+
const code = stripped(file);
|
|
2593
|
+
if (code === null) {
|
|
2594
|
+
const out2 = { files: [], lost: true };
|
|
2595
|
+
importsCache.set(file.absolutePath, out2);
|
|
2596
|
+
return out2;
|
|
2597
|
+
}
|
|
2598
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
2599
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2600
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2601
|
+
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]);
|
|
2602
|
+
const specs = [];
|
|
2603
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
2604
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
2605
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
2606
|
+
for (const spec of specs) {
|
|
2607
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
2608
|
+
let resolved = null;
|
|
2609
|
+
if (spec.startsWith(".")) {
|
|
2610
|
+
resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
|
|
2611
|
+
if (!resolved) lost = true;
|
|
2612
|
+
} else {
|
|
2613
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
2614
|
+
if (alias) {
|
|
2615
|
+
for (const t of alias.targets) {
|
|
2616
|
+
resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
|
|
2617
|
+
if (resolved) break;
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
|
|
2621
|
+
if (!resolved) {
|
|
2622
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
2623
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
2627
|
+
}
|
|
2628
|
+
const out = { files, lost };
|
|
2629
|
+
importsCache.set(file.absolutePath, out);
|
|
2630
|
+
return out;
|
|
2631
|
+
};
|
|
2632
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
2633
|
+
const stripped = (file) => {
|
|
2634
|
+
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
2635
|
+
return strippedCache.get(file.absolutePath);
|
|
2636
|
+
};
|
|
2637
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
2638
|
+
const reach = (file, test2, depth, seen) => {
|
|
2639
|
+
let cache = memo.get(test2);
|
|
2640
|
+
if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
2641
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
2642
|
+
const free = cache.free.get(k);
|
|
2643
|
+
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
2644
|
+
const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
2645
|
+
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
2646
|
+
let result;
|
|
2647
|
+
const cut = /* @__PURE__ */ new Set();
|
|
2648
|
+
const code = stripped(file);
|
|
2649
|
+
if (code === null) result = "unknown";
|
|
2650
|
+
else if (test2(code)) result = "yes";
|
|
2651
|
+
else {
|
|
2652
|
+
const { files, lost } = importsOf(file);
|
|
2653
|
+
let unknown = lost && depth > 0;
|
|
2654
|
+
result = "no";
|
|
2655
|
+
if (depth > 0) {
|
|
2656
|
+
seen.add(file.absolutePath);
|
|
2657
|
+
for (const abs of files) {
|
|
2658
|
+
if (seen.has(abs)) {
|
|
2659
|
+
cut.add(abs);
|
|
2660
|
+
continue;
|
|
2661
|
+
}
|
|
2662
|
+
const target = read(abs);
|
|
2663
|
+
if (!target) {
|
|
2664
|
+
unknown = true;
|
|
2665
|
+
continue;
|
|
2666
|
+
}
|
|
2667
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
2668
|
+
for (const m of c) cut.add(m);
|
|
2669
|
+
if (r === "yes") {
|
|
2670
|
+
result = "yes";
|
|
2671
|
+
break;
|
|
2672
|
+
}
|
|
2673
|
+
if (r === "unknown") unknown = true;
|
|
2674
|
+
}
|
|
2675
|
+
seen.delete(file.absolutePath);
|
|
2676
|
+
cut.delete(file.absolutePath);
|
|
2677
|
+
}
|
|
2678
|
+
if (result === "no" && unknown) result = "unknown";
|
|
2679
|
+
}
|
|
2680
|
+
if (result === "yes" || cut.size === 0) {
|
|
2681
|
+
cache.free.set(k, result);
|
|
2682
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
2683
|
+
}
|
|
2684
|
+
const entries = cache.cut.get(k) ?? [];
|
|
2685
|
+
entries.push({ cut: [...cut], result });
|
|
2686
|
+
cache.cut.set(k, entries);
|
|
2687
|
+
return [result, cut];
|
|
2688
|
+
};
|
|
2689
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
// src/doctor/routes.ts
|
|
2258
2693
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
2259
|
-
var
|
|
2260
|
-
|
|
2694
|
+
var STEMS = {
|
|
2695
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
2696
|
+
"next-app": {
|
|
2697
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
2698
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
2699
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
2700
|
+
},
|
|
2701
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
2702
|
+
};
|
|
2261
2703
|
var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
2262
2704
|
var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
2705
|
+
var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
2706
|
+
var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
2707
|
+
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
2708
|
function routesDir(ctx) {
|
|
2264
2709
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
2265
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
2710
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
|
|
2266
2711
|
}
|
|
2267
2712
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
2713
|
+
function flavorOf(dir, rels) {
|
|
2714
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
2715
|
+
if (stems.includes("__root")) return "tanstack";
|
|
2716
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
2717
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
2718
|
+
return "tanstack";
|
|
2719
|
+
}
|
|
2720
|
+
function renders(code) {
|
|
2721
|
+
const elements = renderedElements(code);
|
|
2722
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
2723
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
2724
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
2725
|
+
if (named && !definedHere(named)) return true;
|
|
2726
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
2727
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
2728
|
+
return exported !== void 0 && !definedHere(exported);
|
|
2729
|
+
}
|
|
2268
2730
|
function webRoutes(ctx) {
|
|
2269
2731
|
const dir = routesDir(ctx);
|
|
2270
2732
|
if (!dir) return [];
|
|
2271
|
-
const
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2733
|
+
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(/\.[^.]+$/, "") }));
|
|
2734
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
2735
|
+
const stems = STEMS[flavor];
|
|
2736
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2737
|
+
for (const { file, rel } of candidates) {
|
|
2275
2738
|
const parts = rel.split("/");
|
|
2276
2739
|
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
2740
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
2741
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
2742
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
2743
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
2744
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
2745
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
2746
|
+
}
|
|
2747
|
+
const trail = trailFor(ctx);
|
|
2748
|
+
const routes = [];
|
|
2749
|
+
for (const [id, files] of groups) {
|
|
2750
|
+
const parts = id.split("/");
|
|
2277
2751
|
const stem = parts.pop();
|
|
2278
|
-
const
|
|
2279
|
-
|
|
2280
|
-
|
|
2752
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
2753
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
2754
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
2755
|
+
const segments = [...folders, ...own];
|
|
2756
|
+
const tree = [...parts, ...own];
|
|
2757
|
+
let index = stems.index.has(stem);
|
|
2758
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
2281
2759
|
segments.pop();
|
|
2760
|
+
tree.pop();
|
|
2282
2761
|
index = true;
|
|
2283
2762
|
}
|
|
2284
|
-
const
|
|
2285
|
-
const
|
|
2763
|
+
const code = files.map((f) => f.code).join("\n");
|
|
2764
|
+
const elements = renderedElements(code);
|
|
2765
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
2766
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
2767
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
2768
|
+
const rendering = renders(code);
|
|
2769
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
2770
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
2771
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
2286
2772
|
routes.push({
|
|
2287
|
-
file,
|
|
2773
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
2774
|
+
files,
|
|
2288
2775
|
segments,
|
|
2776
|
+
tree,
|
|
2289
2777
|
index,
|
|
2290
2778
|
layout,
|
|
2291
|
-
|
|
2292
|
-
|
|
2779
|
+
page,
|
|
2780
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
2781
|
+
redirectOnly: !rendering,
|
|
2293
2782
|
parents: []
|
|
2294
2783
|
});
|
|
2295
2784
|
}
|
|
2296
2785
|
for (const r of routes) {
|
|
2297
|
-
const own = r.
|
|
2786
|
+
const own = r.tree;
|
|
2298
2787
|
for (const p of routes) {
|
|
2299
2788
|
if (p === r || !p.layout) continue;
|
|
2300
|
-
const n = p.
|
|
2789
|
+
const n = p.tree.length;
|
|
2301
2790
|
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.
|
|
2791
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
2792
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
2304
2793
|
r.parents.push(p);
|
|
2305
2794
|
}
|
|
2306
|
-
r.parents.sort((a, b) => b.
|
|
2795
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
2307
2796
|
}
|
|
2308
2797
|
return routes;
|
|
2309
2798
|
}
|
|
@@ -2321,8 +2810,19 @@ var rendersRe = (names) => {
|
|
|
2321
2810
|
const list = [...names];
|
|
2322
2811
|
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
2323
2812
|
};
|
|
2813
|
+
function routeReach(ctx, r, test2) {
|
|
2814
|
+
const trail = trailFor(ctx);
|
|
2815
|
+
let unknown = false;
|
|
2816
|
+
for (const f of r.files) {
|
|
2817
|
+
const got = trail.reach(f, test2);
|
|
2818
|
+
if (got === "yes") return "yes";
|
|
2819
|
+
if (got === "unknown") unknown = true;
|
|
2820
|
+
}
|
|
2821
|
+
return unknown ? "unknown" : "no";
|
|
2822
|
+
}
|
|
2823
|
+
var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
2324
2824
|
function insideShell(ctx, routes) {
|
|
2325
|
-
const shell = new Set(routes.filter((r) =>
|
|
2825
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
2326
2826
|
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
2327
2827
|
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
2328
2828
|
}
|
|
@@ -2333,20 +2833,19 @@ function checkHandRolledSubNav(ctx) {
|
|
|
2333
2833
|
const inShell = insideShell(ctx, routes);
|
|
2334
2834
|
const ui = ctx.genesis.uiPackage;
|
|
2335
2835
|
for (const r of routes) {
|
|
2336
|
-
if (!inShell(r)) continue;
|
|
2337
|
-
const
|
|
2338
|
-
if (
|
|
2339
|
-
|
|
2340
|
-
|
|
2836
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
2837
|
+
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);
|
|
2838
|
+
if (hit) {
|
|
2839
|
+
const { f, m } = hit;
|
|
2840
|
+
const code = f.code;
|
|
2341
2841
|
ctx.report({
|
|
2342
2842
|
rule: "hand-rolled-sub-nav",
|
|
2343
2843
|
level: "warn",
|
|
2344
|
-
file:
|
|
2844
|
+
file: f.path,
|
|
2345
2845
|
line: lineAt(code, m.index),
|
|
2346
2846
|
subject: m[1],
|
|
2347
2847
|
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
2848
|
});
|
|
2349
|
-
break;
|
|
2350
2849
|
}
|
|
2351
2850
|
}
|
|
2352
2851
|
}
|
|
@@ -2394,11 +2893,12 @@ function checkResourceWorkspaces(ctx) {
|
|
|
2394
2893
|
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
2395
2894
|
}
|
|
2396
2895
|
for (const [dir, routes] of byFolder) {
|
|
2397
|
-
const
|
|
2896
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
2897
|
+
const has = routes.filter((r) => reach.get(r) === "yes");
|
|
2398
2898
|
if (has.length === 0) continue;
|
|
2399
2899
|
const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
2400
2900
|
for (const r of routes) {
|
|
2401
|
-
if (
|
|
2901
|
+
if (reach.get(r) !== "no") continue;
|
|
2402
2902
|
ctx.report({
|
|
2403
2903
|
rule: "resource-workspace",
|
|
2404
2904
|
level: "info",
|
|
@@ -2422,14 +2922,14 @@ function checkPageLayouts(ctx) {
|
|
|
2422
2922
|
};
|
|
2423
2923
|
const cache = /* @__PURE__ */ new Map();
|
|
2424
2924
|
const provides = (r) => {
|
|
2425
|
-
if (!cache.has(r)) cache.set(r,
|
|
2925
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
2426
2926
|
return cache.get(r);
|
|
2427
2927
|
};
|
|
2428
2928
|
const list = [...layouts].sort();
|
|
2429
2929
|
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
2430
2930
|
for (const r of routes) {
|
|
2431
|
-
if (r.
|
|
2432
|
-
if (provides(r) || r.parents.some(provides)) continue;
|
|
2931
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
2932
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
2433
2933
|
ctx.report({
|
|
2434
2934
|
rule: "page-layout",
|
|
2435
2935
|
level: "warn",
|
|
@@ -2460,7 +2960,7 @@ function checkIsoDateSlices(ctx) {
|
|
|
2460
2960
|
|
|
2461
2961
|
// src/doctor/index.ts
|
|
2462
2962
|
async function runDoctor(options = {}) {
|
|
2463
|
-
const root =
|
|
2963
|
+
const root = path14.resolve(options.root ?? process.cwd());
|
|
2464
2964
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
2465
2965
|
const config = loaded.config;
|
|
2466
2966
|
const genesis = options.genesis ?? loadGenesis(root, config);
|