@marktiderman/genesis-cli 1.16.2 → 1.17.1
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 +161 -8
- package/dist/cli.js +1628 -686
- package/dist/cli.js.map +1 -1
- package/dist/{config-DewJ3DR6.d.ts → config-1jP8eCZy.d.ts} +7 -0
- package/dist/doctor.d.ts +5 -4
- package/dist/doctor.js +577 -215
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +3 -2
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +131 -31
- package/dist/index.d.ts +10 -3
- package/dist/index.js +581 -219
- package/dist/index.js.map +1 -1
- package/dist/starter/__tests__/starter.test.ts +5 -1
- package/dist/starter/src/lib/native-modules.ts +5 -1
- package/dist/starter/tailwind.config.mjs +3 -1
- package/dist/vite.js +577 -215
- package/dist/vite.js.map +1 -1
- package/package.json +9 -5
package/dist/vite.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as path19 from 'path';
|
|
2
2
|
import { spawnSync } from 'child_process';
|
|
3
3
|
import { existsSync, readFileSync, statSync, realpathSync, readdirSync, lstatSync } from 'fs';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
5
|
import 'crypto';
|
|
6
6
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
7
7
|
import { pathToFileURL } from 'url';
|
|
8
|
+
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
8
9
|
import 'jiti';
|
|
9
10
|
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
@@ -210,6 +211,16 @@ function parse(comment, keys, where2) {
|
|
|
210
211
|
if (!kind) {
|
|
211
212
|
throw new CommentSettingsError(`${where2}: unknown ${MARKER} setting "${key2}". Allowed: ${Object.keys(keys).join(", ")}.`);
|
|
212
213
|
}
|
|
214
|
+
if (kind === "key") {
|
|
215
|
+
const list = typeof v === "string" ? [v] : v;
|
|
216
|
+
if (!Array.isArray(list) || list.length === 0 || !list.every((c) => typeof c === "string" && c !== "")) {
|
|
217
|
+
throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" must be a column name or a list of them.`);
|
|
218
|
+
}
|
|
219
|
+
const twice = list.find((c, i) => list.indexOf(c) !== i);
|
|
220
|
+
if (twice) throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" names "${twice}" twice.`);
|
|
221
|
+
settings[key2] = list;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
213
224
|
if (typeof v !== kind) throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" must be a ${kind}.`);
|
|
214
225
|
settings[key2] = v;
|
|
215
226
|
}
|
|
@@ -224,11 +235,22 @@ function parseTableComment(comment, table) {
|
|
|
224
235
|
function parseColumnComment(comment, column) {
|
|
225
236
|
return parse(comment, FIELD_KEYS, column);
|
|
226
237
|
}
|
|
238
|
+
function withKeySetting(table, warn) {
|
|
239
|
+
const key2 = table.settings?.key;
|
|
240
|
+
if (!key2) return table;
|
|
241
|
+
const columns = new Set(table.columns.map((c) => c.name));
|
|
242
|
+
const missing = key2.filter((k) => !columns.has(k));
|
|
243
|
+
if (missing.length) throw new CommentSettingsError(`${table.name}: ${MARKER} key "${missing.join('", "')}" isn't one of its columns.`);
|
|
244
|
+
if (table.key.length && table.key.join("\0") !== key2.join("\0")) {
|
|
245
|
+
warn?.(`${table.name}: ${MARKER} key (${key2.join(", ")}) differs from its primary key (${table.key.join(", ")}); the comment's key is used.`);
|
|
246
|
+
}
|
|
247
|
+
return { ...table, key: [...key2] };
|
|
248
|
+
}
|
|
227
249
|
var MARKER, TABLE_KEYS, FIELD_KEYS, CommentSettingsError;
|
|
228
250
|
var init_comments = __esm({
|
|
229
251
|
"src/introspect/comments.ts"() {
|
|
230
252
|
MARKER = "@genesis";
|
|
231
|
-
TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string" };
|
|
253
|
+
TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string", key: "key" };
|
|
232
254
|
FIELD_KEYS = { label: "string", description: "string", widget: "string", readonly: "boolean", sensitive: "boolean" };
|
|
233
255
|
CommentSettingsError = class extends Error {
|
|
234
256
|
};
|
|
@@ -259,6 +281,12 @@ var init_model = __esm({
|
|
|
259
281
|
function where(sql, scope) {
|
|
260
282
|
return "schemas" in scope ? sql`n.nspname = any(${scope.schemas})` : sql`c.oid = any(${scope.oids}::oid[])`;
|
|
261
283
|
}
|
|
284
|
+
function linkOf(columns, refColumns, refUnique = []) {
|
|
285
|
+
if (columns.length === 1) return 0;
|
|
286
|
+
if (columns.length !== refColumns.length) return -1;
|
|
287
|
+
const own = columns.flatMap((c, i) => c === refColumns[i] ? [] : [i]);
|
|
288
|
+
return own.length === 1 && refUnique[own[0]] === true ? own[0] : -1;
|
|
289
|
+
}
|
|
262
290
|
async function readRelations(sql, scope, into) {
|
|
263
291
|
const columns = await sql`
|
|
264
292
|
select c.oid::text as oid, c.relkind::text as relkind, n.nspname as schema, c.relname as table,
|
|
@@ -290,16 +318,24 @@ async function readRelations(sql, scope, into) {
|
|
|
290
318
|
where con.contype = 'p' and ${where(sql, scope)}
|
|
291
319
|
group by c.oid`;
|
|
292
320
|
const links = await sql`
|
|
293
|
-
select c.oid::text as oid, con.conkey[
|
|
294
|
-
|
|
321
|
+
select c.oid::text as oid, con.conkey::int[] as attnums,
|
|
322
|
+
array(select a.attname::text from unnest(con.conkey) with ordinality k(attnum, ord)
|
|
323
|
+
join pg_attribute a on a.attrelid = c.oid and a.attnum = k.attnum order by k.ord) as columns,
|
|
324
|
+
array(select ra.attname::text from unnest(con.confkey) with ordinality k(attnum, ord)
|
|
325
|
+
join pg_attribute ra on ra.attrelid = con.confrelid and ra.attnum = k.attnum order by k.ord) as ref_columns,
|
|
326
|
+
array(select exists (select 1 from pg_index i
|
|
327
|
+
where i.indrelid = con.confrelid and i.indisunique and i.indpred is null
|
|
328
|
+
and i.indnkeyatts = 1 and i.indkey[0] = k.attnum)
|
|
329
|
+
from unnest(con.confkey) with ordinality k(attnum, ord) order by k.ord) as ref_unique,
|
|
330
|
+
rn.nspname as ref_schema, rc.relname as ref_table
|
|
295
331
|
from pg_constraint con
|
|
296
332
|
join pg_class c on c.oid = con.conrelid
|
|
297
333
|
join pg_namespace n on n.oid = c.relnamespace
|
|
298
334
|
join pg_class rc on rc.oid = con.confrelid
|
|
299
335
|
join pg_namespace rn on rn.oid = rc.relnamespace
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
336
|
+
where con.contype = 'f'
|
|
337
|
+
and ${where(sql, scope)}
|
|
338
|
+
order by con.conname`;
|
|
303
339
|
const checks = await sql`
|
|
304
340
|
select c.oid::text as oid, con.conkey[1]::int as attnum, a.attname as column,
|
|
305
341
|
pg_get_constraintdef(con.oid) as definition
|
|
@@ -364,9 +400,12 @@ async function readRelations(sql, scope, into) {
|
|
|
364
400
|
const relation = into.get(k.oid);
|
|
365
401
|
if (relation) relation.key = k.columns;
|
|
366
402
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
403
|
+
const ordered = [...links].sort((a, b) => a.attnums.length - b.attnums.length);
|
|
404
|
+
for (const l of ordered) {
|
|
405
|
+
const at = linkOf(l.columns, l.ref_columns, l.ref_unique);
|
|
406
|
+
if (at < 0) continue;
|
|
407
|
+
const column = into.get(l.oid)?.columns.get(l.attnums[at]);
|
|
408
|
+
if (column && !column.references) column.references = { resource: qualifiedName(l.ref_schema, l.ref_table), field: l.ref_columns[at] };
|
|
370
409
|
}
|
|
371
410
|
const listed = /* @__PURE__ */ new Map();
|
|
372
411
|
for (const check of checks) {
|
|
@@ -415,14 +454,14 @@ function inherit(own, source) {
|
|
|
415
454
|
}
|
|
416
455
|
function resolveViews(relations) {
|
|
417
456
|
const done = /* @__PURE__ */ new Set();
|
|
418
|
-
const
|
|
457
|
+
const resolve17 = (relation, depth) => {
|
|
419
458
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
420
459
|
done.add(relation.oid);
|
|
421
460
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
422
461
|
if (sources.size !== 1) return;
|
|
423
462
|
const source = relations.get([...sources][0]);
|
|
424
463
|
if (!source) return;
|
|
425
|
-
|
|
464
|
+
resolve17(source, depth + 1);
|
|
426
465
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
427
466
|
for (const [attnum, origin] of relation.origins) {
|
|
428
467
|
const own = relation.columns.get(attnum);
|
|
@@ -445,9 +484,9 @@ function resolveViews(relations) {
|
|
|
445
484
|
};
|
|
446
485
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
447
486
|
};
|
|
448
|
-
for (const relation of relations.values())
|
|
487
|
+
for (const relation of relations.values()) resolve17(relation, 0);
|
|
449
488
|
}
|
|
450
|
-
async function introspectPostgres(sql, schemas) {
|
|
489
|
+
async function introspectPostgres(sql, schemas, options = {}) {
|
|
451
490
|
const relations = /* @__PURE__ */ new Map();
|
|
452
491
|
const wanted = await readRelations(sql, { schemas: [...schemas] }, relations);
|
|
453
492
|
for (let depth = 0; depth < MAX_VIEW_DEPTH; depth++) {
|
|
@@ -464,7 +503,7 @@ async function introspectPostgres(sql, schemas) {
|
|
|
464
503
|
resolveViews(relations);
|
|
465
504
|
return wanted.map((oid) => {
|
|
466
505
|
const relation = relations.get(oid);
|
|
467
|
-
return { ...relation.table, key: relation.key.map((attnum) => relation.columns.get(attnum).name) };
|
|
506
|
+
return withKeySetting({ ...relation.table, key: relation.key.map((attnum) => relation.columns.get(attnum).name) }, options.warn);
|
|
468
507
|
});
|
|
469
508
|
}
|
|
470
509
|
var MAX_VIEW_DEPTH;
|
|
@@ -482,7 +521,7 @@ function clean(description) {
|
|
|
482
521
|
if (!description) return void 0;
|
|
483
522
|
return description.replace(NOTES, "").trim() || void 0;
|
|
484
523
|
}
|
|
485
|
-
function introspectOpenApi(doc, schema = "public") {
|
|
524
|
+
function introspectOpenApi(doc, schema = "public", options = {}) {
|
|
486
525
|
const definitions = doc.definitions ?? doc.components?.schemas;
|
|
487
526
|
if (!definitions) throw new Error("This OpenAPI document has no definitions. Is it a PostgREST (Supabase /rest/v1/) spec?");
|
|
488
527
|
return Object.keys(definitions).sort().map((tableName) => {
|
|
@@ -514,7 +553,7 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
514
553
|
};
|
|
515
554
|
});
|
|
516
555
|
const comment = parseTableComment(def.description, name);
|
|
517
|
-
return {
|
|
556
|
+
return withKeySetting({
|
|
518
557
|
name,
|
|
519
558
|
schema,
|
|
520
559
|
table: tableName,
|
|
@@ -522,7 +561,7 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
522
561
|
columns,
|
|
523
562
|
...comment.description ? { description: comment.description } : {},
|
|
524
563
|
...comment.settings ? { settings: comment.settings } : {}
|
|
525
|
-
};
|
|
564
|
+
}, options.warn);
|
|
526
565
|
});
|
|
527
566
|
}
|
|
528
567
|
var PK, FK, NOTES;
|
|
@@ -681,19 +720,19 @@ var init_introspect = __esm({
|
|
|
681
720
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
682
721
|
function buildCommands(root, config) {
|
|
683
722
|
if (config.build) return config.build;
|
|
684
|
-
const pkgFile =
|
|
723
|
+
const pkgFile = path19.join(root, "package.json");
|
|
685
724
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
686
725
|
const pm = packageManager(root);
|
|
687
726
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
688
727
|
}
|
|
689
728
|
function packageManager(root) {
|
|
690
|
-
let dir =
|
|
729
|
+
let dir = path19.resolve(root);
|
|
691
730
|
for (; ; ) {
|
|
692
|
-
if (existsSync(
|
|
693
|
-
if (existsSync(
|
|
694
|
-
if (existsSync(
|
|
695
|
-
if (existsSync(
|
|
696
|
-
const parent =
|
|
731
|
+
if (existsSync(path19.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
732
|
+
if (existsSync(path19.join(dir, "bun.lock")) || existsSync(path19.join(dir, "bun.lockb"))) return "bun";
|
|
733
|
+
if (existsSync(path19.join(dir, "yarn.lock"))) return "yarn";
|
|
734
|
+
if (existsSync(path19.join(dir, "package-lock.json"))) return "npm";
|
|
735
|
+
const parent = path19.dirname(dir);
|
|
697
736
|
if (parent === dir) return "npm";
|
|
698
737
|
dir = parent;
|
|
699
738
|
}
|
|
@@ -808,25 +847,25 @@ var PACK_KEYS = {
|
|
|
808
847
|
};
|
|
809
848
|
function appPath(v, where2, fail) {
|
|
810
849
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
811
|
-
if (
|
|
812
|
-
const norm =
|
|
850
|
+
if (path19.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
851
|
+
const norm = path19.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
813
852
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
814
853
|
return norm;
|
|
815
854
|
}
|
|
816
855
|
function loadConfig(root, configPath) {
|
|
817
856
|
if (configPath) {
|
|
818
|
-
const file =
|
|
857
|
+
const file = path19.resolve(root, configPath);
|
|
819
858
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
820
859
|
const json = readJson(file);
|
|
821
|
-
const block =
|
|
822
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
860
|
+
const block = path19.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
861
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path19.dirname(file) };
|
|
823
862
|
}
|
|
824
|
-
const own =
|
|
863
|
+
const own = path19.join(root, "genesis.config.json");
|
|
825
864
|
if (existsSync(own)) {
|
|
826
865
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
827
866
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
828
867
|
}
|
|
829
|
-
const pkg =
|
|
868
|
+
const pkg = path19.join(root, "package.json");
|
|
830
869
|
if (existsSync(pkg)) {
|
|
831
870
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
832
871
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -835,14 +874,14 @@ function loadConfig(root, configPath) {
|
|
|
835
874
|
}
|
|
836
875
|
function doctorBlock(json, file, explicit) {
|
|
837
876
|
const j = json;
|
|
838
|
-
if (
|
|
877
|
+
if (path19.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
839
878
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
840
879
|
}
|
|
841
880
|
function isPackageDeclaration(block) {
|
|
842
881
|
if (typeof block === "string") return true;
|
|
843
882
|
if (!isObject(block)) return false;
|
|
844
883
|
const keys = Object.keys(block).filter((k) => k !== "$comment");
|
|
845
|
-
return keys.some((k) => ["prefer", "primitives", "plugin", "enforce"].includes(k)) && !keys.some((k) => KNOWN.has(k));
|
|
884
|
+
return keys.some((k) => ["prefer", "catalog", "primitives", "plugin", "enforce"].includes(k)) && !keys.some((k) => KNOWN.has(k));
|
|
846
885
|
}
|
|
847
886
|
function readJson(file) {
|
|
848
887
|
try {
|
|
@@ -852,7 +891,7 @@ function readJson(file) {
|
|
|
852
891
|
}
|
|
853
892
|
}
|
|
854
893
|
function readGenesisConfig(root) {
|
|
855
|
-
const file =
|
|
894
|
+
const file = path19.join(root, "genesis.config.json");
|
|
856
895
|
if (!existsSync(file)) return null;
|
|
857
896
|
const raw = readJson(file);
|
|
858
897
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -1017,7 +1056,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1017
1056
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1018
1057
|
if (contracts.out !== void 0) {
|
|
1019
1058
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1020
|
-
if (
|
|
1059
|
+
if (path19.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1021
1060
|
}
|
|
1022
1061
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1023
1062
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1085,7 +1124,7 @@ function globToRegExp(glob) {
|
|
|
1085
1124
|
}
|
|
1086
1125
|
function globMatcher(globs) {
|
|
1087
1126
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1088
|
-
return (
|
|
1127
|
+
return (path31) => res.some((re) => re.test(path31));
|
|
1089
1128
|
}
|
|
1090
1129
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1091
1130
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
@@ -1125,11 +1164,11 @@ var TAILWIND_PALETTE = [
|
|
|
1125
1164
|
"olive"
|
|
1126
1165
|
];
|
|
1127
1166
|
function findPackageDir(from, name) {
|
|
1128
|
-
let dir =
|
|
1167
|
+
let dir = path19.resolve(from);
|
|
1129
1168
|
for (; ; ) {
|
|
1130
|
-
const candidate =
|
|
1131
|
-
if (existsSync(
|
|
1132
|
-
const parent =
|
|
1169
|
+
const candidate = path19.join(dir, "node_modules", name);
|
|
1170
|
+
if (existsSync(path19.join(candidate, "package.json"))) return candidate;
|
|
1171
|
+
const parent = path19.dirname(dir);
|
|
1133
1172
|
if (parent === dir) return null;
|
|
1134
1173
|
dir = parent;
|
|
1135
1174
|
}
|
|
@@ -1181,37 +1220,50 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1181
1220
|
function readPackageExports(root, uiPackage) {
|
|
1182
1221
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1183
1222
|
if (!uiDir) return null;
|
|
1184
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1223
|
+
const uiPkg = JSON.parse(readFileSync(path19.join(uiDir, "package.json"), "utf8"));
|
|
1224
|
+
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
1225
|
+
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1226
|
+
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
1227
|
+
const entryOf = fromSource ? exportSource : exportTypes;
|
|
1185
1228
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
1186
|
-
const mainTypes =
|
|
1229
|
+
const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
|
|
1187
1230
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
1188
|
-
for (const target of
|
|
1189
|
-
const t =
|
|
1231
|
+
for (const target of subpaths) {
|
|
1232
|
+
const t = entryOf(target);
|
|
1190
1233
|
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
1191
1234
|
}
|
|
1192
1235
|
const exportNames = /* @__PURE__ */ new Set();
|
|
1193
1236
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1194
1237
|
let readAny = false;
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
if (!existsSync(file))
|
|
1238
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1239
|
+
const readEntry = (file) => {
|
|
1240
|
+
if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
|
|
1241
|
+
seen.add(file);
|
|
1198
1242
|
readAny = true;
|
|
1199
|
-
const
|
|
1200
|
-
for (const name of parseExportNames(
|
|
1201
|
-
for (const m of
|
|
1243
|
+
const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
|
|
1244
|
+
for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
|
|
1245
|
+
for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
1202
1246
|
reexportedPackages.add(packageName(m[1]));
|
|
1203
1247
|
}
|
|
1204
|
-
|
|
1248
|
+
if (fromSource) {
|
|
1249
|
+
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
1250
|
+
const next = resolveSource(path19.dirname(file), m[1]);
|
|
1251
|
+
if (next) readEntry(next);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
for (const entry of typeEntries) readEntry(path19.join(uiDir, entry));
|
|
1205
1256
|
if (!readAny) {
|
|
1206
|
-
|
|
1257
|
+
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
1258
|
+
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1207
1259
|
}
|
|
1208
1260
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1209
1261
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1210
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1211
|
-
const declFiles = walkDts(declRoot);
|
|
1262
|
+
const declRoot = typeof mainTypes === "string" ? path19.dirname(path19.join(uiDir, mainTypes)) : uiDir;
|
|
1263
|
+
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
1212
1264
|
for (const pkg of reexportedPackages) {
|
|
1213
1265
|
const dir = findPackageDir(uiDir, pkg);
|
|
1214
|
-
if (dir) walkDts(
|
|
1266
|
+
if (dir) walkDts(path19.join(dir, "dist"), declFiles);
|
|
1215
1267
|
}
|
|
1216
1268
|
for (const file of declFiles) {
|
|
1217
1269
|
const text = readFileSync(file, "utf8");
|
|
@@ -1243,6 +1295,72 @@ function packageName(specifier) {
|
|
|
1243
1295
|
const parts = specifier.split("/");
|
|
1244
1296
|
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1245
1297
|
}
|
|
1298
|
+
function parseSourceExportNames(code) {
|
|
1299
|
+
const names = parseExportNames(code);
|
|
1300
|
+
for (const m of code.matchAll(/export\s+(?:default\s+)?(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:var|class|function\*?)\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
1301
|
+
for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
1302
|
+
return [...new Set(names)];
|
|
1303
|
+
}
|
|
1304
|
+
var TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
1305
|
+
var isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
|
|
1306
|
+
function exportSource(target) {
|
|
1307
|
+
if (isTsSource(target)) return target;
|
|
1308
|
+
if (!target || typeof target !== "object") return void 0;
|
|
1309
|
+
for (const value of Object.values(target)) {
|
|
1310
|
+
const nested = exportSource(value);
|
|
1311
|
+
if (nested) return nested;
|
|
1312
|
+
}
|
|
1313
|
+
return void 0;
|
|
1314
|
+
}
|
|
1315
|
+
function resolveSource(dir, spec) {
|
|
1316
|
+
const base = path19.resolve(dir, spec.replace(/\.js$/, ""));
|
|
1317
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path19.join(base, i))];
|
|
1318
|
+
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
1319
|
+
}
|
|
1320
|
+
function insidePackage(dir, file) {
|
|
1321
|
+
const rel = path19.relative(path19.resolve(dir), path19.resolve(file));
|
|
1322
|
+
return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
|
|
1323
|
+
}
|
|
1324
|
+
function stripComments(code) {
|
|
1325
|
+
let out = "";
|
|
1326
|
+
let i = 0;
|
|
1327
|
+
while (i < code.length) {
|
|
1328
|
+
const c = code[i];
|
|
1329
|
+
const next = code[i + 1];
|
|
1330
|
+
if (c === "/" && next === "*") {
|
|
1331
|
+
const end = code.indexOf("*/", i + 2);
|
|
1332
|
+
const stop = end < 0 ? code.length : end + 2;
|
|
1333
|
+
out += code.slice(i, stop).replace(/[^\n]/g, " ");
|
|
1334
|
+
i = stop;
|
|
1335
|
+
} else if (c === "/" && next === "/") {
|
|
1336
|
+
const end = code.indexOf("\n", i);
|
|
1337
|
+
i = end < 0 ? code.length : end;
|
|
1338
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
1339
|
+
let j = i + 1;
|
|
1340
|
+
while (j < code.length && code[j] !== c) {
|
|
1341
|
+
if (code[j] === "\\") j++;
|
|
1342
|
+
else if (c !== "`" && code[j] === "\n") break;
|
|
1343
|
+
j++;
|
|
1344
|
+
}
|
|
1345
|
+
out += code.slice(i, j + 1);
|
|
1346
|
+
i = j + 1;
|
|
1347
|
+
} else {
|
|
1348
|
+
out += c;
|
|
1349
|
+
i++;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return out;
|
|
1353
|
+
}
|
|
1354
|
+
function walkSource(dir, out = []) {
|
|
1355
|
+
if (!existsSync(dir)) return out;
|
|
1356
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1357
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
1358
|
+
const p = path19.join(dir, entry.name);
|
|
1359
|
+
if (entry.isDirectory()) walkSource(p, out);
|
|
1360
|
+
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1361
|
+
}
|
|
1362
|
+
return out;
|
|
1363
|
+
}
|
|
1246
1364
|
function exportTypes(target) {
|
|
1247
1365
|
if (!target || typeof target !== "object") return void 0;
|
|
1248
1366
|
const t = target;
|
|
@@ -1257,7 +1375,7 @@ function walkDts(dir, out = []) {
|
|
|
1257
1375
|
if (!existsSync(dir)) return out;
|
|
1258
1376
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1259
1377
|
if (entry.name === "node_modules") continue;
|
|
1260
|
-
const p =
|
|
1378
|
+
const p = path19.join(dir, entry.name);
|
|
1261
1379
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1262
1380
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1263
1381
|
}
|
|
@@ -1274,27 +1392,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1274
1392
|
}
|
|
1275
1393
|
const files = [];
|
|
1276
1394
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1277
|
-
const themes = ds &&
|
|
1395
|
+
const themes = ds && path19.join(ds, "dist", "themes");
|
|
1278
1396
|
if (themes && existsSync(themes)) {
|
|
1279
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1397
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path19.join(themes, name));
|
|
1280
1398
|
}
|
|
1281
1399
|
if (files.length === 0) {
|
|
1282
1400
|
throw new DoctorConfigError(
|
|
1283
1401
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1284
1402
|
);
|
|
1285
1403
|
}
|
|
1286
|
-
const uiStyles =
|
|
1404
|
+
const uiStyles = path19.join(uiDir, "dist", "styles.css");
|
|
1287
1405
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1288
1406
|
return files;
|
|
1289
1407
|
}
|
|
1290
1408
|
function resolveSpec(root, spec) {
|
|
1291
|
-
const local =
|
|
1292
|
-
if (spec.startsWith(".") ||
|
|
1409
|
+
const local = path19.resolve(root, spec);
|
|
1410
|
+
if (spec.startsWith(".") || path19.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1293
1411
|
const parts = spec.split("/");
|
|
1294
1412
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1295
1413
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1296
1414
|
if (dir) {
|
|
1297
|
-
const file =
|
|
1415
|
+
const file = path19.join(dir, ...parts.slice(nameLength));
|
|
1298
1416
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1299
1417
|
}
|
|
1300
1418
|
return existsSync(local) ? local : null;
|
|
@@ -1302,7 +1420,7 @@ function resolveSpec(root, spec) {
|
|
|
1302
1420
|
function loadPalette(root) {
|
|
1303
1421
|
const names = new Set(TAILWIND_PALETTE);
|
|
1304
1422
|
try {
|
|
1305
|
-
const req = createRequire(
|
|
1423
|
+
const req = createRequire(path19.join(root, "package.json"));
|
|
1306
1424
|
const colors = req("tailwindcss/colors");
|
|
1307
1425
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1308
1426
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -1445,7 +1563,8 @@ function parseManifest(home, id, raw, version, options = {}) {
|
|
|
1445
1563
|
if (!isObject2(f) || typeof f["name"] !== "string" || typeof f["summary"] !== "string") problems.push(`${at}.feature: needs a name and a summary`);
|
|
1446
1564
|
else {
|
|
1447
1565
|
feature = { name: f["name"], summary: f["summary"] };
|
|
1448
|
-
|
|
1566
|
+
const kind = f["kind"] ?? f["layer"];
|
|
1567
|
+
if (typeof kind === "string") feature.kind = kind === "primitive" ? "element" : kind;
|
|
1449
1568
|
if (strings(f["keywords"])) feature.keywords = f["keywords"];
|
|
1450
1569
|
if (strings(f["audience"])) feature.audience = f["audience"];
|
|
1451
1570
|
}
|
|
@@ -1490,8 +1609,8 @@ function rawBlocksOf(packageJson) {
|
|
|
1490
1609
|
|
|
1491
1610
|
// src/blocks/files.ts
|
|
1492
1611
|
function inside(parent, child) {
|
|
1493
|
-
const rel =
|
|
1494
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
1612
|
+
const rel = path19.relative(parent, child);
|
|
1613
|
+
return rel === "" || !rel.startsWith("..") && !path19.isAbsolute(rel);
|
|
1495
1614
|
}
|
|
1496
1615
|
|
|
1497
1616
|
// src/blocks/local.ts
|
|
@@ -1504,8 +1623,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1504
1623
|
return raw.map((entry, i) => {
|
|
1505
1624
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
1506
1625
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
1507
|
-
if (
|
|
1508
|
-
const norm =
|
|
1626
|
+
if (path19.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
1627
|
+
const norm = path19.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1509
1628
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
1510
1629
|
const parts = norm.split("/");
|
|
1511
1630
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -1516,7 +1635,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
1516
1635
|
});
|
|
1517
1636
|
}
|
|
1518
1637
|
function localPackageGlobs(root) {
|
|
1519
|
-
const file =
|
|
1638
|
+
const file = path19.join(root, "genesis.config.json");
|
|
1520
1639
|
if (!existsSync(file)) return [];
|
|
1521
1640
|
let raw;
|
|
1522
1641
|
try {
|
|
@@ -1530,14 +1649,14 @@ function localPackageGlobs(root) {
|
|
|
1530
1649
|
var cache = /* @__PURE__ */ new Map();
|
|
1531
1650
|
function repositoryRoot(appRoot) {
|
|
1532
1651
|
for (let dir = appRoot; ; ) {
|
|
1533
|
-
if (existsSync(
|
|
1534
|
-
const parent =
|
|
1652
|
+
if (existsSync(path19.join(dir, ".git"))) return dir;
|
|
1653
|
+
const parent = path19.dirname(dir);
|
|
1535
1654
|
if (parent === dir) return appRoot;
|
|
1536
1655
|
dir = parent;
|
|
1537
1656
|
}
|
|
1538
1657
|
}
|
|
1539
1658
|
function localPackages(root) {
|
|
1540
|
-
const appRoot =
|
|
1659
|
+
const appRoot = path19.resolve(root);
|
|
1541
1660
|
const globs = localPackageGlobs(appRoot);
|
|
1542
1661
|
const key2 = `${appRoot}
|
|
1543
1662
|
${globs.join("\n")}`;
|
|
@@ -1546,24 +1665,24 @@ ${globs.join("\n")}`;
|
|
|
1546
1665
|
const dirs = /* @__PURE__ */ new Set();
|
|
1547
1666
|
for (const glob of globs) {
|
|
1548
1667
|
if (glob.endsWith("/*") || glob === "*") {
|
|
1549
|
-
const parent =
|
|
1668
|
+
const parent = path19.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
1550
1669
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
1551
1670
|
for (const entry of readdirSync(parent).sort()) {
|
|
1552
1671
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
1553
|
-
dirs.add(
|
|
1672
|
+
dirs.add(path19.join(parent, entry));
|
|
1554
1673
|
}
|
|
1555
1674
|
} else {
|
|
1556
|
-
dirs.add(
|
|
1675
|
+
dirs.add(path19.join(appRoot, glob));
|
|
1557
1676
|
}
|
|
1558
1677
|
}
|
|
1559
1678
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
1560
1679
|
const out = [];
|
|
1561
1680
|
const byName = /* @__PURE__ */ new Map();
|
|
1562
1681
|
for (const dir of [...dirs].sort()) {
|
|
1563
|
-
const manifest =
|
|
1682
|
+
const manifest = path19.join(dir, "package.json");
|
|
1564
1683
|
if (!existsSync(manifest)) continue;
|
|
1565
1684
|
if (!inside(real2, realpathSync(dir))) {
|
|
1566
|
-
throw new LocalPackagesError(`${
|
|
1685
|
+
throw new LocalPackagesError(`${path19.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
1567
1686
|
}
|
|
1568
1687
|
let pkg;
|
|
1569
1688
|
try {
|
|
@@ -1572,7 +1691,7 @@ ${globs.join("\n")}`;
|
|
|
1572
1691
|
continue;
|
|
1573
1692
|
}
|
|
1574
1693
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
1575
|
-
const rel =
|
|
1694
|
+
const rel = path19.relative(appRoot, dir).split(path19.sep).join("/");
|
|
1576
1695
|
const other = byName.get(pkg.name);
|
|
1577
1696
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
1578
1697
|
byName.set(pkg.name, rel);
|
|
@@ -1757,16 +1876,16 @@ var DEFAULT_IGNORE = [
|
|
|
1757
1876
|
];
|
|
1758
1877
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1759
1878
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1760
|
-
var toPosix = (p) => p.split(
|
|
1879
|
+
var toPosix = (p) => p.split(path19.sep).join("/");
|
|
1761
1880
|
function scanFiles(root, config) {
|
|
1762
1881
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
1763
1882
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
1764
1883
|
const files = [];
|
|
1765
1884
|
const seen = /* @__PURE__ */ new Set();
|
|
1766
1885
|
const visit = (abs) => {
|
|
1767
|
-
const rel = toPosix(
|
|
1886
|
+
const rel = toPosix(path19.relative(root, abs));
|
|
1768
1887
|
if (seen.has(rel) || ignored(rel)) return;
|
|
1769
|
-
const ext =
|
|
1888
|
+
const ext = path19.extname(abs);
|
|
1770
1889
|
if (!extensions.has(ext)) return;
|
|
1771
1890
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1772
1891
|
seen.add(rel);
|
|
@@ -1776,14 +1895,14 @@ function scanFiles(root, config) {
|
|
|
1776
1895
|
const walk = (dir) => {
|
|
1777
1896
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1778
1897
|
if (entry.isDirectory()) {
|
|
1779
|
-
if (!SKIP_DIRS.has(entry.name)) walk(
|
|
1898
|
+
if (!SKIP_DIRS.has(entry.name)) walk(path19.join(dir, entry.name));
|
|
1780
1899
|
} else if (entry.isFile()) {
|
|
1781
|
-
visit(
|
|
1900
|
+
visit(path19.join(dir, entry.name));
|
|
1782
1901
|
}
|
|
1783
1902
|
}
|
|
1784
1903
|
};
|
|
1785
1904
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1786
|
-
const abs =
|
|
1905
|
+
const abs = path19.resolve(root, src);
|
|
1787
1906
|
if (!existsSync(abs)) continue;
|
|
1788
1907
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
1789
1908
|
else visit(abs);
|
|
@@ -1871,7 +1990,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
1871
1990
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
1872
1991
|
let all = compiled;
|
|
1873
1992
|
if (rulesDoc) {
|
|
1874
|
-
const file =
|
|
1993
|
+
const file = path19.resolve(root, rulesDoc);
|
|
1875
1994
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
1876
1995
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
1877
1996
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -1929,15 +2048,112 @@ async function loadPlugins(specs, configDir) {
|
|
|
1929
2048
|
}
|
|
1930
2049
|
function resolvePlugin(id, configDir) {
|
|
1931
2050
|
try {
|
|
1932
|
-
if (id.startsWith(".") ||
|
|
2051
|
+
if (id.startsWith(".") || path19.isAbsolute(id)) return resolveFrom(path19.resolve(configDir, id), configDir);
|
|
1933
2052
|
return resolveFrom(id, configDir);
|
|
1934
2053
|
} catch {
|
|
1935
2054
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
1936
2055
|
}
|
|
1937
2056
|
}
|
|
1938
2057
|
function resolveFrom(id, from) {
|
|
1939
|
-
return createRequire(
|
|
2058
|
+
return createRequire(path19.join(from, "noop.js")).resolve(id);
|
|
2059
|
+
}
|
|
2060
|
+
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
2061
|
+
var OVERLAY_NOTICE_DAYS = 14;
|
|
2062
|
+
var OVERLAY_WARN_DAYS = 30;
|
|
2063
|
+
function overlayState(name, json) {
|
|
2064
|
+
const raw = json?.genesis?.overlay;
|
|
2065
|
+
if (raw === void 0) return { kind: "none" };
|
|
2066
|
+
const problems = [];
|
|
2067
|
+
const marker = readOverlayMarker(name, raw, problems);
|
|
2068
|
+
return marker ? { kind: "marked", marker } : { kind: "invalid", problems };
|
|
1940
2069
|
}
|
|
2070
|
+
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2071
|
+
const problems = [];
|
|
2072
|
+
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2073
|
+
const rel = path19.relative(path19.resolve(root), path19.resolve(dir)).split(path19.sep).join("/");
|
|
2074
|
+
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2075
|
+
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2076
|
+
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})`);
|
|
2077
|
+
return problems;
|
|
2078
|
+
}
|
|
2079
|
+
function markedOverlays(ctx) {
|
|
2080
|
+
const out = /* @__PURE__ */ new Map();
|
|
2081
|
+
for (const p of ctx.packages) {
|
|
2082
|
+
if (!p.local || !p.overlay) continue;
|
|
2083
|
+
if (overlaySetupProblems(ctx.root, ctx.config, p.dir, p.name, { private: p.private }).length) continue;
|
|
2084
|
+
out.set(p.name, { dir: p.dir, marker: p.overlay });
|
|
2085
|
+
}
|
|
2086
|
+
return out;
|
|
2087
|
+
}
|
|
2088
|
+
function insideOverlayOf(overlays, file, packageName3) {
|
|
2089
|
+
const dir = overlays.get(packageName3)?.dir;
|
|
2090
|
+
return dir !== void 0 && inside(dir, file.absolutePath);
|
|
2091
|
+
}
|
|
2092
|
+
function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
|
|
2093
|
+
const [y, m, d] = since.split("-").map(Number);
|
|
2094
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
2095
|
+
return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
|
|
2096
|
+
}
|
|
2097
|
+
var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
|
|
2098
|
+
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
2099
|
+
let packages;
|
|
2100
|
+
try {
|
|
2101
|
+
packages = localPackages(ctx.root);
|
|
2102
|
+
} catch {
|
|
2103
|
+
return;
|
|
2104
|
+
}
|
|
2105
|
+
for (const pkg of packages) {
|
|
2106
|
+
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
2107
|
+
const file = `${pkg.rel}/package.json`;
|
|
2108
|
+
let json;
|
|
2109
|
+
try {
|
|
2110
|
+
json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
|
|
2111
|
+
} catch {
|
|
2112
|
+
continue;
|
|
2113
|
+
}
|
|
2114
|
+
const state = overlayState(pkg.name, json);
|
|
2115
|
+
if (state.kind === "none") {
|
|
2116
|
+
ctx.report({
|
|
2117
|
+
rule: "overlay-unmarked",
|
|
2118
|
+
file,
|
|
2119
|
+
subject: pkg.name,
|
|
2120
|
+
message: `${pkg.name} is a local package with a Genesis package's name, so it shadows the published one, but it carries no overlay marker; add "genesis": { "overlay": { "upstream": "${pkg.name}@<version copied>", "since": "YYYY-MM-DD", "owner": "\u2026", "reason": "\u2026" } }, or rename it`
|
|
2121
|
+
});
|
|
2122
|
+
continue;
|
|
2123
|
+
}
|
|
2124
|
+
if (state.kind === "invalid") {
|
|
2125
|
+
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2126
|
+
continue;
|
|
2127
|
+
}
|
|
2128
|
+
const { marker } = state;
|
|
2129
|
+
for (const problem of overlaySetupProblems(ctx.root, ctx.config, pkg.dir, pkg.name, json)) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2130
|
+
const age = overlayAgeDays(marker.since, now);
|
|
2131
|
+
if (age < -1) {
|
|
2132
|
+
ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: `${pkg.name} genesis.overlay.since: ${marker.since} is in the future; use the day the overlay was made` });
|
|
2133
|
+
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
2134
|
+
ctx.report({
|
|
2135
|
+
rule: "overlay-age",
|
|
2136
|
+
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
2137
|
+
file,
|
|
2138
|
+
subject: pkg.name,
|
|
2139
|
+
message: `the overlay of ${marker.upstream} is ${age} days old (since ${marker.since}, owner ${marker.owner}); promote its change to Genesis and adopt the release, or drop it (an overlay is reported after ${OVERLAY_NOTICE_DAYS} days, and after ${OVERLAY_WARN_DAYS} it warns, which fails --strict)`
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
const upstream = overlayUpstream(marker).version;
|
|
2143
|
+
const version = typeof json.version === "string" ? json.version : "";
|
|
2144
|
+
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
2145
|
+
ctx.report({
|
|
2146
|
+
rule: "overlay-version",
|
|
2147
|
+
level: "warn",
|
|
2148
|
+
file,
|
|
2149
|
+
subject: version || "(none)",
|
|
2150
|
+
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`
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
// src/doctor/rules.ts
|
|
1941
2157
|
var BUILTIN_RULES = [
|
|
1942
2158
|
"local-primitives",
|
|
1943
2159
|
"starter-leftover",
|
|
@@ -1963,6 +2179,9 @@ var BUILTIN_RULES = [
|
|
|
1963
2179
|
"studio-server-auth-import",
|
|
1964
2180
|
"removed-scope-name",
|
|
1965
2181
|
"scope-practice-id",
|
|
2182
|
+
// export maturity (stability.ts)
|
|
2183
|
+
"deprecated-import",
|
|
2184
|
+
"beta-import",
|
|
1966
2185
|
// native pack
|
|
1967
2186
|
"native-raw-primitive",
|
|
1968
2187
|
"native-literal-color",
|
|
@@ -1988,6 +2207,11 @@ var BUILTIN_RULES = [
|
|
|
1988
2207
|
"package-block-invalid",
|
|
1989
2208
|
"package-untagged-tests",
|
|
1990
2209
|
"package-doctor-declaration",
|
|
2210
|
+
// overlays (overlays.ts)
|
|
2211
|
+
"overlay-unmarked",
|
|
2212
|
+
"overlay-invalid",
|
|
2213
|
+
"overlay-age",
|
|
2214
|
+
"overlay-version",
|
|
1991
2215
|
// package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
|
|
1992
2216
|
"package-rules-invalid",
|
|
1993
2217
|
"package-rule-override",
|
|
@@ -2016,7 +2240,7 @@ function importSpecifiers(file) {
|
|
|
2016
2240
|
}
|
|
2017
2241
|
function checkProjectLayout(ctx) {
|
|
2018
2242
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2019
|
-
if (existsSync(
|
|
2243
|
+
if (existsSync(path19.join(ctx.root, dir))) {
|
|
2020
2244
|
ctx.report({
|
|
2021
2245
|
rule: "local-primitives",
|
|
2022
2246
|
file: dir,
|
|
@@ -2026,7 +2250,7 @@ function checkProjectLayout(ctx) {
|
|
|
2026
2250
|
}
|
|
2027
2251
|
}
|
|
2028
2252
|
for (const file of STARTER_LEFTOVERS) {
|
|
2029
|
-
if (existsSync(
|
|
2253
|
+
if (existsSync(path19.join(ctx.root, file))) {
|
|
2030
2254
|
ctx.report({
|
|
2031
2255
|
rule: "starter-leftover",
|
|
2032
2256
|
level: "warn",
|
|
@@ -2056,8 +2280,9 @@ function checkImports(ctx) {
|
|
|
2056
2280
|
function checkRawTags(ctx) {
|
|
2057
2281
|
const tags = [...ctx.genesis.rawTags].map(([tag, component]) => [tag, component, new RegExp(`<${tag}(?=[\\s>/]|$)`)]);
|
|
2058
2282
|
if (tags.length === 0) return;
|
|
2283
|
+
const overlays = markedOverlays(ctx);
|
|
2059
2284
|
for (const file of ctx.files) {
|
|
2060
|
-
if (!JSX_EXTS.has(file.ext)) continue;
|
|
2285
|
+
if (!JSX_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
2061
2286
|
file.code.split("\n").forEach((text, i) => {
|
|
2062
2287
|
for (const [tag, component, re] of tags) {
|
|
2063
2288
|
if (re.test(text)) {
|
|
@@ -2115,7 +2340,7 @@ function checkTokens(ctx) {
|
|
|
2115
2340
|
}
|
|
2116
2341
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2117
2342
|
if (/[*?]/.test(pattern)) continue;
|
|
2118
|
-
const abs =
|
|
2343
|
+
const abs = path19.join(ctx.root, pattern);
|
|
2119
2344
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2120
2345
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2121
2346
|
}
|
|
@@ -2132,9 +2357,10 @@ function checkTokens(ctx) {
|
|
|
2132
2357
|
}
|
|
2133
2358
|
}
|
|
2134
2359
|
function checkShadowedExports(ctx) {
|
|
2360
|
+
const overlays = markedOverlays(ctx);
|
|
2135
2361
|
const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
|
|
2136
2362
|
for (const file of ctx.files) {
|
|
2137
|
-
if (!SCRIPT_EXTS.has(file.ext)) continue;
|
|
2363
|
+
if (!SCRIPT_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
2138
2364
|
file.code.split("\n").forEach((text, i) => {
|
|
2139
2365
|
for (const m of text.matchAll(re)) {
|
|
2140
2366
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
@@ -2218,10 +2444,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
|
|
|
2218
2444
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2219
2445
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2220
2446
|
function resolveLocal(root, fromFile, spec) {
|
|
2221
|
-
const bases = spec.startsWith(".") ? [
|
|
2447
|
+
const bases = spec.startsWith(".") ? [path19.resolve(path19.dirname(fromFile), spec)] : [path19.join(root, spec.slice(2)), path19.join(root, "src", spec.slice(2))];
|
|
2222
2448
|
for (const base of bases) {
|
|
2223
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2224
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2449
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path19.join(base, `index${e}`))].find(
|
|
2450
|
+
(p) => SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p)
|
|
2225
2451
|
);
|
|
2226
2452
|
if (hit) return hit;
|
|
2227
2453
|
}
|
|
@@ -2341,6 +2567,7 @@ function checkNativePack(ctx) {
|
|
|
2341
2567
|
}
|
|
2342
2568
|
var RN = String.raw`["']react-native["']`;
|
|
2343
2569
|
function checkRawPrimitives(ctx, pkg) {
|
|
2570
|
+
const overlays = markedOverlays(ctx);
|
|
2344
2571
|
const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
|
|
2345
2572
|
const named = [
|
|
2346
2573
|
// import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
|
|
@@ -2354,7 +2581,7 @@ function checkRawPrimitives(ctx, pkg) {
|
|
|
2354
2581
|
];
|
|
2355
2582
|
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
2356
2583
|
for (const file of ctx.files) {
|
|
2357
|
-
if (!SCRIPT_EXTS3.has(file.ext)) continue;
|
|
2584
|
+
if (!SCRIPT_EXTS3.has(file.ext) || insideOverlayOf(overlays, file, NATIVE_UI_PACKAGE)) continue;
|
|
2358
2585
|
const code = file.code;
|
|
2359
2586
|
const report = (name, at) => {
|
|
2360
2587
|
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
@@ -2403,7 +2630,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2403
2630
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2404
2631
|
const code = file.code;
|
|
2405
2632
|
const hidden = HIDES_HEADER.exec(code);
|
|
2406
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2633
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path19.posix.dirname(file.path), file.path);
|
|
2407
2634
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2408
2635
|
if (hidden && own) {
|
|
2409
2636
|
reported.add(file.path);
|
|
@@ -2431,7 +2658,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2431
2658
|
}
|
|
2432
2659
|
for (const file of ctx.files) {
|
|
2433
2660
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2434
|
-
const layout = hidingLayouts.get(
|
|
2661
|
+
const layout = hidingLayouts.get(path19.posix.dirname(file.path));
|
|
2435
2662
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2436
2663
|
if (!layout || !own) continue;
|
|
2437
2664
|
ctx.report({
|
|
@@ -2453,13 +2680,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
2453
2680
|
}
|
|
2454
2681
|
function routerRoot(ctx) {
|
|
2455
2682
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2456
|
-
return existsSync(
|
|
2683
|
+
return existsSync(path19.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2457
2684
|
}
|
|
2458
2685
|
function checkScreenLayouts(ctx, pkg) {
|
|
2459
2686
|
const layouts = nativeLayouts(pkg);
|
|
2460
2687
|
if (layouts.length === 0) return;
|
|
2461
2688
|
const rootDir = routerRoot(ctx);
|
|
2462
|
-
if (!existsSync(
|
|
2689
|
+
if (!existsSync(path19.join(ctx.root, rootDir))) {
|
|
2463
2690
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2464
2691
|
return;
|
|
2465
2692
|
}
|
|
@@ -2515,7 +2742,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
2515
2742
|
function readExpoConfigs(root) {
|
|
2516
2743
|
const out = [];
|
|
2517
2744
|
for (const name of EXPO_CONFIGS) {
|
|
2518
|
-
const abs =
|
|
2745
|
+
const abs = path19.join(root, name);
|
|
2519
2746
|
if (!existsSync(abs)) continue;
|
|
2520
2747
|
const text = readFileSync(abs, "utf8");
|
|
2521
2748
|
let json = null;
|
|
@@ -2549,13 +2776,13 @@ function pluginOptions(json, module) {
|
|
|
2549
2776
|
return null;
|
|
2550
2777
|
}
|
|
2551
2778
|
function dependencies(root) {
|
|
2552
|
-
const file =
|
|
2779
|
+
const file = path19.join(root, "package.json");
|
|
2553
2780
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2554
2781
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2555
2782
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2556
2783
|
}
|
|
2557
2784
|
function runtimeDependencies(root) {
|
|
2558
|
-
const file =
|
|
2785
|
+
const file = path19.join(root, "package.json");
|
|
2559
2786
|
if (!existsSync(file)) return {};
|
|
2560
2787
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2561
2788
|
}
|
|
@@ -2929,14 +3156,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
2929
3156
|
seen.add(file);
|
|
2930
3157
|
const json = readJsonc(file);
|
|
2931
3158
|
if (!json) return {};
|
|
2932
|
-
const dir =
|
|
3159
|
+
const dir = path19.dirname(file);
|
|
2933
3160
|
let merged = {};
|
|
2934
3161
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2935
3162
|
for (const ext of parents) {
|
|
2936
3163
|
if (typeof ext !== "string") continue;
|
|
2937
3164
|
let target = null;
|
|
2938
|
-
if (ext.startsWith(".") ||
|
|
2939
|
-
const abs =
|
|
3165
|
+
if (ext.startsWith(".") || path19.isAbsolute(ext)) {
|
|
3166
|
+
const abs = path19.resolve(dir, ext);
|
|
2940
3167
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2941
3168
|
} else {
|
|
2942
3169
|
const parts = ext.split("/");
|
|
@@ -2944,14 +3171,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
2944
3171
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2945
3172
|
if (pkgDir) {
|
|
2946
3173
|
const sub = parts.slice(nameLength).join("/");
|
|
2947
|
-
const abs =
|
|
3174
|
+
const abs = path19.join(pkgDir, sub || "tsconfig.json");
|
|
2948
3175
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2949
3176
|
}
|
|
2950
3177
|
}
|
|
2951
3178
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2952
3179
|
}
|
|
2953
3180
|
const opts = json.compilerOptions ?? {};
|
|
2954
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
3181
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path19.resolve(dir, opts.baseUrl);
|
|
2955
3182
|
if (opts.paths && typeof opts.paths === "object") {
|
|
2956
3183
|
merged.paths = opts.paths;
|
|
2957
3184
|
merged.pathsDir = dir;
|
|
@@ -2962,7 +3189,7 @@ function aliases(root) {
|
|
|
2962
3189
|
const table = [];
|
|
2963
3190
|
let baseUrl = null;
|
|
2964
3191
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2965
|
-
const file =
|
|
3192
|
+
const file = path19.join(root, name);
|
|
2966
3193
|
if (!existsSync(file)) continue;
|
|
2967
3194
|
const config = readTsconfig(root, file);
|
|
2968
3195
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -2970,22 +3197,22 @@ function aliases(root) {
|
|
|
2970
3197
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2971
3198
|
if (!Array.isArray(targets)) continue;
|
|
2972
3199
|
const exact = !pattern.endsWith("*");
|
|
2973
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
3200
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path19.join(base, String(t).replace(/\*$/, ""))) });
|
|
2974
3201
|
}
|
|
2975
3202
|
}
|
|
2976
|
-
const pkg = readJsonc(
|
|
3203
|
+
const pkg = readJsonc(path19.join(root, "package.json"));
|
|
2977
3204
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2978
3205
|
if (typeof target !== "string") continue;
|
|
2979
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
3206
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path19.join(root, target.replace(/\*.*$/, ""))] });
|
|
2980
3207
|
}
|
|
2981
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
3208
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path19.join(root, "src") + path19.sep, root + path19.sep] });
|
|
2982
3209
|
return { table, baseUrl };
|
|
2983
3210
|
}
|
|
2984
3211
|
function resolveFile(base) {
|
|
2985
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
3212
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path19.join(base, `index${e}`))];
|
|
2986
3213
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2987
3214
|
for (const p of tries) {
|
|
2988
|
-
if (SCRIPT_EXTS2.has(
|
|
3215
|
+
if (SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2989
3216
|
}
|
|
2990
3217
|
return null;
|
|
2991
3218
|
}
|
|
@@ -2999,7 +3226,7 @@ function createTrail(ctx) {
|
|
|
2999
3226
|
const { table, baseUrl } = aliases(ctx.root);
|
|
3000
3227
|
let declared = null;
|
|
3001
3228
|
try {
|
|
3002
|
-
const pkg = JSON.parse(readFileSync(
|
|
3229
|
+
const pkg = JSON.parse(readFileSync(path19.join(ctx.root, "package.json"), "utf8"));
|
|
3003
3230
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3004
3231
|
} catch {
|
|
3005
3232
|
declared = null;
|
|
@@ -3030,17 +3257,17 @@ function createTrail(ctx) {
|
|
|
3030
3257
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3031
3258
|
let resolved = null;
|
|
3032
3259
|
if (spec.startsWith(".")) {
|
|
3033
|
-
resolved = resolveFile(
|
|
3260
|
+
resolved = resolveFile(path19.resolve(path19.dirname(file.absolutePath), spec));
|
|
3034
3261
|
if (!resolved) lost = true;
|
|
3035
3262
|
} else {
|
|
3036
3263
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3037
3264
|
if (alias) {
|
|
3038
3265
|
for (const t of alias.targets) {
|
|
3039
|
-
resolved = resolveFile(alias.exact ? t :
|
|
3266
|
+
resolved = resolveFile(alias.exact ? t : path19.join(t, spec.slice(alias.prefix.length)));
|
|
3040
3267
|
if (resolved) break;
|
|
3041
3268
|
}
|
|
3042
3269
|
}
|
|
3043
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
3270
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path19.join(baseUrl, spec));
|
|
3044
3271
|
if (!resolved) {
|
|
3045
3272
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3046
3273
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -3116,18 +3343,18 @@ function createTrail(ctx) {
|
|
|
3116
3343
|
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
3117
3344
|
function installedGenesis(root) {
|
|
3118
3345
|
const found = /* @__PURE__ */ new Map();
|
|
3119
|
-
let dir =
|
|
3346
|
+
let dir = path19.resolve(root);
|
|
3120
3347
|
for (; ; ) {
|
|
3121
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
3122
|
-
const scope =
|
|
3348
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path19.join(dir, m)));
|
|
3349
|
+
const scope = path19.join(dir, "node_modules", "@marktiderman");
|
|
3123
3350
|
if (existsSync(scope)) {
|
|
3124
3351
|
for (const entry of readdirSync(scope)) {
|
|
3125
3352
|
const name = `@marktiderman/${entry}`;
|
|
3126
3353
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
3127
|
-
if (existsSync(
|
|
3354
|
+
if (existsSync(path19.join(scope, entry, "package.json"))) found.set(name, path19.join(scope, entry));
|
|
3128
3355
|
}
|
|
3129
3356
|
}
|
|
3130
|
-
const parent =
|
|
3357
|
+
const parent = path19.dirname(dir);
|
|
3131
3358
|
if (atInstallRoot || parent === dir) return found;
|
|
3132
3359
|
dir = parent;
|
|
3133
3360
|
}
|
|
@@ -3149,7 +3376,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
3149
3376
|
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;
|
|
3150
3377
|
function routesDir(ctx) {
|
|
3151
3378
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3152
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
3379
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path19.join(ctx.root, d))) ?? null;
|
|
3153
3380
|
}
|
|
3154
3381
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3155
3382
|
function flavorOf(dir, rels) {
|
|
@@ -3250,7 +3477,7 @@ var PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "f
|
|
|
3250
3477
|
var FORBID_KEYS = /* @__PURE__ */ new Set(["jsx", "imports", "pattern"]);
|
|
3251
3478
|
var UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "pattern"]);
|
|
3252
3479
|
var PRIMITIVE_KEYS = /* @__PURE__ */ new Set(["need", "use", "import", "docs"]);
|
|
3253
|
-
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "primitives", "plugin", "$comment"]);
|
|
3480
|
+
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "catalog", "primitives", "plugin", "$comment"]);
|
|
3254
3481
|
var SCRIPT_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts", "**/*.cts", "**/*.mjs", "**/*.cjs"];
|
|
3255
3482
|
function ruleNamespace(packageName3) {
|
|
3256
3483
|
const m = GENESIS.exec(packageName3);
|
|
@@ -3263,7 +3490,7 @@ function toRegExp2(source, flags = "") {
|
|
|
3263
3490
|
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
3264
3491
|
return new RegExp(source, flags);
|
|
3265
3492
|
}
|
|
3266
|
-
function validateDeclaration(raw, packageName3,
|
|
3493
|
+
function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
3267
3494
|
const fail = (msg) => {
|
|
3268
3495
|
throw new PackageDeclarationError(`${packageName3}: genesis.doctor ${msg}`);
|
|
3269
3496
|
};
|
|
@@ -3283,9 +3510,9 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3283
3510
|
}
|
|
3284
3511
|
});
|
|
3285
3512
|
if (typeof raw === "string") {
|
|
3286
|
-
if (!
|
|
3287
|
-
const file =
|
|
3288
|
-
if (!inside(
|
|
3513
|
+
if (!packageDir2) fail(`points at ${raw}, but the package folder is unknown`);
|
|
3514
|
+
const file = path19.resolve(packageDir2, raw);
|
|
3515
|
+
if (!inside(packageDir2, file)) fail(`points outside the package (${raw})`);
|
|
3289
3516
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
3290
3517
|
let parsed;
|
|
3291
3518
|
try {
|
|
@@ -3293,7 +3520,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3293
3520
|
} catch (err) {
|
|
3294
3521
|
return fail(`file ${raw} is not valid JSON: ${err.message}`);
|
|
3295
3522
|
}
|
|
3296
|
-
return validateDeclaration(parsed, packageName3,
|
|
3523
|
+
return validateDeclaration(parsed, packageName3, packageDir2, ignored);
|
|
3297
3524
|
}
|
|
3298
3525
|
if (raw === false) fail(`is false; say why with { "enforce": false, "reason": "\u2026" }`);
|
|
3299
3526
|
if (!isObject3(raw)) fail(`must be an object (or a path to a JSON file in the package)`);
|
|
@@ -3304,8 +3531,10 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3304
3531
|
if (c.reason !== void 0 && (typeof c.reason !== "string" || !c.reason.trim())) fail(`reason must be a sentence`);
|
|
3305
3532
|
const prefer = c.prefer === void 0 ? [] : c.prefer;
|
|
3306
3533
|
if (!Array.isArray(prefer)) fail(`prefer must be a list`);
|
|
3307
|
-
|
|
3308
|
-
|
|
3534
|
+
if (c.catalog !== void 0 && c.primitives !== void 0) fail(`declares both catalog and primitives; keep catalog (primitives is its old name)`);
|
|
3535
|
+
const listKey = c.catalog !== void 0 ? "catalog" : "primitives";
|
|
3536
|
+
const primitives = c[listKey] === void 0 ? [] : c[listKey];
|
|
3537
|
+
if (!Array.isArray(primitives)) fail(`${listKey} must be a list`);
|
|
3309
3538
|
if (c.plugin !== void 0 && (typeof c.plugin !== "string" || !c.plugin.trim())) fail(`plugin must be a module path inside the package`);
|
|
3310
3539
|
if (!enforce) {
|
|
3311
3540
|
if (typeof c.reason !== "string") fail(`turns enforcement off without a reason; add "reason"`);
|
|
@@ -3320,7 +3549,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3320
3549
|
ids.add(r.id);
|
|
3321
3550
|
}
|
|
3322
3551
|
const entries = each(primitives, (p, i) => {
|
|
3323
|
-
const where2 =
|
|
3552
|
+
const where2 = `${listKey}[${i}]`;
|
|
3324
3553
|
if (!isObject3(p)) return fail(`${where2} must be an object`);
|
|
3325
3554
|
for (const key2 of Object.keys(p)) if (!PRIMITIVE_KEYS.has(key2)) unknownKey(where2, key2);
|
|
3326
3555
|
for (const key2 of ["need", "use"]) if (typeof p[key2] !== "string" || !p[key2].trim()) fail(`${where2} needs "${key2}"`);
|
|
@@ -3329,10 +3558,10 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3329
3558
|
});
|
|
3330
3559
|
let plugin;
|
|
3331
3560
|
if (typeof c.plugin === "string") {
|
|
3332
|
-
if (!
|
|
3561
|
+
if (!packageDir2) plugin = c.plugin;
|
|
3333
3562
|
else {
|
|
3334
|
-
plugin =
|
|
3335
|
-
if (!inside(
|
|
3563
|
+
plugin = path19.resolve(packageDir2, c.plugin);
|
|
3564
|
+
if (!inside(packageDir2, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
3336
3565
|
}
|
|
3337
3566
|
}
|
|
3338
3567
|
return {
|
|
@@ -3381,7 +3610,7 @@ function checkPattern(v, where2, fail) {
|
|
|
3381
3610
|
}
|
|
3382
3611
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
3383
3612
|
function readDeclaringPackage(dir, local) {
|
|
3384
|
-
const file =
|
|
3613
|
+
const file = path19.join(dir, "package.json");
|
|
3385
3614
|
let stamp;
|
|
3386
3615
|
let real2;
|
|
3387
3616
|
try {
|
|
@@ -3404,17 +3633,21 @@ ${local}`;
|
|
|
3404
3633
|
const pkg = {
|
|
3405
3634
|
name: json.name,
|
|
3406
3635
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
3407
|
-
dir:
|
|
3636
|
+
dir: path19.resolve(dir),
|
|
3408
3637
|
namespace: ruleNamespace(json.name),
|
|
3409
3638
|
local,
|
|
3410
3639
|
private: json.private === true,
|
|
3411
3640
|
declaration: null
|
|
3412
3641
|
};
|
|
3642
|
+
if (local) {
|
|
3643
|
+
const state = overlayState(json.name, json);
|
|
3644
|
+
if (state.kind === "marked") pkg.overlay = state.marker;
|
|
3645
|
+
}
|
|
3413
3646
|
const raw = json.genesis?.doctor;
|
|
3414
3647
|
if (raw !== void 0) {
|
|
3415
3648
|
const ignored = [];
|
|
3416
3649
|
try {
|
|
3417
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
3650
|
+
pkg.declaration = validateDeclaration(raw, json.name, path19.resolve(dir), ignored);
|
|
3418
3651
|
if (ignored.length) pkg.ignored = ignored;
|
|
3419
3652
|
} catch (err) {
|
|
3420
3653
|
pkg.error = err.message;
|
|
@@ -3433,14 +3666,14 @@ function discoverPackages(root) {
|
|
|
3433
3666
|
for (const dir of installed) {
|
|
3434
3667
|
let scope;
|
|
3435
3668
|
try {
|
|
3436
|
-
scope =
|
|
3669
|
+
scope = path19.dirname(realpathSync(dir));
|
|
3437
3670
|
} catch {
|
|
3438
3671
|
continue;
|
|
3439
3672
|
}
|
|
3440
|
-
if (
|
|
3673
|
+
if (path19.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
3441
3674
|
for (const entry of readdirSync(scope)) {
|
|
3442
3675
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
3443
|
-
const pkg = readDeclaringPackage(
|
|
3676
|
+
const pkg = readDeclaringPackage(path19.join(scope, entry), false);
|
|
3444
3677
|
if (pkg) byName.set(pkg.name, pkg);
|
|
3445
3678
|
}
|
|
3446
3679
|
}
|
|
@@ -3609,7 +3842,7 @@ function unknownPackageRuleSettings(config, packages, reported) {
|
|
|
3609
3842
|
level: "warn",
|
|
3610
3843
|
file: "genesis config",
|
|
3611
3844
|
subject: id,
|
|
3612
|
-
message: `packageRules names ${id}, which no installed package declares; check the id (genesis
|
|
3845
|
+
message: `packageRules names ${id}, which no installed package declares; check the id (genesis catalog lists them) or remove it`
|
|
3613
3846
|
}));
|
|
3614
3847
|
}
|
|
3615
3848
|
function packageRuleIds(packages) {
|
|
@@ -3624,10 +3857,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
3624
3857
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
3625
3858
|
function sourceFiles(dir, rel = "") {
|
|
3626
3859
|
const out = [];
|
|
3627
|
-
for (const entry of readdirSync(
|
|
3860
|
+
for (const entry of readdirSync(path19.join(dir, rel)).sort()) {
|
|
3628
3861
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
3629
3862
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
3630
|
-
const stat = lstatSync(
|
|
3863
|
+
const stat = lstatSync(path19.join(dir, child));
|
|
3631
3864
|
if (stat.isSymbolicLink()) continue;
|
|
3632
3865
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
3633
3866
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -3650,13 +3883,13 @@ function matchPattern(pattern, spec) {
|
|
|
3650
3883
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
3651
3884
|
}
|
|
3652
3885
|
function tsconfigPaths(dir) {
|
|
3653
|
-
const file =
|
|
3886
|
+
const file = path19.join(dir, "tsconfig.json");
|
|
3654
3887
|
if (!existsSync(file)) return [];
|
|
3655
3888
|
try {
|
|
3656
3889
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
3657
3890
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
3658
|
-
const base =
|
|
3659
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
3891
|
+
const base = path19.resolve(dir, options.baseUrl ?? ".");
|
|
3892
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path19.resolve(base, t)) }));
|
|
3660
3893
|
} catch {
|
|
3661
3894
|
return [];
|
|
3662
3895
|
}
|
|
@@ -3670,8 +3903,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3670
3903
|
const hit = matchPattern(pattern, spec);
|
|
3671
3904
|
if (hit === null) continue;
|
|
3672
3905
|
return targets.some((t) => {
|
|
3673
|
-
const rel =
|
|
3674
|
-
return !rel.startsWith("..") && !
|
|
3906
|
+
const rel = path19.relative(pkg.dir, t.replace("*", hit));
|
|
3907
|
+
return !rel.startsWith("..") && !path19.isAbsolute(rel);
|
|
3675
3908
|
});
|
|
3676
3909
|
}
|
|
3677
3910
|
return null;
|
|
@@ -3684,7 +3917,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3684
3917
|
...Object.keys(json.optionalDependencies ?? {})
|
|
3685
3918
|
]);
|
|
3686
3919
|
for (const file of sourceFiles(pkg.dir)) {
|
|
3687
|
-
const code = stripForImports(readFileSync(
|
|
3920
|
+
const code = stripForImports(readFileSync(path19.join(pkg.dir, file), "utf8"));
|
|
3688
3921
|
if (code === null) continue;
|
|
3689
3922
|
const at = `${pkg.rel}/${file}`;
|
|
3690
3923
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -3709,9 +3942,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3709
3942
|
continue;
|
|
3710
3943
|
}
|
|
3711
3944
|
if (spec.startsWith(".")) {
|
|
3712
|
-
const target =
|
|
3713
|
-
const rel =
|
|
3714
|
-
if (rel.startsWith("..") ||
|
|
3945
|
+
const target = path19.resolve(pkg.dir, path19.dirname(file), spec);
|
|
3946
|
+
const rel = path19.relative(pkg.dir, target);
|
|
3947
|
+
if (rel.startsWith("..") || path19.isAbsolute(rel)) {
|
|
3715
3948
|
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` });
|
|
3716
3949
|
}
|
|
3717
3950
|
continue;
|
|
@@ -3725,20 +3958,35 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3725
3958
|
});
|
|
3726
3959
|
}
|
|
3727
3960
|
}
|
|
3728
|
-
|
|
3961
|
+
var NPM_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
3962
|
+
function migrationHome(pkg, named, locals) {
|
|
3963
|
+
if (named === void 0 || named === pkg.name) return { dir: pkg.dir };
|
|
3964
|
+
if (typeof named !== "string" || !NPM_NAME.test(named) || named.split("/").some((s) => s === "." || s === "..")) return { problem: `names the package ${JSON.stringify(named)}, which isn't a valid package name` };
|
|
3965
|
+
const dir = locals.find((l) => l.name === named)?.dir ?? findPackageDir(pkg.dir, named);
|
|
3966
|
+
return dir ? { dir } : { problem: `names the package ${named}, which isn't installed or a local package, so its test can't be checked` };
|
|
3967
|
+
}
|
|
3968
|
+
function checkMigrations(ctx, pkg, json, locals) {
|
|
3729
3969
|
const declaredFiles = /* @__PURE__ */ new Set();
|
|
3730
3970
|
for (const [id, raw] of Object.entries(rawBlocksOf(json))) {
|
|
3731
3971
|
const migrations = raw.migrations ?? [];
|
|
3732
3972
|
for (const m of migrations) {
|
|
3733
|
-
|
|
3973
|
+
const found = migrationHome(pkg, m.package, locals);
|
|
3974
|
+
if ("problem" in found) {
|
|
3975
|
+
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: typeof m.file === "string" ? m.file : id, message: `${pkg.name} block ${id}: a migration ${found.problem}` });
|
|
3976
|
+
continue;
|
|
3977
|
+
}
|
|
3978
|
+
const home = found.dir;
|
|
3979
|
+
const own = home === pkg.dir;
|
|
3980
|
+
if (own && typeof m.file === "string" && typeof m.test === "string") declaredFiles.add(m.file);
|
|
3981
|
+
const from = own ? "" : ` (in ${m.package})`;
|
|
3734
3982
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
3735
|
-
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file} has no pgTAP test; declare one as "test" beside it` });
|
|
3736
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
3737
|
-
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test} doesn't exist` });
|
|
3983
|
+
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` });
|
|
3984
|
+
} else if (typeof m.test === "string" && !existsSync(path19.join(home, m.test))) {
|
|
3985
|
+
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` });
|
|
3738
3986
|
}
|
|
3739
3987
|
}
|
|
3740
3988
|
}
|
|
3741
|
-
const dir =
|
|
3989
|
+
const dir = path19.join(pkg.dir, "migrations");
|
|
3742
3990
|
if (!existsSync(dir)) return;
|
|
3743
3991
|
const seen = /* @__PURE__ */ new Map();
|
|
3744
3992
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3747,7 +3995,7 @@ function checkMigrations(ctx, pkg, json) {
|
|
|
3747
3995
|
const other = seen.get(m[1]);
|
|
3748
3996
|
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` });
|
|
3749
3997
|
else seen.set(m[1], name);
|
|
3750
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
3998
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path19.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
3751
3999
|
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")})` });
|
|
3752
4000
|
}
|
|
3753
4001
|
}
|
|
@@ -3761,7 +4009,7 @@ function checkExports(ctx, pkg, json) {
|
|
|
3761
4009
|
walk(json.exports);
|
|
3762
4010
|
for (const t of targets) {
|
|
3763
4011
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
3764
|
-
if (!existsSync(
|
|
4012
|
+
if (!existsSync(path19.join(pkg.dir, t))) {
|
|
3765
4013
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
3766
4014
|
}
|
|
3767
4015
|
}
|
|
@@ -3779,11 +4027,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
3779
4027
|
function checkTaggedTests(ctx, pkg) {
|
|
3780
4028
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
3781
4029
|
if (!tests.length) return;
|
|
3782
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
4030
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path19.join(pkg.dir, f), "utf8")));
|
|
3783
4031
|
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>` });
|
|
3784
4032
|
}
|
|
3785
4033
|
function checkRegistered(ctx, pkg) {
|
|
3786
|
-
const file =
|
|
4034
|
+
const file = path19.join(ctx.root, "features.json");
|
|
3787
4035
|
if (!existsSync(file)) return;
|
|
3788
4036
|
let doc;
|
|
3789
4037
|
try {
|
|
@@ -3793,7 +4041,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
3793
4041
|
}
|
|
3794
4042
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
3795
4043
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
3796
|
-
if (top) forms.add(
|
|
4044
|
+
if (top) forms.add(path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/"));
|
|
3797
4045
|
const covered = (doc.features ?? []).some(
|
|
3798
4046
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
3799
4047
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -3823,8 +4071,8 @@ function mergeBaseOf(root, base) {
|
|
|
3823
4071
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
3824
4072
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
3825
4073
|
if (!top) return;
|
|
3826
|
-
const appRelative = (fromTop) =>
|
|
3827
|
-
const inRepo =
|
|
4074
|
+
const appRelative = (fromTop) => path19.relative(realpathSync(ctx.root), path19.join(top, fromTop)).split(path19.sep).join("/");
|
|
4075
|
+
const inRepo = path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/");
|
|
3828
4076
|
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");
|
|
3829
4077
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
3830
4078
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -3847,11 +4095,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
3847
4095
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
3848
4096
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
3849
4097
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
3850
|
-
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) =>
|
|
4098
|
+
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) => path19.join(top, f)) : [];
|
|
3851
4099
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
3852
4100
|
const named = naming.length > 0;
|
|
3853
4101
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
3854
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
4102
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path19.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
3855
4103
|
}
|
|
3856
4104
|
let jsonBefore = null;
|
|
3857
4105
|
try {
|
|
@@ -3861,7 +4109,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
3861
4109
|
}
|
|
3862
4110
|
const raw = json;
|
|
3863
4111
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
3864
|
-
const appInRepo =
|
|
4112
|
+
const appInRepo = path19.relative(top, realpathSync(ctx.root)).split(path19.sep).join("/");
|
|
3865
4113
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
3866
4114
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
3867
4115
|
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` });
|
|
@@ -3913,15 +4161,16 @@ function checkPackagesPack(ctx) {
|
|
|
3913
4161
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
3914
4162
|
}
|
|
3915
4163
|
for (const pkg of packages) {
|
|
3916
|
-
const json = JSON.parse(readFileSync(
|
|
4164
|
+
const json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
|
|
3917
4165
|
checkImports2(ctx, pkg, json);
|
|
3918
4166
|
checkExports(ctx, pkg, json);
|
|
3919
4167
|
checkBlocks(ctx, pkg, json);
|
|
3920
|
-
checkMigrations(ctx, pkg, json);
|
|
4168
|
+
checkMigrations(ctx, pkg, json, packages);
|
|
3921
4169
|
checkTaggedTests(ctx, pkg);
|
|
3922
4170
|
checkRegistered(ctx, pkg);
|
|
3923
4171
|
checkDoctorDeclaration(ctx, pkg, json);
|
|
3924
|
-
|
|
4172
|
+
const overlay = GENESIS_NAME.test(json.name) && overlayState(json.name, json).kind === "marked" && overlaySetupProblems(ctx.root, ctx.config, pkg.dir, json.name, json).length === 0;
|
|
4173
|
+
if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
3925
4174
|
}
|
|
3926
4175
|
}
|
|
3927
4176
|
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
@@ -4106,9 +4355,9 @@ function gitView(root, dir, base) {
|
|
|
4106
4355
|
function checkSupabasePack(ctx) {
|
|
4107
4356
|
const settings = ctx.config.supabase ?? {};
|
|
4108
4357
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
4109
|
-
const abs =
|
|
4358
|
+
const abs = path19.join(ctx.root, dir);
|
|
4110
4359
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
4111
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
4360
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path19.join(abs, n), "utf8")) }));
|
|
4112
4361
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
4113
4362
|
const base = settings.base ?? DEFAULT_BASE;
|
|
4114
4363
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -4125,7 +4374,7 @@ function checkSupabasePack(ctx) {
|
|
|
4125
4374
|
}
|
|
4126
4375
|
}
|
|
4127
4376
|
const since = settings.since;
|
|
4128
|
-
const afterSince = (file) => since === void 0 ||
|
|
4377
|
+
const afterSince = (file) => since === void 0 || path19.posix.basename(file) >= since;
|
|
4129
4378
|
if ("reason" in view && since === void 0) {
|
|
4130
4379
|
ctx.report({
|
|
4131
4380
|
rule: "migration-grants",
|
|
@@ -4377,17 +4626,32 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
4377
4626
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
4378
4627
|
function readReleaseManifest(root) {
|
|
4379
4628
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
4380
|
-
const file = dir &&
|
|
4629
|
+
const file = dir && path19.join(dir, "dist", "versions.json");
|
|
4381
4630
|
if (!file || !existsSync(file)) return null;
|
|
4382
4631
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
4383
4632
|
}
|
|
4384
4633
|
function checkVersionSkew(ctx) {
|
|
4385
4634
|
const manifest = readReleaseManifest(ctx.root);
|
|
4386
4635
|
if (!manifest) return;
|
|
4636
|
+
const overlays = markedOverlays(ctx);
|
|
4387
4637
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
4638
|
+
const overlay = overlays.get(name);
|
|
4639
|
+
if (overlay) {
|
|
4640
|
+
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
4641
|
+
if (from !== want) {
|
|
4642
|
+
ctx.report({
|
|
4643
|
+
rule: "version-skew",
|
|
4644
|
+
level: "warn",
|
|
4645
|
+
file: "package.json",
|
|
4646
|
+
subject: name,
|
|
4647
|
+
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).`
|
|
4648
|
+
});
|
|
4649
|
+
}
|
|
4650
|
+
continue;
|
|
4651
|
+
}
|
|
4388
4652
|
const dir = findPackageDir(ctx.root, name);
|
|
4389
4653
|
if (!dir) continue;
|
|
4390
|
-
const have = JSON.parse(readFileSync(
|
|
4654
|
+
const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
|
|
4391
4655
|
if (have === want) continue;
|
|
4392
4656
|
ctx.report({
|
|
4393
4657
|
rule: "version-skew",
|
|
@@ -4403,7 +4667,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
|
4403
4667
|
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)$/;
|
|
4404
4668
|
var readManifest = (dir) => {
|
|
4405
4669
|
try {
|
|
4406
|
-
return JSON.parse(readFileSync(
|
|
4670
|
+
return JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
|
|
4407
4671
|
} catch {
|
|
4408
4672
|
return null;
|
|
4409
4673
|
}
|
|
@@ -4417,18 +4681,18 @@ var real = (p) => {
|
|
|
4417
4681
|
};
|
|
4418
4682
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
4419
4683
|
function nodeModulesOf(dir) {
|
|
4420
|
-
const parent =
|
|
4421
|
-
return
|
|
4684
|
+
const parent = path19.dirname(dir);
|
|
4685
|
+
return path19.basename(parent).startsWith("@") ? path19.dirname(parent) : parent;
|
|
4422
4686
|
}
|
|
4423
4687
|
function packagesIn(nodeModules) {
|
|
4424
4688
|
if (!existsSync(nodeModules)) return [];
|
|
4425
4689
|
const out = [];
|
|
4426
4690
|
for (const entry of readdirSync(nodeModules)) {
|
|
4427
4691
|
if (entry.startsWith(".")) continue;
|
|
4428
|
-
const p =
|
|
4692
|
+
const p = path19.join(nodeModules, entry);
|
|
4429
4693
|
if (entry.startsWith("@")) {
|
|
4430
4694
|
try {
|
|
4431
|
-
for (const sub of readdirSync(p)) out.push(
|
|
4695
|
+
for (const sub of readdirSync(p)) out.push(path19.join(p, sub));
|
|
4432
4696
|
} catch {
|
|
4433
4697
|
}
|
|
4434
4698
|
} else {
|
|
@@ -4440,7 +4704,7 @@ function packagesIn(nodeModules) {
|
|
|
4440
4704
|
function genesisInstalls(root) {
|
|
4441
4705
|
const copies = /* @__PURE__ */ new Map();
|
|
4442
4706
|
const realRoot = real(root);
|
|
4443
|
-
const rel = (abs) =>
|
|
4707
|
+
const rel = (abs) => path19.relative(realRoot, abs).split(path19.sep).join("/") || ".";
|
|
4444
4708
|
const via = /* @__PURE__ */ new Map();
|
|
4445
4709
|
const record = (real2, manifest, by, range, root2) => {
|
|
4446
4710
|
let copy = copies.get(real2);
|
|
@@ -4485,7 +4749,7 @@ function genesisInstalls(root) {
|
|
|
4485
4749
|
if (!dir) return null;
|
|
4486
4750
|
if (!ownInstall || name in declared) return dir;
|
|
4487
4751
|
const realDir = real(dir);
|
|
4488
|
-
if (realDir.startsWith(realRoot +
|
|
4752
|
+
if (realDir.startsWith(realRoot + path19.sep)) return dir;
|
|
4489
4753
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
4490
4754
|
};
|
|
4491
4755
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -4493,7 +4757,7 @@ function genesisInstalls(root) {
|
|
|
4493
4757
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
4494
4758
|
});
|
|
4495
4759
|
const app = readManifest(root);
|
|
4496
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
4760
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path19.join(root, f)));
|
|
4497
4761
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
4498
4762
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
4499
4763
|
const runtimeDeps = {
|
|
@@ -4504,11 +4768,11 @@ function genesisInstalls(root) {
|
|
|
4504
4768
|
};
|
|
4505
4769
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
4506
4770
|
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
4507
|
-
const top =
|
|
4771
|
+
const top = path19.join(root, "node_modules");
|
|
4508
4772
|
walk(
|
|
4509
4773
|
"hoisted",
|
|
4510
4774
|
packagesIn(top).filter((dir) => {
|
|
4511
|
-
const name =
|
|
4775
|
+
const name = path19.relative(top, dir).split(path19.sep).join("/");
|
|
4512
4776
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
4513
4777
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
4514
4778
|
);
|
|
@@ -4550,7 +4814,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
4550
4814
|
}
|
|
4551
4815
|
}
|
|
4552
4816
|
function checkPeerRanges(ctx) {
|
|
4553
|
-
const rel = (abs) =>
|
|
4817
|
+
const rel = (abs) => path19.relative(ctx.root, abs).split(path19.sep).join("/");
|
|
4554
4818
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
4555
4819
|
for (const copy of copies) {
|
|
4556
4820
|
const dir = copy.absolutePath;
|
|
@@ -4580,9 +4844,9 @@ var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Dra
|
|
|
4580
4844
|
var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
4581
4845
|
var SHELL = /<AppShell(?=[\s>/])/;
|
|
4582
4846
|
var GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
4583
|
-
var PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView)$/;
|
|
4847
|
+
var PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView|RecordView)$/;
|
|
4584
4848
|
var EMBEDDED_RESOURCE_VIEW = /<ResourceView\b[^>]*?\blayout\s*=\s*(?:(["'`]) {8}\1|\{\s*(["'`]) {8}\2\s*\})[^>]*>/g;
|
|
4585
|
-
var PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView)$/;
|
|
4849
|
+
var PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView|RecordView)$/;
|
|
4586
4850
|
var isNative2 = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
4587
4851
|
var rendersRe = (names) => {
|
|
4588
4852
|
const list = [...names];
|
|
@@ -4634,6 +4898,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
4634
4898
|
if (owner.size === 0) return;
|
|
4635
4899
|
const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
|
|
4636
4900
|
const routes = routesDir(ctx);
|
|
4901
|
+
const overlays = markedOverlays(ctx);
|
|
4637
4902
|
for (const file of ctx.files) {
|
|
4638
4903
|
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
4639
4904
|
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
|
|
@@ -4644,6 +4909,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
4644
4909
|
const [, exported, name] = m;
|
|
4645
4910
|
const pkg = owner.get(name);
|
|
4646
4911
|
if (!pkg || imported.has(name) || routeComponents.has(name)) return;
|
|
4912
|
+
if (insideOverlayOf(overlays, file, pkg)) return;
|
|
4647
4913
|
if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
|
|
4648
4914
|
const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
|
|
4649
4915
|
if (!rendersJsx(body)) return;
|
|
@@ -4932,11 +5198,11 @@ function appScripts(root) {
|
|
|
4932
5198
|
const out = [];
|
|
4933
5199
|
const walk = (dir) => {
|
|
4934
5200
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
4935
|
-
const abs =
|
|
5201
|
+
const abs = path19.join(dir, entry.name);
|
|
4936
5202
|
if (entry.isDirectory()) {
|
|
4937
5203
|
if (!SKIP_DIRS3.has(entry.name)) walk(abs);
|
|
4938
5204
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
4939
|
-
out.push(
|
|
5205
|
+
out.push(path19.relative(root, abs).split(path19.sep).join("/"));
|
|
4940
5206
|
}
|
|
4941
5207
|
}
|
|
4942
5208
|
};
|
|
@@ -5024,7 +5290,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
5024
5290
|
function moduleFiles(ctx) {
|
|
5025
5291
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
5026
5292
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
5027
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
5293
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path19.join(ctx.root, rel), "utf8"), true) }));
|
|
5028
5294
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
5029
5295
|
}
|
|
5030
5296
|
function checkStudioServerImports(ctx) {
|
|
@@ -5060,7 +5326,7 @@ var REMOVED_WORDS = {
|
|
|
5060
5326
|
};
|
|
5061
5327
|
function checkRemovedScopeNames(ctx) {
|
|
5062
5328
|
let augmentedMemo;
|
|
5063
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
5329
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path19.join(ctx.root, rel), "utf8")));
|
|
5064
5330
|
for (const file of ctx.files) {
|
|
5065
5331
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
5066
5332
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -5087,6 +5353,98 @@ function checkRemovedScopeNames(ctx) {
|
|
|
5087
5353
|
}
|
|
5088
5354
|
}
|
|
5089
5355
|
}
|
|
5356
|
+
var SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
5357
|
+
var DECLARATION = /\/\*\*((?:(?!\*\/)[\s\S])*)\*\/\s*\n(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/g;
|
|
5358
|
+
function stabilityTagsIn(dts) {
|
|
5359
|
+
const tags = /* @__PURE__ */ new Map();
|
|
5360
|
+
for (const m of dts.matchAll(DECLARATION)) {
|
|
5361
|
+
const doc = m[1].replace(/^[ \t]*\*?[ \t]*/gm, "");
|
|
5362
|
+
const deprecated = /^@deprecated\b[ \t]*([\s\S]*?)(?=^@|(?![\s\S]))/m.exec(doc);
|
|
5363
|
+
const stability = /^@stability\s+(Experimental|Beta|Stable|Deprecated)\b/im.exec(doc)?.[1]?.toLowerCase();
|
|
5364
|
+
const note = deprecated?.[1].replace(/\s+/g, " ").trim();
|
|
5365
|
+
if (deprecated) tags.set(m[2], { stability: "deprecated", ...note ? { note } : {} });
|
|
5366
|
+
else if (stability) tags.set(m[2], { stability });
|
|
5367
|
+
}
|
|
5368
|
+
return tags;
|
|
5369
|
+
}
|
|
5370
|
+
function genesisNamedImports(code) {
|
|
5371
|
+
const out = [];
|
|
5372
|
+
const re = /import\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']((@marktiderman\/genesis[\w-]*)(?:\/[^"']*)?)["']/g;
|
|
5373
|
+
for (const m of code.matchAll(re)) {
|
|
5374
|
+
const names = m[1].split(",").map((n) => n.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim()).filter(Boolean);
|
|
5375
|
+
out.push({ pkg: m[3], specifier: m[2], names, line: code.slice(0, m.index).split("\n").length });
|
|
5376
|
+
}
|
|
5377
|
+
return out;
|
|
5378
|
+
}
|
|
5379
|
+
function declarationFiles(dir, out = []) {
|
|
5380
|
+
for (const name of readdirSync(dir)) {
|
|
5381
|
+
const full = path19.join(dir, name);
|
|
5382
|
+
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
5383
|
+
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
5384
|
+
}
|
|
5385
|
+
return out;
|
|
5386
|
+
}
|
|
5387
|
+
function packageDir(root, pkg) {
|
|
5388
|
+
for (let dir = path19.resolve(root); ; dir = path19.dirname(dir)) {
|
|
5389
|
+
const candidate = path19.join(dir, "node_modules", ...pkg.split("/"));
|
|
5390
|
+
if (existsSync(path19.join(candidate, "package.json"))) return candidate;
|
|
5391
|
+
if (path19.dirname(dir) === dir) return null;
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
function readPackageTags(dir) {
|
|
5395
|
+
const pkg = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
|
|
5396
|
+
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
5397
|
+
const dist = path19.join(dir, "dist");
|
|
5398
|
+
if (!existsSync(dist)) return tags;
|
|
5399
|
+
for (const file of declarationFiles(dist)) {
|
|
5400
|
+
const text = readFileSync(file, "utf8");
|
|
5401
|
+
tags.byFile.set(file, stabilityTagsIn(text));
|
|
5402
|
+
for (const m of text.matchAll(/^(?:export\s+)?(?:declare\s+)?(?:abstract\s+)?(?:function|const|let|class|interface|type|enum|namespace)\s+([A-Za-z_$][\w$]*)/gm)) {
|
|
5403
|
+
const files = tags.declaredIn.get(m[1]) ?? [];
|
|
5404
|
+
if (!files.includes(file)) files.push(file);
|
|
5405
|
+
tags.declaredIn.set(m[1], files);
|
|
5406
|
+
}
|
|
5407
|
+
}
|
|
5408
|
+
return tags;
|
|
5409
|
+
}
|
|
5410
|
+
function entryFile(tags, pkg, specifier) {
|
|
5411
|
+
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
5412
|
+
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
5413
|
+
const types = typeof target === "object" && target ? target.types : null;
|
|
5414
|
+
return typeof types === "string" ? path19.join(tags.dir, types) : null;
|
|
5415
|
+
}
|
|
5416
|
+
function tagFor(tags, entry, name) {
|
|
5417
|
+
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
5418
|
+
const all = (tags.declaredIn.get(name) ?? []).map((f) => tags.byFile.get(f)?.get(name));
|
|
5419
|
+
if (!all.length || all.some((t) => !t)) return void 0;
|
|
5420
|
+
return all.every((t) => t.stability === all[0].stability) ? all[0] : void 0;
|
|
5421
|
+
}
|
|
5422
|
+
function checkStabilityImports(ctx) {
|
|
5423
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
5424
|
+
const tagsOf = (pkg) => {
|
|
5425
|
+
if (!cache2.has(pkg)) {
|
|
5426
|
+
const dir = packageDir(ctx.root, pkg);
|
|
5427
|
+
cache2.set(pkg, dir ? readPackageTags(dir) : null);
|
|
5428
|
+
}
|
|
5429
|
+
return cache2.get(pkg);
|
|
5430
|
+
};
|
|
5431
|
+
for (const file of ctx.files) {
|
|
5432
|
+
if (!SCRIPT_EXTS6.has(file.ext)) continue;
|
|
5433
|
+
for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
|
|
5434
|
+
const tags = tagsOf(pkg);
|
|
5435
|
+
if (!tags) continue;
|
|
5436
|
+
const entry = entryFile(tags, pkg, specifier);
|
|
5437
|
+
for (const name of names) {
|
|
5438
|
+
const tag = tagFor(tags, entry, name);
|
|
5439
|
+
if (tag?.stability === "deprecated") {
|
|
5440
|
+
ctx.report({ rule: "deprecated-import", level: "warn", file: file.path, line, subject: name, message: `${name} from ${pkg} is deprecated and goes at the next major${tag.note ? `: ${tag.note}` : ""}` });
|
|
5441
|
+
} else if (tag && (tag.stability === "beta" || tag.stability === "experimental")) {
|
|
5442
|
+
ctx.report({ rule: "beta-import", level: "info", file: file.path, line, subject: name, message: `${name} from ${pkg} is ${tag.stability}: it may still change in a minor release` });
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
}
|
|
5447
|
+
}
|
|
5090
5448
|
function git3(root, args) {
|
|
5091
5449
|
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
5092
5450
|
return r.status === 0 ? r.stdout : null;
|
|
@@ -5108,7 +5466,7 @@ function showAt(dir, rev, file) {
|
|
|
5108
5466
|
function configAtBase(root, base, explicitFile) {
|
|
5109
5467
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
5110
5468
|
if (!mergeBase) return null;
|
|
5111
|
-
const candidates = explicitFile ? [{ dir:
|
|
5469
|
+
const candidates = explicitFile ? [{ dir: path19.dirname(explicitFile), file: path19.basename(explicitFile), explicit: true }] : [
|
|
5112
5470
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
5113
5471
|
{ dir: root, file: "package.json", explicit: false }
|
|
5114
5472
|
];
|
|
@@ -5220,7 +5578,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5220
5578
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
5221
5579
|
let current = null;
|
|
5222
5580
|
try {
|
|
5223
|
-
current = lf(readFileSync(
|
|
5581
|
+
current = lf(readFileSync(path19.join(ctx.root, out), "utf8"));
|
|
5224
5582
|
} catch {
|
|
5225
5583
|
current = null;
|
|
5226
5584
|
}
|
|
@@ -5244,7 +5602,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5244
5602
|
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}` });
|
|
5245
5603
|
return;
|
|
5246
5604
|
}
|
|
5247
|
-
const target =
|
|
5605
|
+
const target = path19.relative(process.cwd(), path19.join(ctx.root, out)) || out;
|
|
5248
5606
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
5249
5607
|
if (current !== expected) {
|
|
5250
5608
|
ctx.report({
|
|
@@ -5264,7 +5622,7 @@ var CORE = [
|
|
|
5264
5622
|
},
|
|
5265
5623
|
{
|
|
5266
5624
|
need: "a page inside the app shell",
|
|
5267
|
-
use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` (from `@marktiderman/genesis-ui/data`)",
|
|
5625
|
+
use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` / `RecordView` (from `@marktiderman/genesis-ui/data`)",
|
|
5268
5626
|
import: "@marktiderman/genesis-ui",
|
|
5269
5627
|
rule: "page-layout",
|
|
5270
5628
|
from: "genesis-cli"
|
|
@@ -5351,7 +5709,7 @@ function renderSkill(rows) {
|
|
|
5351
5709
|
"",
|
|
5352
5710
|
catalogTable(rows, { docs: true }),
|
|
5353
5711
|
"",
|
|
5354
|
-
"`genesis
|
|
5712
|
+
"`genesis catalog` prints the same list; `genesis doctor` enforces the rules named above.",
|
|
5355
5713
|
""
|
|
5356
5714
|
].join("\n");
|
|
5357
5715
|
}
|
|
@@ -5362,7 +5720,7 @@ function renderAgentsBlock(rows) {
|
|
|
5362
5720
|
"",
|
|
5363
5721
|
"Generated by `genesis agents` from the installed Genesis packages. Don't edit this block; run `genesis agents` after upgrading Genesis.",
|
|
5364
5722
|
"",
|
|
5365
|
-
`Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis
|
|
5723
|
+
`Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis catalog\`).`,
|
|
5366
5724
|
"",
|
|
5367
5725
|
...RULES.map((r) => `- ${r}`),
|
|
5368
5726
|
"",
|
|
@@ -5387,8 +5745,8 @@ function currentAgentsBlock(agents) {
|
|
|
5387
5745
|
var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
5388
5746
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
5389
5747
|
const rows = primitivesCatalog(packages);
|
|
5390
|
-
const skill = read(
|
|
5391
|
-
const block = currentAgentsBlock(read(
|
|
5748
|
+
const skill = read(path19.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
5749
|
+
const block = currentAgentsBlock(read(path19.join(root, agentsFile)));
|
|
5392
5750
|
return {
|
|
5393
5751
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
5394
5752
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -5410,8 +5768,9 @@ function checkAgentGuide(ctx) {
|
|
|
5410
5768
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
5411
5769
|
}
|
|
5412
5770
|
}
|
|
5771
|
+
var RATCHETED_BY_DEFAULT = ["deprecated-import"];
|
|
5413
5772
|
async function runDoctor(options = {}) {
|
|
5414
|
-
const root =
|
|
5773
|
+
const root = path19.resolve(options.root ?? process.cwd());
|
|
5415
5774
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
5416
5775
|
const config = loaded.config;
|
|
5417
5776
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -5425,7 +5784,7 @@ async function runDoctor(options = {}) {
|
|
|
5425
5784
|
if (builtinIds.has(p.id) || META_RULES.has(p.id)) throw new DoctorConfigError(`doctor.patterns: "${p.id}" is a built-in rule id; pick another`);
|
|
5426
5785
|
}
|
|
5427
5786
|
const raw = [];
|
|
5428
|
-
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, report: (f) => raw.push(f) };
|
|
5787
|
+
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
5429
5788
|
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
5430
5789
|
try {
|
|
5431
5790
|
await plugin.check(ctx);
|
|
@@ -5439,10 +5798,11 @@ async function runDoctor(options = {}) {
|
|
|
5439
5798
|
if (failure) raw.push(failure);
|
|
5440
5799
|
}
|
|
5441
5800
|
raw.push(...unknownPackageRuleSettings(config, packages, raw));
|
|
5442
|
-
const newOnly = /* @__PURE__ */ new Set([...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
|
|
5801
|
+
const newOnly = /* @__PURE__ */ new Set([...RATCHETED_BY_DEFAULT, ...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
|
|
5443
5802
|
let changed = null;
|
|
5444
5803
|
let skipped = false;
|
|
5445
|
-
|
|
5804
|
+
const ratchetNeeded = newOnly.size > RATCHETED_BY_DEFAULT.length || raw.some((f) => RATCHETED_BY_DEFAULT.includes(f.rule));
|
|
5805
|
+
if (options.base && (ratchetNeeded || config.ratchet)) {
|
|
5446
5806
|
changed = options.changedFiles ? new Set(options.changedFiles) : changedSince(root, options.base);
|
|
5447
5807
|
skipped ||= !changed;
|
|
5448
5808
|
}
|
|
@@ -5464,7 +5824,7 @@ async function runDoctor(options = {}) {
|
|
|
5464
5824
|
}
|
|
5465
5825
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
5466
5826
|
if (options.base && changed) {
|
|
5467
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
5827
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path19.join(root, f)) });
|
|
5468
5828
|
}
|
|
5469
5829
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
5470
5830
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -5506,7 +5866,9 @@ function builtinChecks(config, options = {}) {
|
|
|
5506
5866
|
{ name: "resource-view-trees", check: checkTreeViews },
|
|
5507
5867
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
5508
5868
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
5869
|
+
{ name: "stability-imports", check: checkStabilityImports },
|
|
5509
5870
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
5871
|
+
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
5510
5872
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
5511
5873
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
5512
5874
|
];
|
|
@@ -5569,7 +5931,7 @@ function formatReport(result) {
|
|
|
5569
5931
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
5570
5932
|
}
|
|
5571
5933
|
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
5572
|
-
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis
|
|
5934
|
+
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
5573
5935
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
5574
5936
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
5575
5937
|
return lines.join("\n");
|
|
@@ -5640,15 +6002,15 @@ ${formatProblems(result)}`);
|
|
|
5640
6002
|
}
|
|
5641
6003
|
}
|
|
5642
6004
|
};
|
|
5643
|
-
const explicit = /* @__PURE__ */ new Set([
|
|
6005
|
+
const explicit = /* @__PURE__ */ new Set([path19.join(root, "genesis.config.json"), ...options.configPath ? [path19.resolve(root, options.configPath)] : []]);
|
|
5644
6006
|
try {
|
|
5645
6007
|
const { config } = loadConfig(root, options.configPath);
|
|
5646
|
-
if (config.rulesDoc) explicit.add(
|
|
6008
|
+
if (config.rulesDoc) explicit.add(path19.resolve(root, config.rulesDoc));
|
|
5647
6009
|
} catch {
|
|
5648
6010
|
}
|
|
5649
6011
|
const schedule = (file) => {
|
|
5650
|
-
if (!explicit.has(
|
|
5651
|
-
const rel =
|
|
6012
|
+
if (!explicit.has(path19.resolve(file))) {
|
|
6013
|
+
const rel = path19.relative(root, file).split(path19.sep).join("/");
|
|
5652
6014
|
if (rel.startsWith("..") || rel.includes("node_modules/")) return;
|
|
5653
6015
|
}
|
|
5654
6016
|
clearTimeout(timer);
|