@marktiderman/genesis-cli 1.16.2 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -8
- package/dist/cli.js +1620 -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/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/doctor.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, readdirSync, statSync, realpathSync, mkdirSync, writeFileSync, 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 resolve16 = (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
|
+
resolve16(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()) resolve16(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 (path30) => res.some((re) => re.test(path30));
|
|
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));
|
|
@@ -1932,15 +2051,112 @@ async function loadPlugins(specs, configDir) {
|
|
|
1932
2051
|
}
|
|
1933
2052
|
function resolvePlugin(id, configDir) {
|
|
1934
2053
|
try {
|
|
1935
|
-
if (id.startsWith(".") ||
|
|
2054
|
+
if (id.startsWith(".") || path19.isAbsolute(id)) return resolveFrom(path19.resolve(configDir, id), configDir);
|
|
1936
2055
|
return resolveFrom(id, configDir);
|
|
1937
2056
|
} catch {
|
|
1938
2057
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
1939
2058
|
}
|
|
1940
2059
|
}
|
|
1941
2060
|
function resolveFrom(id, from) {
|
|
1942
|
-
return createRequire(
|
|
2061
|
+
return createRequire(path19.join(from, "noop.js")).resolve(id);
|
|
2062
|
+
}
|
|
2063
|
+
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
2064
|
+
var OVERLAY_NOTICE_DAYS = 14;
|
|
2065
|
+
var OVERLAY_WARN_DAYS = 30;
|
|
2066
|
+
function overlayState(name, json) {
|
|
2067
|
+
const raw = json?.genesis?.overlay;
|
|
2068
|
+
if (raw === void 0) return { kind: "none" };
|
|
2069
|
+
const problems = [];
|
|
2070
|
+
const marker = readOverlayMarker(name, raw, problems);
|
|
2071
|
+
return marker ? { kind: "marked", marker } : { kind: "invalid", problems };
|
|
1943
2072
|
}
|
|
2073
|
+
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2074
|
+
const problems = [];
|
|
2075
|
+
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2076
|
+
const rel = path19.relative(path19.resolve(root), path19.resolve(dir)).split(path19.sep).join("/");
|
|
2077
|
+
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2078
|
+
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2079
|
+
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})`);
|
|
2080
|
+
return problems;
|
|
2081
|
+
}
|
|
2082
|
+
function markedOverlays(ctx) {
|
|
2083
|
+
const out = /* @__PURE__ */ new Map();
|
|
2084
|
+
for (const p of ctx.packages) {
|
|
2085
|
+
if (!p.local || !p.overlay) continue;
|
|
2086
|
+
if (overlaySetupProblems(ctx.root, ctx.config, p.dir, p.name, { private: p.private }).length) continue;
|
|
2087
|
+
out.set(p.name, { dir: p.dir, marker: p.overlay });
|
|
2088
|
+
}
|
|
2089
|
+
return out;
|
|
2090
|
+
}
|
|
2091
|
+
function insideOverlayOf(overlays, file, packageName3) {
|
|
2092
|
+
const dir = overlays.get(packageName3)?.dir;
|
|
2093
|
+
return dir !== void 0 && inside(dir, file.absolutePath);
|
|
2094
|
+
}
|
|
2095
|
+
function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
|
|
2096
|
+
const [y, m, d] = since.split("-").map(Number);
|
|
2097
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
2098
|
+
return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
|
|
2099
|
+
}
|
|
2100
|
+
var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
|
|
2101
|
+
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
2102
|
+
let packages;
|
|
2103
|
+
try {
|
|
2104
|
+
packages = localPackages(ctx.root);
|
|
2105
|
+
} catch {
|
|
2106
|
+
return;
|
|
2107
|
+
}
|
|
2108
|
+
for (const pkg of packages) {
|
|
2109
|
+
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
2110
|
+
const file = `${pkg.rel}/package.json`;
|
|
2111
|
+
let json;
|
|
2112
|
+
try {
|
|
2113
|
+
json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
|
|
2114
|
+
} catch {
|
|
2115
|
+
continue;
|
|
2116
|
+
}
|
|
2117
|
+
const state = overlayState(pkg.name, json);
|
|
2118
|
+
if (state.kind === "none") {
|
|
2119
|
+
ctx.report({
|
|
2120
|
+
rule: "overlay-unmarked",
|
|
2121
|
+
file,
|
|
2122
|
+
subject: pkg.name,
|
|
2123
|
+
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`
|
|
2124
|
+
});
|
|
2125
|
+
continue;
|
|
2126
|
+
}
|
|
2127
|
+
if (state.kind === "invalid") {
|
|
2128
|
+
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
2129
|
+
continue;
|
|
2130
|
+
}
|
|
2131
|
+
const { marker } = state;
|
|
2132
|
+
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 });
|
|
2133
|
+
const age = overlayAgeDays(marker.since, now);
|
|
2134
|
+
if (age < -1) {
|
|
2135
|
+
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` });
|
|
2136
|
+
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
2137
|
+
ctx.report({
|
|
2138
|
+
rule: "overlay-age",
|
|
2139
|
+
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
2140
|
+
file,
|
|
2141
|
+
subject: pkg.name,
|
|
2142
|
+
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)`
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
const upstream = overlayUpstream(marker).version;
|
|
2146
|
+
const version = typeof json.version === "string" ? json.version : "";
|
|
2147
|
+
if (LOCAL_VERSION.exec(version)?.[1] !== upstream) {
|
|
2148
|
+
ctx.report({
|
|
2149
|
+
rule: "overlay-version",
|
|
2150
|
+
level: "warn",
|
|
2151
|
+
file,
|
|
2152
|
+
subject: version || "(none)",
|
|
2153
|
+
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
// src/doctor/rules.ts
|
|
1944
2160
|
var BUILTIN_RULES = [
|
|
1945
2161
|
"local-primitives",
|
|
1946
2162
|
"starter-leftover",
|
|
@@ -1966,6 +2182,9 @@ var BUILTIN_RULES = [
|
|
|
1966
2182
|
"studio-server-auth-import",
|
|
1967
2183
|
"removed-scope-name",
|
|
1968
2184
|
"scope-practice-id",
|
|
2185
|
+
// export maturity (stability.ts)
|
|
2186
|
+
"deprecated-import",
|
|
2187
|
+
"beta-import",
|
|
1969
2188
|
// native pack
|
|
1970
2189
|
"native-raw-primitive",
|
|
1971
2190
|
"native-literal-color",
|
|
@@ -1991,6 +2210,11 @@ var BUILTIN_RULES = [
|
|
|
1991
2210
|
"package-block-invalid",
|
|
1992
2211
|
"package-untagged-tests",
|
|
1993
2212
|
"package-doctor-declaration",
|
|
2213
|
+
// overlays (overlays.ts)
|
|
2214
|
+
"overlay-unmarked",
|
|
2215
|
+
"overlay-invalid",
|
|
2216
|
+
"overlay-age",
|
|
2217
|
+
"overlay-version",
|
|
1994
2218
|
// package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
|
|
1995
2219
|
"package-rules-invalid",
|
|
1996
2220
|
"package-rule-override",
|
|
@@ -2019,7 +2243,7 @@ function importSpecifiers(file) {
|
|
|
2019
2243
|
}
|
|
2020
2244
|
function checkProjectLayout(ctx) {
|
|
2021
2245
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2022
|
-
if (existsSync(
|
|
2246
|
+
if (existsSync(path19.join(ctx.root, dir))) {
|
|
2023
2247
|
ctx.report({
|
|
2024
2248
|
rule: "local-primitives",
|
|
2025
2249
|
file: dir,
|
|
@@ -2029,7 +2253,7 @@ function checkProjectLayout(ctx) {
|
|
|
2029
2253
|
}
|
|
2030
2254
|
}
|
|
2031
2255
|
for (const file of STARTER_LEFTOVERS) {
|
|
2032
|
-
if (existsSync(
|
|
2256
|
+
if (existsSync(path19.join(ctx.root, file))) {
|
|
2033
2257
|
ctx.report({
|
|
2034
2258
|
rule: "starter-leftover",
|
|
2035
2259
|
level: "warn",
|
|
@@ -2059,8 +2283,9 @@ function checkImports(ctx) {
|
|
|
2059
2283
|
function checkRawTags(ctx) {
|
|
2060
2284
|
const tags = [...ctx.genesis.rawTags].map(([tag, component]) => [tag, component, new RegExp(`<${tag}(?=[\\s>/]|$)`)]);
|
|
2061
2285
|
if (tags.length === 0) return;
|
|
2286
|
+
const overlays = markedOverlays(ctx);
|
|
2062
2287
|
for (const file of ctx.files) {
|
|
2063
|
-
if (!JSX_EXTS.has(file.ext)) continue;
|
|
2288
|
+
if (!JSX_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
2064
2289
|
file.code.split("\n").forEach((text, i) => {
|
|
2065
2290
|
for (const [tag, component, re] of tags) {
|
|
2066
2291
|
if (re.test(text)) {
|
|
@@ -2118,7 +2343,7 @@ function checkTokens(ctx) {
|
|
|
2118
2343
|
}
|
|
2119
2344
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
2120
2345
|
if (/[*?]/.test(pattern)) continue;
|
|
2121
|
-
const abs =
|
|
2346
|
+
const abs = path19.join(ctx.root, pattern);
|
|
2122
2347
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
2123
2348
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
2124
2349
|
}
|
|
@@ -2135,9 +2360,10 @@ function checkTokens(ctx) {
|
|
|
2135
2360
|
}
|
|
2136
2361
|
}
|
|
2137
2362
|
function checkShadowedExports(ctx) {
|
|
2363
|
+
const overlays = markedOverlays(ctx);
|
|
2138
2364
|
const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
|
|
2139
2365
|
for (const file of ctx.files) {
|
|
2140
|
-
if (!SCRIPT_EXTS.has(file.ext)) continue;
|
|
2366
|
+
if (!SCRIPT_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
2141
2367
|
file.code.split("\n").forEach((text, i) => {
|
|
2142
2368
|
for (const m of text.matchAll(re)) {
|
|
2143
2369
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
@@ -2221,10 +2447,10 @@ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts"
|
|
|
2221
2447
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
2222
2448
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2223
2449
|
function resolveLocal(root, fromFile, spec) {
|
|
2224
|
-
const bases = spec.startsWith(".") ? [
|
|
2450
|
+
const bases = spec.startsWith(".") ? [path19.resolve(path19.dirname(fromFile), spec)] : [path19.join(root, spec.slice(2)), path19.join(root, "src", spec.slice(2))];
|
|
2225
2451
|
for (const base of bases) {
|
|
2226
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
2227
|
-
(p) => SCRIPT_EXTS2.has(
|
|
2452
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path19.join(base, `index${e}`))].find(
|
|
2453
|
+
(p) => SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p)
|
|
2228
2454
|
);
|
|
2229
2455
|
if (hit) return hit;
|
|
2230
2456
|
}
|
|
@@ -2344,6 +2570,7 @@ function checkNativePack(ctx) {
|
|
|
2344
2570
|
}
|
|
2345
2571
|
var RN = String.raw`["']react-native["']`;
|
|
2346
2572
|
function checkRawPrimitives(ctx, pkg) {
|
|
2573
|
+
const overlays = markedOverlays(ctx);
|
|
2347
2574
|
const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
|
|
2348
2575
|
const named = [
|
|
2349
2576
|
// import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
|
|
@@ -2357,7 +2584,7 @@ function checkRawPrimitives(ctx, pkg) {
|
|
|
2357
2584
|
];
|
|
2358
2585
|
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
2359
2586
|
for (const file of ctx.files) {
|
|
2360
|
-
if (!SCRIPT_EXTS3.has(file.ext)) continue;
|
|
2587
|
+
if (!SCRIPT_EXTS3.has(file.ext) || insideOverlayOf(overlays, file, NATIVE_UI_PACKAGE)) continue;
|
|
2361
2588
|
const code = file.code;
|
|
2362
2589
|
const report = (name, at) => {
|
|
2363
2590
|
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
@@ -2406,7 +2633,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2406
2633
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
2407
2634
|
const code = file.code;
|
|
2408
2635
|
const hidden = HIDES_HEADER.exec(code);
|
|
2409
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
2636
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path19.posix.dirname(file.path), file.path);
|
|
2410
2637
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
2411
2638
|
if (hidden && own) {
|
|
2412
2639
|
reported.add(file.path);
|
|
@@ -2434,7 +2661,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
2434
2661
|
}
|
|
2435
2662
|
for (const file of ctx.files) {
|
|
2436
2663
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
2437
|
-
const layout = hidingLayouts.get(
|
|
2664
|
+
const layout = hidingLayouts.get(path19.posix.dirname(file.path));
|
|
2438
2665
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
2439
2666
|
if (!layout || !own) continue;
|
|
2440
2667
|
ctx.report({
|
|
@@ -2456,13 +2683,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
2456
2683
|
}
|
|
2457
2684
|
function routerRoot(ctx) {
|
|
2458
2685
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
2459
|
-
return existsSync(
|
|
2686
|
+
return existsSync(path19.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
2460
2687
|
}
|
|
2461
2688
|
function checkScreenLayouts(ctx, pkg) {
|
|
2462
2689
|
const layouts = nativeLayouts(pkg);
|
|
2463
2690
|
if (layouts.length === 0) return;
|
|
2464
2691
|
const rootDir = routerRoot(ctx);
|
|
2465
|
-
if (!existsSync(
|
|
2692
|
+
if (!existsSync(path19.join(ctx.root, rootDir))) {
|
|
2466
2693
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
2467
2694
|
return;
|
|
2468
2695
|
}
|
|
@@ -2518,7 +2745,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
2518
2745
|
function readExpoConfigs(root) {
|
|
2519
2746
|
const out = [];
|
|
2520
2747
|
for (const name of EXPO_CONFIGS) {
|
|
2521
|
-
const abs =
|
|
2748
|
+
const abs = path19.join(root, name);
|
|
2522
2749
|
if (!existsSync(abs)) continue;
|
|
2523
2750
|
const text = readFileSync(abs, "utf8");
|
|
2524
2751
|
let json = null;
|
|
@@ -2552,13 +2779,13 @@ function pluginOptions(json, module) {
|
|
|
2552
2779
|
return null;
|
|
2553
2780
|
}
|
|
2554
2781
|
function dependencies(root) {
|
|
2555
|
-
const file =
|
|
2782
|
+
const file = path19.join(root, "package.json");
|
|
2556
2783
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
2557
2784
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
2558
2785
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
2559
2786
|
}
|
|
2560
2787
|
function runtimeDependencies(root) {
|
|
2561
|
-
const file =
|
|
2788
|
+
const file = path19.join(root, "package.json");
|
|
2562
2789
|
if (!existsSync(file)) return {};
|
|
2563
2790
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
2564
2791
|
}
|
|
@@ -2932,14 +3159,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
2932
3159
|
seen.add(file);
|
|
2933
3160
|
const json = readJsonc(file);
|
|
2934
3161
|
if (!json) return {};
|
|
2935
|
-
const dir =
|
|
3162
|
+
const dir = path19.dirname(file);
|
|
2936
3163
|
let merged = {};
|
|
2937
3164
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2938
3165
|
for (const ext of parents) {
|
|
2939
3166
|
if (typeof ext !== "string") continue;
|
|
2940
3167
|
let target = null;
|
|
2941
|
-
if (ext.startsWith(".") ||
|
|
2942
|
-
const abs =
|
|
3168
|
+
if (ext.startsWith(".") || path19.isAbsolute(ext)) {
|
|
3169
|
+
const abs = path19.resolve(dir, ext);
|
|
2943
3170
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2944
3171
|
} else {
|
|
2945
3172
|
const parts = ext.split("/");
|
|
@@ -2947,14 +3174,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
2947
3174
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2948
3175
|
if (pkgDir) {
|
|
2949
3176
|
const sub = parts.slice(nameLength).join("/");
|
|
2950
|
-
const abs =
|
|
3177
|
+
const abs = path19.join(pkgDir, sub || "tsconfig.json");
|
|
2951
3178
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2952
3179
|
}
|
|
2953
3180
|
}
|
|
2954
3181
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2955
3182
|
}
|
|
2956
3183
|
const opts = json.compilerOptions ?? {};
|
|
2957
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
3184
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path19.resolve(dir, opts.baseUrl);
|
|
2958
3185
|
if (opts.paths && typeof opts.paths === "object") {
|
|
2959
3186
|
merged.paths = opts.paths;
|
|
2960
3187
|
merged.pathsDir = dir;
|
|
@@ -2965,7 +3192,7 @@ function aliases(root) {
|
|
|
2965
3192
|
const table = [];
|
|
2966
3193
|
let baseUrl = null;
|
|
2967
3194
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2968
|
-
const file =
|
|
3195
|
+
const file = path19.join(root, name);
|
|
2969
3196
|
if (!existsSync(file)) continue;
|
|
2970
3197
|
const config = readTsconfig(root, file);
|
|
2971
3198
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -2973,22 +3200,22 @@ function aliases(root) {
|
|
|
2973
3200
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2974
3201
|
if (!Array.isArray(targets)) continue;
|
|
2975
3202
|
const exact = !pattern.endsWith("*");
|
|
2976
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
3203
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path19.join(base, String(t).replace(/\*$/, ""))) });
|
|
2977
3204
|
}
|
|
2978
3205
|
}
|
|
2979
|
-
const pkg = readJsonc(
|
|
3206
|
+
const pkg = readJsonc(path19.join(root, "package.json"));
|
|
2980
3207
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2981
3208
|
if (typeof target !== "string") continue;
|
|
2982
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
3209
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path19.join(root, target.replace(/\*.*$/, ""))] });
|
|
2983
3210
|
}
|
|
2984
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
3211
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path19.join(root, "src") + path19.sep, root + path19.sep] });
|
|
2985
3212
|
return { table, baseUrl };
|
|
2986
3213
|
}
|
|
2987
3214
|
function resolveFile(base) {
|
|
2988
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
3215
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path19.join(base, `index${e}`))];
|
|
2989
3216
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2990
3217
|
for (const p of tries) {
|
|
2991
|
-
if (SCRIPT_EXTS2.has(
|
|
3218
|
+
if (SCRIPT_EXTS2.has(path19.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2992
3219
|
}
|
|
2993
3220
|
return null;
|
|
2994
3221
|
}
|
|
@@ -3002,7 +3229,7 @@ function createTrail(ctx) {
|
|
|
3002
3229
|
const { table, baseUrl } = aliases(ctx.root);
|
|
3003
3230
|
let declared = null;
|
|
3004
3231
|
try {
|
|
3005
|
-
const pkg = JSON.parse(readFileSync(
|
|
3232
|
+
const pkg = JSON.parse(readFileSync(path19.join(ctx.root, "package.json"), "utf8"));
|
|
3006
3233
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3007
3234
|
} catch {
|
|
3008
3235
|
declared = null;
|
|
@@ -3033,17 +3260,17 @@ function createTrail(ctx) {
|
|
|
3033
3260
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3034
3261
|
let resolved = null;
|
|
3035
3262
|
if (spec.startsWith(".")) {
|
|
3036
|
-
resolved = resolveFile(
|
|
3263
|
+
resolved = resolveFile(path19.resolve(path19.dirname(file.absolutePath), spec));
|
|
3037
3264
|
if (!resolved) lost = true;
|
|
3038
3265
|
} else {
|
|
3039
3266
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3040
3267
|
if (alias) {
|
|
3041
3268
|
for (const t of alias.targets) {
|
|
3042
|
-
resolved = resolveFile(alias.exact ? t :
|
|
3269
|
+
resolved = resolveFile(alias.exact ? t : path19.join(t, spec.slice(alias.prefix.length)));
|
|
3043
3270
|
if (resolved) break;
|
|
3044
3271
|
}
|
|
3045
3272
|
}
|
|
3046
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
3273
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path19.join(baseUrl, spec));
|
|
3047
3274
|
if (!resolved) {
|
|
3048
3275
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3049
3276
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -3119,18 +3346,18 @@ function createTrail(ctx) {
|
|
|
3119
3346
|
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
3120
3347
|
function installedGenesis(root) {
|
|
3121
3348
|
const found = /* @__PURE__ */ new Map();
|
|
3122
|
-
let dir =
|
|
3349
|
+
let dir = path19.resolve(root);
|
|
3123
3350
|
for (; ; ) {
|
|
3124
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
3125
|
-
const scope =
|
|
3351
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path19.join(dir, m)));
|
|
3352
|
+
const scope = path19.join(dir, "node_modules", "@marktiderman");
|
|
3126
3353
|
if (existsSync(scope)) {
|
|
3127
3354
|
for (const entry of readdirSync(scope)) {
|
|
3128
3355
|
const name = `@marktiderman/${entry}`;
|
|
3129
3356
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
3130
|
-
if (existsSync(
|
|
3357
|
+
if (existsSync(path19.join(scope, entry, "package.json"))) found.set(name, path19.join(scope, entry));
|
|
3131
3358
|
}
|
|
3132
3359
|
}
|
|
3133
|
-
const parent =
|
|
3360
|
+
const parent = path19.dirname(dir);
|
|
3134
3361
|
if (atInstallRoot || parent === dir) return found;
|
|
3135
3362
|
dir = parent;
|
|
3136
3363
|
}
|
|
@@ -3152,7 +3379,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
3152
3379
|
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;
|
|
3153
3380
|
function routesDir(ctx) {
|
|
3154
3381
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
3155
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
3382
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path19.join(ctx.root, d))) ?? null;
|
|
3156
3383
|
}
|
|
3157
3384
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
3158
3385
|
function flavorOf(dir, rels) {
|
|
@@ -3253,7 +3480,7 @@ var PREFER_KEYS = /* @__PURE__ */ new Set(["id", "need", "level", "platform", "f
|
|
|
3253
3480
|
var FORBID_KEYS = /* @__PURE__ */ new Set(["jsx", "imports", "pattern"]);
|
|
3254
3481
|
var UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "pattern"]);
|
|
3255
3482
|
var PRIMITIVE_KEYS = /* @__PURE__ */ new Set(["need", "use", "import", "docs"]);
|
|
3256
|
-
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "primitives", "plugin", "$comment"]);
|
|
3483
|
+
var DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "catalog", "primitives", "plugin", "$comment"]);
|
|
3257
3484
|
var SCRIPT_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts", "**/*.cts", "**/*.mjs", "**/*.cjs"];
|
|
3258
3485
|
function ruleNamespace(packageName3) {
|
|
3259
3486
|
const m = GENESIS.exec(packageName3);
|
|
@@ -3266,7 +3493,7 @@ function toRegExp2(source, flags = "") {
|
|
|
3266
3493
|
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
3267
3494
|
return new RegExp(source, flags);
|
|
3268
3495
|
}
|
|
3269
|
-
function validateDeclaration(raw, packageName3,
|
|
3496
|
+
function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
3270
3497
|
const fail = (msg) => {
|
|
3271
3498
|
throw new PackageDeclarationError(`${packageName3}: genesis.doctor ${msg}`);
|
|
3272
3499
|
};
|
|
@@ -3286,9 +3513,9 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3286
3513
|
}
|
|
3287
3514
|
});
|
|
3288
3515
|
if (typeof raw === "string") {
|
|
3289
|
-
if (!
|
|
3290
|
-
const file =
|
|
3291
|
-
if (!inside(
|
|
3516
|
+
if (!packageDir2) fail(`points at ${raw}, but the package folder is unknown`);
|
|
3517
|
+
const file = path19.resolve(packageDir2, raw);
|
|
3518
|
+
if (!inside(packageDir2, file)) fail(`points outside the package (${raw})`);
|
|
3292
3519
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
3293
3520
|
let parsed;
|
|
3294
3521
|
try {
|
|
@@ -3296,7 +3523,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3296
3523
|
} catch (err) {
|
|
3297
3524
|
return fail(`file ${raw} is not valid JSON: ${err.message}`);
|
|
3298
3525
|
}
|
|
3299
|
-
return validateDeclaration(parsed, packageName3,
|
|
3526
|
+
return validateDeclaration(parsed, packageName3, packageDir2, ignored);
|
|
3300
3527
|
}
|
|
3301
3528
|
if (raw === false) fail(`is false; say why with { "enforce": false, "reason": "\u2026" }`);
|
|
3302
3529
|
if (!isObject3(raw)) fail(`must be an object (or a path to a JSON file in the package)`);
|
|
@@ -3307,8 +3534,10 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3307
3534
|
if (c.reason !== void 0 && (typeof c.reason !== "string" || !c.reason.trim())) fail(`reason must be a sentence`);
|
|
3308
3535
|
const prefer = c.prefer === void 0 ? [] : c.prefer;
|
|
3309
3536
|
if (!Array.isArray(prefer)) fail(`prefer must be a list`);
|
|
3310
|
-
|
|
3311
|
-
|
|
3537
|
+
if (c.catalog !== void 0 && c.primitives !== void 0) fail(`declares both catalog and primitives; keep catalog (primitives is its old name)`);
|
|
3538
|
+
const listKey = c.catalog !== void 0 ? "catalog" : "primitives";
|
|
3539
|
+
const primitives = c[listKey] === void 0 ? [] : c[listKey];
|
|
3540
|
+
if (!Array.isArray(primitives)) fail(`${listKey} must be a list`);
|
|
3312
3541
|
if (c.plugin !== void 0 && (typeof c.plugin !== "string" || !c.plugin.trim())) fail(`plugin must be a module path inside the package`);
|
|
3313
3542
|
if (!enforce) {
|
|
3314
3543
|
if (typeof c.reason !== "string") fail(`turns enforcement off without a reason; add "reason"`);
|
|
@@ -3323,7 +3552,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3323
3552
|
ids.add(r.id);
|
|
3324
3553
|
}
|
|
3325
3554
|
const entries = each(primitives, (p, i) => {
|
|
3326
|
-
const where2 =
|
|
3555
|
+
const where2 = `${listKey}[${i}]`;
|
|
3327
3556
|
if (!isObject3(p)) return fail(`${where2} must be an object`);
|
|
3328
3557
|
for (const key2 of Object.keys(p)) if (!PRIMITIVE_KEYS.has(key2)) unknownKey(where2, key2);
|
|
3329
3558
|
for (const key2 of ["need", "use"]) if (typeof p[key2] !== "string" || !p[key2].trim()) fail(`${where2} needs "${key2}"`);
|
|
@@ -3332,10 +3561,10 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
3332
3561
|
});
|
|
3333
3562
|
let plugin;
|
|
3334
3563
|
if (typeof c.plugin === "string") {
|
|
3335
|
-
if (!
|
|
3564
|
+
if (!packageDir2) plugin = c.plugin;
|
|
3336
3565
|
else {
|
|
3337
|
-
plugin =
|
|
3338
|
-
if (!inside(
|
|
3566
|
+
plugin = path19.resolve(packageDir2, c.plugin);
|
|
3567
|
+
if (!inside(packageDir2, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
3339
3568
|
}
|
|
3340
3569
|
}
|
|
3341
3570
|
return {
|
|
@@ -3384,7 +3613,7 @@ function checkPattern(v, where2, fail) {
|
|
|
3384
3613
|
}
|
|
3385
3614
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
3386
3615
|
function readDeclaringPackage(dir, local) {
|
|
3387
|
-
const file =
|
|
3616
|
+
const file = path19.join(dir, "package.json");
|
|
3388
3617
|
let stamp;
|
|
3389
3618
|
let real2;
|
|
3390
3619
|
try {
|
|
@@ -3407,17 +3636,21 @@ ${local}`;
|
|
|
3407
3636
|
const pkg = {
|
|
3408
3637
|
name: json.name,
|
|
3409
3638
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
3410
|
-
dir:
|
|
3639
|
+
dir: path19.resolve(dir),
|
|
3411
3640
|
namespace: ruleNamespace(json.name),
|
|
3412
3641
|
local,
|
|
3413
3642
|
private: json.private === true,
|
|
3414
3643
|
declaration: null
|
|
3415
3644
|
};
|
|
3645
|
+
if (local) {
|
|
3646
|
+
const state = overlayState(json.name, json);
|
|
3647
|
+
if (state.kind === "marked") pkg.overlay = state.marker;
|
|
3648
|
+
}
|
|
3416
3649
|
const raw = json.genesis?.doctor;
|
|
3417
3650
|
if (raw !== void 0) {
|
|
3418
3651
|
const ignored = [];
|
|
3419
3652
|
try {
|
|
3420
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
3653
|
+
pkg.declaration = validateDeclaration(raw, json.name, path19.resolve(dir), ignored);
|
|
3421
3654
|
if (ignored.length) pkg.ignored = ignored;
|
|
3422
3655
|
} catch (err) {
|
|
3423
3656
|
pkg.error = err.message;
|
|
@@ -3436,14 +3669,14 @@ function discoverPackages(root) {
|
|
|
3436
3669
|
for (const dir of installed) {
|
|
3437
3670
|
let scope;
|
|
3438
3671
|
try {
|
|
3439
|
-
scope =
|
|
3672
|
+
scope = path19.dirname(realpathSync(dir));
|
|
3440
3673
|
} catch {
|
|
3441
3674
|
continue;
|
|
3442
3675
|
}
|
|
3443
|
-
if (
|
|
3676
|
+
if (path19.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
3444
3677
|
for (const entry of readdirSync(scope)) {
|
|
3445
3678
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
3446
|
-
const pkg = readDeclaringPackage(
|
|
3679
|
+
const pkg = readDeclaringPackage(path19.join(scope, entry), false);
|
|
3447
3680
|
if (pkg) byName.set(pkg.name, pkg);
|
|
3448
3681
|
}
|
|
3449
3682
|
}
|
|
@@ -3615,7 +3848,7 @@ function unknownPackageRuleSettings(config, packages, reported) {
|
|
|
3615
3848
|
level: "warn",
|
|
3616
3849
|
file: "genesis config",
|
|
3617
3850
|
subject: id,
|
|
3618
|
-
message: `packageRules names ${id}, which no installed package declares; check the id (genesis
|
|
3851
|
+
message: `packageRules names ${id}, which no installed package declares; check the id (genesis catalog lists them) or remove it`
|
|
3619
3852
|
}));
|
|
3620
3853
|
}
|
|
3621
3854
|
function packageRuleIds(packages) {
|
|
@@ -3630,10 +3863,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
3630
3863
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
3631
3864
|
function sourceFiles(dir, rel = "") {
|
|
3632
3865
|
const out = [];
|
|
3633
|
-
for (const entry of readdirSync(
|
|
3866
|
+
for (const entry of readdirSync(path19.join(dir, rel)).sort()) {
|
|
3634
3867
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
3635
3868
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
3636
|
-
const stat = lstatSync(
|
|
3869
|
+
const stat = lstatSync(path19.join(dir, child));
|
|
3637
3870
|
if (stat.isSymbolicLink()) continue;
|
|
3638
3871
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
3639
3872
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -3656,13 +3889,13 @@ function matchPattern(pattern, spec) {
|
|
|
3656
3889
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
3657
3890
|
}
|
|
3658
3891
|
function tsconfigPaths(dir) {
|
|
3659
|
-
const file =
|
|
3892
|
+
const file = path19.join(dir, "tsconfig.json");
|
|
3660
3893
|
if (!existsSync(file)) return [];
|
|
3661
3894
|
try {
|
|
3662
3895
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
3663
3896
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
3664
|
-
const base =
|
|
3665
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
3897
|
+
const base = path19.resolve(dir, options.baseUrl ?? ".");
|
|
3898
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path19.resolve(base, t)) }));
|
|
3666
3899
|
} catch {
|
|
3667
3900
|
return [];
|
|
3668
3901
|
}
|
|
@@ -3676,8 +3909,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3676
3909
|
const hit = matchPattern(pattern, spec);
|
|
3677
3910
|
if (hit === null) continue;
|
|
3678
3911
|
return targets.some((t) => {
|
|
3679
|
-
const rel =
|
|
3680
|
-
return !rel.startsWith("..") && !
|
|
3912
|
+
const rel = path19.relative(pkg.dir, t.replace("*", hit));
|
|
3913
|
+
return !rel.startsWith("..") && !path19.isAbsolute(rel);
|
|
3681
3914
|
});
|
|
3682
3915
|
}
|
|
3683
3916
|
return null;
|
|
@@ -3690,7 +3923,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3690
3923
|
...Object.keys(json.optionalDependencies ?? {})
|
|
3691
3924
|
]);
|
|
3692
3925
|
for (const file of sourceFiles(pkg.dir)) {
|
|
3693
|
-
const code = stripForImports(readFileSync(
|
|
3926
|
+
const code = stripForImports(readFileSync(path19.join(pkg.dir, file), "utf8"));
|
|
3694
3927
|
if (code === null) continue;
|
|
3695
3928
|
const at = `${pkg.rel}/${file}`;
|
|
3696
3929
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -3715,9 +3948,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3715
3948
|
continue;
|
|
3716
3949
|
}
|
|
3717
3950
|
if (spec.startsWith(".")) {
|
|
3718
|
-
const target =
|
|
3719
|
-
const rel =
|
|
3720
|
-
if (rel.startsWith("..") ||
|
|
3951
|
+
const target = path19.resolve(pkg.dir, path19.dirname(file), spec);
|
|
3952
|
+
const rel = path19.relative(pkg.dir, target);
|
|
3953
|
+
if (rel.startsWith("..") || path19.isAbsolute(rel)) {
|
|
3721
3954
|
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` });
|
|
3722
3955
|
}
|
|
3723
3956
|
continue;
|
|
@@ -3731,20 +3964,35 @@ function checkImports2(ctx, pkg, json) {
|
|
|
3731
3964
|
});
|
|
3732
3965
|
}
|
|
3733
3966
|
}
|
|
3734
|
-
|
|
3967
|
+
var NPM_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
3968
|
+
function migrationHome(pkg, named, locals) {
|
|
3969
|
+
if (named === void 0 || named === pkg.name) return { dir: pkg.dir };
|
|
3970
|
+
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` };
|
|
3971
|
+
const dir = locals.find((l) => l.name === named)?.dir ?? findPackageDir(pkg.dir, named);
|
|
3972
|
+
return dir ? { dir } : { problem: `names the package ${named}, which isn't installed or a local package, so its test can't be checked` };
|
|
3973
|
+
}
|
|
3974
|
+
function checkMigrations(ctx, pkg, json, locals) {
|
|
3735
3975
|
const declaredFiles = /* @__PURE__ */ new Set();
|
|
3736
3976
|
for (const [id, raw] of Object.entries(rawBlocksOf(json))) {
|
|
3737
3977
|
const migrations = raw.migrations ?? [];
|
|
3738
3978
|
for (const m of migrations) {
|
|
3739
|
-
|
|
3979
|
+
const found = migrationHome(pkg, m.package, locals);
|
|
3980
|
+
if ("problem" in found) {
|
|
3981
|
+
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}` });
|
|
3982
|
+
continue;
|
|
3983
|
+
}
|
|
3984
|
+
const home = found.dir;
|
|
3985
|
+
const own = home === pkg.dir;
|
|
3986
|
+
if (own && typeof m.file === "string" && typeof m.test === "string") declaredFiles.add(m.file);
|
|
3987
|
+
const from = own ? "" : ` (in ${m.package})`;
|
|
3740
3988
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
3741
|
-
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` });
|
|
3742
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
3743
|
-
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` });
|
|
3989
|
+
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` });
|
|
3990
|
+
} else if (typeof m.test === "string" && !existsSync(path19.join(home, m.test))) {
|
|
3991
|
+
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` });
|
|
3744
3992
|
}
|
|
3745
3993
|
}
|
|
3746
3994
|
}
|
|
3747
|
-
const dir =
|
|
3995
|
+
const dir = path19.join(pkg.dir, "migrations");
|
|
3748
3996
|
if (!existsSync(dir)) return;
|
|
3749
3997
|
const seen = /* @__PURE__ */ new Map();
|
|
3750
3998
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3753,7 +4001,7 @@ function checkMigrations(ctx, pkg, json) {
|
|
|
3753
4001
|
const other = seen.get(m[1]);
|
|
3754
4002
|
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` });
|
|
3755
4003
|
else seen.set(m[1], name);
|
|
3756
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
4004
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path19.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
3757
4005
|
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")})` });
|
|
3758
4006
|
}
|
|
3759
4007
|
}
|
|
@@ -3767,7 +4015,7 @@ function checkExports(ctx, pkg, json) {
|
|
|
3767
4015
|
walk(json.exports);
|
|
3768
4016
|
for (const t of targets) {
|
|
3769
4017
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
3770
|
-
if (!existsSync(
|
|
4018
|
+
if (!existsSync(path19.join(pkg.dir, t))) {
|
|
3771
4019
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
3772
4020
|
}
|
|
3773
4021
|
}
|
|
@@ -3785,11 +4033,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
3785
4033
|
function checkTaggedTests(ctx, pkg) {
|
|
3786
4034
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
3787
4035
|
if (!tests.length) return;
|
|
3788
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
4036
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path19.join(pkg.dir, f), "utf8")));
|
|
3789
4037
|
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>` });
|
|
3790
4038
|
}
|
|
3791
4039
|
function checkRegistered(ctx, pkg) {
|
|
3792
|
-
const file =
|
|
4040
|
+
const file = path19.join(ctx.root, "features.json");
|
|
3793
4041
|
if (!existsSync(file)) return;
|
|
3794
4042
|
let doc;
|
|
3795
4043
|
try {
|
|
@@ -3799,7 +4047,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
3799
4047
|
}
|
|
3800
4048
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
3801
4049
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
3802
|
-
if (top) forms.add(
|
|
4050
|
+
if (top) forms.add(path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/"));
|
|
3803
4051
|
const covered = (doc.features ?? []).some(
|
|
3804
4052
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
3805
4053
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -3829,8 +4077,8 @@ function mergeBaseOf(root, base) {
|
|
|
3829
4077
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
3830
4078
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
3831
4079
|
if (!top) return;
|
|
3832
|
-
const appRelative = (fromTop) =>
|
|
3833
|
-
const inRepo =
|
|
4080
|
+
const appRelative = (fromTop) => path19.relative(realpathSync(ctx.root), path19.join(top, fromTop)).split(path19.sep).join("/");
|
|
4081
|
+
const inRepo = path19.relative(top, realpathSync(pkg.dir)).split(path19.sep).join("/");
|
|
3834
4082
|
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");
|
|
3835
4083
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
3836
4084
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -3853,11 +4101,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
3853
4101
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
3854
4102
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
3855
4103
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
3856
|
-
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) =>
|
|
4104
|
+
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)) : [];
|
|
3857
4105
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
3858
4106
|
const named = naming.length > 0;
|
|
3859
4107
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
3860
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
4108
|
+
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` });
|
|
3861
4109
|
}
|
|
3862
4110
|
let jsonBefore = null;
|
|
3863
4111
|
try {
|
|
@@ -3867,7 +4115,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
3867
4115
|
}
|
|
3868
4116
|
const raw = json;
|
|
3869
4117
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
3870
|
-
const appInRepo =
|
|
4118
|
+
const appInRepo = path19.relative(top, realpathSync(ctx.root)).split(path19.sep).join("/");
|
|
3871
4119
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
3872
4120
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
3873
4121
|
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` });
|
|
@@ -3919,15 +4167,16 @@ function checkPackagesPack(ctx) {
|
|
|
3919
4167
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
3920
4168
|
}
|
|
3921
4169
|
for (const pkg of packages) {
|
|
3922
|
-
const json = JSON.parse(readFileSync(
|
|
4170
|
+
const json = JSON.parse(readFileSync(path19.join(pkg.dir, "package.json"), "utf8"));
|
|
3923
4171
|
checkImports2(ctx, pkg, json);
|
|
3924
4172
|
checkExports(ctx, pkg, json);
|
|
3925
4173
|
checkBlocks(ctx, pkg, json);
|
|
3926
|
-
checkMigrations(ctx, pkg, json);
|
|
4174
|
+
checkMigrations(ctx, pkg, json, packages);
|
|
3927
4175
|
checkTaggedTests(ctx, pkg);
|
|
3928
4176
|
checkRegistered(ctx, pkg);
|
|
3929
4177
|
checkDoctorDeclaration(ctx, pkg, json);
|
|
3930
|
-
|
|
4178
|
+
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;
|
|
4179
|
+
if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
3931
4180
|
}
|
|
3932
4181
|
}
|
|
3933
4182
|
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
@@ -4112,9 +4361,9 @@ function gitView(root, dir, base) {
|
|
|
4112
4361
|
function checkSupabasePack(ctx) {
|
|
4113
4362
|
const settings = ctx.config.supabase ?? {};
|
|
4114
4363
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
4115
|
-
const abs =
|
|
4364
|
+
const abs = path19.join(ctx.root, dir);
|
|
4116
4365
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
4117
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
4366
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path19.join(abs, n), "utf8")) }));
|
|
4118
4367
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
4119
4368
|
const base = settings.base ?? DEFAULT_BASE;
|
|
4120
4369
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -4131,7 +4380,7 @@ function checkSupabasePack(ctx) {
|
|
|
4131
4380
|
}
|
|
4132
4381
|
}
|
|
4133
4382
|
const since = settings.since;
|
|
4134
|
-
const afterSince = (file) => since === void 0 ||
|
|
4383
|
+
const afterSince = (file) => since === void 0 || path19.posix.basename(file) >= since;
|
|
4135
4384
|
if ("reason" in view && since === void 0) {
|
|
4136
4385
|
ctx.report({
|
|
4137
4386
|
rule: "migration-grants",
|
|
@@ -4383,17 +4632,32 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
4383
4632
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
4384
4633
|
function readReleaseManifest(root) {
|
|
4385
4634
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
4386
|
-
const file = dir &&
|
|
4635
|
+
const file = dir && path19.join(dir, "dist", "versions.json");
|
|
4387
4636
|
if (!file || !existsSync(file)) return null;
|
|
4388
4637
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
4389
4638
|
}
|
|
4390
4639
|
function checkVersionSkew(ctx) {
|
|
4391
4640
|
const manifest = readReleaseManifest(ctx.root);
|
|
4392
4641
|
if (!manifest) return;
|
|
4642
|
+
const overlays = markedOverlays(ctx);
|
|
4393
4643
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
4644
|
+
const overlay = overlays.get(name);
|
|
4645
|
+
if (overlay) {
|
|
4646
|
+
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
4647
|
+
if (from !== want) {
|
|
4648
|
+
ctx.report({
|
|
4649
|
+
rule: "version-skew",
|
|
4650
|
+
level: "warn",
|
|
4651
|
+
file: "package.json",
|
|
4652
|
+
subject: name,
|
|
4653
|
+
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).`
|
|
4654
|
+
});
|
|
4655
|
+
}
|
|
4656
|
+
continue;
|
|
4657
|
+
}
|
|
4394
4658
|
const dir = findPackageDir(ctx.root, name);
|
|
4395
4659
|
if (!dir) continue;
|
|
4396
|
-
const have = JSON.parse(readFileSync(
|
|
4660
|
+
const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
|
|
4397
4661
|
if (have === want) continue;
|
|
4398
4662
|
ctx.report({
|
|
4399
4663
|
rule: "version-skew",
|
|
@@ -4409,7 +4673,7 @@ var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
|
4409
4673
|
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)$/;
|
|
4410
4674
|
var readManifest = (dir) => {
|
|
4411
4675
|
try {
|
|
4412
|
-
return JSON.parse(readFileSync(
|
|
4676
|
+
return JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
|
|
4413
4677
|
} catch {
|
|
4414
4678
|
return null;
|
|
4415
4679
|
}
|
|
@@ -4423,18 +4687,18 @@ var real = (p) => {
|
|
|
4423
4687
|
};
|
|
4424
4688
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
4425
4689
|
function nodeModulesOf(dir) {
|
|
4426
|
-
const parent =
|
|
4427
|
-
return
|
|
4690
|
+
const parent = path19.dirname(dir);
|
|
4691
|
+
return path19.basename(parent).startsWith("@") ? path19.dirname(parent) : parent;
|
|
4428
4692
|
}
|
|
4429
4693
|
function packagesIn(nodeModules) {
|
|
4430
4694
|
if (!existsSync(nodeModules)) return [];
|
|
4431
4695
|
const out = [];
|
|
4432
4696
|
for (const entry of readdirSync(nodeModules)) {
|
|
4433
4697
|
if (entry.startsWith(".")) continue;
|
|
4434
|
-
const p =
|
|
4698
|
+
const p = path19.join(nodeModules, entry);
|
|
4435
4699
|
if (entry.startsWith("@")) {
|
|
4436
4700
|
try {
|
|
4437
|
-
for (const sub of readdirSync(p)) out.push(
|
|
4701
|
+
for (const sub of readdirSync(p)) out.push(path19.join(p, sub));
|
|
4438
4702
|
} catch {
|
|
4439
4703
|
}
|
|
4440
4704
|
} else {
|
|
@@ -4446,7 +4710,7 @@ function packagesIn(nodeModules) {
|
|
|
4446
4710
|
function genesisInstalls(root) {
|
|
4447
4711
|
const copies = /* @__PURE__ */ new Map();
|
|
4448
4712
|
const realRoot = real(root);
|
|
4449
|
-
const rel = (abs) =>
|
|
4713
|
+
const rel = (abs) => path19.relative(realRoot, abs).split(path19.sep).join("/") || ".";
|
|
4450
4714
|
const via = /* @__PURE__ */ new Map();
|
|
4451
4715
|
const record = (real2, manifest, by, range, root2) => {
|
|
4452
4716
|
let copy = copies.get(real2);
|
|
@@ -4491,7 +4755,7 @@ function genesisInstalls(root) {
|
|
|
4491
4755
|
if (!dir) return null;
|
|
4492
4756
|
if (!ownInstall || name in declared) return dir;
|
|
4493
4757
|
const realDir = real(dir);
|
|
4494
|
-
if (realDir.startsWith(realRoot +
|
|
4758
|
+
if (realDir.startsWith(realRoot + path19.sep)) return dir;
|
|
4495
4759
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
4496
4760
|
};
|
|
4497
4761
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -4499,7 +4763,7 @@ function genesisInstalls(root) {
|
|
|
4499
4763
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
4500
4764
|
});
|
|
4501
4765
|
const app = readManifest(root);
|
|
4502
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
4766
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path19.join(root, f)));
|
|
4503
4767
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
4504
4768
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
4505
4769
|
const runtimeDeps = {
|
|
@@ -4510,11 +4774,11 @@ function genesisInstalls(root) {
|
|
|
4510
4774
|
};
|
|
4511
4775
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
4512
4776
|
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
4513
|
-
const top =
|
|
4777
|
+
const top = path19.join(root, "node_modules");
|
|
4514
4778
|
walk(
|
|
4515
4779
|
"hoisted",
|
|
4516
4780
|
packagesIn(top).filter((dir) => {
|
|
4517
|
-
const name =
|
|
4781
|
+
const name = path19.relative(top, dir).split(path19.sep).join("/");
|
|
4518
4782
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
4519
4783
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
4520
4784
|
);
|
|
@@ -4556,7 +4820,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
4556
4820
|
}
|
|
4557
4821
|
}
|
|
4558
4822
|
function checkPeerRanges(ctx) {
|
|
4559
|
-
const rel = (abs) =>
|
|
4823
|
+
const rel = (abs) => path19.relative(ctx.root, abs).split(path19.sep).join("/");
|
|
4560
4824
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
4561
4825
|
for (const copy of copies) {
|
|
4562
4826
|
const dir = copy.absolutePath;
|
|
@@ -4586,9 +4850,9 @@ var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Dra
|
|
|
4586
4850
|
var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
4587
4851
|
var SHELL = /<AppShell(?=[\s>/])/;
|
|
4588
4852
|
var GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
4589
|
-
var PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView)$/;
|
|
4853
|
+
var PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView|RecordView)$/;
|
|
4590
4854
|
var EMBEDDED_RESOURCE_VIEW = /<ResourceView\b[^>]*?\blayout\s*=\s*(?:(["'`]) {8}\1|\{\s*(["'`]) {8}\2\s*\})[^>]*>/g;
|
|
4591
|
-
var PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView)$/;
|
|
4855
|
+
var PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView|RecordView)$/;
|
|
4592
4856
|
var isNative2 = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
4593
4857
|
var rendersRe = (names) => {
|
|
4594
4858
|
const list = [...names];
|
|
@@ -4640,6 +4904,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
4640
4904
|
if (owner.size === 0) return;
|
|
4641
4905
|
const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
|
|
4642
4906
|
const routes = routesDir(ctx);
|
|
4907
|
+
const overlays = markedOverlays(ctx);
|
|
4643
4908
|
for (const file of ctx.files) {
|
|
4644
4909
|
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
4645
4910
|
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
|
|
@@ -4650,6 +4915,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
4650
4915
|
const [, exported, name] = m;
|
|
4651
4916
|
const pkg = owner.get(name);
|
|
4652
4917
|
if (!pkg || imported.has(name) || routeComponents.has(name)) return;
|
|
4918
|
+
if (insideOverlayOf(overlays, file, pkg)) return;
|
|
4653
4919
|
if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
|
|
4654
4920
|
const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
|
|
4655
4921
|
if (!rendersJsx(body)) return;
|
|
@@ -4938,11 +5204,11 @@ function appScripts(root) {
|
|
|
4938
5204
|
const out = [];
|
|
4939
5205
|
const walk = (dir) => {
|
|
4940
5206
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
4941
|
-
const abs =
|
|
5207
|
+
const abs = path19.join(dir, entry.name);
|
|
4942
5208
|
if (entry.isDirectory()) {
|
|
4943
5209
|
if (!SKIP_DIRS3.has(entry.name)) walk(abs);
|
|
4944
5210
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
4945
|
-
out.push(
|
|
5211
|
+
out.push(path19.relative(root, abs).split(path19.sep).join("/"));
|
|
4946
5212
|
}
|
|
4947
5213
|
}
|
|
4948
5214
|
};
|
|
@@ -5030,7 +5296,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
5030
5296
|
function moduleFiles(ctx) {
|
|
5031
5297
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
5032
5298
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
5033
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
5299
|
+
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) }));
|
|
5034
5300
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
5035
5301
|
}
|
|
5036
5302
|
function checkStudioServerImports(ctx) {
|
|
@@ -5066,7 +5332,7 @@ var REMOVED_WORDS = {
|
|
|
5066
5332
|
};
|
|
5067
5333
|
function checkRemovedScopeNames(ctx) {
|
|
5068
5334
|
let augmentedMemo;
|
|
5069
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
5335
|
+
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")));
|
|
5070
5336
|
for (const file of ctx.files) {
|
|
5071
5337
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
5072
5338
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -5093,6 +5359,98 @@ function checkRemovedScopeNames(ctx) {
|
|
|
5093
5359
|
}
|
|
5094
5360
|
}
|
|
5095
5361
|
}
|
|
5362
|
+
var SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
5363
|
+
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;
|
|
5364
|
+
function stabilityTagsIn(dts) {
|
|
5365
|
+
const tags = /* @__PURE__ */ new Map();
|
|
5366
|
+
for (const m of dts.matchAll(DECLARATION)) {
|
|
5367
|
+
const doc = m[1].replace(/^[ \t]*\*?[ \t]*/gm, "");
|
|
5368
|
+
const deprecated = /^@deprecated\b[ \t]*([\s\S]*?)(?=^@|(?![\s\S]))/m.exec(doc);
|
|
5369
|
+
const stability = /^@stability\s+(Experimental|Beta|Stable|Deprecated)\b/im.exec(doc)?.[1]?.toLowerCase();
|
|
5370
|
+
const note = deprecated?.[1].replace(/\s+/g, " ").trim();
|
|
5371
|
+
if (deprecated) tags.set(m[2], { stability: "deprecated", ...note ? { note } : {} });
|
|
5372
|
+
else if (stability) tags.set(m[2], { stability });
|
|
5373
|
+
}
|
|
5374
|
+
return tags;
|
|
5375
|
+
}
|
|
5376
|
+
function genesisNamedImports(code) {
|
|
5377
|
+
const out = [];
|
|
5378
|
+
const re = /import\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']((@marktiderman\/genesis[\w-]*)(?:\/[^"']*)?)["']/g;
|
|
5379
|
+
for (const m of code.matchAll(re)) {
|
|
5380
|
+
const names = m[1].split(",").map((n) => n.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim()).filter(Boolean);
|
|
5381
|
+
out.push({ pkg: m[3], specifier: m[2], names, line: code.slice(0, m.index).split("\n").length });
|
|
5382
|
+
}
|
|
5383
|
+
return out;
|
|
5384
|
+
}
|
|
5385
|
+
function declarationFiles(dir, out = []) {
|
|
5386
|
+
for (const name of readdirSync(dir)) {
|
|
5387
|
+
const full = path19.join(dir, name);
|
|
5388
|
+
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
5389
|
+
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
5390
|
+
}
|
|
5391
|
+
return out;
|
|
5392
|
+
}
|
|
5393
|
+
function packageDir(root, pkg) {
|
|
5394
|
+
for (let dir = path19.resolve(root); ; dir = path19.dirname(dir)) {
|
|
5395
|
+
const candidate = path19.join(dir, "node_modules", ...pkg.split("/"));
|
|
5396
|
+
if (existsSync(path19.join(candidate, "package.json"))) return candidate;
|
|
5397
|
+
if (path19.dirname(dir) === dir) return null;
|
|
5398
|
+
}
|
|
5399
|
+
}
|
|
5400
|
+
function readPackageTags(dir) {
|
|
5401
|
+
const pkg = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8"));
|
|
5402
|
+
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
5403
|
+
const dist = path19.join(dir, "dist");
|
|
5404
|
+
if (!existsSync(dist)) return tags;
|
|
5405
|
+
for (const file of declarationFiles(dist)) {
|
|
5406
|
+
const text = readFileSync(file, "utf8");
|
|
5407
|
+
tags.byFile.set(file, stabilityTagsIn(text));
|
|
5408
|
+
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)) {
|
|
5409
|
+
const files = tags.declaredIn.get(m[1]) ?? [];
|
|
5410
|
+
if (!files.includes(file)) files.push(file);
|
|
5411
|
+
tags.declaredIn.set(m[1], files);
|
|
5412
|
+
}
|
|
5413
|
+
}
|
|
5414
|
+
return tags;
|
|
5415
|
+
}
|
|
5416
|
+
function entryFile(tags, pkg, specifier) {
|
|
5417
|
+
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
5418
|
+
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
5419
|
+
const types = typeof target === "object" && target ? target.types : null;
|
|
5420
|
+
return typeof types === "string" ? path19.join(tags.dir, types) : null;
|
|
5421
|
+
}
|
|
5422
|
+
function tagFor(tags, entry, name) {
|
|
5423
|
+
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
5424
|
+
const all = (tags.declaredIn.get(name) ?? []).map((f) => tags.byFile.get(f)?.get(name));
|
|
5425
|
+
if (!all.length || all.some((t) => !t)) return void 0;
|
|
5426
|
+
return all.every((t) => t.stability === all[0].stability) ? all[0] : void 0;
|
|
5427
|
+
}
|
|
5428
|
+
function checkStabilityImports(ctx) {
|
|
5429
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
5430
|
+
const tagsOf = (pkg) => {
|
|
5431
|
+
if (!cache2.has(pkg)) {
|
|
5432
|
+
const dir = packageDir(ctx.root, pkg);
|
|
5433
|
+
cache2.set(pkg, dir ? readPackageTags(dir) : null);
|
|
5434
|
+
}
|
|
5435
|
+
return cache2.get(pkg);
|
|
5436
|
+
};
|
|
5437
|
+
for (const file of ctx.files) {
|
|
5438
|
+
if (!SCRIPT_EXTS6.has(file.ext)) continue;
|
|
5439
|
+
for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
|
|
5440
|
+
const tags = tagsOf(pkg);
|
|
5441
|
+
if (!tags) continue;
|
|
5442
|
+
const entry = entryFile(tags, pkg, specifier);
|
|
5443
|
+
for (const name of names) {
|
|
5444
|
+
const tag = tagFor(tags, entry, name);
|
|
5445
|
+
if (tag?.stability === "deprecated") {
|
|
5446
|
+
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}` : ""}` });
|
|
5447
|
+
} else if (tag && (tag.stability === "beta" || tag.stability === "experimental")) {
|
|
5448
|
+
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` });
|
|
5449
|
+
}
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
}
|
|
5453
|
+
}
|
|
5096
5454
|
function git3(root, args) {
|
|
5097
5455
|
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
5098
5456
|
return r.status === 0 ? r.stdout : null;
|
|
@@ -5114,7 +5472,7 @@ function showAt(dir, rev, file) {
|
|
|
5114
5472
|
function configAtBase(root, base, explicitFile) {
|
|
5115
5473
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
5116
5474
|
if (!mergeBase) return null;
|
|
5117
|
-
const candidates = explicitFile ? [{ dir:
|
|
5475
|
+
const candidates = explicitFile ? [{ dir: path19.dirname(explicitFile), file: path19.basename(explicitFile), explicit: true }] : [
|
|
5118
5476
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
5119
5477
|
{ dir: root, file: "package.json", explicit: false }
|
|
5120
5478
|
];
|
|
@@ -5226,7 +5584,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5226
5584
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
5227
5585
|
let current = null;
|
|
5228
5586
|
try {
|
|
5229
|
-
current = lf(readFileSync(
|
|
5587
|
+
current = lf(readFileSync(path19.join(ctx.root, out), "utf8"));
|
|
5230
5588
|
} catch {
|
|
5231
5589
|
current = null;
|
|
5232
5590
|
}
|
|
@@ -5250,7 +5608,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
5250
5608
|
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}` });
|
|
5251
5609
|
return;
|
|
5252
5610
|
}
|
|
5253
|
-
const target =
|
|
5611
|
+
const target = path19.relative(process.cwd(), path19.join(ctx.root, out)) || out;
|
|
5254
5612
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
5255
5613
|
if (current !== expected) {
|
|
5256
5614
|
ctx.report({
|
|
@@ -5270,7 +5628,7 @@ var CORE = [
|
|
|
5270
5628
|
},
|
|
5271
5629
|
{
|
|
5272
5630
|
need: "a page inside the app shell",
|
|
5273
|
-
use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` (from `@marktiderman/genesis-ui/data`)",
|
|
5631
|
+
use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` / `RecordView` (from `@marktiderman/genesis-ui/data`)",
|
|
5274
5632
|
import: "@marktiderman/genesis-ui",
|
|
5275
5633
|
rule: "page-layout",
|
|
5276
5634
|
from: "genesis-cli"
|
|
@@ -5330,7 +5688,7 @@ function catalogTable(rows, options = {}) {
|
|
|
5330
5688
|
return [head, ...body].join("\n");
|
|
5331
5689
|
}
|
|
5332
5690
|
function formatPrimitives(rows) {
|
|
5333
|
-
const lines = ["Genesis
|
|
5691
|
+
const lines = ["Genesis catalog: what to use for each need (reuse, then extend, then invent).", ""];
|
|
5334
5692
|
for (const r of rows) {
|
|
5335
5693
|
lines.push(`- ${r.need}: ${r.use}`);
|
|
5336
5694
|
if (r.import) lines.push(` import ${r.import}`);
|
|
@@ -5367,7 +5725,7 @@ function renderSkill(rows) {
|
|
|
5367
5725
|
"",
|
|
5368
5726
|
catalogTable(rows, { docs: true }),
|
|
5369
5727
|
"",
|
|
5370
|
-
"`genesis
|
|
5728
|
+
"`genesis catalog` prints the same list; `genesis doctor` enforces the rules named above.",
|
|
5371
5729
|
""
|
|
5372
5730
|
].join("\n");
|
|
5373
5731
|
}
|
|
@@ -5378,7 +5736,7 @@ function renderAgentsBlock(rows) {
|
|
|
5378
5736
|
"",
|
|
5379
5737
|
"Generated by `genesis agents` from the installed Genesis packages. Don't edit this block; run `genesis agents` after upgrading Genesis.",
|
|
5380
5738
|
"",
|
|
5381
|
-
`Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis
|
|
5739
|
+
`Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis catalog\`).`,
|
|
5382
5740
|
"",
|
|
5383
5741
|
...RULES.map((r) => `- ${r}`),
|
|
5384
5742
|
"",
|
|
@@ -5413,13 +5771,13 @@ var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
|
5413
5771
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
5414
5772
|
const rows = primitivesCatalog(packages);
|
|
5415
5773
|
const changed = [];
|
|
5416
|
-
const agents =
|
|
5774
|
+
const agents = path19.join(root, agentsFile);
|
|
5417
5775
|
const before = read(agents);
|
|
5418
5776
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
5419
|
-
const skill =
|
|
5777
|
+
const skill = path19.join(root, SKILL_PATH);
|
|
5420
5778
|
const skillText = renderSkill(rows);
|
|
5421
5779
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
5422
|
-
mkdirSync(
|
|
5780
|
+
mkdirSync(path19.dirname(skill), { recursive: true });
|
|
5423
5781
|
writeFileSync(skill, skillText);
|
|
5424
5782
|
changed.push(SKILL_PATH);
|
|
5425
5783
|
}
|
|
@@ -5431,8 +5789,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
5431
5789
|
}
|
|
5432
5790
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
5433
5791
|
const rows = primitivesCatalog(packages);
|
|
5434
|
-
const skill = read(
|
|
5435
|
-
const block = currentAgentsBlock(read(
|
|
5792
|
+
const skill = read(path19.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
5793
|
+
const block = currentAgentsBlock(read(path19.join(root, agentsFile)));
|
|
5436
5794
|
return {
|
|
5437
5795
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
5438
5796
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -5454,8 +5812,9 @@ function checkAgentGuide(ctx) {
|
|
|
5454
5812
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
5455
5813
|
}
|
|
5456
5814
|
}
|
|
5815
|
+
var RATCHETED_BY_DEFAULT = ["deprecated-import"];
|
|
5457
5816
|
async function runDoctor(options = {}) {
|
|
5458
|
-
const root =
|
|
5817
|
+
const root = path19.resolve(options.root ?? process.cwd());
|
|
5459
5818
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
5460
5819
|
const config = loaded.config;
|
|
5461
5820
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -5469,7 +5828,7 @@ async function runDoctor(options = {}) {
|
|
|
5469
5828
|
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`);
|
|
5470
5829
|
}
|
|
5471
5830
|
const raw = [];
|
|
5472
|
-
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, report: (f) => raw.push(f) };
|
|
5831
|
+
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
5473
5832
|
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
5474
5833
|
try {
|
|
5475
5834
|
await plugin.check(ctx);
|
|
@@ -5483,10 +5842,11 @@ async function runDoctor(options = {}) {
|
|
|
5483
5842
|
if (failure) raw.push(failure);
|
|
5484
5843
|
}
|
|
5485
5844
|
raw.push(...unknownPackageRuleSettings(config, packages, raw));
|
|
5486
|
-
const newOnly = /* @__PURE__ */ new Set([...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
|
|
5845
|
+
const newOnly = /* @__PURE__ */ new Set([...RATCHETED_BY_DEFAULT, ...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
|
|
5487
5846
|
let changed = null;
|
|
5488
5847
|
let skipped = false;
|
|
5489
|
-
|
|
5848
|
+
const ratchetNeeded = newOnly.size > RATCHETED_BY_DEFAULT.length || raw.some((f) => RATCHETED_BY_DEFAULT.includes(f.rule));
|
|
5849
|
+
if (options.base && (ratchetNeeded || config.ratchet)) {
|
|
5490
5850
|
changed = options.changedFiles ? new Set(options.changedFiles) : changedSince(root, options.base);
|
|
5491
5851
|
skipped ||= !changed;
|
|
5492
5852
|
}
|
|
@@ -5508,7 +5868,7 @@ async function runDoctor(options = {}) {
|
|
|
5508
5868
|
}
|
|
5509
5869
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
5510
5870
|
if (options.base && changed) {
|
|
5511
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
5871
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path19.join(root, f)) });
|
|
5512
5872
|
}
|
|
5513
5873
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
5514
5874
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -5550,7 +5910,9 @@ function builtinChecks(config, options = {}) {
|
|
|
5550
5910
|
{ name: "resource-view-trees", check: checkTreeViews },
|
|
5551
5911
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
5552
5912
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
5913
|
+
{ name: "stability-imports", check: checkStabilityImports },
|
|
5553
5914
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
5915
|
+
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
5554
5916
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
5555
5917
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
5556
5918
|
];
|
|
@@ -5613,7 +5975,7 @@ function formatReport(result) {
|
|
|
5613
5975
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
5614
5976
|
}
|
|
5615
5977
|
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
5616
|
-
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis
|
|
5978
|
+
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
5617
5979
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
5618
5980
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
5619
5981
|
return lines.join("\n");
|