@marktiderman/genesis-cli 1.21.0 → 1.22.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 +140 -9
- package/dist/cli.js +1025 -101
- package/dist/cli.js.map +1 -1
- package/dist/{config-Dj_f9T7J.d.ts → config-HOmiOLQc.d.ts} +2 -0
- package/dist/doctor.d.ts +10 -5
- package/dist/doctor.js +1501 -1115
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +10 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +69 -18
- package/dist/index.d.ts +114 -2
- package/dist/index.js +1524 -1119
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +4 -4
- package/dist/starter/__tests__/starter.test.ts +9 -0
- package/dist/starter/pnpm-workspace.yaml +22 -0
- package/dist/starter/src/lib/check-in.ts +5 -3
- package/dist/starter/src/lib/native-modules.ts +4 -1
- package/dist/starter/supabase/migrations/20261025000090_genesis_chat_attachment_paths.sql +80 -0
- package/dist/starter/supabase/tests/database/genesis_chat_attachment_paths.test.sql +111 -0
- package/dist/vite.js +1500 -1114
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/doctor.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as path21 from 'path';
|
|
2
2
|
import { spawnSync } from 'child_process';
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, statSync, realpathSync, mkdirSync, writeFileSync, lstatSync } from 'fs';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
|
+
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
5
6
|
import { createHash } from 'crypto';
|
|
6
7
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
7
8
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
8
|
-
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
9
9
|
import { createJiti } from 'jiti';
|
|
10
10
|
import 'os';
|
|
11
11
|
|
|
12
12
|
var __defProp = Object.defineProperty;
|
|
13
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __esm = (fn, res) => function __init() {
|
|
15
|
-
|
|
14
|
+
var __esm = (fn, res, err) => function __init() {
|
|
15
|
+
if (err) throw err[0];
|
|
16
|
+
try {
|
|
17
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw err = [e], e;
|
|
20
|
+
}
|
|
16
21
|
};
|
|
17
22
|
var __export = (target, all) => {
|
|
18
23
|
for (var name in all)
|
|
@@ -455,14 +460,14 @@ function inherit(own, source) {
|
|
|
455
460
|
}
|
|
456
461
|
function resolveViews(relations) {
|
|
457
462
|
const done = /* @__PURE__ */ new Set();
|
|
458
|
-
const
|
|
463
|
+
const resolve18 = (relation, depth) => {
|
|
459
464
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
460
465
|
done.add(relation.oid);
|
|
461
466
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
462
467
|
if (sources.size !== 1) return;
|
|
463
468
|
const source = relations.get([...sources][0]);
|
|
464
469
|
if (!source) return;
|
|
465
|
-
|
|
470
|
+
resolve18(source, depth + 1);
|
|
466
471
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
467
472
|
for (const [attnum, origin] of relation.origins) {
|
|
468
473
|
const own = relation.columns.get(attnum);
|
|
@@ -485,7 +490,7 @@ function resolveViews(relations) {
|
|
|
485
490
|
};
|
|
486
491
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
487
492
|
};
|
|
488
|
-
for (const relation of relations.values())
|
|
493
|
+
for (const relation of relations.values()) resolve18(relation, 0);
|
|
489
494
|
}
|
|
490
495
|
async function introspectPostgres(sql, schemas, options = {}) {
|
|
491
496
|
const relations = /* @__PURE__ */ new Map();
|
|
@@ -721,19 +726,19 @@ var init_introspect = __esm({
|
|
|
721
726
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
722
727
|
function buildCommands(root, config) {
|
|
723
728
|
if (config.build) return config.build;
|
|
724
|
-
const pkgFile =
|
|
729
|
+
const pkgFile = path21.join(root, "package.json");
|
|
725
730
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
726
731
|
const pm = packageManager(root);
|
|
727
732
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
728
733
|
}
|
|
729
734
|
function packageManager(root) {
|
|
730
|
-
let dir =
|
|
735
|
+
let dir = path21.resolve(root);
|
|
731
736
|
for (; ; ) {
|
|
732
|
-
if (existsSync(
|
|
733
|
-
if (existsSync(
|
|
734
|
-
if (existsSync(
|
|
735
|
-
if (existsSync(
|
|
736
|
-
const parent =
|
|
737
|
+
if (existsSync(path21.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
738
|
+
if (existsSync(path21.join(dir, "bun.lock")) || existsSync(path21.join(dir, "bun.lockb"))) return "bun";
|
|
739
|
+
if (existsSync(path21.join(dir, "yarn.lock"))) return "yarn";
|
|
740
|
+
if (existsSync(path21.join(dir, "package-lock.json"))) return "npm";
|
|
741
|
+
const parent = path21.dirname(dir);
|
|
737
742
|
if (parent === dir) return "npm";
|
|
738
743
|
dir = parent;
|
|
739
744
|
}
|
|
@@ -848,25 +853,25 @@ var PACK_KEYS = {
|
|
|
848
853
|
};
|
|
849
854
|
function appPath(v, where2, fail) {
|
|
850
855
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
851
|
-
if (
|
|
852
|
-
const norm =
|
|
856
|
+
if (path21.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
857
|
+
const norm = path21.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
853
858
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
854
859
|
return norm;
|
|
855
860
|
}
|
|
856
861
|
function loadConfig(root, configPath) {
|
|
857
862
|
if (configPath) {
|
|
858
|
-
const file =
|
|
863
|
+
const file = path21.resolve(root, configPath);
|
|
859
864
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
860
865
|
const json = readJson(file);
|
|
861
|
-
const block =
|
|
862
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
866
|
+
const block = path21.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
867
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path21.dirname(file) };
|
|
863
868
|
}
|
|
864
|
-
const own =
|
|
869
|
+
const own = path21.join(root, "genesis.config.json");
|
|
865
870
|
if (existsSync(own)) {
|
|
866
871
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
867
872
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
868
873
|
}
|
|
869
|
-
const pkg =
|
|
874
|
+
const pkg = path21.join(root, "package.json");
|
|
870
875
|
if (existsSync(pkg)) {
|
|
871
876
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
872
877
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -875,7 +880,7 @@ function loadConfig(root, configPath) {
|
|
|
875
880
|
}
|
|
876
881
|
function doctorBlock(json, file, explicit) {
|
|
877
882
|
const j = json;
|
|
878
|
-
if (
|
|
883
|
+
if (path21.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
879
884
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
880
885
|
}
|
|
881
886
|
function isPackageDeclaration(block) {
|
|
@@ -892,7 +897,7 @@ function readJson(file) {
|
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
899
|
function readGenesisConfig(root) {
|
|
895
|
-
const file =
|
|
900
|
+
const file = path21.join(root, "genesis.config.json");
|
|
896
901
|
if (!existsSync(file)) return null;
|
|
897
902
|
const raw = readJson(file);
|
|
898
903
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -903,8 +908,18 @@ function readGenesisConfig(root) {
|
|
|
903
908
|
const supabase = validateSupabase(raw.supabase, file);
|
|
904
909
|
if (supabase !== true) out.supabase = supabase;
|
|
905
910
|
}
|
|
911
|
+
if (raw.appFolder !== void 0) out.appFolder = validateAppFolder(raw.appFolder, file);
|
|
906
912
|
return out;
|
|
907
913
|
}
|
|
914
|
+
var PLAIN_FOLDER = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}(?:\/[A-Za-z0-9_][A-Za-z0-9_.-]{0,59}){0,7}$/;
|
|
915
|
+
function isPlainFolder(value) {
|
|
916
|
+
return PLAIN_FOLDER.test(value) && !value.split("/").includes("..");
|
|
917
|
+
}
|
|
918
|
+
function validateAppFolder(raw, source = "config") {
|
|
919
|
+
const norm = typeof raw === "string" ? raw.replace(/^\.\//, "").replace(/\/+$/, "") : "";
|
|
920
|
+
if (!isPlainFolder(norm)) throw new GenesisConfigError(`${source}: "appFolder" must be the app's folder from the repository root, such as "mobile" or "apps/phone" (got ${JSON.stringify(raw)})`);
|
|
921
|
+
return norm;
|
|
922
|
+
}
|
|
908
923
|
function validateSupabase(raw, source = "config") {
|
|
909
924
|
const fail = (msg) => {
|
|
910
925
|
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
@@ -914,8 +929,8 @@ function validateSupabase(raw, source = "config") {
|
|
|
914
929
|
for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
|
|
915
930
|
const app = raw.app;
|
|
916
931
|
if (typeof app !== "string" || !app.trim()) return fail(`supabase.app must be the folder of the app that holds supabase/, relative to this one (e.g. "../app")`);
|
|
917
|
-
if (
|
|
918
|
-
const norm =
|
|
932
|
+
if (path21.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
|
|
933
|
+
const norm = path21.posix.normalize(app).replace(/\/+$/, "");
|
|
919
934
|
if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
|
|
920
935
|
return { app: norm };
|
|
921
936
|
}
|
|
@@ -1075,7 +1090,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1075
1090
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1076
1091
|
if (contracts.out !== void 0) {
|
|
1077
1092
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1078
|
-
if (
|
|
1093
|
+
if (path21.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1079
1094
|
}
|
|
1080
1095
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1081
1096
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1143,429 +1158,126 @@ function globToRegExp(glob) {
|
|
|
1143
1158
|
}
|
|
1144
1159
|
function globMatcher(globs) {
|
|
1145
1160
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1146
|
-
return (
|
|
1161
|
+
return (path48) => res.some((re) => re.test(path48));
|
|
1147
1162
|
}
|
|
1148
|
-
var
|
|
1149
|
-
var
|
|
1150
|
-
var
|
|
1151
|
-
var
|
|
1152
|
-
var
|
|
1153
|
-
var
|
|
1154
|
-
var
|
|
1155
|
-
var
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
"
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
"stone",
|
|
1163
|
-
"red",
|
|
1164
|
-
"orange",
|
|
1165
|
-
"amber",
|
|
1166
|
-
"yellow",
|
|
1167
|
-
"lime",
|
|
1168
|
-
"green",
|
|
1169
|
-
"emerald",
|
|
1170
|
-
"teal",
|
|
1171
|
-
"cyan",
|
|
1172
|
-
"sky",
|
|
1173
|
-
"blue",
|
|
1174
|
-
"indigo",
|
|
1175
|
-
"violet",
|
|
1176
|
-
"purple",
|
|
1177
|
-
"fuchsia",
|
|
1178
|
-
"pink",
|
|
1179
|
-
"rose",
|
|
1180
|
-
"taupe",
|
|
1181
|
-
"mauve",
|
|
1182
|
-
"mist",
|
|
1183
|
-
"olive"
|
|
1184
|
-
];
|
|
1185
|
-
function findPackageDir(from, name) {
|
|
1186
|
-
let dir = path20.resolve(from);
|
|
1187
|
-
for (; ; ) {
|
|
1188
|
-
const candidate = path20.join(dir, "node_modules", name);
|
|
1189
|
-
if (existsSync(path20.join(candidate, "package.json"))) return candidate;
|
|
1190
|
-
const parent = path20.dirname(dir);
|
|
1191
|
-
if (parent === dir) return null;
|
|
1192
|
-
dir = parent;
|
|
1163
|
+
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
1164
|
+
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
1165
|
+
var MIGRATION_FILE = /^(\d{4})_([a-z0-9_]+)\.sql$/;
|
|
1166
|
+
var FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
1167
|
+
var ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
|
|
1168
|
+
var INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
|
|
1169
|
+
var SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
1170
|
+
var SQL_FUNCTION = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/;
|
|
1171
|
+
var ManifestError = class extends Error {
|
|
1172
|
+
constructor(problems) {
|
|
1173
|
+
super(`Invalid block manifest:
|
|
1174
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
1175
|
+
this.problems = problems;
|
|
1176
|
+
this.name = "ManifestError";
|
|
1193
1177
|
}
|
|
1178
|
+
problems;
|
|
1179
|
+
};
|
|
1180
|
+
function safeRelative(value) {
|
|
1181
|
+
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
1182
|
+
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
1183
|
+
const segments = value.split("/");
|
|
1184
|
+
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
1185
|
+
return value;
|
|
1194
1186
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
if (!
|
|
1202
|
-
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
1211
|
-
if (comp === false) rawTags.delete(tag);
|
|
1212
|
-
else rawTags.set(tag, comp);
|
|
1213
|
-
}
|
|
1214
|
-
return {
|
|
1215
|
-
uiPackage,
|
|
1216
|
-
uiVersion: pkg.version,
|
|
1217
|
-
exports: exportNames,
|
|
1218
|
-
values,
|
|
1219
|
-
components,
|
|
1220
|
-
tokens,
|
|
1221
|
-
rawTags,
|
|
1222
|
-
palette: loadPalette(root),
|
|
1223
|
-
companions: loadCompanions(root, config, uiPackage)
|
|
1187
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1188
|
+
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
1189
|
+
function parseManifest(home, id, raw, version, options = {}) {
|
|
1190
|
+
const problems = [];
|
|
1191
|
+
const at = `${home} genesis.blocks.${id}`;
|
|
1192
|
+
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
1193
|
+
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
1194
|
+
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
1195
|
+
const pkgOf = (value, where2) => {
|
|
1196
|
+
if (value === void 0) return home;
|
|
1197
|
+
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
1198
|
+
problems.push(`${where2}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
1199
|
+
return home;
|
|
1200
|
+
}
|
|
1201
|
+
return value;
|
|
1224
1202
|
};
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1203
|
+
const pathOf = (value, where2) => {
|
|
1204
|
+
const safe = safeRelative(value);
|
|
1205
|
+
if (!safe) problems.push(`${where2}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
1206
|
+
return safe ?? "";
|
|
1207
|
+
};
|
|
1208
|
+
const list = (key2) => {
|
|
1209
|
+
const v = raw[key2];
|
|
1210
|
+
if (v === void 0) return [];
|
|
1211
|
+
if (!Array.isArray(v)) {
|
|
1212
|
+
problems.push(`${at}.${key2}: must be a list`);
|
|
1213
|
+
return [];
|
|
1235
1214
|
}
|
|
1215
|
+
return v;
|
|
1216
|
+
};
|
|
1217
|
+
const requires = list("requires").filter((r) => {
|
|
1218
|
+
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
1219
|
+
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
1220
|
+
return ok;
|
|
1221
|
+
});
|
|
1222
|
+
let platforms;
|
|
1223
|
+
if (raw["platforms"] !== void 0) {
|
|
1224
|
+
platforms = list("platforms").filter((p) => {
|
|
1225
|
+
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
1226
|
+
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
1227
|
+
return ok;
|
|
1228
|
+
});
|
|
1236
1229
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
|
|
1249
|
-
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
1250
|
-
for (const target of subpaths) {
|
|
1251
|
-
const t = entryOf(target);
|
|
1252
|
-
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
1253
|
-
}
|
|
1254
|
-
const exportNames = /* @__PURE__ */ new Set();
|
|
1255
|
-
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1256
|
-
let readAny = false;
|
|
1257
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1258
|
-
const readEntry = (file) => {
|
|
1259
|
-
if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
|
|
1260
|
-
seen.add(file);
|
|
1261
|
-
readAny = true;
|
|
1262
|
-
const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
|
|
1263
|
-
for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
|
|
1264
|
-
for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
1265
|
-
reexportedPackages.add(packageName(m[1]));
|
|
1230
|
+
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
1231
|
+
const install = list("install").filter((s) => {
|
|
1232
|
+
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
1233
|
+
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
1234
|
+
return ok;
|
|
1235
|
+
});
|
|
1236
|
+
const migrations = list("migrations").map((m, i) => {
|
|
1237
|
+
const where2 = `${at}.migrations[${i}]`;
|
|
1238
|
+
if (!isObject2(m)) {
|
|
1239
|
+
problems.push(`${where2}: must be an object`);
|
|
1240
|
+
return { package: home, file: "" };
|
|
1266
1241
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1242
|
+
const file = pathOf(m["file"], `${where2}.file`);
|
|
1243
|
+
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
1244
|
+
const out = { package: pkgOf(m["package"], where2), file };
|
|
1245
|
+
if (m["provides"] !== void 0) {
|
|
1246
|
+
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
1247
|
+
else {
|
|
1248
|
+
out.provides = m["provides"].map((p, j) => {
|
|
1249
|
+
const at2 = `${where2}.provides[${j}]`;
|
|
1250
|
+
if (!isObject2(p)) {
|
|
1251
|
+
problems.push(`${at2}: must be an object`);
|
|
1252
|
+
return { package: home, file: "" };
|
|
1253
|
+
}
|
|
1254
|
+
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
1255
|
+
if (p["functions"] !== void 0) {
|
|
1256
|
+
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
1257
|
+
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
1258
|
+
}
|
|
1259
|
+
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
1260
|
+
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
1261
|
+
return provided;
|
|
1262
|
+
});
|
|
1271
1263
|
}
|
|
1272
1264
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
for (const m of text.matchAll(/\b(?:declare\s+)?(?:const|let|var|function|class|enum)\s+([A-Za-z_$][\w$]*)/g)) valueDecls.add(m[1]);
|
|
1290
|
-
for (const m of text.matchAll(/\b(?:interface|type)\s+([A-Za-z_$][\w$]*)/g)) typeDecls.add(m[1]);
|
|
1291
|
-
}
|
|
1292
|
-
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
1293
|
-
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
1294
|
-
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
1295
|
-
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
1296
|
-
}
|
|
1297
|
-
function parseExportNames(dts) {
|
|
1298
|
-
const names = [];
|
|
1299
|
-
for (const m of dts.matchAll(/export\s+(?:type\s+)?\{([^}]*)\}/g)) {
|
|
1300
|
-
for (const part of m[1].split(",")) {
|
|
1301
|
-
const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
1302
|
-
if (name && name !== "default") names.push(name);
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
for (const m of dts.matchAll(/export\s+(?:declare\s+)?(?:const|let|function|class|enum|interface|type)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
1306
|
-
names.push(m[1]);
|
|
1307
|
-
}
|
|
1308
|
-
return names;
|
|
1309
|
-
}
|
|
1310
|
-
function declaredTokens(css) {
|
|
1311
|
-
return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
|
|
1312
|
-
}
|
|
1313
|
-
function packageName(specifier) {
|
|
1314
|
-
const parts = specifier.split("/");
|
|
1315
|
-
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1316
|
-
}
|
|
1317
|
-
function parseSourceExportNames(code) {
|
|
1318
|
-
const names = parseExportNames(code);
|
|
1319
|
-
for (const m of code.matchAll(/export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:var|class|function\*?)\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
1320
|
-
for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
1321
|
-
return [...new Set(names)];
|
|
1322
|
-
}
|
|
1323
|
-
var TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
1324
|
-
var isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
|
|
1325
|
-
function exportSource(target) {
|
|
1326
|
-
if (isTsSource(target)) return target;
|
|
1327
|
-
if (!target || typeof target !== "object") return void 0;
|
|
1328
|
-
for (const value of Object.values(target)) {
|
|
1329
|
-
const nested = exportSource(value);
|
|
1330
|
-
if (nested) return nested;
|
|
1331
|
-
}
|
|
1332
|
-
return void 0;
|
|
1333
|
-
}
|
|
1334
|
-
function resolveSource(dir, spec) {
|
|
1335
|
-
const base = path20.resolve(dir, spec.replace(/\.js$/, ""));
|
|
1336
|
-
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path20.join(base, i))];
|
|
1337
|
-
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
1338
|
-
}
|
|
1339
|
-
function insidePackage(dir, file) {
|
|
1340
|
-
const rel = path20.relative(path20.resolve(dir), path20.resolve(file));
|
|
1341
|
-
return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
1342
|
-
}
|
|
1343
|
-
function stripComments(code) {
|
|
1344
|
-
let out = "";
|
|
1345
|
-
let i = 0;
|
|
1346
|
-
while (i < code.length) {
|
|
1347
|
-
const c = code[i];
|
|
1348
|
-
const next = code[i + 1];
|
|
1349
|
-
if (c === "/" && next === "*") {
|
|
1350
|
-
const end = code.indexOf("*/", i + 2);
|
|
1351
|
-
const stop = end < 0 ? code.length : end + 2;
|
|
1352
|
-
out += code.slice(i, stop).replace(/[^\n]/g, " ");
|
|
1353
|
-
i = stop;
|
|
1354
|
-
} else if (c === "/" && next === "/") {
|
|
1355
|
-
const end = code.indexOf("\n", i);
|
|
1356
|
-
i = end < 0 ? code.length : end;
|
|
1357
|
-
} else if (c === '"' || c === "'" || c === "`") {
|
|
1358
|
-
let j = i + 1;
|
|
1359
|
-
while (j < code.length && code[j] !== c) {
|
|
1360
|
-
if (code[j] === "\\") j++;
|
|
1361
|
-
else if (c !== "`" && code[j] === "\n") break;
|
|
1362
|
-
j++;
|
|
1363
|
-
}
|
|
1364
|
-
out += code.slice(i, j + 1);
|
|
1365
|
-
i = j + 1;
|
|
1366
|
-
} else {
|
|
1367
|
-
out += c;
|
|
1368
|
-
i++;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
return out;
|
|
1372
|
-
}
|
|
1373
|
-
function walkSource(dir, out = []) {
|
|
1374
|
-
if (!existsSync(dir)) return out;
|
|
1375
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1376
|
-
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
1377
|
-
const p = path20.join(dir, entry.name);
|
|
1378
|
-
if (entry.isDirectory()) walkSource(p, out);
|
|
1379
|
-
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1380
|
-
}
|
|
1381
|
-
return out;
|
|
1382
|
-
}
|
|
1383
|
-
function exportTypes(target) {
|
|
1384
|
-
if (!target || typeof target !== "object") return void 0;
|
|
1385
|
-
const t = target;
|
|
1386
|
-
if (typeof t.types === "string") return t.types;
|
|
1387
|
-
for (const key2 of ["import", "default", "require"]) {
|
|
1388
|
-
const nested = exportTypes(t[key2]);
|
|
1389
|
-
if (nested) return nested;
|
|
1390
|
-
}
|
|
1391
|
-
return void 0;
|
|
1392
|
-
}
|
|
1393
|
-
function walkDts(dir, out = []) {
|
|
1394
|
-
if (!existsSync(dir)) return out;
|
|
1395
|
-
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1396
|
-
if (entry.name === "node_modules") continue;
|
|
1397
|
-
const p = path20.join(dir, entry.name);
|
|
1398
|
-
if (entry.isDirectory()) walkDts(p, out);
|
|
1399
|
-
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1400
|
-
}
|
|
1401
|
-
return out;
|
|
1402
|
-
}
|
|
1403
|
-
function resolveThemeFiles(root, config, uiDir) {
|
|
1404
|
-
if (config.themeCss) {
|
|
1405
|
-
const specs = typeof config.themeCss === "string" ? [config.themeCss] : config.themeCss;
|
|
1406
|
-
return specs.map((spec) => {
|
|
1407
|
-
const file = resolveSpec(root, spec);
|
|
1408
|
-
if (!file) throw new DoctorConfigError(`doctor.themeCss: cannot find ${spec}`);
|
|
1409
|
-
return file;
|
|
1410
|
-
});
|
|
1411
|
-
}
|
|
1412
|
-
const files = [];
|
|
1413
|
-
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1414
|
-
const themes = ds && path20.join(ds, "dist", "themes");
|
|
1415
|
-
if (themes && existsSync(themes)) {
|
|
1416
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path20.join(themes, name));
|
|
1417
|
-
}
|
|
1418
|
-
if (files.length === 0) {
|
|
1419
|
-
throw new DoctorConfigError(
|
|
1420
|
-
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
const uiStyles = path20.join(uiDir, "dist", "styles.css");
|
|
1424
|
-
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1425
|
-
return files;
|
|
1426
|
-
}
|
|
1427
|
-
function resolveSpec(root, spec) {
|
|
1428
|
-
const local = path20.resolve(root, spec);
|
|
1429
|
-
if (spec.startsWith(".") || path20.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1430
|
-
const parts = spec.split("/");
|
|
1431
|
-
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1432
|
-
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1433
|
-
if (dir) {
|
|
1434
|
-
const file = path20.join(dir, ...parts.slice(nameLength));
|
|
1435
|
-
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1436
|
-
}
|
|
1437
|
-
return existsSync(local) ? local : null;
|
|
1438
|
-
}
|
|
1439
|
-
function loadPalette(root) {
|
|
1440
|
-
const names = new Set(TAILWIND_PALETTE);
|
|
1441
|
-
try {
|
|
1442
|
-
const req = createRequire(path20.join(root, "package.json"));
|
|
1443
|
-
const colors = req("tailwindcss/colors");
|
|
1444
|
-
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1445
|
-
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
1446
|
-
}
|
|
1447
|
-
} catch {
|
|
1448
|
-
}
|
|
1449
|
-
return [...names].sort();
|
|
1450
|
-
}
|
|
1451
|
-
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
1452
|
-
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
1453
|
-
var MIGRATION_FILE = /^(\d{4})_([a-z0-9_]+)\.sql$/;
|
|
1454
|
-
var FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
1455
|
-
var ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
|
|
1456
|
-
var INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
|
|
1457
|
-
var SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
1458
|
-
var SQL_FUNCTION = /^[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*$/;
|
|
1459
|
-
var ManifestError = class extends Error {
|
|
1460
|
-
constructor(problems) {
|
|
1461
|
-
super(`Invalid block manifest:
|
|
1462
|
-
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
1463
|
-
this.problems = problems;
|
|
1464
|
-
this.name = "ManifestError";
|
|
1465
|
-
}
|
|
1466
|
-
problems;
|
|
1467
|
-
};
|
|
1468
|
-
function safeRelative(value) {
|
|
1469
|
-
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
1470
|
-
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
1471
|
-
const segments = value.split("/");
|
|
1472
|
-
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
1473
|
-
return value;
|
|
1474
|
-
}
|
|
1475
|
-
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1476
|
-
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
1477
|
-
function parseManifest(home, id, raw, version, options = {}) {
|
|
1478
|
-
const problems = [];
|
|
1479
|
-
const at = `${home} genesis.blocks.${id}`;
|
|
1480
|
-
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
1481
|
-
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
1482
|
-
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
1483
|
-
const pkgOf = (value, where2) => {
|
|
1484
|
-
if (value === void 0) return home;
|
|
1485
|
-
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
1486
|
-
problems.push(`${where2}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
1487
|
-
return home;
|
|
1488
|
-
}
|
|
1489
|
-
return value;
|
|
1490
|
-
};
|
|
1491
|
-
const pathOf = (value, where2) => {
|
|
1492
|
-
const safe = safeRelative(value);
|
|
1493
|
-
if (!safe) problems.push(`${where2}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
1494
|
-
return safe ?? "";
|
|
1495
|
-
};
|
|
1496
|
-
const list = (key2) => {
|
|
1497
|
-
const v = raw[key2];
|
|
1498
|
-
if (v === void 0) return [];
|
|
1499
|
-
if (!Array.isArray(v)) {
|
|
1500
|
-
problems.push(`${at}.${key2}: must be a list`);
|
|
1501
|
-
return [];
|
|
1502
|
-
}
|
|
1503
|
-
return v;
|
|
1504
|
-
};
|
|
1505
|
-
const requires = list("requires").filter((r) => {
|
|
1506
|
-
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
1507
|
-
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
1508
|
-
return ok;
|
|
1509
|
-
});
|
|
1510
|
-
let platforms;
|
|
1511
|
-
if (raw["platforms"] !== void 0) {
|
|
1512
|
-
platforms = list("platforms").filter((p) => {
|
|
1513
|
-
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
1514
|
-
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
1515
|
-
return ok;
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1518
|
-
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
1519
|
-
const install = list("install").filter((s) => {
|
|
1520
|
-
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
1521
|
-
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
1522
|
-
return ok;
|
|
1523
|
-
});
|
|
1524
|
-
const migrations = list("migrations").map((m, i) => {
|
|
1525
|
-
const where2 = `${at}.migrations[${i}]`;
|
|
1526
|
-
if (!isObject2(m)) {
|
|
1527
|
-
problems.push(`${where2}: must be an object`);
|
|
1528
|
-
return { package: home, file: "" };
|
|
1529
|
-
}
|
|
1530
|
-
const file = pathOf(m["file"], `${where2}.file`);
|
|
1531
|
-
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
1532
|
-
const out = { package: pkgOf(m["package"], where2), file };
|
|
1533
|
-
if (m["provides"] !== void 0) {
|
|
1534
|
-
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
1535
|
-
else {
|
|
1536
|
-
out.provides = m["provides"].map((p, j) => {
|
|
1537
|
-
const at2 = `${where2}.provides[${j}]`;
|
|
1538
|
-
if (!isObject2(p)) {
|
|
1539
|
-
problems.push(`${at2}: must be an object`);
|
|
1540
|
-
return { package: home, file: "" };
|
|
1541
|
-
}
|
|
1542
|
-
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
1543
|
-
if (p["functions"] !== void 0) {
|
|
1544
|
-
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
1545
|
-
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
1546
|
-
}
|
|
1547
|
-
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
1548
|
-
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
1549
|
-
return provided;
|
|
1550
|
-
});
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
if (m["needs"] !== void 0) {
|
|
1554
|
-
if (!Array.isArray(m["needs"])) problems.push(`${where2}.needs: must be a list of { function, how }`);
|
|
1555
|
-
else {
|
|
1556
|
-
out.needs = m["needs"].flatMap((n, j) => {
|
|
1557
|
-
const at2 = `${where2}.needs[${j}]`;
|
|
1558
|
-
if (!isObject2(n) || typeof n["function"] !== "string" || typeof n["how"] !== "string" || !n["how"].trim()) {
|
|
1559
|
-
problems.push(`${at2}: must be { function: "schema.name", how: "what to add" }`);
|
|
1560
|
-
return [];
|
|
1561
|
-
}
|
|
1562
|
-
if (!SQL_FUNCTION.test(n["function"])) {
|
|
1563
|
-
problems.push(`${at2}.function: "${n["function"]}" must be a schema-qualified function name, like private.genesis_viewer_people`);
|
|
1564
|
-
return [];
|
|
1565
|
-
}
|
|
1566
|
-
return [{ function: n["function"], how: n["how"].trim() }];
|
|
1567
|
-
});
|
|
1568
|
-
}
|
|
1265
|
+
if (m["needs"] !== void 0) {
|
|
1266
|
+
if (!Array.isArray(m["needs"])) problems.push(`${where2}.needs: must be a list of { function, how }`);
|
|
1267
|
+
else {
|
|
1268
|
+
out.needs = m["needs"].flatMap((n, j) => {
|
|
1269
|
+
const at2 = `${where2}.needs[${j}]`;
|
|
1270
|
+
if (!isObject2(n) || typeof n["function"] !== "string" || typeof n["how"] !== "string" || !n["how"].trim()) {
|
|
1271
|
+
problems.push(`${at2}: must be { function: "schema.name", how: "what to add" }`);
|
|
1272
|
+
return [];
|
|
1273
|
+
}
|
|
1274
|
+
if (!SQL_FUNCTION.test(n["function"])) {
|
|
1275
|
+
problems.push(`${at2}.function: "${n["function"]}" must be a schema-qualified function name, like private.genesis_viewer_people`);
|
|
1276
|
+
return [];
|
|
1277
|
+
}
|
|
1278
|
+
return [{ function: n["function"], how: n["how"].trim() }];
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1569
1281
|
}
|
|
1570
1282
|
if (m["runsBefore"] !== void 0) {
|
|
1571
1283
|
if (!Array.isArray(m["runsBefore"])) problems.push(`${where2}.runsBefore: must be a list of { package, file }`);
|
|
@@ -1697,15 +1409,15 @@ function isBlockDef(value) {
|
|
|
1697
1409
|
// src/blocks/files.ts
|
|
1698
1410
|
var sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
1699
1411
|
function inside(parent, child) {
|
|
1700
|
-
const rel =
|
|
1701
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1412
|
+
const rel = path21.relative(parent, child);
|
|
1413
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
1702
1414
|
}
|
|
1703
1415
|
function appPath2(root, rel) {
|
|
1704
1416
|
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
1705
1417
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
1706
1418
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
1707
1419
|
const realRoot = realpathSync(root);
|
|
1708
|
-
const target =
|
|
1420
|
+
const target = path21.join(realRoot, ...safe.split("/"));
|
|
1709
1421
|
const there = (p) => {
|
|
1710
1422
|
try {
|
|
1711
1423
|
lstatSync(p);
|
|
@@ -1714,20 +1426,18 @@ function appPath2(root, rel) {
|
|
|
1714
1426
|
return false;
|
|
1715
1427
|
}
|
|
1716
1428
|
};
|
|
1717
|
-
let probe =
|
|
1718
|
-
while (!there(probe)) probe =
|
|
1429
|
+
let probe = path21.dirname(target);
|
|
1430
|
+
while (!there(probe)) probe = path21.dirname(probe);
|
|
1719
1431
|
let real2;
|
|
1720
1432
|
try {
|
|
1721
1433
|
real2 = realpathSync(probe);
|
|
1722
1434
|
} catch {
|
|
1723
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
1435
|
+
throw new Error(`${rel} goes through a broken symlink (${path21.relative(realRoot, probe)}); refused`);
|
|
1724
1436
|
}
|
|
1725
1437
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
1726
1438
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
1727
1439
|
return target;
|
|
1728
1440
|
}
|
|
1729
|
-
|
|
1730
|
-
// src/blocks/local.ts
|
|
1731
1441
|
var LOCAL_PACKAGES_KEY = "localPackages";
|
|
1732
1442
|
var LocalPackagesError = class extends Error {
|
|
1733
1443
|
name = "LocalPackagesError";
|
|
@@ -1737,8 +1447,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1737
1447
|
return raw.map((entry, i) => {
|
|
1738
1448
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
1739
1449
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
1740
|
-
if (
|
|
1741
|
-
const norm =
|
|
1450
|
+
if (path21.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
1451
|
+
const norm = path21.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1742
1452
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
1743
1453
|
const parts = norm.split("/");
|
|
1744
1454
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -1749,7 +1459,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1749
1459
|
});
|
|
1750
1460
|
}
|
|
1751
1461
|
function localPackageGlobs(root) {
|
|
1752
|
-
const file =
|
|
1462
|
+
const file = path21.join(root, "genesis.config.json");
|
|
1753
1463
|
if (!existsSync(file)) return [];
|
|
1754
1464
|
let raw;
|
|
1755
1465
|
try {
|
|
@@ -1763,14 +1473,14 @@ function localPackageGlobs(root) {
|
|
|
1763
1473
|
var cache = /* @__PURE__ */ new Map();
|
|
1764
1474
|
function repositoryRoot(appRoot) {
|
|
1765
1475
|
for (let dir = appRoot; ; ) {
|
|
1766
|
-
if (existsSync(
|
|
1767
|
-
const parent =
|
|
1476
|
+
if (existsSync(path21.join(dir, ".git"))) return dir;
|
|
1477
|
+
const parent = path21.dirname(dir);
|
|
1768
1478
|
if (parent === dir) return appRoot;
|
|
1769
1479
|
dir = parent;
|
|
1770
1480
|
}
|
|
1771
1481
|
}
|
|
1772
1482
|
function localPackages(root) {
|
|
1773
|
-
const appRoot =
|
|
1483
|
+
const appRoot = path21.resolve(root);
|
|
1774
1484
|
const globs = localPackageGlobs(appRoot);
|
|
1775
1485
|
const key2 = `${appRoot}
|
|
1776
1486
|
${globs.join("\n")}`;
|
|
@@ -1779,24 +1489,24 @@ ${globs.join("\n")}`;
|
|
|
1779
1489
|
const dirs = /* @__PURE__ */ new Set();
|
|
1780
1490
|
for (const glob of globs) {
|
|
1781
1491
|
if (glob.endsWith("/*") || glob === "*") {
|
|
1782
|
-
const parent =
|
|
1492
|
+
const parent = path21.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
1783
1493
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
1784
1494
|
for (const entry of readdirSync(parent).sort()) {
|
|
1785
1495
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
1786
|
-
dirs.add(
|
|
1496
|
+
dirs.add(path21.join(parent, entry));
|
|
1787
1497
|
}
|
|
1788
1498
|
} else {
|
|
1789
|
-
dirs.add(
|
|
1499
|
+
dirs.add(path21.join(appRoot, glob));
|
|
1790
1500
|
}
|
|
1791
1501
|
}
|
|
1792
1502
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
1793
1503
|
const out = [];
|
|
1794
1504
|
const byName = /* @__PURE__ */ new Map();
|
|
1795
1505
|
for (const dir of [...dirs].sort()) {
|
|
1796
|
-
const manifest =
|
|
1506
|
+
const manifest = path21.join(dir, "package.json");
|
|
1797
1507
|
if (!existsSync(manifest)) continue;
|
|
1798
1508
|
if (!inside(real2, realpathSync(dir))) {
|
|
1799
|
-
throw new LocalPackagesError(`${
|
|
1509
|
+
throw new LocalPackagesError(`${path21.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
1800
1510
|
}
|
|
1801
1511
|
let pkg;
|
|
1802
1512
|
try {
|
|
@@ -1805,7 +1515,7 @@ ${globs.join("\n")}`;
|
|
|
1805
1515
|
continue;
|
|
1806
1516
|
}
|
|
1807
1517
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
1808
|
-
const rel =
|
|
1518
|
+
const rel = path21.relative(appRoot, dir).split(path21.sep).join("/");
|
|
1809
1519
|
const other = byName.get(pkg.name);
|
|
1810
1520
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
1811
1521
|
byName.set(pkg.name, rel);
|
|
@@ -1993,35 +1703,35 @@ var DEFAULT_IGNORE = [
|
|
|
1993
1703
|
];
|
|
1994
1704
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1995
1705
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1996
|
-
var toPosix = (p) => p.split(
|
|
1706
|
+
var toPosix = (p) => p.split(path21.sep).join("/");
|
|
1997
1707
|
function scanFiles(root, config) {
|
|
1998
1708
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
1999
1709
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
2000
1710
|
const files = [];
|
|
2001
1711
|
const seen = /* @__PURE__ */ new Set();
|
|
2002
1712
|
const visit = (abs) => {
|
|
2003
|
-
const rel = toPosix(
|
|
1713
|
+
const rel = toPosix(path21.relative(root, abs));
|
|
2004
1714
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2005
|
-
const ext =
|
|
1715
|
+
const ext = path21.extname(abs);
|
|
2006
1716
|
if (!extensions.has(ext)) return;
|
|
2007
1717
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2008
1718
|
seen.add(rel);
|
|
2009
1719
|
const text = readFileSync(abs, "utf8");
|
|
2010
1720
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
2011
1721
|
};
|
|
2012
|
-
const
|
|
1722
|
+
const walk3 = (dir) => {
|
|
2013
1723
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2014
1724
|
if (entry.isDirectory()) {
|
|
2015
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
1725
|
+
if (!SKIP_DIRS.has(entry.name)) walk3(path21.join(dir, entry.name));
|
|
2016
1726
|
} else if (entry.isFile()) {
|
|
2017
|
-
visit(
|
|
1727
|
+
visit(path21.join(dir, entry.name));
|
|
2018
1728
|
}
|
|
2019
1729
|
}
|
|
2020
1730
|
};
|
|
2021
1731
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2022
|
-
const abs =
|
|
1732
|
+
const abs = path21.resolve(root, src);
|
|
2023
1733
|
if (!existsSync(abs)) continue;
|
|
2024
|
-
if (statSync(abs).isDirectory())
|
|
1734
|
+
if (statSync(abs).isDirectory()) walk3(abs);
|
|
2025
1735
|
else visit(abs);
|
|
2026
1736
|
}
|
|
2027
1737
|
let local = [];
|
|
@@ -2030,7 +1740,7 @@ function scanFiles(root, config) {
|
|
|
2030
1740
|
} catch {
|
|
2031
1741
|
local = [];
|
|
2032
1742
|
}
|
|
2033
|
-
for (const pkg of local)
|
|
1743
|
+
for (const pkg of local) walk3(pkg.dir);
|
|
2034
1744
|
return files;
|
|
2035
1745
|
}
|
|
2036
1746
|
function lineAt(text, index) {
|
|
@@ -2039,145 +1749,6 @@ function lineAt(text, index) {
|
|
|
2039
1749
|
return line;
|
|
2040
1750
|
}
|
|
2041
1751
|
|
|
2042
|
-
// src/doctor/patterns.ts
|
|
2043
|
-
function parseRulesMarkdown(markdown) {
|
|
2044
|
-
const rules = [];
|
|
2045
|
-
let current = null;
|
|
2046
|
-
for (const line of markdown.split("\n")) {
|
|
2047
|
-
const heading = line.match(/^###\s+([A-Za-z0-9_-]+)\s*$/);
|
|
2048
|
-
if (heading) {
|
|
2049
|
-
current = { id: heading[1] };
|
|
2050
|
-
rules.push(current);
|
|
2051
|
-
continue;
|
|
2052
|
-
}
|
|
2053
|
-
if (/^#{1,2}\s/.test(line)) {
|
|
2054
|
-
current = null;
|
|
2055
|
-
continue;
|
|
2056
|
-
}
|
|
2057
|
-
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message|newOnly):\s*(.*)$/);
|
|
2058
|
-
if (!current || !kv) continue;
|
|
2059
|
-
const [, key2, raw] = kv;
|
|
2060
|
-
const value = raw.trim();
|
|
2061
|
-
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2062
|
-
else if (key2 === "level") current.level = value;
|
|
2063
|
-
else if (key2 === "newOnly") current.newOnly = value === "true" ? true : value === "false" ? false : value;
|
|
2064
|
-
else current[key2] = value;
|
|
2065
|
-
}
|
|
2066
|
-
return rules;
|
|
2067
|
-
}
|
|
2068
|
-
function toRegExp(source, flags = "") {
|
|
2069
|
-
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
2070
|
-
return new RegExp(source, flags);
|
|
2071
|
-
}
|
|
2072
|
-
function compilePatternRules(rules, source) {
|
|
2073
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2074
|
-
const out = [];
|
|
2075
|
-
for (const rule of rules) {
|
|
2076
|
-
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
2077
|
-
ids.add(rule.id);
|
|
2078
|
-
const level = rule.level ?? "error";
|
|
2079
|
-
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
2080
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
2081
|
-
}
|
|
2082
|
-
if (rule.newOnly !== void 0 && typeof rule.newOnly !== "boolean") {
|
|
2083
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has newOnly "${String(rule.newOnly)}" (use true or false)`);
|
|
2084
|
-
}
|
|
2085
|
-
if (level === "guide") continue;
|
|
2086
|
-
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
2087
|
-
if (!rule.forbid && !rule.require && !rule.path) {
|
|
2088
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" needs forbid, require or path (or level: guide)`);
|
|
2089
|
-
}
|
|
2090
|
-
try {
|
|
2091
|
-
out.push({
|
|
2092
|
-
rule,
|
|
2093
|
-
level,
|
|
2094
|
-
includes: globMatcher(rule.files),
|
|
2095
|
-
excludes: globMatcher(rule.exclude),
|
|
2096
|
-
forbid: rule.forbid ? toRegExp(rule.forbid, "m") : void 0,
|
|
2097
|
-
require: rule.require ? toRegExp(rule.require, "m") : void 0,
|
|
2098
|
-
path: rule.path ? toRegExp(rule.path) : void 0
|
|
2099
|
-
});
|
|
2100
|
-
} catch (err) {
|
|
2101
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has an invalid pattern: ${err.message}`);
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
return out;
|
|
2105
|
-
}
|
|
2106
|
-
function loadPatternRules(root, patterns, rulesDoc) {
|
|
2107
|
-
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2108
|
-
let all = compiled;
|
|
2109
|
-
if (rulesDoc) {
|
|
2110
|
-
const file = path20.resolve(root, rulesDoc);
|
|
2111
|
-
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2112
|
-
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2113
|
-
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
2114
|
-
if (clash) throw new DoctorConfigError(`rule "${clash.rule.id}" is defined in both doctor.patterns and ${rulesDoc}`);
|
|
2115
|
-
all = [...compiled, ...fromDoc];
|
|
2116
|
-
}
|
|
2117
|
-
if (all.length === 0) return null;
|
|
2118
|
-
return {
|
|
2119
|
-
count: all.length,
|
|
2120
|
-
ids: all.map((r) => r.rule.id),
|
|
2121
|
-
newOnly: all.filter((r) => r.rule.newOnly).map((r) => r.rule.id),
|
|
2122
|
-
plugin: {
|
|
2123
|
-
name: "patterns",
|
|
2124
|
-
check(ctx) {
|
|
2125
|
-
for (const r of all) {
|
|
2126
|
-
const message = r.rule.message ?? "breaks a design rule";
|
|
2127
|
-
for (const file of ctx.files) {
|
|
2128
|
-
if (!r.includes(file.path) || r.excludes(file.path)) continue;
|
|
2129
|
-
const report = (line) => ctx.report({ rule: r.rule.id, level: r.level, file: file.path, line, message });
|
|
2130
|
-
if (r.path && !r.path.test(file.path)) report(0);
|
|
2131
|
-
if (r.require && !r.require.test(file.code)) report(0);
|
|
2132
|
-
if (r.forbid) {
|
|
2133
|
-
const m = r.forbid.exec(file.code);
|
|
2134
|
-
if (m) report(lineAt(file.code, m.index));
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
}
|
|
2140
|
-
};
|
|
2141
|
-
}
|
|
2142
|
-
function defineDoctorPlugin(plugin) {
|
|
2143
|
-
return plugin;
|
|
2144
|
-
}
|
|
2145
|
-
async function loadPlugins(specs, configDir) {
|
|
2146
|
-
const plugins = [];
|
|
2147
|
-
for (const spec of specs ?? []) {
|
|
2148
|
-
const [id, options] = typeof spec === "string" ? [spec, void 0] : spec;
|
|
2149
|
-
const file = resolvePlugin(id, configDir);
|
|
2150
|
-
const url = `${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`;
|
|
2151
|
-
let mod;
|
|
2152
|
-
try {
|
|
2153
|
-
mod = await import(url);
|
|
2154
|
-
} catch (err) {
|
|
2155
|
-
throw new DoctorConfigError(`doctor.plugins: could not load ${id}: ${err.message}`);
|
|
2156
|
-
}
|
|
2157
|
-
let value = mod.default;
|
|
2158
|
-
if (typeof value === "function") value = await value(options);
|
|
2159
|
-
const list = Array.isArray(value) ? value : [value];
|
|
2160
|
-
for (const p of list) {
|
|
2161
|
-
if (!p || typeof p !== "object" || typeof p.check !== "function" || typeof p.name !== "string") {
|
|
2162
|
-
throw new DoctorConfigError(`doctor.plugins: ${id} must default-export { name, check(context) } (or an array, or a factory returning one)`);
|
|
2163
|
-
}
|
|
2164
|
-
plugins.push(p);
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
return plugins;
|
|
2168
|
-
}
|
|
2169
|
-
function resolvePlugin(id, configDir) {
|
|
2170
|
-
try {
|
|
2171
|
-
if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
|
|
2172
|
-
return resolveFrom(id, configDir);
|
|
2173
|
-
} catch {
|
|
2174
|
-
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
function resolveFrom(id, from) {
|
|
2178
|
-
return createRequire(path20.join(from, "noop.js")).resolve(id);
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
1752
|
// src/doctor/semver.ts
|
|
2182
1753
|
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2183
1754
|
function parseVersion(v) {
|
|
@@ -2297,46 +1868,6 @@ function satisfies(version, range) {
|
|
|
2297
1868
|
(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))
|
|
2298
1869
|
);
|
|
2299
1870
|
}
|
|
2300
|
-
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2301
|
-
function readReleaseManifest(root) {
|
|
2302
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2303
|
-
const file = dir && path20.join(dir, "dist", "versions.json");
|
|
2304
|
-
if (!file || !existsSync(file)) return null;
|
|
2305
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
2306
|
-
}
|
|
2307
|
-
function checkVersionSkew(ctx) {
|
|
2308
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
2309
|
-
if (!manifest) return;
|
|
2310
|
-
const overlays = markedOverlays(ctx);
|
|
2311
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2312
|
-
const overlay = overlays.get(name);
|
|
2313
|
-
if (overlay) {
|
|
2314
|
-
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
2315
|
-
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
2316
|
-
if (from !== want && !behind) {
|
|
2317
|
-
ctx.report({
|
|
2318
|
-
rule: "version-skew",
|
|
2319
|
-
level: "warn",
|
|
2320
|
-
file: "package.json",
|
|
2321
|
-
subject: name,
|
|
2322
|
-
message: `the app's overlay of ${name} was copied from ${from}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Bring the overlay onto ${want} (or promote it and adopt the release).`
|
|
2323
|
-
});
|
|
2324
|
-
}
|
|
2325
|
-
continue;
|
|
2326
|
-
}
|
|
2327
|
-
const dir = findPackageDir(ctx.root, name);
|
|
2328
|
-
if (!dir) continue;
|
|
2329
|
-
const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
|
|
2330
|
-
if (have === want) continue;
|
|
2331
|
-
ctx.report({
|
|
2332
|
-
rule: "version-skew",
|
|
2333
|
-
level: "warn",
|
|
2334
|
-
file: "package.json",
|
|
2335
|
-
subject: name,
|
|
2336
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2337
|
-
});
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
1871
|
|
|
2341
1872
|
// src/doctor/overlays.ts
|
|
2342
1873
|
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
@@ -2352,7 +1883,7 @@ function overlayState(name, json) {
|
|
|
2352
1883
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2353
1884
|
const problems = [];
|
|
2354
1885
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2355
|
-
const rel =
|
|
1886
|
+
const rel = path21.relative(path21.resolve(root), path21.resolve(dir)).split(path21.sep).join("/");
|
|
2356
1887
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2357
1888
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2358
1889
|
if (holds !== void 0) problems.push(`${name}: an overlay lives in a package folder of its own, not in ${rel || "the app root"}, which holds the app's source (${holds})`);
|
|
@@ -2389,92 +1920,760 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
2389
1920
|
for (const file of manifests) {
|
|
2390
1921
|
let json;
|
|
2391
1922
|
try {
|
|
2392
|
-
json = JSON.parse(readFileSync(
|
|
2393
|
-
} catch {
|
|
2394
|
-
continue;
|
|
1923
|
+
json = JSON.parse(readFileSync(path21.join(root, file), "utf8"));
|
|
1924
|
+
} catch {
|
|
1925
|
+
continue;
|
|
1926
|
+
}
|
|
1927
|
+
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
1928
|
+
const spec = json[section2]?.[name];
|
|
1929
|
+
const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
|
|
1930
|
+
const parsed = v && parseVersion(v);
|
|
1931
|
+
if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
return best;
|
|
1935
|
+
}
|
|
1936
|
+
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
1937
|
+
let packages;
|
|
1938
|
+
try {
|
|
1939
|
+
packages = localPackages(ctx.root);
|
|
1940
|
+
} catch {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
for (const pkg of packages) {
|
|
1944
|
+
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
1945
|
+
const file = `${pkg.rel}/package.json`;
|
|
1946
|
+
let json;
|
|
1947
|
+
try {
|
|
1948
|
+
json = JSON.parse(readFileSync(path21.join(pkg.dir, "package.json"), "utf8"));
|
|
1949
|
+
} catch {
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
const state = overlayState(pkg.name, json);
|
|
1953
|
+
if (state.kind === "none") {
|
|
1954
|
+
ctx.report({
|
|
1955
|
+
rule: "overlay-unmarked",
|
|
1956
|
+
file,
|
|
1957
|
+
subject: pkg.name,
|
|
1958
|
+
message: `${pkg.name} is a local package with a Genesis package's name, so it shadows the published one, but it carries no overlay marker; add "genesis": { "overlay": { "upstream": "${pkg.name}@<version copied>", "since": "YYYY-MM-DD", "owner": "\u2026", "reason": "\u2026" } }, or rename it`
|
|
1959
|
+
});
|
|
1960
|
+
continue;
|
|
1961
|
+
}
|
|
1962
|
+
if (state.kind === "invalid") {
|
|
1963
|
+
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
1964
|
+
continue;
|
|
1965
|
+
}
|
|
1966
|
+
const { marker } = state;
|
|
1967
|
+
for (const problem of overlaySetupProblems(ctx.root, ctx.config, pkg.dir, pkg.name, json)) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
1968
|
+
const age = overlayAgeDays(marker.since, now);
|
|
1969
|
+
if (age < -1) {
|
|
1970
|
+
ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: `${pkg.name} genesis.overlay.since: ${marker.since} is in the future; use the day the overlay was made` });
|
|
1971
|
+
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
1972
|
+
ctx.report({
|
|
1973
|
+
rule: "overlay-age",
|
|
1974
|
+
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
1975
|
+
file,
|
|
1976
|
+
subject: pkg.name,
|
|
1977
|
+
message: `the overlay of ${marker.upstream} is ${age} days old (since ${marker.since}, owner ${marker.owner}); promote its change to Genesis and adopt the release, or drop it (an overlay is reported after ${OVERLAY_NOTICE_DAYS} days, and after ${OVERLAY_WARN_DAYS} it warns, which fails --strict)`
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
const upstream = overlayUpstream(marker).version;
|
|
1981
|
+
const version = typeof json.version === "string" ? json.version : "";
|
|
1982
|
+
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
1983
|
+
ctx.report({
|
|
1984
|
+
rule: "overlay-version",
|
|
1985
|
+
level: "warn",
|
|
1986
|
+
file,
|
|
1987
|
+
subject: version || "(none)",
|
|
1988
|
+
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
1992
|
+
const from = parseVersion(upstream);
|
|
1993
|
+
const to = pinned ? parseVersion(pinned) : null;
|
|
1994
|
+
if (from && to && compareVersions(from, to) < 0) {
|
|
1995
|
+
ctx.report({
|
|
1996
|
+
rule: "overlay-behind",
|
|
1997
|
+
level: "warn",
|
|
1998
|
+
file,
|
|
1999
|
+
subject: pkg.name,
|
|
2000
|
+
message: `the overlay of ${marker.upstream} is behind ${pkg.name}@${pinned}, the version the app now pins; run genesis upgrade, which rebases the overlay onto it (dropping what Genesis now ships) and moves the marker's upstream, or rebase it by hand`
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
// src/doctor/versions.ts
|
|
2007
|
+
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2008
|
+
function readReleaseManifest(root) {
|
|
2009
|
+
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2010
|
+
const file = dir && path21.join(dir, "dist", "versions.json");
|
|
2011
|
+
if (!file || !existsSync(file)) return null;
|
|
2012
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
2013
|
+
}
|
|
2014
|
+
function checkVersionSkew(ctx) {
|
|
2015
|
+
const manifest = readReleaseManifest(ctx.root);
|
|
2016
|
+
if (!manifest) return;
|
|
2017
|
+
const overlays = markedOverlays(ctx);
|
|
2018
|
+
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2019
|
+
const overlay = overlays.get(name);
|
|
2020
|
+
if (overlay) {
|
|
2021
|
+
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
2022
|
+
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
2023
|
+
if (from !== want && !behind) {
|
|
2024
|
+
ctx.report({
|
|
2025
|
+
rule: "version-skew",
|
|
2026
|
+
level: "warn",
|
|
2027
|
+
file: "package.json",
|
|
2028
|
+
subject: name,
|
|
2029
|
+
message: `the app's overlay of ${name} was copied from ${from}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Bring the overlay onto ${want} (or promote it and adopt the release).`
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
continue;
|
|
2033
|
+
}
|
|
2034
|
+
const dir = findPackageDir(ctx.root, name);
|
|
2035
|
+
if (!dir) continue;
|
|
2036
|
+
const have = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8")).version;
|
|
2037
|
+
if (have === want) continue;
|
|
2038
|
+
ctx.report({
|
|
2039
|
+
rule: "version-skew",
|
|
2040
|
+
level: "warn",
|
|
2041
|
+
file: "package.json",
|
|
2042
|
+
subject: name,
|
|
2043
|
+
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2044
|
+
});
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
function buildCatalog(packagesDir) {
|
|
2048
|
+
const packages = {};
|
|
2049
|
+
for (const dir of readdirSync(packagesDir).sort()) {
|
|
2050
|
+
const file = path21.join(packagesDir, dir, "package.json");
|
|
2051
|
+
if (!existsSync(file)) continue;
|
|
2052
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2053
|
+
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
2054
|
+
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
2055
|
+
}
|
|
2056
|
+
return { packages };
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
// src/blocks/discover.ts
|
|
2060
|
+
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
2061
|
+
function cliPackageDir() {
|
|
2062
|
+
let dir = path21.dirname(fileURLToPath(import.meta.url));
|
|
2063
|
+
for (; ; ) {
|
|
2064
|
+
const file = path21.join(dir, "package.json");
|
|
2065
|
+
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
2066
|
+
const parent = path21.dirname(dir);
|
|
2067
|
+
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
2068
|
+
dir = parent;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
function workspacePackagesDir() {
|
|
2072
|
+
const dir = path21.resolve(cliPackageDir(), "..");
|
|
2073
|
+
return existsSync(path21.join(dir, "features", "package.json")) && existsSync(path21.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
2074
|
+
}
|
|
2075
|
+
var catalogCache;
|
|
2076
|
+
function readCatalog() {
|
|
2077
|
+
if (catalogCache) return catalogCache;
|
|
2078
|
+
const workspace = workspacePackagesDir();
|
|
2079
|
+
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
2080
|
+
const file = path21.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
2081
|
+
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
2082
|
+
return catalogCache;
|
|
2083
|
+
}
|
|
2084
|
+
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
2085
|
+
function installedGenesis(root) {
|
|
2086
|
+
const found = /* @__PURE__ */ new Map();
|
|
2087
|
+
let dir = path21.resolve(root);
|
|
2088
|
+
for (; ; ) {
|
|
2089
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path21.join(dir, m)));
|
|
2090
|
+
const scope = path21.join(dir, "node_modules", "@marktiderman");
|
|
2091
|
+
if (existsSync(scope)) {
|
|
2092
|
+
for (const entry of readdirSync(scope)) {
|
|
2093
|
+
const name = `@marktiderman/${entry}`;
|
|
2094
|
+
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
2095
|
+
if (existsSync(path21.join(scope, entry, "package.json"))) found.set(name, path21.join(scope, entry));
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
const parent = path21.dirname(dir);
|
|
2099
|
+
if (atInstallRoot || parent === dir) return found;
|
|
2100
|
+
dir = parent;
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
var declarationCache = /* @__PURE__ */ new Map();
|
|
2104
|
+
function declarationsOf(dir, warnings) {
|
|
2105
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
2106
|
+
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
2107
|
+
let cached = declarationCache.get(key2);
|
|
2108
|
+
if (!cached) {
|
|
2109
|
+
cached = loadDeclarations(dir, warnings);
|
|
2110
|
+
declarationCache.set(key2, cached);
|
|
2111
|
+
}
|
|
2112
|
+
return cached;
|
|
2113
|
+
}
|
|
2114
|
+
async function loadDeclarations(dir, warnings) {
|
|
2115
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
2116
|
+
const entry = pkg.exports?.["./blocks"];
|
|
2117
|
+
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
2118
|
+
if (typeof target !== "string") return {};
|
|
2119
|
+
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
2120
|
+
const file = rel && path21.join(dir, ...rel.split("/"));
|
|
2121
|
+
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
2122
|
+
try {
|
|
2123
|
+
const jiti = createJiti(path21.join(dir, "package.json"), { moduleCache: false });
|
|
2124
|
+
const mod = await jiti.import(file);
|
|
2125
|
+
const out = {};
|
|
2126
|
+
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
2127
|
+
return out;
|
|
2128
|
+
} catch (err) {
|
|
2129
|
+
warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
|
|
2130
|
+
return {};
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
2134
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
2135
|
+
const raw = rawBlocksOf(pkg);
|
|
2136
|
+
const declared = await declarationsOf(dir, warnings);
|
|
2137
|
+
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
2138
|
+
const out = [];
|
|
2139
|
+
for (const id of [...ids].sort()) {
|
|
2140
|
+
const fromJson = raw[id] ?? {};
|
|
2141
|
+
const merged = { ...fromJson, ...declared[id] };
|
|
2142
|
+
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
2143
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
2144
|
+
if (manifest) out.push(manifest);
|
|
2145
|
+
}
|
|
2146
|
+
return out;
|
|
2147
|
+
}
|
|
2148
|
+
function withProvides(declared, json) {
|
|
2149
|
+
if (!Array.isArray(declared)) return declared;
|
|
2150
|
+
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
2151
|
+
return declared.map((m) => {
|
|
2152
|
+
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
2153
|
+
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
async function allBlocks(root, warnings = []) {
|
|
2157
|
+
const out = [];
|
|
2158
|
+
for (const local of localPackages(root)) {
|
|
2159
|
+
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
2160
|
+
}
|
|
2161
|
+
const installed = installedGenesis(root);
|
|
2162
|
+
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
2163
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
2164
|
+
if (installed.has(name)) continue;
|
|
2165
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
2166
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
2167
|
+
if (manifest) out.push({ manifest, from: "catalog" });
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
return out;
|
|
2171
|
+
}
|
|
2172
|
+
function tryParse(parse2, warnings) {
|
|
2173
|
+
try {
|
|
2174
|
+
return parse2();
|
|
2175
|
+
} catch (err) {
|
|
2176
|
+
if (!(err instanceof ManifestError)) throw err;
|
|
2177
|
+
warnings.push(err.message);
|
|
2178
|
+
return null;
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
function catalogBlocks(warnings = []) {
|
|
2182
|
+
const out = [];
|
|
2183
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
2184
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
2185
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
2186
|
+
if (manifest) out.push(manifest);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return out;
|
|
2190
|
+
}
|
|
2191
|
+
async function findBlock(root, id, options = {}) {
|
|
2192
|
+
const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
|
|
2193
|
+
if (all.length === 0) {
|
|
2194
|
+
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
2195
|
+
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
2196
|
+
}
|
|
2197
|
+
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
2198
|
+
return all[0];
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2201
|
+
// src/blocks/pm.ts
|
|
2202
|
+
function findLockfile(root) {
|
|
2203
|
+
let dir = path21.resolve(root);
|
|
2204
|
+
for (; ; ) {
|
|
2205
|
+
if (existsSync(path21.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
2206
|
+
if (existsSync(path21.join(dir, "bun.lock")) || existsSync(path21.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
2207
|
+
if (existsSync(path21.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
2208
|
+
if (existsSync(path21.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
2209
|
+
const parent = path21.dirname(dir);
|
|
2210
|
+
if (parent === dir) return null;
|
|
2211
|
+
dir = parent;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
function detectPackageManager(root) {
|
|
2215
|
+
return findLockfile(root)?.pm ?? "npm";
|
|
2216
|
+
}
|
|
2217
|
+
function installCommand(pm) {
|
|
2218
|
+
return pm === "yarn" ? ["yarn", "install"] : [pm, "install"];
|
|
2219
|
+
}
|
|
2220
|
+
var shellLine = (argv) => argv.map((a) => /^[\w@./:^~=-]+$/.test(a) ? a : `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
|
2221
|
+
|
|
2222
|
+
// src/doctor/genesis.ts
|
|
2223
|
+
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
2224
|
+
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
2225
|
+
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
2226
|
+
var DEFAULT_COMPONENT_PACKAGES = ["@marktiderman/genesis-forms-studio"];
|
|
2227
|
+
var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
2228
|
+
var TAG_ALIASES = { hr: "Separator" };
|
|
2229
|
+
var NON_COMPONENT_SUFFIX = /(Props|Variant|Variants|Type|Types|Config|Context|Options|Status)$/;
|
|
2230
|
+
var TAILWIND_PALETTE = [
|
|
2231
|
+
"black",
|
|
2232
|
+
"white",
|
|
2233
|
+
"slate",
|
|
2234
|
+
"gray",
|
|
2235
|
+
"zinc",
|
|
2236
|
+
"neutral",
|
|
2237
|
+
"stone",
|
|
2238
|
+
"red",
|
|
2239
|
+
"orange",
|
|
2240
|
+
"amber",
|
|
2241
|
+
"yellow",
|
|
2242
|
+
"lime",
|
|
2243
|
+
"green",
|
|
2244
|
+
"emerald",
|
|
2245
|
+
"teal",
|
|
2246
|
+
"cyan",
|
|
2247
|
+
"sky",
|
|
2248
|
+
"blue",
|
|
2249
|
+
"indigo",
|
|
2250
|
+
"violet",
|
|
2251
|
+
"purple",
|
|
2252
|
+
"fuchsia",
|
|
2253
|
+
"pink",
|
|
2254
|
+
"rose",
|
|
2255
|
+
"taupe",
|
|
2256
|
+
"mauve",
|
|
2257
|
+
"mist",
|
|
2258
|
+
"olive"
|
|
2259
|
+
];
|
|
2260
|
+
function findPackageDir(from, name) {
|
|
2261
|
+
let dir = path21.resolve(from);
|
|
2262
|
+
for (; ; ) {
|
|
2263
|
+
const candidate = path21.join(dir, "node_modules", name);
|
|
2264
|
+
if (existsSync(path21.join(candidate, "package.json"))) return candidate;
|
|
2265
|
+
const parent = path21.dirname(dir);
|
|
2266
|
+
if (parent === dir) return null;
|
|
2267
|
+
dir = parent;
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
function uiPackageFor(config) {
|
|
2271
|
+
return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
|
|
2272
|
+
}
|
|
2273
|
+
function loadGenesis(root, config) {
|
|
2274
|
+
const uiPackage = uiPackageFor(config);
|
|
2275
|
+
const pkg = readPackageExports(root, uiPackage);
|
|
2276
|
+
if (!pkg) throw new DoctorConfigError(notInstalled(root, uiPackage));
|
|
2277
|
+
const { dir: uiDir, exports: exportNames, values, components } = pkg;
|
|
2278
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
2279
|
+
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
2280
|
+
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
2281
|
+
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
2282
|
+
const rawTags = /* @__PURE__ */ new Map();
|
|
2283
|
+
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
2284
|
+
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
2285
|
+
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
2286
|
+
if (comp === false) rawTags.delete(tag);
|
|
2287
|
+
else rawTags.set(tag, comp);
|
|
2288
|
+
}
|
|
2289
|
+
return {
|
|
2290
|
+
uiPackage,
|
|
2291
|
+
uiVersion: pkg.version,
|
|
2292
|
+
exports: exportNames,
|
|
2293
|
+
values,
|
|
2294
|
+
components,
|
|
2295
|
+
tokens,
|
|
2296
|
+
rawTags,
|
|
2297
|
+
palette: loadPalette(root),
|
|
2298
|
+
companions: loadCompanions(root, config, uiPackage)
|
|
2299
|
+
};
|
|
2300
|
+
}
|
|
2301
|
+
function notInstalled(root, uiPackage) {
|
|
2302
|
+
let declared = false;
|
|
2303
|
+
try {
|
|
2304
|
+
const pkg = JSON.parse(readFileSync(path21.join(root, "package.json"), "utf8"));
|
|
2305
|
+
declared = ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"].some((s) => pkg[s]?.[uiPackage] !== void 0);
|
|
2306
|
+
} catch {
|
|
2307
|
+
}
|
|
2308
|
+
if (!declared) return `${uiPackage} is not installed here and isn't in this app's package.json. Add it, or set doctor.uiPackage.`;
|
|
2309
|
+
return `${uiPackage} is in package.json but not installed, so this app's dependencies aren't installed. Run \`${shellLine(installCommand(detectPackageManager(root)))}\`, then run this again.`;
|
|
2310
|
+
}
|
|
2311
|
+
function loadCompanions(root, config, uiPackage) {
|
|
2312
|
+
const out = [];
|
|
2313
|
+
for (const name of config.componentPackages ?? DEFAULT_COMPONENT_PACKAGES) {
|
|
2314
|
+
if (name === uiPackage) continue;
|
|
2315
|
+
try {
|
|
2316
|
+
const pkg = readPackageExports(root, name);
|
|
2317
|
+
if (pkg) out.push({ package: name, version: pkg.version, components: pkg.components });
|
|
2318
|
+
} catch (err) {
|
|
2319
|
+
if (!(err instanceof DoctorConfigError)) throw err;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
return out;
|
|
2323
|
+
}
|
|
2324
|
+
function readPackageExports(root, uiPackage) {
|
|
2325
|
+
const uiDir = findPackageDir(root, uiPackage);
|
|
2326
|
+
if (!uiDir) return null;
|
|
2327
|
+
const uiPkg = JSON.parse(readFileSync(path21.join(uiDir, "package.json"), "utf8"));
|
|
2328
|
+
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
2329
|
+
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
2330
|
+
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
2331
|
+
const entryOf = fromSource ? exportSource : exportTypes;
|
|
2332
|
+
const typeEntries = /* @__PURE__ */ new Set();
|
|
2333
|
+
const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
|
|
2334
|
+
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
2335
|
+
for (const target of subpaths) {
|
|
2336
|
+
const t = entryOf(target);
|
|
2337
|
+
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
2338
|
+
}
|
|
2339
|
+
const exportNames = /* @__PURE__ */ new Set();
|
|
2340
|
+
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
2341
|
+
let readAny = false;
|
|
2342
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2343
|
+
const readEntry = (file) => {
|
|
2344
|
+
if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
|
|
2345
|
+
seen.add(file);
|
|
2346
|
+
readAny = true;
|
|
2347
|
+
const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
|
|
2348
|
+
for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
|
|
2349
|
+
for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
2350
|
+
reexportedPackages.add(packageName(m[1]));
|
|
2351
|
+
}
|
|
2352
|
+
if (fromSource) {
|
|
2353
|
+
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
2354
|
+
const next = resolveSource(path21.dirname(file), m[1]);
|
|
2355
|
+
if (next) readEntry(next);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
for (const entry of typeEntries) readEntry(path21.join(uiDir, entry));
|
|
2360
|
+
if (!readAny) {
|
|
2361
|
+
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
2362
|
+
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
2363
|
+
}
|
|
2364
|
+
const valueDecls = /* @__PURE__ */ new Set();
|
|
2365
|
+
const typeDecls = /* @__PURE__ */ new Set();
|
|
2366
|
+
const declRoot = typeof mainTypes === "string" ? path21.dirname(path21.join(uiDir, mainTypes)) : uiDir;
|
|
2367
|
+
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
2368
|
+
for (const pkg of reexportedPackages) {
|
|
2369
|
+
const dir = findPackageDir(uiDir, pkg);
|
|
2370
|
+
if (dir) walkDts(path21.join(dir, "dist"), declFiles);
|
|
2371
|
+
}
|
|
2372
|
+
for (const file of declFiles) {
|
|
2373
|
+
const text = readFileSync(file, "utf8");
|
|
2374
|
+
for (const m of text.matchAll(/\b(?:declare\s+)?(?:const|let|var|function|class|enum)\s+([A-Za-z_$][\w$]*)/g)) valueDecls.add(m[1]);
|
|
2375
|
+
for (const m of text.matchAll(/\b(?:interface|type)\s+([A-Za-z_$][\w$]*)/g)) typeDecls.add(m[1]);
|
|
2376
|
+
}
|
|
2377
|
+
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
2378
|
+
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
2379
|
+
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
2380
|
+
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
2381
|
+
}
|
|
2382
|
+
function parseExportNames(dts) {
|
|
2383
|
+
const names = [];
|
|
2384
|
+
for (const m of dts.matchAll(/export\s+(?:type\s+)?\{([^}]*)\}/g)) {
|
|
2385
|
+
for (const part of m[1].split(",")) {
|
|
2386
|
+
const name = part.trim().replace(/^type\s+/, "").split(/\s+as\s+/).pop()?.trim();
|
|
2387
|
+
if (name && name !== "default") names.push(name);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
for (const m of dts.matchAll(/export\s+(?:declare\s+)?(?:const|let|function|class|enum|interface|type)\s+([A-Za-z_$][\w$]*)/g)) {
|
|
2391
|
+
names.push(m[1]);
|
|
2392
|
+
}
|
|
2393
|
+
return names;
|
|
2394
|
+
}
|
|
2395
|
+
function declaredTokens(css) {
|
|
2396
|
+
return [...css.matchAll(/(--[A-Za-z0-9_-]+)\s*:/g)].map((m) => m[1]);
|
|
2397
|
+
}
|
|
2398
|
+
function packageName(specifier) {
|
|
2399
|
+
const parts = specifier.split("/");
|
|
2400
|
+
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
2401
|
+
}
|
|
2402
|
+
function parseSourceExportNames(code) {
|
|
2403
|
+
const names = parseExportNames(code);
|
|
2404
|
+
for (const m of code.matchAll(/export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:var|class|function\*?)\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
2405
|
+
for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
2406
|
+
return [...new Set(names)];
|
|
2407
|
+
}
|
|
2408
|
+
var TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
2409
|
+
var isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
|
|
2410
|
+
function exportSource(target) {
|
|
2411
|
+
if (isTsSource(target)) return target;
|
|
2412
|
+
if (!target || typeof target !== "object") return void 0;
|
|
2413
|
+
for (const value of Object.values(target)) {
|
|
2414
|
+
const nested = exportSource(value);
|
|
2415
|
+
if (nested) return nested;
|
|
2416
|
+
}
|
|
2417
|
+
return void 0;
|
|
2418
|
+
}
|
|
2419
|
+
function resolveSource(dir, spec) {
|
|
2420
|
+
const base = path21.resolve(dir, spec.replace(/\.js$/, ""));
|
|
2421
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path21.join(base, i))];
|
|
2422
|
+
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
2423
|
+
}
|
|
2424
|
+
function insidePackage(dir, file) {
|
|
2425
|
+
const rel = path21.relative(path21.resolve(dir), path21.resolve(file));
|
|
2426
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
2427
|
+
}
|
|
2428
|
+
function stripComments(code) {
|
|
2429
|
+
let out = "";
|
|
2430
|
+
let i = 0;
|
|
2431
|
+
while (i < code.length) {
|
|
2432
|
+
const c = code[i];
|
|
2433
|
+
const next = code[i + 1];
|
|
2434
|
+
if (c === "/" && next === "*") {
|
|
2435
|
+
const end = code.indexOf("*/", i + 2);
|
|
2436
|
+
const stop = end < 0 ? code.length : end + 2;
|
|
2437
|
+
out += code.slice(i, stop).replace(/[^\n]/g, " ");
|
|
2438
|
+
i = stop;
|
|
2439
|
+
} else if (c === "/" && next === "/") {
|
|
2440
|
+
const end = code.indexOf("\n", i);
|
|
2441
|
+
i = end < 0 ? code.length : end;
|
|
2442
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
2443
|
+
let j = i + 1;
|
|
2444
|
+
while (j < code.length && code[j] !== c) {
|
|
2445
|
+
if (code[j] === "\\") j++;
|
|
2446
|
+
else if (c !== "`" && code[j] === "\n") break;
|
|
2447
|
+
j++;
|
|
2448
|
+
}
|
|
2449
|
+
out += code.slice(i, j + 1);
|
|
2450
|
+
i = j + 1;
|
|
2451
|
+
} else {
|
|
2452
|
+
out += c;
|
|
2453
|
+
i++;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return out;
|
|
2457
|
+
}
|
|
2458
|
+
function walkSource(dir, out = []) {
|
|
2459
|
+
if (!existsSync(dir)) return out;
|
|
2460
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2461
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
2462
|
+
const p = path21.join(dir, entry.name);
|
|
2463
|
+
if (entry.isDirectory()) walkSource(p, out);
|
|
2464
|
+
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
2465
|
+
}
|
|
2466
|
+
return out;
|
|
2467
|
+
}
|
|
2468
|
+
function exportTypes(target) {
|
|
2469
|
+
if (!target || typeof target !== "object") return void 0;
|
|
2470
|
+
const t = target;
|
|
2471
|
+
if (typeof t.types === "string") return t.types;
|
|
2472
|
+
for (const key2 of ["import", "default", "require"]) {
|
|
2473
|
+
const nested = exportTypes(t[key2]);
|
|
2474
|
+
if (nested) return nested;
|
|
2475
|
+
}
|
|
2476
|
+
return void 0;
|
|
2477
|
+
}
|
|
2478
|
+
function walkDts(dir, out = []) {
|
|
2479
|
+
if (!existsSync(dir)) return out;
|
|
2480
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2481
|
+
if (entry.name === "node_modules") continue;
|
|
2482
|
+
const p = path21.join(dir, entry.name);
|
|
2483
|
+
if (entry.isDirectory()) walkDts(p, out);
|
|
2484
|
+
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
2485
|
+
}
|
|
2486
|
+
return out;
|
|
2487
|
+
}
|
|
2488
|
+
function resolveThemeFiles(root, config, uiDir) {
|
|
2489
|
+
if (config.themeCss) {
|
|
2490
|
+
const specs = typeof config.themeCss === "string" ? [config.themeCss] : config.themeCss;
|
|
2491
|
+
return specs.map((spec) => {
|
|
2492
|
+
const file = resolveSpec(root, spec);
|
|
2493
|
+
if (!file) throw new DoctorConfigError(`doctor.themeCss: cannot find ${spec}`);
|
|
2494
|
+
return file;
|
|
2495
|
+
});
|
|
2496
|
+
}
|
|
2497
|
+
const files = [];
|
|
2498
|
+
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
2499
|
+
const themes = ds && path21.join(ds, "dist", "themes");
|
|
2500
|
+
if (themes && existsSync(themes)) {
|
|
2501
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path21.join(themes, name));
|
|
2502
|
+
}
|
|
2503
|
+
if (files.length === 0) {
|
|
2504
|
+
throw new DoctorConfigError(
|
|
2505
|
+
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
2506
|
+
);
|
|
2507
|
+
}
|
|
2508
|
+
const uiStyles = path21.join(uiDir, "dist", "styles.css");
|
|
2509
|
+
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
2510
|
+
return files;
|
|
2511
|
+
}
|
|
2512
|
+
function resolveSpec(root, spec) {
|
|
2513
|
+
const local = path21.resolve(root, spec);
|
|
2514
|
+
if (spec.startsWith(".") || path21.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
2515
|
+
const parts = spec.split("/");
|
|
2516
|
+
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
2517
|
+
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2518
|
+
if (dir) {
|
|
2519
|
+
const file = path21.join(dir, ...parts.slice(nameLength));
|
|
2520
|
+
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
2521
|
+
}
|
|
2522
|
+
return existsSync(local) ? local : null;
|
|
2523
|
+
}
|
|
2524
|
+
function loadPalette(root) {
|
|
2525
|
+
const names = new Set(TAILWIND_PALETTE);
|
|
2526
|
+
try {
|
|
2527
|
+
const req = createRequire(path21.join(root, "package.json"));
|
|
2528
|
+
const colors = req("tailwindcss/colors");
|
|
2529
|
+
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
2530
|
+
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
2531
|
+
}
|
|
2532
|
+
} catch {
|
|
2533
|
+
}
|
|
2534
|
+
return [...names].sort();
|
|
2535
|
+
}
|
|
2536
|
+
function parseRulesMarkdown(markdown) {
|
|
2537
|
+
const rules = [];
|
|
2538
|
+
let current = null;
|
|
2539
|
+
for (const line of markdown.split("\n")) {
|
|
2540
|
+
const heading = line.match(/^###\s+([A-Za-z0-9_-]+)\s*$/);
|
|
2541
|
+
if (heading) {
|
|
2542
|
+
current = { id: heading[1] };
|
|
2543
|
+
rules.push(current);
|
|
2544
|
+
continue;
|
|
2545
|
+
}
|
|
2546
|
+
if (/^#{1,2}\s/.test(line)) {
|
|
2547
|
+
current = null;
|
|
2548
|
+
continue;
|
|
2549
|
+
}
|
|
2550
|
+
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message|newOnly):\s*(.*)$/);
|
|
2551
|
+
if (!current || !kv) continue;
|
|
2552
|
+
const [, key2, raw] = kv;
|
|
2553
|
+
const value = raw.trim();
|
|
2554
|
+
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2555
|
+
else if (key2 === "level") current.level = value;
|
|
2556
|
+
else if (key2 === "newOnly") current.newOnly = value === "true" ? true : value === "false" ? false : value;
|
|
2557
|
+
else current[key2] = value;
|
|
2558
|
+
}
|
|
2559
|
+
return rules;
|
|
2560
|
+
}
|
|
2561
|
+
function toRegExp(source, flags = "") {
|
|
2562
|
+
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
2563
|
+
return new RegExp(source, flags);
|
|
2564
|
+
}
|
|
2565
|
+
function compilePatternRules(rules, source) {
|
|
2566
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2567
|
+
const out = [];
|
|
2568
|
+
for (const rule of rules) {
|
|
2569
|
+
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
2570
|
+
ids.add(rule.id);
|
|
2571
|
+
const level = rule.level ?? "error";
|
|
2572
|
+
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
2573
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
2574
|
+
}
|
|
2575
|
+
if (rule.newOnly !== void 0 && typeof rule.newOnly !== "boolean") {
|
|
2576
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has newOnly "${String(rule.newOnly)}" (use true or false)`);
|
|
2577
|
+
}
|
|
2578
|
+
if (level === "guide") continue;
|
|
2579
|
+
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
2580
|
+
if (!rule.forbid && !rule.require && !rule.path) {
|
|
2581
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" needs forbid, require or path (or level: guide)`);
|
|
2582
|
+
}
|
|
2583
|
+
try {
|
|
2584
|
+
out.push({
|
|
2585
|
+
rule,
|
|
2586
|
+
level,
|
|
2587
|
+
includes: globMatcher(rule.files),
|
|
2588
|
+
excludes: globMatcher(rule.exclude),
|
|
2589
|
+
forbid: rule.forbid ? toRegExp(rule.forbid, "m") : void 0,
|
|
2590
|
+
require: rule.require ? toRegExp(rule.require, "m") : void 0,
|
|
2591
|
+
path: rule.path ? toRegExp(rule.path) : void 0
|
|
2592
|
+
});
|
|
2593
|
+
} catch (err) {
|
|
2594
|
+
throw new DoctorConfigError(`${source}: rule "${rule.id}" has an invalid pattern: ${err.message}`);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
return out;
|
|
2598
|
+
}
|
|
2599
|
+
function loadPatternRules(root, patterns, rulesDoc) {
|
|
2600
|
+
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2601
|
+
let all = compiled;
|
|
2602
|
+
if (rulesDoc) {
|
|
2603
|
+
const file = path21.resolve(root, rulesDoc);
|
|
2604
|
+
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2605
|
+
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2606
|
+
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
2607
|
+
if (clash) throw new DoctorConfigError(`rule "${clash.rule.id}" is defined in both doctor.patterns and ${rulesDoc}`);
|
|
2608
|
+
all = [...compiled, ...fromDoc];
|
|
2609
|
+
}
|
|
2610
|
+
if (all.length === 0) return null;
|
|
2611
|
+
return {
|
|
2612
|
+
count: all.length,
|
|
2613
|
+
ids: all.map((r) => r.rule.id),
|
|
2614
|
+
newOnly: all.filter((r) => r.rule.newOnly).map((r) => r.rule.id),
|
|
2615
|
+
plugin: {
|
|
2616
|
+
name: "patterns",
|
|
2617
|
+
check(ctx) {
|
|
2618
|
+
for (const r of all) {
|
|
2619
|
+
const message = r.rule.message ?? "breaks a design rule";
|
|
2620
|
+
for (const file of ctx.files) {
|
|
2621
|
+
if (!r.includes(file.path) || r.excludes(file.path)) continue;
|
|
2622
|
+
const report = (line) => ctx.report({ rule: r.rule.id, level: r.level, file: file.path, line, message });
|
|
2623
|
+
if (r.path && !r.path.test(file.path)) report(0);
|
|
2624
|
+
if (r.require && !r.require.test(file.code)) report(0);
|
|
2625
|
+
if (r.forbid) {
|
|
2626
|
+
const m = r.forbid.exec(file.code);
|
|
2627
|
+
if (m) report(lineAt(file.code, m.index));
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
}
|
|
2635
|
+
function defineDoctorPlugin(plugin) {
|
|
2636
|
+
return plugin;
|
|
2637
|
+
}
|
|
2638
|
+
async function loadPlugins(specs, configDir) {
|
|
2639
|
+
const plugins = [];
|
|
2640
|
+
for (const spec of specs ?? []) {
|
|
2641
|
+
const [id, options] = typeof spec === "string" ? [spec, void 0] : spec;
|
|
2642
|
+
const file = resolvePlugin(id, configDir);
|
|
2643
|
+
const url = `${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`;
|
|
2644
|
+
let mod;
|
|
2645
|
+
try {
|
|
2646
|
+
mod = await import(url);
|
|
2647
|
+
} catch (err) {
|
|
2648
|
+
throw new DoctorConfigError(`doctor.plugins: could not load ${id}: ${err.message}`);
|
|
2395
2649
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
if (
|
|
2650
|
+
let value = mod.default;
|
|
2651
|
+
if (typeof value === "function") value = await value(options);
|
|
2652
|
+
const list = Array.isArray(value) ? value : [value];
|
|
2653
|
+
for (const p of list) {
|
|
2654
|
+
if (!p || typeof p !== "object" || typeof p.check !== "function" || typeof p.name !== "string") {
|
|
2655
|
+
throw new DoctorConfigError(`doctor.plugins: ${id} must default-export { name, check(context) } (or an array, or a factory returning one)`);
|
|
2656
|
+
}
|
|
2657
|
+
plugins.push(p);
|
|
2401
2658
|
}
|
|
2402
2659
|
}
|
|
2403
|
-
return
|
|
2660
|
+
return plugins;
|
|
2404
2661
|
}
|
|
2405
|
-
function
|
|
2406
|
-
let packages;
|
|
2662
|
+
function resolvePlugin(id, configDir) {
|
|
2407
2663
|
try {
|
|
2408
|
-
|
|
2664
|
+
if (id.startsWith(".") || path21.isAbsolute(id)) return resolveFrom(path21.resolve(configDir, id), configDir);
|
|
2665
|
+
return resolveFrom(id, configDir);
|
|
2409
2666
|
} catch {
|
|
2410
|
-
|
|
2411
|
-
}
|
|
2412
|
-
for (const pkg of packages) {
|
|
2413
|
-
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
2414
|
-
const file = `${pkg.rel}/package.json`;
|
|
2415
|
-
let json;
|
|
2416
|
-
try {
|
|
2417
|
-
json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
2418
|
-
} catch {
|
|
2419
|
-
continue;
|
|
2420
|
-
}
|
|
2421
|
-
const state = overlayState(pkg.name, json);
|
|
2422
|
-
if (state.kind === "none") {
|
|
2423
|
-
ctx.report({
|
|
2424
|
-
rule: "overlay-unmarked",
|
|
2425
|
-
file,
|
|
2426
|
-
subject: pkg.name,
|
|
2427
|
-
message: `${pkg.name} is a local package with a Genesis package's name, so it shadows the published one, but it carries no overlay marker; add "genesis": { "overlay": { "upstream": "${pkg.name}@<version copied>", "since": "YYYY-MM-DD", "owner": "\u2026", "reason": "\u2026" } }, or rename it`
|
|
2428
|
-
});
|
|
2429
|
-
continue;
|
|
2430
|
-
}
|
|
2431
|
-
if (state.kind === "invalid") {
|
|
2432
|
-
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2433
|
-
continue;
|
|
2434
|
-
}
|
|
2435
|
-
const { marker } = state;
|
|
2436
|
-
for (const problem of overlaySetupProblems(ctx.root, ctx.config, pkg.dir, pkg.name, json)) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2437
|
-
const age = overlayAgeDays(marker.since, now);
|
|
2438
|
-
if (age < -1) {
|
|
2439
|
-
ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: `${pkg.name} genesis.overlay.since: ${marker.since} is in the future; use the day the overlay was made` });
|
|
2440
|
-
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
2441
|
-
ctx.report({
|
|
2442
|
-
rule: "overlay-age",
|
|
2443
|
-
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
2444
|
-
file,
|
|
2445
|
-
subject: pkg.name,
|
|
2446
|
-
message: `the overlay of ${marker.upstream} is ${age} days old (since ${marker.since}, owner ${marker.owner}); promote its change to Genesis and adopt the release, or drop it (an overlay is reported after ${OVERLAY_NOTICE_DAYS} days, and after ${OVERLAY_WARN_DAYS} it warns, which fails --strict)`
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
const upstream = overlayUpstream(marker).version;
|
|
2450
|
-
const version = typeof json.version === "string" ? json.version : "";
|
|
2451
|
-
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
2452
|
-
ctx.report({
|
|
2453
|
-
rule: "overlay-version",
|
|
2454
|
-
level: "warn",
|
|
2455
|
-
file,
|
|
2456
|
-
subject: version || "(none)",
|
|
2457
|
-
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
|
|
2458
|
-
});
|
|
2459
|
-
}
|
|
2460
|
-
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
2461
|
-
const from = parseVersion(upstream);
|
|
2462
|
-
const to = pinned ? parseVersion(pinned) : null;
|
|
2463
|
-
if (from && to && compareVersions(from, to) < 0) {
|
|
2464
|
-
ctx.report({
|
|
2465
|
-
rule: "overlay-behind",
|
|
2466
|
-
level: "warn",
|
|
2467
|
-
file,
|
|
2468
|
-
subject: pkg.name,
|
|
2469
|
-
message: `the overlay of ${marker.upstream} is behind ${pkg.name}@${pinned}, the version the app now pins; run genesis upgrade, which rebases the overlay onto it (dropping what Genesis now ships) and moves the marker's upstream, or rebase it by hand`
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2667
|
+
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2472
2668
|
}
|
|
2473
2669
|
}
|
|
2474
|
-
|
|
2475
|
-
|
|
2670
|
+
function resolveFrom(id, from) {
|
|
2671
|
+
return createRequire(path21.join(from, "noop.js")).resolve(id);
|
|
2672
|
+
}
|
|
2476
2673
|
var BUILTIN_RULES = [
|
|
2477
2674
|
"local-primitives",
|
|
2675
|
+
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
2676
|
+
"figma-routes",
|
|
2478
2677
|
"starter-leftover",
|
|
2479
2678
|
"forbidden-import",
|
|
2480
2679
|
"raw-tag",
|
|
@@ -2567,7 +2766,7 @@ function importSpecifiers(file) {
|
|
|
2567
2766
|
}
|
|
2568
2767
|
function checkProjectLayout(ctx) {
|
|
2569
2768
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2570
|
-
if (existsSync(
|
|
2769
|
+
if (existsSync(path21.join(ctx.root, dir))) {
|
|
2571
2770
|
ctx.report({
|
|
2572
2771
|
rule: "local-primitives",
|
|
2573
2772
|
file: dir,
|
|
@@ -2577,7 +2776,7 @@ function checkProjectLayout(ctx) {
|
|
|
2577
2776
|
}
|
|
2578
2777
|
}
|
|
2579
2778
|
for (const file of STARTER_LEFTOVERS) {
|
|
2580
|
-
if (existsSync(
|
|
2779
|
+
if (existsSync(path21.join(ctx.root, file))) {
|
|
2581
2780
|
ctx.report({
|
|
2582
2781
|
rule: "starter-leftover",
|
|
2583
2782
|
level: "warn",
|
|
@@ -2667,7 +2866,7 @@ function checkTokens(ctx) {
|
|
|
2667
2866
|
}
|
|
2668
2867
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2669
2868
|
if (/[*?]/.test(pattern)) continue;
|
|
2670
|
-
const abs =
|
|
2869
|
+
const abs = path21.join(ctx.root, pattern);
|
|
2671
2870
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2672
2871
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2673
2872
|
}
|
|
@@ -2691,7 +2890,7 @@ function checkShadowedExports(ctx) {
|
|
|
2691
2890
|
file.code.split("\n").forEach((text, i) => {
|
|
2692
2891
|
for (const m of text.matchAll(re)) {
|
|
2693
2892
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
2694
|
-
ctx.report({ rule: "shadowed-export", file: file.path, line: i + 1, subject: m[1], message: `shadows the Genesis export '${m[1]}'; reuse or extend
|
|
2893
|
+
ctx.report({ rule: "shadowed-export", file: file.path, line: i + 1, subject: m[1], message: `shadows the Genesis export '${m[1]}'; reuse or extend ${m[1]} from ${ctx.genesis.uiPackage} (or rename yours if it's a different thing)` });
|
|
2695
2894
|
}
|
|
2696
2895
|
});
|
|
2697
2896
|
}
|
|
@@ -2790,10 +2989,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
|
|
|
2790
2989
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2791
2990
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2792
2991
|
function resolveLocal(root, fromFile, spec) {
|
|
2793
|
-
const bases = spec.startsWith(".") ? [
|
|
2992
|
+
const bases = spec.startsWith(".") ? [path21.resolve(path21.dirname(fromFile), spec)] : [path21.join(root, spec.slice(2)), path21.join(root, "src", spec.slice(2))];
|
|
2794
2993
|
for (const base of bases) {
|
|
2795
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2796
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2994
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path21.join(base, `index${e}`))].find(
|
|
2995
|
+
(p) => SCRIPT_EXTS2.has(path21.extname(p)) && existsSync(p)
|
|
2797
2996
|
);
|
|
2798
2997
|
if (hit) return hit;
|
|
2799
2998
|
}
|
|
@@ -2914,13 +3113,13 @@ function checkNativePack(ctx) {
|
|
|
2914
3113
|
}
|
|
2915
3114
|
function checkEasPlaceholders(ctx) {
|
|
2916
3115
|
const files = [];
|
|
2917
|
-
if (existsSync(
|
|
2918
|
-
const workflows =
|
|
3116
|
+
if (existsSync(path21.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
3117
|
+
const workflows = path21.join(ctx.root, ".eas", "workflows");
|
|
2919
3118
|
if (existsSync(workflows)) {
|
|
2920
3119
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
2921
3120
|
}
|
|
2922
3121
|
for (const file of files) {
|
|
2923
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
3122
|
+
for (const hit of findPlaceholders(file, readFileSync(path21.join(ctx.root, file), "utf8"))) {
|
|
2924
3123
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
2925
3124
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
2926
3125
|
ctx.report({
|
|
@@ -2999,7 +3198,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2999
3198
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
3000
3199
|
const code = file.code;
|
|
3001
3200
|
const hidden = HIDES_HEADER.exec(code);
|
|
3002
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
3201
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path21.posix.dirname(file.path), file.path);
|
|
3003
3202
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
3004
3203
|
if (hidden && own) {
|
|
3005
3204
|
reported.add(file.path);
|
|
@@ -3027,7 +3226,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3027
3226
|
}
|
|
3028
3227
|
for (const file of ctx.files) {
|
|
3029
3228
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
3030
|
-
const layout = hidingLayouts.get(
|
|
3229
|
+
const layout = hidingLayouts.get(path21.posix.dirname(file.path));
|
|
3031
3230
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
3032
3231
|
if (!layout || !own) continue;
|
|
3033
3232
|
ctx.report({
|
|
@@ -3049,13 +3248,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
3049
3248
|
}
|
|
3050
3249
|
function routerRoot(ctx) {
|
|
3051
3250
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
3052
|
-
return existsSync(
|
|
3251
|
+
return existsSync(path21.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
3053
3252
|
}
|
|
3054
3253
|
function checkScreenLayouts(ctx, pkg) {
|
|
3055
3254
|
const layouts = nativeLayouts(pkg);
|
|
3056
3255
|
if (layouts.length === 0) return;
|
|
3057
3256
|
const rootDir = routerRoot(ctx);
|
|
3058
|
-
if (!existsSync(
|
|
3257
|
+
if (!existsSync(path21.join(ctx.root, rootDir))) {
|
|
3059
3258
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
3060
3259
|
return;
|
|
3061
3260
|
}
|
|
@@ -3111,7 +3310,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
3111
3310
|
function readExpoConfigs(root) {
|
|
3112
3311
|
const out = [];
|
|
3113
3312
|
for (const name of EXPO_CONFIGS) {
|
|
3114
|
-
const abs =
|
|
3313
|
+
const abs = path21.join(root, name);
|
|
3115
3314
|
if (!existsSync(abs)) continue;
|
|
3116
3315
|
const text = readFileSync(abs, "utf8");
|
|
3117
3316
|
let json = null;
|
|
@@ -3145,13 +3344,13 @@ function pluginOptions(json, module) {
|
|
|
3145
3344
|
return null;
|
|
3146
3345
|
}
|
|
3147
3346
|
function dependencies(root) {
|
|
3148
|
-
const file =
|
|
3347
|
+
const file = path21.join(root, "package.json");
|
|
3149
3348
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
3150
3349
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3151
3350
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
3152
3351
|
}
|
|
3153
3352
|
function runtimeDependencies(root) {
|
|
3154
|
-
const file =
|
|
3353
|
+
const file = path21.join(root, "package.json");
|
|
3155
3354
|
if (!existsSync(file)) return {};
|
|
3156
3355
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
3157
3356
|
}
|
|
@@ -3405,14 +3604,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3405
3604
|
seen.add(file);
|
|
3406
3605
|
const json = readJsonc(file);
|
|
3407
3606
|
if (!json) return {};
|
|
3408
|
-
const dir =
|
|
3607
|
+
const dir = path21.dirname(file);
|
|
3409
3608
|
let merged = {};
|
|
3410
3609
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3411
3610
|
for (const ext of parents) {
|
|
3412
3611
|
if (typeof ext !== "string") continue;
|
|
3413
3612
|
let target = null;
|
|
3414
|
-
if (ext.startsWith(".") ||
|
|
3415
|
-
const abs =
|
|
3613
|
+
if (ext.startsWith(".") || path21.isAbsolute(ext)) {
|
|
3614
|
+
const abs = path21.resolve(dir, ext);
|
|
3416
3615
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3417
3616
|
} else {
|
|
3418
3617
|
const parts = ext.split("/");
|
|
@@ -3420,14 +3619,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3420
3619
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3421
3620
|
if (pkgDir) {
|
|
3422
3621
|
const sub = parts.slice(nameLength).join("/");
|
|
3423
|
-
const abs =
|
|
3622
|
+
const abs = path21.join(pkgDir, sub || "tsconfig.json");
|
|
3424
3623
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3425
3624
|
}
|
|
3426
3625
|
}
|
|
3427
3626
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3428
3627
|
}
|
|
3429
3628
|
const opts = json.compilerOptions ?? {};
|
|
3430
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
3629
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path21.resolve(dir, opts.baseUrl);
|
|
3431
3630
|
if (opts.paths && typeof opts.paths === "object") {
|
|
3432
3631
|
merged.paths = opts.paths;
|
|
3433
3632
|
merged.pathsDir = dir;
|
|
@@ -3438,7 +3637,7 @@ function aliases(root) {
|
|
|
3438
3637
|
const table = [];
|
|
3439
3638
|
let baseUrl = null;
|
|
3440
3639
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3441
|
-
const file =
|
|
3640
|
+
const file = path21.join(root, name);
|
|
3442
3641
|
if (!existsSync(file)) continue;
|
|
3443
3642
|
const config = readTsconfig(root, file);
|
|
3444
3643
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -3446,22 +3645,22 @@ function aliases(root) {
|
|
|
3446
3645
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3447
3646
|
if (!Array.isArray(targets)) continue;
|
|
3448
3647
|
const exact = !pattern.endsWith("*");
|
|
3449
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
3648
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path21.join(base, String(t).replace(/\*$/, ""))) });
|
|
3450
3649
|
}
|
|
3451
3650
|
}
|
|
3452
|
-
const pkg = readJsonc(
|
|
3651
|
+
const pkg = readJsonc(path21.join(root, "package.json"));
|
|
3453
3652
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3454
3653
|
if (typeof target !== "string") continue;
|
|
3455
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
3654
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path21.join(root, target.replace(/\*.*$/, ""))] });
|
|
3456
3655
|
}
|
|
3457
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
3656
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path21.join(root, "src") + path21.sep, root + path21.sep] });
|
|
3458
3657
|
return { table, baseUrl };
|
|
3459
3658
|
}
|
|
3460
3659
|
function resolveFile(base) {
|
|
3461
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
3660
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path21.join(base, `index${e}`))];
|
|
3462
3661
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3463
3662
|
for (const p of tries) {
|
|
3464
|
-
if (SCRIPT_EXTS2.has(
|
|
3663
|
+
if (SCRIPT_EXTS2.has(path21.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3465
3664
|
}
|
|
3466
3665
|
return null;
|
|
3467
3666
|
}
|
|
@@ -3475,7 +3674,7 @@ function createTrail(ctx) {
|
|
|
3475
3674
|
const { table, baseUrl } = aliases(ctx.root);
|
|
3476
3675
|
let declared = null;
|
|
3477
3676
|
try {
|
|
3478
|
-
const pkg = JSON.parse(readFileSync(
|
|
3677
|
+
const pkg = JSON.parse(readFileSync(path21.join(ctx.root, "package.json"), "utf8"));
|
|
3479
3678
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3480
3679
|
} catch {
|
|
3481
3680
|
declared = null;
|
|
@@ -3506,17 +3705,17 @@ function createTrail(ctx) {
|
|
|
3506
3705
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3507
3706
|
let resolved = null;
|
|
3508
3707
|
if (spec.startsWith(".")) {
|
|
3509
|
-
resolved = resolveFile(
|
|
3708
|
+
resolved = resolveFile(path21.resolve(path21.dirname(file.absolutePath), spec));
|
|
3510
3709
|
if (!resolved) lost = true;
|
|
3511
3710
|
} else {
|
|
3512
3711
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3513
3712
|
if (alias) {
|
|
3514
3713
|
for (const t of alias.targets) {
|
|
3515
|
-
resolved = resolveFile(alias.exact ? t :
|
|
3714
|
+
resolved = resolveFile(alias.exact ? t : path21.join(t, spec.slice(alias.prefix.length)));
|
|
3516
3715
|
if (resolved) break;
|
|
3517
3716
|
}
|
|
3518
3717
|
}
|
|
3519
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
3718
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path21.join(baseUrl, spec));
|
|
3520
3719
|
if (!resolved) {
|
|
3521
3720
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3522
3721
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -3527,218 +3726,65 @@ function createTrail(ctx) {
|
|
|
3527
3726
|
const out = { files, lost };
|
|
3528
3727
|
importsCache.set(file.absolutePath, out);
|
|
3529
3728
|
return out;
|
|
3530
|
-
};
|
|
3531
|
-
const strippedCache = /* @__PURE__ */ new Map();
|
|
3532
|
-
const stripped = (file) => {
|
|
3533
|
-
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
3534
|
-
return strippedCache.get(file.absolutePath);
|
|
3535
|
-
};
|
|
3536
|
-
const memo = /* @__PURE__ */ new WeakMap();
|
|
3537
|
-
const reach = (file, test2, depth, seen) => {
|
|
3538
|
-
let cache2 = memo.get(test2);
|
|
3539
|
-
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
3540
|
-
const k = `${file.absolutePath}\0${depth}`;
|
|
3541
|
-
const free = cache2.free.get(k);
|
|
3542
|
-
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
3543
|
-
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
3544
|
-
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
3545
|
-
let result;
|
|
3546
|
-
const cut = /* @__PURE__ */ new Set();
|
|
3547
|
-
const code = stripped(file);
|
|
3548
|
-
if (code === null) result = "unknown";
|
|
3549
|
-
else if (test2(code)) result = "yes";
|
|
3550
|
-
else {
|
|
3551
|
-
const { files, lost } = importsOf(file);
|
|
3552
|
-
let unknown = lost && depth > 0;
|
|
3553
|
-
result = "no";
|
|
3554
|
-
if (depth > 0) {
|
|
3555
|
-
seen.add(file.absolutePath);
|
|
3556
|
-
for (const abs of files) {
|
|
3557
|
-
if (seen.has(abs)) {
|
|
3558
|
-
cut.add(abs);
|
|
3559
|
-
continue;
|
|
3560
|
-
}
|
|
3561
|
-
const target = read2(abs);
|
|
3562
|
-
if (!target) {
|
|
3563
|
-
unknown = true;
|
|
3564
|
-
continue;
|
|
3565
|
-
}
|
|
3566
|
-
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
3567
|
-
for (const m of c) cut.add(m);
|
|
3568
|
-
if (r === "yes") {
|
|
3569
|
-
result = "yes";
|
|
3570
|
-
break;
|
|
3571
|
-
}
|
|
3572
|
-
if (r === "unknown") unknown = true;
|
|
3573
|
-
}
|
|
3574
|
-
seen.delete(file.absolutePath);
|
|
3575
|
-
cut.delete(file.absolutePath);
|
|
3576
|
-
}
|
|
3577
|
-
if (result === "no" && unknown) result = "unknown";
|
|
3578
|
-
}
|
|
3579
|
-
if (result === "yes" || cut.size === 0) {
|
|
3580
|
-
cache2.free.set(k, result);
|
|
3581
|
-
return [result, /* @__PURE__ */ new Set()];
|
|
3582
|
-
}
|
|
3583
|
-
const entries = cache2.cut.get(k) ?? [];
|
|
3584
|
-
entries.push({ cut: [...cut], result });
|
|
3585
|
-
cache2.cut.set(k, entries);
|
|
3586
|
-
return [result, cut];
|
|
3587
|
-
};
|
|
3588
|
-
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3589
|
-
}
|
|
3590
|
-
function buildCatalog(packagesDir) {
|
|
3591
|
-
const packages = {};
|
|
3592
|
-
for (const dir of readdirSync(packagesDir).sort()) {
|
|
3593
|
-
const file = path20.join(packagesDir, dir, "package.json");
|
|
3594
|
-
if (!existsSync(file)) continue;
|
|
3595
|
-
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3596
|
-
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
3597
|
-
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
3598
|
-
}
|
|
3599
|
-
return { packages };
|
|
3600
|
-
}
|
|
3601
|
-
|
|
3602
|
-
// src/blocks/discover.ts
|
|
3603
|
-
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
3604
|
-
function cliPackageDir() {
|
|
3605
|
-
let dir = path20.dirname(fileURLToPath(import.meta.url));
|
|
3606
|
-
for (; ; ) {
|
|
3607
|
-
const file = path20.join(dir, "package.json");
|
|
3608
|
-
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
3609
|
-
const parent = path20.dirname(dir);
|
|
3610
|
-
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
3611
|
-
dir = parent;
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
function workspacePackagesDir() {
|
|
3615
|
-
const dir = path20.resolve(cliPackageDir(), "..");
|
|
3616
|
-
return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
3617
|
-
}
|
|
3618
|
-
var catalogCache;
|
|
3619
|
-
function readCatalog() {
|
|
3620
|
-
if (catalogCache) return catalogCache;
|
|
3621
|
-
const workspace = workspacePackagesDir();
|
|
3622
|
-
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
3623
|
-
const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
3624
|
-
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
3625
|
-
return catalogCache;
|
|
3626
|
-
}
|
|
3627
|
-
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
3628
|
-
function installedGenesis(root) {
|
|
3629
|
-
const found = /* @__PURE__ */ new Map();
|
|
3630
|
-
let dir = path20.resolve(root);
|
|
3631
|
-
for (; ; ) {
|
|
3632
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
|
|
3633
|
-
const scope = path20.join(dir, "node_modules", "@marktiderman");
|
|
3634
|
-
if (existsSync(scope)) {
|
|
3635
|
-
for (const entry of readdirSync(scope)) {
|
|
3636
|
-
const name = `@marktiderman/${entry}`;
|
|
3637
|
-
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
3638
|
-
if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
const parent = path20.dirname(dir);
|
|
3642
|
-
if (atInstallRoot || parent === dir) return found;
|
|
3643
|
-
dir = parent;
|
|
3644
|
-
}
|
|
3645
|
-
}
|
|
3646
|
-
var declarationCache = /* @__PURE__ */ new Map();
|
|
3647
|
-
function declarationsOf(dir, warnings) {
|
|
3648
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3649
|
-
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
3650
|
-
let cached = declarationCache.get(key2);
|
|
3651
|
-
if (!cached) {
|
|
3652
|
-
cached = loadDeclarations(dir, warnings);
|
|
3653
|
-
declarationCache.set(key2, cached);
|
|
3654
|
-
}
|
|
3655
|
-
return cached;
|
|
3656
|
-
}
|
|
3657
|
-
async function loadDeclarations(dir, warnings) {
|
|
3658
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3659
|
-
const entry = pkg.exports?.["./blocks"];
|
|
3660
|
-
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
3661
|
-
if (typeof target !== "string") return {};
|
|
3662
|
-
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
3663
|
-
const file = rel && path20.join(dir, ...rel.split("/"));
|
|
3664
|
-
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
3665
|
-
try {
|
|
3666
|
-
const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
|
|
3667
|
-
const mod = await jiti.import(file);
|
|
3668
|
-
const out = {};
|
|
3669
|
-
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
3670
|
-
return out;
|
|
3671
|
-
} catch (err) {
|
|
3672
|
-
warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
|
|
3673
|
-
return {};
|
|
3674
|
-
}
|
|
3675
|
-
}
|
|
3676
|
-
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
3677
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3678
|
-
const raw = rawBlocksOf(pkg);
|
|
3679
|
-
const declared = await declarationsOf(dir, warnings);
|
|
3680
|
-
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
3681
|
-
const out = [];
|
|
3682
|
-
for (const id of [...ids].sort()) {
|
|
3683
|
-
const fromJson = raw[id] ?? {};
|
|
3684
|
-
const merged = { ...fromJson, ...declared[id] };
|
|
3685
|
-
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
3686
|
-
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
3687
|
-
if (manifest) out.push(manifest);
|
|
3688
|
-
}
|
|
3689
|
-
return out;
|
|
3690
|
-
}
|
|
3691
|
-
function withProvides(declared, json) {
|
|
3692
|
-
if (!Array.isArray(declared)) return declared;
|
|
3693
|
-
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
3694
|
-
return declared.map((m) => {
|
|
3695
|
-
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
3696
|
-
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
3697
|
-
});
|
|
3698
|
-
}
|
|
3699
|
-
async function allBlocks(root, warnings = []) {
|
|
3700
|
-
const out = [];
|
|
3701
|
-
for (const local of localPackages(root)) {
|
|
3702
|
-
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
3703
|
-
}
|
|
3704
|
-
const installed = installedGenesis(root);
|
|
3705
|
-
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
3706
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
3707
|
-
if (installed.has(name)) continue;
|
|
3708
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
3709
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
3710
|
-
if (manifest) out.push({ manifest, from: "catalog" });
|
|
3729
|
+
};
|
|
3730
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
3731
|
+
const stripped = (file) => {
|
|
3732
|
+
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
3733
|
+
return strippedCache.get(file.absolutePath);
|
|
3734
|
+
};
|
|
3735
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
3736
|
+
const reach = (file, test2, depth, seen) => {
|
|
3737
|
+
let cache2 = memo.get(test2);
|
|
3738
|
+
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
3739
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
3740
|
+
const free = cache2.free.get(k);
|
|
3741
|
+
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
3742
|
+
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
3743
|
+
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
3744
|
+
let result;
|
|
3745
|
+
const cut = /* @__PURE__ */ new Set();
|
|
3746
|
+
const code = stripped(file);
|
|
3747
|
+
if (code === null) result = "unknown";
|
|
3748
|
+
else if (test2(code)) result = "yes";
|
|
3749
|
+
else {
|
|
3750
|
+
const { files, lost } = importsOf(file);
|
|
3751
|
+
let unknown = lost && depth > 0;
|
|
3752
|
+
result = "no";
|
|
3753
|
+
if (depth > 0) {
|
|
3754
|
+
seen.add(file.absolutePath);
|
|
3755
|
+
for (const abs of files) {
|
|
3756
|
+
if (seen.has(abs)) {
|
|
3757
|
+
cut.add(abs);
|
|
3758
|
+
continue;
|
|
3759
|
+
}
|
|
3760
|
+
const target = read2(abs);
|
|
3761
|
+
if (!target) {
|
|
3762
|
+
unknown = true;
|
|
3763
|
+
continue;
|
|
3764
|
+
}
|
|
3765
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
3766
|
+
for (const m of c) cut.add(m);
|
|
3767
|
+
if (r === "yes") {
|
|
3768
|
+
result = "yes";
|
|
3769
|
+
break;
|
|
3770
|
+
}
|
|
3771
|
+
if (r === "unknown") unknown = true;
|
|
3772
|
+
}
|
|
3773
|
+
seen.delete(file.absolutePath);
|
|
3774
|
+
cut.delete(file.absolutePath);
|
|
3775
|
+
}
|
|
3776
|
+
if (result === "no" && unknown) result = "unknown";
|
|
3711
3777
|
}
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
function tryParse(parse2, warnings) {
|
|
3716
|
-
try {
|
|
3717
|
-
return parse2();
|
|
3718
|
-
} catch (err) {
|
|
3719
|
-
if (!(err instanceof ManifestError)) throw err;
|
|
3720
|
-
warnings.push(err.message);
|
|
3721
|
-
return null;
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
function catalogBlocks(warnings = []) {
|
|
3725
|
-
const out = [];
|
|
3726
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
3727
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
3728
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
3729
|
-
if (manifest) out.push(manifest);
|
|
3778
|
+
if (result === "yes" || cut.size === 0) {
|
|
3779
|
+
cache2.free.set(k, result);
|
|
3780
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
3730
3781
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
3738
|
-
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
3739
|
-
}
|
|
3740
|
-
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
3741
|
-
return all[0];
|
|
3782
|
+
const entries = cache2.cut.get(k) ?? [];
|
|
3783
|
+
entries.push({ cut: [...cut], result });
|
|
3784
|
+
cache2.cut.set(k, entries);
|
|
3785
|
+
return [result, cut];
|
|
3786
|
+
};
|
|
3787
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3742
3788
|
}
|
|
3743
3789
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3744
3790
|
var STEMS = {
|
|
@@ -3757,7 +3803,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
3757
3803
|
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;
|
|
3758
3804
|
function routesDir(ctx) {
|
|
3759
3805
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3760
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
3806
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path21.join(ctx.root, d))) ?? null;
|
|
3761
3807
|
}
|
|
3762
3808
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3763
3809
|
function flavorOf(dir, rels) {
|
|
@@ -3892,7 +3938,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3892
3938
|
});
|
|
3893
3939
|
if (typeof raw === "string") {
|
|
3894
3940
|
if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
|
|
3895
|
-
const file =
|
|
3941
|
+
const file = path21.resolve(packageDir, raw);
|
|
3896
3942
|
if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
|
|
3897
3943
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
3898
3944
|
let parsed;
|
|
@@ -3941,7 +3987,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3941
3987
|
if (typeof c.plugin === "string") {
|
|
3942
3988
|
if (!packageDir) plugin = c.plugin;
|
|
3943
3989
|
else {
|
|
3944
|
-
plugin =
|
|
3990
|
+
plugin = path21.resolve(packageDir, c.plugin);
|
|
3945
3991
|
if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
3946
3992
|
}
|
|
3947
3993
|
}
|
|
@@ -3991,7 +4037,7 @@ function checkPattern(v, where2, fail) {
|
|
|
3991
4037
|
}
|
|
3992
4038
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
3993
4039
|
function readDeclaringPackage(dir, local) {
|
|
3994
|
-
const file =
|
|
4040
|
+
const file = path21.join(dir, "package.json");
|
|
3995
4041
|
let stamp;
|
|
3996
4042
|
let real2;
|
|
3997
4043
|
try {
|
|
@@ -4014,7 +4060,7 @@ ${local}`;
|
|
|
4014
4060
|
const pkg = {
|
|
4015
4061
|
name: json.name,
|
|
4016
4062
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
4017
|
-
dir:
|
|
4063
|
+
dir: path21.resolve(dir),
|
|
4018
4064
|
namespace: ruleNamespace(json.name),
|
|
4019
4065
|
local,
|
|
4020
4066
|
private: json.private === true,
|
|
@@ -4028,7 +4074,7 @@ ${local}`;
|
|
|
4028
4074
|
if (raw !== void 0) {
|
|
4029
4075
|
const ignored = [];
|
|
4030
4076
|
try {
|
|
4031
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
4077
|
+
pkg.declaration = validateDeclaration(raw, json.name, path21.resolve(dir), ignored);
|
|
4032
4078
|
if (ignored.length) pkg.ignored = ignored;
|
|
4033
4079
|
} catch (err) {
|
|
4034
4080
|
pkg.error = err.message;
|
|
@@ -4047,14 +4093,14 @@ function discoverPackages(root) {
|
|
|
4047
4093
|
for (const dir of installed) {
|
|
4048
4094
|
let scope;
|
|
4049
4095
|
try {
|
|
4050
|
-
scope =
|
|
4096
|
+
scope = path21.dirname(realpathSync(dir));
|
|
4051
4097
|
} catch {
|
|
4052
4098
|
continue;
|
|
4053
4099
|
}
|
|
4054
|
-
if (
|
|
4100
|
+
if (path21.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
4055
4101
|
for (const entry of readdirSync(scope)) {
|
|
4056
4102
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
4057
|
-
const pkg = readDeclaringPackage(
|
|
4103
|
+
const pkg = readDeclaringPackage(path21.join(scope, entry), false);
|
|
4058
4104
|
if (pkg) byName.set(pkg.name, pkg);
|
|
4059
4105
|
}
|
|
4060
4106
|
}
|
|
@@ -4241,10 +4287,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
4241
4287
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
4242
4288
|
function sourceFiles(dir, rel = "") {
|
|
4243
4289
|
const out = [];
|
|
4244
|
-
for (const entry of readdirSync(
|
|
4290
|
+
for (const entry of readdirSync(path21.join(dir, rel)).sort()) {
|
|
4245
4291
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
4246
4292
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
4247
|
-
const stat = lstatSync(
|
|
4293
|
+
const stat = lstatSync(path21.join(dir, child));
|
|
4248
4294
|
if (stat.isSymbolicLink()) continue;
|
|
4249
4295
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
4250
4296
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -4267,13 +4313,13 @@ function matchPattern(pattern, spec) {
|
|
|
4267
4313
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
4268
4314
|
}
|
|
4269
4315
|
function tsconfigPaths(dir) {
|
|
4270
|
-
const file =
|
|
4316
|
+
const file = path21.join(dir, "tsconfig.json");
|
|
4271
4317
|
if (!existsSync(file)) return [];
|
|
4272
4318
|
try {
|
|
4273
4319
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
4274
4320
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
4275
|
-
const base =
|
|
4276
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
4321
|
+
const base = path21.resolve(dir, options.baseUrl ?? ".");
|
|
4322
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path21.resolve(base, t)) }));
|
|
4277
4323
|
} catch {
|
|
4278
4324
|
return [];
|
|
4279
4325
|
}
|
|
@@ -4287,8 +4333,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4287
4333
|
const hit = matchPattern(pattern, spec);
|
|
4288
4334
|
if (hit === null) continue;
|
|
4289
4335
|
return targets.some((t) => {
|
|
4290
|
-
const rel =
|
|
4291
|
-
return !rel.startsWith("..") && !
|
|
4336
|
+
const rel = path21.relative(pkg.dir, t.replace("*", hit));
|
|
4337
|
+
return !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
4292
4338
|
});
|
|
4293
4339
|
}
|
|
4294
4340
|
return null;
|
|
@@ -4301,7 +4347,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4301
4347
|
...Object.keys(json.optionalDependencies ?? {})
|
|
4302
4348
|
]);
|
|
4303
4349
|
for (const file of sourceFiles(pkg.dir)) {
|
|
4304
|
-
const code = stripForImports(readFileSync(
|
|
4350
|
+
const code = stripForImports(readFileSync(path21.join(pkg.dir, file), "utf8"));
|
|
4305
4351
|
if (code === null) continue;
|
|
4306
4352
|
const at = `${pkg.rel}/${file}`;
|
|
4307
4353
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -4326,9 +4372,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4326
4372
|
continue;
|
|
4327
4373
|
}
|
|
4328
4374
|
if (spec.startsWith(".")) {
|
|
4329
|
-
const target =
|
|
4330
|
-
const rel =
|
|
4331
|
-
if (rel.startsWith("..") ||
|
|
4375
|
+
const target = path21.resolve(pkg.dir, path21.dirname(file), spec);
|
|
4376
|
+
const rel = path21.relative(pkg.dir, target);
|
|
4377
|
+
if (rel.startsWith("..") || path21.isAbsolute(rel)) {
|
|
4332
4378
|
ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} reaches outside its folder (${spec}); move what it needs into the package or a dependency` });
|
|
4333
4379
|
}
|
|
4334
4380
|
continue;
|
|
@@ -4365,12 +4411,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4365
4411
|
const from = own ? "" : ` (in ${m.package})`;
|
|
4366
4412
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
4367
4413
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file}${from} has no pgTAP test; declare one as "test" beside it` });
|
|
4368
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
4414
|
+
} else if (typeof m.test === "string" && !existsSync(path21.join(home, m.test))) {
|
|
4369
4415
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test}${from} doesn't exist` });
|
|
4370
4416
|
}
|
|
4371
4417
|
}
|
|
4372
4418
|
}
|
|
4373
|
-
const dir =
|
|
4419
|
+
const dir = path21.join(pkg.dir, "migrations");
|
|
4374
4420
|
if (!existsSync(dir)) return;
|
|
4375
4421
|
const seen = /* @__PURE__ */ new Map();
|
|
4376
4422
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -4379,21 +4425,21 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4379
4425
|
const other = seen.get(m[1]);
|
|
4380
4426
|
if (other) ctx.report({ rule: "package-migration-number", file: `${pkg.rel}/migrations/${name}`, subject: m[1], message: `${pkg.name}: ${name} and ${other} share the number ${m[1]}; give each migration its own` });
|
|
4381
4427
|
else seen.set(m[1], name);
|
|
4382
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
4428
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path21.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
4383
4429
|
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/migrations/${name}`, subject: name, message: `${pkg.name}: ${name} has no pgTAP test (migrations/tests/${name.replace(/\.sql$/, ".test.sql")})` });
|
|
4384
4430
|
}
|
|
4385
4431
|
}
|
|
4386
4432
|
}
|
|
4387
4433
|
function checkExports(ctx, pkg, json) {
|
|
4388
4434
|
const targets = [];
|
|
4389
|
-
const
|
|
4435
|
+
const walk3 = (v) => {
|
|
4390
4436
|
if (typeof v === "string") targets.push(v);
|
|
4391
|
-
else if (v && typeof v === "object") for (const x of Object.values(v))
|
|
4437
|
+
else if (v && typeof v === "object") for (const x of Object.values(v)) walk3(x);
|
|
4392
4438
|
};
|
|
4393
|
-
|
|
4439
|
+
walk3(json.exports);
|
|
4394
4440
|
for (const t of targets) {
|
|
4395
4441
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
4396
|
-
if (!existsSync(
|
|
4442
|
+
if (!existsSync(path21.join(pkg.dir, t))) {
|
|
4397
4443
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
4398
4444
|
}
|
|
4399
4445
|
}
|
|
@@ -4411,11 +4457,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
4411
4457
|
function checkTaggedTests(ctx, pkg) {
|
|
4412
4458
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
4413
4459
|
if (!tests.length) return;
|
|
4414
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
4460
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path21.join(pkg.dir, f), "utf8")));
|
|
4415
4461
|
if (!tagged) ctx.report({ rule: "package-untagged-tests", level: "warn", file: pkg.rel, message: `${pkg.name}'s tests name no feature; tag them with // @feat:<feature id>` });
|
|
4416
4462
|
}
|
|
4417
4463
|
function checkRegistered(ctx, pkg) {
|
|
4418
|
-
const file =
|
|
4464
|
+
const file = path21.join(ctx.root, "features.json");
|
|
4419
4465
|
if (!existsSync(file)) return;
|
|
4420
4466
|
let doc;
|
|
4421
4467
|
try {
|
|
@@ -4425,7 +4471,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
4425
4471
|
}
|
|
4426
4472
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4427
4473
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
4428
|
-
if (top) forms.add(
|
|
4474
|
+
if (top) forms.add(path21.relative(top, realpathSync(pkg.dir)).split(path21.sep).join("/"));
|
|
4429
4475
|
const covered = (doc.features ?? []).some(
|
|
4430
4476
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
4431
4477
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -4455,8 +4501,8 @@ function mergeBaseOf(root, base) {
|
|
|
4455
4501
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
4456
4502
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4457
4503
|
if (!top) return;
|
|
4458
|
-
const appRelative = (fromTop) =>
|
|
4459
|
-
const inRepo =
|
|
4504
|
+
const appRelative = (fromTop) => path21.relative(realpathSync(ctx.root), path21.join(top, fromTop)).split(path21.sep).join("/");
|
|
4505
|
+
const inRepo = path21.relative(top, realpathSync(pkg.dir)).split(path21.sep).join("/");
|
|
4460
4506
|
const diff = (git(top, ["diff", "--name-status", "-M", mergeBase, "--", inRepo]) ?? "").split("\n").filter(Boolean).map((row) => row.split(" ").map((cell2, i) => i === 0 ? cell2 : appRelative(cell2)).join(" ")).join("\n");
|
|
4461
4507
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
4462
4508
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -4479,11 +4525,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4479
4525
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
4480
4526
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
4481
4527
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
4482
|
-
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) =>
|
|
4528
|
+
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path21.join(top, f)) : [];
|
|
4483
4529
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
4484
4530
|
const named = naming.length > 0;
|
|
4485
4531
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
4486
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
4532
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path21.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
4487
4533
|
}
|
|
4488
4534
|
let jsonBefore = null;
|
|
4489
4535
|
try {
|
|
@@ -4493,7 +4539,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4493
4539
|
}
|
|
4494
4540
|
const raw = json;
|
|
4495
4541
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
4496
|
-
const appInRepo =
|
|
4542
|
+
const appInRepo = path21.relative(top, realpathSync(ctx.root)).split(path21.sep).join("/");
|
|
4497
4543
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
4498
4544
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
4499
4545
|
if (!registry) ctx.report({ rule: "package-unversioned-change", level: "warn", file: `${pkg.rel}/package.json`, message: `${pkg.name}'s blocks or exports changed but features.ts didn't; update the features they belong to` });
|
|
@@ -4545,7 +4591,7 @@ function checkPackagesPack(ctx) {
|
|
|
4545
4591
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
4546
4592
|
}
|
|
4547
4593
|
for (const pkg of packages) {
|
|
4548
|
-
const json = JSON.parse(readFileSync(
|
|
4594
|
+
const json = JSON.parse(readFileSync(path21.join(pkg.dir, "package.json"), "utf8"));
|
|
4549
4595
|
checkImports2(ctx, pkg, json);
|
|
4550
4596
|
checkExports(ctx, pkg, json);
|
|
4551
4597
|
checkBlocks(ctx, pkg, json);
|
|
@@ -4562,7 +4608,7 @@ function emptyLock() {
|
|
|
4562
4608
|
return { version: 1, blocks: {}, files: {} };
|
|
4563
4609
|
}
|
|
4564
4610
|
function readLock(root) {
|
|
4565
|
-
const file =
|
|
4611
|
+
const file = path21.join(root, LOCK_FILE);
|
|
4566
4612
|
if (!existsSync(file)) return emptyLock();
|
|
4567
4613
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
4568
4614
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -4585,11 +4631,11 @@ function databaseElsewhere(root) {
|
|
|
4585
4631
|
const setting = readGenesisConfig(root)?.supabase;
|
|
4586
4632
|
if (setting === void 0) return null;
|
|
4587
4633
|
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
4588
|
-
const resolved =
|
|
4634
|
+
const resolved = path21.resolve(root, setting.app);
|
|
4589
4635
|
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
4590
4636
|
const dir = real2(resolved);
|
|
4591
|
-
if (dir === real2(
|
|
4592
|
-
return { app: setting.app, dir, hasSupabase: existsSync(
|
|
4637
|
+
if (dir === real2(path21.resolve(root))) throw new GenesisConfigError(`${path21.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
|
|
4638
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path21.join(dir, "supabase")) };
|
|
4593
4639
|
}
|
|
4594
4640
|
function isSupabasePath(rel) {
|
|
4595
4641
|
return rel === "supabase" || rel.startsWith("supabase/");
|
|
@@ -4779,9 +4825,9 @@ function checkSupabasePack(ctx) {
|
|
|
4779
4825
|
if (databaseElsewhere(ctx.root)) return;
|
|
4780
4826
|
const settings = ctx.config.supabase ?? {};
|
|
4781
4827
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
4782
|
-
const abs =
|
|
4828
|
+
const abs = path21.join(ctx.root, dir);
|
|
4783
4829
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
4784
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
4830
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path21.join(abs, n), "utf8")) }));
|
|
4785
4831
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
4786
4832
|
const base = settings.base ?? DEFAULT_BASE;
|
|
4787
4833
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -4798,7 +4844,7 @@ function checkSupabasePack(ctx) {
|
|
|
4798
4844
|
}
|
|
4799
4845
|
}
|
|
4800
4846
|
const since = settings.since;
|
|
4801
|
-
const afterSince = (file) => since === void 0 ||
|
|
4847
|
+
const afterSince = (file) => since === void 0 || path21.posix.basename(file) >= since;
|
|
4802
4848
|
if ("reason" in view && since === void 0) {
|
|
4803
4849
|
ctx.report({
|
|
4804
4850
|
rule: "migration-grants",
|
|
@@ -5081,7 +5127,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
|
5081
5127
|
var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
5082
5128
|
var readManifest = (dir) => {
|
|
5083
5129
|
try {
|
|
5084
|
-
return JSON.parse(readFileSync(
|
|
5130
|
+
return JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
5085
5131
|
} catch {
|
|
5086
5132
|
return null;
|
|
5087
5133
|
}
|
|
@@ -5095,18 +5141,18 @@ var real = (p) => {
|
|
|
5095
5141
|
};
|
|
5096
5142
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
5097
5143
|
function nodeModulesOf(dir) {
|
|
5098
|
-
const parent =
|
|
5099
|
-
return
|
|
5144
|
+
const parent = path21.dirname(dir);
|
|
5145
|
+
return path21.basename(parent).startsWith("@") ? path21.dirname(parent) : parent;
|
|
5100
5146
|
}
|
|
5101
5147
|
function packagesIn(nodeModules) {
|
|
5102
5148
|
if (!existsSync(nodeModules)) return [];
|
|
5103
5149
|
const out = [];
|
|
5104
5150
|
for (const entry of readdirSync(nodeModules)) {
|
|
5105
5151
|
if (entry.startsWith(".")) continue;
|
|
5106
|
-
const p =
|
|
5152
|
+
const p = path21.join(nodeModules, entry);
|
|
5107
5153
|
if (entry.startsWith("@")) {
|
|
5108
5154
|
try {
|
|
5109
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5155
|
+
for (const sub of readdirSync(p)) out.push(path21.join(p, sub));
|
|
5110
5156
|
} catch {
|
|
5111
5157
|
}
|
|
5112
5158
|
} else {
|
|
@@ -5118,7 +5164,7 @@ function packagesIn(nodeModules) {
|
|
|
5118
5164
|
function genesisInstalls(root) {
|
|
5119
5165
|
const copies = /* @__PURE__ */ new Map();
|
|
5120
5166
|
const realRoot = real(root);
|
|
5121
|
-
const rel = (abs) =>
|
|
5167
|
+
const rel = (abs) => path21.relative(realRoot, abs).split(path21.sep).join("/") || ".";
|
|
5122
5168
|
const via = /* @__PURE__ */ new Map();
|
|
5123
5169
|
const record = (real2, manifest, by, range, root2) => {
|
|
5124
5170
|
let copy = copies.get(real2);
|
|
@@ -5130,7 +5176,7 @@ function genesisInstalls(root) {
|
|
|
5130
5176
|
via.get(real2).add(root2);
|
|
5131
5177
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
5132
5178
|
};
|
|
5133
|
-
const
|
|
5179
|
+
const walk3 = (kind, roots) => {
|
|
5134
5180
|
const expanded = /* @__PURE__ */ new Set();
|
|
5135
5181
|
const queue = [];
|
|
5136
5182
|
const visit = (dir, by, range) => {
|
|
@@ -5163,7 +5209,7 @@ function genesisInstalls(root) {
|
|
|
5163
5209
|
if (!dir) return null;
|
|
5164
5210
|
if (!ownInstall || name in declared) return dir;
|
|
5165
5211
|
const realDir = real(dir);
|
|
5166
|
-
if (realDir.startsWith(realRoot +
|
|
5212
|
+
if (realDir.startsWith(realRoot + path21.sep)) return dir;
|
|
5167
5213
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
5168
5214
|
};
|
|
5169
5215
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -5171,7 +5217,7 @@ function genesisInstalls(root) {
|
|
|
5171
5217
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
5172
5218
|
});
|
|
5173
5219
|
const app = readManifest(root);
|
|
5174
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5220
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path21.join(root, f)));
|
|
5175
5221
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
5176
5222
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
5177
5223
|
const runtimeDeps = {
|
|
@@ -5181,18 +5227,18 @@ function genesisInstalls(root) {
|
|
|
5181
5227
|
...app?.dependencies
|
|
5182
5228
|
};
|
|
5183
5229
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
5184
|
-
|
|
5185
|
-
const top =
|
|
5186
|
-
|
|
5230
|
+
walk3("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5231
|
+
const top = path21.join(root, "node_modules");
|
|
5232
|
+
walk3(
|
|
5187
5233
|
"hoisted",
|
|
5188
5234
|
packagesIn(top).filter((dir) => {
|
|
5189
|
-
const name =
|
|
5235
|
+
const name = path21.relative(top, dir).split(path21.sep).join("/");
|
|
5190
5236
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
5191
5237
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
5192
5238
|
);
|
|
5193
5239
|
const devRoots = { ...devDeps };
|
|
5194
5240
|
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
5195
|
-
|
|
5241
|
+
walk3("dev", rootsOf(devRoots, "the app (dev)"));
|
|
5196
5242
|
for (const [key2, copy] of copies) {
|
|
5197
5243
|
const kinds = via.get(key2);
|
|
5198
5244
|
copy.runtime = kinds.has("runtime");
|
|
@@ -5228,7 +5274,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
5228
5274
|
}
|
|
5229
5275
|
}
|
|
5230
5276
|
function checkPeerRanges(ctx) {
|
|
5231
|
-
const rel = (abs) =>
|
|
5277
|
+
const rel = (abs) => path21.relative(ctx.root, abs).split(path21.sep).join("/");
|
|
5232
5278
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
5233
5279
|
for (const copy of copies) {
|
|
5234
5280
|
const dir = copy.absolutePath;
|
|
@@ -5415,6 +5461,24 @@ function checkIsoDateSlices(ctx) {
|
|
|
5415
5461
|
}
|
|
5416
5462
|
}
|
|
5417
5463
|
}
|
|
5464
|
+
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
5465
|
+
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
5466
|
+
var MAX_BYTES = 2 * 1024 * 1024;
|
|
5467
|
+
function appScripts(root) {
|
|
5468
|
+
const out = [];
|
|
5469
|
+
const walk3 = (dir) => {
|
|
5470
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5471
|
+
const abs = path21.join(dir, entry.name);
|
|
5472
|
+
if (entry.isDirectory()) {
|
|
5473
|
+
if (!SKIP_DIRS3.has(entry.name)) walk3(abs);
|
|
5474
|
+
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
5475
|
+
out.push(path21.relative(root, abs).split(path21.sep).join("/"));
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
};
|
|
5479
|
+
walk3(root);
|
|
5480
|
+
return out;
|
|
5481
|
+
}
|
|
5418
5482
|
|
|
5419
5483
|
// src/upgrade/scope-names.ts
|
|
5420
5484
|
var IMPORTS_GENESIS = /\bfrom\s*["']@marktiderman\/genesis[\w/-]*["']/;
|
|
@@ -5609,11 +5673,11 @@ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
|
|
|
5609
5673
|
var TESTING_LIBRARY = "eslint-plugin-testing-library";
|
|
5610
5674
|
var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
|
|
5611
5675
|
function findEslintConfig(root) {
|
|
5612
|
-
return FLAT_CONFIG_FILES.find((name) => existsSync(
|
|
5676
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path21.join(root, name))) ?? null;
|
|
5613
5677
|
}
|
|
5614
5678
|
function readPackageJson(root) {
|
|
5615
5679
|
try {
|
|
5616
|
-
return JSON.parse(readFileSync(
|
|
5680
|
+
return JSON.parse(readFileSync(path21.join(root, "package.json"), "utf8"));
|
|
5617
5681
|
} catch {
|
|
5618
5682
|
return null;
|
|
5619
5683
|
}
|
|
@@ -5629,26 +5693,6 @@ function usesGenesisLint(text) {
|
|
|
5629
5693
|
return text.includes(ESLINT_EXPORT);
|
|
5630
5694
|
}
|
|
5631
5695
|
|
|
5632
|
-
// src/upgrade/codemods.ts
|
|
5633
|
-
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
5634
|
-
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
5635
|
-
var MAX_BYTES = 2 * 1024 * 1024;
|
|
5636
|
-
function appScripts(root) {
|
|
5637
|
-
const out = [];
|
|
5638
|
-
const walk2 = (dir) => {
|
|
5639
|
-
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5640
|
-
const abs = path20.join(dir, entry.name);
|
|
5641
|
-
if (entry.isDirectory()) {
|
|
5642
|
-
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
5643
|
-
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
5644
|
-
out.push(path20.relative(root, abs).split(path20.sep).join("/"));
|
|
5645
|
-
}
|
|
5646
|
-
}
|
|
5647
|
-
};
|
|
5648
|
-
walk2(root);
|
|
5649
|
-
return out;
|
|
5650
|
-
}
|
|
5651
|
-
|
|
5652
5696
|
// src/doctor/api-usage.ts
|
|
5653
5697
|
var SCRIPT_EXTS5 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
5654
5698
|
function openingTag(code, start) {
|
|
@@ -5729,7 +5773,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
5729
5773
|
function moduleFiles(ctx) {
|
|
5730
5774
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
5731
5775
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
5732
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
5776
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path21.join(ctx.root, rel), "utf8"), true) }));
|
|
5733
5777
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
5734
5778
|
}
|
|
5735
5779
|
function checkStudioServerImports(ctx) {
|
|
@@ -5765,7 +5809,7 @@ var REMOVED_WORDS = {
|
|
|
5765
5809
|
};
|
|
5766
5810
|
function checkRemovedScopeNames(ctx) {
|
|
5767
5811
|
let augmentedMemo;
|
|
5768
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
5812
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path21.join(ctx.root, rel), "utf8")));
|
|
5769
5813
|
for (const file of ctx.files) {
|
|
5770
5814
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
5771
5815
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -5837,16 +5881,16 @@ function genesisNamedImports(source) {
|
|
|
5837
5881
|
}
|
|
5838
5882
|
function declarationFiles(dir, out = []) {
|
|
5839
5883
|
for (const name of readdirSync(dir)) {
|
|
5840
|
-
const full =
|
|
5884
|
+
const full = path21.join(dir, name);
|
|
5841
5885
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
5842
5886
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
5843
5887
|
}
|
|
5844
5888
|
return out;
|
|
5845
5889
|
}
|
|
5846
5890
|
function readPackageTags(dir) {
|
|
5847
|
-
const pkg = JSON.parse(readFileSync(
|
|
5891
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
5848
5892
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
5849
|
-
const dist =
|
|
5893
|
+
const dist = path21.join(dir, "dist");
|
|
5850
5894
|
if (!existsSync(dist)) return tags;
|
|
5851
5895
|
for (const file of declarationFiles(dist)) {
|
|
5852
5896
|
const text = readFileSync(file, "utf8");
|
|
@@ -5864,7 +5908,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
5864
5908
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
5865
5909
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
5866
5910
|
const types = typeof target === "object" && target ? target.types : null;
|
|
5867
|
-
return typeof types === "string" ?
|
|
5911
|
+
return typeof types === "string" ? path21.join(tags.dir, types) : null;
|
|
5868
5912
|
}
|
|
5869
5913
|
function tagFor(tags, entry, name) {
|
|
5870
5914
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -5919,7 +5963,7 @@ function showAt(dir, rev, file) {
|
|
|
5919
5963
|
function configAtBase(root, base, explicitFile) {
|
|
5920
5964
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
5921
5965
|
if (!mergeBase) return null;
|
|
5922
|
-
const candidates = explicitFile ? [{ dir:
|
|
5966
|
+
const candidates = explicitFile ? [{ dir: path21.dirname(explicitFile), file: path21.basename(explicitFile), explicit: true }] : [
|
|
5923
5967
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
5924
5968
|
{ dir: root, file: "package.json", explicit: false }
|
|
5925
5969
|
];
|
|
@@ -6031,7 +6075,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6031
6075
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
6032
6076
|
let current = null;
|
|
6033
6077
|
try {
|
|
6034
|
-
current = lf(readFileSync(
|
|
6078
|
+
current = lf(readFileSync(path21.join(ctx.root, out), "utf8"));
|
|
6035
6079
|
} catch {
|
|
6036
6080
|
current = null;
|
|
6037
6081
|
}
|
|
@@ -6055,7 +6099,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6055
6099
|
ctx.report({ rule: "contracts-stale", level: generation ? "error" : "warn", file: out, message: generation ? `couldn't be generated: ${message}` : `couldn't read the database through ${env}: ${message}` });
|
|
6056
6100
|
return;
|
|
6057
6101
|
}
|
|
6058
|
-
const target =
|
|
6102
|
+
const target = path21.relative(process.cwd(), path21.join(ctx.root, out)) || out;
|
|
6059
6103
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
6060
6104
|
if (current !== expected) {
|
|
6061
6105
|
ctx.report({
|
|
@@ -6069,7 +6113,7 @@ var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
|
|
|
6069
6113
|
var CORE = [
|
|
6070
6114
|
{
|
|
6071
6115
|
need: "anything, before building it",
|
|
6072
|
-
use: 'search what exists: `genesis features find <term>`, this catalog, and the
|
|
6116
|
+
use: 'search what exists: `genesis features find <term>`, this catalog, and the "Available but unused" list in `genesis doctor --verbose`',
|
|
6073
6117
|
docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
|
|
6074
6118
|
from: "genesis-cli"
|
|
6075
6119
|
},
|
|
@@ -6218,13 +6262,13 @@ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
|
6218
6262
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
6219
6263
|
const rows = primitivesCatalog(packages);
|
|
6220
6264
|
const changed = [];
|
|
6221
|
-
const agents =
|
|
6265
|
+
const agents = path21.join(root, agentsFile);
|
|
6222
6266
|
const before = read(agents);
|
|
6223
6267
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
6224
|
-
const skill =
|
|
6268
|
+
const skill = path21.join(root, SKILL_PATH);
|
|
6225
6269
|
const skillText = renderSkill(rows);
|
|
6226
6270
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
6227
|
-
mkdirSync(
|
|
6271
|
+
mkdirSync(path21.dirname(skill), { recursive: true });
|
|
6228
6272
|
writeFileSync(skill, skillText);
|
|
6229
6273
|
changed.push(SKILL_PATH);
|
|
6230
6274
|
}
|
|
@@ -6236,8 +6280,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
6236
6280
|
}
|
|
6237
6281
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6238
6282
|
const rows = primitivesCatalog(packages);
|
|
6239
|
-
const skill = read(
|
|
6240
|
-
const block = currentAgentsBlock(read(
|
|
6283
|
+
const skill = read(path21.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
6284
|
+
const block = currentAgentsBlock(read(path21.join(root, agentsFile)));
|
|
6241
6285
|
return {
|
|
6242
6286
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6243
6287
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -6259,36 +6303,14 @@ function checkAgentGuide(ctx) {
|
|
|
6259
6303
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6260
6304
|
}
|
|
6261
6305
|
}
|
|
6262
|
-
var CLI = "@marktiderman/genesis-cli";
|
|
6263
|
-
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6264
|
-
let parsed;
|
|
6265
|
-
try {
|
|
6266
|
-
parsed = parseSource(source);
|
|
6267
|
-
} catch (err) {
|
|
6268
|
-
return err instanceof Error ? err.message : String(err);
|
|
6269
|
-
}
|
|
6270
|
-
const { package: pkg, path: rel } = parsed;
|
|
6271
|
-
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6272
|
-
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6273
|
-
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6274
|
-
const base = rel.split("/").pop();
|
|
6275
|
-
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6276
|
-
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6277
|
-
}
|
|
6278
|
-
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6279
|
-
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6280
|
-
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6281
|
-
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6282
|
-
return `${key2} doesn't match its source ${source}`;
|
|
6283
|
-
}
|
|
6284
6306
|
|
|
6285
6307
|
// src/blocks/templates.ts
|
|
6286
6308
|
function starterDir() {
|
|
6287
6309
|
const workspace = workspacePackagesDir();
|
|
6288
|
-
const live = workspace &&
|
|
6289
|
-
if (live && existsSync(
|
|
6290
|
-
const packaged =
|
|
6291
|
-
if (existsSync(
|
|
6310
|
+
const live = workspace && path21.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
6311
|
+
if (live && existsSync(path21.join(live, "package.json"))) return live;
|
|
6312
|
+
const packaged = path21.join(cliPackageDir(), "dist", "starter");
|
|
6313
|
+
if (existsSync(path21.join(packaged, "package.json"))) return packaged;
|
|
6292
6314
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
6293
6315
|
}
|
|
6294
6316
|
|
|
@@ -6362,7 +6384,7 @@ function readText(file) {
|
|
|
6362
6384
|
}
|
|
6363
6385
|
function starterBlockMap(root) {
|
|
6364
6386
|
if (root) {
|
|
6365
|
-
const file =
|
|
6387
|
+
const file = path21.join(root, GENESIS_CONFIG);
|
|
6366
6388
|
const text2 = readText(file);
|
|
6367
6389
|
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
6368
6390
|
if (own) return own;
|
|
@@ -6373,7 +6395,7 @@ function starterBlockMap(root) {
|
|
|
6373
6395
|
} catch {
|
|
6374
6396
|
return {};
|
|
6375
6397
|
}
|
|
6376
|
-
const text = readText(
|
|
6398
|
+
const text = readText(path21.join(dir, GENESIS_CONFIG));
|
|
6377
6399
|
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
6378
6400
|
}
|
|
6379
6401
|
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
@@ -6393,10 +6415,10 @@ function blocksSwitchedOff(switches, map, manifests, present) {
|
|
|
6393
6415
|
return off;
|
|
6394
6416
|
}
|
|
6395
6417
|
function appBlocksSwitchedOff(root, manifests, present) {
|
|
6396
|
-
const text = readText(
|
|
6418
|
+
const text = readText(path21.join(root, STARTER_CONFIG));
|
|
6397
6419
|
const switches = text === null ? null : parseStarterFeatures(text);
|
|
6398
6420
|
if (!switches) return /* @__PURE__ */ new Map();
|
|
6399
|
-
return blocksSwitchedOff(switches, starterBlockMap(existsSync(
|
|
6421
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path21.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
6400
6422
|
}
|
|
6401
6423
|
function blockOfSource(source, manifests) {
|
|
6402
6424
|
const at = source.indexOf(":");
|
|
@@ -6409,6 +6431,34 @@ function blockOfSource(source, manifests) {
|
|
|
6409
6431
|
}
|
|
6410
6432
|
return null;
|
|
6411
6433
|
}
|
|
6434
|
+
|
|
6435
|
+
// src/blocks/app-folder.ts
|
|
6436
|
+
function appFolderOf(root) {
|
|
6437
|
+
return readGenesisConfig(root)?.appFolder ?? null;
|
|
6438
|
+
}
|
|
6439
|
+
var isRepositoryWorkflow = (rel) => rel.startsWith(".github/workflows/");
|
|
6440
|
+
var CLI = "@marktiderman/genesis-cli";
|
|
6441
|
+
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6442
|
+
let parsed;
|
|
6443
|
+
try {
|
|
6444
|
+
parsed = parseSource(source);
|
|
6445
|
+
} catch (err) {
|
|
6446
|
+
return err instanceof Error ? err.message : String(err);
|
|
6447
|
+
}
|
|
6448
|
+
const { package: pkg, path: rel } = parsed;
|
|
6449
|
+
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6450
|
+
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6451
|
+
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6452
|
+
const base = rel.split("/").pop();
|
|
6453
|
+
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6454
|
+
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6455
|
+
}
|
|
6456
|
+
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6457
|
+
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6458
|
+
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6459
|
+
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6460
|
+
return `${key2} doesn't match its source ${source}`;
|
|
6461
|
+
}
|
|
6412
6462
|
var BUN_LOCK = "bun.lock";
|
|
6413
6463
|
var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
|
|
6414
6464
|
var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
|
|
@@ -6541,21 +6591,9 @@ function staleNestedEntries(text, want = () => null) {
|
|
|
6541
6591
|
return out;
|
|
6542
6592
|
}
|
|
6543
6593
|
function readBunLock(dir) {
|
|
6544
|
-
const file =
|
|
6594
|
+
const file = path21.join(dir, BUN_LOCK);
|
|
6545
6595
|
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6546
6596
|
}
|
|
6547
|
-
function findLockfile(root) {
|
|
6548
|
-
let dir = path20.resolve(root);
|
|
6549
|
-
for (; ; ) {
|
|
6550
|
-
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
6551
|
-
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
6552
|
-
if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
6553
|
-
if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
6554
|
-
const parent = path20.dirname(dir);
|
|
6555
|
-
if (parent === dir) return null;
|
|
6556
|
-
dir = parent;
|
|
6557
|
-
}
|
|
6558
|
-
}
|
|
6559
6597
|
|
|
6560
6598
|
// src/doctor/lock-files.ts
|
|
6561
6599
|
function checkBunLock(ctx) {
|
|
@@ -6563,7 +6601,7 @@ function checkBunLock(ctx) {
|
|
|
6563
6601
|
if (found?.pm !== "bun") return;
|
|
6564
6602
|
const text = readBunLock(found.dir);
|
|
6565
6603
|
if (text === null) return;
|
|
6566
|
-
const file =
|
|
6604
|
+
const file = path21.relative(ctx.root, path21.join(found.dir, BUN_LOCK)).split(path21.sep).join("/");
|
|
6567
6605
|
let stale;
|
|
6568
6606
|
try {
|
|
6569
6607
|
stale = staleNestedEntries(text);
|
|
@@ -6582,7 +6620,7 @@ function checkBunLock(ctx) {
|
|
|
6582
6620
|
}
|
|
6583
6621
|
async function checkLockFiles(ctx) {
|
|
6584
6622
|
checkBunLock(ctx);
|
|
6585
|
-
if (!existsSync(
|
|
6623
|
+
if (!existsSync(path21.join(ctx.root, LOCK_FILE))) return;
|
|
6586
6624
|
let lock;
|
|
6587
6625
|
try {
|
|
6588
6626
|
lock = readLock(ctx.root);
|
|
@@ -6615,6 +6653,11 @@ async function checkLockFiles(ctx) {
|
|
|
6615
6653
|
home = databaseElsewhere(ctx.root);
|
|
6616
6654
|
} catch {
|
|
6617
6655
|
}
|
|
6656
|
+
let appFolder = null;
|
|
6657
|
+
try {
|
|
6658
|
+
appFolder = appFolderOf(ctx.root);
|
|
6659
|
+
} catch {
|
|
6660
|
+
}
|
|
6618
6661
|
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
6619
6662
|
if (home && elsewhere.length) {
|
|
6620
6663
|
ctx.report({
|
|
@@ -6650,6 +6693,7 @@ async function checkLockFiles(ctx) {
|
|
|
6650
6693
|
}
|
|
6651
6694
|
if (text === null) {
|
|
6652
6695
|
if (entry.deleted) continue;
|
|
6696
|
+
if (appFolder && isRepositoryWorkflow(rel)) continue;
|
|
6653
6697
|
ctx.report({
|
|
6654
6698
|
rule: "lock-files",
|
|
6655
6699
|
level: "warn",
|
|
@@ -6684,7 +6728,7 @@ function checkDatabaseHome(ctx) {
|
|
|
6684
6728
|
message: `supabase.app is ${home.app}, which has no supabase folder; name the app that holds this app's database (its migrations, tests and Edge Functions)`
|
|
6685
6729
|
});
|
|
6686
6730
|
}
|
|
6687
|
-
if (existsSync(
|
|
6731
|
+
if (existsSync(path21.join(ctx.root, "supabase"))) {
|
|
6688
6732
|
ctx.report({
|
|
6689
6733
|
rule: "database-elsewhere",
|
|
6690
6734
|
level: "warn",
|
|
@@ -6702,7 +6746,7 @@ function checkEslintConfig(ctx) {
|
|
|
6702
6746
|
if (!file) return;
|
|
6703
6747
|
let text;
|
|
6704
6748
|
try {
|
|
6705
|
-
text = readFileSync(
|
|
6749
|
+
text = readFileSync(path21.join(ctx.root, file), "utf8");
|
|
6706
6750
|
} catch {
|
|
6707
6751
|
return;
|
|
6708
6752
|
}
|
|
@@ -6722,11 +6766,352 @@ function checkEslintConfig(ctx) {
|
|
|
6722
6766
|
subject: TESTING_LIBRARY,
|
|
6723
6767
|
message: `${file} loads Genesis's native lint rules, which need ${TESTING_LIBRARY}: add it to devDependencies (pnpm add -D ${TESTING_LIBRARY}), or the lint can't load its config`
|
|
6724
6768
|
});
|
|
6769
|
+
} else if (!findPackageDir(ctx.root, TESTING_LIBRARY)) {
|
|
6770
|
+
ctx.report({
|
|
6771
|
+
rule: "genesis-eslint-config",
|
|
6772
|
+
level: "warn",
|
|
6773
|
+
file: "package.json",
|
|
6774
|
+
subject: TESTING_LIBRARY,
|
|
6775
|
+
message: `lists ${TESTING_LIBRARY}, which ${file} needs, but it isn't installed, so the lint can't load its config: run ${shellLine(installCommand(detectPackageManager(ctx.root)))}`
|
|
6776
|
+
});
|
|
6777
|
+
}
|
|
6778
|
+
}
|
|
6779
|
+
var FigmaConfigError = class extends Error {
|
|
6780
|
+
};
|
|
6781
|
+
function validateFigmaConfig(raw, source = "genesis.config.json") {
|
|
6782
|
+
const obj = raw;
|
|
6783
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) throw new FigmaConfigError(`${source}: figma must be an object`);
|
|
6784
|
+
if (typeof obj.file !== "string" || !/^[A-Za-z0-9]+$/.test(obj.file)) throw new FigmaConfigError(`${source}: figma.file must be the file key (letters and digits, from the file's URL)`);
|
|
6785
|
+
const pages = obj.pages;
|
|
6786
|
+
if (!pages || typeof pages !== "object" || Array.isArray(pages)) throw new FigmaConfigError(`${source}: figma.pages must be { "web"?: "<page>", "native"?: "<page>" }`);
|
|
6787
|
+
const out = {};
|
|
6788
|
+
for (const [k, v] of Object.entries(pages)) {
|
|
6789
|
+
if (k !== "web" && k !== "native") throw new FigmaConfigError(`${source}: figma.pages.${k}: only "web" and "native"`);
|
|
6790
|
+
if (typeof v !== "string" || !v) throw new FigmaConfigError(`${source}: figma.pages.${k} must be a page name`);
|
|
6791
|
+
out[k] = v;
|
|
6792
|
+
}
|
|
6793
|
+
if (!out.web && !out.native) throw new FigmaConfigError(`${source}: figma.pages needs "web" or "native"`);
|
|
6794
|
+
if (obj.proposalsPage !== void 0 && (typeof obj.proposalsPage !== "string" || !obj.proposalsPage)) throw new FigmaConfigError(`${source}: figma.proposalsPage must be a page name`);
|
|
6795
|
+
return { file: obj.file, pages: out, proposalsPage: obj.proposalsPage ?? "Proposals" };
|
|
6796
|
+
}
|
|
6797
|
+
function readFigmaConfig(root) {
|
|
6798
|
+
const file = path21.join(root, "genesis.config.json");
|
|
6799
|
+
if (!existsSync(file)) return null;
|
|
6800
|
+
let raw;
|
|
6801
|
+
try {
|
|
6802
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
6803
|
+
} catch (err) {
|
|
6804
|
+
throw new FigmaConfigError(`${file} isn't valid JSON: ${err.message}`);
|
|
6805
|
+
}
|
|
6806
|
+
return raw?.figma === void 0 ? null : validateFigmaConfig(raw.figma, file);
|
|
6807
|
+
}
|
|
6808
|
+
var CODE = /\.(?:tsx|ts|jsx|js)$/;
|
|
6809
|
+
var FIGMA_ID = /^\s*\/\/\s*figma:\s*(\d+[:-]\d+)\s*$/;
|
|
6810
|
+
function walk2(dir, out = []) {
|
|
6811
|
+
if (!existsSync(dir)) return out;
|
|
6812
|
+
for (const name of readdirSync(dir).sort()) {
|
|
6813
|
+
if (name === "node_modules" || name.startsWith(".")) continue;
|
|
6814
|
+
const full = path21.join(dir, name);
|
|
6815
|
+
if (statSync(full).isDirectory()) walk2(full, out);
|
|
6816
|
+
else if (CODE.test(name) && !/\.(?:test|spec|d)\.[jt]sx?$/.test(name)) out.push(full);
|
|
6817
|
+
}
|
|
6818
|
+
return out;
|
|
6819
|
+
}
|
|
6820
|
+
function figmaIdOf(code) {
|
|
6821
|
+
for (const line of code.split("\n").slice(0, 5)) {
|
|
6822
|
+
const m = FIGMA_ID.exec(line);
|
|
6823
|
+
if (m) return m[1].replace("-", ":");
|
|
6824
|
+
}
|
|
6825
|
+
return void 0;
|
|
6826
|
+
}
|
|
6827
|
+
function tanstackSegments(stem) {
|
|
6828
|
+
const out = [];
|
|
6829
|
+
let cur = "";
|
|
6830
|
+
let depth = 0;
|
|
6831
|
+
for (const ch of stem) {
|
|
6832
|
+
if (ch === "{") depth++;
|
|
6833
|
+
if (ch === "}") depth--;
|
|
6834
|
+
if (ch === "." && depth === 0) {
|
|
6835
|
+
out.push(cur);
|
|
6836
|
+
cur = "";
|
|
6837
|
+
} else cur += ch;
|
|
6838
|
+
}
|
|
6839
|
+
out.push(cur);
|
|
6840
|
+
return out;
|
|
6841
|
+
}
|
|
6842
|
+
function expoRoot(root) {
|
|
6843
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path21.join(root, dir))) return dir;
|
|
6844
|
+
return null;
|
|
6845
|
+
}
|
|
6846
|
+
function appRoutes(root) {
|
|
6847
|
+
const out = [];
|
|
6848
|
+
const rel = (f) => path21.relative(root, f).split(path21.sep).join("/");
|
|
6849
|
+
const expo = expoRoot(root);
|
|
6850
|
+
if (expo) {
|
|
6851
|
+
for (const f of walk2(path21.join(root, expo))) {
|
|
6852
|
+
const parts = path21.relative(path21.join(root, expo), f).split(path21.sep);
|
|
6853
|
+
const stem = parts.pop().replace(CODE, "");
|
|
6854
|
+
if (stem === "_layout" || stem.startsWith("+")) continue;
|
|
6855
|
+
if (stem !== "index") parts.push(stem);
|
|
6856
|
+
out.push(withId({ route: parts.join("/") || "index", platform: "native", file: rel(f) }, f));
|
|
6857
|
+
}
|
|
6858
|
+
}
|
|
6859
|
+
const tanstack = path21.join(root, "src/routes");
|
|
6860
|
+
if (existsSync(tanstack)) {
|
|
6861
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6862
|
+
for (const f of walk2(tanstack)) {
|
|
6863
|
+
const parts = path21.relative(tanstack, f).split(path21.sep);
|
|
6864
|
+
const stem = parts.pop().replace(CODE, "").replace(/\.lazy$/, "");
|
|
6865
|
+
if (stem === "__root" || stem === "route" || stem.startsWith("-") || parts.some((p) => p.startsWith("-"))) continue;
|
|
6866
|
+
const segs = [...parts.flatMap(tanstackSegments), ...tanstackSegments(stem)];
|
|
6867
|
+
if (segs.at(-1) === "index") segs.pop();
|
|
6868
|
+
const route = segs.join("/") || "index";
|
|
6869
|
+
if (seen.has(route)) continue;
|
|
6870
|
+
seen.add(route);
|
|
6871
|
+
out.push(withId({ route, platform: "web", file: rel(f) }, f));
|
|
6872
|
+
}
|
|
6873
|
+
}
|
|
6874
|
+
return out;
|
|
6875
|
+
}
|
|
6876
|
+
function withId(r, file) {
|
|
6877
|
+
const id = figmaIdOf(readFileSync(file, "utf8"));
|
|
6878
|
+
return id ? { ...r, figmaId: id } : r;
|
|
6879
|
+
}
|
|
6880
|
+
function urlSegments(route) {
|
|
6881
|
+
return route.replace(/^\/+/, "").split("/").filter((s) => s && s !== "index" && !/^\(.*\)$/.test(s) && !/^_/.test(s)).map((s) => s.replace(/_$/, "")).map((s) => /^\{-\$.*\}$/.test(s) ? "?" : /^\[\.\.\..+\]$/.test(s) ? "**" : /^\$|^\[.*\]$/.test(s) ? "*" : s);
|
|
6882
|
+
}
|
|
6883
|
+
function routeMatches(route, target) {
|
|
6884
|
+
const pattern = urlSegments(route);
|
|
6885
|
+
const url = target.split(/[?#]/)[0].split("/").filter(Boolean);
|
|
6886
|
+
if (/(?:^|\/)\$$/.test(route)) {
|
|
6887
|
+
const head = pattern.slice(0, -1);
|
|
6888
|
+
return url.length >= head.length && head.every((p, i) => p === "*" || p === url[i]);
|
|
6889
|
+
}
|
|
6890
|
+
const go = (i, j) => {
|
|
6891
|
+
if (i === pattern.length) return j === url.length;
|
|
6892
|
+
const p = pattern[i];
|
|
6893
|
+
if (p === "?") return go(i + 1, j) || j < url.length && go(i + 1, j + 1);
|
|
6894
|
+
if (j === url.length) return false;
|
|
6895
|
+
if (p === "**") {
|
|
6896
|
+
for (let k = j + 1; k <= url.length; k++) if (go(i + 1, k)) return true;
|
|
6897
|
+
return false;
|
|
6898
|
+
}
|
|
6899
|
+
return (p === "*" || p === url[j]) && go(i + 1, j + 1);
|
|
6900
|
+
};
|
|
6901
|
+
return go(0, 0);
|
|
6902
|
+
}
|
|
6903
|
+
function sameScreen(a, b) {
|
|
6904
|
+
return a.replace(/^\/+/, "") === b.replace(/^\/+/, "") || urlSegments(a).join("/") === urlSegments(b).join("/");
|
|
6905
|
+
}
|
|
6906
|
+
var STR = String.raw`(?:"([^"\n]*)"|'([^'\n]*)'|` + "`([^`$\\n]*)`)";
|
|
6907
|
+
var NAV_PATTERNS = [
|
|
6908
|
+
new RegExp(String.raw`\brouter\.(?:push|replace|navigate)\(\s*` + STR, "g"),
|
|
6909
|
+
new RegExp(String.raw`<Link\b[^>]*?\b(?:href|to)=\{?\s*` + STR, "g"),
|
|
6910
|
+
new RegExp(String.raw`\bnavigate\(\s*\{[^}]*?\bto\s*:\s*` + STR, "g")
|
|
6911
|
+
];
|
|
6912
|
+
var DYNAMIC_PATTERNS = [
|
|
6913
|
+
new RegExp(String.raw`\brouter\.(?:push|replace|navigate)\(\s*` + "(`[^`\\n]*\\$\\{[^`\\n]*`)", "g"),
|
|
6914
|
+
new RegExp(String.raw`<Link\b[^>]*?\b(?:href|to)=\{\s*` + "(`[^`\\n]*\\$\\{[^`\\n]*`)", "g"),
|
|
6915
|
+
new RegExp(String.raw`\bnavigate\(\s*\{[^}]*?\bto\s*:\s*` + "(`[^`\\n]*\\$\\{[^`\\n]*`)", "g"),
|
|
6916
|
+
new RegExp(String.raw`\brouter\.(?:push|replace|navigate)\(\s*(\{[^}\n]*?\bpathname\b[^}\n]*\}?)`, "g"),
|
|
6917
|
+
new RegExp(String.raw`<Link\b[^>]*?\bhref=\{(\{[^}\n]*?\bpathname\b[^}\n]*\}?)`, "g")
|
|
6918
|
+
];
|
|
6919
|
+
function dynamicNavTargets(code, file) {
|
|
6920
|
+
const out = [];
|
|
6921
|
+
for (const re of DYNAMIC_PATTERNS) {
|
|
6922
|
+
for (const m of code.matchAll(re)) {
|
|
6923
|
+
const raw = m[1].trim();
|
|
6924
|
+
out.push({ file, line: code.slice(0, m.index).split("\n").length, target: raw.length > 60 ? `${raw.slice(0, 57)}...` : raw });
|
|
6925
|
+
}
|
|
6926
|
+
}
|
|
6927
|
+
return out.sort((a, b) => a.line - b.line);
|
|
6928
|
+
}
|
|
6929
|
+
function navTargets(code, file) {
|
|
6930
|
+
const out = [];
|
|
6931
|
+
for (const re of NAV_PATTERNS) {
|
|
6932
|
+
for (const m of code.matchAll(re)) {
|
|
6933
|
+
const target = m[1] ?? m[2] ?? m[3];
|
|
6934
|
+
if (target === void 0 || /^[a-z]+:/i.test(target) || target.startsWith("#") || target.startsWith(".")) continue;
|
|
6935
|
+
out.push({ file, line: code.slice(0, m.index).split("\n").length, target });
|
|
6936
|
+
}
|
|
6937
|
+
}
|
|
6938
|
+
return out.sort((a, b) => a.line - b.line);
|
|
6939
|
+
}
|
|
6940
|
+
function appNavTargets(root) {
|
|
6941
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path21.join(root, "src")), ...walk2(path21.join(root, "app"))])];
|
|
6942
|
+
return files.flatMap((f) => navTargets(readFileSync(f, "utf8"), path21.relative(root, f).split(path21.sep).join("/")));
|
|
6943
|
+
}
|
|
6944
|
+
function appDynamicNavTargets(root) {
|
|
6945
|
+
const files = [.../* @__PURE__ */ new Set([...walk2(path21.join(root, "src")), ...walk2(path21.join(root, "app"))])];
|
|
6946
|
+
return files.flatMap((f) => dynamicNavTargets(readFileSync(f, "utf8"), path21.relative(root, f).split(path21.sep).join("/")));
|
|
6947
|
+
}
|
|
6948
|
+
var FIGMA_API = "https://api.figma.com";
|
|
6949
|
+
var FIGMA_TIMEOUT_MS = 3e4;
|
|
6950
|
+
function splitName(name) {
|
|
6951
|
+
const i = name.indexOf(" \xB7 ");
|
|
6952
|
+
return i < 0 ? { route: name.trim() } : { route: name.slice(0, i).trim(), state: name.slice(i + 3).trim() };
|
|
6953
|
+
}
|
|
6954
|
+
function destinations(node, out = /* @__PURE__ */ new Set()) {
|
|
6955
|
+
if (node.transitionNodeID) out.add(node.transitionNodeID);
|
|
6956
|
+
for (const i of node.interactions ?? []) {
|
|
6957
|
+
for (const a of i.actions ?? []) if (a?.type === "NODE" && a.destinationId && a.navigation !== "CHANGE_TO") out.add(a.destinationId);
|
|
6958
|
+
}
|
|
6959
|
+
for (const c of node.children ?? []) destinations(c, out);
|
|
6960
|
+
return out;
|
|
6961
|
+
}
|
|
6962
|
+
var SCREEN_TYPES = /* @__PURE__ */ new Set(["FRAME", "COMPONENT", "COMPONENT_SET", "INSTANCE"]);
|
|
6963
|
+
async function readFigma(config, token, fetchImpl = fetch, timeoutMs = FIGMA_TIMEOUT_MS) {
|
|
6964
|
+
const get2 = async (p) => {
|
|
6965
|
+
const where2 = p.split("?")[0];
|
|
6966
|
+
try {
|
|
6967
|
+
const res = await fetchImpl(`${FIGMA_API}${p}`, { headers: { "X-Figma-Token": token }, signal: AbortSignal.timeout(timeoutMs) });
|
|
6968
|
+
if (!res.ok) throw new Error(`Figma API ${where2} answered ${res.status}${res.status === 403 ? " (check FIGMA_ACCESS_TOKEN and its access to the file)" : ""}`);
|
|
6969
|
+
return await res.json();
|
|
6970
|
+
} catch (err) {
|
|
6971
|
+
const name = err?.name;
|
|
6972
|
+
if (name === "TimeoutError" || name === "AbortError") throw new Error(`Figma API ${where2} didn't answer within ${Math.round(timeoutMs / 1e3)}s`);
|
|
6973
|
+
throw err;
|
|
6974
|
+
}
|
|
6975
|
+
};
|
|
6976
|
+
const nodes = async (ids, depth) => {
|
|
6977
|
+
const out = [];
|
|
6978
|
+
for (let i = 0; i < ids.length; i += 50) {
|
|
6979
|
+
const chunk = ids.slice(i, i + 50);
|
|
6980
|
+
const body = await get2(`/v1/files/${config.file}/nodes?ids=${encodeURIComponent(chunk.join(","))}${depth ? `&depth=${depth}` : ""}`);
|
|
6981
|
+
for (const id of chunk) {
|
|
6982
|
+
const doc = body.nodes[id]?.document;
|
|
6983
|
+
if (doc) out.push(doc);
|
|
6984
|
+
}
|
|
6985
|
+
}
|
|
6986
|
+
return out;
|
|
6987
|
+
};
|
|
6988
|
+
const file = await get2(`/v1/files/${config.file}?depth=2`);
|
|
6989
|
+
const canvases = file.document.children ?? [];
|
|
6990
|
+
const wanted = /* @__PURE__ */ new Set([...Object.values(config.pages), config.proposalsPage]);
|
|
6991
|
+
const frames = [];
|
|
6992
|
+
const sections = [];
|
|
6993
|
+
for (const page of canvases) {
|
|
6994
|
+
if (!wanted.has(page.name)) continue;
|
|
6995
|
+
for (const child of page.children ?? []) {
|
|
6996
|
+
if (child.type === "SECTION") sections.push({ id: child.id, name: child.name, page: page.name });
|
|
6997
|
+
else if (SCREEN_TYPES.has(child.type)) frames.push({ id: child.id, name: child.name, page: page.name, ...splitName(child.name) });
|
|
6998
|
+
}
|
|
6999
|
+
}
|
|
7000
|
+
for (const s of await nodes(sections.map((x) => x.id), 1)) {
|
|
7001
|
+
const section2 = sections.find((x) => x.id === s.id);
|
|
7002
|
+
for (const child of s.children ?? []) {
|
|
7003
|
+
if (SCREEN_TYPES.has(child.type)) frames.push({ id: child.id, name: child.name, page: section2.page, section: section2.name, ...splitName(child.name) });
|
|
7004
|
+
}
|
|
7005
|
+
}
|
|
7006
|
+
const hotspots = [];
|
|
7007
|
+
for (const tree of await nodes(frames.filter((f) => f.page !== config.proposalsPage).map((f) => f.id))) {
|
|
7008
|
+
for (const to of destinations(tree)) if (to !== tree.id) hotspots.push({ from: tree.id, to });
|
|
7009
|
+
}
|
|
7010
|
+
return { pages: canvases.map((p) => p.name), frames, hotspots };
|
|
7011
|
+
}
|
|
7012
|
+
function compare(config, routes, targets, figma, dynamicTargets = []) {
|
|
7013
|
+
const platformOf = (page) => config.pages.web === page ? "web" : config.pages.native === page ? "native" : void 0;
|
|
7014
|
+
const routeFrames = figma.frames.filter((f) => platformOf(f.page));
|
|
7015
|
+
const framesFor = (r) => routeFrames.filter((f) => platformOf(f.page) === r.platform && (sameScreen(f.route, r.route) || r.route === "index" && f.route === "/"));
|
|
7016
|
+
const byId = new Map(figma.frames.map((f) => [f.id, f]));
|
|
7017
|
+
const framed = new Set(routes.flatMap((r) => framesFor(r).map((f) => f.id)));
|
|
7018
|
+
const covered = routes.filter((r) => framesFor(r).length > 0);
|
|
7019
|
+
const routesWithoutFrame = routes.filter((r) => framesFor(r).length === 0);
|
|
7020
|
+
const framesWithoutRoute = routeFrames.filter((f) => !framed.has(f.id));
|
|
7021
|
+
const proposals = {};
|
|
7022
|
+
for (const f of figma.frames.filter((x) => x.page === config.proposalsPage)) (proposals[f.section ?? "(no section)"] ??= []).push(f);
|
|
7023
|
+
const missingHotspots = [];
|
|
7024
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7025
|
+
for (const t of targets) {
|
|
7026
|
+
const source = routes.find((r) => r.file === t.file);
|
|
7027
|
+
if (!source) continue;
|
|
7028
|
+
const from = framesFor(source);
|
|
7029
|
+
if (!from.length) continue;
|
|
7030
|
+
const dest = routes.find((r) => r.platform === source.platform && routeMatches(r.route, t.target));
|
|
7031
|
+
if (!dest || dest === source) continue;
|
|
7032
|
+
const key2 = `${source.route}\u2192${dest.route}`;
|
|
7033
|
+
if (seen.has(key2)) continue;
|
|
7034
|
+
seen.add(key2);
|
|
7035
|
+
const to = new Set(framesFor(dest).map((f) => f.id));
|
|
7036
|
+
const linked = figma.hotspots.some((h) => from.some((f) => f.id === h.from) && to.has(h.to));
|
|
7037
|
+
if (!linked) missingHotspots.push({ ...t, from: source.route, to: dest.route, targetHasFrame: to.size > 0 });
|
|
7038
|
+
}
|
|
7039
|
+
const deadHotspots = [];
|
|
7040
|
+
for (const h of figma.hotspots) {
|
|
7041
|
+
const from = byId.get(h.from);
|
|
7042
|
+
const to = byId.get(h.to);
|
|
7043
|
+
if (from && to && platformOf(to.page) && !framed.has(to.id)) deadHotspots.push({ from, to });
|
|
7044
|
+
}
|
|
7045
|
+
const idMismatches = routes.filter((r) => r.figmaId && !framesFor(r).some((f) => f.id === r.figmaId)).map((r) => ({ ...r, frames: framesFor(r).map((f) => f.id) }));
|
|
7046
|
+
const wantedPages = [...Object.values(config.pages), config.proposalsPage];
|
|
7047
|
+
const missingPages = wantedPages.filter((p) => !figma.pages.includes(p));
|
|
7048
|
+
const uncheckedNavigation = dynamicTargets.filter((t) => routes.some((r) => r.file === t.file));
|
|
7049
|
+
return {
|
|
7050
|
+
file: config.file,
|
|
7051
|
+
summary: {
|
|
7052
|
+
routes: routes.length,
|
|
7053
|
+
frames: routeFrames.length,
|
|
7054
|
+
covered: covered.length,
|
|
7055
|
+
coveredPercent: routes.length ? Math.round(covered.length / routes.length * 100) : 100,
|
|
7056
|
+
hotspots: figma.hotspots.length,
|
|
7057
|
+
missing: missingPages.length + routesWithoutFrame.length + missingHotspots.length + idMismatches.length
|
|
7058
|
+
},
|
|
7059
|
+
missingPages,
|
|
7060
|
+
routesWithoutFrame,
|
|
7061
|
+
framesWithoutRoute,
|
|
7062
|
+
proposals,
|
|
7063
|
+
missingHotspots,
|
|
7064
|
+
deadHotspots,
|
|
7065
|
+
idMismatches,
|
|
7066
|
+
uncheckedNavigation
|
|
7067
|
+
};
|
|
7068
|
+
}
|
|
7069
|
+
async function checkFigmaRoutes(options) {
|
|
7070
|
+
const config = options.config ?? readFigmaConfig(options.root);
|
|
7071
|
+
if (!config) throw new FigmaConfigError(`no "figma" block in ${path21.join(options.root, "genesis.config.json")}`);
|
|
7072
|
+
const token = options.token ?? process.env.FIGMA_ACCESS_TOKEN;
|
|
7073
|
+
if (!token) throw new FigmaConfigError("FIGMA_ACCESS_TOKEN isn't set");
|
|
7074
|
+
const figma = await readFigma(config, token, options.fetch);
|
|
7075
|
+
return compare(config, appRoutes(options.root), appNavTargets(options.root), figma, appDynamicNavTargets(options.root));
|
|
7076
|
+
}
|
|
7077
|
+
function coverageFindings(r, strict) {
|
|
7078
|
+
const gap = strict ? "warn" : "info";
|
|
7079
|
+
return [
|
|
7080
|
+
...r.missingPages.map((p) => ({ level: gap, file: `figma:${p}`, message: `the Figma file has no page "${p}" (named in genesis.config.json figma)`, subject: p })),
|
|
7081
|
+
...r.routesWithoutFrame.map((x) => ({ level: gap, file: x.file, message: `route ${x.route} has no ${x.platform} frame in the Figma file`, subject: x.route })),
|
|
7082
|
+
...r.missingHotspots.map((m) => ({ level: gap, file: m.file, line: m.line, message: `navigates to ${m.to}, but the ${m.from} frame has no hotspot to it${m.targetHasFrame ? "" : " (and it has no frame)"}`, subject: m.to })),
|
|
7083
|
+
...r.idMismatches.map((m) => ({ level: gap, file: m.file, line: 1, message: `// figma: ${m.figmaId} isn't the frame named ${m.route} (${m.frames.join(", ") || "none"})`, subject: m.route })),
|
|
7084
|
+
...r.framesWithoutRoute.map((f) => ({ level: "info", file: `figma:${f.page}`, message: `frame "${f.name}" (${f.id}) has no route: move it to Proposals, or add the route`, subject: f.route })),
|
|
7085
|
+
...r.deadHotspots.map((d) => ({ level: "info", file: `figma:${d.from.page}`, message: `"${d.from.name}" links to "${d.to.name}", which has no route`, subject: d.to.route })),
|
|
7086
|
+
...r.uncheckedNavigation.map((t) => ({ level: "info", file: t.file, line: t.line, message: `navigation to ${t.target} isn't a string literal, so it isn't checked against the Figma file`, subject: t.target }))
|
|
7087
|
+
];
|
|
7088
|
+
}
|
|
7089
|
+
|
|
7090
|
+
// src/doctor/figma-routes.ts
|
|
7091
|
+
async function checkFigmaRoutesRule(ctx) {
|
|
7092
|
+
let config;
|
|
7093
|
+
try {
|
|
7094
|
+
config = readFigmaConfig(ctx.root);
|
|
7095
|
+
} catch (err) {
|
|
7096
|
+
if (!(err instanceof FigmaConfigError)) throw err;
|
|
7097
|
+
ctx.report({ rule: "figma-routes", level: "warn", file: "genesis.config.json", message: err.message });
|
|
7098
|
+
return;
|
|
7099
|
+
}
|
|
7100
|
+
if (!config) return;
|
|
7101
|
+
if (!process.env.FIGMA_ACCESS_TOKEN) {
|
|
7102
|
+
ctx.report({ rule: "figma-routes", level: "info", file: "genesis.config.json", message: "skipped: FIGMA_ACCESS_TOKEN isn't set (CI sets it from a secret)" });
|
|
7103
|
+
return;
|
|
7104
|
+
}
|
|
7105
|
+
try {
|
|
7106
|
+
const report = await checkFigmaRoutes({ root: ctx.root, config });
|
|
7107
|
+
for (const f of coverageFindings(report, ctx.strict ?? false)) ctx.report({ rule: "figma-routes", ...f });
|
|
7108
|
+
} catch (err) {
|
|
7109
|
+
ctx.report({ rule: "figma-routes", level: "info", file: "genesis.config.json", message: `skipped: ${err.message}` });
|
|
6725
7110
|
}
|
|
6726
7111
|
}
|
|
6727
7112
|
var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
|
|
6728
7113
|
async function runDoctor(options = {}) {
|
|
6729
|
-
const root =
|
|
7114
|
+
const root = path21.resolve(options.root ?? process.cwd());
|
|
6730
7115
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
6731
7116
|
const config = loaded.config;
|
|
6732
7117
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -6741,7 +7126,7 @@ async function runDoctor(options = {}) {
|
|
|
6741
7126
|
}
|
|
6742
7127
|
const raw = [];
|
|
6743
7128
|
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
6744
|
-
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
7129
|
+
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true, figma: options.figma ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
6745
7130
|
try {
|
|
6746
7131
|
await plugin.check(ctx);
|
|
6747
7132
|
} catch (err) {
|
|
@@ -6780,7 +7165,7 @@ async function runDoctor(options = {}) {
|
|
|
6780
7165
|
}
|
|
6781
7166
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
6782
7167
|
if (options.base && changed) {
|
|
6783
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
7168
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path21.join(root, f)) });
|
|
6784
7169
|
}
|
|
6785
7170
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
6786
7171
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -6829,6 +7214,7 @@ function builtinChecks(config, options = {}) {
|
|
|
6829
7214
|
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
6830
7215
|
{ name: "eslint-config", check: checkEslintConfig },
|
|
6831
7216
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
7217
|
+
...options.figma !== false ? [{ name: "figma-routes", check: checkFigmaRoutesRule }] : [],
|
|
6832
7218
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
6833
7219
|
];
|
|
6834
7220
|
}
|
|
@@ -6881,7 +7267,7 @@ function applyConfig(raw, config, packageIds) {
|
|
|
6881
7267
|
}
|
|
6882
7268
|
return out.sort((x, y) => x.file.localeCompare(y.file) || x.line - y.line || x.rule.localeCompare(y.rule));
|
|
6883
7269
|
}
|
|
6884
|
-
function formatReport(result) {
|
|
7270
|
+
function formatReport(result, options = {}) {
|
|
6885
7271
|
const g = result.genesis;
|
|
6886
7272
|
const lines = [
|
|
6887
7273
|
`Genesis doctor: ${g.uiPackage}@${g.uiVersion}, ${g.components.length} components, ${g.tokens.size} tokens, ${result.ruleCount} app rules; raw tags checked: ${[...g.rawTags.keys()].join(", ") || "none"}`
|
|
@@ -6889,7 +7275,7 @@ function formatReport(result) {
|
|
|
6889
7275
|
for (const f of result.findings) {
|
|
6890
7276
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
6891
7277
|
}
|
|
6892
|
-
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
7278
|
+
lines.push(options.verbose ? `Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}` : `Available but unused: ${result.unused.length} (genesis doctor --verbose lists them)`);
|
|
6893
7279
|
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
6894
7280
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
6895
7281
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|