@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/doctor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as path14 from 'path';
|
|
2
2
|
import { spawnSync } from 'child_process';
|
|
3
|
-
import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
|
|
3
|
+
import { existsSync, readFileSync, readdirSync, statSync, realpathSync } from 'fs';
|
|
4
4
|
import { createRequire } from 'module';
|
|
5
5
|
import { pathToFileURL } from 'url';
|
|
6
6
|
|
|
@@ -8,19 +8,19 @@ import { pathToFileURL } from 'url';
|
|
|
8
8
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
9
9
|
function buildCommands(root, config) {
|
|
10
10
|
if (config.build) return config.build;
|
|
11
|
-
const pkgFile =
|
|
11
|
+
const pkgFile = path14.join(root, "package.json");
|
|
12
12
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
13
13
|
const pm = packageManager(root);
|
|
14
14
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
15
15
|
}
|
|
16
16
|
function packageManager(root) {
|
|
17
|
-
let dir =
|
|
17
|
+
let dir = path14.resolve(root);
|
|
18
18
|
for (; ; ) {
|
|
19
|
-
if (existsSync(
|
|
20
|
-
if (existsSync(
|
|
21
|
-
if (existsSync(
|
|
22
|
-
if (existsSync(
|
|
23
|
-
const parent =
|
|
19
|
+
if (existsSync(path14.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
20
|
+
if (existsSync(path14.join(dir, "bun.lock")) || existsSync(path14.join(dir, "bun.lockb"))) return "bun";
|
|
21
|
+
if (existsSync(path14.join(dir, "yarn.lock"))) return "yarn";
|
|
22
|
+
if (existsSync(path14.join(dir, "package-lock.json"))) return "npm";
|
|
23
|
+
const parent = path14.dirname(dir);
|
|
24
24
|
if (parent === dir) return "npm";
|
|
25
25
|
dir = parent;
|
|
26
26
|
}
|
|
@@ -99,7 +99,7 @@ var PRIVACY_PURPOSES = {
|
|
|
99
99
|
"third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
|
|
100
100
|
other: "NSPrivacyCollectedDataTypePurposeOther"
|
|
101
101
|
};
|
|
102
|
-
var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
102
|
+
var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build", "componentPackages"];
|
|
103
103
|
var STRINGS = ["uiPackage", "rulesDoc"];
|
|
104
104
|
var KNOWN = /* @__PURE__ */ new Set([
|
|
105
105
|
...STRING_LISTS,
|
|
@@ -114,10 +114,11 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
114
114
|
"packs",
|
|
115
115
|
"native",
|
|
116
116
|
"supabase",
|
|
117
|
+
"routesDir",
|
|
117
118
|
"$schema",
|
|
118
119
|
"$comment"
|
|
119
120
|
]);
|
|
120
|
-
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
121
|
+
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
|
|
121
122
|
var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
122
123
|
var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
123
124
|
var PACK_KEYS = {
|
|
@@ -126,25 +127,25 @@ var PACK_KEYS = {
|
|
|
126
127
|
};
|
|
127
128
|
function appPath(v, where, fail) {
|
|
128
129
|
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
129
|
-
if (
|
|
130
|
-
const norm =
|
|
130
|
+
if (path14.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
131
|
+
const norm = path14.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
131
132
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
132
133
|
return norm;
|
|
133
134
|
}
|
|
134
135
|
function loadConfig(root, configPath) {
|
|
135
136
|
if (configPath) {
|
|
136
|
-
const file =
|
|
137
|
+
const file = path14.resolve(root, configPath);
|
|
137
138
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
138
139
|
const json = readJson(file);
|
|
139
|
-
const block =
|
|
140
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
140
|
+
const block = path14.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
141
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path14.dirname(file) };
|
|
141
142
|
}
|
|
142
|
-
const own =
|
|
143
|
+
const own = path14.join(root, "genesis.config.json");
|
|
143
144
|
if (existsSync(own)) {
|
|
144
145
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
145
146
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
146
147
|
}
|
|
147
|
-
const pkg =
|
|
148
|
+
const pkg = path14.join(root, "package.json");
|
|
148
149
|
if (existsSync(pkg)) {
|
|
149
150
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
150
151
|
if (block !== void 0) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -159,7 +160,7 @@ function readJson(file) {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
function readGenesisConfig(root) {
|
|
162
|
-
const file =
|
|
163
|
+
const file = path14.join(root, "genesis.config.json");
|
|
163
164
|
if (!existsSync(file)) return null;
|
|
164
165
|
const raw = readJson(file);
|
|
165
166
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -176,7 +177,7 @@ function validatePrivacy(raw, source = "config") {
|
|
|
176
177
|
};
|
|
177
178
|
if (!isObject(raw)) fail(`"privacy" must be an object`);
|
|
178
179
|
const c = raw;
|
|
179
|
-
for (const
|
|
180
|
+
for (const key2 of Object.keys(c)) if (!PRIVACY_KEYS.has(key2)) fail(`privacy: unknown setting "${key2}"`);
|
|
180
181
|
const out = {};
|
|
181
182
|
if (c.blocks !== void 0) {
|
|
182
183
|
if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
|
|
@@ -191,7 +192,7 @@ function validatePrivacy(raw, source = "config") {
|
|
|
191
192
|
out.collects = c.collects.map((entry, i) => {
|
|
192
193
|
const where = `privacy.collects[${i}]`;
|
|
193
194
|
if (!isObject(entry)) return fail(`${where} must be an object`);
|
|
194
|
-
for (const
|
|
195
|
+
for (const key2 of Object.keys(entry)) if (!DATA_USE_KEYS.has(key2)) fail(`${where}: unknown setting "${key2}"`);
|
|
195
196
|
if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
|
|
196
197
|
fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
|
|
197
198
|
}
|
|
@@ -214,7 +215,7 @@ function validateLinks(raw, source = "config") {
|
|
|
214
215
|
};
|
|
215
216
|
if (!isObject(raw)) fail(`"links" must be an object`);
|
|
216
217
|
const c = raw;
|
|
217
|
-
for (const
|
|
218
|
+
for (const key2 of Object.keys(c)) if (!LINK_KEYS.has(key2)) fail(`links: unknown setting "${key2}"`);
|
|
218
219
|
if (!isStringList(c.hosts) || c.hosts.length === 0) fail(`links.hosts must be a non-empty list of host names`);
|
|
219
220
|
for (const host of c.hosts) {
|
|
220
221
|
if (!HOST.test(host)) {
|
|
@@ -241,15 +242,16 @@ function validateConfig(raw, source = "config") {
|
|
|
241
242
|
};
|
|
242
243
|
if (!isObject(raw)) fail("the doctor settings must be an object");
|
|
243
244
|
const c = raw;
|
|
244
|
-
for (const
|
|
245
|
+
for (const key2 of Object.keys(c)) if (!KNOWN.has(key2)) fail(`unknown setting "${key2}"`);
|
|
245
246
|
if (typeof c.themeCss === "string") c.themeCss = [c.themeCss];
|
|
246
247
|
if (c.themeCss !== void 0 && !isStringList(c.themeCss)) fail(`"themeCss" must be a path or a list of paths`);
|
|
247
|
-
for (const
|
|
248
|
-
if (c[
|
|
248
|
+
for (const key2 of STRING_LISTS) {
|
|
249
|
+
if (c[key2] !== void 0 && !isStringList(c[key2])) fail(`"${key2}" must be a list of strings`);
|
|
249
250
|
}
|
|
250
|
-
for (const
|
|
251
|
-
if (c[
|
|
251
|
+
for (const key2 of STRINGS) {
|
|
252
|
+
if (c[key2] !== void 0 && typeof c[key2] !== "string") fail(`"${key2}" must be a string`);
|
|
252
253
|
}
|
|
254
|
+
if (c.routesDir !== void 0) c.routesDir = appPath(c.routesDir, `"routesDir"`, fail);
|
|
253
255
|
if (c.rawTags !== void 0) {
|
|
254
256
|
if (!isObject(c.rawTags)) fail(`"rawTags" must be an object`);
|
|
255
257
|
for (const [tag, v] of Object.entries(c.rawTags)) {
|
|
@@ -267,7 +269,7 @@ function validateConfig(raw, source = "config") {
|
|
|
267
269
|
if (c.rules !== void 0) {
|
|
268
270
|
if (!isObject(c.rules)) fail(`"rules" must be an object of rule \u2192 level`);
|
|
269
271
|
for (const [rule, level] of Object.entries(c.rules)) {
|
|
270
|
-
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn" or "off"`);
|
|
272
|
+
if (!LEVELS.has(level)) fail(`rules.${rule} must be "error", "warn", "info" or "off"`);
|
|
271
273
|
}
|
|
272
274
|
}
|
|
273
275
|
if (c.allow !== void 0) {
|
|
@@ -360,11 +362,12 @@ function globToRegExp(glob) {
|
|
|
360
362
|
}
|
|
361
363
|
function globMatcher(globs) {
|
|
362
364
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
363
|
-
return (
|
|
365
|
+
return (path17) => res.some((re) => re.test(path17));
|
|
364
366
|
}
|
|
365
367
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
366
368
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
367
369
|
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
370
|
+
var DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
|
|
368
371
|
var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
369
372
|
var TAG_ALIASES = { hr: "Separator" };
|
|
370
373
|
var NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
@@ -399,11 +402,11 @@ var TAILWIND_PALETTE = [
|
|
|
399
402
|
"olive"
|
|
400
403
|
];
|
|
401
404
|
function findPackageDir(from, name) {
|
|
402
|
-
let dir =
|
|
405
|
+
let dir = path14.resolve(from);
|
|
403
406
|
for (; ; ) {
|
|
404
|
-
const candidate =
|
|
405
|
-
if (existsSync(
|
|
406
|
-
const parent =
|
|
407
|
+
const candidate = path14.join(dir, "node_modules", name);
|
|
408
|
+
if (existsSync(path14.join(candidate, "package.json"))) return candidate;
|
|
409
|
+
const parent = path14.dirname(dir);
|
|
407
410
|
if (parent === dir) return null;
|
|
408
411
|
dir = parent;
|
|
409
412
|
}
|
|
@@ -435,13 +438,27 @@ function loadGenesis(root, config) {
|
|
|
435
438
|
components,
|
|
436
439
|
tokens,
|
|
437
440
|
rawTags,
|
|
438
|
-
palette: loadPalette(root)
|
|
441
|
+
palette: loadPalette(root),
|
|
442
|
+
companions: loadCompanions(root, config, uiPackage)
|
|
439
443
|
};
|
|
440
444
|
}
|
|
445
|
+
function loadCompanions(root, config, uiPackage) {
|
|
446
|
+
const out = [];
|
|
447
|
+
for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
|
|
448
|
+
if (name === uiPackage) continue;
|
|
449
|
+
try {
|
|
450
|
+
const pkg = readPackageExports(root, name);
|
|
451
|
+
if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
|
|
452
|
+
} catch (err) {
|
|
453
|
+
if (!(err instanceof DoctorConfigError)) throw err;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return out;
|
|
457
|
+
}
|
|
441
458
|
function readPackageExports(root, uiPackage) {
|
|
442
459
|
const uiDir = findPackageDir(root, uiPackage);
|
|
443
460
|
if (!uiDir) return null;
|
|
444
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
461
|
+
const uiPkg = JSON.parse(readFileSync(path14.join(uiDir, "package.json"), "utf8"));
|
|
445
462
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
446
463
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
447
464
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
@@ -453,7 +470,7 @@ function readPackageExports(root, uiPackage) {
|
|
|
453
470
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
454
471
|
let readAny = false;
|
|
455
472
|
for (const entry of typeEntries) {
|
|
456
|
-
const file =
|
|
473
|
+
const file = path14.join(uiDir, entry);
|
|
457
474
|
if (!existsSync(file)) continue;
|
|
458
475
|
readAny = true;
|
|
459
476
|
const dts = readFileSync(file, "utf8");
|
|
@@ -467,11 +484,11 @@ function readPackageExports(root, uiPackage) {
|
|
|
467
484
|
}
|
|
468
485
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
469
486
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
470
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
487
|
+
const declRoot = typeof mainTypes === "string" ? path14.dirname(path14.join(uiDir, mainTypes)) : uiDir;
|
|
471
488
|
const declFiles = walkDts(declRoot);
|
|
472
489
|
for (const pkg of reexportedPackages) {
|
|
473
490
|
const dir = findPackageDir(uiDir, pkg);
|
|
474
|
-
if (dir) walkDts(
|
|
491
|
+
if (dir) walkDts(path14.join(dir, "dist"), declFiles);
|
|
475
492
|
}
|
|
476
493
|
for (const file of declFiles) {
|
|
477
494
|
const text = readFileSync(file, "utf8");
|
|
@@ -507,8 +524,8 @@ function exportTypes(target) {
|
|
|
507
524
|
if (!target || typeof target !== "object") return void 0;
|
|
508
525
|
const t = target;
|
|
509
526
|
if (typeof t.types === "string") return t.types;
|
|
510
|
-
for (const
|
|
511
|
-
const nested = exportTypes(t[
|
|
527
|
+
for (const key2 of ["import", "default", "require"]) {
|
|
528
|
+
const nested = exportTypes(t[key2]);
|
|
512
529
|
if (nested) return nested;
|
|
513
530
|
}
|
|
514
531
|
return void 0;
|
|
@@ -517,7 +534,7 @@ function walkDts(dir, out = []) {
|
|
|
517
534
|
if (!existsSync(dir)) return out;
|
|
518
535
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
519
536
|
if (entry.name === "node_modules") continue;
|
|
520
|
-
const p =
|
|
537
|
+
const p = path14.join(dir, entry.name);
|
|
521
538
|
if (entry.isDirectory()) walkDts(p, out);
|
|
522
539
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
523
540
|
}
|
|
@@ -534,27 +551,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
534
551
|
}
|
|
535
552
|
const files = [];
|
|
536
553
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
537
|
-
const themes = ds &&
|
|
554
|
+
const themes = ds && path14.join(ds, "dist", "themes");
|
|
538
555
|
if (themes && existsSync(themes)) {
|
|
539
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
556
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path14.join(themes, name));
|
|
540
557
|
}
|
|
541
558
|
if (files.length === 0) {
|
|
542
559
|
throw new DoctorConfigError(
|
|
543
560
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
544
561
|
);
|
|
545
562
|
}
|
|
546
|
-
const uiStyles =
|
|
563
|
+
const uiStyles = path14.join(uiDir, "dist", "styles.css");
|
|
547
564
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
548
565
|
return files;
|
|
549
566
|
}
|
|
550
567
|
function resolveSpec(root, spec) {
|
|
551
|
-
const local =
|
|
552
|
-
if (spec.startsWith(".") ||
|
|
568
|
+
const local = path14.resolve(root, spec);
|
|
569
|
+
if (spec.startsWith(".") || path14.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
553
570
|
const parts = spec.split("/");
|
|
554
571
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
555
572
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
556
573
|
if (dir) {
|
|
557
|
-
const file =
|
|
574
|
+
const file = path14.join(dir, ...parts.slice(nameLength));
|
|
558
575
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
559
576
|
}
|
|
560
577
|
return existsSync(local) ? local : null;
|
|
@@ -562,10 +579,10 @@ function resolveSpec(root, spec) {
|
|
|
562
579
|
function loadPalette(root) {
|
|
563
580
|
const names = new Set(TAILWIND_PALETTE);
|
|
564
581
|
try {
|
|
565
|
-
const req = createRequire(
|
|
582
|
+
const req = createRequire(path14.join(root, "package.json"));
|
|
566
583
|
const colors = req("tailwindcss/colors");
|
|
567
|
-
for (const
|
|
568
|
-
if (/^[a-z]+$/.test(
|
|
584
|
+
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
585
|
+
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
569
586
|
}
|
|
570
587
|
} catch {
|
|
571
588
|
}
|
|
@@ -747,16 +764,16 @@ var DEFAULT_IGNORE = [
|
|
|
747
764
|
];
|
|
748
765
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
749
766
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
750
|
-
var toPosix = (p) => p.split(
|
|
767
|
+
var toPosix = (p) => p.split(path14.sep).join("/");
|
|
751
768
|
function scanFiles(root, config) {
|
|
752
769
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
753
770
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
754
771
|
const files = [];
|
|
755
772
|
const seen = /* @__PURE__ */ new Set();
|
|
756
773
|
const visit = (abs) => {
|
|
757
|
-
const rel = toPosix(
|
|
774
|
+
const rel = toPosix(path14.relative(root, abs));
|
|
758
775
|
if (seen.has(rel) || ignored(rel)) return;
|
|
759
|
-
const ext =
|
|
776
|
+
const ext = path14.extname(abs);
|
|
760
777
|
if (!extensions.has(ext)) return;
|
|
761
778
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
762
779
|
seen.add(rel);
|
|
@@ -766,14 +783,14 @@ function scanFiles(root, config) {
|
|
|
766
783
|
const walk = (dir) => {
|
|
767
784
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
768
785
|
if (entry.isDirectory()) {
|
|
769
|
-
if (!SKIP_DIRS.has(entry.name)) walk(
|
|
786
|
+
if (!SKIP_DIRS.has(entry.name)) walk(path14.join(dir, entry.name));
|
|
770
787
|
} else if (entry.isFile()) {
|
|
771
|
-
visit(
|
|
788
|
+
visit(path14.join(dir, entry.name));
|
|
772
789
|
}
|
|
773
790
|
}
|
|
774
791
|
};
|
|
775
792
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
776
|
-
const abs =
|
|
793
|
+
const abs = path14.resolve(root, src);
|
|
777
794
|
if (!existsSync(abs)) continue;
|
|
778
795
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
779
796
|
else visit(abs);
|
|
@@ -803,11 +820,11 @@ function parseRulesMarkdown(markdown) {
|
|
|
803
820
|
}
|
|
804
821
|
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message):\s*(.*)$/);
|
|
805
822
|
if (!current || !kv) continue;
|
|
806
|
-
const [,
|
|
823
|
+
const [, key2, raw] = kv;
|
|
807
824
|
const value = raw.trim();
|
|
808
|
-
if (
|
|
809
|
-
else if (
|
|
810
|
-
else current[
|
|
825
|
+
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
826
|
+
else if (key2 === "level") current.level = value;
|
|
827
|
+
else current[key2] = value;
|
|
811
828
|
}
|
|
812
829
|
return rules;
|
|
813
830
|
}
|
|
@@ -822,8 +839,8 @@ function compilePatternRules(rules, source) {
|
|
|
822
839
|
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
823
840
|
ids.add(rule.id);
|
|
824
841
|
const level = rule.level ?? "error";
|
|
825
|
-
if (!["error", "warn", "guide"].includes(level)) {
|
|
826
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn or guide)`);
|
|
842
|
+
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
843
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
827
844
|
}
|
|
828
845
|
if (level === "guide") continue;
|
|
829
846
|
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
@@ -850,7 +867,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
850
867
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
851
868
|
let all = compiled;
|
|
852
869
|
if (rulesDoc) {
|
|
853
|
-
const file =
|
|
870
|
+
const file = path14.resolve(root, rulesDoc);
|
|
854
871
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
855
872
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
856
873
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -909,14 +926,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
909
926
|
}
|
|
910
927
|
function resolvePlugin(id, configDir) {
|
|
911
928
|
try {
|
|
912
|
-
if (id.startsWith(".") ||
|
|
929
|
+
if (id.startsWith(".") || path14.isAbsolute(id)) return resolveFrom(path14.resolve(configDir, id), configDir);
|
|
913
930
|
return resolveFrom(id, configDir);
|
|
914
931
|
} catch {
|
|
915
932
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
916
933
|
}
|
|
917
934
|
}
|
|
918
935
|
function resolveFrom(id, from) {
|
|
919
|
-
return createRequire(
|
|
936
|
+
return createRequire(path14.join(from, "noop.js")).resolve(id);
|
|
920
937
|
}
|
|
921
938
|
var BUILTIN_RULES = [
|
|
922
939
|
"local-primitives",
|
|
@@ -929,6 +946,15 @@ var BUILTIN_RULES = [
|
|
|
929
946
|
"undefined-token",
|
|
930
947
|
"shadowed-export",
|
|
931
948
|
"version-skew",
|
|
949
|
+
"duplicate-genesis-package",
|
|
950
|
+
"peer-range-mismatch",
|
|
951
|
+
// structure
|
|
952
|
+
"hand-rolled-sub-nav",
|
|
953
|
+
"local-genesis-copy",
|
|
954
|
+
"resource-workspace",
|
|
955
|
+
"page-layout",
|
|
956
|
+
// dates
|
|
957
|
+
"iso-date-slice",
|
|
932
958
|
// native pack
|
|
933
959
|
"native-raw-primitive",
|
|
934
960
|
"native-literal-color",
|
|
@@ -939,7 +965,8 @@ var BUILTIN_RULES = [
|
|
|
939
965
|
"migration-grants",
|
|
940
966
|
"migration-rls",
|
|
941
967
|
"migration-definer-search-path",
|
|
942
|
-
"migration-edited"
|
|
968
|
+
"migration-edited",
|
|
969
|
+
"migration-testing-kit"
|
|
943
970
|
];
|
|
944
971
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
945
972
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -957,7 +984,7 @@ function importSpecifiers(file) {
|
|
|
957
984
|
}
|
|
958
985
|
function checkProjectLayout(ctx) {
|
|
959
986
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
960
|
-
if (existsSync(
|
|
987
|
+
if (existsSync(path14.join(ctx.root, dir))) {
|
|
961
988
|
ctx.report({
|
|
962
989
|
rule: "local-primitives",
|
|
963
990
|
file: dir,
|
|
@@ -967,7 +994,7 @@ function checkProjectLayout(ctx) {
|
|
|
967
994
|
}
|
|
968
995
|
}
|
|
969
996
|
for (const file of STARTER_LEFTOVERS) {
|
|
970
|
-
if (existsSync(
|
|
997
|
+
if (existsSync(path14.join(ctx.root, file))) {
|
|
971
998
|
ctx.report({
|
|
972
999
|
rule: "starter-leftover",
|
|
973
1000
|
level: "warn",
|
|
@@ -1056,7 +1083,7 @@ function checkTokens(ctx) {
|
|
|
1056
1083
|
}
|
|
1057
1084
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
1058
1085
|
if (/[*?]/.test(pattern)) continue;
|
|
1059
|
-
const abs =
|
|
1086
|
+
const abs = path14.join(ctx.root, pattern);
|
|
1060
1087
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
1061
1088
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
1062
1089
|
}
|
|
@@ -1155,11 +1182,97 @@ var appFunctionality = (type, ...more) => ({
|
|
|
1155
1182
|
function privacyApisFor(dependencies2) {
|
|
1156
1183
|
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
1157
1184
|
}
|
|
1158
|
-
|
|
1159
|
-
// src/doctor/native.ts
|
|
1160
1185
|
var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
1161
1186
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
1162
1187
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
1188
|
+
function localImports(root, file) {
|
|
1189
|
+
const out = [];
|
|
1190
|
+
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1191
|
+
const spec = m[1];
|
|
1192
|
+
const bases = spec.startsWith(".") ? [path14.resolve(path14.dirname(file.absolutePath), spec)] : [path14.join(root, spec.slice(2)), path14.join(root, "src", spec.slice(2))];
|
|
1193
|
+
for (const base of bases) {
|
|
1194
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path14.join(base, `index${e}`))].find(
|
|
1195
|
+
(p) => SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p)
|
|
1196
|
+
);
|
|
1197
|
+
if (hit) {
|
|
1198
|
+
out.push(hit);
|
|
1199
|
+
break;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
return out;
|
|
1204
|
+
}
|
|
1205
|
+
function readSource(abs) {
|
|
1206
|
+
try {
|
|
1207
|
+
return { absolutePath: abs, code: readFileSync(abs, "utf8") };
|
|
1208
|
+
} catch {
|
|
1209
|
+
return null;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
function tagEnd(code, start) {
|
|
1213
|
+
let depth = 0;
|
|
1214
|
+
let quote = null;
|
|
1215
|
+
for (let i = start + 1; i < code.length; i++) {
|
|
1216
|
+
const ch = code[i];
|
|
1217
|
+
if (quote) {
|
|
1218
|
+
if (ch === "\\") i++;
|
|
1219
|
+
else if (ch === quote) quote = null;
|
|
1220
|
+
continue;
|
|
1221
|
+
}
|
|
1222
|
+
if (ch === '"' || ch === "'" || ch === "`") quote = ch;
|
|
1223
|
+
else if (ch === "{") depth++;
|
|
1224
|
+
else if (ch === "}") depth--;
|
|
1225
|
+
else if (ch === ">" && depth === 0) {
|
|
1226
|
+
let j = i - 1;
|
|
1227
|
+
while (j > start && /\s/.test(code[j])) j--;
|
|
1228
|
+
return { end: i + 1, selfClosing: code[j] === "/" };
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
return { end: code.length, selfClosing: false };
|
|
1232
|
+
}
|
|
1233
|
+
function openElementsAt(code, index, track) {
|
|
1234
|
+
const open = [];
|
|
1235
|
+
const re = /<(\/?)([A-Z][\w.]*)(?=[\s>/])/g;
|
|
1236
|
+
for (let m = re.exec(code); m && m.index < index; m = re.exec(code)) {
|
|
1237
|
+
const name = m[2];
|
|
1238
|
+
if (!track(name)) continue;
|
|
1239
|
+
if (!m[1] && /[\w$.]$/.test(code.slice(Math.max(0, m.index - 1), m.index))) continue;
|
|
1240
|
+
if (m[1]) {
|
|
1241
|
+
const at = open.lastIndexOf(name);
|
|
1242
|
+
if (at !== -1) open.splice(at, 1);
|
|
1243
|
+
continue;
|
|
1244
|
+
}
|
|
1245
|
+
const { end, selfClosing } = tagEnd(code, m.index);
|
|
1246
|
+
if (end > index) break;
|
|
1247
|
+
if (!selfClosing) open.push(name);
|
|
1248
|
+
}
|
|
1249
|
+
return open;
|
|
1250
|
+
}
|
|
1251
|
+
function renderedElements(code) {
|
|
1252
|
+
const out = [];
|
|
1253
|
+
for (const m of code.matchAll(/(?<![\w$.])<([A-Z][\w.]*)(?=[\s>/])/g)) out.push(m[1]);
|
|
1254
|
+
return out;
|
|
1255
|
+
}
|
|
1256
|
+
function rendersJsx(code) {
|
|
1257
|
+
return renderedElements(code).length > 0 || /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/.test(code);
|
|
1258
|
+
}
|
|
1259
|
+
function namedImportsFrom(code, pkg) {
|
|
1260
|
+
const out = [];
|
|
1261
|
+
for (const m of code.matchAll(/\bimport\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']([^"']+)["']/g)) {
|
|
1262
|
+
if (!pkg.test(m[2])) continue;
|
|
1263
|
+
for (const part of m[1].split(",")) {
|
|
1264
|
+
const p = part.trim();
|
|
1265
|
+
if (!p || p.startsWith("type ")) continue;
|
|
1266
|
+
const local = p.split(/\s+as\s+/).pop()?.trim();
|
|
1267
|
+
if (local) out.push(local);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
return out;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// src/doctor/native.ts
|
|
1274
|
+
var SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
1275
|
+
var JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
1163
1276
|
var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
|
|
1164
1277
|
var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
|
|
1165
1278
|
var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
|
|
@@ -1194,7 +1307,7 @@ function checkRawPrimitives(ctx, pkg) {
|
|
|
1194
1307
|
];
|
|
1195
1308
|
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
1196
1309
|
for (const file of ctx.files) {
|
|
1197
|
-
if (!
|
|
1310
|
+
if (!SCRIPT_EXTS3.has(file.ext)) continue;
|
|
1198
1311
|
const code = file.code;
|
|
1199
1312
|
const report = (name, at) => {
|
|
1200
1313
|
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
@@ -1240,10 +1353,10 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1240
1353
|
const reported = /* @__PURE__ */ new Set();
|
|
1241
1354
|
const hidingLayouts = /* @__PURE__ */ new Map();
|
|
1242
1355
|
for (const file of ctx.files) {
|
|
1243
|
-
if (!
|
|
1356
|
+
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
1244
1357
|
const code = file.code;
|
|
1245
1358
|
const hidden = HIDES_HEADER.exec(code);
|
|
1246
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
1359
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path14.posix.dirname(file.path), file.path);
|
|
1247
1360
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1248
1361
|
if (hidden && own) {
|
|
1249
1362
|
reported.add(file.path);
|
|
@@ -1270,8 +1383,8 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1270
1383
|
}
|
|
1271
1384
|
}
|
|
1272
1385
|
for (const file of ctx.files) {
|
|
1273
|
-
if (!
|
|
1274
|
-
const layout = hidingLayouts.get(
|
|
1386
|
+
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1387
|
+
const layout = hidingLayouts.get(path14.posix.dirname(file.path));
|
|
1275
1388
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1276
1389
|
if (!layout || !own) continue;
|
|
1277
1390
|
ctx.report({
|
|
@@ -1286,13 +1399,13 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
1286
1399
|
}
|
|
1287
1400
|
function routerRoot(ctx) {
|
|
1288
1401
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1289
|
-
return existsSync(
|
|
1402
|
+
return existsSync(path14.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1290
1403
|
}
|
|
1291
1404
|
function checkScreenLayouts(ctx, pkg) {
|
|
1292
1405
|
const layouts = nativeLayouts(pkg);
|
|
1293
1406
|
if (layouts.length === 0) return;
|
|
1294
1407
|
const rootDir = routerRoot(ctx);
|
|
1295
|
-
if (!existsSync(
|
|
1408
|
+
if (!existsSync(path14.join(ctx.root, rootDir))) {
|
|
1296
1409
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1297
1410
|
return;
|
|
1298
1411
|
}
|
|
@@ -1306,15 +1419,15 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
1306
1419
|
});
|
|
1307
1420
|
return;
|
|
1308
1421
|
}
|
|
1309
|
-
const
|
|
1422
|
+
const renders2 = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
1310
1423
|
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
1311
1424
|
for (const file of routes) {
|
|
1312
|
-
if (!
|
|
1425
|
+
if (!JSX_EXTS3.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1313
1426
|
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
1314
|
-
if (
|
|
1427
|
+
if (renders2.test(file.code)) continue;
|
|
1315
1428
|
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
1316
1429
|
const target = byPath.get(abs) ?? readSource(abs);
|
|
1317
|
-
return target !== null &&
|
|
1430
|
+
return target !== null && renders2.test(target.code);
|
|
1318
1431
|
});
|
|
1319
1432
|
if (viaImport) continue;
|
|
1320
1433
|
ctx.report({
|
|
@@ -1325,30 +1438,6 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
1325
1438
|
});
|
|
1326
1439
|
}
|
|
1327
1440
|
}
|
|
1328
|
-
function localImports(root, file) {
|
|
1329
|
-
const out = [];
|
|
1330
|
-
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1331
|
-
const spec = m[1];
|
|
1332
|
-
const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
|
|
1333
|
-
for (const base of bases) {
|
|
1334
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
|
|
1335
|
-
(p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
|
|
1336
|
-
);
|
|
1337
|
-
if (hit) {
|
|
1338
|
-
out.push(hit);
|
|
1339
|
-
break;
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
return out;
|
|
1344
|
-
}
|
|
1345
|
-
function readSource(abs) {
|
|
1346
|
-
try {
|
|
1347
|
-
return { code: readFileSync(abs, "utf8") };
|
|
1348
|
-
} catch {
|
|
1349
|
-
return null;
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
1441
|
var PERMISSIONS = [
|
|
1353
1442
|
{ module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
|
|
1354
1443
|
{ module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
|
|
@@ -1371,7 +1460,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
1371
1460
|
function readExpoConfigs(root) {
|
|
1372
1461
|
const out = [];
|
|
1373
1462
|
for (const name of EXPO_CONFIGS) {
|
|
1374
|
-
const abs =
|
|
1463
|
+
const abs = path14.join(root, name);
|
|
1375
1464
|
if (!existsSync(abs)) continue;
|
|
1376
1465
|
const text = readFileSync(abs, "utf8");
|
|
1377
1466
|
let json = null;
|
|
@@ -1405,13 +1494,13 @@ function pluginOptions(json, module) {
|
|
|
1405
1494
|
return null;
|
|
1406
1495
|
}
|
|
1407
1496
|
function dependencies(root) {
|
|
1408
|
-
const file =
|
|
1497
|
+
const file = path14.join(root, "package.json");
|
|
1409
1498
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1410
1499
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1411
1500
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1412
1501
|
}
|
|
1413
1502
|
function runtimeDependencies(root) {
|
|
1414
|
-
const file =
|
|
1503
|
+
const file = path14.join(root, "package.json");
|
|
1415
1504
|
if (!existsSync(file)) return {};
|
|
1416
1505
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1417
1506
|
}
|
|
@@ -1471,14 +1560,14 @@ function checkStoreReadiness(ctx) {
|
|
|
1471
1560
|
});
|
|
1472
1561
|
if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
|
|
1473
1562
|
}
|
|
1474
|
-
for (const [
|
|
1475
|
-
const opt = PERMISSIONS.find((p) => p.key ===
|
|
1563
|
+
for (const [key2, modules] of generic) {
|
|
1564
|
+
const opt = PERMISSIONS.find((p) => p.key === key2).option;
|
|
1476
1565
|
ctx.report({
|
|
1477
1566
|
rule: "store-readiness",
|
|
1478
1567
|
level: "warn",
|
|
1479
1568
|
file,
|
|
1480
|
-
subject:
|
|
1481
|
-
message: `leaves ${
|
|
1569
|
+
subject: key2,
|
|
1570
|
+
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`
|
|
1482
1571
|
});
|
|
1483
1572
|
}
|
|
1484
1573
|
const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
|
|
@@ -1674,9 +1763,9 @@ function gitView(root, dir, base) {
|
|
|
1674
1763
|
function checkSupabasePack(ctx) {
|
|
1675
1764
|
const settings = ctx.config.supabase ?? {};
|
|
1676
1765
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1677
|
-
const abs =
|
|
1766
|
+
const abs = path14.join(ctx.root, dir);
|
|
1678
1767
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1679
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
1768
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
1680
1769
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1681
1770
|
const base = settings.base ?? DEFAULT_BASE;
|
|
1682
1771
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -1693,7 +1782,7 @@ function checkSupabasePack(ctx) {
|
|
|
1693
1782
|
}
|
|
1694
1783
|
}
|
|
1695
1784
|
const since = settings.since;
|
|
1696
|
-
const afterSince = (file) => since === void 0 ||
|
|
1785
|
+
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
1697
1786
|
if ("reason" in view && since === void 0) {
|
|
1698
1787
|
ctx.report({
|
|
1699
1788
|
rule: "migration-grants",
|
|
@@ -1707,6 +1796,20 @@ function checkSupabasePack(ctx) {
|
|
|
1707
1796
|
}
|
|
1708
1797
|
checkRls(ctx, migrations, exposed);
|
|
1709
1798
|
checkDefinerSearchPath(ctx, migrations);
|
|
1799
|
+
checkTestingKit(ctx, migrations);
|
|
1800
|
+
}
|
|
1801
|
+
function checkTestingKit(ctx, migrations) {
|
|
1802
|
+
for (const { file, statements } of migrations) {
|
|
1803
|
+
const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
|
|
1804
|
+
if (!hit) continue;
|
|
1805
|
+
ctx.report({
|
|
1806
|
+
rule: "migration-testing-kit",
|
|
1807
|
+
file,
|
|
1808
|
+
line: hit.line,
|
|
1809
|
+
subject: "genesis_testing",
|
|
1810
|
+
message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1710
1813
|
}
|
|
1711
1814
|
function granteesOf(s) {
|
|
1712
1815
|
return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
|
|
@@ -1835,8 +1938,8 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1835
1938
|
for (const { sql, line } of statements) {
|
|
1836
1939
|
const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
|
|
1837
1940
|
if (create) {
|
|
1838
|
-
const [
|
|
1839
|
-
fns.set(
|
|
1941
|
+
const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
|
|
1942
|
+
fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
|
|
1840
1943
|
continue;
|
|
1841
1944
|
}
|
|
1842
1945
|
const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
|
|
@@ -1845,13 +1948,13 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1845
1948
|
const keys = keysFor(sql, alter[0].length, fnName);
|
|
1846
1949
|
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
1847
1950
|
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
1848
|
-
for (const
|
|
1849
|
-
const state = fns.get(
|
|
1951
|
+
for (const key2 of keys) {
|
|
1952
|
+
const state = fns.get(key2);
|
|
1850
1953
|
if (rename || move) {
|
|
1851
1954
|
if (!state) continue;
|
|
1852
|
-
fns.delete(
|
|
1955
|
+
fns.delete(key2);
|
|
1853
1956
|
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
1854
|
-
fns.set(newName +
|
|
1957
|
+
fns.set(newName + key2.slice(fnName.length), state);
|
|
1855
1958
|
continue;
|
|
1856
1959
|
}
|
|
1857
1960
|
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
@@ -1859,7 +1962,7 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1859
1962
|
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
1860
1963
|
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
1861
1964
|
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
1862
|
-
fns.set(
|
|
1965
|
+
fns.set(key2, next);
|
|
1863
1966
|
}
|
|
1864
1967
|
continue;
|
|
1865
1968
|
}
|
|
@@ -1867,26 +1970,26 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
1867
1970
|
if (drop) {
|
|
1868
1971
|
for (const part of splitTop(drop[1])) {
|
|
1869
1972
|
const m = /^([\w$.]+)\s*/.exec(part);
|
|
1870
|
-
if (m) for (const
|
|
1973
|
+
if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
|
|
1871
1974
|
}
|
|
1872
1975
|
}
|
|
1873
1976
|
}
|
|
1874
1977
|
}
|
|
1875
|
-
for (const [
|
|
1978
|
+
for (const [key2, at] of fns) {
|
|
1876
1979
|
if (!at.definer || at.searchPath) continue;
|
|
1877
1980
|
ctx.report({
|
|
1878
1981
|
rule: "migration-definer-search-path",
|
|
1879
1982
|
file: at.file,
|
|
1880
1983
|
line: at.line,
|
|
1881
|
-
subject:
|
|
1882
|
-
message: `${
|
|
1984
|
+
subject: key2,
|
|
1985
|
+
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`
|
|
1883
1986
|
});
|
|
1884
1987
|
}
|
|
1885
1988
|
}
|
|
1886
1989
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
1887
1990
|
function readReleaseManifest(root) {
|
|
1888
1991
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
1889
|
-
const file = dir &&
|
|
1992
|
+
const file = dir && path14.join(dir, "dist", "versions.json");
|
|
1890
1993
|
if (!file || !existsSync(file)) return null;
|
|
1891
1994
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
1892
1995
|
}
|
|
@@ -1896,7 +1999,7 @@ function checkVersionSkew(ctx) {
|
|
|
1896
1999
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
1897
2000
|
const dir = findPackageDir(ctx.root, name);
|
|
1898
2001
|
if (!dir) continue;
|
|
1899
|
-
const have = JSON.parse(readFileSync(
|
|
2002
|
+
const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
|
|
1900
2003
|
if (have === want) continue;
|
|
1901
2004
|
ctx.report({
|
|
1902
2005
|
rule: "version-skew",
|
|
@@ -1908,9 +2011,842 @@ function checkVersionSkew(ctx) {
|
|
|
1908
2011
|
}
|
|
1909
2012
|
}
|
|
1910
2013
|
|
|
2014
|
+
// src/doctor/semver.ts
|
|
2015
|
+
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2016
|
+
function parseVersion(v) {
|
|
2017
|
+
const m = VERSION.exec(v.trim());
|
|
2018
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2019
|
+
}
|
|
2020
|
+
function compareVersions(a, b) {
|
|
2021
|
+
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
2022
|
+
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
2023
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
2024
|
+
const x = a.pre[i];
|
|
2025
|
+
const y = b.pre[i];
|
|
2026
|
+
if (x === void 0) return -1;
|
|
2027
|
+
if (y === void 0) return 1;
|
|
2028
|
+
if (x === y) continue;
|
|
2029
|
+
const nx = /^\d+$/.test(x);
|
|
2030
|
+
const ny = /^\d+$/.test(y);
|
|
2031
|
+
if (nx && ny) return +x < +y ? -1 : 1;
|
|
2032
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
2033
|
+
return x < y ? -1 : 1;
|
|
2034
|
+
}
|
|
2035
|
+
return 0;
|
|
2036
|
+
}
|
|
2037
|
+
function partial(s) {
|
|
2038
|
+
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
2039
|
+
if (!m) return null;
|
|
2040
|
+
const nums = [];
|
|
2041
|
+
let wild = false;
|
|
2042
|
+
for (const part of [m[1], m[2], m[3]]) {
|
|
2043
|
+
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
2044
|
+
wild = true;
|
|
2045
|
+
nums.push(null);
|
|
2046
|
+
} else nums.push(+part);
|
|
2047
|
+
}
|
|
2048
|
+
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
2049
|
+
}
|
|
2050
|
+
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
2051
|
+
function comparators(token) {
|
|
2052
|
+
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
2053
|
+
if (!m) return null;
|
|
2054
|
+
const op = m[1] ?? "";
|
|
2055
|
+
const p = partial(m[2]);
|
|
2056
|
+
if (!p) return null;
|
|
2057
|
+
const [major, mi, pa] = p.nums;
|
|
2058
|
+
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
2059
|
+
const M = major;
|
|
2060
|
+
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
2061
|
+
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"]);
|
|
2062
|
+
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
2063
|
+
const out = switchOp();
|
|
2064
|
+
if (p.pre.length) {
|
|
2065
|
+
for (const c of out) if (c.v === lo) c.pre = true;
|
|
2066
|
+
}
|
|
2067
|
+
return out;
|
|
2068
|
+
function switchOp() {
|
|
2069
|
+
switch (op) {
|
|
2070
|
+
case "^": {
|
|
2071
|
+
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
2072
|
+
return [
|
|
2073
|
+
{ op: ">=", v: lo },
|
|
2074
|
+
{ op: "<", v: bound }
|
|
2075
|
+
];
|
|
2076
|
+
}
|
|
2077
|
+
case "~":
|
|
2078
|
+
case "~>":
|
|
2079
|
+
return [
|
|
2080
|
+
{ op: ">=", v: lo },
|
|
2081
|
+
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
2082
|
+
];
|
|
2083
|
+
case ">":
|
|
2084
|
+
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
2085
|
+
case ">=":
|
|
2086
|
+
return [{ op: ">=", v: lo }];
|
|
2087
|
+
case "<":
|
|
2088
|
+
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
2089
|
+
case "<=":
|
|
2090
|
+
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
2091
|
+
default:
|
|
2092
|
+
return upper ? [
|
|
2093
|
+
{ op: ">=", v: lo },
|
|
2094
|
+
{ op: "<", v: upper }
|
|
2095
|
+
] : [{ op: "=", v: lo }];
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
function test(c, v) {
|
|
2100
|
+
const d = compareVersions(v, c.v);
|
|
2101
|
+
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
2102
|
+
}
|
|
2103
|
+
function parseRange(range) {
|
|
2104
|
+
const alts = [];
|
|
2105
|
+
for (const raw of range.trim().split("||")) {
|
|
2106
|
+
const alt = raw.trim();
|
|
2107
|
+
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
2108
|
+
if (hyphen) {
|
|
2109
|
+
const from = comparators(`>=${hyphen[1]}`);
|
|
2110
|
+
const to = comparators(`<=${hyphen[2]}`);
|
|
2111
|
+
if (!from || !to) return null;
|
|
2112
|
+
alts.push([...from, ...to]);
|
|
2113
|
+
continue;
|
|
2114
|
+
}
|
|
2115
|
+
const set = [];
|
|
2116
|
+
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
2117
|
+
const cs = comparators(token);
|
|
2118
|
+
if (!cs) return null;
|
|
2119
|
+
set.push(...cs);
|
|
2120
|
+
}
|
|
2121
|
+
alts.push(set);
|
|
2122
|
+
}
|
|
2123
|
+
return alts;
|
|
2124
|
+
}
|
|
2125
|
+
function satisfies(version, range) {
|
|
2126
|
+
const v = parseVersion(version);
|
|
2127
|
+
const alts = parseRange(range);
|
|
2128
|
+
if (!v || !alts) return null;
|
|
2129
|
+
return alts.some(
|
|
2130
|
+
(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))
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// src/doctor/installs.ts
|
|
2135
|
+
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
2136
|
+
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
2137
|
+
var readManifest = (dir) => {
|
|
2138
|
+
try {
|
|
2139
|
+
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
2140
|
+
} catch {
|
|
2141
|
+
return null;
|
|
2142
|
+
}
|
|
2143
|
+
};
|
|
2144
|
+
var real = (p) => {
|
|
2145
|
+
try {
|
|
2146
|
+
return realpathSync(p);
|
|
2147
|
+
} catch {
|
|
2148
|
+
return p;
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
function packagesIn(nodeModules) {
|
|
2152
|
+
if (!existsSync(nodeModules)) return [];
|
|
2153
|
+
const out = [];
|
|
2154
|
+
for (const entry of readdirSync(nodeModules)) {
|
|
2155
|
+
if (entry.startsWith(".")) continue;
|
|
2156
|
+
const p = path14.join(nodeModules, entry);
|
|
2157
|
+
if (entry.startsWith("@")) {
|
|
2158
|
+
try {
|
|
2159
|
+
for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
|
|
2160
|
+
} catch {
|
|
2161
|
+
}
|
|
2162
|
+
} else {
|
|
2163
|
+
out.push(p);
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
return out;
|
|
2167
|
+
}
|
|
2168
|
+
function genesisInstalls(root) {
|
|
2169
|
+
const copies = /* @__PURE__ */ new Map();
|
|
2170
|
+
const realRoot = real(root);
|
|
2171
|
+
const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
|
|
2172
|
+
const via = /* @__PURE__ */ new Map();
|
|
2173
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
2174
|
+
let copy = copies.get(real2);
|
|
2175
|
+
if (!copy) {
|
|
2176
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
2177
|
+
copies.set(real2, copy);
|
|
2178
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
2179
|
+
}
|
|
2180
|
+
via.get(real2).add(root2);
|
|
2181
|
+
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
2182
|
+
};
|
|
2183
|
+
const walk = (kind, roots) => {
|
|
2184
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
2185
|
+
const queue = [];
|
|
2186
|
+
const visit = (dir, by, range) => {
|
|
2187
|
+
const manifest = readManifest(dir);
|
|
2188
|
+
if (!manifest?.name) return;
|
|
2189
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
2190
|
+
const realDir = real(dir);
|
|
2191
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
2192
|
+
if (expanded.has(realDir)) return;
|
|
2193
|
+
expanded.add(realDir);
|
|
2194
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
2195
|
+
};
|
|
2196
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
2197
|
+
while (queue.length) {
|
|
2198
|
+
const { real: from, manifest, label } = queue.shift();
|
|
2199
|
+
const deps = { ...manifest.peerDependencies, ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
2200
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
2201
|
+
const dir = findPackageDir(from, name);
|
|
2202
|
+
if (dir) visit(dir, label, range);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
};
|
|
2206
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
2207
|
+
const dir = findPackageDir(root, name);
|
|
2208
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
2209
|
+
});
|
|
2210
|
+
const app = readManifest(root);
|
|
2211
|
+
let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
2212
|
+
let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
|
|
2213
|
+
if (Object.keys(runtimeDeps).length === 0) {
|
|
2214
|
+
runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
|
|
2215
|
+
devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
|
|
2216
|
+
}
|
|
2217
|
+
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
2218
|
+
const top = path14.join(root, "node_modules");
|
|
2219
|
+
walk(
|
|
2220
|
+
"hoisted",
|
|
2221
|
+
packagesIn(top).filter((dir) => {
|
|
2222
|
+
const name = path14.relative(top, dir).split(path14.sep).join("/");
|
|
2223
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
2224
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
2225
|
+
);
|
|
2226
|
+
const devRoots = { ...devDeps };
|
|
2227
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots)) devRoots[tool] = runtimeDeps[tool];
|
|
2228
|
+
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
2229
|
+
for (const [key2, copy] of copies) {
|
|
2230
|
+
const kinds = via.get(key2);
|
|
2231
|
+
copy.runtime = kinds.has("runtime");
|
|
2232
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
2233
|
+
}
|
|
2234
|
+
const byName = /* @__PURE__ */ new Map();
|
|
2235
|
+
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
2236
|
+
for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
|
|
2237
|
+
return byName;
|
|
2238
|
+
}
|
|
2239
|
+
function checkDuplicatePackages(ctx) {
|
|
2240
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
2241
|
+
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
2242
|
+
if (copies.length < 2) continue;
|
|
2243
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
2244
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
2245
|
+
ctx.report({
|
|
2246
|
+
rule: "duplicate-genesis-package",
|
|
2247
|
+
level: "warn",
|
|
2248
|
+
file: "package.json",
|
|
2249
|
+
subject: name,
|
|
2250
|
+
message: `${name} is installed ${copies.length} times: ${copies.map((c) => `${describe(c)}${c.devOnly ? " [dev only]" : ""}`).join(", ")}. Each copy is its own module, so a provider from one (DataProvider, the shell's contexts) is invisible to hooks from another. Align the ranges so one copy satisfies them all, or add an override/resolution`
|
|
2251
|
+
});
|
|
2252
|
+
continue;
|
|
2253
|
+
}
|
|
2254
|
+
ctx.report({
|
|
2255
|
+
rule: "duplicate-genesis-package",
|
|
2256
|
+
level: "info",
|
|
2257
|
+
file: "package.json",
|
|
2258
|
+
subject: name,
|
|
2259
|
+
message: `${name} has dev-only copies beside the one the app loads: ${copies.filter((c) => c.devOnly).map(describe).join(", ")}. They run in tooling, not the app, so they can't split its contexts; upgrade the tool to drop them`
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
function checkPeerRanges(ctx) {
|
|
2264
|
+
const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
|
|
2265
|
+
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
2266
|
+
for (const copy of copies) {
|
|
2267
|
+
const dir = copy.absolutePath;
|
|
2268
|
+
const peers = readManifest(dir)?.peerDependencies ?? {};
|
|
2269
|
+
for (const [peer, range] of Object.entries(peers)) {
|
|
2270
|
+
if (!GENESIS.test(peer)) continue;
|
|
2271
|
+
const peerDir = findPackageDir(dir, peer);
|
|
2272
|
+
const installed = peerDir && readManifest(peerDir)?.version;
|
|
2273
|
+
if (!peerDir || !installed) continue;
|
|
2274
|
+
if (satisfies(installed, range) !== false) continue;
|
|
2275
|
+
ctx.report({
|
|
2276
|
+
rule: "peer-range-mismatch",
|
|
2277
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
2278
|
+
level: copy.devOnly ? "info" : "warn",
|
|
2279
|
+
file: "package.json",
|
|
2280
|
+
subject: `${copy.name}>${peer}`,
|
|
2281
|
+
message: `${copy.name}@${copy.version} (${copy.dir}) wants ${peer} ${range}, but ${installed} is installed (${rel(peerDir)}). Install a ${peer} in that range, or a ${copy.name} release built against ${installed}`
|
|
2282
|
+
});
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
var TRAIL_DEPTH = 6;
|
|
2288
|
+
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
2289
|
+
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
2290
|
+
var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
2291
|
+
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
2292
|
+
function stripForImports(code) {
|
|
2293
|
+
const out = [];
|
|
2294
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
2295
|
+
const n = code.length;
|
|
2296
|
+
const templates = [];
|
|
2297
|
+
let depth = 0;
|
|
2298
|
+
let i = 0;
|
|
2299
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
2300
|
+
const opensString = () => {
|
|
2301
|
+
const before = out.slice(-12).join("");
|
|
2302
|
+
if (!/[\w$]$/.test(before)) return true;
|
|
2303
|
+
return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
|
|
2304
|
+
};
|
|
2305
|
+
const templateBody = () => {
|
|
2306
|
+
while (i < n) {
|
|
2307
|
+
const ch = code[i];
|
|
2308
|
+
if (ch === "\\") {
|
|
2309
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2310
|
+
i += 2;
|
|
2311
|
+
} else if (ch === "`") {
|
|
2312
|
+
out.push("`");
|
|
2313
|
+
i++;
|
|
2314
|
+
return;
|
|
2315
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
2316
|
+
out.push("${");
|
|
2317
|
+
i += 2;
|
|
2318
|
+
templates.push(depth);
|
|
2319
|
+
depth++;
|
|
2320
|
+
return;
|
|
2321
|
+
} else {
|
|
2322
|
+
out.push(blank(ch));
|
|
2323
|
+
i++;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
while (i < n) {
|
|
2328
|
+
const ch = code[i];
|
|
2329
|
+
const next = code[i + 1];
|
|
2330
|
+
if (ch === "/" && next === "/") {
|
|
2331
|
+
while (i < n && code[i] !== "\n") {
|
|
2332
|
+
out.push(" ");
|
|
2333
|
+
i++;
|
|
2334
|
+
}
|
|
2335
|
+
} else if (ch === "/" && next === "*") {
|
|
2336
|
+
out.push(" ");
|
|
2337
|
+
i += 2;
|
|
2338
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
2339
|
+
out.push(blank(code[i]));
|
|
2340
|
+
i++;
|
|
2341
|
+
}
|
|
2342
|
+
if (i < n) {
|
|
2343
|
+
out.push(" ");
|
|
2344
|
+
i += 2;
|
|
2345
|
+
}
|
|
2346
|
+
} else if ((ch === '"' || ch === "'") && opensString()) {
|
|
2347
|
+
const keep = isSpecifier();
|
|
2348
|
+
out.push(ch);
|
|
2349
|
+
i++;
|
|
2350
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
2351
|
+
if (code[i] === "\\") {
|
|
2352
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
2353
|
+
i += 2;
|
|
2354
|
+
} else {
|
|
2355
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
2356
|
+
i++;
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
if (i < n) {
|
|
2360
|
+
out.push(code[i]);
|
|
2361
|
+
i++;
|
|
2362
|
+
}
|
|
2363
|
+
} else if (ch === "`") {
|
|
2364
|
+
out.push("`");
|
|
2365
|
+
i++;
|
|
2366
|
+
templateBody();
|
|
2367
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
2368
|
+
templates.pop();
|
|
2369
|
+
depth--;
|
|
2370
|
+
out.push("}");
|
|
2371
|
+
i++;
|
|
2372
|
+
templateBody();
|
|
2373
|
+
} else {
|
|
2374
|
+
if (ch === "{") depth++;
|
|
2375
|
+
else if (ch === "}") depth--;
|
|
2376
|
+
out.push(ch);
|
|
2377
|
+
i++;
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
return out.join("");
|
|
2381
|
+
}
|
|
2382
|
+
function bindings(clause) {
|
|
2383
|
+
const out = [];
|
|
2384
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
2385
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
2386
|
+
const p = part.trim();
|
|
2387
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2388
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
2389
|
+
}
|
|
2390
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
2391
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
2392
|
+
if (ns) out.push(ns[1]);
|
|
2393
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
2394
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
2395
|
+
return out;
|
|
2396
|
+
}
|
|
2397
|
+
function readJsonc(file) {
|
|
2398
|
+
try {
|
|
2399
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
2400
|
+
return JSON.parse(text);
|
|
2401
|
+
} catch {
|
|
2402
|
+
return null;
|
|
2403
|
+
}
|
|
2404
|
+
}
|
|
2405
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
2406
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
2407
|
+
seen.add(file);
|
|
2408
|
+
const json = readJsonc(file);
|
|
2409
|
+
if (!json) return {};
|
|
2410
|
+
const dir = path14.dirname(file);
|
|
2411
|
+
let merged = {};
|
|
2412
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2413
|
+
for (const ext of parents) {
|
|
2414
|
+
if (typeof ext !== "string") continue;
|
|
2415
|
+
let target = null;
|
|
2416
|
+
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
2417
|
+
const abs = path14.resolve(dir, ext);
|
|
2418
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2419
|
+
} else {
|
|
2420
|
+
const parts = ext.split("/");
|
|
2421
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
2422
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2423
|
+
if (pkgDir) {
|
|
2424
|
+
const sub = parts.slice(nameLength).join("/");
|
|
2425
|
+
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
2426
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2430
|
+
}
|
|
2431
|
+
const opts = json.compilerOptions ?? {};
|
|
2432
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
2433
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
2434
|
+
merged.paths = opts.paths;
|
|
2435
|
+
merged.pathsDir = dir;
|
|
2436
|
+
}
|
|
2437
|
+
return merged;
|
|
2438
|
+
}
|
|
2439
|
+
function aliases(root) {
|
|
2440
|
+
const table = [];
|
|
2441
|
+
let baseUrl = null;
|
|
2442
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2443
|
+
const file = path14.join(root, name);
|
|
2444
|
+
if (!existsSync(file)) continue;
|
|
2445
|
+
const config = readTsconfig(root, file);
|
|
2446
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
2447
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
2448
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2449
|
+
if (!Array.isArray(targets)) continue;
|
|
2450
|
+
const exact = !pattern.endsWith("*");
|
|
2451
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
2455
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2456
|
+
if (typeof target !== "string") continue;
|
|
2457
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
2458
|
+
}
|
|
2459
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
|
|
2460
|
+
return { table, baseUrl };
|
|
2461
|
+
}
|
|
2462
|
+
function resolveFile(base) {
|
|
2463
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
|
|
2464
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2465
|
+
for (const p of tries) {
|
|
2466
|
+
if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2467
|
+
}
|
|
2468
|
+
return null;
|
|
2469
|
+
}
|
|
2470
|
+
var trails = /* @__PURE__ */ new WeakMap();
|
|
2471
|
+
function trailFor(ctx) {
|
|
2472
|
+
let t = trails.get(ctx.files);
|
|
2473
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
2474
|
+
return t;
|
|
2475
|
+
}
|
|
2476
|
+
function createTrail(ctx) {
|
|
2477
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
2478
|
+
let declared = null;
|
|
2479
|
+
try {
|
|
2480
|
+
const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
|
|
2481
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
2482
|
+
} catch {
|
|
2483
|
+
declared = null;
|
|
2484
|
+
}
|
|
2485
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2486
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
2487
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
2488
|
+
const importsOf = (file) => {
|
|
2489
|
+
const hit = importsCache.get(file.absolutePath);
|
|
2490
|
+
if (hit) return hit;
|
|
2491
|
+
const files = [];
|
|
2492
|
+
let lost = false;
|
|
2493
|
+
const code = stripped(file);
|
|
2494
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
2495
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2496
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2497
|
+
for (const m of code.matchAll(/\bexport\s*\{([^}]*)\}\s*;/g)) for (const n of m[1].split(",")) used.add(n.trim().split(/\s+as\s+/)[0]);
|
|
2498
|
+
const specs = [];
|
|
2499
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
2500
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
2501
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
2502
|
+
for (const spec of specs) {
|
|
2503
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
2504
|
+
let resolved = null;
|
|
2505
|
+
if (spec.startsWith(".")) {
|
|
2506
|
+
resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
|
|
2507
|
+
if (!resolved) lost = true;
|
|
2508
|
+
} else {
|
|
2509
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
2510
|
+
if (alias) {
|
|
2511
|
+
for (const t of alias.targets) {
|
|
2512
|
+
resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
|
|
2513
|
+
if (resolved) break;
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
|
|
2517
|
+
if (!resolved) {
|
|
2518
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
2519
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
2523
|
+
}
|
|
2524
|
+
const out = { files, lost };
|
|
2525
|
+
importsCache.set(file.absolutePath, out);
|
|
2526
|
+
return out;
|
|
2527
|
+
};
|
|
2528
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
2529
|
+
const stripped = (file) => {
|
|
2530
|
+
let c = strippedCache.get(file.absolutePath);
|
|
2531
|
+
if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
|
|
2532
|
+
return c;
|
|
2533
|
+
};
|
|
2534
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
2535
|
+
const reach = (file, test2, depth, seen) => {
|
|
2536
|
+
let cache = memo.get(test2);
|
|
2537
|
+
if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
|
|
2538
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
2539
|
+
const cached = cache.get(k);
|
|
2540
|
+
if (cached) return [cached, false];
|
|
2541
|
+
let result;
|
|
2542
|
+
let cut = false;
|
|
2543
|
+
if (test2(stripped(file))) result = "yes";
|
|
2544
|
+
else {
|
|
2545
|
+
const { files, lost } = importsOf(file);
|
|
2546
|
+
let unknown = lost && depth > 0;
|
|
2547
|
+
result = "no";
|
|
2548
|
+
if (depth > 0) {
|
|
2549
|
+
seen.add(file.absolutePath);
|
|
2550
|
+
for (const abs of files) {
|
|
2551
|
+
if (seen.has(abs)) {
|
|
2552
|
+
cut = true;
|
|
2553
|
+
continue;
|
|
2554
|
+
}
|
|
2555
|
+
const target = read(abs);
|
|
2556
|
+
if (!target) {
|
|
2557
|
+
unknown = true;
|
|
2558
|
+
continue;
|
|
2559
|
+
}
|
|
2560
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
2561
|
+
if (c) cut = true;
|
|
2562
|
+
if (r === "yes") {
|
|
2563
|
+
result = "yes";
|
|
2564
|
+
break;
|
|
2565
|
+
}
|
|
2566
|
+
if (r === "unknown") unknown = true;
|
|
2567
|
+
}
|
|
2568
|
+
seen.delete(file.absolutePath);
|
|
2569
|
+
}
|
|
2570
|
+
if (result === "no" && unknown) result = "unknown";
|
|
2571
|
+
}
|
|
2572
|
+
if (result === "yes" || !cut) cache.set(k, result);
|
|
2573
|
+
return [result, cut && result !== "yes"];
|
|
2574
|
+
};
|
|
2575
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
// src/doctor/routes.ts
|
|
2579
|
+
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
2580
|
+
var STEMS = {
|
|
2581
|
+
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
2582
|
+
"next-app": {
|
|
2583
|
+
layout: /* @__PURE__ */ new Set(["layout"]),
|
|
2584
|
+
index: /* @__PURE__ */ new Set(["page"]),
|
|
2585
|
+
skip: /^(?:error|global-error|loading|not-found|forbidden|unauthorized|template|default|route|middleware|instrumentation|opengraph-image|twitter-image|icon|apple-icon|sitemap|robots|manifest)$/
|
|
2586
|
+
},
|
|
2587
|
+
"next-pages": { layout: /* @__PURE__ */ new Set(["_app"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^(?:_document|_error|404|500)$/ }
|
|
2588
|
+
};
|
|
2589
|
+
var NON_PAGE_ELEMENTS = /* @__PURE__ */ new Set(["Navigate", "Redirect", "Outlet", "Fragment", "React.Fragment"]);
|
|
2590
|
+
var HTML_ELEMENT = /(?<![\w$.])<(?:[a-z][\w-]*(?=[\s>/])|>)/;
|
|
2591
|
+
var COMPONENT_OPTION = /\bcomponent\s*:\s*(?!undefined\b|null\b)([A-Za-z_$][\w$]*)/;
|
|
2592
|
+
var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
2593
|
+
var OWN_CONTENT = /(?<![=-])>\s*[A-Za-z][^<>{}]*</.source + "|" + /(?<![\w$.])<(?:h[1-6]|ul|ol|table|dl|H[1-6]|[A-Z]\w*(?:Heading|Title|Table|List|Grid))(?=[\s>/])/.source;
|
|
2594
|
+
function routesDir(ctx) {
|
|
2595
|
+
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
2596
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path14.join(ctx.root, d))) ?? null;
|
|
2597
|
+
}
|
|
2598
|
+
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
2599
|
+
function flavorOf(dir, rels) {
|
|
2600
|
+
const stems = rels.map((r) => r.split("/").pop());
|
|
2601
|
+
if (stems.includes("__root")) return "tanstack";
|
|
2602
|
+
if (stems.some((s) => s === "page" || s === "layout")) return "next-app";
|
|
2603
|
+
if (/(?:^|\/)pages$/.test(dir) && stems.some((s) => s === "_app" || s === "_document")) return "next-pages";
|
|
2604
|
+
return "tanstack";
|
|
2605
|
+
}
|
|
2606
|
+
function renders(code) {
|
|
2607
|
+
const elements = renderedElements(code);
|
|
2608
|
+
if (elements.some((e) => !NON_PAGE_ELEMENTS.has(e)) || HTML_ELEMENT.test(code)) return true;
|
|
2609
|
+
const definedHere = (name) => new RegExp(`\\b(?:function|const|let|var|class)\\s+${name.replace(/\$/g, "\\$")}\\b`).test(code);
|
|
2610
|
+
const named = COMPONENT_OPTION.exec(code)?.[1];
|
|
2611
|
+
if (named && !definedHere(named)) return true;
|
|
2612
|
+
if (/\bexport\s*\{\s*default\b[^}]*\}\s*from\b/.test(code)) return true;
|
|
2613
|
+
const exported = /\bexport\s+default\s+([A-Z][\w$]*)\s*;?\s*$/m.exec(code)?.[1];
|
|
2614
|
+
return exported !== void 0 && !definedHere(exported);
|
|
2615
|
+
}
|
|
2616
|
+
function webRoutes(ctx) {
|
|
2617
|
+
const dir = routesDir(ctx);
|
|
2618
|
+
if (!dir) return [];
|
|
2619
|
+
const candidates = ctx.files.filter((f) => JSX_EXTS2.has(f.ext) && f.path.startsWith(`${dir}/`)).map((file) => ({ file, rel: file.path.slice(dir.length + 1).replace(/\.[^.]+$/, "") }));
|
|
2620
|
+
const flavor = flavorOf(dir, candidates.map((c) => c.rel));
|
|
2621
|
+
const stems = STEMS[flavor];
|
|
2622
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2623
|
+
for (const { file, rel } of candidates) {
|
|
2624
|
+
const parts = rel.split("/");
|
|
2625
|
+
if (parts.some((p) => p.startsWith("-"))) continue;
|
|
2626
|
+
if (flavor !== "tanstack" && parts.slice(0, -1).some((p) => p.startsWith("_"))) continue;
|
|
2627
|
+
if (flavor === "next-pages" && parts[0] === "api") continue;
|
|
2628
|
+
if (stems.skip.test(parts.at(-1))) continue;
|
|
2629
|
+
if (flavor === "next-app" && !stems.layout.has(parts.at(-1)) && !stems.index.has(parts.at(-1))) continue;
|
|
2630
|
+
const id = flavor === "tanstack" ? rel.replace(/\.lazy$/, "") : rel;
|
|
2631
|
+
groups.set(id, [...groups.get(id) ?? [], file]);
|
|
2632
|
+
}
|
|
2633
|
+
const trail = trailFor(ctx);
|
|
2634
|
+
const routes = [];
|
|
2635
|
+
for (const [id, files] of groups) {
|
|
2636
|
+
const parts = id.split("/");
|
|
2637
|
+
const stem = parts.pop();
|
|
2638
|
+
const folders = flavor === "next-app" ? parts.map((p) => p.replace(/^\((?:\.{1,3}|\.\.\)\(\.\.)\)(?=.)/, "")).filter((p) => !/^\(.*\)$/.test(p) && !p.startsWith("@")) : parts;
|
|
2639
|
+
const named = stems.layout.has(stem) || stems.index.has(stem);
|
|
2640
|
+
const own = named ? [] : flavor === "tanstack" ? stem.split(".") : [stem];
|
|
2641
|
+
const segments = [...folders, ...own];
|
|
2642
|
+
const tree = [...parts, ...own];
|
|
2643
|
+
let index = stems.index.has(stem);
|
|
2644
|
+
if (!index && !stems.layout.has(stem) && flavor === "tanstack" && stems.index.has(segments.at(-1) ?? "")) {
|
|
2645
|
+
segments.pop();
|
|
2646
|
+
tree.pop();
|
|
2647
|
+
index = true;
|
|
2648
|
+
}
|
|
2649
|
+
const code = files.map((f) => f.code).join("\n");
|
|
2650
|
+
const elements = renderedElements(code);
|
|
2651
|
+
const pathless = flavor === "tanstack" && !index && /^_(?!_)/.test(tree.at(-1) ?? "");
|
|
2652
|
+
const outlet = elements.includes("Outlet") || !stems.index.has(stem) && files.some((f) => trail.reach(f, RENDERS_OUTLET, 2) === "yes");
|
|
2653
|
+
const layout = stems.layout.has(stem) || pathless || outlet;
|
|
2654
|
+
const rendering = renders(code);
|
|
2655
|
+
const ownContent = new RegExp(OWN_CONTENT).test(code);
|
|
2656
|
+
const pure = stem === "__root" || flavor !== "tanstack" && stems.layout.has(stem);
|
|
2657
|
+
const page = !pure && !pathless && (!layout || ownContent);
|
|
2658
|
+
routes.push({
|
|
2659
|
+
file: files.find((f) => /\.lazy\.[^.]+$/.test(f.path)) ?? files[0],
|
|
2660
|
+
files,
|
|
2661
|
+
segments,
|
|
2662
|
+
tree,
|
|
2663
|
+
index,
|
|
2664
|
+
layout,
|
|
2665
|
+
page,
|
|
2666
|
+
detail: page && !index && /^(?:\$|\[)/.test(segments.at(-1) ?? ""),
|
|
2667
|
+
redirectOnly: !rendering,
|
|
2668
|
+
parents: []
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
for (const r of routes) {
|
|
2672
|
+
const own = r.tree;
|
|
2673
|
+
for (const p of routes) {
|
|
2674
|
+
if (p === r || !p.layout) continue;
|
|
2675
|
+
const n = p.tree.length;
|
|
2676
|
+
if (n > own.length || n === own.length && !(r.index && !r.layout)) continue;
|
|
2677
|
+
if (key(own.slice(0, n)) !== key(p.tree)) continue;
|
|
2678
|
+
if (n > 0 && own[n - 1].endsWith("_") && !p.tree[n - 1].endsWith("_")) continue;
|
|
2679
|
+
r.parents.push(p);
|
|
2680
|
+
}
|
|
2681
|
+
r.parents.sort((a, b) => b.tree.length - a.tree.length);
|
|
2682
|
+
}
|
|
2683
|
+
return routes;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
// src/doctor/structure.ts
|
|
2687
|
+
var SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/ui/SKILL.md (Sub-navigation)";
|
|
2688
|
+
var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
|
|
2689
|
+
var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
2690
|
+
var SHELL = /<AppShell(?=[\s>/])/;
|
|
2691
|
+
var GENESIS_PACKAGE = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
2692
|
+
var PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
|
|
2693
|
+
var PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
|
|
2694
|
+
var isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
2695
|
+
var rendersRe = (names) => {
|
|
2696
|
+
const list = [...names];
|
|
2697
|
+
return list.length ? new RegExp(`<(?:${list.map((n) => n.replace(/[.$]/g, "\\$&")).join("|")})(?=[\\s>/])`) : null;
|
|
2698
|
+
};
|
|
2699
|
+
function routeReach(ctx, r, test2) {
|
|
2700
|
+
const trail = trailFor(ctx);
|
|
2701
|
+
let unknown = false;
|
|
2702
|
+
for (const f of r.files) {
|
|
2703
|
+
const got = trail.reach(f, test2);
|
|
2704
|
+
if (got === "yes") return "yes";
|
|
2705
|
+
if (got === "unknown") unknown = true;
|
|
2706
|
+
}
|
|
2707
|
+
return unknown ? "unknown" : "no";
|
|
2708
|
+
}
|
|
2709
|
+
var routeVia = (ctx, r, test2) => routeReach(ctx, r, test2) === "yes";
|
|
2710
|
+
function insideShell(ctx, routes) {
|
|
2711
|
+
const shell = new Set(routes.filter((r) => routeVia(ctx, r, (code) => SHELL.test(code))));
|
|
2712
|
+
const anyShell = shell.size === 0 && ctx.files.some((f) => SHELL.test(f.code));
|
|
2713
|
+
return (r) => !shell.has(r) && (anyShell || r.parents.some((p) => shell.has(p)));
|
|
2714
|
+
}
|
|
2715
|
+
function checkHandRolledSubNav(ctx) {
|
|
2716
|
+
if (isNative(ctx) || !ctx.genesis.values.has("useAppShellSubNav")) return;
|
|
2717
|
+
const routes = webRoutes(ctx);
|
|
2718
|
+
if (routes.length === 0) return;
|
|
2719
|
+
const inShell = insideShell(ctx, routes);
|
|
2720
|
+
const ui = ctx.genesis.uiPackage;
|
|
2721
|
+
for (const r of routes) {
|
|
2722
|
+
if (!inShell(r) || r.files.some((f) => /\buseAppShellSubNav\s*\(/.test(f.code))) continue;
|
|
2723
|
+
const hit = r.files.flatMap((f) => [...f.code.matchAll(SWITCHER)].map((m) => ({ f, m }))).find(({ f, m }) => openElementsAt(f.code, m.index, (n) => CONTAINER.test(n)).length === 0);
|
|
2724
|
+
if (hit) {
|
|
2725
|
+
const { f, m } = hit;
|
|
2726
|
+
const code = f.code;
|
|
2727
|
+
ctx.report({
|
|
2728
|
+
rule: "hand-rolled-sub-nav",
|
|
2729
|
+
level: "warn",
|
|
2730
|
+
file: f.path,
|
|
2731
|
+
line: lineAt(code, m.index),
|
|
2732
|
+
subject: m[1],
|
|
2733
|
+
message: `switches the page's sections with its own <${m[1]}>; hand them to the shell with useAppShellSubNav(items, { mode: "tabs" }) and put the header in AppShellPageHeader (chips in AppShellSubNavEnd), from ${ui}/layout, so the sections are the shell's tab row and the phone's bottom bar. See ${SUB_NAV_DOCS}`
|
|
2734
|
+
});
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
function checkLocalGenesisCopies(ctx) {
|
|
2739
|
+
const owner = /* @__PURE__ */ new Map();
|
|
2740
|
+
for (const c of ctx.genesis.companions) for (const name of c.components) owner.set(name, c.package);
|
|
2741
|
+
for (const name of ctx.genesis.components) owner.set(name, ctx.genesis.uiPackage);
|
|
2742
|
+
if (owner.size === 0) return;
|
|
2743
|
+
const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
|
|
2744
|
+
const routes = routesDir(ctx);
|
|
2745
|
+
for (const file of ctx.files) {
|
|
2746
|
+
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
2747
|
+
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE));
|
|
2748
|
+
const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
|
|
2749
|
+
const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
|
|
2750
|
+
const decls = [...file.code.matchAll(decl)];
|
|
2751
|
+
decls.forEach((m, i) => {
|
|
2752
|
+
const [, exported, name] = m;
|
|
2753
|
+
const pkg = owner.get(name);
|
|
2754
|
+
if (!pkg || imported.has(name) || routeComponents.has(name)) return;
|
|
2755
|
+
if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
|
|
2756
|
+
const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
|
|
2757
|
+
if (!rendersJsx(body)) return;
|
|
2758
|
+
if (exported && pkg === ctx.genesis.uiPackage && ctx.genesis.values.has(name)) return;
|
|
2759
|
+
const init = file.code.slice(m.index + m[0].length, m.index + m[0].length + 400).split(";")[0];
|
|
2760
|
+
if (/["']@marktiderman\/genesis/.test(init)) return;
|
|
2761
|
+
ctx.report({
|
|
2762
|
+
rule: "local-genesis-copy",
|
|
2763
|
+
level: "warn",
|
|
2764
|
+
file: file.path,
|
|
2765
|
+
line: lineAt(file.code, m.index),
|
|
2766
|
+
subject: name,
|
|
2767
|
+
message: `defines its own ${name}; Genesis already has ${name} (${pkg}). Use it, or extend it upstream`
|
|
2768
|
+
});
|
|
2769
|
+
});
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
function checkResourceWorkspaces(ctx) {
|
|
2773
|
+
if (isNative(ctx) || !ctx.genesis.values.has("AppShellPageHeader")) return;
|
|
2774
|
+
const header = /<AppShellPageHeader(?=[\s>/])/;
|
|
2775
|
+
const byFolder = /* @__PURE__ */ new Map();
|
|
2776
|
+
for (const r of webRoutes(ctx)) {
|
|
2777
|
+
if (!r.detail || r.redirectOnly) continue;
|
|
2778
|
+
const dir = r.file.path.slice(0, r.file.path.lastIndexOf("/"));
|
|
2779
|
+
byFolder.set(dir, [...byFolder.get(dir) ?? [], r]);
|
|
2780
|
+
}
|
|
2781
|
+
for (const [dir, routes] of byFolder) {
|
|
2782
|
+
const reach = new Map(routes.map((r) => [r, routeReach(ctx, r, (code) => header.test(code))]));
|
|
2783
|
+
const has = routes.filter((r) => reach.get(r) === "yes");
|
|
2784
|
+
if (has.length === 0) continue;
|
|
2785
|
+
const ref = has.map((r) => r.file.path.slice(dir.length + 1)).join(", ");
|
|
2786
|
+
for (const r of routes) {
|
|
2787
|
+
if (reach.get(r) !== "no") continue;
|
|
2788
|
+
ctx.report({
|
|
2789
|
+
rule: "resource-workspace",
|
|
2790
|
+
level: "info",
|
|
2791
|
+
file: r.file.path,
|
|
2792
|
+
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`
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
function checkPageLayouts(ctx) {
|
|
2798
|
+
if (isNative(ctx)) return;
|
|
2799
|
+
const layouts = new Set(ctx.genesis.components.filter((n) => PAGE_LAYOUT.test(n)));
|
|
2800
|
+
for (const c of ctx.genesis.companions) for (const n of c.components) if (PAGE_LAYOUT.test(n)) layouts.add(n);
|
|
2801
|
+
if (layouts.size === 0) return;
|
|
2802
|
+
const routes = webRoutes(ctx);
|
|
2803
|
+
const inShell = insideShell(ctx, routes);
|
|
2804
|
+
const rendersLayout = (code) => {
|
|
2805
|
+
const names = new Set(layouts);
|
|
2806
|
+
for (const n of namedImportsFrom(code, GENESIS_PACKAGE)) if (PACKAGE_SCREEN.test(n)) names.add(n);
|
|
2807
|
+
return rendersRe(names)?.test(code) ?? false;
|
|
2808
|
+
};
|
|
2809
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2810
|
+
const provides = (r) => {
|
|
2811
|
+
if (!cache.has(r)) cache.set(r, routeReach(ctx, r, rendersLayout));
|
|
2812
|
+
return cache.get(r);
|
|
2813
|
+
};
|
|
2814
|
+
const list = [...layouts].sort();
|
|
2815
|
+
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
2816
|
+
for (const r of routes) {
|
|
2817
|
+
if (!r.page || r.redirectOnly || !inShell(r)) continue;
|
|
2818
|
+
if (provides(r) !== "no" || r.parents.some((p) => provides(p) !== "no")) continue;
|
|
2819
|
+
ctx.report({
|
|
2820
|
+
rule: "page-layout",
|
|
2821
|
+
level: "warn",
|
|
2822
|
+
file: r.file.path,
|
|
2823
|
+
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`
|
|
2824
|
+
});
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
// src/doctor/dates.ts
|
|
2829
|
+
var SCRIPT_EXTS4 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
2830
|
+
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;
|
|
2831
|
+
function checkIsoDateSlices(ctx) {
|
|
2832
|
+
for (const file of ctx.files) {
|
|
2833
|
+
if (!SCRIPT_EXTS4.has(file.ext) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(file.path)) continue;
|
|
2834
|
+
for (const m of file.code.matchAll(ISO_DAY_CUT)) {
|
|
2835
|
+
ctx.report({
|
|
2836
|
+
rule: "iso-date-slice",
|
|
2837
|
+
level: "warn",
|
|
2838
|
+
file: file.path,
|
|
2839
|
+
line: lineAt(file.code, m.index ?? 0),
|
|
2840
|
+
subject: "toISOString",
|
|
2841
|
+
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)"
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
|
|
1911
2847
|
// src/doctor/index.ts
|
|
1912
2848
|
async function runDoctor(options = {}) {
|
|
1913
|
-
const root =
|
|
2849
|
+
const root = path14.resolve(options.root ?? process.cwd());
|
|
1914
2850
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
1915
2851
|
const config = loaded.config;
|
|
1916
2852
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -1923,18 +2859,7 @@ async function runDoctor(options = {}) {
|
|
|
1923
2859
|
}
|
|
1924
2860
|
const raw = [];
|
|
1925
2861
|
const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
|
|
1926
|
-
const
|
|
1927
|
-
{ name: "layout", check: checkProjectLayout },
|
|
1928
|
-
{ name: "imports", check: checkImports },
|
|
1929
|
-
{ name: "raw-tags", check: checkRawTags },
|
|
1930
|
-
{ name: "colors", check: checkColors },
|
|
1931
|
-
{ name: "tokens", check: checkTokens },
|
|
1932
|
-
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
1933
|
-
{ name: "version-skew", check: checkVersionSkew },
|
|
1934
|
-
...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
|
|
1935
|
-
...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
|
|
1936
|
-
];
|
|
1937
|
-
for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
2862
|
+
for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
1938
2863
|
try {
|
|
1939
2864
|
await plugin.check(ctx);
|
|
1940
2865
|
} catch (err) {
|
|
@@ -1948,7 +2873,8 @@ async function runDoctor(options = {}) {
|
|
|
1948
2873
|
}
|
|
1949
2874
|
const findings = applyConfig(raw, config);
|
|
1950
2875
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
1951
|
-
const warnings = findings.
|
|
2876
|
+
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
2877
|
+
const infos = findings.length - errors - warnings;
|
|
1952
2878
|
return {
|
|
1953
2879
|
ok: errors === 0 && !(options.strict && warnings > 0),
|
|
1954
2880
|
root,
|
|
@@ -1957,8 +2883,32 @@ async function runDoctor(options = {}) {
|
|
|
1957
2883
|
unused: unusedComponents(ctx),
|
|
1958
2884
|
ruleCount: (patterns?.count ?? 0) + plugins.length,
|
|
1959
2885
|
errors,
|
|
1960
|
-
warnings
|
|
2886
|
+
warnings,
|
|
2887
|
+
infos
|
|
2888
|
+
};
|
|
2889
|
+
}
|
|
2890
|
+
function builtinChecks(config) {
|
|
2891
|
+
const packs = {
|
|
2892
|
+
native: { name: "native", check: checkNativePack },
|
|
2893
|
+
supabase: { name: "supabase", check: checkSupabasePack }
|
|
1961
2894
|
};
|
|
2895
|
+
return [
|
|
2896
|
+
{ name: "layout", check: checkProjectLayout },
|
|
2897
|
+
{ name: "imports", check: checkImports },
|
|
2898
|
+
{ name: "raw-tags", check: checkRawTags },
|
|
2899
|
+
{ name: "colors", check: checkColors },
|
|
2900
|
+
{ name: "tokens", check: checkTokens },
|
|
2901
|
+
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
2902
|
+
{ name: "version-skew", check: checkVersionSkew },
|
|
2903
|
+
{ name: "duplicate-packages", check: checkDuplicatePackages },
|
|
2904
|
+
{ name: "peer-ranges", check: checkPeerRanges },
|
|
2905
|
+
{ name: "hand-rolled-sub-nav", check: checkHandRolledSubNav },
|
|
2906
|
+
{ name: "local-genesis-copies", check: checkLocalGenesisCopies },
|
|
2907
|
+
{ name: "resource-workspaces", check: checkResourceWorkspaces },
|
|
2908
|
+
{ name: "page-layouts", check: checkPageLayouts },
|
|
2909
|
+
{ name: "iso-date-slices", check: checkIsoDateSlices },
|
|
2910
|
+
...(config.packs ?? []).map((p) => packs[p])
|
|
2911
|
+
];
|
|
1962
2912
|
}
|
|
1963
2913
|
function applyConfig(raw, config) {
|
|
1964
2914
|
const allow = (config.allow ?? []).map((entry) => ({ entry, file: entry.file ? globToRegExp(entry.file) : null, used: false }));
|
|
@@ -2006,7 +2956,8 @@ function formatReport(result) {
|
|
|
2006
2956
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
2007
2957
|
}
|
|
2008
2958
|
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
2009
|
-
|
|
2959
|
+
const info = result.infos ? `, ${result.infos} info` : "";
|
|
2960
|
+
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
2010
2961
|
return lines.join("\n");
|
|
2011
2962
|
}
|
|
2012
2963
|
function toJson(result) {
|
|
@@ -2015,6 +2966,7 @@ function toJson(result) {
|
|
|
2015
2966
|
genesis: `${result.genesis.uiPackage}@${result.genesis.uiVersion}`,
|
|
2016
2967
|
errors: result.errors,
|
|
2017
2968
|
warnings: result.warnings,
|
|
2969
|
+
infos: result.infos,
|
|
2018
2970
|
findings: result.findings,
|
|
2019
2971
|
unused: result.unused
|
|
2020
2972
|
};
|
|
@@ -2025,10 +2977,11 @@ function genesisSummary(g) {
|
|
|
2025
2977
|
components: g.components,
|
|
2026
2978
|
tokens: [...g.tokens].sort(),
|
|
2027
2979
|
rawTags: Object.fromEntries(g.rawTags),
|
|
2028
|
-
palette: g.palette
|
|
2980
|
+
palette: g.palette,
|
|
2981
|
+
companions: Object.fromEntries(g.companions.map((c) => [`${c.package}@${c.version}`, c.components]))
|
|
2029
2982
|
};
|
|
2030
2983
|
}
|
|
2031
2984
|
|
|
2032
|
-
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, nativeLayouts, parseExportNames, parseRulesMarkdown, readGenesisConfig, readPackageExports, readReleaseManifest, runDoctor, sqlStatements, toJson, validateConfig, validateLinks };
|
|
2985
|
+
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, builtinChecks, defineDoctorPlugin, findPackageDir, formatReport, genesisInstalls, genesisSummary, globToRegExp, loadConfig, loadGenesis, nativeLayouts, parseExportNames, parseRulesMarkdown, readGenesisConfig, readPackageExports, readReleaseManifest, routesDir, runDoctor, satisfies, sqlStatements, toJson, validateConfig, validateLinks, webRoutes };
|
|
2033
2986
|
//# sourceMappingURL=doctor.js.map
|
|
2034
2987
|
//# sourceMappingURL=doctor.js.map
|