@marktiderman/genesis-cli 1.20.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 +168 -9
- package/dist/cli.js +1114 -103
- 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 +1515 -1095
- 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 +140 -20
- package/dist/index.d.ts +114 -2
- package/dist/index.js +1538 -1099
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +8 -5
- package/dist/starter/__tests__/components/setup.ts +11 -0
- package/dist/starter/__tests__/starter.test.ts +28 -0
- package/dist/starter/package.json +4 -3
- package/dist/starter/pnpm-workspace.yaml +22 -0
- package/dist/starter/src/lib/app.ts +13 -5
- package/dist/starter/src/lib/check-in.ts +5 -3
- package/dist/starter/src/lib/define-starter.ts +1 -1
- package/dist/starter/src/lib/devtools-overlay.ts +3 -4
- package/dist/starter/src/lib/native-modules.ts +9 -2
- package/dist/starter/src/lib/offline.ts +14 -0
- package/dist/starter/supabase/migrations/20261024000750_support_default_tenant.sql +18 -0
- package/dist/starter/supabase/migrations/20261024000800_genesis_support_tickets.sql +800 -0
- package/dist/starter/supabase/migrations/20261025000070_starter_tenancy.sql +26 -0
- package/dist/starter/supabase/migrations/20261025000080_genesis_chat_tenants.sql +716 -0
- package/dist/starter/supabase/migrations/20261025000090_genesis_chat_attachment_paths.sql +80 -0
- package/dist/starter/supabase/tests/database/chat_people.test.sql +1 -1
- package/dist/starter/supabase/tests/database/genesis_chat.test.sql +10 -2
- package/dist/starter/supabase/tests/database/genesis_chat_attachment_paths.test.sql +111 -0
- package/dist/starter/supabase/tests/database/genesis_chat_coaching.test.sql +8 -0
- package/dist/starter/supabase/tests/database/genesis_chat_search_threads.test.sql +8 -0
- package/dist/starter/supabase/tests/database/genesis_chat_tenants.test.sql +259 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +15 -3
- package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +10 -0
- package/dist/starter/supabase/tests/database/genesis_support_tickets.test.sql +327 -0
- package/dist/starter/supabase/tests/database/starter_tenancy.test.sql +19 -0
- package/dist/vite.js +1514 -1094
- 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,409 +1158,140 @@ 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);
|
|
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
|
+
}
|
|
1303
1281
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
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 ManifestError = class extends Error {
|
|
1459
|
-
constructor(problems) {
|
|
1460
|
-
super(`Invalid block manifest:
|
|
1461
|
-
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
1462
|
-
this.problems = problems;
|
|
1463
|
-
this.name = "ManifestError";
|
|
1464
|
-
}
|
|
1465
|
-
problems;
|
|
1466
|
-
};
|
|
1467
|
-
function safeRelative(value) {
|
|
1468
|
-
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
1469
|
-
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
1470
|
-
const segments = value.split("/");
|
|
1471
|
-
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
1472
|
-
return value;
|
|
1473
|
-
}
|
|
1474
|
-
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1475
|
-
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
1476
|
-
function parseManifest(home, id, raw, version, options = {}) {
|
|
1477
|
-
const problems = [];
|
|
1478
|
-
const at = `${home} genesis.blocks.${id}`;
|
|
1479
|
-
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
1480
|
-
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
1481
|
-
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
1482
|
-
const pkgOf = (value, where2) => {
|
|
1483
|
-
if (value === void 0) return home;
|
|
1484
|
-
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
1485
|
-
problems.push(`${where2}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
1486
|
-
return home;
|
|
1487
|
-
}
|
|
1488
|
-
return value;
|
|
1489
|
-
};
|
|
1490
|
-
const pathOf = (value, where2) => {
|
|
1491
|
-
const safe = safeRelative(value);
|
|
1492
|
-
if (!safe) problems.push(`${where2}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
1493
|
-
return safe ?? "";
|
|
1494
|
-
};
|
|
1495
|
-
const list = (key2) => {
|
|
1496
|
-
const v = raw[key2];
|
|
1497
|
-
if (v === void 0) return [];
|
|
1498
|
-
if (!Array.isArray(v)) {
|
|
1499
|
-
problems.push(`${at}.${key2}: must be a list`);
|
|
1500
|
-
return [];
|
|
1501
|
-
}
|
|
1502
|
-
return v;
|
|
1503
|
-
};
|
|
1504
|
-
const requires = list("requires").filter((r) => {
|
|
1505
|
-
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
1506
|
-
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
1507
|
-
return ok;
|
|
1508
|
-
});
|
|
1509
|
-
let platforms;
|
|
1510
|
-
if (raw["platforms"] !== void 0) {
|
|
1511
|
-
platforms = list("platforms").filter((p) => {
|
|
1512
|
-
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
1513
|
-
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
1514
|
-
return ok;
|
|
1515
|
-
});
|
|
1516
|
-
}
|
|
1517
|
-
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
1518
|
-
const install = list("install").filter((s) => {
|
|
1519
|
-
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
1520
|
-
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
1521
|
-
return ok;
|
|
1522
|
-
});
|
|
1523
|
-
const migrations = list("migrations").map((m, i) => {
|
|
1524
|
-
const where2 = `${at}.migrations[${i}]`;
|
|
1525
|
-
if (!isObject2(m)) {
|
|
1526
|
-
problems.push(`${where2}: must be an object`);
|
|
1527
|
-
return { package: home, file: "" };
|
|
1528
|
-
}
|
|
1529
|
-
const file = pathOf(m["file"], `${where2}.file`);
|
|
1530
|
-
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
1531
|
-
const out = { package: pkgOf(m["package"], where2), file };
|
|
1532
|
-
if (m["provides"] !== void 0) {
|
|
1533
|
-
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
1282
|
+
if (m["runsBefore"] !== void 0) {
|
|
1283
|
+
if (!Array.isArray(m["runsBefore"])) problems.push(`${where2}.runsBefore: must be a list of { package, file }`);
|
|
1534
1284
|
else {
|
|
1535
|
-
out.
|
|
1536
|
-
const at2 = `${where2}.
|
|
1537
|
-
if (!isObject2(
|
|
1285
|
+
out.runsBefore = m["runsBefore"].map((r, j) => {
|
|
1286
|
+
const at2 = `${where2}.runsBefore[${j}]`;
|
|
1287
|
+
if (!isObject2(r)) {
|
|
1538
1288
|
problems.push(`${at2}: must be an object`);
|
|
1539
1289
|
return { package: home, file: "" };
|
|
1540
1290
|
}
|
|
1541
|
-
const
|
|
1542
|
-
if (
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
}
|
|
1546
|
-
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
1547
|
-
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
1548
|
-
return provided;
|
|
1291
|
+
const before = { package: pkgOf(r["package"], at2), file: pathOf(r["file"], `${at2}.file`) };
|
|
1292
|
+
if (before.file && !MIGRATION_FILE.test(before.file.split("/").pop())) problems.push(`${at2}.file: "${before.file}" must be named NNNN_name.sql`);
|
|
1293
|
+
if (before.package === out.package && before.file === file) problems.push(`${at2}: a migration can't run before itself`);
|
|
1294
|
+
return before;
|
|
1549
1295
|
});
|
|
1550
1296
|
}
|
|
1551
1297
|
}
|
|
@@ -1663,15 +1409,15 @@ function isBlockDef(value) {
|
|
|
1663
1409
|
// src/blocks/files.ts
|
|
1664
1410
|
var sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
1665
1411
|
function inside(parent, child) {
|
|
1666
|
-
const rel =
|
|
1667
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1412
|
+
const rel = path21.relative(parent, child);
|
|
1413
|
+
return rel === "" || !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
1668
1414
|
}
|
|
1669
1415
|
function appPath2(root, rel) {
|
|
1670
1416
|
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
1671
1417
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
1672
1418
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
1673
1419
|
const realRoot = realpathSync(root);
|
|
1674
|
-
const target =
|
|
1420
|
+
const target = path21.join(realRoot, ...safe.split("/"));
|
|
1675
1421
|
const there = (p) => {
|
|
1676
1422
|
try {
|
|
1677
1423
|
lstatSync(p);
|
|
@@ -1680,20 +1426,18 @@ function appPath2(root, rel) {
|
|
|
1680
1426
|
return false;
|
|
1681
1427
|
}
|
|
1682
1428
|
};
|
|
1683
|
-
let probe =
|
|
1684
|
-
while (!there(probe)) probe =
|
|
1429
|
+
let probe = path21.dirname(target);
|
|
1430
|
+
while (!there(probe)) probe = path21.dirname(probe);
|
|
1685
1431
|
let real2;
|
|
1686
1432
|
try {
|
|
1687
1433
|
real2 = realpathSync(probe);
|
|
1688
1434
|
} catch {
|
|
1689
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
1435
|
+
throw new Error(`${rel} goes through a broken symlink (${path21.relative(realRoot, probe)}); refused`);
|
|
1690
1436
|
}
|
|
1691
1437
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
1692
1438
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
1693
1439
|
return target;
|
|
1694
1440
|
}
|
|
1695
|
-
|
|
1696
|
-
// src/blocks/local.ts
|
|
1697
1441
|
var LOCAL_PACKAGES_KEY = "localPackages";
|
|
1698
1442
|
var LocalPackagesError = class extends Error {
|
|
1699
1443
|
name = "LocalPackagesError";
|
|
@@ -1703,8 +1447,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1703
1447
|
return raw.map((entry, i) => {
|
|
1704
1448
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
1705
1449
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
1706
|
-
if (
|
|
1707
|
-
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(/\/+$/, "");
|
|
1708
1452
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
1709
1453
|
const parts = norm.split("/");
|
|
1710
1454
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -1715,7 +1459,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1715
1459
|
});
|
|
1716
1460
|
}
|
|
1717
1461
|
function localPackageGlobs(root) {
|
|
1718
|
-
const file =
|
|
1462
|
+
const file = path21.join(root, "genesis.config.json");
|
|
1719
1463
|
if (!existsSync(file)) return [];
|
|
1720
1464
|
let raw;
|
|
1721
1465
|
try {
|
|
@@ -1729,14 +1473,14 @@ function localPackageGlobs(root) {
|
|
|
1729
1473
|
var cache = /* @__PURE__ */ new Map();
|
|
1730
1474
|
function repositoryRoot(appRoot) {
|
|
1731
1475
|
for (let dir = appRoot; ; ) {
|
|
1732
|
-
if (existsSync(
|
|
1733
|
-
const parent =
|
|
1476
|
+
if (existsSync(path21.join(dir, ".git"))) return dir;
|
|
1477
|
+
const parent = path21.dirname(dir);
|
|
1734
1478
|
if (parent === dir) return appRoot;
|
|
1735
1479
|
dir = parent;
|
|
1736
1480
|
}
|
|
1737
1481
|
}
|
|
1738
1482
|
function localPackages(root) {
|
|
1739
|
-
const appRoot =
|
|
1483
|
+
const appRoot = path21.resolve(root);
|
|
1740
1484
|
const globs = localPackageGlobs(appRoot);
|
|
1741
1485
|
const key2 = `${appRoot}
|
|
1742
1486
|
${globs.join("\n")}`;
|
|
@@ -1745,24 +1489,24 @@ ${globs.join("\n")}`;
|
|
|
1745
1489
|
const dirs = /* @__PURE__ */ new Set();
|
|
1746
1490
|
for (const glob of globs) {
|
|
1747
1491
|
if (glob.endsWith("/*") || glob === "*") {
|
|
1748
|
-
const parent =
|
|
1492
|
+
const parent = path21.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
1749
1493
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
1750
1494
|
for (const entry of readdirSync(parent).sort()) {
|
|
1751
1495
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
1752
|
-
dirs.add(
|
|
1496
|
+
dirs.add(path21.join(parent, entry));
|
|
1753
1497
|
}
|
|
1754
1498
|
} else {
|
|
1755
|
-
dirs.add(
|
|
1499
|
+
dirs.add(path21.join(appRoot, glob));
|
|
1756
1500
|
}
|
|
1757
1501
|
}
|
|
1758
1502
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
1759
1503
|
const out = [];
|
|
1760
1504
|
const byName = /* @__PURE__ */ new Map();
|
|
1761
1505
|
for (const dir of [...dirs].sort()) {
|
|
1762
|
-
const manifest =
|
|
1506
|
+
const manifest = path21.join(dir, "package.json");
|
|
1763
1507
|
if (!existsSync(manifest)) continue;
|
|
1764
1508
|
if (!inside(real2, realpathSync(dir))) {
|
|
1765
|
-
throw new LocalPackagesError(`${
|
|
1509
|
+
throw new LocalPackagesError(`${path21.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
1766
1510
|
}
|
|
1767
1511
|
let pkg;
|
|
1768
1512
|
try {
|
|
@@ -1771,7 +1515,7 @@ ${globs.join("\n")}`;
|
|
|
1771
1515
|
continue;
|
|
1772
1516
|
}
|
|
1773
1517
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
1774
|
-
const rel =
|
|
1518
|
+
const rel = path21.relative(appRoot, dir).split(path21.sep).join("/");
|
|
1775
1519
|
const other = byName.get(pkg.name);
|
|
1776
1520
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
1777
1521
|
byName.set(pkg.name, rel);
|
|
@@ -1959,35 +1703,35 @@ var DEFAULT_IGNORE = [
|
|
|
1959
1703
|
];
|
|
1960
1704
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1961
1705
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1962
|
-
var toPosix = (p) => p.split(
|
|
1706
|
+
var toPosix = (p) => p.split(path21.sep).join("/");
|
|
1963
1707
|
function scanFiles(root, config) {
|
|
1964
1708
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
1965
1709
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
1966
1710
|
const files = [];
|
|
1967
1711
|
const seen = /* @__PURE__ */ new Set();
|
|
1968
1712
|
const visit = (abs) => {
|
|
1969
|
-
const rel = toPosix(
|
|
1713
|
+
const rel = toPosix(path21.relative(root, abs));
|
|
1970
1714
|
if (seen.has(rel) || ignored(rel)) return;
|
|
1971
|
-
const ext =
|
|
1715
|
+
const ext = path21.extname(abs);
|
|
1972
1716
|
if (!extensions.has(ext)) return;
|
|
1973
1717
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1974
1718
|
seen.add(rel);
|
|
1975
1719
|
const text = readFileSync(abs, "utf8");
|
|
1976
1720
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
1977
1721
|
};
|
|
1978
|
-
const
|
|
1722
|
+
const walk3 = (dir) => {
|
|
1979
1723
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1980
1724
|
if (entry.isDirectory()) {
|
|
1981
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
1725
|
+
if (!SKIP_DIRS.has(entry.name)) walk3(path21.join(dir, entry.name));
|
|
1982
1726
|
} else if (entry.isFile()) {
|
|
1983
|
-
visit(
|
|
1727
|
+
visit(path21.join(dir, entry.name));
|
|
1984
1728
|
}
|
|
1985
1729
|
}
|
|
1986
1730
|
};
|
|
1987
1731
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1988
|
-
const abs =
|
|
1732
|
+
const abs = path21.resolve(root, src);
|
|
1989
1733
|
if (!existsSync(abs)) continue;
|
|
1990
|
-
if (statSync(abs).isDirectory())
|
|
1734
|
+
if (statSync(abs).isDirectory()) walk3(abs);
|
|
1991
1735
|
else visit(abs);
|
|
1992
1736
|
}
|
|
1993
1737
|
let local = [];
|
|
@@ -1996,7 +1740,7 @@ function scanFiles(root, config) {
|
|
|
1996
1740
|
} catch {
|
|
1997
1741
|
local = [];
|
|
1998
1742
|
}
|
|
1999
|
-
for (const pkg of local)
|
|
1743
|
+
for (const pkg of local) walk3(pkg.dir);
|
|
2000
1744
|
return files;
|
|
2001
1745
|
}
|
|
2002
1746
|
function lineAt(text, index) {
|
|
@@ -2005,150 +1749,11 @@ function lineAt(text, index) {
|
|
|
2005
1749
|
return line;
|
|
2006
1750
|
}
|
|
2007
1751
|
|
|
2008
|
-
// src/doctor/
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
const heading = line.match(/^###\s+([A-Za-z0-9_-]+)\s*$/);
|
|
2014
|
-
if (heading) {
|
|
2015
|
-
current = { id: heading[1] };
|
|
2016
|
-
rules.push(current);
|
|
2017
|
-
continue;
|
|
2018
|
-
}
|
|
2019
|
-
if (/^#{1,2}\s/.test(line)) {
|
|
2020
|
-
current = null;
|
|
2021
|
-
continue;
|
|
2022
|
-
}
|
|
2023
|
-
const kv = current && line.match(/^-\s+(level|files|exclude|forbid|require|path|message|newOnly):\s*(.*)$/);
|
|
2024
|
-
if (!current || !kv) continue;
|
|
2025
|
-
const [, key2, raw] = kv;
|
|
2026
|
-
const value = raw.trim();
|
|
2027
|
-
if (key2 === "files" || key2 === "exclude") current[key2] = value.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2028
|
-
else if (key2 === "level") current.level = value;
|
|
2029
|
-
else if (key2 === "newOnly") current.newOnly = value === "true" ? true : value === "false" ? false : value;
|
|
2030
|
-
else current[key2] = value;
|
|
2031
|
-
}
|
|
2032
|
-
return rules;
|
|
2033
|
-
}
|
|
2034
|
-
function toRegExp(source, flags = "") {
|
|
2035
|
-
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
2036
|
-
return new RegExp(source, flags);
|
|
2037
|
-
}
|
|
2038
|
-
function compilePatternRules(rules, source) {
|
|
2039
|
-
const ids = /* @__PURE__ */ new Set();
|
|
2040
|
-
const out = [];
|
|
2041
|
-
for (const rule of rules) {
|
|
2042
|
-
if (ids.has(rule.id)) throw new DoctorConfigError(`${source}: rule "${rule.id}" is defined twice`);
|
|
2043
|
-
ids.add(rule.id);
|
|
2044
|
-
const level = rule.level ?? "error";
|
|
2045
|
-
if (!["error", "warn", "info", "guide"].includes(level)) {
|
|
2046
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has level "${level}" (use error, warn, info or guide)`);
|
|
2047
|
-
}
|
|
2048
|
-
if (rule.newOnly !== void 0 && typeof rule.newOnly !== "boolean") {
|
|
2049
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has newOnly "${String(rule.newOnly)}" (use true or false)`);
|
|
2050
|
-
}
|
|
2051
|
-
if (level === "guide") continue;
|
|
2052
|
-
if (!rule.files?.length) throw new DoctorConfigError(`${source}: rule "${rule.id}" needs "files" (or level: guide)`);
|
|
2053
|
-
if (!rule.forbid && !rule.require && !rule.path) {
|
|
2054
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" needs forbid, require or path (or level: guide)`);
|
|
2055
|
-
}
|
|
2056
|
-
try {
|
|
2057
|
-
out.push({
|
|
2058
|
-
rule,
|
|
2059
|
-
level,
|
|
2060
|
-
includes: globMatcher(rule.files),
|
|
2061
|
-
excludes: globMatcher(rule.exclude),
|
|
2062
|
-
forbid: rule.forbid ? toRegExp(rule.forbid, "m") : void 0,
|
|
2063
|
-
require: rule.require ? toRegExp(rule.require, "m") : void 0,
|
|
2064
|
-
path: rule.path ? toRegExp(rule.path) : void 0
|
|
2065
|
-
});
|
|
2066
|
-
} catch (err) {
|
|
2067
|
-
throw new DoctorConfigError(`${source}: rule "${rule.id}" has an invalid pattern: ${err.message}`);
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
return out;
|
|
2071
|
-
}
|
|
2072
|
-
function loadPatternRules(root, patterns, rulesDoc) {
|
|
2073
|
-
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2074
|
-
let all = compiled;
|
|
2075
|
-
if (rulesDoc) {
|
|
2076
|
-
const file = path20.resolve(root, rulesDoc);
|
|
2077
|
-
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2078
|
-
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2079
|
-
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
2080
|
-
if (clash) throw new DoctorConfigError(`rule "${clash.rule.id}" is defined in both doctor.patterns and ${rulesDoc}`);
|
|
2081
|
-
all = [...compiled, ...fromDoc];
|
|
2082
|
-
}
|
|
2083
|
-
if (all.length === 0) return null;
|
|
2084
|
-
return {
|
|
2085
|
-
count: all.length,
|
|
2086
|
-
ids: all.map((r) => r.rule.id),
|
|
2087
|
-
newOnly: all.filter((r) => r.rule.newOnly).map((r) => r.rule.id),
|
|
2088
|
-
plugin: {
|
|
2089
|
-
name: "patterns",
|
|
2090
|
-
check(ctx) {
|
|
2091
|
-
for (const r of all) {
|
|
2092
|
-
const message = r.rule.message ?? "breaks a design rule";
|
|
2093
|
-
for (const file of ctx.files) {
|
|
2094
|
-
if (!r.includes(file.path) || r.excludes(file.path)) continue;
|
|
2095
|
-
const report = (line) => ctx.report({ rule: r.rule.id, level: r.level, file: file.path, line, message });
|
|
2096
|
-
if (r.path && !r.path.test(file.path)) report(0);
|
|
2097
|
-
if (r.require && !r.require.test(file.code)) report(0);
|
|
2098
|
-
if (r.forbid) {
|
|
2099
|
-
const m = r.forbid.exec(file.code);
|
|
2100
|
-
if (m) report(lineAt(file.code, m.index));
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
}
|
|
2105
|
-
}
|
|
2106
|
-
};
|
|
2107
|
-
}
|
|
2108
|
-
function defineDoctorPlugin(plugin) {
|
|
2109
|
-
return plugin;
|
|
2110
|
-
}
|
|
2111
|
-
async function loadPlugins(specs, configDir) {
|
|
2112
|
-
const plugins = [];
|
|
2113
|
-
for (const spec of specs ?? []) {
|
|
2114
|
-
const [id, options] = typeof spec === "string" ? [spec, void 0] : spec;
|
|
2115
|
-
const file = resolvePlugin(id, configDir);
|
|
2116
|
-
const url = `${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`;
|
|
2117
|
-
let mod;
|
|
2118
|
-
try {
|
|
2119
|
-
mod = await import(url);
|
|
2120
|
-
} catch (err) {
|
|
2121
|
-
throw new DoctorConfigError(`doctor.plugins: could not load ${id}: ${err.message}`);
|
|
2122
|
-
}
|
|
2123
|
-
let value = mod.default;
|
|
2124
|
-
if (typeof value === "function") value = await value(options);
|
|
2125
|
-
const list = Array.isArray(value) ? value : [value];
|
|
2126
|
-
for (const p of list) {
|
|
2127
|
-
if (!p || typeof p !== "object" || typeof p.check !== "function" || typeof p.name !== "string") {
|
|
2128
|
-
throw new DoctorConfigError(`doctor.plugins: ${id} must default-export { name, check(context) } (or an array, or a factory returning one)`);
|
|
2129
|
-
}
|
|
2130
|
-
plugins.push(p);
|
|
2131
|
-
}
|
|
2132
|
-
}
|
|
2133
|
-
return plugins;
|
|
2134
|
-
}
|
|
2135
|
-
function resolvePlugin(id, configDir) {
|
|
2136
|
-
try {
|
|
2137
|
-
if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
|
|
2138
|
-
return resolveFrom(id, configDir);
|
|
2139
|
-
} catch {
|
|
2140
|
-
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
function resolveFrom(id, from) {
|
|
2144
|
-
return createRequire(path20.join(from, "noop.js")).resolve(id);
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
// src/doctor/semver.ts
|
|
2148
|
-
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2149
|
-
function parseVersion(v) {
|
|
2150
|
-
const m = VERSION.exec(v.trim());
|
|
2151
|
-
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
1752
|
+
// src/doctor/semver.ts
|
|
1753
|
+
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1754
|
+
function parseVersion(v) {
|
|
1755
|
+
const m = VERSION.exec(v.trim());
|
|
1756
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2152
1757
|
}
|
|
2153
1758
|
function compareVersions(a, b) {
|
|
2154
1759
|
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
@@ -2263,46 +1868,6 @@ function satisfies(version, range) {
|
|
|
2263
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))
|
|
2264
1869
|
);
|
|
2265
1870
|
}
|
|
2266
|
-
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2267
|
-
function readReleaseManifest(root) {
|
|
2268
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2269
|
-
const file = dir && path20.join(dir, "dist", "versions.json");
|
|
2270
|
-
if (!file || !existsSync(file)) return null;
|
|
2271
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
2272
|
-
}
|
|
2273
|
-
function checkVersionSkew(ctx) {
|
|
2274
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
2275
|
-
if (!manifest) return;
|
|
2276
|
-
const overlays = markedOverlays(ctx);
|
|
2277
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2278
|
-
const overlay = overlays.get(name);
|
|
2279
|
-
if (overlay) {
|
|
2280
|
-
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
2281
|
-
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
2282
|
-
if (from !== want && !behind) {
|
|
2283
|
-
ctx.report({
|
|
2284
|
-
rule: "version-skew",
|
|
2285
|
-
level: "warn",
|
|
2286
|
-
file: "package.json",
|
|
2287
|
-
subject: name,
|
|
2288
|
-
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).`
|
|
2289
|
-
});
|
|
2290
|
-
}
|
|
2291
|
-
continue;
|
|
2292
|
-
}
|
|
2293
|
-
const dir = findPackageDir(ctx.root, name);
|
|
2294
|
-
if (!dir) continue;
|
|
2295
|
-
const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
|
|
2296
|
-
if (have === want) continue;
|
|
2297
|
-
ctx.report({
|
|
2298
|
-
rule: "version-skew",
|
|
2299
|
-
level: "warn",
|
|
2300
|
-
file: "package.json",
|
|
2301
|
-
subject: name,
|
|
2302
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2303
|
-
});
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
1871
|
|
|
2307
1872
|
// src/doctor/overlays.ts
|
|
2308
1873
|
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
@@ -2318,7 +1883,7 @@ function overlayState(name, json) {
|
|
|
2318
1883
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2319
1884
|
const problems = [];
|
|
2320
1885
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2321
|
-
const rel =
|
|
1886
|
+
const rel = path21.relative(path21.resolve(root), path21.resolve(dir)).split(path21.sep).join("/");
|
|
2322
1887
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2323
1888
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2324
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})`);
|
|
@@ -2355,92 +1920,760 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
2355
1920
|
for (const file of manifests) {
|
|
2356
1921
|
let json;
|
|
2357
1922
|
try {
|
|
2358
|
-
json = JSON.parse(readFileSync(
|
|
2359
|
-
} catch {
|
|
2360
|
-
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}`);
|
|
2361
2649
|
}
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
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);
|
|
2367
2658
|
}
|
|
2368
2659
|
}
|
|
2369
|
-
return
|
|
2660
|
+
return plugins;
|
|
2370
2661
|
}
|
|
2371
|
-
function
|
|
2372
|
-
let packages;
|
|
2662
|
+
function resolvePlugin(id, configDir) {
|
|
2373
2663
|
try {
|
|
2374
|
-
|
|
2664
|
+
if (id.startsWith(".") || path21.isAbsolute(id)) return resolveFrom(path21.resolve(configDir, id), configDir);
|
|
2665
|
+
return resolveFrom(id, configDir);
|
|
2375
2666
|
} catch {
|
|
2376
|
-
|
|
2377
|
-
}
|
|
2378
|
-
for (const pkg of packages) {
|
|
2379
|
-
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
2380
|
-
const file = `${pkg.rel}/package.json`;
|
|
2381
|
-
let json;
|
|
2382
|
-
try {
|
|
2383
|
-
json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
2384
|
-
} catch {
|
|
2385
|
-
continue;
|
|
2386
|
-
}
|
|
2387
|
-
const state = overlayState(pkg.name, json);
|
|
2388
|
-
if (state.kind === "none") {
|
|
2389
|
-
ctx.report({
|
|
2390
|
-
rule: "overlay-unmarked",
|
|
2391
|
-
file,
|
|
2392
|
-
subject: pkg.name,
|
|
2393
|
-
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`
|
|
2394
|
-
});
|
|
2395
|
-
continue;
|
|
2396
|
-
}
|
|
2397
|
-
if (state.kind === "invalid") {
|
|
2398
|
-
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2399
|
-
continue;
|
|
2400
|
-
}
|
|
2401
|
-
const { marker } = state;
|
|
2402
|
-
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 });
|
|
2403
|
-
const age = overlayAgeDays(marker.since, now);
|
|
2404
|
-
if (age < -1) {
|
|
2405
|
-
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` });
|
|
2406
|
-
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
2407
|
-
ctx.report({
|
|
2408
|
-
rule: "overlay-age",
|
|
2409
|
-
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
2410
|
-
file,
|
|
2411
|
-
subject: pkg.name,
|
|
2412
|
-
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)`
|
|
2413
|
-
});
|
|
2414
|
-
}
|
|
2415
|
-
const upstream = overlayUpstream(marker).version;
|
|
2416
|
-
const version = typeof json.version === "string" ? json.version : "";
|
|
2417
|
-
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
2418
|
-
ctx.report({
|
|
2419
|
-
rule: "overlay-version",
|
|
2420
|
-
level: "warn",
|
|
2421
|
-
file,
|
|
2422
|
-
subject: version || "(none)",
|
|
2423
|
-
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`
|
|
2424
|
-
});
|
|
2425
|
-
}
|
|
2426
|
-
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
2427
|
-
const from = parseVersion(upstream);
|
|
2428
|
-
const to = pinned ? parseVersion(pinned) : null;
|
|
2429
|
-
if (from && to && compareVersions(from, to) < 0) {
|
|
2430
|
-
ctx.report({
|
|
2431
|
-
rule: "overlay-behind",
|
|
2432
|
-
level: "warn",
|
|
2433
|
-
file,
|
|
2434
|
-
subject: pkg.name,
|
|
2435
|
-
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`
|
|
2436
|
-
});
|
|
2437
|
-
}
|
|
2667
|
+
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2438
2668
|
}
|
|
2439
2669
|
}
|
|
2440
|
-
|
|
2441
|
-
|
|
2670
|
+
function resolveFrom(id, from) {
|
|
2671
|
+
return createRequire(path21.join(from, "noop.js")).resolve(id);
|
|
2672
|
+
}
|
|
2442
2673
|
var BUILTIN_RULES = [
|
|
2443
2674
|
"local-primitives",
|
|
2675
|
+
// figma (figma/routes.ts; runs when genesis.config.json has a figma block)
|
|
2676
|
+
"figma-routes",
|
|
2444
2677
|
"starter-leftover",
|
|
2445
2678
|
"forbidden-import",
|
|
2446
2679
|
"raw-tag",
|
|
@@ -2533,7 +2766,7 @@ function importSpecifiers(file) {
|
|
|
2533
2766
|
}
|
|
2534
2767
|
function checkProjectLayout(ctx) {
|
|
2535
2768
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2536
|
-
if (existsSync(
|
|
2769
|
+
if (existsSync(path21.join(ctx.root, dir))) {
|
|
2537
2770
|
ctx.report({
|
|
2538
2771
|
rule: "local-primitives",
|
|
2539
2772
|
file: dir,
|
|
@@ -2543,7 +2776,7 @@ function checkProjectLayout(ctx) {
|
|
|
2543
2776
|
}
|
|
2544
2777
|
}
|
|
2545
2778
|
for (const file of STARTER_LEFTOVERS) {
|
|
2546
|
-
if (existsSync(
|
|
2779
|
+
if (existsSync(path21.join(ctx.root, file))) {
|
|
2547
2780
|
ctx.report({
|
|
2548
2781
|
rule: "starter-leftover",
|
|
2549
2782
|
level: "warn",
|
|
@@ -2633,7 +2866,7 @@ function checkTokens(ctx) {
|
|
|
2633
2866
|
}
|
|
2634
2867
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2635
2868
|
if (/[*?]/.test(pattern)) continue;
|
|
2636
|
-
const abs =
|
|
2869
|
+
const abs = path21.join(ctx.root, pattern);
|
|
2637
2870
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2638
2871
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2639
2872
|
}
|
|
@@ -2657,7 +2890,7 @@ function checkShadowedExports(ctx) {
|
|
|
2657
2890
|
file.code.split("\n").forEach((text, i) => {
|
|
2658
2891
|
for (const m of text.matchAll(re)) {
|
|
2659
2892
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
2660
|
-
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)` });
|
|
2661
2894
|
}
|
|
2662
2895
|
});
|
|
2663
2896
|
}
|
|
@@ -2756,10 +2989,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
|
|
|
2756
2989
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2757
2990
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2758
2991
|
function resolveLocal(root, fromFile, spec) {
|
|
2759
|
-
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))];
|
|
2760
2993
|
for (const base of bases) {
|
|
2761
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2762
|
-
(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)
|
|
2763
2996
|
);
|
|
2764
2997
|
if (hit) return hit;
|
|
2765
2998
|
}
|
|
@@ -2880,13 +3113,13 @@ function checkNativePack(ctx) {
|
|
|
2880
3113
|
}
|
|
2881
3114
|
function checkEasPlaceholders(ctx) {
|
|
2882
3115
|
const files = [];
|
|
2883
|
-
if (existsSync(
|
|
2884
|
-
const workflows =
|
|
3116
|
+
if (existsSync(path21.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
3117
|
+
const workflows = path21.join(ctx.root, ".eas", "workflows");
|
|
2885
3118
|
if (existsSync(workflows)) {
|
|
2886
3119
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
2887
3120
|
}
|
|
2888
3121
|
for (const file of files) {
|
|
2889
|
-
for (const hit of findPlaceholders(file, readFileSync(
|
|
3122
|
+
for (const hit of findPlaceholders(file, readFileSync(path21.join(ctx.root, file), "utf8"))) {
|
|
2890
3123
|
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
2891
3124
|
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
2892
3125
|
ctx.report({
|
|
@@ -2965,7 +3198,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2965
3198
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2966
3199
|
const code = file.code;
|
|
2967
3200
|
const hidden = HIDES_HEADER.exec(code);
|
|
2968
|
-
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);
|
|
2969
3202
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2970
3203
|
if (hidden && own) {
|
|
2971
3204
|
reported.add(file.path);
|
|
@@ -2993,7 +3226,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2993
3226
|
}
|
|
2994
3227
|
for (const file of ctx.files) {
|
|
2995
3228
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2996
|
-
const layout = hidingLayouts.get(
|
|
3229
|
+
const layout = hidingLayouts.get(path21.posix.dirname(file.path));
|
|
2997
3230
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2998
3231
|
if (!layout || !own) continue;
|
|
2999
3232
|
ctx.report({
|
|
@@ -3015,13 +3248,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
3015
3248
|
}
|
|
3016
3249
|
function routerRoot(ctx) {
|
|
3017
3250
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
3018
|
-
return existsSync(
|
|
3251
|
+
return existsSync(path21.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
3019
3252
|
}
|
|
3020
3253
|
function checkScreenLayouts(ctx, pkg) {
|
|
3021
3254
|
const layouts = nativeLayouts(pkg);
|
|
3022
3255
|
if (layouts.length === 0) return;
|
|
3023
3256
|
const rootDir = routerRoot(ctx);
|
|
3024
|
-
if (!existsSync(
|
|
3257
|
+
if (!existsSync(path21.join(ctx.root, rootDir))) {
|
|
3025
3258
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
3026
3259
|
return;
|
|
3027
3260
|
}
|
|
@@ -3077,7 +3310,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
3077
3310
|
function readExpoConfigs(root) {
|
|
3078
3311
|
const out = [];
|
|
3079
3312
|
for (const name of EXPO_CONFIGS) {
|
|
3080
|
-
const abs =
|
|
3313
|
+
const abs = path21.join(root, name);
|
|
3081
3314
|
if (!existsSync(abs)) continue;
|
|
3082
3315
|
const text = readFileSync(abs, "utf8");
|
|
3083
3316
|
let json = null;
|
|
@@ -3111,13 +3344,13 @@ function pluginOptions(json, module) {
|
|
|
3111
3344
|
return null;
|
|
3112
3345
|
}
|
|
3113
3346
|
function dependencies(root) {
|
|
3114
|
-
const file =
|
|
3347
|
+
const file = path21.join(root, "package.json");
|
|
3115
3348
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
3116
3349
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3117
3350
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
3118
3351
|
}
|
|
3119
3352
|
function runtimeDependencies(root) {
|
|
3120
|
-
const file =
|
|
3353
|
+
const file = path21.join(root, "package.json");
|
|
3121
3354
|
if (!existsSync(file)) return {};
|
|
3122
3355
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
3123
3356
|
}
|
|
@@ -3371,14 +3604,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3371
3604
|
seen.add(file);
|
|
3372
3605
|
const json = readJsonc(file);
|
|
3373
3606
|
if (!json) return {};
|
|
3374
|
-
const dir =
|
|
3607
|
+
const dir = path21.dirname(file);
|
|
3375
3608
|
let merged = {};
|
|
3376
3609
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3377
3610
|
for (const ext of parents) {
|
|
3378
3611
|
if (typeof ext !== "string") continue;
|
|
3379
3612
|
let target = null;
|
|
3380
|
-
if (ext.startsWith(".") ||
|
|
3381
|
-
const abs =
|
|
3613
|
+
if (ext.startsWith(".") || path21.isAbsolute(ext)) {
|
|
3614
|
+
const abs = path21.resolve(dir, ext);
|
|
3382
3615
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3383
3616
|
} else {
|
|
3384
3617
|
const parts = ext.split("/");
|
|
@@ -3386,14 +3619,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3386
3619
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3387
3620
|
if (pkgDir) {
|
|
3388
3621
|
const sub = parts.slice(nameLength).join("/");
|
|
3389
|
-
const abs =
|
|
3622
|
+
const abs = path21.join(pkgDir, sub || "tsconfig.json");
|
|
3390
3623
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3391
3624
|
}
|
|
3392
3625
|
}
|
|
3393
3626
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3394
3627
|
}
|
|
3395
3628
|
const opts = json.compilerOptions ?? {};
|
|
3396
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
3629
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path21.resolve(dir, opts.baseUrl);
|
|
3397
3630
|
if (opts.paths && typeof opts.paths === "object") {
|
|
3398
3631
|
merged.paths = opts.paths;
|
|
3399
3632
|
merged.pathsDir = dir;
|
|
@@ -3404,7 +3637,7 @@ function aliases(root) {
|
|
|
3404
3637
|
const table = [];
|
|
3405
3638
|
let baseUrl = null;
|
|
3406
3639
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3407
|
-
const file =
|
|
3640
|
+
const file = path21.join(root, name);
|
|
3408
3641
|
if (!existsSync(file)) continue;
|
|
3409
3642
|
const config = readTsconfig(root, file);
|
|
3410
3643
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -3412,22 +3645,22 @@ function aliases(root) {
|
|
|
3412
3645
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3413
3646
|
if (!Array.isArray(targets)) continue;
|
|
3414
3647
|
const exact = !pattern.endsWith("*");
|
|
3415
|
-
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(/\*$/, ""))) });
|
|
3416
3649
|
}
|
|
3417
3650
|
}
|
|
3418
|
-
const pkg = readJsonc(
|
|
3651
|
+
const pkg = readJsonc(path21.join(root, "package.json"));
|
|
3419
3652
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3420
3653
|
if (typeof target !== "string") continue;
|
|
3421
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
3654
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path21.join(root, target.replace(/\*.*$/, ""))] });
|
|
3422
3655
|
}
|
|
3423
|
-
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] });
|
|
3424
3657
|
return { table, baseUrl };
|
|
3425
3658
|
}
|
|
3426
3659
|
function resolveFile(base) {
|
|
3427
|
-
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}`))];
|
|
3428
3661
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3429
3662
|
for (const p of tries) {
|
|
3430
|
-
if (SCRIPT_EXTS2.has(
|
|
3663
|
+
if (SCRIPT_EXTS2.has(path21.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3431
3664
|
}
|
|
3432
3665
|
return null;
|
|
3433
3666
|
}
|
|
@@ -3441,7 +3674,7 @@ function createTrail(ctx) {
|
|
|
3441
3674
|
const { table, baseUrl } = aliases(ctx.root);
|
|
3442
3675
|
let declared = null;
|
|
3443
3676
|
try {
|
|
3444
|
-
const pkg = JSON.parse(readFileSync(
|
|
3677
|
+
const pkg = JSON.parse(readFileSync(path21.join(ctx.root, "package.json"), "utf8"));
|
|
3445
3678
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3446
3679
|
} catch {
|
|
3447
3680
|
declared = null;
|
|
@@ -3472,17 +3705,17 @@ function createTrail(ctx) {
|
|
|
3472
3705
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3473
3706
|
let resolved = null;
|
|
3474
3707
|
if (spec.startsWith(".")) {
|
|
3475
|
-
resolved = resolveFile(
|
|
3708
|
+
resolved = resolveFile(path21.resolve(path21.dirname(file.absolutePath), spec));
|
|
3476
3709
|
if (!resolved) lost = true;
|
|
3477
3710
|
} else {
|
|
3478
3711
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3479
3712
|
if (alias) {
|
|
3480
3713
|
for (const t of alias.targets) {
|
|
3481
|
-
resolved = resolveFile(alias.exact ? t :
|
|
3714
|
+
resolved = resolveFile(alias.exact ? t : path21.join(t, spec.slice(alias.prefix.length)));
|
|
3482
3715
|
if (resolved) break;
|
|
3483
3716
|
}
|
|
3484
3717
|
}
|
|
3485
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
3718
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path21.join(baseUrl, spec));
|
|
3486
3719
|
if (!resolved) {
|
|
3487
3720
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3488
3721
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -3493,218 +3726,65 @@ function createTrail(ctx) {
|
|
|
3493
3726
|
const out = { files, lost };
|
|
3494
3727
|
importsCache.set(file.absolutePath, out);
|
|
3495
3728
|
return out;
|
|
3496
|
-
};
|
|
3497
|
-
const strippedCache = /* @__PURE__ */ new Map();
|
|
3498
|
-
const stripped = (file) => {
|
|
3499
|
-
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
3500
|
-
return strippedCache.get(file.absolutePath);
|
|
3501
|
-
};
|
|
3502
|
-
const memo = /* @__PURE__ */ new WeakMap();
|
|
3503
|
-
const reach = (file, test2, depth, seen) => {
|
|
3504
|
-
let cache2 = memo.get(test2);
|
|
3505
|
-
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
3506
|
-
const k = `${file.absolutePath}\0${depth}`;
|
|
3507
|
-
const free = cache2.free.get(k);
|
|
3508
|
-
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
3509
|
-
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
3510
|
-
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
3511
|
-
let result;
|
|
3512
|
-
const cut = /* @__PURE__ */ new Set();
|
|
3513
|
-
const code = stripped(file);
|
|
3514
|
-
if (code === null) result = "unknown";
|
|
3515
|
-
else if (test2(code)) result = "yes";
|
|
3516
|
-
else {
|
|
3517
|
-
const { files, lost } = importsOf(file);
|
|
3518
|
-
let unknown = lost && depth > 0;
|
|
3519
|
-
result = "no";
|
|
3520
|
-
if (depth > 0) {
|
|
3521
|
-
seen.add(file.absolutePath);
|
|
3522
|
-
for (const abs of files) {
|
|
3523
|
-
if (seen.has(abs)) {
|
|
3524
|
-
cut.add(abs);
|
|
3525
|
-
continue;
|
|
3526
|
-
}
|
|
3527
|
-
const target = read2(abs);
|
|
3528
|
-
if (!target) {
|
|
3529
|
-
unknown = true;
|
|
3530
|
-
continue;
|
|
3531
|
-
}
|
|
3532
|
-
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
3533
|
-
for (const m of c) cut.add(m);
|
|
3534
|
-
if (r === "yes") {
|
|
3535
|
-
result = "yes";
|
|
3536
|
-
break;
|
|
3537
|
-
}
|
|
3538
|
-
if (r === "unknown") unknown = true;
|
|
3539
|
-
}
|
|
3540
|
-
seen.delete(file.absolutePath);
|
|
3541
|
-
cut.delete(file.absolutePath);
|
|
3542
|
-
}
|
|
3543
|
-
if (result === "no" && unknown) result = "unknown";
|
|
3544
|
-
}
|
|
3545
|
-
if (result === "yes" || cut.size === 0) {
|
|
3546
|
-
cache2.free.set(k, result);
|
|
3547
|
-
return [result, /* @__PURE__ */ new Set()];
|
|
3548
|
-
}
|
|
3549
|
-
const entries = cache2.cut.get(k) ?? [];
|
|
3550
|
-
entries.push({ cut: [...cut], result });
|
|
3551
|
-
cache2.cut.set(k, entries);
|
|
3552
|
-
return [result, cut];
|
|
3553
|
-
};
|
|
3554
|
-
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3555
|
-
}
|
|
3556
|
-
function buildCatalog(packagesDir) {
|
|
3557
|
-
const packages = {};
|
|
3558
|
-
for (const dir of readdirSync(packagesDir).sort()) {
|
|
3559
|
-
const file = path20.join(packagesDir, dir, "package.json");
|
|
3560
|
-
if (!existsSync(file)) continue;
|
|
3561
|
-
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3562
|
-
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
3563
|
-
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
3564
|
-
}
|
|
3565
|
-
return { packages };
|
|
3566
|
-
}
|
|
3567
|
-
|
|
3568
|
-
// src/blocks/discover.ts
|
|
3569
|
-
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
3570
|
-
function cliPackageDir() {
|
|
3571
|
-
let dir = path20.dirname(fileURLToPath(import.meta.url));
|
|
3572
|
-
for (; ; ) {
|
|
3573
|
-
const file = path20.join(dir, "package.json");
|
|
3574
|
-
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
3575
|
-
const parent = path20.dirname(dir);
|
|
3576
|
-
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
3577
|
-
dir = parent;
|
|
3578
|
-
}
|
|
3579
|
-
}
|
|
3580
|
-
function workspacePackagesDir() {
|
|
3581
|
-
const dir = path20.resolve(cliPackageDir(), "..");
|
|
3582
|
-
return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
3583
|
-
}
|
|
3584
|
-
var catalogCache;
|
|
3585
|
-
function readCatalog() {
|
|
3586
|
-
if (catalogCache) return catalogCache;
|
|
3587
|
-
const workspace = workspacePackagesDir();
|
|
3588
|
-
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
3589
|
-
const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
3590
|
-
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
3591
|
-
return catalogCache;
|
|
3592
|
-
}
|
|
3593
|
-
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
3594
|
-
function installedGenesis(root) {
|
|
3595
|
-
const found = /* @__PURE__ */ new Map();
|
|
3596
|
-
let dir = path20.resolve(root);
|
|
3597
|
-
for (; ; ) {
|
|
3598
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
|
|
3599
|
-
const scope = path20.join(dir, "node_modules", "@marktiderman");
|
|
3600
|
-
if (existsSync(scope)) {
|
|
3601
|
-
for (const entry of readdirSync(scope)) {
|
|
3602
|
-
const name = `@marktiderman/${entry}`;
|
|
3603
|
-
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
3604
|
-
if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
|
|
3605
|
-
}
|
|
3606
|
-
}
|
|
3607
|
-
const parent = path20.dirname(dir);
|
|
3608
|
-
if (atInstallRoot || parent === dir) return found;
|
|
3609
|
-
dir = parent;
|
|
3610
|
-
}
|
|
3611
|
-
}
|
|
3612
|
-
var declarationCache = /* @__PURE__ */ new Map();
|
|
3613
|
-
function declarationsOf(dir, warnings) {
|
|
3614
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3615
|
-
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
3616
|
-
let cached = declarationCache.get(key2);
|
|
3617
|
-
if (!cached) {
|
|
3618
|
-
cached = loadDeclarations(dir, warnings);
|
|
3619
|
-
declarationCache.set(key2, cached);
|
|
3620
|
-
}
|
|
3621
|
-
return cached;
|
|
3622
|
-
}
|
|
3623
|
-
async function loadDeclarations(dir, warnings) {
|
|
3624
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3625
|
-
const entry = pkg.exports?.["./blocks"];
|
|
3626
|
-
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
3627
|
-
if (typeof target !== "string") return {};
|
|
3628
|
-
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
3629
|
-
const file = rel && path20.join(dir, ...rel.split("/"));
|
|
3630
|
-
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
3631
|
-
try {
|
|
3632
|
-
const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
|
|
3633
|
-
const mod = await jiti.import(file);
|
|
3634
|
-
const out = {};
|
|
3635
|
-
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
3636
|
-
return out;
|
|
3637
|
-
} catch (err) {
|
|
3638
|
-
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.`);
|
|
3639
|
-
return {};
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
3643
|
-
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3644
|
-
const raw = rawBlocksOf(pkg);
|
|
3645
|
-
const declared = await declarationsOf(dir, warnings);
|
|
3646
|
-
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
3647
|
-
const out = [];
|
|
3648
|
-
for (const id of [...ids].sort()) {
|
|
3649
|
-
const fromJson = raw[id] ?? {};
|
|
3650
|
-
const merged = { ...fromJson, ...declared[id] };
|
|
3651
|
-
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
3652
|
-
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
3653
|
-
if (manifest) out.push(manifest);
|
|
3654
|
-
}
|
|
3655
|
-
return out;
|
|
3656
|
-
}
|
|
3657
|
-
function withProvides(declared, json) {
|
|
3658
|
-
if (!Array.isArray(declared)) return declared;
|
|
3659
|
-
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
3660
|
-
return declared.map((m) => {
|
|
3661
|
-
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
3662
|
-
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
3663
|
-
});
|
|
3664
|
-
}
|
|
3665
|
-
async function allBlocks(root, warnings = []) {
|
|
3666
|
-
const out = [];
|
|
3667
|
-
for (const local of localPackages(root)) {
|
|
3668
|
-
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
3669
|
-
}
|
|
3670
|
-
const installed = installedGenesis(root);
|
|
3671
|
-
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
3672
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
3673
|
-
if (installed.has(name)) continue;
|
|
3674
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
3675
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
3676
|
-
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";
|
|
3677
3777
|
}
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
function tryParse(parse2, warnings) {
|
|
3682
|
-
try {
|
|
3683
|
-
return parse2();
|
|
3684
|
-
} catch (err) {
|
|
3685
|
-
if (!(err instanceof ManifestError)) throw err;
|
|
3686
|
-
warnings.push(err.message);
|
|
3687
|
-
return null;
|
|
3688
|
-
}
|
|
3689
|
-
}
|
|
3690
|
-
function catalogBlocks(warnings = []) {
|
|
3691
|
-
const out = [];
|
|
3692
|
-
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
3693
|
-
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
3694
|
-
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
3695
|
-
if (manifest) out.push(manifest);
|
|
3778
|
+
if (result === "yes" || cut.size === 0) {
|
|
3779
|
+
cache2.free.set(k, result);
|
|
3780
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
3696
3781
|
}
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
3704
|
-
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
3705
|
-
}
|
|
3706
|
-
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
3707
|
-
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] };
|
|
3708
3788
|
}
|
|
3709
3789
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3710
3790
|
var STEMS = {
|
|
@@ -3723,7 +3803,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
3723
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;
|
|
3724
3804
|
function routesDir(ctx) {
|
|
3725
3805
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3726
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
3806
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path21.join(ctx.root, d))) ?? null;
|
|
3727
3807
|
}
|
|
3728
3808
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3729
3809
|
function flavorOf(dir, rels) {
|
|
@@ -3858,7 +3938,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3858
3938
|
});
|
|
3859
3939
|
if (typeof raw === "string") {
|
|
3860
3940
|
if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
|
|
3861
|
-
const file =
|
|
3941
|
+
const file = path21.resolve(packageDir, raw);
|
|
3862
3942
|
if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
|
|
3863
3943
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
3864
3944
|
let parsed;
|
|
@@ -3907,7 +3987,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3907
3987
|
if (typeof c.plugin === "string") {
|
|
3908
3988
|
if (!packageDir) plugin = c.plugin;
|
|
3909
3989
|
else {
|
|
3910
|
-
plugin =
|
|
3990
|
+
plugin = path21.resolve(packageDir, c.plugin);
|
|
3911
3991
|
if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
3912
3992
|
}
|
|
3913
3993
|
}
|
|
@@ -3957,7 +4037,7 @@ function checkPattern(v, where2, fail) {
|
|
|
3957
4037
|
}
|
|
3958
4038
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
3959
4039
|
function readDeclaringPackage(dir, local) {
|
|
3960
|
-
const file =
|
|
4040
|
+
const file = path21.join(dir, "package.json");
|
|
3961
4041
|
let stamp;
|
|
3962
4042
|
let real2;
|
|
3963
4043
|
try {
|
|
@@ -3980,7 +4060,7 @@ ${local}`;
|
|
|
3980
4060
|
const pkg = {
|
|
3981
4061
|
name: json.name,
|
|
3982
4062
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
3983
|
-
dir:
|
|
4063
|
+
dir: path21.resolve(dir),
|
|
3984
4064
|
namespace: ruleNamespace(json.name),
|
|
3985
4065
|
local,
|
|
3986
4066
|
private: json.private === true,
|
|
@@ -3994,7 +4074,7 @@ ${local}`;
|
|
|
3994
4074
|
if (raw !== void 0) {
|
|
3995
4075
|
const ignored = [];
|
|
3996
4076
|
try {
|
|
3997
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
4077
|
+
pkg.declaration = validateDeclaration(raw, json.name, path21.resolve(dir), ignored);
|
|
3998
4078
|
if (ignored.length) pkg.ignored = ignored;
|
|
3999
4079
|
} catch (err) {
|
|
4000
4080
|
pkg.error = err.message;
|
|
@@ -4013,14 +4093,14 @@ function discoverPackages(root) {
|
|
|
4013
4093
|
for (const dir of installed) {
|
|
4014
4094
|
let scope;
|
|
4015
4095
|
try {
|
|
4016
|
-
scope =
|
|
4096
|
+
scope = path21.dirname(realpathSync(dir));
|
|
4017
4097
|
} catch {
|
|
4018
4098
|
continue;
|
|
4019
4099
|
}
|
|
4020
|
-
if (
|
|
4100
|
+
if (path21.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
4021
4101
|
for (const entry of readdirSync(scope)) {
|
|
4022
4102
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
4023
|
-
const pkg = readDeclaringPackage(
|
|
4103
|
+
const pkg = readDeclaringPackage(path21.join(scope, entry), false);
|
|
4024
4104
|
if (pkg) byName.set(pkg.name, pkg);
|
|
4025
4105
|
}
|
|
4026
4106
|
}
|
|
@@ -4207,10 +4287,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
4207
4287
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
4208
4288
|
function sourceFiles(dir, rel = "") {
|
|
4209
4289
|
const out = [];
|
|
4210
|
-
for (const entry of readdirSync(
|
|
4290
|
+
for (const entry of readdirSync(path21.join(dir, rel)).sort()) {
|
|
4211
4291
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
4212
4292
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
4213
|
-
const stat = lstatSync(
|
|
4293
|
+
const stat = lstatSync(path21.join(dir, child));
|
|
4214
4294
|
if (stat.isSymbolicLink()) continue;
|
|
4215
4295
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
4216
4296
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -4233,13 +4313,13 @@ function matchPattern(pattern, spec) {
|
|
|
4233
4313
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
4234
4314
|
}
|
|
4235
4315
|
function tsconfigPaths(dir) {
|
|
4236
|
-
const file =
|
|
4316
|
+
const file = path21.join(dir, "tsconfig.json");
|
|
4237
4317
|
if (!existsSync(file)) return [];
|
|
4238
4318
|
try {
|
|
4239
4319
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
4240
4320
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
4241
|
-
const base =
|
|
4242
|
-
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)) }));
|
|
4243
4323
|
} catch {
|
|
4244
4324
|
return [];
|
|
4245
4325
|
}
|
|
@@ -4253,8 +4333,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4253
4333
|
const hit = matchPattern(pattern, spec);
|
|
4254
4334
|
if (hit === null) continue;
|
|
4255
4335
|
return targets.some((t) => {
|
|
4256
|
-
const rel =
|
|
4257
|
-
return !rel.startsWith("..") && !
|
|
4336
|
+
const rel = path21.relative(pkg.dir, t.replace("*", hit));
|
|
4337
|
+
return !rel.startsWith("..") && !path21.isAbsolute(rel);
|
|
4258
4338
|
});
|
|
4259
4339
|
}
|
|
4260
4340
|
return null;
|
|
@@ -4267,7 +4347,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4267
4347
|
...Object.keys(json.optionalDependencies ?? {})
|
|
4268
4348
|
]);
|
|
4269
4349
|
for (const file of sourceFiles(pkg.dir)) {
|
|
4270
|
-
const code = stripForImports(readFileSync(
|
|
4350
|
+
const code = stripForImports(readFileSync(path21.join(pkg.dir, file), "utf8"));
|
|
4271
4351
|
if (code === null) continue;
|
|
4272
4352
|
const at = `${pkg.rel}/${file}`;
|
|
4273
4353
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -4292,9 +4372,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4292
4372
|
continue;
|
|
4293
4373
|
}
|
|
4294
4374
|
if (spec.startsWith(".")) {
|
|
4295
|
-
const target =
|
|
4296
|
-
const rel =
|
|
4297
|
-
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)) {
|
|
4298
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` });
|
|
4299
4379
|
}
|
|
4300
4380
|
continue;
|
|
@@ -4331,12 +4411,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4331
4411
|
const from = own ? "" : ` (in ${m.package})`;
|
|
4332
4412
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
4333
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` });
|
|
4334
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
4414
|
+
} else if (typeof m.test === "string" && !existsSync(path21.join(home, m.test))) {
|
|
4335
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` });
|
|
4336
4416
|
}
|
|
4337
4417
|
}
|
|
4338
4418
|
}
|
|
4339
|
-
const dir =
|
|
4419
|
+
const dir = path21.join(pkg.dir, "migrations");
|
|
4340
4420
|
if (!existsSync(dir)) return;
|
|
4341
4421
|
const seen = /* @__PURE__ */ new Map();
|
|
4342
4422
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -4345,21 +4425,21 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4345
4425
|
const other = seen.get(m[1]);
|
|
4346
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` });
|
|
4347
4427
|
else seen.set(m[1], name);
|
|
4348
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
4428
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path21.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
4349
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")})` });
|
|
4350
4430
|
}
|
|
4351
4431
|
}
|
|
4352
4432
|
}
|
|
4353
4433
|
function checkExports(ctx, pkg, json) {
|
|
4354
4434
|
const targets = [];
|
|
4355
|
-
const
|
|
4435
|
+
const walk3 = (v) => {
|
|
4356
4436
|
if (typeof v === "string") targets.push(v);
|
|
4357
|
-
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);
|
|
4358
4438
|
};
|
|
4359
|
-
|
|
4439
|
+
walk3(json.exports);
|
|
4360
4440
|
for (const t of targets) {
|
|
4361
4441
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
4362
|
-
if (!existsSync(
|
|
4442
|
+
if (!existsSync(path21.join(pkg.dir, t))) {
|
|
4363
4443
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
4364
4444
|
}
|
|
4365
4445
|
}
|
|
@@ -4377,11 +4457,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
4377
4457
|
function checkTaggedTests(ctx, pkg) {
|
|
4378
4458
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
4379
4459
|
if (!tests.length) return;
|
|
4380
|
-
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")));
|
|
4381
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>` });
|
|
4382
4462
|
}
|
|
4383
4463
|
function checkRegistered(ctx, pkg) {
|
|
4384
|
-
const file =
|
|
4464
|
+
const file = path21.join(ctx.root, "features.json");
|
|
4385
4465
|
if (!existsSync(file)) return;
|
|
4386
4466
|
let doc;
|
|
4387
4467
|
try {
|
|
@@ -4391,7 +4471,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
4391
4471
|
}
|
|
4392
4472
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4393
4473
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
4394
|
-
if (top) forms.add(
|
|
4474
|
+
if (top) forms.add(path21.relative(top, realpathSync(pkg.dir)).split(path21.sep).join("/"));
|
|
4395
4475
|
const covered = (doc.features ?? []).some(
|
|
4396
4476
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
4397
4477
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -4421,8 +4501,8 @@ function mergeBaseOf(root, base) {
|
|
|
4421
4501
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
4422
4502
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4423
4503
|
if (!top) return;
|
|
4424
|
-
const appRelative = (fromTop) =>
|
|
4425
|
-
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("/");
|
|
4426
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");
|
|
4427
4507
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
4428
4508
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -4445,11 +4525,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4445
4525
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
4446
4526
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
4447
4527
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
4448
|
-
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)) : [];
|
|
4449
4529
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
4450
4530
|
const named = naming.length > 0;
|
|
4451
4531
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
4452
|
-
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` });
|
|
4453
4533
|
}
|
|
4454
4534
|
let jsonBefore = null;
|
|
4455
4535
|
try {
|
|
@@ -4459,7 +4539,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4459
4539
|
}
|
|
4460
4540
|
const raw = json;
|
|
4461
4541
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
4462
|
-
const appInRepo =
|
|
4542
|
+
const appInRepo = path21.relative(top, realpathSync(ctx.root)).split(path21.sep).join("/");
|
|
4463
4543
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
4464
4544
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
4465
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` });
|
|
@@ -4511,7 +4591,7 @@ function checkPackagesPack(ctx) {
|
|
|
4511
4591
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
4512
4592
|
}
|
|
4513
4593
|
for (const pkg of packages) {
|
|
4514
|
-
const json = JSON.parse(readFileSync(
|
|
4594
|
+
const json = JSON.parse(readFileSync(path21.join(pkg.dir, "package.json"), "utf8"));
|
|
4515
4595
|
checkImports2(ctx, pkg, json);
|
|
4516
4596
|
checkExports(ctx, pkg, json);
|
|
4517
4597
|
checkBlocks(ctx, pkg, json);
|
|
@@ -4528,7 +4608,7 @@ function emptyLock() {
|
|
|
4528
4608
|
return { version: 1, blocks: {}, files: {} };
|
|
4529
4609
|
}
|
|
4530
4610
|
function readLock(root) {
|
|
4531
|
-
const file =
|
|
4611
|
+
const file = path21.join(root, LOCK_FILE);
|
|
4532
4612
|
if (!existsSync(file)) return emptyLock();
|
|
4533
4613
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
4534
4614
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
@@ -4551,11 +4631,11 @@ function databaseElsewhere(root) {
|
|
|
4551
4631
|
const setting = readGenesisConfig(root)?.supabase;
|
|
4552
4632
|
if (setting === void 0) return null;
|
|
4553
4633
|
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
4554
|
-
const resolved =
|
|
4634
|
+
const resolved = path21.resolve(root, setting.app);
|
|
4555
4635
|
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
4556
4636
|
const dir = real2(resolved);
|
|
4557
|
-
if (dir === real2(
|
|
4558
|
-
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")) };
|
|
4559
4639
|
}
|
|
4560
4640
|
function isSupabasePath(rel) {
|
|
4561
4641
|
return rel === "supabase" || rel.startsWith("supabase/");
|
|
@@ -4745,9 +4825,9 @@ function checkSupabasePack(ctx) {
|
|
|
4745
4825
|
if (databaseElsewhere(ctx.root)) return;
|
|
4746
4826
|
const settings = ctx.config.supabase ?? {};
|
|
4747
4827
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
4748
|
-
const abs =
|
|
4828
|
+
const abs = path21.join(ctx.root, dir);
|
|
4749
4829
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
4750
|
-
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")) }));
|
|
4751
4831
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
4752
4832
|
const base = settings.base ?? DEFAULT_BASE;
|
|
4753
4833
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -4764,7 +4844,7 @@ function checkSupabasePack(ctx) {
|
|
|
4764
4844
|
}
|
|
4765
4845
|
}
|
|
4766
4846
|
const since = settings.since;
|
|
4767
|
-
const afterSince = (file) => since === void 0 ||
|
|
4847
|
+
const afterSince = (file) => since === void 0 || path21.posix.basename(file) >= since;
|
|
4768
4848
|
if ("reason" in view && since === void 0) {
|
|
4769
4849
|
ctx.report({
|
|
4770
4850
|
rule: "migration-grants",
|
|
@@ -5047,7 +5127,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
|
5047
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)$/;
|
|
5048
5128
|
var readManifest = (dir) => {
|
|
5049
5129
|
try {
|
|
5050
|
-
return JSON.parse(readFileSync(
|
|
5130
|
+
return JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
5051
5131
|
} catch {
|
|
5052
5132
|
return null;
|
|
5053
5133
|
}
|
|
@@ -5061,18 +5141,18 @@ var real = (p) => {
|
|
|
5061
5141
|
};
|
|
5062
5142
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
5063
5143
|
function nodeModulesOf(dir) {
|
|
5064
|
-
const parent =
|
|
5065
|
-
return
|
|
5144
|
+
const parent = path21.dirname(dir);
|
|
5145
|
+
return path21.basename(parent).startsWith("@") ? path21.dirname(parent) : parent;
|
|
5066
5146
|
}
|
|
5067
5147
|
function packagesIn(nodeModules) {
|
|
5068
5148
|
if (!existsSync(nodeModules)) return [];
|
|
5069
5149
|
const out = [];
|
|
5070
5150
|
for (const entry of readdirSync(nodeModules)) {
|
|
5071
5151
|
if (entry.startsWith(".")) continue;
|
|
5072
|
-
const p =
|
|
5152
|
+
const p = path21.join(nodeModules, entry);
|
|
5073
5153
|
if (entry.startsWith("@")) {
|
|
5074
5154
|
try {
|
|
5075
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5155
|
+
for (const sub of readdirSync(p)) out.push(path21.join(p, sub));
|
|
5076
5156
|
} catch {
|
|
5077
5157
|
}
|
|
5078
5158
|
} else {
|
|
@@ -5084,7 +5164,7 @@ function packagesIn(nodeModules) {
|
|
|
5084
5164
|
function genesisInstalls(root) {
|
|
5085
5165
|
const copies = /* @__PURE__ */ new Map();
|
|
5086
5166
|
const realRoot = real(root);
|
|
5087
|
-
const rel = (abs) =>
|
|
5167
|
+
const rel = (abs) => path21.relative(realRoot, abs).split(path21.sep).join("/") || ".";
|
|
5088
5168
|
const via = /* @__PURE__ */ new Map();
|
|
5089
5169
|
const record = (real2, manifest, by, range, root2) => {
|
|
5090
5170
|
let copy = copies.get(real2);
|
|
@@ -5096,7 +5176,7 @@ function genesisInstalls(root) {
|
|
|
5096
5176
|
via.get(real2).add(root2);
|
|
5097
5177
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
5098
5178
|
};
|
|
5099
|
-
const
|
|
5179
|
+
const walk3 = (kind, roots) => {
|
|
5100
5180
|
const expanded = /* @__PURE__ */ new Set();
|
|
5101
5181
|
const queue = [];
|
|
5102
5182
|
const visit = (dir, by, range) => {
|
|
@@ -5129,7 +5209,7 @@ function genesisInstalls(root) {
|
|
|
5129
5209
|
if (!dir) return null;
|
|
5130
5210
|
if (!ownInstall || name in declared) return dir;
|
|
5131
5211
|
const realDir = real(dir);
|
|
5132
|
-
if (realDir.startsWith(realRoot +
|
|
5212
|
+
if (realDir.startsWith(realRoot + path21.sep)) return dir;
|
|
5133
5213
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
5134
5214
|
};
|
|
5135
5215
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -5137,7 +5217,7 @@ function genesisInstalls(root) {
|
|
|
5137
5217
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
5138
5218
|
});
|
|
5139
5219
|
const app = readManifest(root);
|
|
5140
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5220
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path21.join(root, f)));
|
|
5141
5221
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
5142
5222
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
5143
5223
|
const runtimeDeps = {
|
|
@@ -5147,18 +5227,18 @@ function genesisInstalls(root) {
|
|
|
5147
5227
|
...app?.dependencies
|
|
5148
5228
|
};
|
|
5149
5229
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
5150
|
-
|
|
5151
|
-
const top =
|
|
5152
|
-
|
|
5230
|
+
walk3("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5231
|
+
const top = path21.join(root, "node_modules");
|
|
5232
|
+
walk3(
|
|
5153
5233
|
"hoisted",
|
|
5154
5234
|
packagesIn(top).filter((dir) => {
|
|
5155
|
-
const name =
|
|
5235
|
+
const name = path21.relative(top, dir).split(path21.sep).join("/");
|
|
5156
5236
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
5157
5237
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
5158
5238
|
);
|
|
5159
5239
|
const devRoots = { ...devDeps };
|
|
5160
5240
|
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
5161
|
-
|
|
5241
|
+
walk3("dev", rootsOf(devRoots, "the app (dev)"));
|
|
5162
5242
|
for (const [key2, copy] of copies) {
|
|
5163
5243
|
const kinds = via.get(key2);
|
|
5164
5244
|
copy.runtime = kinds.has("runtime");
|
|
@@ -5194,7 +5274,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
5194
5274
|
}
|
|
5195
5275
|
}
|
|
5196
5276
|
function checkPeerRanges(ctx) {
|
|
5197
|
-
const rel = (abs) =>
|
|
5277
|
+
const rel = (abs) => path21.relative(ctx.root, abs).split(path21.sep).join("/");
|
|
5198
5278
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
5199
5279
|
for (const copy of copies) {
|
|
5200
5280
|
const dir = copy.absolutePath;
|
|
@@ -5381,6 +5461,24 @@ function checkIsoDateSlices(ctx) {
|
|
|
5381
5461
|
}
|
|
5382
5462
|
}
|
|
5383
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
|
+
}
|
|
5384
5482
|
|
|
5385
5483
|
// src/upgrade/scope-names.ts
|
|
5386
5484
|
var IMPORTS_GENESIS = /\bfrom\s*["']@marktiderman\/genesis[\w/-]*["']/;
|
|
@@ -5575,11 +5673,11 @@ var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
|
|
|
5575
5673
|
var TESTING_LIBRARY = "eslint-plugin-testing-library";
|
|
5576
5674
|
var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
|
|
5577
5675
|
function findEslintConfig(root) {
|
|
5578
|
-
return FLAT_CONFIG_FILES.find((name) => existsSync(
|
|
5676
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path21.join(root, name))) ?? null;
|
|
5579
5677
|
}
|
|
5580
5678
|
function readPackageJson(root) {
|
|
5581
5679
|
try {
|
|
5582
|
-
return JSON.parse(readFileSync(
|
|
5680
|
+
return JSON.parse(readFileSync(path21.join(root, "package.json"), "utf8"));
|
|
5583
5681
|
} catch {
|
|
5584
5682
|
return null;
|
|
5585
5683
|
}
|
|
@@ -5595,26 +5693,6 @@ function usesGenesisLint(text) {
|
|
|
5595
5693
|
return text.includes(ESLINT_EXPORT);
|
|
5596
5694
|
}
|
|
5597
5695
|
|
|
5598
|
-
// src/upgrade/codemods.ts
|
|
5599
|
-
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
5600
|
-
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
5601
|
-
var MAX_BYTES = 2 * 1024 * 1024;
|
|
5602
|
-
function appScripts(root) {
|
|
5603
|
-
const out = [];
|
|
5604
|
-
const walk2 = (dir) => {
|
|
5605
|
-
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5606
|
-
const abs = path20.join(dir, entry.name);
|
|
5607
|
-
if (entry.isDirectory()) {
|
|
5608
|
-
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
5609
|
-
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
5610
|
-
out.push(path20.relative(root, abs).split(path20.sep).join("/"));
|
|
5611
|
-
}
|
|
5612
|
-
}
|
|
5613
|
-
};
|
|
5614
|
-
walk2(root);
|
|
5615
|
-
return out;
|
|
5616
|
-
}
|
|
5617
|
-
|
|
5618
5696
|
// src/doctor/api-usage.ts
|
|
5619
5697
|
var SCRIPT_EXTS5 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
5620
5698
|
function openingTag(code, start) {
|
|
@@ -5695,7 +5773,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
5695
5773
|
function moduleFiles(ctx) {
|
|
5696
5774
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
5697
5775
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
5698
|
-
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) }));
|
|
5699
5777
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
5700
5778
|
}
|
|
5701
5779
|
function checkStudioServerImports(ctx) {
|
|
@@ -5731,7 +5809,7 @@ var REMOVED_WORDS = {
|
|
|
5731
5809
|
};
|
|
5732
5810
|
function checkRemovedScopeNames(ctx) {
|
|
5733
5811
|
let augmentedMemo;
|
|
5734
|
-
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")));
|
|
5735
5813
|
for (const file of ctx.files) {
|
|
5736
5814
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
5737
5815
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -5803,16 +5881,16 @@ function genesisNamedImports(source) {
|
|
|
5803
5881
|
}
|
|
5804
5882
|
function declarationFiles(dir, out = []) {
|
|
5805
5883
|
for (const name of readdirSync(dir)) {
|
|
5806
|
-
const full =
|
|
5884
|
+
const full = path21.join(dir, name);
|
|
5807
5885
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
5808
5886
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
5809
5887
|
}
|
|
5810
5888
|
return out;
|
|
5811
5889
|
}
|
|
5812
5890
|
function readPackageTags(dir) {
|
|
5813
|
-
const pkg = JSON.parse(readFileSync(
|
|
5891
|
+
const pkg = JSON.parse(readFileSync(path21.join(dir, "package.json"), "utf8"));
|
|
5814
5892
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
5815
|
-
const dist =
|
|
5893
|
+
const dist = path21.join(dir, "dist");
|
|
5816
5894
|
if (!existsSync(dist)) return tags;
|
|
5817
5895
|
for (const file of declarationFiles(dist)) {
|
|
5818
5896
|
const text = readFileSync(file, "utf8");
|
|
@@ -5830,7 +5908,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
5830
5908
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
5831
5909
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
5832
5910
|
const types = typeof target === "object" && target ? target.types : null;
|
|
5833
|
-
return typeof types === "string" ?
|
|
5911
|
+
return typeof types === "string" ? path21.join(tags.dir, types) : null;
|
|
5834
5912
|
}
|
|
5835
5913
|
function tagFor(tags, entry, name) {
|
|
5836
5914
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -5885,7 +5963,7 @@ function showAt(dir, rev, file) {
|
|
|
5885
5963
|
function configAtBase(root, base, explicitFile) {
|
|
5886
5964
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
5887
5965
|
if (!mergeBase) return null;
|
|
5888
|
-
const candidates = explicitFile ? [{ dir:
|
|
5966
|
+
const candidates = explicitFile ? [{ dir: path21.dirname(explicitFile), file: path21.basename(explicitFile), explicit: true }] : [
|
|
5889
5967
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
5890
5968
|
{ dir: root, file: "package.json", explicit: false }
|
|
5891
5969
|
];
|
|
@@ -5997,7 +6075,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5997
6075
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
5998
6076
|
let current = null;
|
|
5999
6077
|
try {
|
|
6000
|
-
current = lf(readFileSync(
|
|
6078
|
+
current = lf(readFileSync(path21.join(ctx.root, out), "utf8"));
|
|
6001
6079
|
} catch {
|
|
6002
6080
|
current = null;
|
|
6003
6081
|
}
|
|
@@ -6021,7 +6099,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6021
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}` });
|
|
6022
6100
|
return;
|
|
6023
6101
|
}
|
|
6024
|
-
const target =
|
|
6102
|
+
const target = path21.relative(process.cwd(), path21.join(ctx.root, out)) || out;
|
|
6025
6103
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
6026
6104
|
if (current !== expected) {
|
|
6027
6105
|
ctx.report({
|
|
@@ -6035,7 +6113,7 @@ var GENESIS_DOCS = "https://github.com/marktiderman/genesis/blob/main/docs";
|
|
|
6035
6113
|
var CORE = [
|
|
6036
6114
|
{
|
|
6037
6115
|
need: "anything, before building it",
|
|
6038
|
-
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`',
|
|
6039
6117
|
docs: `${GENESIS_DOCS}/FRAMEWORK.md`,
|
|
6040
6118
|
from: "genesis-cli"
|
|
6041
6119
|
},
|
|
@@ -6184,13 +6262,13 @@ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
|
6184
6262
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
6185
6263
|
const rows = primitivesCatalog(packages);
|
|
6186
6264
|
const changed = [];
|
|
6187
|
-
const agents =
|
|
6265
|
+
const agents = path21.join(root, agentsFile);
|
|
6188
6266
|
const before = read(agents);
|
|
6189
6267
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
6190
|
-
const skill =
|
|
6268
|
+
const skill = path21.join(root, SKILL_PATH);
|
|
6191
6269
|
const skillText = renderSkill(rows);
|
|
6192
6270
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
6193
|
-
mkdirSync(
|
|
6271
|
+
mkdirSync(path21.dirname(skill), { recursive: true });
|
|
6194
6272
|
writeFileSync(skill, skillText);
|
|
6195
6273
|
changed.push(SKILL_PATH);
|
|
6196
6274
|
}
|
|
@@ -6202,8 +6280,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
6202
6280
|
}
|
|
6203
6281
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6204
6282
|
const rows = primitivesCatalog(packages);
|
|
6205
|
-
const skill = read(
|
|
6206
|
-
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)));
|
|
6207
6285
|
return {
|
|
6208
6286
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6209
6287
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -6225,36 +6303,14 @@ function checkAgentGuide(ctx) {
|
|
|
6225
6303
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6226
6304
|
}
|
|
6227
6305
|
}
|
|
6228
|
-
var CLI = "@marktiderman/genesis-cli";
|
|
6229
|
-
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6230
|
-
let parsed;
|
|
6231
|
-
try {
|
|
6232
|
-
parsed = parseSource(source);
|
|
6233
|
-
} catch (err) {
|
|
6234
|
-
return err instanceof Error ? err.message : String(err);
|
|
6235
|
-
}
|
|
6236
|
-
const { package: pkg, path: rel } = parsed;
|
|
6237
|
-
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6238
|
-
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6239
|
-
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6240
|
-
const base = rel.split("/").pop();
|
|
6241
|
-
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6242
|
-
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6243
|
-
}
|
|
6244
|
-
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6245
|
-
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6246
|
-
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6247
|
-
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6248
|
-
return `${key2} doesn't match its source ${source}`;
|
|
6249
|
-
}
|
|
6250
6306
|
|
|
6251
6307
|
// src/blocks/templates.ts
|
|
6252
6308
|
function starterDir() {
|
|
6253
6309
|
const workspace = workspacePackagesDir();
|
|
6254
|
-
const live = workspace &&
|
|
6255
|
-
if (live && existsSync(
|
|
6256
|
-
const packaged =
|
|
6257
|
-
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;
|
|
6258
6314
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
6259
6315
|
}
|
|
6260
6316
|
|
|
@@ -6328,7 +6384,7 @@ function readText(file) {
|
|
|
6328
6384
|
}
|
|
6329
6385
|
function starterBlockMap(root) {
|
|
6330
6386
|
if (root) {
|
|
6331
|
-
const file =
|
|
6387
|
+
const file = path21.join(root, GENESIS_CONFIG);
|
|
6332
6388
|
const text2 = readText(file);
|
|
6333
6389
|
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
6334
6390
|
if (own) return own;
|
|
@@ -6339,7 +6395,7 @@ function starterBlockMap(root) {
|
|
|
6339
6395
|
} catch {
|
|
6340
6396
|
return {};
|
|
6341
6397
|
}
|
|
6342
|
-
const text = readText(
|
|
6398
|
+
const text = readText(path21.join(dir, GENESIS_CONFIG));
|
|
6343
6399
|
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
6344
6400
|
}
|
|
6345
6401
|
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
@@ -6359,10 +6415,10 @@ function blocksSwitchedOff(switches, map, manifests, present) {
|
|
|
6359
6415
|
return off;
|
|
6360
6416
|
}
|
|
6361
6417
|
function appBlocksSwitchedOff(root, manifests, present) {
|
|
6362
|
-
const text = readText(
|
|
6418
|
+
const text = readText(path21.join(root, STARTER_CONFIG));
|
|
6363
6419
|
const switches = text === null ? null : parseStarterFeatures(text);
|
|
6364
6420
|
if (!switches) return /* @__PURE__ */ new Map();
|
|
6365
|
-
return blocksSwitchedOff(switches, starterBlockMap(existsSync(
|
|
6421
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path21.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
6366
6422
|
}
|
|
6367
6423
|
function blockOfSource(source, manifests) {
|
|
6368
6424
|
const at = source.indexOf(":");
|
|
@@ -6375,6 +6431,34 @@ function blockOfSource(source, manifests) {
|
|
|
6375
6431
|
}
|
|
6376
6432
|
return null;
|
|
6377
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
|
+
}
|
|
6378
6462
|
var BUN_LOCK = "bun.lock";
|
|
6379
6463
|
var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
|
|
6380
6464
|
var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
|
|
@@ -6507,21 +6591,9 @@ function staleNestedEntries(text, want = () => null) {
|
|
|
6507
6591
|
return out;
|
|
6508
6592
|
}
|
|
6509
6593
|
function readBunLock(dir) {
|
|
6510
|
-
const file =
|
|
6594
|
+
const file = path21.join(dir, BUN_LOCK);
|
|
6511
6595
|
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6512
6596
|
}
|
|
6513
|
-
function findLockfile(root) {
|
|
6514
|
-
let dir = path20.resolve(root);
|
|
6515
|
-
for (; ; ) {
|
|
6516
|
-
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
6517
|
-
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
6518
|
-
if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
6519
|
-
if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
6520
|
-
const parent = path20.dirname(dir);
|
|
6521
|
-
if (parent === dir) return null;
|
|
6522
|
-
dir = parent;
|
|
6523
|
-
}
|
|
6524
|
-
}
|
|
6525
6597
|
|
|
6526
6598
|
// src/doctor/lock-files.ts
|
|
6527
6599
|
function checkBunLock(ctx) {
|
|
@@ -6529,7 +6601,7 @@ function checkBunLock(ctx) {
|
|
|
6529
6601
|
if (found?.pm !== "bun") return;
|
|
6530
6602
|
const text = readBunLock(found.dir);
|
|
6531
6603
|
if (text === null) return;
|
|
6532
|
-
const file =
|
|
6604
|
+
const file = path21.relative(ctx.root, path21.join(found.dir, BUN_LOCK)).split(path21.sep).join("/");
|
|
6533
6605
|
let stale;
|
|
6534
6606
|
try {
|
|
6535
6607
|
stale = staleNestedEntries(text);
|
|
@@ -6548,7 +6620,7 @@ function checkBunLock(ctx) {
|
|
|
6548
6620
|
}
|
|
6549
6621
|
async function checkLockFiles(ctx) {
|
|
6550
6622
|
checkBunLock(ctx);
|
|
6551
|
-
if (!existsSync(
|
|
6623
|
+
if (!existsSync(path21.join(ctx.root, LOCK_FILE))) return;
|
|
6552
6624
|
let lock;
|
|
6553
6625
|
try {
|
|
6554
6626
|
lock = readLock(ctx.root);
|
|
@@ -6581,6 +6653,11 @@ async function checkLockFiles(ctx) {
|
|
|
6581
6653
|
home = databaseElsewhere(ctx.root);
|
|
6582
6654
|
} catch {
|
|
6583
6655
|
}
|
|
6656
|
+
let appFolder = null;
|
|
6657
|
+
try {
|
|
6658
|
+
appFolder = appFolderOf(ctx.root);
|
|
6659
|
+
} catch {
|
|
6660
|
+
}
|
|
6584
6661
|
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
6585
6662
|
if (home && elsewhere.length) {
|
|
6586
6663
|
ctx.report({
|
|
@@ -6616,6 +6693,7 @@ async function checkLockFiles(ctx) {
|
|
|
6616
6693
|
}
|
|
6617
6694
|
if (text === null) {
|
|
6618
6695
|
if (entry.deleted) continue;
|
|
6696
|
+
if (appFolder && isRepositoryWorkflow(rel)) continue;
|
|
6619
6697
|
ctx.report({
|
|
6620
6698
|
rule: "lock-files",
|
|
6621
6699
|
level: "warn",
|
|
@@ -6650,7 +6728,7 @@ function checkDatabaseHome(ctx) {
|
|
|
6650
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)`
|
|
6651
6729
|
});
|
|
6652
6730
|
}
|
|
6653
|
-
if (existsSync(
|
|
6731
|
+
if (existsSync(path21.join(ctx.root, "supabase"))) {
|
|
6654
6732
|
ctx.report({
|
|
6655
6733
|
rule: "database-elsewhere",
|
|
6656
6734
|
level: "warn",
|
|
@@ -6668,7 +6746,7 @@ function checkEslintConfig(ctx) {
|
|
|
6668
6746
|
if (!file) return;
|
|
6669
6747
|
let text;
|
|
6670
6748
|
try {
|
|
6671
|
-
text = readFileSync(
|
|
6749
|
+
text = readFileSync(path21.join(ctx.root, file), "utf8");
|
|
6672
6750
|
} catch {
|
|
6673
6751
|
return;
|
|
6674
6752
|
}
|
|
@@ -6688,11 +6766,352 @@ function checkEslintConfig(ctx) {
|
|
|
6688
6766
|
subject: TESTING_LIBRARY,
|
|
6689
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`
|
|
6690
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}` });
|
|
6691
7110
|
}
|
|
6692
7111
|
}
|
|
6693
7112
|
var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
|
|
6694
7113
|
async function runDoctor(options = {}) {
|
|
6695
|
-
const root =
|
|
7114
|
+
const root = path21.resolve(options.root ?? process.cwd());
|
|
6696
7115
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
6697
7116
|
const config = loaded.config;
|
|
6698
7117
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -6707,7 +7126,7 @@ async function runDoctor(options = {}) {
|
|
|
6707
7126
|
}
|
|
6708
7127
|
const raw = [];
|
|
6709
7128
|
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
6710
|
-
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]) {
|
|
6711
7130
|
try {
|
|
6712
7131
|
await plugin.check(ctx);
|
|
6713
7132
|
} catch (err) {
|
|
@@ -6746,7 +7165,7 @@ async function runDoctor(options = {}) {
|
|
|
6746
7165
|
}
|
|
6747
7166
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
6748
7167
|
if (options.base && changed) {
|
|
6749
|
-
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)) });
|
|
6750
7169
|
}
|
|
6751
7170
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
6752
7171
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -6795,6 +7214,7 @@ function builtinChecks(config, options = {}) {
|
|
|
6795
7214
|
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
6796
7215
|
{ name: "eslint-config", check: checkEslintConfig },
|
|
6797
7216
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
7217
|
+
...options.figma !== false ? [{ name: "figma-routes", check: checkFigmaRoutesRule }] : [],
|
|
6798
7218
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
6799
7219
|
];
|
|
6800
7220
|
}
|
|
@@ -6847,7 +7267,7 @@ function applyConfig(raw, config, packageIds) {
|
|
|
6847
7267
|
}
|
|
6848
7268
|
return out.sort((x, y) => x.file.localeCompare(y.file) || x.line - y.line || x.rule.localeCompare(y.rule));
|
|
6849
7269
|
}
|
|
6850
|
-
function formatReport(result) {
|
|
7270
|
+
function formatReport(result, options = {}) {
|
|
6851
7271
|
const g = result.genesis;
|
|
6852
7272
|
const lines = [
|
|
6853
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"}`
|
|
@@ -6855,7 +7275,7 @@ function formatReport(result) {
|
|
|
6855
7275
|
for (const f of result.findings) {
|
|
6856
7276
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
6857
7277
|
}
|
|
6858
|
-
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)`);
|
|
6859
7279
|
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
6860
7280
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
6861
7281
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|