@marktiderman/genesis-cli 1.17.3 → 1.19.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 +162 -17
- package/dist/cli.js +2099 -747
- package/dist/cli.js.map +1 -1
- package/dist/{config-1jP8eCZy.d.ts → config-Dj_f9T7J.d.ts} +14 -1
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +944 -361
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +18 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +29 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +944 -361
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +9 -0
- package/dist/starter/__tests__/components/gestures.test.tsx +64 -0
- package/dist/starter/__tests__/components/resolver.js +14 -2
- package/dist/starter/__tests__/components/setup.ts +5 -0
- package/dist/starter/__tests__/starter.test.ts +56 -22
- package/dist/starter/genesis.config.json +10 -0
- package/dist/starter/jest.config.js +3 -0
- package/dist/starter/package.json +2 -0
- package/dist/starter/src/lib/link-hosts.ts +12 -0
- package/dist/starter/src/lib/links.ts +2 -1
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +7 -2
- package/dist/starter/supabase/migrations/20261024000700_genesis_support_findings.sql +339 -0
- package/dist/starter/supabase/tests/database/genesis_notifications.test.sql +5 -3
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +1 -1
- package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +219 -0
- package/dist/templates/ci/genesis-upgrade.yml +1 -0
- package/dist/vite.js +945 -362
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/doctor.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as path20 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 'crypto';
|
|
5
|
+
import { createHash } from 'crypto';
|
|
6
6
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
7
|
-
import { pathToFileURL } from 'url';
|
|
7
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
8
8
|
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
9
|
-
import 'jiti';
|
|
9
|
+
import { createJiti } from 'jiti';
|
|
10
|
+
import 'os';
|
|
10
11
|
|
|
11
12
|
var __defProp = Object.defineProperty;
|
|
12
13
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -454,14 +455,14 @@ function inherit(own, source) {
|
|
|
454
455
|
}
|
|
455
456
|
function resolveViews(relations) {
|
|
456
457
|
const done = /* @__PURE__ */ new Set();
|
|
457
|
-
const
|
|
458
|
+
const resolve16 = (relation, depth) => {
|
|
458
459
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
459
460
|
done.add(relation.oid);
|
|
460
461
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
461
462
|
if (sources.size !== 1) return;
|
|
462
463
|
const source = relations.get([...sources][0]);
|
|
463
464
|
if (!source) return;
|
|
464
|
-
|
|
465
|
+
resolve16(source, depth + 1);
|
|
465
466
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
466
467
|
for (const [attnum, origin] of relation.origins) {
|
|
467
468
|
const own = relation.columns.get(attnum);
|
|
@@ -484,7 +485,7 @@ function resolveViews(relations) {
|
|
|
484
485
|
};
|
|
485
486
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
486
487
|
};
|
|
487
|
-
for (const relation of relations.values())
|
|
488
|
+
for (const relation of relations.values()) resolve16(relation, 0);
|
|
488
489
|
}
|
|
489
490
|
async function introspectPostgres(sql, schemas, options = {}) {
|
|
490
491
|
const relations = /* @__PURE__ */ new Map();
|
|
@@ -720,19 +721,19 @@ var init_introspect = __esm({
|
|
|
720
721
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
721
722
|
function buildCommands(root, config) {
|
|
722
723
|
if (config.build) return config.build;
|
|
723
|
-
const pkgFile =
|
|
724
|
+
const pkgFile = path20.join(root, "package.json");
|
|
724
725
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
725
726
|
const pm = packageManager(root);
|
|
726
727
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
727
728
|
}
|
|
728
729
|
function packageManager(root) {
|
|
729
|
-
let dir =
|
|
730
|
+
let dir = path20.resolve(root);
|
|
730
731
|
for (; ; ) {
|
|
731
|
-
if (existsSync(
|
|
732
|
-
if (existsSync(
|
|
733
|
-
if (existsSync(
|
|
734
|
-
if (existsSync(
|
|
735
|
-
const parent =
|
|
732
|
+
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
733
|
+
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return "bun";
|
|
734
|
+
if (existsSync(path20.join(dir, "yarn.lock"))) return "yarn";
|
|
735
|
+
if (existsSync(path20.join(dir, "package-lock.json"))) return "npm";
|
|
736
|
+
const parent = path20.dirname(dir);
|
|
736
737
|
if (parent === dir) return "npm";
|
|
737
738
|
dir = parent;
|
|
738
739
|
}
|
|
@@ -847,25 +848,25 @@ var PACK_KEYS = {
|
|
|
847
848
|
};
|
|
848
849
|
function appPath(v, where2, fail) {
|
|
849
850
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
850
|
-
if (
|
|
851
|
-
const norm =
|
|
851
|
+
if (path20.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
852
|
+
const norm = path20.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
852
853
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
853
854
|
return norm;
|
|
854
855
|
}
|
|
855
856
|
function loadConfig(root, configPath) {
|
|
856
857
|
if (configPath) {
|
|
857
|
-
const file =
|
|
858
|
+
const file = path20.resolve(root, configPath);
|
|
858
859
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
859
860
|
const json = readJson(file);
|
|
860
|
-
const block =
|
|
861
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
861
|
+
const block = path20.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
862
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path20.dirname(file) };
|
|
862
863
|
}
|
|
863
|
-
const own =
|
|
864
|
+
const own = path20.join(root, "genesis.config.json");
|
|
864
865
|
if (existsSync(own)) {
|
|
865
866
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
866
867
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
867
868
|
}
|
|
868
|
-
const pkg =
|
|
869
|
+
const pkg = path20.join(root, "package.json");
|
|
869
870
|
if (existsSync(pkg)) {
|
|
870
871
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
871
872
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -874,7 +875,7 @@ function loadConfig(root, configPath) {
|
|
|
874
875
|
}
|
|
875
876
|
function doctorBlock(json, file, explicit) {
|
|
876
877
|
const j = json;
|
|
877
|
-
if (
|
|
878
|
+
if (path20.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
878
879
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
879
880
|
}
|
|
880
881
|
function isPackageDeclaration(block) {
|
|
@@ -891,15 +892,33 @@ function readJson(file) {
|
|
|
891
892
|
}
|
|
892
893
|
}
|
|
893
894
|
function readGenesisConfig(root) {
|
|
894
|
-
const file =
|
|
895
|
+
const file = path20.join(root, "genesis.config.json");
|
|
895
896
|
if (!existsSync(file)) return null;
|
|
896
897
|
const raw = readJson(file);
|
|
897
898
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
898
899
|
const out = { raw };
|
|
899
900
|
if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
|
|
900
901
|
if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
|
|
902
|
+
if (raw.supabase !== void 0) {
|
|
903
|
+
const supabase = validateSupabase(raw.supabase, file);
|
|
904
|
+
if (supabase !== true) out.supabase = supabase;
|
|
905
|
+
}
|
|
901
906
|
return out;
|
|
902
907
|
}
|
|
908
|
+
function validateSupabase(raw, source = "config") {
|
|
909
|
+
const fail = (msg) => {
|
|
910
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
911
|
+
};
|
|
912
|
+
if (typeof raw === "boolean") return raw ? true : false;
|
|
913
|
+
if (!isObject(raw)) return fail(`"supabase" must be false or { "app": "<the folder of the app that holds supabase/>" }`);
|
|
914
|
+
for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
|
|
915
|
+
const app = raw.app;
|
|
916
|
+
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 (path20.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
|
|
918
|
+
const norm = path20.posix.normalize(app).replace(/\/+$/, "");
|
|
919
|
+
if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
|
|
920
|
+
return { app: norm };
|
|
921
|
+
}
|
|
903
922
|
var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
|
|
904
923
|
var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
|
|
905
924
|
function validatePrivacy(raw, source = "config") {
|
|
@@ -1056,7 +1075,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1056
1075
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1057
1076
|
if (contracts.out !== void 0) {
|
|
1058
1077
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1059
|
-
if (
|
|
1078
|
+
if (path20.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1060
1079
|
}
|
|
1061
1080
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1062
1081
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1124,7 +1143,7 @@ function globToRegExp(glob) {
|
|
|
1124
1143
|
}
|
|
1125
1144
|
function globMatcher(globs) {
|
|
1126
1145
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1127
|
-
return (
|
|
1146
|
+
return (path39) => res.some((re) => re.test(path39));
|
|
1128
1147
|
}
|
|
1129
1148
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1130
1149
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
@@ -1164,11 +1183,11 @@ var TAILWIND_PALETTE = [
|
|
|
1164
1183
|
"olive"
|
|
1165
1184
|
];
|
|
1166
1185
|
function findPackageDir(from, name) {
|
|
1167
|
-
let dir =
|
|
1186
|
+
let dir = path20.resolve(from);
|
|
1168
1187
|
for (; ; ) {
|
|
1169
|
-
const candidate =
|
|
1170
|
-
if (existsSync(
|
|
1171
|
-
const parent =
|
|
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);
|
|
1172
1191
|
if (parent === dir) return null;
|
|
1173
1192
|
dir = parent;
|
|
1174
1193
|
}
|
|
@@ -1220,7 +1239,7 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1220
1239
|
function readPackageExports(root, uiPackage) {
|
|
1221
1240
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1222
1241
|
if (!uiDir) return null;
|
|
1223
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1242
|
+
const uiPkg = JSON.parse(readFileSync(path20.join(uiDir, "package.json"), "utf8"));
|
|
1224
1243
|
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
1225
1244
|
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1226
1245
|
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
@@ -1247,23 +1266,23 @@ function readPackageExports(root, uiPackage) {
|
|
|
1247
1266
|
}
|
|
1248
1267
|
if (fromSource) {
|
|
1249
1268
|
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
1250
|
-
const next = resolveSource(
|
|
1269
|
+
const next = resolveSource(path20.dirname(file), m[1]);
|
|
1251
1270
|
if (next) readEntry(next);
|
|
1252
1271
|
}
|
|
1253
1272
|
}
|
|
1254
1273
|
};
|
|
1255
|
-
for (const entry of typeEntries) readEntry(
|
|
1274
|
+
for (const entry of typeEntries) readEntry(path20.join(uiDir, entry));
|
|
1256
1275
|
if (!readAny) {
|
|
1257
1276
|
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
1258
1277
|
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1259
1278
|
}
|
|
1260
1279
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1261
1280
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1262
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1281
|
+
const declRoot = typeof mainTypes === "string" ? path20.dirname(path20.join(uiDir, mainTypes)) : uiDir;
|
|
1263
1282
|
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
1264
1283
|
for (const pkg of reexportedPackages) {
|
|
1265
1284
|
const dir = findPackageDir(uiDir, pkg);
|
|
1266
|
-
if (dir) walkDts(
|
|
1285
|
+
if (dir) walkDts(path20.join(dir, "dist"), declFiles);
|
|
1267
1286
|
}
|
|
1268
1287
|
for (const file of declFiles) {
|
|
1269
1288
|
const text = readFileSync(file, "utf8");
|
|
@@ -1313,13 +1332,13 @@ function exportSource(target) {
|
|
|
1313
1332
|
return void 0;
|
|
1314
1333
|
}
|
|
1315
1334
|
function resolveSource(dir, spec) {
|
|
1316
|
-
const base =
|
|
1317
|
-
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) =>
|
|
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))];
|
|
1318
1337
|
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
1319
1338
|
}
|
|
1320
1339
|
function insidePackage(dir, file) {
|
|
1321
|
-
const rel =
|
|
1322
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1340
|
+
const rel = path20.relative(path20.resolve(dir), path20.resolve(file));
|
|
1341
|
+
return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
1323
1342
|
}
|
|
1324
1343
|
function stripComments(code) {
|
|
1325
1344
|
let out = "";
|
|
@@ -1355,7 +1374,7 @@ function walkSource(dir, out = []) {
|
|
|
1355
1374
|
if (!existsSync(dir)) return out;
|
|
1356
1375
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1357
1376
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
1358
|
-
const p =
|
|
1377
|
+
const p = path20.join(dir, entry.name);
|
|
1359
1378
|
if (entry.isDirectory()) walkSource(p, out);
|
|
1360
1379
|
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1361
1380
|
}
|
|
@@ -1375,7 +1394,7 @@ function walkDts(dir, out = []) {
|
|
|
1375
1394
|
if (!existsSync(dir)) return out;
|
|
1376
1395
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1377
1396
|
if (entry.name === "node_modules") continue;
|
|
1378
|
-
const p =
|
|
1397
|
+
const p = path20.join(dir, entry.name);
|
|
1379
1398
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1380
1399
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1381
1400
|
}
|
|
@@ -1392,27 +1411,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1392
1411
|
}
|
|
1393
1412
|
const files = [];
|
|
1394
1413
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1395
|
-
const themes = ds &&
|
|
1414
|
+
const themes = ds && path20.join(ds, "dist", "themes");
|
|
1396
1415
|
if (themes && existsSync(themes)) {
|
|
1397
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1416
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path20.join(themes, name));
|
|
1398
1417
|
}
|
|
1399
1418
|
if (files.length === 0) {
|
|
1400
1419
|
throw new DoctorConfigError(
|
|
1401
1420
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1402
1421
|
);
|
|
1403
1422
|
}
|
|
1404
|
-
const uiStyles =
|
|
1423
|
+
const uiStyles = path20.join(uiDir, "dist", "styles.css");
|
|
1405
1424
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1406
1425
|
return files;
|
|
1407
1426
|
}
|
|
1408
1427
|
function resolveSpec(root, spec) {
|
|
1409
|
-
const local =
|
|
1410
|
-
if (spec.startsWith(".") ||
|
|
1428
|
+
const local = path20.resolve(root, spec);
|
|
1429
|
+
if (spec.startsWith(".") || path20.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1411
1430
|
const parts = spec.split("/");
|
|
1412
1431
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1413
1432
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1414
1433
|
if (dir) {
|
|
1415
|
-
const file =
|
|
1434
|
+
const file = path20.join(dir, ...parts.slice(nameLength));
|
|
1416
1435
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1417
1436
|
}
|
|
1418
1437
|
return existsSync(local) ? local : null;
|
|
@@ -1420,7 +1439,7 @@ function resolveSpec(root, spec) {
|
|
|
1420
1439
|
function loadPalette(root) {
|
|
1421
1440
|
const names = new Set(TAILWIND_PALETTE);
|
|
1422
1441
|
try {
|
|
1423
|
-
const req = createRequire(
|
|
1442
|
+
const req = createRequire(path20.join(root, "package.json"));
|
|
1424
1443
|
const colors = req("tailwindcss/colors");
|
|
1425
1444
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1426
1445
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -1510,6 +1529,26 @@ function parseManifest(home, id, raw, version, options = {}) {
|
|
|
1510
1529
|
const file = pathOf(m["file"], `${where2}.file`);
|
|
1511
1530
|
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
1512
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 }`);
|
|
1534
|
+
else {
|
|
1535
|
+
out.provides = m["provides"].map((p, j) => {
|
|
1536
|
+
const at2 = `${where2}.provides[${j}]`;
|
|
1537
|
+
if (!isObject2(p)) {
|
|
1538
|
+
problems.push(`${at2}: must be an object`);
|
|
1539
|
+
return { package: home, file: "" };
|
|
1540
|
+
}
|
|
1541
|
+
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
1542
|
+
if (p["functions"] !== void 0) {
|
|
1543
|
+
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
1544
|
+
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
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;
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1513
1552
|
if (m["test"] !== void 0) {
|
|
1514
1553
|
out.test = pathOf(m["test"], `${where2}.test`);
|
|
1515
1554
|
if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where2}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
|
|
@@ -1606,11 +1645,52 @@ function rawBlocksOf(packageJson) {
|
|
|
1606
1645
|
const blocks = packageJson["genesis"]["blocks"];
|
|
1607
1646
|
return isObject2(blocks) ? blocks : {};
|
|
1608
1647
|
}
|
|
1648
|
+
function declarationFields(block) {
|
|
1649
|
+
const c = block.contributes ?? {};
|
|
1650
|
+
return {
|
|
1651
|
+
...block.requires ? { requires: [...block.requires] } : {},
|
|
1652
|
+
...block.platforms ? { platforms: [...block.platforms] } : {},
|
|
1653
|
+
...c.migrations ? { migrations: c.migrations.map((m) => ({ ...m })) } : {},
|
|
1654
|
+
...c.routes ? { routes: c.routes.map((r) => ({ ...r })) } : {},
|
|
1655
|
+
...c.skills ? { skills: [...c.skills] } : {},
|
|
1656
|
+
...c.privacy ? { privacy: c.privacy } : {}
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
function isBlockDef(value) {
|
|
1660
|
+
return isObject2(value) && typeof value["id"] === "string" && BLOCK_ID.test(value["id"]) && (value["contributes"] === void 0 || isObject2(value["contributes"])) && (isObject2(value["contributes"]) || Array.isArray(value["requires"]));
|
|
1661
|
+
}
|
|
1609
1662
|
|
|
1610
1663
|
// src/blocks/files.ts
|
|
1664
|
+
var sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
1611
1665
|
function inside(parent, child) {
|
|
1612
|
-
const rel =
|
|
1613
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1666
|
+
const rel = path20.relative(parent, child);
|
|
1667
|
+
return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
1668
|
+
}
|
|
1669
|
+
function appPath2(root, rel) {
|
|
1670
|
+
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
1671
|
+
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
1672
|
+
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
1673
|
+
const realRoot = realpathSync(root);
|
|
1674
|
+
const target = path20.join(realRoot, ...safe.split("/"));
|
|
1675
|
+
const there = (p) => {
|
|
1676
|
+
try {
|
|
1677
|
+
lstatSync(p);
|
|
1678
|
+
return true;
|
|
1679
|
+
} catch {
|
|
1680
|
+
return false;
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
let probe = path20.dirname(target);
|
|
1684
|
+
while (!there(probe)) probe = path20.dirname(probe);
|
|
1685
|
+
let real2;
|
|
1686
|
+
try {
|
|
1687
|
+
real2 = realpathSync(probe);
|
|
1688
|
+
} catch {
|
|
1689
|
+
throw new Error(`${rel} goes through a broken symlink (${path20.relative(realRoot, probe)}); refused`);
|
|
1690
|
+
}
|
|
1691
|
+
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
1692
|
+
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
1693
|
+
return target;
|
|
1614
1694
|
}
|
|
1615
1695
|
|
|
1616
1696
|
// src/blocks/local.ts
|
|
@@ -1623,8 +1703,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1623
1703
|
return raw.map((entry, i) => {
|
|
1624
1704
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
1625
1705
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
1626
|
-
if (
|
|
1627
|
-
const norm =
|
|
1706
|
+
if (path20.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
1707
|
+
const norm = path20.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1628
1708
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
1629
1709
|
const parts = norm.split("/");
|
|
1630
1710
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -1635,7 +1715,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1635
1715
|
});
|
|
1636
1716
|
}
|
|
1637
1717
|
function localPackageGlobs(root) {
|
|
1638
|
-
const file =
|
|
1718
|
+
const file = path20.join(root, "genesis.config.json");
|
|
1639
1719
|
if (!existsSync(file)) return [];
|
|
1640
1720
|
let raw;
|
|
1641
1721
|
try {
|
|
@@ -1649,14 +1729,14 @@ function localPackageGlobs(root) {
|
|
|
1649
1729
|
var cache = /* @__PURE__ */ new Map();
|
|
1650
1730
|
function repositoryRoot(appRoot) {
|
|
1651
1731
|
for (let dir = appRoot; ; ) {
|
|
1652
|
-
if (existsSync(
|
|
1653
|
-
const parent =
|
|
1732
|
+
if (existsSync(path20.join(dir, ".git"))) return dir;
|
|
1733
|
+
const parent = path20.dirname(dir);
|
|
1654
1734
|
if (parent === dir) return appRoot;
|
|
1655
1735
|
dir = parent;
|
|
1656
1736
|
}
|
|
1657
1737
|
}
|
|
1658
1738
|
function localPackages(root) {
|
|
1659
|
-
const appRoot =
|
|
1739
|
+
const appRoot = path20.resolve(root);
|
|
1660
1740
|
const globs = localPackageGlobs(appRoot);
|
|
1661
1741
|
const key2 = `${appRoot}
|
|
1662
1742
|
${globs.join("\n")}`;
|
|
@@ -1665,24 +1745,24 @@ ${globs.join("\n")}`;
|
|
|
1665
1745
|
const dirs = /* @__PURE__ */ new Set();
|
|
1666
1746
|
for (const glob of globs) {
|
|
1667
1747
|
if (glob.endsWith("/*") || glob === "*") {
|
|
1668
|
-
const parent =
|
|
1748
|
+
const parent = path20.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
1669
1749
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
1670
1750
|
for (const entry of readdirSync(parent).sort()) {
|
|
1671
1751
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
1672
|
-
dirs.add(
|
|
1752
|
+
dirs.add(path20.join(parent, entry));
|
|
1673
1753
|
}
|
|
1674
1754
|
} else {
|
|
1675
|
-
dirs.add(
|
|
1755
|
+
dirs.add(path20.join(appRoot, glob));
|
|
1676
1756
|
}
|
|
1677
1757
|
}
|
|
1678
1758
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
1679
1759
|
const out = [];
|
|
1680
1760
|
const byName = /* @__PURE__ */ new Map();
|
|
1681
1761
|
for (const dir of [...dirs].sort()) {
|
|
1682
|
-
const manifest =
|
|
1762
|
+
const manifest = path20.join(dir, "package.json");
|
|
1683
1763
|
if (!existsSync(manifest)) continue;
|
|
1684
1764
|
if (!inside(real2, realpathSync(dir))) {
|
|
1685
|
-
throw new LocalPackagesError(`${
|
|
1765
|
+
throw new LocalPackagesError(`${path20.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
1686
1766
|
}
|
|
1687
1767
|
let pkg;
|
|
1688
1768
|
try {
|
|
@@ -1691,7 +1771,7 @@ ${globs.join("\n")}`;
|
|
|
1691
1771
|
continue;
|
|
1692
1772
|
}
|
|
1693
1773
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
1694
|
-
const rel =
|
|
1774
|
+
const rel = path20.relative(appRoot, dir).split(path20.sep).join("/");
|
|
1695
1775
|
const other = byName.get(pkg.name);
|
|
1696
1776
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
1697
1777
|
byName.set(pkg.name, rel);
|
|
@@ -1700,6 +1780,9 @@ ${globs.join("\n")}`;
|
|
|
1700
1780
|
cache.set(key2, out);
|
|
1701
1781
|
return out;
|
|
1702
1782
|
}
|
|
1783
|
+
function localPackageNames(root) {
|
|
1784
|
+
return new Set(localPackages(root).map((p) => p.name));
|
|
1785
|
+
}
|
|
1703
1786
|
|
|
1704
1787
|
// ../../scripts/lib/color-literals.mjs
|
|
1705
1788
|
var LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
|
|
@@ -1876,35 +1959,35 @@ var DEFAULT_IGNORE = [
|
|
|
1876
1959
|
];
|
|
1877
1960
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1878
1961
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1879
|
-
var toPosix = (p) => p.split(
|
|
1962
|
+
var toPosix = (p) => p.split(path20.sep).join("/");
|
|
1880
1963
|
function scanFiles(root, config) {
|
|
1881
1964
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
1882
1965
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
1883
1966
|
const files = [];
|
|
1884
1967
|
const seen = /* @__PURE__ */ new Set();
|
|
1885
1968
|
const visit = (abs) => {
|
|
1886
|
-
const rel = toPosix(
|
|
1969
|
+
const rel = toPosix(path20.relative(root, abs));
|
|
1887
1970
|
if (seen.has(rel) || ignored(rel)) return;
|
|
1888
|
-
const ext =
|
|
1971
|
+
const ext = path20.extname(abs);
|
|
1889
1972
|
if (!extensions.has(ext)) return;
|
|
1890
1973
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1891
1974
|
seen.add(rel);
|
|
1892
1975
|
const text = readFileSync(abs, "utf8");
|
|
1893
1976
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
1894
1977
|
};
|
|
1895
|
-
const
|
|
1978
|
+
const walk2 = (dir) => {
|
|
1896
1979
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1897
1980
|
if (entry.isDirectory()) {
|
|
1898
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
1981
|
+
if (!SKIP_DIRS.has(entry.name)) walk2(path20.join(dir, entry.name));
|
|
1899
1982
|
} else if (entry.isFile()) {
|
|
1900
|
-
visit(
|
|
1983
|
+
visit(path20.join(dir, entry.name));
|
|
1901
1984
|
}
|
|
1902
1985
|
}
|
|
1903
1986
|
};
|
|
1904
1987
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1905
|
-
const abs =
|
|
1988
|
+
const abs = path20.resolve(root, src);
|
|
1906
1989
|
if (!existsSync(abs)) continue;
|
|
1907
|
-
if (statSync(abs).isDirectory())
|
|
1990
|
+
if (statSync(abs).isDirectory()) walk2(abs);
|
|
1908
1991
|
else visit(abs);
|
|
1909
1992
|
}
|
|
1910
1993
|
let local = [];
|
|
@@ -1913,7 +1996,7 @@ function scanFiles(root, config) {
|
|
|
1913
1996
|
} catch {
|
|
1914
1997
|
local = [];
|
|
1915
1998
|
}
|
|
1916
|
-
for (const pkg of local)
|
|
1999
|
+
for (const pkg of local) walk2(pkg.dir);
|
|
1917
2000
|
return files;
|
|
1918
2001
|
}
|
|
1919
2002
|
function lineAt(text, index) {
|
|
@@ -1990,7 +2073,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
1990
2073
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
1991
2074
|
let all = compiled;
|
|
1992
2075
|
if (rulesDoc) {
|
|
1993
|
-
const file =
|
|
2076
|
+
const file = path20.resolve(root, rulesDoc);
|
|
1994
2077
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
1995
2078
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
1996
2079
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -2051,15 +2134,177 @@ async function loadPlugins(specs, configDir) {
|
|
|
2051
2134
|
}
|
|
2052
2135
|
function resolvePlugin(id, configDir) {
|
|
2053
2136
|
try {
|
|
2054
|
-
if (id.startsWith(".") ||
|
|
2137
|
+
if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
|
|
2055
2138
|
return resolveFrom(id, configDir);
|
|
2056
2139
|
} catch {
|
|
2057
2140
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2058
2141
|
}
|
|
2059
2142
|
}
|
|
2060
2143
|
function resolveFrom(id, from) {
|
|
2061
|
-
return createRequire(
|
|
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;
|
|
2152
|
+
}
|
|
2153
|
+
function compareVersions(a, b) {
|
|
2154
|
+
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
2155
|
+
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
2156
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
2157
|
+
const x = a.pre[i];
|
|
2158
|
+
const y = b.pre[i];
|
|
2159
|
+
if (x === void 0) return -1;
|
|
2160
|
+
if (y === void 0) return 1;
|
|
2161
|
+
if (x === y) continue;
|
|
2162
|
+
const nx = /^\d+$/.test(x);
|
|
2163
|
+
const ny = /^\d+$/.test(y);
|
|
2164
|
+
if (nx && ny) return +x < +y ? -1 : 1;
|
|
2165
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
2166
|
+
return x < y ? -1 : 1;
|
|
2167
|
+
}
|
|
2168
|
+
return 0;
|
|
2062
2169
|
}
|
|
2170
|
+
function partial(s) {
|
|
2171
|
+
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
2172
|
+
if (!m) return null;
|
|
2173
|
+
const nums = [];
|
|
2174
|
+
let wild = false;
|
|
2175
|
+
for (const part of [m[1], m[2], m[3]]) {
|
|
2176
|
+
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
2177
|
+
wild = true;
|
|
2178
|
+
nums.push(null);
|
|
2179
|
+
} else nums.push(+part);
|
|
2180
|
+
}
|
|
2181
|
+
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
2182
|
+
}
|
|
2183
|
+
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
2184
|
+
function comparators(token) {
|
|
2185
|
+
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
2186
|
+
if (!m) return null;
|
|
2187
|
+
const op = m[1] ?? "";
|
|
2188
|
+
const p = partial(m[2]);
|
|
2189
|
+
if (!p) return null;
|
|
2190
|
+
const [major, mi, pa] = p.nums;
|
|
2191
|
+
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
2192
|
+
const M = major;
|
|
2193
|
+
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
2194
|
+
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
2195
|
+
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
2196
|
+
const out = switchOp();
|
|
2197
|
+
if (p.pre.length) {
|
|
2198
|
+
for (const c of out) if (c.v === lo) c.pre = true;
|
|
2199
|
+
}
|
|
2200
|
+
return out;
|
|
2201
|
+
function switchOp() {
|
|
2202
|
+
switch (op) {
|
|
2203
|
+
case "^": {
|
|
2204
|
+
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
2205
|
+
return [
|
|
2206
|
+
{ op: ">=", v: lo },
|
|
2207
|
+
{ op: "<", v: bound }
|
|
2208
|
+
];
|
|
2209
|
+
}
|
|
2210
|
+
case "~":
|
|
2211
|
+
case "~>":
|
|
2212
|
+
return [
|
|
2213
|
+
{ op: ">=", v: lo },
|
|
2214
|
+
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
2215
|
+
];
|
|
2216
|
+
case ">":
|
|
2217
|
+
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
2218
|
+
case ">=":
|
|
2219
|
+
return [{ op: ">=", v: lo }];
|
|
2220
|
+
case "<":
|
|
2221
|
+
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
2222
|
+
case "<=":
|
|
2223
|
+
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
2224
|
+
default:
|
|
2225
|
+
return upper ? [
|
|
2226
|
+
{ op: ">=", v: lo },
|
|
2227
|
+
{ op: "<", v: upper }
|
|
2228
|
+
] : [{ op: "=", v: lo }];
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
function test(c, v) {
|
|
2233
|
+
const d = compareVersions(v, c.v);
|
|
2234
|
+
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
2235
|
+
}
|
|
2236
|
+
function parseRange(range) {
|
|
2237
|
+
const alts = [];
|
|
2238
|
+
for (const raw of range.trim().split("||")) {
|
|
2239
|
+
const alt = raw.trim();
|
|
2240
|
+
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
2241
|
+
if (hyphen) {
|
|
2242
|
+
const from = comparators(`>=${hyphen[1]}`);
|
|
2243
|
+
const to = comparators(`<=${hyphen[2]}`);
|
|
2244
|
+
if (!from || !to) return null;
|
|
2245
|
+
alts.push([...from, ...to]);
|
|
2246
|
+
continue;
|
|
2247
|
+
}
|
|
2248
|
+
const set = [];
|
|
2249
|
+
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
2250
|
+
const cs = comparators(token);
|
|
2251
|
+
if (!cs) return null;
|
|
2252
|
+
set.push(...cs);
|
|
2253
|
+
}
|
|
2254
|
+
alts.push(set);
|
|
2255
|
+
}
|
|
2256
|
+
return alts;
|
|
2257
|
+
}
|
|
2258
|
+
function satisfies(version, range) {
|
|
2259
|
+
const v = parseVersion(version);
|
|
2260
|
+
const alts = parseRange(range);
|
|
2261
|
+
if (!v || !alts) return null;
|
|
2262
|
+
return alts.some(
|
|
2263
|
+
(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
|
+
);
|
|
2265
|
+
}
|
|
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
|
+
|
|
2307
|
+
// src/doctor/overlays.ts
|
|
2063
2308
|
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
2064
2309
|
var OVERLAY_NOTICE_DAYS = 14;
|
|
2065
2310
|
var OVERLAY_WARN_DAYS = 30;
|
|
@@ -2073,7 +2318,7 @@ function overlayState(name, json) {
|
|
|
2073
2318
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2074
2319
|
const problems = [];
|
|
2075
2320
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2076
|
-
const rel =
|
|
2321
|
+
const rel = path20.relative(path20.resolve(root), path20.resolve(dir)).split(path20.sep).join("/");
|
|
2077
2322
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2078
2323
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2079
2324
|
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})`);
|
|
@@ -2098,6 +2343,31 @@ function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
|
|
|
2098
2343
|
return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
|
|
2099
2344
|
}
|
|
2100
2345
|
var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
|
|
2346
|
+
function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
2347
|
+
let manifest = null;
|
|
2348
|
+
try {
|
|
2349
|
+
manifest = readReleaseManifest(root);
|
|
2350
|
+
} catch {
|
|
2351
|
+
}
|
|
2352
|
+
const released = manifest?.packages[name];
|
|
2353
|
+
if (released && parseVersion(released)) return released;
|
|
2354
|
+
let best = null;
|
|
2355
|
+
for (const file of manifests) {
|
|
2356
|
+
let json;
|
|
2357
|
+
try {
|
|
2358
|
+
json = JSON.parse(readFileSync(path20.join(root, file), "utf8"));
|
|
2359
|
+
} catch {
|
|
2360
|
+
continue;
|
|
2361
|
+
}
|
|
2362
|
+
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
2363
|
+
const spec = json[section]?.[name];
|
|
2364
|
+
const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
|
|
2365
|
+
const parsed = v && parseVersion(v);
|
|
2366
|
+
if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
return best;
|
|
2370
|
+
}
|
|
2101
2371
|
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
2102
2372
|
let packages;
|
|
2103
2373
|
try {
|
|
@@ -2110,7 +2380,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
|
2110
2380
|
const file = `${pkg.rel}/package.json`;
|
|
2111
2381
|
let json;
|
|
2112
2382
|
try {
|
|
2113
|
-
json = JSON.parse(readFileSync(
|
|
2383
|
+
json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
2114
2384
|
} catch {
|
|
2115
2385
|
continue;
|
|
2116
2386
|
}
|
|
@@ -2153,6 +2423,18 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
|
2153
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`
|
|
2154
2424
|
});
|
|
2155
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
|
+
}
|
|
2156
2438
|
}
|
|
2157
2439
|
}
|
|
2158
2440
|
|
|
@@ -2216,6 +2498,7 @@ var BUILTIN_RULES = [
|
|
|
2216
2498
|
"overlay-invalid",
|
|
2217
2499
|
"overlay-age",
|
|
2218
2500
|
"overlay-version",
|
|
2501
|
+
"overlay-behind",
|
|
2219
2502
|
// package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
|
|
2220
2503
|
"package-rules-invalid",
|
|
2221
2504
|
"package-rule-override",
|
|
@@ -2226,7 +2509,11 @@ var BUILTIN_RULES = [
|
|
|
2226
2509
|
// agent guide (primitives.ts)
|
|
2227
2510
|
"agent-guide-stale",
|
|
2228
2511
|
// supabase pack: contracts (contracts.ts)
|
|
2229
|
-
"contracts-stale"
|
|
2512
|
+
"contracts-stale",
|
|
2513
|
+
// genesis.lock.json against the files (lock-files.ts)
|
|
2514
|
+
"lock-files",
|
|
2515
|
+
// an app whose database files live in another app (database.ts)
|
|
2516
|
+
"database-elsewhere"
|
|
2230
2517
|
];
|
|
2231
2518
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
2232
2519
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -2244,7 +2531,7 @@ function importSpecifiers(file) {
|
|
|
2244
2531
|
}
|
|
2245
2532
|
function checkProjectLayout(ctx) {
|
|
2246
2533
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2247
|
-
if (existsSync(
|
|
2534
|
+
if (existsSync(path20.join(ctx.root, dir))) {
|
|
2248
2535
|
ctx.report({
|
|
2249
2536
|
rule: "local-primitives",
|
|
2250
2537
|
file: dir,
|
|
@@ -2254,7 +2541,7 @@ function checkProjectLayout(ctx) {
|
|
|
2254
2541
|
}
|
|
2255
2542
|
}
|
|
2256
2543
|
for (const file of STARTER_LEFTOVERS) {
|
|
2257
|
-
if (existsSync(
|
|
2544
|
+
if (existsSync(path20.join(ctx.root, file))) {
|
|
2258
2545
|
ctx.report({
|
|
2259
2546
|
rule: "starter-leftover",
|
|
2260
2547
|
level: "warn",
|
|
@@ -2344,7 +2631,7 @@ function checkTokens(ctx) {
|
|
|
2344
2631
|
}
|
|
2345
2632
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2346
2633
|
if (/[*?]/.test(pattern)) continue;
|
|
2347
|
-
const abs =
|
|
2634
|
+
const abs = path20.join(ctx.root, pattern);
|
|
2348
2635
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2349
2636
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2350
2637
|
}
|
|
@@ -2444,14 +2731,33 @@ var appFunctionality = (type, ...more) => ({
|
|
|
2444
2731
|
function privacyApisFor(dependencies2) {
|
|
2445
2732
|
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
2446
2733
|
}
|
|
2734
|
+
|
|
2735
|
+
// src/eas-placeholders.ts
|
|
2736
|
+
var EAS_PLACEHOLDERS = {
|
|
2737
|
+
REPLACE_WITH_APP_STORE_CONNECT_APP_ID: "the app's Apple ID from App Store Connect (create the app there, then App Information \u2192 General Information \u2192 Apple ID, a number)",
|
|
2738
|
+
REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
|
|
2739
|
+
REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the Google Play service account key uploaded to EAS, not a local path (deploy-production.yml submits on EAS, where a local file isn't there): create a Google Cloud service account and its JSON key, invite it in Play Console \u2192 Users and permissions, upload the key with `eas credentials` (Android \u2192 Google Service Account), then remove only this serviceAccountKeyPath line (https://docs.expo.dev/submit/android/). Until you ship to Google Play, remove the submit_android job from deploy-production.yml instead, and keep submit.production.android as it is (the internal track, as a draft)",
|
|
2740
|
+
REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
|
|
2741
|
+
};
|
|
2742
|
+
function placeholderKey(line, placeholder) {
|
|
2743
|
+
return new RegExp(`"([A-Za-z0-9_]+)"\\s*:\\s*"${placeholder}"`).exec(line)?.[1] ?? null;
|
|
2744
|
+
}
|
|
2745
|
+
function findPlaceholders(file, text) {
|
|
2746
|
+
const out = [];
|
|
2747
|
+
text.split("\n").forEach((line, i) => {
|
|
2748
|
+
if (!file.endsWith(".json") && /^\s*#/.test(line)) return;
|
|
2749
|
+
for (const m of line.matchAll(/\bREPLACE_WITH_[A-Z0-9_]+/g)) out.push({ line: i + 1, text: line, placeholder: m[0] });
|
|
2750
|
+
});
|
|
2751
|
+
return out;
|
|
2752
|
+
}
|
|
2447
2753
|
var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
2448
2754
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2449
2755
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2450
2756
|
function resolveLocal(root, fromFile, spec) {
|
|
2451
|
-
const bases = spec.startsWith(".") ? [
|
|
2757
|
+
const bases = spec.startsWith(".") ? [path20.resolve(path20.dirname(fromFile), spec)] : [path20.join(root, spec.slice(2)), path20.join(root, "src", spec.slice(2))];
|
|
2452
2758
|
for (const base of bases) {
|
|
2453
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2454
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2759
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path20.join(base, `index${e}`))].find(
|
|
2760
|
+
(p) => SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p)
|
|
2455
2761
|
);
|
|
2456
2762
|
if (hit) return hit;
|
|
2457
2763
|
}
|
|
@@ -2570,29 +2876,26 @@ function checkNativePack(ctx) {
|
|
|
2570
2876
|
checkStoreReadiness(ctx);
|
|
2571
2877
|
checkEasPlaceholders(ctx);
|
|
2572
2878
|
}
|
|
2573
|
-
var EAS_PLACEHOLDER = /\bREPLACE_WITH_[A-Z0-9_]+/g;
|
|
2574
2879
|
function checkEasPlaceholders(ctx) {
|
|
2575
2880
|
const files = [];
|
|
2576
|
-
if (existsSync(
|
|
2577
|
-
const workflows =
|
|
2881
|
+
if (existsSync(path20.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
2882
|
+
const workflows = path20.join(ctx.root, ".eas", "workflows");
|
|
2578
2883
|
if (existsSync(workflows)) {
|
|
2579
2884
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
2580
2885
|
}
|
|
2581
2886
|
for (const file of files) {
|
|
2582
|
-
const
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
}
|
|
2595
|
-
});
|
|
2887
|
+
for (const hit of findPlaceholders(file, readFileSync(path20.join(ctx.root, file), "utf8"))) {
|
|
2888
|
+
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
2889
|
+
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
2890
|
+
ctx.report({
|
|
2891
|
+
rule: "eas-placeholder",
|
|
2892
|
+
level: "warn",
|
|
2893
|
+
file,
|
|
2894
|
+
line: hit.line,
|
|
2895
|
+
subject: hit.placeholder,
|
|
2896
|
+
message: hit.placeholder === "REPLACE_WITH_APP_FOLDER" ? `still names REPLACE_WITH_APP_FOLDER, so only config changes start a preview; replace it with ${what}` : `${key2 ? `${key2} is` : "still has"} the template placeholder ${hit.placeholder}; replace it with ${what ?? "its value (see docs/NATIVE-RELEASE.md in the Genesis repository)"} before the job that reads it runs`
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2596
2899
|
}
|
|
2597
2900
|
}
|
|
2598
2901
|
var RN = String.raw`["']react-native["']`;
|
|
@@ -2660,7 +2963,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2660
2963
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2661
2964
|
const code = file.code;
|
|
2662
2965
|
const hidden = HIDES_HEADER.exec(code);
|
|
2663
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2966
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path20.posix.dirname(file.path), file.path);
|
|
2664
2967
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2665
2968
|
if (hidden && own) {
|
|
2666
2969
|
reported.add(file.path);
|
|
@@ -2688,7 +2991,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2688
2991
|
}
|
|
2689
2992
|
for (const file of ctx.files) {
|
|
2690
2993
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2691
|
-
const layout = hidingLayouts.get(
|
|
2994
|
+
const layout = hidingLayouts.get(path20.posix.dirname(file.path));
|
|
2692
2995
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2693
2996
|
if (!layout || !own) continue;
|
|
2694
2997
|
ctx.report({
|
|
@@ -2710,13 +3013,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
2710
3013
|
}
|
|
2711
3014
|
function routerRoot(ctx) {
|
|
2712
3015
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2713
|
-
return existsSync(
|
|
3016
|
+
return existsSync(path20.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2714
3017
|
}
|
|
2715
3018
|
function checkScreenLayouts(ctx, pkg) {
|
|
2716
3019
|
const layouts = nativeLayouts(pkg);
|
|
2717
3020
|
if (layouts.length === 0) return;
|
|
2718
3021
|
const rootDir = routerRoot(ctx);
|
|
2719
|
-
if (!existsSync(
|
|
3022
|
+
if (!existsSync(path20.join(ctx.root, rootDir))) {
|
|
2720
3023
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2721
3024
|
return;
|
|
2722
3025
|
}
|
|
@@ -2772,7 +3075,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
2772
3075
|
function readExpoConfigs(root) {
|
|
2773
3076
|
const out = [];
|
|
2774
3077
|
for (const name of EXPO_CONFIGS) {
|
|
2775
|
-
const abs =
|
|
3078
|
+
const abs = path20.join(root, name);
|
|
2776
3079
|
if (!existsSync(abs)) continue;
|
|
2777
3080
|
const text = readFileSync(abs, "utf8");
|
|
2778
3081
|
let json = null;
|
|
@@ -2806,13 +3109,13 @@ function pluginOptions(json, module) {
|
|
|
2806
3109
|
return null;
|
|
2807
3110
|
}
|
|
2808
3111
|
function dependencies(root) {
|
|
2809
|
-
const file =
|
|
3112
|
+
const file = path20.join(root, "package.json");
|
|
2810
3113
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2811
3114
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2812
3115
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2813
3116
|
}
|
|
2814
3117
|
function runtimeDependencies(root) {
|
|
2815
|
-
const file =
|
|
3118
|
+
const file = path20.join(root, "package.json");
|
|
2816
3119
|
if (!existsSync(file)) return {};
|
|
2817
3120
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2818
3121
|
}
|
|
@@ -2893,126 +3196,6 @@ function checkStoreReadiness(ctx) {
|
|
|
2893
3196
|
});
|
|
2894
3197
|
}
|
|
2895
3198
|
}
|
|
2896
|
-
|
|
2897
|
-
// src/doctor/semver.ts
|
|
2898
|
-
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2899
|
-
function parseVersion(v) {
|
|
2900
|
-
const m = VERSION.exec(v.trim());
|
|
2901
|
-
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2902
|
-
}
|
|
2903
|
-
function compareVersions(a, b) {
|
|
2904
|
-
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
2905
|
-
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
2906
|
-
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
2907
|
-
const x = a.pre[i];
|
|
2908
|
-
const y = b.pre[i];
|
|
2909
|
-
if (x === void 0) return -1;
|
|
2910
|
-
if (y === void 0) return 1;
|
|
2911
|
-
if (x === y) continue;
|
|
2912
|
-
const nx = /^\d+$/.test(x);
|
|
2913
|
-
const ny = /^\d+$/.test(y);
|
|
2914
|
-
if (nx && ny) return +x < +y ? -1 : 1;
|
|
2915
|
-
if (nx !== ny) return nx ? -1 : 1;
|
|
2916
|
-
return x < y ? -1 : 1;
|
|
2917
|
-
}
|
|
2918
|
-
return 0;
|
|
2919
|
-
}
|
|
2920
|
-
function partial(s) {
|
|
2921
|
-
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
2922
|
-
if (!m) return null;
|
|
2923
|
-
const nums = [];
|
|
2924
|
-
let wild = false;
|
|
2925
|
-
for (const part of [m[1], m[2], m[3]]) {
|
|
2926
|
-
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
2927
|
-
wild = true;
|
|
2928
|
-
nums.push(null);
|
|
2929
|
-
} else nums.push(+part);
|
|
2930
|
-
}
|
|
2931
|
-
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
2932
|
-
}
|
|
2933
|
-
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
2934
|
-
function comparators(token) {
|
|
2935
|
-
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
2936
|
-
if (!m) return null;
|
|
2937
|
-
const op = m[1] ?? "";
|
|
2938
|
-
const p = partial(m[2]);
|
|
2939
|
-
if (!p) return null;
|
|
2940
|
-
const [major, mi, pa] = p.nums;
|
|
2941
|
-
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
2942
|
-
const M = major;
|
|
2943
|
-
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
2944
|
-
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
2945
|
-
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
2946
|
-
const out = switchOp();
|
|
2947
|
-
if (p.pre.length) {
|
|
2948
|
-
for (const c of out) if (c.v === lo) c.pre = true;
|
|
2949
|
-
}
|
|
2950
|
-
return out;
|
|
2951
|
-
function switchOp() {
|
|
2952
|
-
switch (op) {
|
|
2953
|
-
case "^": {
|
|
2954
|
-
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
2955
|
-
return [
|
|
2956
|
-
{ op: ">=", v: lo },
|
|
2957
|
-
{ op: "<", v: bound }
|
|
2958
|
-
];
|
|
2959
|
-
}
|
|
2960
|
-
case "~":
|
|
2961
|
-
case "~>":
|
|
2962
|
-
return [
|
|
2963
|
-
{ op: ">=", v: lo },
|
|
2964
|
-
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
2965
|
-
];
|
|
2966
|
-
case ">":
|
|
2967
|
-
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
2968
|
-
case ">=":
|
|
2969
|
-
return [{ op: ">=", v: lo }];
|
|
2970
|
-
case "<":
|
|
2971
|
-
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
2972
|
-
case "<=":
|
|
2973
|
-
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
2974
|
-
default:
|
|
2975
|
-
return upper ? [
|
|
2976
|
-
{ op: ">=", v: lo },
|
|
2977
|
-
{ op: "<", v: upper }
|
|
2978
|
-
] : [{ op: "=", v: lo }];
|
|
2979
|
-
}
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
function test(c, v) {
|
|
2983
|
-
const d = compareVersions(v, c.v);
|
|
2984
|
-
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
2985
|
-
}
|
|
2986
|
-
function parseRange(range) {
|
|
2987
|
-
const alts = [];
|
|
2988
|
-
for (const raw of range.trim().split("||")) {
|
|
2989
|
-
const alt = raw.trim();
|
|
2990
|
-
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
2991
|
-
if (hyphen) {
|
|
2992
|
-
const from = comparators(`>=${hyphen[1]}`);
|
|
2993
|
-
const to = comparators(`<=${hyphen[2]}`);
|
|
2994
|
-
if (!from || !to) return null;
|
|
2995
|
-
alts.push([...from, ...to]);
|
|
2996
|
-
continue;
|
|
2997
|
-
}
|
|
2998
|
-
const set = [];
|
|
2999
|
-
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
3000
|
-
const cs = comparators(token);
|
|
3001
|
-
if (!cs) return null;
|
|
3002
|
-
set.push(...cs);
|
|
3003
|
-
}
|
|
3004
|
-
alts.push(set);
|
|
3005
|
-
}
|
|
3006
|
-
return alts;
|
|
3007
|
-
}
|
|
3008
|
-
function satisfies(version, range) {
|
|
3009
|
-
const v = parseVersion(version);
|
|
3010
|
-
const alts = parseRange(range);
|
|
3011
|
-
if (!v || !alts) return null;
|
|
3012
|
-
return alts.some(
|
|
3013
|
-
(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))
|
|
3014
|
-
);
|
|
3015
|
-
}
|
|
3016
3199
|
var TRAIL_DEPTH = 6;
|
|
3017
3200
|
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
3018
3201
|
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
@@ -3186,14 +3369,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3186
3369
|
seen.add(file);
|
|
3187
3370
|
const json = readJsonc(file);
|
|
3188
3371
|
if (!json) return {};
|
|
3189
|
-
const dir =
|
|
3372
|
+
const dir = path20.dirname(file);
|
|
3190
3373
|
let merged = {};
|
|
3191
3374
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3192
3375
|
for (const ext of parents) {
|
|
3193
3376
|
if (typeof ext !== "string") continue;
|
|
3194
3377
|
let target = null;
|
|
3195
|
-
if (ext.startsWith(".") ||
|
|
3196
|
-
const abs =
|
|
3378
|
+
if (ext.startsWith(".") || path20.isAbsolute(ext)) {
|
|
3379
|
+
const abs = path20.resolve(dir, ext);
|
|
3197
3380
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3198
3381
|
} else {
|
|
3199
3382
|
const parts = ext.split("/");
|
|
@@ -3201,14 +3384,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3201
3384
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3202
3385
|
if (pkgDir) {
|
|
3203
3386
|
const sub = parts.slice(nameLength).join("/");
|
|
3204
|
-
const abs =
|
|
3387
|
+
const abs = path20.join(pkgDir, sub || "tsconfig.json");
|
|
3205
3388
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3206
3389
|
}
|
|
3207
3390
|
}
|
|
3208
3391
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3209
3392
|
}
|
|
3210
3393
|
const opts = json.compilerOptions ?? {};
|
|
3211
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
3394
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path20.resolve(dir, opts.baseUrl);
|
|
3212
3395
|
if (opts.paths && typeof opts.paths === "object") {
|
|
3213
3396
|
merged.paths = opts.paths;
|
|
3214
3397
|
merged.pathsDir = dir;
|
|
@@ -3219,7 +3402,7 @@ function aliases(root) {
|
|
|
3219
3402
|
const table = [];
|
|
3220
3403
|
let baseUrl = null;
|
|
3221
3404
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3222
|
-
const file =
|
|
3405
|
+
const file = path20.join(root, name);
|
|
3223
3406
|
if (!existsSync(file)) continue;
|
|
3224
3407
|
const config = readTsconfig(root, file);
|
|
3225
3408
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -3227,22 +3410,22 @@ function aliases(root) {
|
|
|
3227
3410
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3228
3411
|
if (!Array.isArray(targets)) continue;
|
|
3229
3412
|
const exact = !pattern.endsWith("*");
|
|
3230
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
3413
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path20.join(base, String(t).replace(/\*$/, ""))) });
|
|
3231
3414
|
}
|
|
3232
3415
|
}
|
|
3233
|
-
const pkg = readJsonc(
|
|
3416
|
+
const pkg = readJsonc(path20.join(root, "package.json"));
|
|
3234
3417
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3235
3418
|
if (typeof target !== "string") continue;
|
|
3236
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
3419
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path20.join(root, target.replace(/\*.*$/, ""))] });
|
|
3237
3420
|
}
|
|
3238
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
3421
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path20.join(root, "src") + path20.sep, root + path20.sep] });
|
|
3239
3422
|
return { table, baseUrl };
|
|
3240
3423
|
}
|
|
3241
3424
|
function resolveFile(base) {
|
|
3242
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
3425
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path20.join(base, `index${e}`))];
|
|
3243
3426
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3244
3427
|
for (const p of tries) {
|
|
3245
|
-
if (SCRIPT_EXTS2.has(
|
|
3428
|
+
if (SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3246
3429
|
}
|
|
3247
3430
|
return null;
|
|
3248
3431
|
}
|
|
@@ -3256,7 +3439,7 @@ function createTrail(ctx) {
|
|
|
3256
3439
|
const { table, baseUrl } = aliases(ctx.root);
|
|
3257
3440
|
let declared = null;
|
|
3258
3441
|
try {
|
|
3259
|
-
const pkg = JSON.parse(readFileSync(
|
|
3442
|
+
const pkg = JSON.parse(readFileSync(path20.join(ctx.root, "package.json"), "utf8"));
|
|
3260
3443
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3261
3444
|
} catch {
|
|
3262
3445
|
declared = null;
|
|
@@ -3287,17 +3470,17 @@ function createTrail(ctx) {
|
|
|
3287
3470
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3288
3471
|
let resolved = null;
|
|
3289
3472
|
if (spec.startsWith(".")) {
|
|
3290
|
-
resolved = resolveFile(
|
|
3473
|
+
resolved = resolveFile(path20.resolve(path20.dirname(file.absolutePath), spec));
|
|
3291
3474
|
if (!resolved) lost = true;
|
|
3292
3475
|
} else {
|
|
3293
3476
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3294
3477
|
if (alias) {
|
|
3295
3478
|
for (const t of alias.targets) {
|
|
3296
|
-
resolved = resolveFile(alias.exact ? t :
|
|
3479
|
+
resolved = resolveFile(alias.exact ? t : path20.join(t, spec.slice(alias.prefix.length)));
|
|
3297
3480
|
if (resolved) break;
|
|
3298
3481
|
}
|
|
3299
3482
|
}
|
|
3300
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
3483
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path20.join(baseUrl, spec));
|
|
3301
3484
|
if (!resolved) {
|
|
3302
3485
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3303
3486
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -3368,27 +3551,159 @@ function createTrail(ctx) {
|
|
|
3368
3551
|
};
|
|
3369
3552
|
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3370
3553
|
}
|
|
3554
|
+
function buildCatalog(packagesDir) {
|
|
3555
|
+
const packages = {};
|
|
3556
|
+
for (const dir of readdirSync(packagesDir).sort()) {
|
|
3557
|
+
const file = path20.join(packagesDir, dir, "package.json");
|
|
3558
|
+
if (!existsSync(file)) continue;
|
|
3559
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3560
|
+
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
3561
|
+
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
3562
|
+
}
|
|
3563
|
+
return { packages };
|
|
3564
|
+
}
|
|
3371
3565
|
|
|
3372
3566
|
// src/blocks/discover.ts
|
|
3567
|
+
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
3568
|
+
function cliPackageDir() {
|
|
3569
|
+
let dir = path20.dirname(fileURLToPath(import.meta.url));
|
|
3570
|
+
for (; ; ) {
|
|
3571
|
+
const file = path20.join(dir, "package.json");
|
|
3572
|
+
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
3573
|
+
const parent = path20.dirname(dir);
|
|
3574
|
+
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
3575
|
+
dir = parent;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
function workspacePackagesDir() {
|
|
3579
|
+
const dir = path20.resolve(cliPackageDir(), "..");
|
|
3580
|
+
return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
3581
|
+
}
|
|
3582
|
+
var catalogCache;
|
|
3583
|
+
function readCatalog() {
|
|
3584
|
+
if (catalogCache) return catalogCache;
|
|
3585
|
+
const workspace = workspacePackagesDir();
|
|
3586
|
+
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
3587
|
+
const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
3588
|
+
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
3589
|
+
return catalogCache;
|
|
3590
|
+
}
|
|
3373
3591
|
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
3374
3592
|
function installedGenesis(root) {
|
|
3375
3593
|
const found = /* @__PURE__ */ new Map();
|
|
3376
|
-
let dir =
|
|
3594
|
+
let dir = path20.resolve(root);
|
|
3377
3595
|
for (; ; ) {
|
|
3378
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
3379
|
-
const scope =
|
|
3596
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
|
|
3597
|
+
const scope = path20.join(dir, "node_modules", "@marktiderman");
|
|
3380
3598
|
if (existsSync(scope)) {
|
|
3381
3599
|
for (const entry of readdirSync(scope)) {
|
|
3382
3600
|
const name = `@marktiderman/${entry}`;
|
|
3383
3601
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
3384
|
-
if (existsSync(
|
|
3602
|
+
if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
|
|
3385
3603
|
}
|
|
3386
3604
|
}
|
|
3387
|
-
const parent =
|
|
3605
|
+
const parent = path20.dirname(dir);
|
|
3388
3606
|
if (atInstallRoot || parent === dir) return found;
|
|
3389
3607
|
dir = parent;
|
|
3390
3608
|
}
|
|
3391
3609
|
}
|
|
3610
|
+
var declarationCache = /* @__PURE__ */ new Map();
|
|
3611
|
+
function declarationsOf(dir, warnings) {
|
|
3612
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3613
|
+
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
3614
|
+
let cached = declarationCache.get(key2);
|
|
3615
|
+
if (!cached) {
|
|
3616
|
+
cached = loadDeclarations(dir, warnings);
|
|
3617
|
+
declarationCache.set(key2, cached);
|
|
3618
|
+
}
|
|
3619
|
+
return cached;
|
|
3620
|
+
}
|
|
3621
|
+
async function loadDeclarations(dir, warnings) {
|
|
3622
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3623
|
+
const entry = pkg.exports?.["./blocks"];
|
|
3624
|
+
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
3625
|
+
if (typeof target !== "string") return {};
|
|
3626
|
+
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
3627
|
+
const file = rel && path20.join(dir, ...rel.split("/"));
|
|
3628
|
+
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
3629
|
+
try {
|
|
3630
|
+
const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
|
|
3631
|
+
const mod = await jiti.import(file);
|
|
3632
|
+
const out = {};
|
|
3633
|
+
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
3634
|
+
return out;
|
|
3635
|
+
} catch (err) {
|
|
3636
|
+
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.`);
|
|
3637
|
+
return {};
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
3641
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
3642
|
+
const raw = rawBlocksOf(pkg);
|
|
3643
|
+
const declared = await declarationsOf(dir, warnings);
|
|
3644
|
+
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
3645
|
+
const out = [];
|
|
3646
|
+
for (const id of [...ids].sort()) {
|
|
3647
|
+
const fromJson = raw[id] ?? {};
|
|
3648
|
+
const merged = { ...fromJson, ...declared[id] };
|
|
3649
|
+
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
3650
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
3651
|
+
if (manifest) out.push(manifest);
|
|
3652
|
+
}
|
|
3653
|
+
return out;
|
|
3654
|
+
}
|
|
3655
|
+
function withProvides(declared, json) {
|
|
3656
|
+
if (!Array.isArray(declared)) return declared;
|
|
3657
|
+
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
3658
|
+
return declared.map((m) => {
|
|
3659
|
+
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
3660
|
+
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
3661
|
+
});
|
|
3662
|
+
}
|
|
3663
|
+
async function allBlocks(root, warnings = []) {
|
|
3664
|
+
const out = [];
|
|
3665
|
+
for (const local of localPackages(root)) {
|
|
3666
|
+
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
3667
|
+
}
|
|
3668
|
+
const installed = installedGenesis(root);
|
|
3669
|
+
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
3670
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
3671
|
+
if (installed.has(name)) continue;
|
|
3672
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
3673
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
3674
|
+
if (manifest) out.push({ manifest, from: "catalog" });
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
return out;
|
|
3678
|
+
}
|
|
3679
|
+
function tryParse(parse2, warnings) {
|
|
3680
|
+
try {
|
|
3681
|
+
return parse2();
|
|
3682
|
+
} catch (err) {
|
|
3683
|
+
if (!(err instanceof ManifestError)) throw err;
|
|
3684
|
+
warnings.push(err.message);
|
|
3685
|
+
return null;
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
function catalogBlocks(warnings = []) {
|
|
3689
|
+
const out = [];
|
|
3690
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
3691
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
3692
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
3693
|
+
if (manifest) out.push(manifest);
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
return out;
|
|
3697
|
+
}
|
|
3698
|
+
async function findBlock(root, id, options = {}) {
|
|
3699
|
+
const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
|
|
3700
|
+
if (all.length === 0) {
|
|
3701
|
+
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
3702
|
+
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
3703
|
+
}
|
|
3704
|
+
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
3705
|
+
return all[0];
|
|
3706
|
+
}
|
|
3392
3707
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
3393
3708
|
var STEMS = {
|
|
3394
3709
|
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
@@ -3406,7 +3721,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
3406
3721
|
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;
|
|
3407
3722
|
function routesDir(ctx) {
|
|
3408
3723
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3409
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
3724
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path20.join(ctx.root, d))) ?? null;
|
|
3410
3725
|
}
|
|
3411
3726
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3412
3727
|
function flavorOf(dir, rels) {
|
|
@@ -3541,7 +3856,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3541
3856
|
});
|
|
3542
3857
|
if (typeof raw === "string") {
|
|
3543
3858
|
if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
|
|
3544
|
-
const file =
|
|
3859
|
+
const file = path20.resolve(packageDir, raw);
|
|
3545
3860
|
if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
|
|
3546
3861
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
3547
3862
|
let parsed;
|
|
@@ -3590,7 +3905,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3590
3905
|
if (typeof c.plugin === "string") {
|
|
3591
3906
|
if (!packageDir) plugin = c.plugin;
|
|
3592
3907
|
else {
|
|
3593
|
-
plugin =
|
|
3908
|
+
plugin = path20.resolve(packageDir, c.plugin);
|
|
3594
3909
|
if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
3595
3910
|
}
|
|
3596
3911
|
}
|
|
@@ -3640,7 +3955,7 @@ function checkPattern(v, where2, fail) {
|
|
|
3640
3955
|
}
|
|
3641
3956
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
3642
3957
|
function readDeclaringPackage(dir, local) {
|
|
3643
|
-
const file =
|
|
3958
|
+
const file = path20.join(dir, "package.json");
|
|
3644
3959
|
let stamp;
|
|
3645
3960
|
let real2;
|
|
3646
3961
|
try {
|
|
@@ -3663,7 +3978,7 @@ ${local}`;
|
|
|
3663
3978
|
const pkg = {
|
|
3664
3979
|
name: json.name,
|
|
3665
3980
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
3666
|
-
dir:
|
|
3981
|
+
dir: path20.resolve(dir),
|
|
3667
3982
|
namespace: ruleNamespace(json.name),
|
|
3668
3983
|
local,
|
|
3669
3984
|
private: json.private === true,
|
|
@@ -3677,7 +3992,7 @@ ${local}`;
|
|
|
3677
3992
|
if (raw !== void 0) {
|
|
3678
3993
|
const ignored = [];
|
|
3679
3994
|
try {
|
|
3680
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
3995
|
+
pkg.declaration = validateDeclaration(raw, json.name, path20.resolve(dir), ignored);
|
|
3681
3996
|
if (ignored.length) pkg.ignored = ignored;
|
|
3682
3997
|
} catch (err) {
|
|
3683
3998
|
pkg.error = err.message;
|
|
@@ -3696,14 +4011,14 @@ function discoverPackages(root) {
|
|
|
3696
4011
|
for (const dir of installed) {
|
|
3697
4012
|
let scope;
|
|
3698
4013
|
try {
|
|
3699
|
-
scope =
|
|
4014
|
+
scope = path20.dirname(realpathSync(dir));
|
|
3700
4015
|
} catch {
|
|
3701
4016
|
continue;
|
|
3702
4017
|
}
|
|
3703
|
-
if (
|
|
4018
|
+
if (path20.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
3704
4019
|
for (const entry of readdirSync(scope)) {
|
|
3705
4020
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
3706
|
-
const pkg = readDeclaringPackage(
|
|
4021
|
+
const pkg = readDeclaringPackage(path20.join(scope, entry), false);
|
|
3707
4022
|
if (pkg) byName.set(pkg.name, pkg);
|
|
3708
4023
|
}
|
|
3709
4024
|
}
|
|
@@ -3890,10 +4205,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
3890
4205
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
3891
4206
|
function sourceFiles(dir, rel = "") {
|
|
3892
4207
|
const out = [];
|
|
3893
|
-
for (const entry of readdirSync(
|
|
4208
|
+
for (const entry of readdirSync(path20.join(dir, rel)).sort()) {
|
|
3894
4209
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
3895
4210
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
3896
|
-
const stat = lstatSync(
|
|
4211
|
+
const stat = lstatSync(path20.join(dir, child));
|
|
3897
4212
|
if (stat.isSymbolicLink()) continue;
|
|
3898
4213
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
3899
4214
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -3916,13 +4231,13 @@ function matchPattern(pattern, spec) {
|
|
|
3916
4231
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
3917
4232
|
}
|
|
3918
4233
|
function tsconfigPaths(dir) {
|
|
3919
|
-
const file =
|
|
4234
|
+
const file = path20.join(dir, "tsconfig.json");
|
|
3920
4235
|
if (!existsSync(file)) return [];
|
|
3921
4236
|
try {
|
|
3922
4237
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
3923
4238
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
3924
|
-
const base =
|
|
3925
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
4239
|
+
const base = path20.resolve(dir, options.baseUrl ?? ".");
|
|
4240
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path20.resolve(base, t)) }));
|
|
3926
4241
|
} catch {
|
|
3927
4242
|
return [];
|
|
3928
4243
|
}
|
|
@@ -3936,8 +4251,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3936
4251
|
const hit = matchPattern(pattern, spec);
|
|
3937
4252
|
if (hit === null) continue;
|
|
3938
4253
|
return targets.some((t) => {
|
|
3939
|
-
const rel =
|
|
3940
|
-
return !rel.startsWith("..") && !
|
|
4254
|
+
const rel = path20.relative(pkg.dir, t.replace("*", hit));
|
|
4255
|
+
return !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
3941
4256
|
});
|
|
3942
4257
|
}
|
|
3943
4258
|
return null;
|
|
@@ -3950,7 +4265,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3950
4265
|
...Object.keys(json.optionalDependencies ?? {})
|
|
3951
4266
|
]);
|
|
3952
4267
|
for (const file of sourceFiles(pkg.dir)) {
|
|
3953
|
-
const code = stripForImports(readFileSync(
|
|
4268
|
+
const code = stripForImports(readFileSync(path20.join(pkg.dir, file), "utf8"));
|
|
3954
4269
|
if (code === null) continue;
|
|
3955
4270
|
const at = `${pkg.rel}/${file}`;
|
|
3956
4271
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -3975,9 +4290,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3975
4290
|
continue;
|
|
3976
4291
|
}
|
|
3977
4292
|
if (spec.startsWith(".")) {
|
|
3978
|
-
const target =
|
|
3979
|
-
const rel =
|
|
3980
|
-
if (rel.startsWith("..") ||
|
|
4293
|
+
const target = path20.resolve(pkg.dir, path20.dirname(file), spec);
|
|
4294
|
+
const rel = path20.relative(pkg.dir, target);
|
|
4295
|
+
if (rel.startsWith("..") || path20.isAbsolute(rel)) {
|
|
3981
4296
|
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` });
|
|
3982
4297
|
}
|
|
3983
4298
|
continue;
|
|
@@ -4014,12 +4329,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4014
4329
|
const from = own ? "" : ` (in ${m.package})`;
|
|
4015
4330
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
4016
4331
|
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` });
|
|
4017
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
4332
|
+
} else if (typeof m.test === "string" && !existsSync(path20.join(home, m.test))) {
|
|
4018
4333
|
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` });
|
|
4019
4334
|
}
|
|
4020
4335
|
}
|
|
4021
4336
|
}
|
|
4022
|
-
const dir =
|
|
4337
|
+
const dir = path20.join(pkg.dir, "migrations");
|
|
4023
4338
|
if (!existsSync(dir)) return;
|
|
4024
4339
|
const seen = /* @__PURE__ */ new Map();
|
|
4025
4340
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -4028,21 +4343,21 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4028
4343
|
const other = seen.get(m[1]);
|
|
4029
4344
|
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` });
|
|
4030
4345
|
else seen.set(m[1], name);
|
|
4031
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
4346
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path20.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
4032
4347
|
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")})` });
|
|
4033
4348
|
}
|
|
4034
4349
|
}
|
|
4035
4350
|
}
|
|
4036
4351
|
function checkExports(ctx, pkg, json) {
|
|
4037
4352
|
const targets = [];
|
|
4038
|
-
const
|
|
4353
|
+
const walk2 = (v) => {
|
|
4039
4354
|
if (typeof v === "string") targets.push(v);
|
|
4040
|
-
else if (v && typeof v === "object") for (const x of Object.values(v))
|
|
4355
|
+
else if (v && typeof v === "object") for (const x of Object.values(v)) walk2(x);
|
|
4041
4356
|
};
|
|
4042
|
-
|
|
4357
|
+
walk2(json.exports);
|
|
4043
4358
|
for (const t of targets) {
|
|
4044
4359
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
4045
|
-
if (!existsSync(
|
|
4360
|
+
if (!existsSync(path20.join(pkg.dir, t))) {
|
|
4046
4361
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
4047
4362
|
}
|
|
4048
4363
|
}
|
|
@@ -4060,11 +4375,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
4060
4375
|
function checkTaggedTests(ctx, pkg) {
|
|
4061
4376
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
4062
4377
|
if (!tests.length) return;
|
|
4063
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
4378
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path20.join(pkg.dir, f), "utf8")));
|
|
4064
4379
|
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>` });
|
|
4065
4380
|
}
|
|
4066
4381
|
function checkRegistered(ctx, pkg) {
|
|
4067
|
-
const file =
|
|
4382
|
+
const file = path20.join(ctx.root, "features.json");
|
|
4068
4383
|
if (!existsSync(file)) return;
|
|
4069
4384
|
let doc;
|
|
4070
4385
|
try {
|
|
@@ -4074,7 +4389,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
4074
4389
|
}
|
|
4075
4390
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4076
4391
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
4077
|
-
if (top) forms.add(
|
|
4392
|
+
if (top) forms.add(path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/"));
|
|
4078
4393
|
const covered = (doc.features ?? []).some(
|
|
4079
4394
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
4080
4395
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -4104,8 +4419,8 @@ function mergeBaseOf(root, base) {
|
|
|
4104
4419
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
4105
4420
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4106
4421
|
if (!top) return;
|
|
4107
|
-
const appRelative = (fromTop) =>
|
|
4108
|
-
const inRepo =
|
|
4422
|
+
const appRelative = (fromTop) => path20.relative(realpathSync(ctx.root), path20.join(top, fromTop)).split(path20.sep).join("/");
|
|
4423
|
+
const inRepo = path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/");
|
|
4109
4424
|
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");
|
|
4110
4425
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
4111
4426
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -4128,11 +4443,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4128
4443
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
4129
4444
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
4130
4445
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
4131
|
-
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) =>
|
|
4446
|
+
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) => path20.join(top, f)) : [];
|
|
4132
4447
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
4133
4448
|
const named = naming.length > 0;
|
|
4134
4449
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
4135
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
4450
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path20.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
4136
4451
|
}
|
|
4137
4452
|
let jsonBefore = null;
|
|
4138
4453
|
try {
|
|
@@ -4142,7 +4457,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4142
4457
|
}
|
|
4143
4458
|
const raw = json;
|
|
4144
4459
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
4145
|
-
const appInRepo =
|
|
4460
|
+
const appInRepo = path20.relative(top, realpathSync(ctx.root)).split(path20.sep).join("/");
|
|
4146
4461
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
4147
4462
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
4148
4463
|
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` });
|
|
@@ -4194,7 +4509,7 @@ function checkPackagesPack(ctx) {
|
|
|
4194
4509
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
4195
4510
|
}
|
|
4196
4511
|
for (const pkg of packages) {
|
|
4197
|
-
const json = JSON.parse(readFileSync(
|
|
4512
|
+
const json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
4198
4513
|
checkImports2(ctx, pkg, json);
|
|
4199
4514
|
checkExports(ctx, pkg, json);
|
|
4200
4515
|
checkBlocks(ctx, pkg, json);
|
|
@@ -4206,6 +4521,45 @@ function checkPackagesPack(ctx) {
|
|
|
4206
4521
|
if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
4207
4522
|
}
|
|
4208
4523
|
}
|
|
4524
|
+
var LOCK_FILE = "genesis.lock.json";
|
|
4525
|
+
function emptyLock() {
|
|
4526
|
+
return { version: 1, blocks: {}, files: {} };
|
|
4527
|
+
}
|
|
4528
|
+
function readLock(root) {
|
|
4529
|
+
const file = path20.join(root, LOCK_FILE);
|
|
4530
|
+
if (!existsSync(file)) return emptyLock();
|
|
4531
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
4532
|
+
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
4533
|
+
return {
|
|
4534
|
+
version: 1,
|
|
4535
|
+
...raw.substitutions ? { substitutions: raw.substitutions } : {},
|
|
4536
|
+
blocks: raw.blocks ?? {},
|
|
4537
|
+
files: raw.files ?? {},
|
|
4538
|
+
...raw.migrations ? { migrations: raw.migrations } : {}
|
|
4539
|
+
};
|
|
4540
|
+
}
|
|
4541
|
+
function parseSource(source) {
|
|
4542
|
+
const at = source.indexOf(":");
|
|
4543
|
+
if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
|
|
4544
|
+
return { package: source.slice(0, at), path: source.slice(at + 1) };
|
|
4545
|
+
}
|
|
4546
|
+
|
|
4547
|
+
// src/blocks/database.ts
|
|
4548
|
+
function databaseElsewhere(root) {
|
|
4549
|
+
const setting = readGenesisConfig(root)?.supabase;
|
|
4550
|
+
if (setting === void 0) return null;
|
|
4551
|
+
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
4552
|
+
const resolved = path20.resolve(root, setting.app);
|
|
4553
|
+
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
4554
|
+
const dir = real2(resolved);
|
|
4555
|
+
if (dir === real2(path20.resolve(root))) throw new GenesisConfigError(`${path20.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
|
|
4556
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path20.join(dir, "supabase")) };
|
|
4557
|
+
}
|
|
4558
|
+
function isSupabasePath(rel) {
|
|
4559
|
+
return rel === "supabase" || rel.startsWith("supabase/");
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
// src/doctor/supabase.ts
|
|
4209
4563
|
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
4210
4564
|
var DEFAULT_BASE = "origin/main";
|
|
4211
4565
|
var DEFAULT_EXPOSED = ["public"];
|
|
@@ -4386,11 +4740,12 @@ function gitView(root, dir, base) {
|
|
|
4386
4740
|
return { touched: touched2, edited };
|
|
4387
4741
|
}
|
|
4388
4742
|
function checkSupabasePack(ctx) {
|
|
4743
|
+
if (databaseElsewhere(ctx.root)) return;
|
|
4389
4744
|
const settings = ctx.config.supabase ?? {};
|
|
4390
4745
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
4391
|
-
const abs =
|
|
4746
|
+
const abs = path20.join(ctx.root, dir);
|
|
4392
4747
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
4393
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
4748
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path20.join(abs, n), "utf8")) }));
|
|
4394
4749
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
4395
4750
|
const base = settings.base ?? DEFAULT_BASE;
|
|
4396
4751
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -4407,7 +4762,7 @@ function checkSupabasePack(ctx) {
|
|
|
4407
4762
|
}
|
|
4408
4763
|
}
|
|
4409
4764
|
const since = settings.since;
|
|
4410
|
-
const afterSince = (file) => since === void 0 ||
|
|
4765
|
+
const afterSince = (file) => since === void 0 || path20.posix.basename(file) >= since;
|
|
4411
4766
|
if ("reason" in view && since === void 0) {
|
|
4412
4767
|
ctx.report({
|
|
4413
4768
|
rule: "migration-grants",
|
|
@@ -4685,51 +5040,12 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
4685
5040
|
});
|
|
4686
5041
|
}
|
|
4687
5042
|
}
|
|
4688
|
-
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
4689
|
-
function readReleaseManifest(root) {
|
|
4690
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
4691
|
-
const file = dir && path19.join(dir, "dist", "versions.json");
|
|
4692
|
-
if (!file || !existsSync(file)) return null;
|
|
4693
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
4694
|
-
}
|
|
4695
|
-
function checkVersionSkew(ctx) {
|
|
4696
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
4697
|
-
if (!manifest) return;
|
|
4698
|
-
const overlays = markedOverlays(ctx);
|
|
4699
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
4700
|
-
const overlay = overlays.get(name);
|
|
4701
|
-
if (overlay) {
|
|
4702
|
-
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
4703
|
-
if (from !== want) {
|
|
4704
|
-
ctx.report({
|
|
4705
|
-
rule: "version-skew",
|
|
4706
|
-
level: "warn",
|
|
4707
|
-
file: "package.json",
|
|
4708
|
-
subject: name,
|
|
4709
|
-
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).`
|
|
4710
|
-
});
|
|
4711
|
-
}
|
|
4712
|
-
continue;
|
|
4713
|
-
}
|
|
4714
|
-
const dir = findPackageDir(ctx.root, name);
|
|
4715
|
-
if (!dir) continue;
|
|
4716
|
-
const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
|
|
4717
|
-
if (have === want) continue;
|
|
4718
|
-
ctx.report({
|
|
4719
|
-
rule: "version-skew",
|
|
4720
|
-
level: "warn",
|
|
4721
|
-
file: "package.json",
|
|
4722
|
-
subject: name,
|
|
4723
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
4724
|
-
});
|
|
4725
|
-
}
|
|
4726
|
-
}
|
|
4727
5043
|
var GENESIS2 = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
4728
5044
|
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
4729
5045
|
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)$/;
|
|
4730
5046
|
var readManifest = (dir) => {
|
|
4731
5047
|
try {
|
|
4732
|
-
return JSON.parse(readFileSync(
|
|
5048
|
+
return JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4733
5049
|
} catch {
|
|
4734
5050
|
return null;
|
|
4735
5051
|
}
|
|
@@ -4743,18 +5059,18 @@ var real = (p) => {
|
|
|
4743
5059
|
};
|
|
4744
5060
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
4745
5061
|
function nodeModulesOf(dir) {
|
|
4746
|
-
const parent =
|
|
4747
|
-
return
|
|
5062
|
+
const parent = path20.dirname(dir);
|
|
5063
|
+
return path20.basename(parent).startsWith("@") ? path20.dirname(parent) : parent;
|
|
4748
5064
|
}
|
|
4749
5065
|
function packagesIn(nodeModules) {
|
|
4750
5066
|
if (!existsSync(nodeModules)) return [];
|
|
4751
5067
|
const out = [];
|
|
4752
5068
|
for (const entry of readdirSync(nodeModules)) {
|
|
4753
5069
|
if (entry.startsWith(".")) continue;
|
|
4754
|
-
const p =
|
|
5070
|
+
const p = path20.join(nodeModules, entry);
|
|
4755
5071
|
if (entry.startsWith("@")) {
|
|
4756
5072
|
try {
|
|
4757
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5073
|
+
for (const sub of readdirSync(p)) out.push(path20.join(p, sub));
|
|
4758
5074
|
} catch {
|
|
4759
5075
|
}
|
|
4760
5076
|
} else {
|
|
@@ -4766,7 +5082,7 @@ function packagesIn(nodeModules) {
|
|
|
4766
5082
|
function genesisInstalls(root) {
|
|
4767
5083
|
const copies = /* @__PURE__ */ new Map();
|
|
4768
5084
|
const realRoot = real(root);
|
|
4769
|
-
const rel = (abs) =>
|
|
5085
|
+
const rel = (abs) => path20.relative(realRoot, abs).split(path20.sep).join("/") || ".";
|
|
4770
5086
|
const via = /* @__PURE__ */ new Map();
|
|
4771
5087
|
const record = (real2, manifest, by, range, root2) => {
|
|
4772
5088
|
let copy = copies.get(real2);
|
|
@@ -4778,7 +5094,7 @@ function genesisInstalls(root) {
|
|
|
4778
5094
|
via.get(real2).add(root2);
|
|
4779
5095
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
4780
5096
|
};
|
|
4781
|
-
const
|
|
5097
|
+
const walk2 = (kind, roots) => {
|
|
4782
5098
|
const expanded = /* @__PURE__ */ new Set();
|
|
4783
5099
|
const queue = [];
|
|
4784
5100
|
const visit = (dir, by, range) => {
|
|
@@ -4811,7 +5127,7 @@ function genesisInstalls(root) {
|
|
|
4811
5127
|
if (!dir) return null;
|
|
4812
5128
|
if (!ownInstall || name in declared) return dir;
|
|
4813
5129
|
const realDir = real(dir);
|
|
4814
|
-
if (realDir.startsWith(realRoot +
|
|
5130
|
+
if (realDir.startsWith(realRoot + path20.sep)) return dir;
|
|
4815
5131
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
4816
5132
|
};
|
|
4817
5133
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -4819,7 +5135,7 @@ function genesisInstalls(root) {
|
|
|
4819
5135
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
4820
5136
|
});
|
|
4821
5137
|
const app = readManifest(root);
|
|
4822
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5138
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path20.join(root, f)));
|
|
4823
5139
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
4824
5140
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
4825
5141
|
const runtimeDeps = {
|
|
@@ -4829,18 +5145,18 @@ function genesisInstalls(root) {
|
|
|
4829
5145
|
...app?.dependencies
|
|
4830
5146
|
};
|
|
4831
5147
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
4832
|
-
|
|
4833
|
-
const top =
|
|
4834
|
-
|
|
5148
|
+
walk2("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5149
|
+
const top = path20.join(root, "node_modules");
|
|
5150
|
+
walk2(
|
|
4835
5151
|
"hoisted",
|
|
4836
5152
|
packagesIn(top).filter((dir) => {
|
|
4837
|
-
const name =
|
|
5153
|
+
const name = path20.relative(top, dir).split(path20.sep).join("/");
|
|
4838
5154
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
4839
5155
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
4840
5156
|
);
|
|
4841
5157
|
const devRoots = { ...devDeps };
|
|
4842
5158
|
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
4843
|
-
|
|
5159
|
+
walk2("dev", rootsOf(devRoots, "the app (dev)"));
|
|
4844
5160
|
for (const [key2, copy] of copies) {
|
|
4845
5161
|
const kinds = via.get(key2);
|
|
4846
5162
|
copy.runtime = kinds.has("runtime");
|
|
@@ -4876,7 +5192,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
4876
5192
|
}
|
|
4877
5193
|
}
|
|
4878
5194
|
function checkPeerRanges(ctx) {
|
|
4879
|
-
const rel = (abs) =>
|
|
5195
|
+
const rel = (abs) => path20.relative(ctx.root, abs).split(path20.sep).join("/");
|
|
4880
5196
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
4881
5197
|
for (const copy of copies) {
|
|
4882
5198
|
const dir = copy.absolutePath;
|
|
@@ -5258,17 +5574,17 @@ var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
|
5258
5574
|
var MAX_BYTES = 2 * 1024 * 1024;
|
|
5259
5575
|
function appScripts(root) {
|
|
5260
5576
|
const out = [];
|
|
5261
|
-
const
|
|
5577
|
+
const walk2 = (dir) => {
|
|
5262
5578
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5263
|
-
const abs =
|
|
5579
|
+
const abs = path20.join(dir, entry.name);
|
|
5264
5580
|
if (entry.isDirectory()) {
|
|
5265
|
-
if (!SKIP_DIRS3.has(entry.name))
|
|
5581
|
+
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
5266
5582
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
5267
|
-
out.push(
|
|
5583
|
+
out.push(path20.relative(root, abs).split(path20.sep).join("/"));
|
|
5268
5584
|
}
|
|
5269
5585
|
}
|
|
5270
5586
|
};
|
|
5271
|
-
|
|
5587
|
+
walk2(root);
|
|
5272
5588
|
return out;
|
|
5273
5589
|
}
|
|
5274
5590
|
|
|
@@ -5352,7 +5668,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
5352
5668
|
function moduleFiles(ctx) {
|
|
5353
5669
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
5354
5670
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
5355
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
5671
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path20.join(ctx.root, rel), "utf8"), true) }));
|
|
5356
5672
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
5357
5673
|
}
|
|
5358
5674
|
function checkStudioServerImports(ctx) {
|
|
@@ -5388,7 +5704,7 @@ var REMOVED_WORDS = {
|
|
|
5388
5704
|
};
|
|
5389
5705
|
function checkRemovedScopeNames(ctx) {
|
|
5390
5706
|
let augmentedMemo;
|
|
5391
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
5707
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path20.join(ctx.root, rel), "utf8")));
|
|
5392
5708
|
for (const file of ctx.files) {
|
|
5393
5709
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
5394
5710
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -5460,16 +5776,16 @@ function genesisNamedImports(source) {
|
|
|
5460
5776
|
}
|
|
5461
5777
|
function declarationFiles(dir, out = []) {
|
|
5462
5778
|
for (const name of readdirSync(dir)) {
|
|
5463
|
-
const full =
|
|
5779
|
+
const full = path20.join(dir, name);
|
|
5464
5780
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
5465
5781
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
5466
5782
|
}
|
|
5467
5783
|
return out;
|
|
5468
5784
|
}
|
|
5469
5785
|
function readPackageTags(dir) {
|
|
5470
|
-
const pkg = JSON.parse(readFileSync(
|
|
5786
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
5471
5787
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
5472
|
-
const dist =
|
|
5788
|
+
const dist = path20.join(dir, "dist");
|
|
5473
5789
|
if (!existsSync(dist)) return tags;
|
|
5474
5790
|
for (const file of declarationFiles(dist)) {
|
|
5475
5791
|
const text = readFileSync(file, "utf8");
|
|
@@ -5487,7 +5803,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
5487
5803
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
5488
5804
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
5489
5805
|
const types = typeof target === "object" && target ? target.types : null;
|
|
5490
|
-
return typeof types === "string" ?
|
|
5806
|
+
return typeof types === "string" ? path20.join(tags.dir, types) : null;
|
|
5491
5807
|
}
|
|
5492
5808
|
function tagFor(tags, entry, name) {
|
|
5493
5809
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -5542,7 +5858,7 @@ function showAt(dir, rev, file) {
|
|
|
5542
5858
|
function configAtBase(root, base, explicitFile) {
|
|
5543
5859
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
5544
5860
|
if (!mergeBase) return null;
|
|
5545
|
-
const candidates = explicitFile ? [{ dir:
|
|
5861
|
+
const candidates = explicitFile ? [{ dir: path20.dirname(explicitFile), file: path20.basename(explicitFile), explicit: true }] : [
|
|
5546
5862
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
5547
5863
|
{ dir: root, file: "package.json", explicit: false }
|
|
5548
5864
|
];
|
|
@@ -5654,7 +5970,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5654
5970
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
5655
5971
|
let current = null;
|
|
5656
5972
|
try {
|
|
5657
|
-
current = lf(readFileSync(
|
|
5973
|
+
current = lf(readFileSync(path20.join(ctx.root, out), "utf8"));
|
|
5658
5974
|
} catch {
|
|
5659
5975
|
current = null;
|
|
5660
5976
|
}
|
|
@@ -5678,7 +5994,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5678
5994
|
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}` });
|
|
5679
5995
|
return;
|
|
5680
5996
|
}
|
|
5681
|
-
const target =
|
|
5997
|
+
const target = path20.relative(process.cwd(), path20.join(ctx.root, out)) || out;
|
|
5682
5998
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
5683
5999
|
if (current !== expected) {
|
|
5684
6000
|
ctx.report({
|
|
@@ -5841,13 +6157,13 @@ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
|
5841
6157
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
5842
6158
|
const rows = primitivesCatalog(packages);
|
|
5843
6159
|
const changed = [];
|
|
5844
|
-
const agents =
|
|
6160
|
+
const agents = path20.join(root, agentsFile);
|
|
5845
6161
|
const before = read(agents);
|
|
5846
6162
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
5847
|
-
const skill =
|
|
6163
|
+
const skill = path20.join(root, SKILL_PATH);
|
|
5848
6164
|
const skillText = renderSkill(rows);
|
|
5849
6165
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
5850
|
-
mkdirSync(
|
|
6166
|
+
mkdirSync(path20.dirname(skill), { recursive: true });
|
|
5851
6167
|
writeFileSync(skill, skillText);
|
|
5852
6168
|
changed.push(SKILL_PATH);
|
|
5853
6169
|
}
|
|
@@ -5859,8 +6175,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
5859
6175
|
}
|
|
5860
6176
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
5861
6177
|
const rows = primitivesCatalog(packages);
|
|
5862
|
-
const skill = read(
|
|
5863
|
-
const block = currentAgentsBlock(read(
|
|
6178
|
+
const skill = read(path20.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
6179
|
+
const block = currentAgentsBlock(read(path20.join(root, agentsFile)));
|
|
5864
6180
|
return {
|
|
5865
6181
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
5866
6182
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -5882,9 +6198,274 @@ function checkAgentGuide(ctx) {
|
|
|
5882
6198
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
5883
6199
|
}
|
|
5884
6200
|
}
|
|
6201
|
+
var CLI = "@marktiderman/genesis-cli";
|
|
6202
|
+
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6203
|
+
let parsed;
|
|
6204
|
+
try {
|
|
6205
|
+
parsed = parseSource(source);
|
|
6206
|
+
} catch (err) {
|
|
6207
|
+
return err instanceof Error ? err.message : String(err);
|
|
6208
|
+
}
|
|
6209
|
+
const { package: pkg, path: rel } = parsed;
|
|
6210
|
+
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6211
|
+
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6212
|
+
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6213
|
+
const base = rel.split("/").pop();
|
|
6214
|
+
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6215
|
+
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6216
|
+
}
|
|
6217
|
+
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6218
|
+
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6219
|
+
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6220
|
+
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6221
|
+
return `${key2} doesn't match its source ${source}`;
|
|
6222
|
+
}
|
|
6223
|
+
|
|
6224
|
+
// src/blocks/templates.ts
|
|
6225
|
+
function starterDir() {
|
|
6226
|
+
const workspace = workspacePackagesDir();
|
|
6227
|
+
const live = workspace && path20.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
6228
|
+
if (live && existsSync(path20.join(live, "package.json"))) return live;
|
|
6229
|
+
const packaged = path20.join(cliPackageDir(), "dist", "starter");
|
|
6230
|
+
if (existsSync(path20.join(packaged, "package.json"))) return packaged;
|
|
6231
|
+
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
6232
|
+
}
|
|
6233
|
+
|
|
6234
|
+
// src/blocks/starter-features.ts
|
|
6235
|
+
var STARTER_CONFIG = "starter.config.ts";
|
|
6236
|
+
var GENESIS_CONFIG = "genesis.config.json";
|
|
6237
|
+
var SWITCH = /^[a-zA-Z][a-zA-Z0-9]*$/;
|
|
6238
|
+
var BLOCK_ID2 = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
6239
|
+
function featuresBody(text) {
|
|
6240
|
+
const m = /\bfeatures:\s*\{/.exec(text);
|
|
6241
|
+
if (!m) return null;
|
|
6242
|
+
const start = m.index + m[0].length;
|
|
6243
|
+
let depth = 1;
|
|
6244
|
+
for (let i = start; i < text.length; i++) {
|
|
6245
|
+
const c = text[i];
|
|
6246
|
+
if (c === "/" && text[i + 1] === "/") {
|
|
6247
|
+
const nl = text.indexOf("\n", i);
|
|
6248
|
+
if (nl < 0) return null;
|
|
6249
|
+
i = nl;
|
|
6250
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
6251
|
+
const close = text.indexOf("*/", i + 2);
|
|
6252
|
+
if (close < 0) return null;
|
|
6253
|
+
i = close + 1;
|
|
6254
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
6255
|
+
let j = i + 1;
|
|
6256
|
+
while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
|
|
6257
|
+
i = j;
|
|
6258
|
+
} else if (c === "{") depth++;
|
|
6259
|
+
else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
|
|
6260
|
+
}
|
|
6261
|
+
return null;
|
|
6262
|
+
}
|
|
6263
|
+
function parseStarterFeatures(text) {
|
|
6264
|
+
const found = featuresBody(text);
|
|
6265
|
+
if (!found) return null;
|
|
6266
|
+
const out = {};
|
|
6267
|
+
for (const line of found.body.split("\n")) {
|
|
6268
|
+
const m = /^\s*([a-zA-Z][a-zA-Z0-9]*)\s*:\s*(true|false)\s*,?\s*(?:\/\/.*)?$/.exec(line);
|
|
6269
|
+
if (m) out[m[1]] = m[2] === "true";
|
|
6270
|
+
}
|
|
6271
|
+
return out;
|
|
6272
|
+
}
|
|
6273
|
+
function parseStarterBlocks(json, source = GENESIS_CONFIG) {
|
|
6274
|
+
let raw;
|
|
6275
|
+
try {
|
|
6276
|
+
raw = JSON.parse(json);
|
|
6277
|
+
} catch (err) {
|
|
6278
|
+
throw new Error(`${source} is not valid JSON: ${err.message}`);
|
|
6279
|
+
}
|
|
6280
|
+
const starter = raw?.starter;
|
|
6281
|
+
if (starter === void 0) return null;
|
|
6282
|
+
const blocks = starter?.blocks;
|
|
6283
|
+
if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
|
|
6284
|
+
if (typeof blocks !== "object" || blocks === null || Array.isArray(blocks)) throw new Error(`${source}: starter.blocks must map each feature switch to a list of block ids`);
|
|
6285
|
+
const out = {};
|
|
6286
|
+
for (const [name, ids] of Object.entries(blocks)) {
|
|
6287
|
+
if (name === "$comment") continue;
|
|
6288
|
+
if (!SWITCH.test(name) || !Array.isArray(ids) || !ids.every((id) => typeof id === "string" && BLOCK_ID2.test(id))) {
|
|
6289
|
+
throw new Error(`${source}: starter.blocks.${name} must be a list of block ids`);
|
|
6290
|
+
}
|
|
6291
|
+
out[name] = ids;
|
|
6292
|
+
}
|
|
6293
|
+
return out;
|
|
6294
|
+
}
|
|
6295
|
+
function readText(file) {
|
|
6296
|
+
try {
|
|
6297
|
+
return readFileSync(file, "utf8");
|
|
6298
|
+
} catch {
|
|
6299
|
+
return null;
|
|
6300
|
+
}
|
|
6301
|
+
}
|
|
6302
|
+
function starterBlockMap(root) {
|
|
6303
|
+
if (root) {
|
|
6304
|
+
const file = path20.join(root, GENESIS_CONFIG);
|
|
6305
|
+
const text2 = readText(file);
|
|
6306
|
+
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
6307
|
+
if (own) return own;
|
|
6308
|
+
}
|
|
6309
|
+
let dir;
|
|
6310
|
+
try {
|
|
6311
|
+
dir = starterDir();
|
|
6312
|
+
} catch {
|
|
6313
|
+
return {};
|
|
6314
|
+
}
|
|
6315
|
+
const text = readText(path20.join(dir, GENESIS_CONFIG));
|
|
6316
|
+
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
6317
|
+
}
|
|
6318
|
+
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
6319
|
+
const ids = new Set(present);
|
|
6320
|
+
const off = /* @__PURE__ */ new Map();
|
|
6321
|
+
for (const [name, carried] of Object.entries(map)) if (switches[name] === false) {
|
|
6322
|
+
for (const id of carried) if (ids.has(id)) off.set(id, name);
|
|
6323
|
+
}
|
|
6324
|
+
const requires = new Map(manifests.map((m) => [m.id, m.requires]));
|
|
6325
|
+
const keep = [...ids].filter((id) => !off.has(id));
|
|
6326
|
+
for (let i = 0; i < keep.length; i++) {
|
|
6327
|
+
for (const r of requires.get(keep[i]) ?? []) {
|
|
6328
|
+
off.delete(r);
|
|
6329
|
+
if (!keep.includes(r)) keep.push(r);
|
|
6330
|
+
}
|
|
6331
|
+
}
|
|
6332
|
+
return off;
|
|
6333
|
+
}
|
|
6334
|
+
function appBlocksSwitchedOff(root, manifests, present) {
|
|
6335
|
+
const text = readText(path20.join(root, STARTER_CONFIG));
|
|
6336
|
+
const switches = text === null ? null : parseStarterFeatures(text);
|
|
6337
|
+
if (!switches) return /* @__PURE__ */ new Map();
|
|
6338
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path20.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
6339
|
+
}
|
|
6340
|
+
function blockOfSource(source, manifests) {
|
|
6341
|
+
const at = source.indexOf(":");
|
|
6342
|
+
if (at < 1) return null;
|
|
6343
|
+
const pkg = source.slice(0, at);
|
|
6344
|
+
const rel = source.slice(at + 1);
|
|
6345
|
+
for (const m of manifests) {
|
|
6346
|
+
if (m.functions.some((fn) => fn.package === pkg && rel.startsWith(`${fn.dir}/`))) return m.id;
|
|
6347
|
+
if (m.migrations.some((mig) => mig.package === pkg && mig.test === rel)) return m.id;
|
|
6348
|
+
}
|
|
6349
|
+
return null;
|
|
6350
|
+
}
|
|
6351
|
+
|
|
6352
|
+
// src/doctor/lock-files.ts
|
|
6353
|
+
async function checkLockFiles(ctx) {
|
|
6354
|
+
if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
|
|
6355
|
+
let lock;
|
|
6356
|
+
try {
|
|
6357
|
+
lock = readLock(ctx.root);
|
|
6358
|
+
} catch (err) {
|
|
6359
|
+
ctx.report({ rule: "lock-files", level: "warn", file: LOCK_FILE, message: `can't be read (${err instanceof Error ? err.message : String(err)}); genesis upgrade and migrate can't either` });
|
|
6360
|
+
return;
|
|
6361
|
+
}
|
|
6362
|
+
const catalog = catalogBlocks();
|
|
6363
|
+
const off = appBlocksSwitchedOff(ctx.root, catalog, Object.keys(lock.blocks));
|
|
6364
|
+
const offManifests = [];
|
|
6365
|
+
for (const [id, entry] of Object.entries(lock.blocks)) {
|
|
6366
|
+
const feature = off.get(id);
|
|
6367
|
+
if (!feature) continue;
|
|
6368
|
+
try {
|
|
6369
|
+
offManifests.push((await findBlock(ctx.root, id, { package: entry.package })).manifest);
|
|
6370
|
+
} catch {
|
|
6371
|
+
offManifests.push(...catalog.filter((m) => m.id === id));
|
|
6372
|
+
}
|
|
6373
|
+
ctx.report({
|
|
6374
|
+
rule: "lock-files",
|
|
6375
|
+
level: "info",
|
|
6376
|
+
file: LOCK_FILE,
|
|
6377
|
+
subject: id,
|
|
6378
|
+
message: `lists the ${id} block, but features.${feature} is off in ${STARTER_CONFIG}: genesis upgrade and migrate leave it out (delete its entry if it's gone for good)`
|
|
6379
|
+
});
|
|
6380
|
+
}
|
|
6381
|
+
const local = localPackageNames(ctx.root);
|
|
6382
|
+
let home = null;
|
|
6383
|
+
try {
|
|
6384
|
+
home = databaseElsewhere(ctx.root);
|
|
6385
|
+
} catch {
|
|
6386
|
+
}
|
|
6387
|
+
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
6388
|
+
if (home && elsewhere.length) {
|
|
6389
|
+
ctx.report({
|
|
6390
|
+
rule: "lock-files",
|
|
6391
|
+
level: "info",
|
|
6392
|
+
file: LOCK_FILE,
|
|
6393
|
+
subject: "supabase/",
|
|
6394
|
+
message: `lists ${elsewhere.length} file${elsewhere.length === 1 ? "" : "s"} under supabase/, but this app's database files live ${home.app ? `in ${home.app}` : "nowhere"} (genesis.config.json supabase): genesis upgrade leaves them alone, so delete those entries`
|
|
6395
|
+
});
|
|
6396
|
+
}
|
|
6397
|
+
for (const [rel, entry] of Object.entries(lock.files)) {
|
|
6398
|
+
if (home && isSupabasePath(rel)) continue;
|
|
6399
|
+
if (ownedKeyProblem(rel, entry.source, local)) continue;
|
|
6400
|
+
if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
|
|
6401
|
+
let file;
|
|
6402
|
+
try {
|
|
6403
|
+
file = appPath2(ctx.root, rel);
|
|
6404
|
+
} catch {
|
|
6405
|
+
continue;
|
|
6406
|
+
}
|
|
6407
|
+
let text;
|
|
6408
|
+
try {
|
|
6409
|
+
text = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6410
|
+
} catch (err) {
|
|
6411
|
+
ctx.report({
|
|
6412
|
+
rule: "lock-files",
|
|
6413
|
+
level: "warn",
|
|
6414
|
+
file: rel,
|
|
6415
|
+
subject: rel,
|
|
6416
|
+
message: `is in ${LOCK_FILE} (from ${entry.source}) but can't be read (${err instanceof Error ? err.message : String(err)}), so genesis upgrade can't refresh it. Make it a file again, or remove its entry from ${LOCK_FILE}`
|
|
6417
|
+
});
|
|
6418
|
+
continue;
|
|
6419
|
+
}
|
|
6420
|
+
if (text === null) {
|
|
6421
|
+
if (entry.deleted) continue;
|
|
6422
|
+
ctx.report({
|
|
6423
|
+
rule: "lock-files",
|
|
6424
|
+
level: "warn",
|
|
6425
|
+
file: rel,
|
|
6426
|
+
subject: rel,
|
|
6427
|
+
message: `is in ${LOCK_FILE} (from ${entry.source}) but not on disk, and genesis upgrade won't bring it back. Deleted on purpose: add "deleted": true to its entry in ${LOCK_FILE}. Otherwise restore it (git checkout, or copy it from ${entry.source})`
|
|
6428
|
+
});
|
|
6429
|
+
continue;
|
|
6430
|
+
}
|
|
6431
|
+
if (entry.deleted) {
|
|
6432
|
+
ctx.report({ rule: "lock-files", level: "info", file: rel, subject: rel, message: `is marked "deleted": true in ${LOCK_FILE} but is on disk; remove the marker` });
|
|
6433
|
+
}
|
|
6434
|
+
if (sha256(text) === entry.sha256) continue;
|
|
6435
|
+
ctx.report({
|
|
6436
|
+
rule: "lock-files",
|
|
6437
|
+
level: "info",
|
|
6438
|
+
file: rel,
|
|
6439
|
+
subject: rel,
|
|
6440
|
+
message: entry.pending ? `differs from ${LOCK_FILE}: the last upgrade's version is waiting in ${rel}.genesis-next; resolve it into this file and delete it` : `differs from ${LOCK_FILE} (edited in the app); genesis upgrade three-way merges the next version into your edits`
|
|
6441
|
+
});
|
|
6442
|
+
}
|
|
6443
|
+
}
|
|
6444
|
+
function checkDatabaseHome(ctx) {
|
|
6445
|
+
const home = databaseElsewhere(ctx.root);
|
|
6446
|
+
if (!home) return;
|
|
6447
|
+
if (home.app && !home.hasSupabase) {
|
|
6448
|
+
ctx.report({
|
|
6449
|
+
rule: "database-elsewhere",
|
|
6450
|
+
level: "warn",
|
|
6451
|
+
file: "genesis.config.json",
|
|
6452
|
+
subject: home.app,
|
|
6453
|
+
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)`
|
|
6454
|
+
});
|
|
6455
|
+
}
|
|
6456
|
+
if (existsSync(path20.join(ctx.root, "supabase"))) {
|
|
6457
|
+
ctx.report({
|
|
6458
|
+
rule: "database-elsewhere",
|
|
6459
|
+
level: "warn",
|
|
6460
|
+
file: "supabase",
|
|
6461
|
+
subject: "supabase/",
|
|
6462
|
+
message: `is here, but genesis.config.json says this app's database files live ${home.app ? `in ${home.app}/supabase` : "nowhere"}: genesis add, migrate and upgrade never plan it, so it is a second, unused copy. Delete it`
|
|
6463
|
+
});
|
|
6464
|
+
}
|
|
6465
|
+
}
|
|
5885
6466
|
var RATCHETED_BY_DEFAULT = ["deprecated-import"];
|
|
5886
6467
|
async function runDoctor(options = {}) {
|
|
5887
|
-
const root =
|
|
6468
|
+
const root = path20.resolve(options.root ?? process.cwd());
|
|
5888
6469
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
5889
6470
|
const config = loaded.config;
|
|
5890
6471
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -5938,7 +6519,7 @@ async function runDoctor(options = {}) {
|
|
|
5938
6519
|
}
|
|
5939
6520
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
5940
6521
|
if (options.base && changed) {
|
|
5941
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
6522
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path20.join(root, f)) });
|
|
5942
6523
|
}
|
|
5943
6524
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
5944
6525
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -5983,6 +6564,8 @@ function builtinChecks(config, options = {}) {
|
|
|
5983
6564
|
{ name: "stability-imports", check: checkStabilityImports },
|
|
5984
6565
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
5985
6566
|
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
6567
|
+
{ name: "lock-files", check: checkLockFiles },
|
|
6568
|
+
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
5986
6569
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
5987
6570
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
5988
6571
|
];
|