@marktiderman/genesis-cli 1.8.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 +53 -4
- package/dist/cli.js +1329 -322
- package/dist/cli.js.map +1 -1
- package/dist/{config-CrZbM3jD.d.ts → config-QC_Ewwwp.d.ts} +27 -3
- package/dist/doctor.d.ts +95 -4
- package/dist/doctor.js +1100 -147
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +52 -17
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1112 -161
- package/dist/index.js.map +1 -1
- package/dist/starter/__tests__/check-in-photos.test.ts +1 -1
- package/dist/starter/__tests__/components/messages.test.tsx +33 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +4 -38
- package/dist/starter/src/app/(app)/messages/[id].tsx +14 -5
- package/dist/starter/src/app/(app)/messages/check-in.tsx +9 -0
- package/dist/starter/src/app/(app)/messages/search.tsx +13 -1
- package/dist/starter/src/copy.ts +2 -0
- package/dist/starter/src/lib/chat.tsx +31 -8
- package/dist/starter/src/lib/check-in-screen.tsx +43 -0
- package/dist/starter/supabase/migrations/20261025000060_genesis_chat_search_threads.sql +85 -0
- package/dist/starter/supabase/tests/database/genesis_chat_coaching.test.sql +7 -3
- package/dist/starter/supabase/tests/database/genesis_chat_search_threads.test.sql +50 -0
- package/dist/vite.js +1101 -150
- package/dist/vite.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import { studioSetupSql } from '@marktiderman/genesis-studio-server';
|
|
3
|
-
import * as
|
|
3
|
+
import * as path14 from 'path';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
|
-
import { existsSync, readFileSync, statSync, readdirSync } from 'fs';
|
|
5
|
+
import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
|
|
6
6
|
import { pathToFileURL } from 'url';
|
|
7
7
|
|
|
8
8
|
// src/scaffolder.ts
|
|
@@ -101,9 +101,9 @@ async function runScaffold(opts, fs) {
|
|
|
101
101
|
function joinPath(...parts) {
|
|
102
102
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
103
103
|
}
|
|
104
|
-
function dirname(
|
|
105
|
-
const idx =
|
|
106
|
-
return idx === -1 ? "." :
|
|
104
|
+
function dirname(path17) {
|
|
105
|
+
const idx = path17.lastIndexOf("/");
|
|
106
|
+
return idx === -1 ? "." : path17.slice(0, idx);
|
|
107
107
|
}
|
|
108
108
|
function brandPackageJson(consumer, genesisVersion) {
|
|
109
109
|
return JSON.stringify(
|
|
@@ -343,12 +343,12 @@ function parse(comment, keys, where) {
|
|
|
343
343
|
throw new CommentSettingsError(`${where}: the text after ${MARKER} must be one JSON object.`);
|
|
344
344
|
}
|
|
345
345
|
const settings = {};
|
|
346
|
-
for (const [
|
|
347
|
-
if (!keys.includes(
|
|
348
|
-
throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${
|
|
346
|
+
for (const [key2, v] of Object.entries(value)) {
|
|
347
|
+
if (!keys.includes(key2)) {
|
|
348
|
+
throw new CommentSettingsError(`${where}: unknown ${MARKER} setting "${key2}". Allowed: ${keys.join(", ")}.`);
|
|
349
349
|
}
|
|
350
|
-
if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${
|
|
351
|
-
settings[
|
|
350
|
+
if (typeof v !== "string") throw new CommentSettingsError(`${where}: ${MARKER} "${key2}" must be a string.`);
|
|
351
|
+
settings[key2] = v;
|
|
352
352
|
}
|
|
353
353
|
return { ...description ? { description } : {}, ...Object.keys(settings).length ? { settings } : {} };
|
|
354
354
|
}
|
|
@@ -468,9 +468,9 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
468
468
|
const def = definitions[tableName];
|
|
469
469
|
const name = `${schema}.${tableName}`;
|
|
470
470
|
const required = new Set(def.required ?? []);
|
|
471
|
-
const
|
|
471
|
+
const key2 = [];
|
|
472
472
|
const columns = Object.entries(def.properties ?? {}).map(([column, prop]) => {
|
|
473
|
-
if (PK.test(prop.description ?? ""))
|
|
473
|
+
if (PK.test(prop.description ?? "")) key2.push(column);
|
|
474
474
|
const fk = FK.exec(prop.description ?? "");
|
|
475
475
|
const isArray = prop.type === "array";
|
|
476
476
|
const format = (isArray ? prop.items?.format : prop.format) ?? prop.type ?? "text";
|
|
@@ -497,7 +497,7 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
497
497
|
name,
|
|
498
498
|
schema,
|
|
499
499
|
table: tableName,
|
|
500
|
-
key,
|
|
500
|
+
key: key2,
|
|
501
501
|
columns,
|
|
502
502
|
...comment.description ? { description: comment.description } : {},
|
|
503
503
|
...comment.settings ? { settings: comment.settings } : {}
|
|
@@ -627,8 +627,8 @@ function routeTags(source) {
|
|
|
627
627
|
var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
|
|
628
628
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
629
629
|
const tags = routeTags(source);
|
|
630
|
-
const
|
|
631
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
630
|
+
const relative3 = route.replace(/^\//, "");
|
|
631
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative3.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
632
632
|
if (existing) {
|
|
633
633
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
634
634
|
}
|
|
@@ -636,17 +636,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
636
636
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
637
637
|
if (roots.length !== 1) {
|
|
638
638
|
return {
|
|
639
|
-
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${
|
|
639
|
+
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative3}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
640
640
|
};
|
|
641
641
|
}
|
|
642
642
|
const layout = roots[0];
|
|
643
643
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
644
|
-
if (base && !
|
|
644
|
+
if (base && !relative3.startsWith(`${base}/`)) {
|
|
645
645
|
return {
|
|
646
646
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
647
647
|
};
|
|
648
648
|
}
|
|
649
|
-
const childPath = base ?
|
|
649
|
+
const childPath = base ? relative3.slice(base.length + 1) : relative3;
|
|
650
650
|
const guard = GUARD.exec(source)?.[1];
|
|
651
651
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
652
652
|
const before = source.slice(0, layout.close);
|
|
@@ -960,19 +960,19 @@ ${line}
|
|
|
960
960
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
961
961
|
function buildCommands(root, config) {
|
|
962
962
|
if (config.build) return config.build;
|
|
963
|
-
const pkgFile =
|
|
963
|
+
const pkgFile = path14.join(root, "package.json");
|
|
964
964
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
965
965
|
const pm = packageManager(root);
|
|
966
966
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
967
967
|
}
|
|
968
968
|
function packageManager(root) {
|
|
969
|
-
let dir =
|
|
969
|
+
let dir = path14.resolve(root);
|
|
970
970
|
for (; ; ) {
|
|
971
|
-
if (existsSync(
|
|
972
|
-
if (existsSync(
|
|
973
|
-
if (existsSync(
|
|
974
|
-
if (existsSync(
|
|
975
|
-
const parent =
|
|
971
|
+
if (existsSync(path14.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
972
|
+
if (existsSync(path14.join(dir, "bun.lock")) || existsSync(path14.join(dir, "bun.lockb"))) return "bun";
|
|
973
|
+
if (existsSync(path14.join(dir, "yarn.lock"))) return "yarn";
|
|
974
|
+
if (existsSync(path14.join(dir, "package-lock.json"))) return "npm";
|
|
975
|
+
const parent = path14.dirname(dir);
|
|
976
976
|
if (parent === dir) return "npm";
|
|
977
977
|
dir = parent;
|
|
978
978
|
}
|
|
@@ -1051,7 +1051,7 @@ var PRIVACY_PURPOSES = {
|
|
|
1051
1051
|
"third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
|
|
1052
1052
|
other: "NSPrivacyCollectedDataTypePurposeOther"
|
|
1053
1053
|
};
|
|
1054
|
-
var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
1054
|
+
var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
|
|
1055
1055
|
var STRINGS = ["uiPackage", "rulesDoc"];
|
|
1056
1056
|
var KNOWN = /* @__PURE__ */ new Set([
|
|
1057
1057
|
...STRING_LISTS,
|
|
@@ -1066,10 +1066,11 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
1066
1066
|
"packs",
|
|
1067
1067
|
"native",
|
|
1068
1068
|
"supabase",
|
|
1069
|
+
"routesDir",
|
|
1069
1070
|
"$schema",
|
|
1070
1071
|
"$comment"
|
|
1071
1072
|
]);
|
|
1072
|
-
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
1073
|
+
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
|
|
1073
1074
|
var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
1074
1075
|
var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
1075
1076
|
var PACK_KEYS = {
|
|
@@ -1078,25 +1079,25 @@ var PACK_KEYS = {
|
|
|
1078
1079
|
};
|
|
1079
1080
|
function appPath(v, where, fail) {
|
|
1080
1081
|
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
1081
|
-
if (
|
|
1082
|
-
const norm =
|
|
1082
|
+
if (path14.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
1083
|
+
const norm = path14.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1083
1084
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
1084
1085
|
return norm;
|
|
1085
1086
|
}
|
|
1086
1087
|
function loadConfig(root, configPath) {
|
|
1087
1088
|
if (configPath) {
|
|
1088
|
-
const file =
|
|
1089
|
+
const file = path14.resolve(root, configPath);
|
|
1089
1090
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
1090
1091
|
const json = readJson(file);
|
|
1091
|
-
const block =
|
|
1092
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
1092
|
+
const block = path14.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
1093
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path14.dirname(file) };
|
|
1093
1094
|
}
|
|
1094
|
-
const own =
|
|
1095
|
+
const own = path14.join(root, "genesis.config.json");
|
|
1095
1096
|
if (existsSync(own)) {
|
|
1096
1097
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
1097
1098
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
1098
1099
|
}
|
|
1099
|
-
const pkg =
|
|
1100
|
+
const pkg = path14.join(root, "package.json");
|
|
1100
1101
|
if (existsSync(pkg)) {
|
|
1101
1102
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
1102
1103
|
if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -1111,7 +1112,7 @@ function readJson(file) {
|
|
|
1111
1112
|
}
|
|
1112
1113
|
}
|
|
1113
1114
|
function readGenesisConfig(root) {
|
|
1114
|
-
const file =
|
|
1115
|
+
const file = path14.join(root, "genesis.config.json");
|
|
1115
1116
|
if (!existsSync(file)) return null;
|
|
1116
1117
|
const raw = readJson(file);
|
|
1117
1118
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -1128,7 +1129,7 @@ function validatePrivacy(raw, source = "config") {
|
|
|
1128
1129
|
};
|
|
1129
1130
|
if (!isObject(raw)) fail(`"privacy" must be an object`);
|
|
1130
1131
|
const c = raw;
|
|
1131
|
-
for (const
|
|
1132
|
+
for (const key2 of Object.keys(c)) if (!PRIVACY_KEYS.has(key2)) fail(`privacy: unknown setting "${key2}"`);
|
|
1132
1133
|
const out = {};
|
|
1133
1134
|
if (c.blocks !== void 0) {
|
|
1134
1135
|
if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
|
|
@@ -1143,7 +1144,7 @@ function validatePrivacy(raw, source = "config") {
|
|
|
1143
1144
|
out.collects = c.collects.map((entry, i) => {
|
|
1144
1145
|
const where = `privacy.collects[${i}]`;
|
|
1145
1146
|
if (!isObject(entry)) return fail(`${where} must be an object`);
|
|
1146
|
-
for (const
|
|
1147
|
+
for (const key2 of Object.keys(entry)) if (!DATA_USE_KEYS.has(key2)) fail(`${where}: unknown setting "${key2}"`);
|
|
1147
1148
|
if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
|
|
1148
1149
|
fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
|
|
1149
1150
|
}
|
|
@@ -1166,7 +1167,7 @@ function validateLinks(raw, source = "config") {
|
|
|
1166
1167
|
};
|
|
1167
1168
|
if (!isObject(raw)) fail(`"links" must be an object`);
|
|
1168
1169
|
const c = raw;
|
|
1169
|
-
for (const
|
|
1170
|
+
for (const key2 of Object.keys(c)) if (!LINK_KEYS.has(key2)) fail(`links: unknown setting "${key2}"`);
|
|
1170
1171
|
if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
|
|
1171
1172
|
for (const host of c.hosts) {
|
|
1172
1173
|
if (!HOST.test(host)) {
|
|
@@ -1193,15 +1194,16 @@ function validateConfig(raw, source = "config") {
|
|
|
1193
1194
|
};
|
|
1194
1195
|
if (!isObject(raw)) fail("the doctor settings must be an object");
|
|
1195
1196
|
const c = raw;
|
|
1196
|
-
for (const
|
|
1197
|
+
for (const key2 of Object.keys(c)) if (!KNOWN.has(key2)) fail(`unknown setting "${key2}"`);
|
|
1197
1198
|
if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
|
|
1198
1199
|
if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
|
|
1199
|
-
for (const
|
|
1200
|
-
if (c[
|
|
1200
|
+
for (const key2 of STRING_LISTS) {
|
|
1201
|
+
if (c[key2] !== void 0 && !isStringList(c[key2])) fail(`"${key2}" must be a list of strings`);
|
|
1201
1202
|
}
|
|
1202
|
-
for (const
|
|
1203
|
-
if (c[
|
|
1203
|
+
for (const key2 of STRINGS) {
|
|
1204
|
+
if (c[key2] !== void 0 && typeof c[key2] !== "string") fail(`"${key2}" must be a string`);
|
|
1204
1205
|
}
|
|
1206
|
+
if (c.routesDir !== void 0) c.routesDir = appPath(c.routesDir, `"routesDir"`, fail);
|
|
1205
1207
|
if (c.rawTags !== void 0) {
|
|
1206
1208
|
if (!isObject(c.rawTags)) fail(`"rawTags" must be an object`);
|
|
1207
1209
|
for (const [tag, v] of Object.entries(c.rawTags)) {
|
|
@@ -1219,7 +1221,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1219
1221
|
if (c.rules !== void 0) {
|
|
1220
1222
|
if (!isObject(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
|
|
1221
1223
|
for (const [rule, level] of Object.entries(c.rules)) {
|
|
1222
|
-
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
|
|
1224
|
+
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn", "info" or "off"`);
|
|
1223
1225
|
}
|
|
1224
1226
|
}
|
|
1225
1227
|
if (c.allow !== void 0) {
|
|
@@ -1312,11 +1314,12 @@ function globToRegExp(glob) {
|
|
|
1312
1314
|
}
|
|
1313
1315
|
function globMatcher(globs) {
|
|
1314
1316
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1315
|
-
return (
|
|
1317
|
+
return (path17) => res.some((re) => re.test(path17));
|
|
1316
1318
|
}
|
|
1317
1319
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1318
1320
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
1319
1321
|
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
1322
|
+
var DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
|
|
1320
1323
|
var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
1321
1324
|
var TAG_ALIASES = { hr: "Separator" };
|
|
1322
1325
|
var NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
@@ -1351,11 +1354,11 @@ var TAILWIND_PALETTE = [
|
|
|
1351
1354
|
"olive"
|
|
1352
1355
|
];
|
|
1353
1356
|
function findPackageDir(from, name) {
|
|
1354
|
-
let dir =
|
|
1357
|
+
let dir = path14.resolve(from);
|
|
1355
1358
|
for (; ; ) {
|
|
1356
|
-
const candidate =
|
|
1357
|
-
if (existsSync(
|
|
1358
|
-
const parent =
|
|
1359
|
+
const candidate = path14.join(dir, "node_modules", name);
|
|
1360
|
+
if (existsSync(path14.join(candidate, "package.json"))) return candidate;
|
|
1361
|
+
const parent = path14.dirname(dir);
|
|
1359
1362
|
if (parent === dir) return null;
|
|
1360
1363
|
dir = parent;
|
|
1361
1364
|
}
|
|
@@ -1387,13 +1390,27 @@ function loadGenesis(root, config) {
|
|
|
1387
1390
|
components,
|
|
1388
1391
|
tokens,
|
|
1389
1392
|
rawTags,
|
|
1390
|
-
palette: loadPalette(root)
|
|
1393
|
+
palette: loadPalette(root),
|
|
1394
|
+
companions: loadCompanions(root, config, uiPackage)
|
|
1391
1395
|
};
|
|
1392
1396
|
}
|
|
1397
|
+
function loadCompanions(root, config, uiPackage) {
|
|
1398
|
+
const out = [];
|
|
1399
|
+
for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
|
|
1400
|
+
if (name === uiPackage) continue;
|
|
1401
|
+
try {
|
|
1402
|
+
const pkg = readPackageExports(root, name);
|
|
1403
|
+
if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
|
|
1404
|
+
} catch (err) {
|
|
1405
|
+
if (!(err instanceof DoctorConfigError)) throw err;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
return out;
|
|
1409
|
+
}
|
|
1393
1410
|
function readPackageExports(root, uiPackage) {
|
|
1394
1411
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1395
1412
|
if (!uiDir) return null;
|
|
1396
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1413
|
+
const uiPkg = JSON.parse(readFileSync(path14.join(uiDir, "package.json"), "utf8"));
|
|
1397
1414
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
1398
1415
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1399
1416
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
@@ -1405,7 +1422,7 @@ function readPackageExports(root, uiPackage) {
|
|
|
1405
1422
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1406
1423
|
let readAny = false;
|
|
1407
1424
|
for (const entry of typeEntries) {
|
|
1408
|
-
const file =
|
|
1425
|
+
const file = path14.join(uiDir, entry);
|
|
1409
1426
|
if (!existsSync(file)) continue;
|
|
1410
1427
|
readAny = true;
|
|
1411
1428
|
const dts = readFileSync(file, "utf8");
|
|
@@ -1419,11 +1436,11 @@ function readPackageExports(root, uiPackage) {
|
|
|
1419
1436
|
}
|
|
1420
1437
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1421
1438
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1422
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1439
|
+
const declRoot = typeof mainTypes === "string" ? path14.dirname(path14.join(uiDir, mainTypes)) : uiDir;
|
|
1423
1440
|
const declFiles = walkDts(declRoot);
|
|
1424
1441
|
for (const pkg of reexportedPackages) {
|
|
1425
1442
|
const dir = findPackageDir(uiDir, pkg);
|
|
1426
|
-
if (dir) walkDts(
|
|
1443
|
+
if (dir) walkDts(path14.join(dir, "dist"), declFiles);
|
|
1427
1444
|
}
|
|
1428
1445
|
for (const file of declFiles) {
|
|
1429
1446
|
const text = readFileSync(file, "utf8");
|
|
@@ -1459,8 +1476,8 @@ function exportTypes(target) {
|
|
|
1459
1476
|
if (!target || typeof target !== "object") return void 0;
|
|
1460
1477
|
const t = target;
|
|
1461
1478
|
if (typeof t.types === "string") return t.types;
|
|
1462
|
-
for (const
|
|
1463
|
-
const nested = exportTypes(t[
|
|
1479
|
+
for (const key2 of ["import", "default", "require"]) {
|
|
1480
|
+
const nested = exportTypes(t[key2]);
|
|
1464
1481
|
if (nested) return nested;
|
|
1465
1482
|
}
|
|
1466
1483
|
return void 0;
|
|
@@ -1469,7 +1486,7 @@ function walkDts(dir, out = []) {
|
|
|
1469
1486
|
if (!existsSync(dir)) return out;
|
|
1470
1487
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1471
1488
|
if (entry.name === "node_modules") continue;
|
|
1472
|
-
const p =
|
|
1489
|
+
const p = path14.join(dir, entry.name);
|
|
1473
1490
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1474
1491
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1475
1492
|
}
|
|
@@ -1486,27 +1503,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1486
1503
|
}
|
|
1487
1504
|
const files = [];
|
|
1488
1505
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1489
|
-
const themes = ds &&
|
|
1506
|
+
const themes = ds && path14.join(ds, "dist", "themes");
|
|
1490
1507
|
if (themes && existsSync(themes)) {
|
|
1491
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1508
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path14.join(themes, name));
|
|
1492
1509
|
}
|
|
1493
1510
|
if (files.length === 0) {
|
|
1494
1511
|
throw new DoctorConfigError(
|
|
1495
1512
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1496
1513
|
);
|
|
1497
1514
|
}
|
|
1498
|
-
const uiStyles =
|
|
1515
|
+
const uiStyles = path14.join(uiDir, "dist", "styles.css");
|
|
1499
1516
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1500
1517
|
return files;
|
|
1501
1518
|
}
|
|
1502
1519
|
function resolveSpec(root, spec) {
|
|
1503
|
-
const local =
|
|
1504
|
-
if (spec.startsWith(".") ||
|
|
1520
|
+
const local = path14.resolve(root, spec);
|
|
1521
|
+
if (spec.startsWith(".") || path14.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1505
1522
|
const parts = spec.split("/");
|
|
1506
1523
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1507
1524
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1508
1525
|
if (dir) {
|
|
1509
|
-
const file =
|
|
1526
|
+
const file = path14.join(dir, ...parts.slice(nameLength));
|
|
1510
1527
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1511
1528
|
}
|
|
1512
1529
|
return existsSync(local) ? local : null;
|
|
@@ -1514,10 +1531,10 @@ function resolveSpec(root, spec) {
|
|
|
1514
1531
|
function loadPalette(root) {
|
|
1515
1532
|
const names = new Set(TAILWIND_PALETTE);
|
|
1516
1533
|
try {
|
|
1517
|
-
const req = createRequire(
|
|
1534
|
+
const req = createRequire(path14.join(root, "package.json"));
|
|
1518
1535
|
const colors = req("tailwindcss/colors");
|
|
1519
|
-
for (const
|
|
1520
|
-
if (/^[a-z]+$/.test(
|
|
1536
|
+
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1537
|
+
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
1521
1538
|
}
|
|
1522
1539
|
} catch {
|
|
1523
1540
|
}
|
|
@@ -1699,16 +1716,16 @@ var DEFAULT_IGNORE = [
|
|
|
1699
1716
|
];
|
|
1700
1717
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1701
1718
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1702
|
-
var toPosix = (p) => p.split(
|
|
1719
|
+
var toPosix = (p) => p.split(path14.sep).join("/");
|
|
1703
1720
|
function scanFiles(root, config) {
|
|
1704
1721
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
1705
1722
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
1706
1723
|
const files = [];
|
|
1707
1724
|
const seen = /* @__PURE__ */ new Set();
|
|
1708
1725
|
const visit = (abs) => {
|
|
1709
|
-
const rel = toPosix(
|
|
1726
|
+
const rel = toPosix(path14.relative(root, abs));
|
|
1710
1727
|
if (seen.has(rel) || ignored(rel)) return;
|
|
1711
|
-
const ext =
|
|
1728
|
+
const ext = path14.extname(abs);
|
|
1712
1729
|
if (!extensions.has(ext)) return;
|
|
1713
1730
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1714
1731
|
seen.add(rel);
|
|
@@ -1718,14 +1735,14 @@ function scanFiles(root, config) {
|
|
|
1718
1735
|
const walk = (dir) => {
|
|
1719
1736
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1720
1737
|
if (entry.isDirectory()) {
|
|
1721
|
-
if (!SKIP_DIRS.has(entry.name)) walk(
|
|
1738
|
+
if (!SKIP_DIRS.has(entry.name)) walk(path14.join(dir, entry.name));
|
|
1722
1739
|
} else if (entry.isFile()) {
|
|
1723
|
-
visit(
|
|
1740
|
+
visit(path14.join(dir, entry.name));
|
|
1724
1741
|
}
|
|
1725
1742
|
}
|
|
1726
1743
|
};
|
|
1727
1744
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1728
|
-
const abs =
|
|
1745
|
+
const abs = path14.resolve(root, src);
|
|
1729
1746
|
if (!existsSync(abs)) continue;
|
|
1730
1747
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
1731
1748
|
else visit(abs);
|
|
@@ -1755,11 +1772,11 @@ function parseRulesMarkdown(markdown) {
|
|
|
1755
1772
|
}
|
|
1756
1773
|
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message):\s*(.*)$/);
|
|
1757
1774
|
if (!current || !kv) continue;
|
|
1758
|
-
const [,
|
|
1775
|
+
const [, key2, raw] = kv;
|
|
1759
1776
|
const value = raw.trim();
|
|
1760
|
-
if (
|
|
1761
|
-
else if (
|
|
1762
|
-
else current[
|
|
1777
|
+
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1778
|
+
else if (key2 === "level") current.level = value;
|
|
1779
|
+
else current[key2] = value;
|
|
1763
1780
|
}
|
|
1764
1781
|
return rules;
|
|
1765
1782
|
}
|
|
@@ -1774,8 +1791,8 @@ function compilePatternRules(rules, source) {
|
|
|
1774
1791
|
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
1775
1792
|
ids.add(rule.id);
|
|
1776
1793
|
const level = rule.level ?? "error";
|
|
1777
|
-
if (!["error", "warn", "guide"].includes(level)) {
|
|
1778
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn or guide)`);
|
|
1794
|
+
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
1795
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
1779
1796
|
}
|
|
1780
1797
|
if (level === "guide") continue;
|
|
1781
1798
|
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
@@ -1802,7 +1819,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
1802
1819
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
1803
1820
|
let all = compiled;
|
|
1804
1821
|
if (rulesDoc) {
|
|
1805
|
-
const file =
|
|
1822
|
+
const file = path14.resolve(root, rulesDoc);
|
|
1806
1823
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
1807
1824
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
1808
1825
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -1861,14 +1878,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
1861
1878
|
}
|
|
1862
1879
|
function resolvePlugin(id, configDir) {
|
|
1863
1880
|
try {
|
|
1864
|
-
if (id.startsWith(".") ||
|
|
1881
|
+
if (id.startsWith(".") || path14.isAbsolute(id)) return resolveFrom(path14.resolve(configDir, id), configDir);
|
|
1865
1882
|
return resolveFrom(id, configDir);
|
|
1866
1883
|
} catch {
|
|
1867
1884
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
1868
1885
|
}
|
|
1869
1886
|
}
|
|
1870
1887
|
function resolveFrom(id, from) {
|
|
1871
|
-
return createRequire(
|
|
1888
|
+
return createRequire(path14.join(from, "noop.js")).resolve(id);
|
|
1872
1889
|
}
|
|
1873
1890
|
var BUILTIN_RULES = [
|
|
1874
1891
|
"local-primitives",
|
|
@@ -1881,6 +1898,15 @@ var BUILTIN_RULES = [
|
|
|
1881
1898
|
"undefined-token",
|
|
1882
1899
|
"shadowed-export",
|
|
1883
1900
|
"version-skew",
|
|
1901
|
+
"duplicate-genesis-package",
|
|
1902
|
+
"peer-range-mismatch",
|
|
1903
|
+
// structure
|
|
1904
|
+
"hand-rolled-sub-nav",
|
|
1905
|
+
"local-genesis-copy",
|
|
1906
|
+
"resource-workspace",
|
|
1907
|
+
"page-layout",
|
|
1908
|
+
// dates
|
|
1909
|
+
"iso-date-slice",
|
|
1884
1910
|
// native pack
|
|
1885
1911
|
"native-raw-primitive",
|
|
1886
1912
|
"native-literal-color",
|
|
@@ -1891,7 +1917,8 @@ var BUILTIN_RULES = [
|
|
|
1891
1917
|
"migration-grants",
|
|
1892
1918
|
"migration-rls",
|
|
1893
1919
|
"migration-definer-search-path",
|
|
1894
|
-
"migration-edited"
|
|
1920
|
+
"migration-edited",
|
|
1921
|
+
"migration-testing-kit"
|
|
1895
1922
|
];
|
|
1896
1923
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
1897
1924
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -1909,7 +1936,7 @@ function importSpecifiers(file) {
|
|
|
1909
1936
|
}
|
|
1910
1937
|
function checkProjectLayout(ctx) {
|
|
1911
1938
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
1912
|
-
if (existsSync(
|
|
1939
|
+
if (existsSync(path14.join(ctx.root, dir))) {
|
|
1913
1940
|
ctx.report({
|
|
1914
1941
|
rule: "local-primitives",
|
|
1915
1942
|
file: dir,
|
|
@@ -1919,7 +1946,7 @@ function checkProjectLayout(ctx) {
|
|
|
1919
1946
|
}
|
|
1920
1947
|
}
|
|
1921
1948
|
for (const file of STARTER_LEFTOVERS) {
|
|
1922
|
-
if (existsSync(
|
|
1949
|
+
if (existsSync(path14.join(ctx.root, file))) {
|
|
1923
1950
|
ctx.report({
|
|
1924
1951
|
rule: "starter-leftover",
|
|
1925
1952
|
level: "warn",
|
|
@@ -2008,7 +2035,7 @@ function checkTokens(ctx) {
|
|
|
2008
2035
|
}
|
|
2009
2036
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2010
2037
|
if (/[*?]/.test(pattern)) continue;
|
|
2011
|
-
const abs =
|
|
2038
|
+
const abs = path14.join(ctx.root, pattern);
|
|
2012
2039
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2013
2040
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2014
2041
|
}
|
|
@@ -2107,11 +2134,97 @@ var appFunctionality = (type, ...more) => ({
|
|
|
2107
2134
|
function privacyApisFor(dependencies2) {
|
|
2108
2135
|
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
2109
2136
|
}
|
|
2110
|
-
|
|
2111
|
-
// src/doctor/native.ts
|
|
2112
2137
|
var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
2113
2138
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2114
2139
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2140
|
+
function localImports(root, file) {
|
|
2141
|
+
const out = [];
|
|
2142
|
+
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
2143
|
+
const spec = m[1];
|
|
2144
|
+
const bases = spec.startsWith(".") ? [path14.resolve(path14.dirname(file.absolutePath), spec)] : [path14.join(root, spec.slice(2)), path14.join(root, "src", spec.slice(2))];
|
|
2145
|
+
for (const base of bases) {
|
|
2146
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
|
|
2147
|
+
(p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
|
|
2148
|
+
);
|
|
2149
|
+
if (hit) {
|
|
2150
|
+
out.push(hit);
|
|
2151
|
+
break;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
return out;
|
|
2156
|
+
}
|
|
2157
|
+
function readSource(abs) {
|
|
2158
|
+
try {
|
|
2159
|
+
return { absolutePath: abs, code: readFileSync(abs, "utf8") };
|
|
2160
|
+
} catch {
|
|
2161
|
+
return null;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
function tagEnd(code, start) {
|
|
2165
|
+
let depth = 0;
|
|
2166
|
+
let quote2 = null;
|
|
2167
|
+
for (let i = start + 1; i < code.length; i++) {
|
|
2168
|
+
const ch = code[i];
|
|
2169
|
+
if (quote2) {
|
|
2170
|
+
if (ch === "\\") i++;
|
|
2171
|
+
else if (ch === quote2) quote2 = null;
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
if (ch === '"' || ch === "'" || ch === "`") quote2 = ch;
|
|
2175
|
+
else if (ch === "{") depth++;
|
|
2176
|
+
else if (ch === "}") depth--;
|
|
2177
|
+
else if (ch === ">" && depth === 0) {
|
|
2178
|
+
let j = i - 1;
|
|
2179
|
+
while (j > start && /\s/.test(code[j])) j--;
|
|
2180
|
+
return { end: i + 1, selfClosing: code[j] === "/" };
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
return { end: code.length, selfClosing: false };
|
|
2184
|
+
}
|
|
2185
|
+
function openElementsAt(code, index, track) {
|
|
2186
|
+
const open = [];
|
|
2187
|
+
const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
|
|
2188
|
+
for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
|
|
2189
|
+
const name = m[2];
|
|
2190
|
+
if (!track(name)) continue;
|
|
2191
|
+
if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
|
|
2192
|
+
if (m[1]) {
|
|
2193
|
+
const at = open.lastIndexOf(name);
|
|
2194
|
+
if (at !== -1) open.splice(at, 1);
|
|
2195
|
+
continue;
|
|
2196
|
+
}
|
|
2197
|
+
const { end, selfClosing } = tagEnd(code, m.index);
|
|
2198
|
+
if (end > index) break;
|
|
2199
|
+
if (!selfClosing) open.push(name);
|
|
2200
|
+
}
|
|
2201
|
+
return open;
|
|
2202
|
+
}
|
|
2203
|
+
function renderedElements(code) {
|
|
2204
|
+
const out = [];
|
|
2205
|
+
for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
|
|
2206
|
+
return out;
|
|
2207
|
+
}
|
|
2208
|
+
function rendersJsx(code) {
|
|
2209
|
+
return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
|
|
2210
|
+
}
|
|
2211
|
+
function namedImportsFrom(code, pkg) {
|
|
2212
|
+
const out = [];
|
|
2213
|
+
for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
2214
|
+
if (!pkg.test(m[2])) continue;
|
|
2215
|
+
for (const part of m[1].split(",")) {
|
|
2216
|
+
const p = part.trim();
|
|
2217
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2218
|
+
const local = p.split(/\s+as\s+/).pop()?.trim();
|
|
2219
|
+
if (local) out.push(local);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
return out;
|
|
2223
|
+
}
|
|
2224
|
+
|
|
2225
|
+
// src/doctor/native.ts
|
|
2226
|
+
var SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
2227
|
+
var JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2115
2228
|
var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
|
|
2116
2229
|
var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
|
|
2117
2230
|
var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
|
|
@@ -2146,7 +2259,7 @@ function checkRawPrimitives(ctx, pkg) {
|
|
|
2146
2259
|
];
|
|
2147
2260
|
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
2148
2261
|
for (const file of ctx.files) {
|
|
2149
|
-
if (!
|
|
2262
|
+
if (!SCRIPT_EXTS3.has(file.ext)) continue;
|
|
2150
2263
|
const code = file.code;
|
|
2151
2264
|
const report = (name, at) => {
|
|
2152
2265
|
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
@@ -2192,10 +2305,10 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2192
2305
|
const reported = /* @__PURE__ */ new Set();
|
|
2193
2306
|
const hidingLayouts = /* @__PURE__ */ new Map();
|
|
2194
2307
|
for (const file of ctx.files) {
|
|
2195
|
-
if (!
|
|
2308
|
+
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2196
2309
|
const code = file.code;
|
|
2197
2310
|
const hidden = HIDES_HEADER.exec(code);
|
|
2198
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2311
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
|
|
2199
2312
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2200
2313
|
if (hidden && own) {
|
|
2201
2314
|
reported.add(file.path);
|
|
@@ -2222,8 +2335,8 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2222
2335
|
}
|
|
2223
2336
|
}
|
|
2224
2337
|
for (const file of ctx.files) {
|
|
2225
|
-
if (!
|
|
2226
|
-
const layout = hidingLayouts.get(
|
|
2338
|
+
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2339
|
+
const layout = hidingLayouts.get(path14.posix.dirname(file.path));
|
|
2227
2340
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2228
2341
|
if (!layout || !own) continue;
|
|
2229
2342
|
ctx.report({
|
|
@@ -2238,13 +2351,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2238
2351
|
}
|
|
2239
2352
|
function routerRoot(ctx) {
|
|
2240
2353
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2241
|
-
return existsSync(
|
|
2354
|
+
return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2242
2355
|
}
|
|
2243
2356
|
function checkScreenLayouts(ctx, pkg) {
|
|
2244
2357
|
const layouts = nativeLayouts(pkg);
|
|
2245
2358
|
if (layouts.length === 0) return;
|
|
2246
2359
|
const rootDir = routerRoot(ctx);
|
|
2247
|
-
if (!existsSync(
|
|
2360
|
+
if (!existsSync(path14.join(ctx.root, rootDir))) {
|
|
2248
2361
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2249
2362
|
return;
|
|
2250
2363
|
}
|
|
@@ -2258,15 +2371,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2258
2371
|
});
|
|
2259
2372
|
return;
|
|
2260
2373
|
}
|
|
2261
|
-
const
|
|
2374
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
2262
2375
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2263
2376
|
for (const file of routes) {
|
|
2264
|
-
if (!
|
|
2377
|
+
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2265
2378
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
2266
|
-
if (
|
|
2379
|
+
if (renders2.test(file.code)) continue;
|
|
2267
2380
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
2268
2381
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
2269
|
-
return target !== null &&
|
|
2382
|
+
return target !== null && renders2.test(target.code);
|
|
2270
2383
|
});
|
|
2271
2384
|
if (viaImport) continue;
|
|
2272
2385
|
ctx.report({
|
|
@@ -2277,30 +2390,6 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
2277
2390
|
});
|
|
2278
2391
|
}
|
|
2279
2392
|
}
|
|
2280
|
-
function localImports(root, file) {
|
|
2281
|
-
const out = [];
|
|
2282
|
-
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
2283
|
-
const spec = m[1];
|
|
2284
|
-
const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
|
|
2285
|
-
for (const base of bases) {
|
|
2286
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
|
|
2287
|
-
(p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
|
|
2288
|
-
);
|
|
2289
|
-
if (hit) {
|
|
2290
|
-
out.push(hit);
|
|
2291
|
-
break;
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
return out;
|
|
2296
|
-
}
|
|
2297
|
-
function readSource(abs) {
|
|
2298
|
-
try {
|
|
2299
|
-
return { code: readFileSync(abs, "utf8") };
|
|
2300
|
-
} catch {
|
|
2301
|
-
return null;
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
2393
|
var PERMISSIONS = [
|
|
2305
2394
|
{ module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
|
|
2306
2395
|
{ module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
|
|
@@ -2323,7 +2412,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
2323
2412
|
function readExpoConfigs(root) {
|
|
2324
2413
|
const out = [];
|
|
2325
2414
|
for (const name of EXPO_CONFIGS) {
|
|
2326
|
-
const abs =
|
|
2415
|
+
const abs = path14.join(root, name);
|
|
2327
2416
|
if (!existsSync(abs)) continue;
|
|
2328
2417
|
const text = readFileSync(abs, "utf8");
|
|
2329
2418
|
let json = null;
|
|
@@ -2357,13 +2446,13 @@ function pluginOptions(json, module) {
|
|
|
2357
2446
|
return null;
|
|
2358
2447
|
}
|
|
2359
2448
|
function dependencies(root) {
|
|
2360
|
-
const file =
|
|
2449
|
+
const file = path14.join(root, "package.json");
|
|
2361
2450
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2362
2451
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2363
2452
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2364
2453
|
}
|
|
2365
2454
|
function runtimeDependencies(root) {
|
|
2366
|
-
const file =
|
|
2455
|
+
const file = path14.join(root, "package.json");
|
|
2367
2456
|
if (!existsSync(file)) return {};
|
|
2368
2457
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2369
2458
|
}
|
|
@@ -2423,14 +2512,14 @@ function checkStoreReadiness(ctx) {
|
|
|
2423
2512
|
});
|
|
2424
2513
|
if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
|
|
2425
2514
|
}
|
|
2426
|
-
for (const [
|
|
2427
|
-
const opt = PERMISSIONS.find((p) => p.key ===
|
|
2515
|
+
for (const [key2, modules] of generic) {
|
|
2516
|
+
const opt = PERMISSIONS.find((p) => p.key === key2).option;
|
|
2428
2517
|
ctx.report({
|
|
2429
2518
|
rule: "store-readiness",
|
|
2430
2519
|
level: "warn",
|
|
2431
2520
|
file,
|
|
2432
|
-
subject:
|
|
2433
|
-
message: `leaves ${
|
|
2521
|
+
subject: key2,
|
|
2522
|
+
message: `leaves ${key2} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key2}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
|
|
2434
2523
|
});
|
|
2435
2524
|
}
|
|
2436
2525
|
const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
|
|
@@ -2626,9 +2715,9 @@ function gitView(root, dir, base) {
|
|
|
2626
2715
|
function checkSupabasePack(ctx) {
|
|
2627
2716
|
const settings = ctx.config.supabase ?? {};
|
|
2628
2717
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
2629
|
-
const abs =
|
|
2718
|
+
const abs = path14.join(ctx.root, dir);
|
|
2630
2719
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
2631
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
2720
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
2632
2721
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
2633
2722
|
const base = settings.base ?? DEFAULT_BASE;
|
|
2634
2723
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -2645,7 +2734,7 @@ function checkSupabasePack(ctx) {
|
|
|
2645
2734
|
}
|
|
2646
2735
|
}
|
|
2647
2736
|
const since = settings.since;
|
|
2648
|
-
const afterSince = (file) => since === void 0 ||
|
|
2737
|
+
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
2649
2738
|
if ("reason" in view && since === void 0) {
|
|
2650
2739
|
ctx.report({
|
|
2651
2740
|
rule: "migration-grants",
|
|
@@ -2659,6 +2748,20 @@ function checkSupabasePack(ctx) {
|
|
|
2659
2748
|
}
|
|
2660
2749
|
checkRls(ctx, migrations, exposed);
|
|
2661
2750
|
checkDefinerSearchPath(ctx, migrations);
|
|
2751
|
+
checkTestingKit(ctx, migrations);
|
|
2752
|
+
}
|
|
2753
|
+
function checkTestingKit(ctx, migrations) {
|
|
2754
|
+
for (const { file, statements } of migrations) {
|
|
2755
|
+
const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
|
|
2756
|
+
if (!hit) continue;
|
|
2757
|
+
ctx.report({
|
|
2758
|
+
rule: "migration-testing-kit",
|
|
2759
|
+
file,
|
|
2760
|
+
line: hit.line,
|
|
2761
|
+
subject: "genesis_testing",
|
|
2762
|
+
message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
|
|
2763
|
+
});
|
|
2764
|
+
}
|
|
2662
2765
|
}
|
|
2663
2766
|
function granteesOf(s) {
|
|
2664
2767
|
return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
|
|
@@ -2787,8 +2890,8 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
2787
2890
|
for (const { sql, line } of statements) {
|
|
2788
2891
|
const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
|
|
2789
2892
|
if (create) {
|
|
2790
|
-
const [
|
|
2791
|
-
fns.set(
|
|
2893
|
+
const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
|
|
2894
|
+
fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
|
|
2792
2895
|
continue;
|
|
2793
2896
|
}
|
|
2794
2897
|
const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
|
|
@@ -2797,13 +2900,13 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
2797
2900
|
const keys = keysFor(sql, alter[0].length, fnName);
|
|
2798
2901
|
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
2799
2902
|
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
2800
|
-
for (const
|
|
2801
|
-
const state = fns.get(
|
|
2903
|
+
for (const key2 of keys) {
|
|
2904
|
+
const state = fns.get(key2);
|
|
2802
2905
|
if (rename || move) {
|
|
2803
2906
|
if (!state) continue;
|
|
2804
|
-
fns.delete(
|
|
2907
|
+
fns.delete(key2);
|
|
2805
2908
|
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
2806
|
-
fns.set(newName +
|
|
2909
|
+
fns.set(newName + key2.slice(fnName.length), state);
|
|
2807
2910
|
continue;
|
|
2808
2911
|
}
|
|
2809
2912
|
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
@@ -2811,7 +2914,7 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
2811
2914
|
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
2812
2915
|
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
2813
2916
|
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
2814
|
-
fns.set(
|
|
2917
|
+
fns.set(key2, next);
|
|
2815
2918
|
}
|
|
2816
2919
|
continue;
|
|
2817
2920
|
}
|
|
@@ -2819,26 +2922,26 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
2819
2922
|
if (drop) {
|
|
2820
2923
|
for (const part of splitTop(drop[1])) {
|
|
2821
2924
|
const m = /^([\w$.]+)\s*/.exec(part);
|
|
2822
|
-
if (m) for (const
|
|
2925
|
+
if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
|
|
2823
2926
|
}
|
|
2824
2927
|
}
|
|
2825
2928
|
}
|
|
2826
2929
|
}
|
|
2827
|
-
for (const [
|
|
2930
|
+
for (const [key2, at] of fns) {
|
|
2828
2931
|
if (!at.definer || at.searchPath) continue;
|
|
2829
2932
|
ctx.report({
|
|
2830
2933
|
rule: "migration-definer-search-path",
|
|
2831
2934
|
file: at.file,
|
|
2832
2935
|
line: at.line,
|
|
2833
|
-
subject:
|
|
2834
|
-
message: `${
|
|
2936
|
+
subject: key2,
|
|
2937
|
+
message: `${key2} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
|
|
2835
2938
|
});
|
|
2836
2939
|
}
|
|
2837
2940
|
}
|
|
2838
2941
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2839
2942
|
function readReleaseManifest(root) {
|
|
2840
2943
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2841
|
-
const file = dir &&
|
|
2944
|
+
const file = dir && path14.join(dir, "dist", "versions.json");
|
|
2842
2945
|
if (!file || !existsSync(file)) return null;
|
|
2843
2946
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
2844
2947
|
}
|
|
@@ -2848,7 +2951,7 @@ function checkVersionSkew(ctx) {
|
|
|
2848
2951
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2849
2952
|
const dir = findPackageDir(ctx.root, name);
|
|
2850
2953
|
if (!dir) continue;
|
|
2851
|
-
const have = JSON.parse(readFileSync(
|
|
2954
|
+
const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
|
|
2852
2955
|
if (have === want) continue;
|
|
2853
2956
|
ctx.report({
|
|
2854
2957
|
rule: "version-skew",
|
|
@@ -2860,9 +2963,842 @@ function checkVersionSkew(ctx) {
|
|
|
2860
2963
|
}
|
|
2861
2964
|
}
|
|
2862
2965
|
|
|
2966
|
+
// src/doctor/semver.ts
|
|
2967
|
+
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2968
|
+
function parseVersion(v) {
|
|
2969
|
+
const m = VERSION.exec(v.trim());
|
|
2970
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2971
|
+
}
|
|
2972
|
+
function compareVersions(a, b) {
|
|
2973
|
+
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
2974
|
+
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
2975
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
2976
|
+
const x = a.pre[i];
|
|
2977
|
+
const y = b.pre[i];
|
|
2978
|
+
if (x === void 0) return -1;
|
|
2979
|
+
if (y === void 0) return 1;
|
|
2980
|
+
if (x === y) continue;
|
|
2981
|
+
const nx = /^\d+$/.test(x);
|
|
2982
|
+
const ny = /^\d+$/.test(y);
|
|
2983
|
+
if (nx && ny) return +x < +y ? -1 : 1;
|
|
2984
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
2985
|
+
return x < y ? -1 : 1;
|
|
2986
|
+
}
|
|
2987
|
+
return 0;
|
|
2988
|
+
}
|
|
2989
|
+
function partial(s) {
|
|
2990
|
+
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
2991
|
+
if (!m) return null;
|
|
2992
|
+
const nums = [];
|
|
2993
|
+
let wild = false;
|
|
2994
|
+
for (const part of [m[1], m[2], m[3]]) {
|
|
2995
|
+
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
2996
|
+
wild = true;
|
|
2997
|
+
nums.push(null);
|
|
2998
|
+
} else nums.push(+part);
|
|
2999
|
+
}
|
|
3000
|
+
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
3001
|
+
}
|
|
3002
|
+
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
3003
|
+
function comparators(token) {
|
|
3004
|
+
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
3005
|
+
if (!m) return null;
|
|
3006
|
+
const op = m[1] ?? "";
|
|
3007
|
+
const p = partial(m[2]);
|
|
3008
|
+
if (!p) return null;
|
|
3009
|
+
const [major, mi, pa] = p.nums;
|
|
3010
|
+
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
3011
|
+
const M = major;
|
|
3012
|
+
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
3013
|
+
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
3014
|
+
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
3015
|
+
const out = switchOp();
|
|
3016
|
+
if (p.pre.length) {
|
|
3017
|
+
for (const c of out) if (c.v === lo) c.pre = true;
|
|
3018
|
+
}
|
|
3019
|
+
return out;
|
|
3020
|
+
function switchOp() {
|
|
3021
|
+
switch (op) {
|
|
3022
|
+
case "^": {
|
|
3023
|
+
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
3024
|
+
return [
|
|
3025
|
+
{ op: ">=", v: lo },
|
|
3026
|
+
{ op: "<", v: bound }
|
|
3027
|
+
];
|
|
3028
|
+
}
|
|
3029
|
+
case "~":
|
|
3030
|
+
case "~>":
|
|
3031
|
+
return [
|
|
3032
|
+
{ op: ">=", v: lo },
|
|
3033
|
+
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
3034
|
+
];
|
|
3035
|
+
case ">":
|
|
3036
|
+
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
3037
|
+
case ">=":
|
|
3038
|
+
return [{ op: ">=", v: lo }];
|
|
3039
|
+
case "<":
|
|
3040
|
+
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
3041
|
+
case "<=":
|
|
3042
|
+
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
3043
|
+
default:
|
|
3044
|
+
return upper ? [
|
|
3045
|
+
{ op: ">=", v: lo },
|
|
3046
|
+
{ op: "<", v: upper }
|
|
3047
|
+
] : [{ op: "=", v: lo }];
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
function test(c, v) {
|
|
3052
|
+
const d = compareVersions(v, c.v);
|
|
3053
|
+
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
3054
|
+
}
|
|
3055
|
+
function parseRange(range) {
|
|
3056
|
+
const alts = [];
|
|
3057
|
+
for (const raw of range.trim().split("||")) {
|
|
3058
|
+
const alt = raw.trim();
|
|
3059
|
+
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
3060
|
+
if (hyphen) {
|
|
3061
|
+
const from = comparators(`>=${hyphen[1]}`);
|
|
3062
|
+
const to = comparators(`<=${hyphen[2]}`);
|
|
3063
|
+
if (!from || !to) return null;
|
|
3064
|
+
alts.push([...from, ...to]);
|
|
3065
|
+
continue;
|
|
3066
|
+
}
|
|
3067
|
+
const set = [];
|
|
3068
|
+
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
3069
|
+
const cs = comparators(token);
|
|
3070
|
+
if (!cs) return null;
|
|
3071
|
+
set.push(...cs);
|
|
3072
|
+
}
|
|
3073
|
+
alts.push(set);
|
|
3074
|
+
}
|
|
3075
|
+
return alts;
|
|
3076
|
+
}
|
|
3077
|
+
function satisfies(version, range) {
|
|
3078
|
+
const v = parseVersion(version);
|
|
3079
|
+
const alts = parseRange(range);
|
|
3080
|
+
if (!v || !alts) return null;
|
|
3081
|
+
return alts.some(
|
|
3082
|
+
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
3083
|
+
);
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
// src/doctor/installs.ts
|
|
3087
|
+
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
3088
|
+
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
3089
|
+
var readManifest = (dir) => {
|
|
3090
|
+
try {
|
|
3091
|
+
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
3092
|
+
} catch {
|
|
3093
|
+
return null;
|
|
3094
|
+
}
|
|
3095
|
+
};
|
|
3096
|
+
var real = (p) => {
|
|
3097
|
+
try {
|
|
3098
|
+
return realpathSync(p);
|
|
3099
|
+
} catch {
|
|
3100
|
+
return p;
|
|
3101
|
+
}
|
|
3102
|
+
};
|
|
3103
|
+
function packagesIn(nodeModules) {
|
|
3104
|
+
if (!existsSync(nodeModules)) return [];
|
|
3105
|
+
const out = [];
|
|
3106
|
+
for (const entry of readdirSync(nodeModules)) {
|
|
3107
|
+
if (entry.startsWith(".")) continue;
|
|
3108
|
+
const p = path14.join(nodeModules, entry);
|
|
3109
|
+
if (entry.startsWith("@")) {
|
|
3110
|
+
try {
|
|
3111
|
+
for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
|
|
3112
|
+
} catch {
|
|
3113
|
+
}
|
|
3114
|
+
} else {
|
|
3115
|
+
out.push(p);
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
return out;
|
|
3119
|
+
}
|
|
3120
|
+
function genesisInstalls(root) {
|
|
3121
|
+
const copies = /* @__PURE__ */ new Map();
|
|
3122
|
+
const realRoot = real(root);
|
|
3123
|
+
const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
|
|
3124
|
+
const via = /* @__PURE__ */ new Map();
|
|
3125
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
3126
|
+
let copy = copies.get(real2);
|
|
3127
|
+
if (!copy) {
|
|
3128
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
3129
|
+
copies.set(real2, copy);
|
|
3130
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
3131
|
+
}
|
|
3132
|
+
via.get(real2).add(root2);
|
|
3133
|
+
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
3134
|
+
};
|
|
3135
|
+
const walk = (kind, roots) => {
|
|
3136
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
3137
|
+
const queue = [];
|
|
3138
|
+
const visit = (dir, by, range) => {
|
|
3139
|
+
const manifest = readManifest(dir);
|
|
3140
|
+
if (!manifest?.name) return;
|
|
3141
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
3142
|
+
const realDir = real(dir);
|
|
3143
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
3144
|
+
if (expanded.has(realDir)) return;
|
|
3145
|
+
expanded.add(realDir);
|
|
3146
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
3147
|
+
};
|
|
3148
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
3149
|
+
while (queue.length) {
|
|
3150
|
+
const { real: from, manifest, label } = queue.shift();
|
|
3151
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
3152
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
3153
|
+
const dir = findPackageDir(from, name);
|
|
3154
|
+
if (dir) visit(dir, label, range);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
};
|
|
3158
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
3159
|
+
const dir = findPackageDir(root, name);
|
|
3160
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
3161
|
+
});
|
|
3162
|
+
const app = readManifest(root);
|
|
3163
|
+
let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
3164
|
+
let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
|
|
3165
|
+
if (Object.keys(runtimeDeps).length === 0) {
|
|
3166
|
+
runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
|
|
3167
|
+
devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
|
|
3168
|
+
}
|
|
3169
|
+
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
3170
|
+
const top = path14.join(root, "node_modules");
|
|
3171
|
+
walk(
|
|
3172
|
+
"hoisted",
|
|
3173
|
+
packagesIn(top).filter((dir) => {
|
|
3174
|
+
const name = path14.relative(top, dir).split(path14.sep).join("/");
|
|
3175
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
3176
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
3177
|
+
);
|
|
3178
|
+
const devRoots = { ...devDeps };
|
|
3179
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
3180
|
+
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
3181
|
+
for (const [key2, copy] of copies) {
|
|
3182
|
+
const kinds = via.get(key2);
|
|
3183
|
+
copy.runtime = kinds.has("runtime");
|
|
3184
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
3185
|
+
}
|
|
3186
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3187
|
+
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
3188
|
+
for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
|
|
3189
|
+
return byName;
|
|
3190
|
+
}
|
|
3191
|
+
function checkDuplicatePackages(ctx) {
|
|
3192
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
3193
|
+
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
3194
|
+
if (copies.length < 2) continue;
|
|
3195
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
3196
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
3197
|
+
ctx.report({
|
|
3198
|
+
rule: "duplicate-genesis-package",
|
|
3199
|
+
level: "warn",
|
|
3200
|
+
file: "package.json",
|
|
3201
|
+
subject: name,
|
|
3202
|
+
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`
|
|
3203
|
+
});
|
|
3204
|
+
continue;
|
|
3205
|
+
}
|
|
3206
|
+
ctx.report({
|
|
3207
|
+
rule: "duplicate-genesis-package",
|
|
3208
|
+
level: "info",
|
|
3209
|
+
file: "package.json",
|
|
3210
|
+
subject: name,
|
|
3211
|
+
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`
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
function checkPeerRanges(ctx) {
|
|
3216
|
+
const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
|
|
3217
|
+
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
3218
|
+
for (const copy of copies) {
|
|
3219
|
+
const dir = copy.absolutePath;
|
|
3220
|
+
const peers = readManifest(dir)?.peerDependencies ?? {};
|
|
3221
|
+
for (const [peer, range] of Object.entries(peers)) {
|
|
3222
|
+
if (!GENESIS.test(peer)) continue;
|
|
3223
|
+
const peerDir = findPackageDir(dir, peer);
|
|
3224
|
+
const installed = peerDir && readManifest(peerDir)?.version;
|
|
3225
|
+
if (!peerDir || !installed) continue;
|
|
3226
|
+
if (satisfies(installed, range) !== false) continue;
|
|
3227
|
+
ctx.report({
|
|
3228
|
+
rule: "peer-range-mismatch",
|
|
3229
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
3230
|
+
level: copy.devOnly ? "info" : "warn",
|
|
3231
|
+
file: "package.json",
|
|
3232
|
+
subject: `${copy.name}>${peer}`,
|
|
3233
|
+
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}`
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
var TRAIL_DEPTH = 6;
|
|
3240
|
+
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
3241
|
+
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
3242
|
+
var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
3243
|
+
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
3244
|
+
function stripForImports(code) {
|
|
3245
|
+
const out = [];
|
|
3246
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
3247
|
+
const n = code.length;
|
|
3248
|
+
const templates = [];
|
|
3249
|
+
let depth = 0;
|
|
3250
|
+
let i = 0;
|
|
3251
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
3252
|
+
const opensString = () => {
|
|
3253
|
+
const before = out.slice(-12).join("");
|
|
3254
|
+
if (!/[\w$]$/.test(before)) return true;
|
|
3255
|
+
return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
|
|
3256
|
+
};
|
|
3257
|
+
const templateBody = () => {
|
|
3258
|
+
while (i < n) {
|
|
3259
|
+
const ch = code[i];
|
|
3260
|
+
if (ch === "\\") {
|
|
3261
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
3262
|
+
i += 2;
|
|
3263
|
+
} else if (ch === "`") {
|
|
3264
|
+
out.push("`");
|
|
3265
|
+
i++;
|
|
3266
|
+
return;
|
|
3267
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
3268
|
+
out.push("${");
|
|
3269
|
+
i += 2;
|
|
3270
|
+
templates.push(depth);
|
|
3271
|
+
depth++;
|
|
3272
|
+
return;
|
|
3273
|
+
} else {
|
|
3274
|
+
out.push(blank(ch));
|
|
3275
|
+
i++;
|
|
3276
|
+
}
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
while (i < n) {
|
|
3280
|
+
const ch = code[i];
|
|
3281
|
+
const next = code[i + 1];
|
|
3282
|
+
if (ch === "/" && next === "/") {
|
|
3283
|
+
while (i < n && code[i] !== "\n") {
|
|
3284
|
+
out.push(" ");
|
|
3285
|
+
i++;
|
|
3286
|
+
}
|
|
3287
|
+
} else if (ch === "/" && next === "*") {
|
|
3288
|
+
out.push(" ");
|
|
3289
|
+
i += 2;
|
|
3290
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
3291
|
+
out.push(blank(code[i]));
|
|
3292
|
+
i++;
|
|
3293
|
+
}
|
|
3294
|
+
if (i < n) {
|
|
3295
|
+
out.push(" ");
|
|
3296
|
+
i += 2;
|
|
3297
|
+
}
|
|
3298
|
+
} else if ((ch === '"' || ch === "'") && opensString()) {
|
|
3299
|
+
const keep = isSpecifier();
|
|
3300
|
+
out.push(ch);
|
|
3301
|
+
i++;
|
|
3302
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
3303
|
+
if (code[i] === "\\") {
|
|
3304
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
3305
|
+
i += 2;
|
|
3306
|
+
} else {
|
|
3307
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
3308
|
+
i++;
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
if (i < n) {
|
|
3312
|
+
out.push(code[i]);
|
|
3313
|
+
i++;
|
|
3314
|
+
}
|
|
3315
|
+
} else if (ch === "`") {
|
|
3316
|
+
out.push("`");
|
|
3317
|
+
i++;
|
|
3318
|
+
templateBody();
|
|
3319
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
3320
|
+
templates.pop();
|
|
3321
|
+
depth--;
|
|
3322
|
+
out.push("}");
|
|
3323
|
+
i++;
|
|
3324
|
+
templateBody();
|
|
3325
|
+
} else {
|
|
3326
|
+
if (ch === "{") depth++;
|
|
3327
|
+
else if (ch === "}") depth--;
|
|
3328
|
+
out.push(ch);
|
|
3329
|
+
i++;
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
return out.join("");
|
|
3333
|
+
}
|
|
3334
|
+
function bindings(clause) {
|
|
3335
|
+
const out = [];
|
|
3336
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
3337
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
3338
|
+
const p = part.trim();
|
|
3339
|
+
if (!p || p.startsWith("type ")) continue;
|
|
3340
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
3341
|
+
}
|
|
3342
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
3343
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
3344
|
+
if (ns) out.push(ns[1]);
|
|
3345
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
3346
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
3347
|
+
return out;
|
|
3348
|
+
}
|
|
3349
|
+
function readJsonc(file) {
|
|
3350
|
+
try {
|
|
3351
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
3352
|
+
return JSON.parse(text);
|
|
3353
|
+
} catch {
|
|
3354
|
+
return null;
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
3358
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
3359
|
+
seen.add(file);
|
|
3360
|
+
const json = readJsonc(file);
|
|
3361
|
+
if (!json) return {};
|
|
3362
|
+
const dir = path14.dirname(file);
|
|
3363
|
+
let merged = {};
|
|
3364
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3365
|
+
for (const ext of parents) {
|
|
3366
|
+
if (typeof ext !== "string") continue;
|
|
3367
|
+
let target = null;
|
|
3368
|
+
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
3369
|
+
const abs = path14.resolve(dir, ext);
|
|
3370
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3371
|
+
} else {
|
|
3372
|
+
const parts = ext.split("/");
|
|
3373
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
3374
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3375
|
+
if (pkgDir) {
|
|
3376
|
+
const sub = parts.slice(nameLength).join("/");
|
|
3377
|
+
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
3378
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3382
|
+
}
|
|
3383
|
+
const opts = json.compilerOptions ?? {};
|
|
3384
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
3385
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
3386
|
+
merged.paths = opts.paths;
|
|
3387
|
+
merged.pathsDir = dir;
|
|
3388
|
+
}
|
|
3389
|
+
return merged;
|
|
3390
|
+
}
|
|
3391
|
+
function aliases(root) {
|
|
3392
|
+
const table = [];
|
|
3393
|
+
let baseUrl = null;
|
|
3394
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3395
|
+
const file = path14.join(root, name);
|
|
3396
|
+
if (!existsSync(file)) continue;
|
|
3397
|
+
const config = readTsconfig(root, file);
|
|
3398
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
3399
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
3400
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3401
|
+
if (!Array.isArray(targets)) continue;
|
|
3402
|
+
const exact = !pattern.endsWith("*");
|
|
3403
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
3407
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3408
|
+
if (typeof target !== "string") continue;
|
|
3409
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
3410
|
+
}
|
|
3411
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
|
|
3412
|
+
return { table, baseUrl };
|
|
3413
|
+
}
|
|
3414
|
+
function resolveFile(base) {
|
|
3415
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
|
|
3416
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3417
|
+
for (const p of tries) {
|
|
3418
|
+
if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3419
|
+
}
|
|
3420
|
+
return null;
|
|
3421
|
+
}
|
|
3422
|
+
var trails = /* @__PURE__ */ new WeakMap();
|
|
3423
|
+
function trailFor(ctx) {
|
|
3424
|
+
let t = trails.get(ctx.files);
|
|
3425
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
3426
|
+
return t;
|
|
3427
|
+
}
|
|
3428
|
+
function createTrail(ctx) {
|
|
3429
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
3430
|
+
let declared = null;
|
|
3431
|
+
try {
|
|
3432
|
+
const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
|
|
3433
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3434
|
+
} catch {
|
|
3435
|
+
declared = null;
|
|
3436
|
+
}
|
|
3437
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
3438
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
3439
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
3440
|
+
const importsOf = (file) => {
|
|
3441
|
+
const hit = importsCache.get(file.absolutePath);
|
|
3442
|
+
if (hit) return hit;
|
|
3443
|
+
const files = [];
|
|
3444
|
+
let lost = false;
|
|
3445
|
+
const code = stripped(file);
|
|
3446
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
3447
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
3448
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
3449
|
+
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]);
|
|
3450
|
+
const specs = [];
|
|
3451
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
3452
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
3453
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
3454
|
+
for (const spec of specs) {
|
|
3455
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3456
|
+
let resolved = null;
|
|
3457
|
+
if (spec.startsWith(".")) {
|
|
3458
|
+
resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
|
|
3459
|
+
if (!resolved) lost = true;
|
|
3460
|
+
} else {
|
|
3461
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3462
|
+
if (alias) {
|
|
3463
|
+
for (const t of alias.targets) {
|
|
3464
|
+
resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
|
|
3465
|
+
if (resolved) break;
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
|
|
3469
|
+
if (!resolved) {
|
|
3470
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3471
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
3475
|
+
}
|
|
3476
|
+
const out = { files, lost };
|
|
3477
|
+
importsCache.set(file.absolutePath, out);
|
|
3478
|
+
return out;
|
|
3479
|
+
};
|
|
3480
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
3481
|
+
const stripped = (file) => {
|
|
3482
|
+
let c = strippedCache.get(file.absolutePath);
|
|
3483
|
+
if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
|
|
3484
|
+
return c;
|
|
3485
|
+
};
|
|
3486
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
3487
|
+
const reach = (file, test2, depth, seen) => {
|
|
3488
|
+
let cache = memo.get(test2);
|
|
3489
|
+
if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
|
|
3490
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
3491
|
+
const cached = cache.get(k);
|
|
3492
|
+
if (cached) return [cached, false];
|
|
3493
|
+
let result;
|
|
3494
|
+
let cut = false;
|
|
3495
|
+
if (test2(stripped(file))) result = "yes";
|
|
3496
|
+
else {
|
|
3497
|
+
const { files, lost } = importsOf(file);
|
|
3498
|
+
let unknown = lost && depth > 0;
|
|
3499
|
+
result = "no";
|
|
3500
|
+
if (depth > 0) {
|
|
3501
|
+
seen.add(file.absolutePath);
|
|
3502
|
+
for (const abs of files) {
|
|
3503
|
+
if (seen.has(abs)) {
|
|
3504
|
+
cut = true;
|
|
3505
|
+
continue;
|
|
3506
|
+
}
|
|
3507
|
+
const target = read(abs);
|
|
3508
|
+
if (!target) {
|
|
3509
|
+
unknown = true;
|
|
3510
|
+
continue;
|
|
3511
|
+
}
|
|
3512
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
3513
|
+
if (c) cut = true;
|
|
3514
|
+
if (r === "yes") {
|
|
3515
|
+
result = "yes";
|
|
3516
|
+
break;
|
|
3517
|
+
}
|
|
3518
|
+
if (r === "unknown") unknown = true;
|
|
3519
|
+
}
|
|
3520
|
+
seen.delete(file.absolutePath);
|
|
3521
|
+
}
|
|
3522
|
+
if (result === "no" && unknown) result = "unknown";
|
|
3523
|
+
}
|
|
3524
|
+
if (result === "yes" || !cut) cache.set(k, result);
|
|
3525
|
+
return [result, cut && result !== "yes"];
|
|
3526
|
+
};
|
|
3527
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
// src/doctor/routes.ts
|
|
3531
|
+
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3532
|
+
var STEMS = {
|
|
3533
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
3534
|
+
"next-app": {
|
|
3535
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
3536
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
3537
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
3538
|
+
},
|
|
3539
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
3540
|
+
};
|
|
3541
|
+
var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
3542
|
+
var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
3543
|
+
var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
3544
|
+
var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
3545
|
+
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;
|
|
3546
|
+
function routesDir(ctx) {
|
|
3547
|
+
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3548
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
|
|
3549
|
+
}
|
|
3550
|
+
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3551
|
+
function flavorOf(dir, rels) {
|
|
3552
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
3553
|
+
if (stems.includes("__root")) return "tanstack";
|
|
3554
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
3555
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
3556
|
+
return "tanstack";
|
|
3557
|
+
}
|
|
3558
|
+
function renders(code) {
|
|
3559
|
+
const elements = renderedElements(code);
|
|
3560
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
3561
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
3562
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
3563
|
+
if (named && !definedHere(named)) return true;
|
|
3564
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
3565
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
3566
|
+
return exported !== void 0 && !definedHere(exported);
|
|
3567
|
+
}
|
|
3568
|
+
function webRoutes(ctx) {
|
|
3569
|
+
const dir = routesDir(ctx);
|
|
3570
|
+
if (!dir) return [];
|
|
3571
|
+
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(/\.[^.]+$/, "") }));
|
|
3572
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
3573
|
+
const stems = STEMS[flavor];
|
|
3574
|
+
const groups = /* @__PURE__ */ new Map();
|
|
3575
|
+
for (const { file, rel } of candidates) {
|
|
3576
|
+
const parts = rel.split("/");
|
|
3577
|
+
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
3578
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
3579
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
3580
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
3581
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
3582
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
3583
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
3584
|
+
}
|
|
3585
|
+
const trail = trailFor(ctx);
|
|
3586
|
+
const routes = [];
|
|
3587
|
+
for (const [id, files] of groups) {
|
|
3588
|
+
const parts = id.split("/");
|
|
3589
|
+
const stem = parts.pop();
|
|
3590
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
3591
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
3592
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
3593
|
+
const segments = [...folders, ...own];
|
|
3594
|
+
const tree = [...parts, ...own];
|
|
3595
|
+
let index = stems.index.has(stem);
|
|
3596
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
3597
|
+
segments.pop();
|
|
3598
|
+
tree.pop();
|
|
3599
|
+
index = true;
|
|
3600
|
+
}
|
|
3601
|
+
const code = files.map((f) => f.code).join("\n");
|
|
3602
|
+
const elements = renderedElements(code);
|
|
3603
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
3604
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
3605
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
3606
|
+
const rendering = renders(code);
|
|
3607
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
3608
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
3609
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
3610
|
+
routes.push({
|
|
3611
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
3612
|
+
files,
|
|
3613
|
+
segments,
|
|
3614
|
+
tree,
|
|
3615
|
+
index,
|
|
3616
|
+
layout,
|
|
3617
|
+
page,
|
|
3618
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
3619
|
+
redirectOnly: !rendering,
|
|
3620
|
+
parents: []
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3623
|
+
for (const r of routes) {
|
|
3624
|
+
const own = r.tree;
|
|
3625
|
+
for (const p of routes) {
|
|
3626
|
+
if (p === r || !p.layout) continue;
|
|
3627
|
+
const n = p.tree.length;
|
|
3628
|
+
if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
|
|
3629
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
3630
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
3631
|
+
r.parents.push(p);
|
|
3632
|
+
}
|
|
3633
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
3634
|
+
}
|
|
3635
|
+
return routes;
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
// src/doctor/structure.ts
|
|
3639
|
+
var SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
|
|
3640
|
+
var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
|
|
3641
|
+
var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
3642
|
+
var SHELL = /<AppShell(?=[\s>/])/;
|
|
3643
|
+
var GENESIS_PACKAGE = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
3644
|
+
var PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
|
|
3645
|
+
var PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
|
|
3646
|
+
var isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
3647
|
+
var rendersRe = (names) => {
|
|
3648
|
+
const list = [...names];
|
|
3649
|
+
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
3650
|
+
};
|
|
3651
|
+
function routeReach(ctx, r, test2) {
|
|
3652
|
+
const trail = trailFor(ctx);
|
|
3653
|
+
let unknown = false;
|
|
3654
|
+
for (const f of r.files) {
|
|
3655
|
+
const got = trail.reach(f, test2);
|
|
3656
|
+
if (got === "yes") return "yes";
|
|
3657
|
+
if (got === "unknown") unknown = true;
|
|
3658
|
+
}
|
|
3659
|
+
return unknown ? "unknown" : "no";
|
|
3660
|
+
}
|
|
3661
|
+
var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
3662
|
+
function insideShell(ctx, routes) {
|
|
3663
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
3664
|
+
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
3665
|
+
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
3666
|
+
}
|
|
3667
|
+
function checkHandRolledSubNav(ctx) {
|
|
3668
|
+
if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
|
|
3669
|
+
const routes = webRoutes(ctx);
|
|
3670
|
+
if (routes.length === 0) return;
|
|
3671
|
+
const inShell = insideShell(ctx, routes);
|
|
3672
|
+
const ui = ctx.genesis.uiPackage;
|
|
3673
|
+
for (const r of routes) {
|
|
3674
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
3675
|
+
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);
|
|
3676
|
+
if (hit) {
|
|
3677
|
+
const { f, m } = hit;
|
|
3678
|
+
const code = f.code;
|
|
3679
|
+
ctx.report({
|
|
3680
|
+
rule: "hand-rolled-sub-nav",
|
|
3681
|
+
level: "warn",
|
|
3682
|
+
file: f.path,
|
|
3683
|
+
line: lineAt(code, m.index),
|
|
3684
|
+
subject: m[1],
|
|
3685
|
+
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}`
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
function checkLocalGenesisCopies(ctx) {
|
|
3691
|
+
const owner = /* @__PURE__ */ new Map();
|
|
3692
|
+
for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
|
|
3693
|
+
for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
|
|
3694
|
+
if (owner.size === 0) return;
|
|
3695
|
+
const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
|
|
3696
|
+
const routes = routesDir(ctx);
|
|
3697
|
+
for (const file of ctx.files) {
|
|
3698
|
+
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
3699
|
+
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE));
|
|
3700
|
+
const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
|
|
3701
|
+
const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
|
|
3702
|
+
const decls = [...file.code.matchAll(decl)];
|
|
3703
|
+
decls.forEach((m, i) => {
|
|
3704
|
+
const [, exported, name] = m;
|
|
3705
|
+
const pkg = owner.get(name);
|
|
3706
|
+
if (!pkg || imported.has(name) || routeComponents.has(name)) return;
|
|
3707
|
+
if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
|
|
3708
|
+
const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
|
|
3709
|
+
if (!rendersJsx(body)) return;
|
|
3710
|
+
if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
|
|
3711
|
+
const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
|
|
3712
|
+
if (/["']@marktiderman\/genesis/.test(init)) return;
|
|
3713
|
+
ctx.report({
|
|
3714
|
+
rule: "local-genesis-copy",
|
|
3715
|
+
level: "warn",
|
|
3716
|
+
file: file.path,
|
|
3717
|
+
line: lineAt(file.code, m.index),
|
|
3718
|
+
subject: name,
|
|
3719
|
+
message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
|
|
3720
|
+
});
|
|
3721
|
+
});
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
function checkResourceWorkspaces(ctx) {
|
|
3725
|
+
if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
|
|
3726
|
+
const header = /<AppShellPageHeader(?=[\s>/])/;
|
|
3727
|
+
const byFolder = /* @__PURE__ */ new Map();
|
|
3728
|
+
for (const r of webRoutes(ctx)) {
|
|
3729
|
+
if (!r.detail || r.redirectOnly) continue;
|
|
3730
|
+
const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
|
|
3731
|
+
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
3732
|
+
}
|
|
3733
|
+
for (const [dir, routes] of byFolder) {
|
|
3734
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
3735
|
+
const has2 = routes.filter((r) => reach.get(r) === "yes");
|
|
3736
|
+
if (has2.length === 0) continue;
|
|
3737
|
+
const ref = has2.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
3738
|
+
for (const r of routes) {
|
|
3739
|
+
if (reach.get(r) !== "no") continue;
|
|
3740
|
+
ctx.report({
|
|
3741
|
+
rule: "resource-workspace",
|
|
3742
|
+
level: "info",
|
|
3743
|
+
file: r.file.path,
|
|
3744
|
+
message: `is a detail page without AppShellPageHeader, unlike ${ref} beside it; put its header in AppShellPageHeader and its sections in useAppShellSubNav so every workspace in ${dir} has the same header, tabs and phone bar`
|
|
3745
|
+
});
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3748
|
+
}
|
|
3749
|
+
function checkPageLayouts(ctx) {
|
|
3750
|
+
if (isNative(ctx)) return;
|
|
3751
|
+
const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
|
|
3752
|
+
for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
|
|
3753
|
+
if (layouts.size === 0) return;
|
|
3754
|
+
const routes = webRoutes(ctx);
|
|
3755
|
+
const inShell = insideShell(ctx, routes);
|
|
3756
|
+
const rendersLayout = (code) => {
|
|
3757
|
+
const names = new Set(layouts);
|
|
3758
|
+
for (const n of namedImportsFrom(code, GENESIS_PACKAGE)) if (PACKAGE_SCREEN.test(n)) names.add(n);
|
|
3759
|
+
return rendersRe(names)?.test(code) ?? false;
|
|
3760
|
+
};
|
|
3761
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3762
|
+
const provides = (r) => {
|
|
3763
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
3764
|
+
return cache.get(r);
|
|
3765
|
+
};
|
|
3766
|
+
const list = [...layouts].sort();
|
|
3767
|
+
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
3768
|
+
for (const r of routes) {
|
|
3769
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
3770
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
3771
|
+
ctx.report({
|
|
3772
|
+
rule: "page-layout",
|
|
3773
|
+
level: "warn",
|
|
3774
|
+
file: r.file.path,
|
|
3775
|
+
message: `renders no Genesis page layout (${named}) itself, through one local import, or from a layout route around it; wrap it in one so the header, width and spacing match every other page`
|
|
3776
|
+
});
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
// src/doctor/dates.ts
|
|
3781
|
+
var SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
3782
|
+
var ISO_DAY_CUT = /\.toISOString\(\)\s*\.\s*(?:slice\(\s*0\s*,\s*10\s*\)|substring\(\s*0\s*,\s*10\s*\)|substr\(\s*0\s*,\s*10\s*\)|split\(\s*(["'`])T\1\s*\)\s*\[\s*0\s*\]|split\(\s*(["'`])T\2\s*\)\s*\.\s*at\(\s*0\s*\))/g;
|
|
3783
|
+
function checkIsoDateSlices(ctx) {
|
|
3784
|
+
for (const file of ctx.files) {
|
|
3785
|
+
if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
|
|
3786
|
+
for (const m of file.code.matchAll(ISO_DAY_CUT)) {
|
|
3787
|
+
ctx.report({
|
|
3788
|
+
rule: "iso-date-slice",
|
|
3789
|
+
level: "warn",
|
|
3790
|
+
file: file.path,
|
|
3791
|
+
line: lineAt(file.code, m.index ?? 0),
|
|
3792
|
+
subject: "toISOString",
|
|
3793
|
+
message: "cuts a day from an ISO timestamp, which is the day in UTC, not the person's; use personDay(person) or dayIn(zone) from @marktiderman/genesis-core/dates (allow it with a reason where UTC is meant)"
|
|
3794
|
+
});
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
|
|
2863
3799
|
// src/doctor/index.ts
|
|
2864
3800
|
async function runDoctor(options = {}) {
|
|
2865
|
-
const root =
|
|
3801
|
+
const root = path14.resolve(options.root ?? process.cwd());
|
|
2866
3802
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
2867
3803
|
const config = loaded.config;
|
|
2868
3804
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -2875,18 +3811,7 @@ async function runDoctor(options = {}) {
|
|
|
2875
3811
|
}
|
|
2876
3812
|
const raw = [];
|
|
2877
3813
|
const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
|
|
2878
|
-
const
|
|
2879
|
-
{ name: "layout", check: checkProjectLayout },
|
|
2880
|
-
{ name: "imports", check: checkImports },
|
|
2881
|
-
{ name: "raw-tags", check: checkRawTags },
|
|
2882
|
-
{ name: "colors", check: checkColors },
|
|
2883
|
-
{ name: "tokens", check: checkTokens },
|
|
2884
|
-
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
2885
|
-
{ name: "version-skew", check: checkVersionSkew },
|
|
2886
|
-
...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
|
|
2887
|
-
...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
|
|
2888
|
-
];
|
|
2889
|
-
for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
3814
|
+
for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
2890
3815
|
try {
|
|
2891
3816
|
await plugin.check(ctx);
|
|
2892
3817
|
} catch (err) {
|
|
@@ -2900,7 +3825,8 @@ async function runDoctor(options = {}) {
|
|
|
2900
3825
|
}
|
|
2901
3826
|
const findings = applyConfig(raw, config);
|
|
2902
3827
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
2903
|
-
const warnings = findings.
|
|
3828
|
+
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
3829
|
+
const infos = findings.length - errors - warnings;
|
|
2904
3830
|
return {
|
|
2905
3831
|
ok: errors === 0 && !(options.strict && warnings > 0),
|
|
2906
3832
|
root,
|
|
@@ -2909,8 +3835,32 @@ async function runDoctor(options = {}) {
|
|
|
2909
3835
|
unused: unusedComponents(ctx),
|
|
2910
3836
|
ruleCount: (patterns?.count ?? 0) + plugins.length,
|
|
2911
3837
|
errors,
|
|
2912
|
-
warnings
|
|
3838
|
+
warnings,
|
|
3839
|
+
infos
|
|
3840
|
+
};
|
|
3841
|
+
}
|
|
3842
|
+
function builtinChecks(config) {
|
|
3843
|
+
const packs = {
|
|
3844
|
+
native: { name: "native", check: checkNativePack },
|
|
3845
|
+
supabase: { name: "supabase", check: checkSupabasePack }
|
|
2913
3846
|
};
|
|
3847
|
+
return [
|
|
3848
|
+
{ name: "layout", check: checkProjectLayout },
|
|
3849
|
+
{ name: "imports", check: checkImports },
|
|
3850
|
+
{ name: "raw-tags", check: checkRawTags },
|
|
3851
|
+
{ name: "colors", check: checkColors },
|
|
3852
|
+
{ name: "tokens", check: checkTokens },
|
|
3853
|
+
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
3854
|
+
{ name: "version-skew", check: checkVersionSkew },
|
|
3855
|
+
{ name: "duplicate-packages", check: checkDuplicatePackages },
|
|
3856
|
+
{ name: "peer-ranges", check: checkPeerRanges },
|
|
3857
|
+
{ name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
|
|
3858
|
+
{ name: "local-genesis-copies", check: checkLocalGenesisCopies },
|
|
3859
|
+
{ name: "resource-workspaces", check: checkResourceWorkspaces },
|
|
3860
|
+
{ name: "page-layouts", check: checkPageLayouts },
|
|
3861
|
+
{ name: "iso-date-slices", check: checkIsoDateSlices },
|
|
3862
|
+
...(config.packs ?? []).map((p) => packs[p])
|
|
3863
|
+
];
|
|
2914
3864
|
}
|
|
2915
3865
|
function applyConfig(raw, config) {
|
|
2916
3866
|
const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
|
|
@@ -2958,7 +3908,8 @@ function formatReport(result) {
|
|
|
2958
3908
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
2959
3909
|
}
|
|
2960
3910
|
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
2961
|
-
|
|
3911
|
+
const info = result.infos ? `, ${result.infos} info` : "";
|
|
3912
|
+
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
2962
3913
|
return lines.join("\n");
|
|
2963
3914
|
}
|
|
2964
3915
|
|