@marktiderman/genesis-cli 1.16.2 → 1.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -8
- package/dist/cli.js +1628 -686
- package/dist/cli.js.map +1 -1
- package/dist/{config-DewJ3DR6.d.ts → config-1jP8eCZy.d.ts} +7 -0
- package/dist/doctor.d.ts +5 -4
- package/dist/doctor.js +577 -215
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +3 -2
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +131 -31
- package/dist/index.d.ts +10 -3
- package/dist/index.js +581 -219
- package/dist/index.js.map +1 -1
- package/dist/starter/__tests__/starter.test.ts +5 -1
- package/dist/starter/src/lib/native-modules.ts +5 -1
- package/dist/starter/tailwind.config.mjs +3 -1
- package/dist/vite.js +577 -215
- package/dist/vite.js.map +1 -1
- package/package.json +9 -5
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import * as
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, mkdirSync, writeFileSync, mkdtempSync, rmSync, realpathSync, statSync, lstatSync } from 'fs';
|
|
3
|
+
import * as path28 from 'path';
|
|
4
4
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
7
7
|
import { createJiti } from 'jiti';
|
|
8
8
|
import { createRequire, builtinModules } from 'module';
|
|
9
|
+
import { FEATURE_KINDS, PACKAGE_LAYERS, findFeatures, featureKind, overlayUpstream, FEATURE_STATUSES, FEATURE_PLATFORMS as FEATURE_PLATFORMS$1, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
9
10
|
import { execFileSync, spawnSync } from 'child_process';
|
|
10
11
|
import { buildFeatureOutputs, checkFeatureOutputs, summarizeCheck } from '@marktiderman/genesis-features/node';
|
|
11
|
-
import { findFeatures } from '@marktiderman/genesis-features';
|
|
12
12
|
import { studioSetupSql } from '@marktiderman/genesis-studio-server';
|
|
13
13
|
import { tmpdir } from 'os';
|
|
14
14
|
import { Command } from 'commander';
|
|
@@ -26,7 +26,7 @@ var __export = (target, all) => {
|
|
|
26
26
|
function buildCatalog(packagesDir) {
|
|
27
27
|
const packages = {};
|
|
28
28
|
for (const dir of readdirSync(packagesDir).sort()) {
|
|
29
|
-
const file =
|
|
29
|
+
const file = path28.join(packagesDir, dir, "package.json");
|
|
30
30
|
if (!existsSync(file)) continue;
|
|
31
31
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
32
32
|
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
@@ -154,7 +154,8 @@ function parseManifest(home, id, raw, version, options = {}) {
|
|
|
154
154
|
if (!isObject(f) || typeof f["name"] !== "string" || typeof f["summary"] !== "string") problems.push(`${at}.feature: needs a name and a summary`);
|
|
155
155
|
else {
|
|
156
156
|
feature = { name: f["name"], summary: f["summary"] };
|
|
157
|
-
|
|
157
|
+
const kind = f["kind"] ?? f["layer"];
|
|
158
|
+
if (typeof kind === "string") feature.kind = kind === "primitive" ? "element" : kind;
|
|
158
159
|
if (strings(f["keywords"])) feature.keywords = f["keywords"];
|
|
159
160
|
if (strings(f["audience"])) feature.audience = f["audience"];
|
|
160
161
|
}
|
|
@@ -234,35 +235,35 @@ ${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
|
234
235
|
}
|
|
235
236
|
});
|
|
236
237
|
function inside(parent, child) {
|
|
237
|
-
const rel =
|
|
238
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
238
|
+
const rel = path28.relative(parent, child);
|
|
239
|
+
return rel === "" || !rel.startsWith("..") && !path28.isAbsolute(rel);
|
|
239
240
|
}
|
|
240
|
-
function readPackageFile(
|
|
241
|
+
function readPackageFile(packageDir3, rel) {
|
|
241
242
|
const safe = safeRelative(rel);
|
|
242
243
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
243
|
-
const root = realpathSync(
|
|
244
|
-
const file =
|
|
244
|
+
const root = realpathSync(packageDir3);
|
|
245
|
+
const file = path28.join(root, ...safe.split("/"));
|
|
245
246
|
if (!existsSync(file)) return null;
|
|
246
247
|
const real2 = realpathSync(file);
|
|
247
|
-
if (!inside(root, real2)) throw new Error(`${rel} in ${
|
|
248
|
+
if (!inside(root, real2)) throw new Error(`${rel} in ${packageDir3} points outside the package`);
|
|
248
249
|
if (!statSync(real2).isFile()) return null;
|
|
249
250
|
return readFileSync(real2, "utf8");
|
|
250
251
|
}
|
|
251
|
-
function readPackageDir(
|
|
252
|
+
function readPackageDir(packageDir3, rel, skipped = []) {
|
|
252
253
|
const safe = safeRelative(rel);
|
|
253
254
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the package`);
|
|
254
|
-
const root = realpathSync(
|
|
255
|
-
const dir =
|
|
255
|
+
const root = realpathSync(packageDir3);
|
|
256
|
+
const dir = path28.join(root, ...safe.split("/"));
|
|
256
257
|
if (!existsSync(dir)) return null;
|
|
257
258
|
const real2 = realpathSync(dir);
|
|
258
|
-
if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${
|
|
259
|
+
if (!inside(root, real2) || !statSync(real2).isDirectory()) throw new Error(`${rel} in ${packageDir3} is not a folder inside the package`);
|
|
259
260
|
const out = [];
|
|
260
261
|
for (const entry of readdirSync(real2, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261
262
|
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(entry.name) || entry.isDirectory()) {
|
|
262
263
|
skipped.push(`${safe}/${entry.name}`);
|
|
263
264
|
continue;
|
|
264
265
|
}
|
|
265
|
-
const content = readPackageFile(
|
|
266
|
+
const content = readPackageFile(packageDir3, `${safe}/${entry.name}`);
|
|
266
267
|
if (content !== null && entry.isFile()) out.push({ name: entry.name, content });
|
|
267
268
|
}
|
|
268
269
|
return out;
|
|
@@ -272,7 +273,7 @@ function appPath(root, rel) {
|
|
|
272
273
|
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
273
274
|
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
274
275
|
const realRoot = realpathSync(root);
|
|
275
|
-
const target =
|
|
276
|
+
const target = path28.join(realRoot, ...safe.split("/"));
|
|
276
277
|
const there = (p) => {
|
|
277
278
|
try {
|
|
278
279
|
lstatSync(p);
|
|
@@ -281,13 +282,13 @@ function appPath(root, rel) {
|
|
|
281
282
|
return false;
|
|
282
283
|
}
|
|
283
284
|
};
|
|
284
|
-
let probe =
|
|
285
|
-
while (!there(probe)) probe =
|
|
285
|
+
let probe = path28.dirname(target);
|
|
286
|
+
while (!there(probe)) probe = path28.dirname(probe);
|
|
286
287
|
let real2;
|
|
287
288
|
try {
|
|
288
289
|
real2 = realpathSync(probe);
|
|
289
290
|
} catch {
|
|
290
|
-
throw new Error(`${rel} goes through a broken symlink (${
|
|
291
|
+
throw new Error(`${rel} goes through a broken symlink (${path28.relative(realRoot, probe)}); refused`);
|
|
291
292
|
}
|
|
292
293
|
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
293
294
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
@@ -299,20 +300,20 @@ function readApp(root, rel) {
|
|
|
299
300
|
}
|
|
300
301
|
function createApp(root, rel, content) {
|
|
301
302
|
const file = appPath(root, rel);
|
|
302
|
-
mkdirSync(
|
|
303
|
+
mkdirSync(path28.dirname(file), { recursive: true });
|
|
303
304
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
304
305
|
}
|
|
305
306
|
function replaceApp(root, rel, content) {
|
|
306
307
|
const file = appPath(root, rel);
|
|
307
|
-
mkdirSync(
|
|
308
|
+
mkdirSync(path28.dirname(file), { recursive: true });
|
|
308
309
|
writeFileSync(file, content, "utf8");
|
|
309
310
|
}
|
|
310
311
|
function listApp(root, rel, options = {}) {
|
|
311
|
-
const dir =
|
|
312
|
+
const dir = path28.join(root, rel);
|
|
312
313
|
if (!existsSync(dir)) return [];
|
|
313
314
|
const out = [];
|
|
314
315
|
const walk2 = (r) => {
|
|
315
|
-
for (const entry of readdirSync(
|
|
316
|
+
for (const entry of readdirSync(path28.join(root, r), { withFileTypes: true })) {
|
|
316
317
|
const child = `${r}/${entry.name}`;
|
|
317
318
|
if (entry.isDirectory()) walk2(child);
|
|
318
319
|
else if (entry.isFile() || options.symlinks && entry.isSymbolicLink()) out.push(child);
|
|
@@ -333,8 +334,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
333
334
|
return raw.map((entry, i) => {
|
|
334
335
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
335
336
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
336
|
-
if (
|
|
337
|
-
const norm =
|
|
337
|
+
if (path28.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
338
|
+
const norm = path28.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
338
339
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
339
340
|
const parts = norm.split("/");
|
|
340
341
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -345,7 +346,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
345
346
|
});
|
|
346
347
|
}
|
|
347
348
|
function localPackageGlobs(root) {
|
|
348
|
-
const file =
|
|
349
|
+
const file = path28.join(root, "genesis.config.json");
|
|
349
350
|
if (!existsSync(file)) return [];
|
|
350
351
|
let raw;
|
|
351
352
|
try {
|
|
@@ -358,14 +359,14 @@ function localPackageGlobs(root) {
|
|
|
358
359
|
}
|
|
359
360
|
function repositoryRoot(appRoot) {
|
|
360
361
|
for (let dir = appRoot; ; ) {
|
|
361
|
-
if (existsSync(
|
|
362
|
-
const parent =
|
|
362
|
+
if (existsSync(path28.join(dir, ".git"))) return dir;
|
|
363
|
+
const parent = path28.dirname(dir);
|
|
363
364
|
if (parent === dir) return appRoot;
|
|
364
365
|
dir = parent;
|
|
365
366
|
}
|
|
366
367
|
}
|
|
367
368
|
function localPackages(root) {
|
|
368
|
-
const appRoot =
|
|
369
|
+
const appRoot = path28.resolve(root);
|
|
369
370
|
const globs = localPackageGlobs(appRoot);
|
|
370
371
|
const key2 = `${appRoot}
|
|
371
372
|
${globs.join("\n")}`;
|
|
@@ -374,24 +375,24 @@ ${globs.join("\n")}`;
|
|
|
374
375
|
const dirs = /* @__PURE__ */ new Set();
|
|
375
376
|
for (const glob of globs) {
|
|
376
377
|
if (glob.endsWith("/*") || glob === "*") {
|
|
377
|
-
const parent =
|
|
378
|
+
const parent = path28.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
378
379
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
379
380
|
for (const entry of readdirSync(parent).sort()) {
|
|
380
381
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
381
|
-
dirs.add(
|
|
382
|
+
dirs.add(path28.join(parent, entry));
|
|
382
383
|
}
|
|
383
384
|
} else {
|
|
384
|
-
dirs.add(
|
|
385
|
+
dirs.add(path28.join(appRoot, glob));
|
|
385
386
|
}
|
|
386
387
|
}
|
|
387
388
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
388
389
|
const out = [];
|
|
389
390
|
const byName = /* @__PURE__ */ new Map();
|
|
390
391
|
for (const dir of [...dirs].sort()) {
|
|
391
|
-
const manifest =
|
|
392
|
+
const manifest = path28.join(dir, "package.json");
|
|
392
393
|
if (!existsSync(manifest)) continue;
|
|
393
394
|
if (!inside(real2, realpathSync(dir))) {
|
|
394
|
-
throw new LocalPackagesError(`${
|
|
395
|
+
throw new LocalPackagesError(`${path28.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
395
396
|
}
|
|
396
397
|
let pkg;
|
|
397
398
|
try {
|
|
@@ -400,7 +401,7 @@ ${globs.join("\n")}`;
|
|
|
400
401
|
continue;
|
|
401
402
|
}
|
|
402
403
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
403
|
-
const rel =
|
|
404
|
+
const rel = path28.relative(appRoot, dir).split(path28.sep).join("/");
|
|
404
405
|
const other = byName.get(pkg.name);
|
|
405
406
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
406
407
|
byName.set(pkg.name, rel);
|
|
@@ -443,41 +444,41 @@ __export(discover_exports, {
|
|
|
443
444
|
workspacePackagesDir: () => workspacePackagesDir
|
|
444
445
|
});
|
|
445
446
|
function cliPackageDir() {
|
|
446
|
-
let dir =
|
|
447
|
+
let dir = path28.dirname(fileURLToPath(import.meta.url));
|
|
447
448
|
for (; ; ) {
|
|
448
|
-
const file =
|
|
449
|
+
const file = path28.join(dir, "package.json");
|
|
449
450
|
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
450
|
-
const parent =
|
|
451
|
+
const parent = path28.dirname(dir);
|
|
451
452
|
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
452
453
|
dir = parent;
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
456
|
function workspacePackagesDir() {
|
|
456
|
-
const dir =
|
|
457
|
-
return existsSync(
|
|
457
|
+
const dir = path28.resolve(cliPackageDir(), "..");
|
|
458
|
+
return existsSync(path28.join(dir, "features", "package.json")) && existsSync(path28.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
458
459
|
}
|
|
459
460
|
function readCatalog() {
|
|
460
461
|
if (catalogCache) return catalogCache;
|
|
461
462
|
const workspace = workspacePackagesDir();
|
|
462
463
|
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
463
|
-
const file =
|
|
464
|
+
const file = path28.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
464
465
|
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
465
466
|
return catalogCache;
|
|
466
467
|
}
|
|
467
468
|
function installedGenesis(root) {
|
|
468
469
|
const found = /* @__PURE__ */ new Map();
|
|
469
|
-
let dir =
|
|
470
|
+
let dir = path28.resolve(root);
|
|
470
471
|
for (; ; ) {
|
|
471
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
472
|
-
const scope =
|
|
472
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path28.join(dir, m)));
|
|
473
|
+
const scope = path28.join(dir, "node_modules", "@marktiderman");
|
|
473
474
|
if (existsSync(scope)) {
|
|
474
475
|
for (const entry of readdirSync(scope)) {
|
|
475
476
|
const name = `@marktiderman/${entry}`;
|
|
476
477
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
477
|
-
if (existsSync(
|
|
478
|
+
if (existsSync(path28.join(scope, entry, "package.json"))) found.set(name, path28.join(scope, entry));
|
|
478
479
|
}
|
|
479
480
|
}
|
|
480
|
-
const parent =
|
|
481
|
+
const parent = path28.dirname(dir);
|
|
481
482
|
if (atInstallRoot || parent === dir) return found;
|
|
482
483
|
dir = parent;
|
|
483
484
|
}
|
|
@@ -491,10 +492,10 @@ function packageDir(root, name) {
|
|
|
491
492
|
return null;
|
|
492
493
|
}
|
|
493
494
|
function packageVersion(dir) {
|
|
494
|
-
return JSON.parse(readFileSync(
|
|
495
|
+
return JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8")).version;
|
|
495
496
|
}
|
|
496
497
|
function declarationsOf(dir, warnings) {
|
|
497
|
-
const pkg = JSON.parse(readFileSync(
|
|
498
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
498
499
|
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
499
500
|
let cached = declarationCache.get(key2);
|
|
500
501
|
if (!cached) {
|
|
@@ -504,15 +505,15 @@ function declarationsOf(dir, warnings) {
|
|
|
504
505
|
return cached;
|
|
505
506
|
}
|
|
506
507
|
async function loadDeclarations(dir, warnings) {
|
|
507
|
-
const pkg = JSON.parse(readFileSync(
|
|
508
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
508
509
|
const entry = pkg.exports?.["./blocks"];
|
|
509
510
|
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
510
511
|
if (typeof target !== "string") return {};
|
|
511
512
|
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
512
|
-
const file = rel &&
|
|
513
|
+
const file = rel && path28.join(dir, ...rel.split("/"));
|
|
513
514
|
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
514
515
|
try {
|
|
515
|
-
const jiti = createJiti(
|
|
516
|
+
const jiti = createJiti(path28.join(dir, "package.json"), { moduleCache: false });
|
|
516
517
|
const mod = await jiti.import(file);
|
|
517
518
|
const out = {};
|
|
518
519
|
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
@@ -523,7 +524,7 @@ async function loadDeclarations(dir, warnings) {
|
|
|
523
524
|
}
|
|
524
525
|
}
|
|
525
526
|
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
526
|
-
const pkg = JSON.parse(readFileSync(
|
|
527
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
527
528
|
const raw = rawBlocksOf(pkg);
|
|
528
529
|
const declared = await declarationsOf(dir, warnings);
|
|
529
530
|
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
@@ -597,6 +598,7 @@ var lock_exports = {};
|
|
|
597
598
|
__export(lock_exports, {
|
|
598
599
|
LOCK_FILE: () => LOCK_FILE,
|
|
599
600
|
emptyLock: () => emptyLock,
|
|
601
|
+
migrationKey: () => migrationKey,
|
|
600
602
|
parseSource: () => parseSource,
|
|
601
603
|
readLock: () => readLock,
|
|
602
604
|
substitute: () => substitute,
|
|
@@ -606,18 +608,33 @@ function emptyLock() {
|
|
|
606
608
|
return { version: 1, blocks: {}, files: {} };
|
|
607
609
|
}
|
|
608
610
|
function readLock(root) {
|
|
609
|
-
const file =
|
|
611
|
+
const file = path28.join(root, LOCK_FILE);
|
|
610
612
|
if (!existsSync(file)) return emptyLock();
|
|
611
613
|
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
612
614
|
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
613
|
-
return {
|
|
615
|
+
return {
|
|
616
|
+
version: 1,
|
|
617
|
+
...raw.substitutions ? { substitutions: raw.substitutions } : {},
|
|
618
|
+
blocks: raw.blocks ?? {},
|
|
619
|
+
files: raw.files ?? {},
|
|
620
|
+
...raw.migrations ? { migrations: raw.migrations } : {}
|
|
621
|
+
};
|
|
614
622
|
}
|
|
615
623
|
function writeLock(root, lock) {
|
|
616
|
-
const
|
|
617
|
-
const out = {
|
|
624
|
+
const sorted2 = (o) => Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b)));
|
|
625
|
+
const out = {
|
|
626
|
+
version: 1,
|
|
627
|
+
...lock.substitutions ? { substitutions: lock.substitutions } : {},
|
|
628
|
+
blocks: sorted2(lock.blocks),
|
|
629
|
+
files: sorted2(lock.files),
|
|
630
|
+
...lock.migrations && Object.keys(lock.migrations).length ? { migrations: sorted2(lock.migrations) } : {}
|
|
631
|
+
};
|
|
618
632
|
replaceApp(root, LOCK_FILE, `${JSON.stringify(out, null, 2)}
|
|
619
633
|
`);
|
|
620
634
|
}
|
|
635
|
+
function migrationKey(pkg, file) {
|
|
636
|
+
return `${pkg}:${file}`;
|
|
637
|
+
}
|
|
621
638
|
function parseSource(source) {
|
|
622
639
|
const at = source.indexOf(":");
|
|
623
640
|
if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
|
|
@@ -649,6 +666,7 @@ __export(migrations_exports, {
|
|
|
649
666
|
nextTimestamps: () => nextTimestamps,
|
|
650
667
|
planMigrations: () => planMigrations,
|
|
651
668
|
readAppMigrations: () => readAppMigrations,
|
|
669
|
+
rememberMigrationCopies: () => rememberMigrationCopies,
|
|
652
670
|
stemOf: () => stemOf,
|
|
653
671
|
stemOrNull: () => stemOrNull,
|
|
654
672
|
textSha: () => textSha,
|
|
@@ -661,7 +679,7 @@ function migrationHeader(pkg, file, source) {
|
|
|
661
679
|
`;
|
|
662
680
|
}
|
|
663
681
|
function stemOrNull(file) {
|
|
664
|
-
return MIGRATION_FILE.exec(
|
|
682
|
+
return MIGRATION_FILE.exec(path28.posix.basename(file))?.[2] ?? null;
|
|
665
683
|
}
|
|
666
684
|
function stemOf(file) {
|
|
667
685
|
const stem = stemOrNull(file);
|
|
@@ -671,7 +689,7 @@ function stemOf(file) {
|
|
|
671
689
|
function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
672
690
|
return listApp(root, dir, { symlinks: true }).filter((p) => p.endsWith(".sql")).map((p) => {
|
|
673
691
|
const content = readApp(root, p) ?? "";
|
|
674
|
-
const name =
|
|
692
|
+
const name = path28.posix.basename(p);
|
|
675
693
|
const m = HEADER.exec(content);
|
|
676
694
|
if (m) return { path: p, name, content, tracked: { package: m[1], file: m[2], sha256: m[3], body: content.slice(m[0].length) } };
|
|
677
695
|
const f = FORWARD.exec(content);
|
|
@@ -680,7 +698,7 @@ function readAppMigrations(root, dir = MIGRATIONS_DIR) {
|
|
|
680
698
|
});
|
|
681
699
|
}
|
|
682
700
|
function needsAttention(row) {
|
|
683
|
-
return row.state !== "current" && row.state !== "new" && !row.forward;
|
|
701
|
+
return row.state !== "current" && row.state !== "new" && row.state !== "deleted" && !row.forward;
|
|
684
702
|
}
|
|
685
703
|
function timestampOf(date) {
|
|
686
704
|
return date.toISOString().replace(/\D/g, "").slice(0, 14);
|
|
@@ -734,6 +752,11 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
734
752
|
rows.push({ ...base, state: "unavailable", ...copy ? { copy: copy.path } : {}, detail: `${src.package} isn't installed, or doesn't ship ${src.file}` });
|
|
735
753
|
continue;
|
|
736
754
|
}
|
|
755
|
+
const copiedTo = options.copied?.[migrationKey(src.package, src.file)];
|
|
756
|
+
if (!copy && copiedTo) {
|
|
757
|
+
rows.push({ ...base, state: "deleted", copy: copiedTo, detail: "deleted in the app after it was copied; not copied again" });
|
|
758
|
+
continue;
|
|
759
|
+
}
|
|
737
760
|
if (!copy) {
|
|
738
761
|
const row2 = { ...base, state: "new" };
|
|
739
762
|
rows.push(row2);
|
|
@@ -753,7 +776,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
753
776
|
detail = copy.tracked ? renamed.trim() : "copied before headers; matches the package";
|
|
754
777
|
} else if (copy.tracked) {
|
|
755
778
|
state = "changed-upstream";
|
|
756
|
-
detail = `${src.package} now ships a different ${
|
|
779
|
+
detail = `${src.package} now ships a different ${path28.posix.basename(src.file)}; the applied copy is never rewritten`;
|
|
757
780
|
} else {
|
|
758
781
|
state = "differs";
|
|
759
782
|
detail = "has the package migration's name but other text and no header; treated as the app's own";
|
|
@@ -775,7 +798,7 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
775
798
|
row.target = target2;
|
|
776
799
|
creates.push({ path: target2, content: migrationHeader(src.package, src.file, src.source) + src.source, kind, source: { package: src.package, file: src.file } });
|
|
777
800
|
if (options.tests !== false && src.test && src.testSource != null) {
|
|
778
|
-
const test2 = `${TESTS_DIR}/${
|
|
801
|
+
const test2 = `${TESTS_DIR}/${path28.posix.basename(src.test).replace(/^\d{4}_/, "")}`;
|
|
779
802
|
if (readApp(root, test2) === null && !creates.some((c) => c.path === test2)) creates.push({ path: test2, content: src.testSource, kind: "test", source: { package: src.package, file: src.test } });
|
|
780
803
|
}
|
|
781
804
|
return;
|
|
@@ -801,6 +824,17 @@ function planMigrations(root, sources, options = { now: /* @__PURE__ */ new Date
|
|
|
801
824
|
});
|
|
802
825
|
return { rows, creates };
|
|
803
826
|
}
|
|
827
|
+
function rememberMigrationCopies(lock, plan) {
|
|
828
|
+
const before = JSON.stringify(lock.migrations ?? {});
|
|
829
|
+
const migrations = { ...lock.migrations };
|
|
830
|
+
for (const row of plan.rows) {
|
|
831
|
+
if (row.copy && (row.state === "current" || row.state === "edited" || row.state === "changed-upstream")) migrations[migrationKey(row.package, row.file)] = row.copy;
|
|
832
|
+
}
|
|
833
|
+
for (const c of plan.creates) if (c.kind === "migration" && c.source) migrations[migrationKey(c.source.package, c.source.file)] = c.path;
|
|
834
|
+
if (JSON.stringify(migrations) === before) return false;
|
|
835
|
+
lock.migrations = migrations;
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
804
838
|
function applyMigrationPlan(root, plan) {
|
|
805
839
|
for (const file of plan.creates) createApp(root, file.path, file.content);
|
|
806
840
|
return plan.creates.map((c) => c.path);
|
|
@@ -810,7 +844,7 @@ function validHeaderFile(file) {
|
|
|
810
844
|
}
|
|
811
845
|
function formatMigrationRows(rows) {
|
|
812
846
|
if (!rows.length) return "No package migrations to compare.";
|
|
813
|
-
const mark = { current: "=", new: "+", edited: "!", "changed-upstream": "!", differs: "!", unavailable: "?" };
|
|
847
|
+
const mark = { current: "=", new: "+", edited: "!", "changed-upstream": "!", differs: "!", deleted: "!", unavailable: "?" };
|
|
814
848
|
return rows.map((r) => {
|
|
815
849
|
const where2 = r.target ? ` \u2192 ${r.target}` : r.copy ? ` (${r.copy})` : "";
|
|
816
850
|
const fwd = r.forward && !r.target ? `; carried by ${r.forward}` : "";
|
|
@@ -822,6 +856,7 @@ var init_migrations = __esm({
|
|
|
822
856
|
"src/blocks/migrations.ts"() {
|
|
823
857
|
init_files();
|
|
824
858
|
init_manifest();
|
|
859
|
+
init_lock();
|
|
825
860
|
MIGRATIONS_DIR = "supabase/migrations";
|
|
826
861
|
TESTS_DIR = "supabase/tests/database";
|
|
827
862
|
HEADER = /^-- genesis-migration: (\S+) (\S+) sha256:([0-9a-f]{64})\r?\n-- [^\n]*\n/;
|
|
@@ -830,30 +865,49 @@ var init_migrations = __esm({
|
|
|
830
865
|
textSha = (text) => sha256(normal(text));
|
|
831
866
|
}
|
|
832
867
|
});
|
|
868
|
+
|
|
869
|
+
// src/doctor/config.ts
|
|
870
|
+
var config_exports = {};
|
|
871
|
+
__export(config_exports, {
|
|
872
|
+
DoctorConfigError: () => DoctorConfigError,
|
|
873
|
+
GenesisConfigError: () => GenesisConfigError,
|
|
874
|
+
META_RULES: () => META_RULES,
|
|
875
|
+
PRIVACY_DATA_TYPES: () => PRIVACY_DATA_TYPES,
|
|
876
|
+
PRIVACY_PURPOSES: () => PRIVACY_PURPOSES,
|
|
877
|
+
checkRegExp: () => checkRegExp,
|
|
878
|
+
doctorBlock: () => doctorBlock,
|
|
879
|
+
isPackageDeclaration: () => isPackageDeclaration,
|
|
880
|
+
loadConfig: () => loadConfig,
|
|
881
|
+
privacyDataType: () => privacyDataType,
|
|
882
|
+
readGenesisConfig: () => readGenesisConfig,
|
|
883
|
+
validateConfig: () => validateConfig,
|
|
884
|
+
validateLinks: () => validateLinks,
|
|
885
|
+
validatePrivacy: () => validatePrivacy
|
|
886
|
+
});
|
|
833
887
|
function privacyDataType(type) {
|
|
834
888
|
return PRIVACY_DATA_TYPES[type.toLowerCase()];
|
|
835
889
|
}
|
|
836
890
|
function appPath2(v, where2, fail) {
|
|
837
891
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
838
|
-
if (
|
|
839
|
-
const norm =
|
|
892
|
+
if (path28.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
893
|
+
const norm = path28.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
840
894
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
841
895
|
return norm;
|
|
842
896
|
}
|
|
843
897
|
function loadConfig(root, configPath) {
|
|
844
898
|
if (configPath) {
|
|
845
|
-
const file =
|
|
899
|
+
const file = path28.resolve(root, configPath);
|
|
846
900
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
847
901
|
const json = readJson(file);
|
|
848
|
-
const block =
|
|
849
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
902
|
+
const block = path28.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
903
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path28.dirname(file) };
|
|
850
904
|
}
|
|
851
|
-
const own =
|
|
905
|
+
const own = path28.join(root, "genesis.config.json");
|
|
852
906
|
if (existsSync(own)) {
|
|
853
907
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
854
908
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
855
909
|
}
|
|
856
|
-
const pkg =
|
|
910
|
+
const pkg = path28.join(root, "package.json");
|
|
857
911
|
if (existsSync(pkg)) {
|
|
858
912
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
859
913
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -862,14 +916,14 @@ function loadConfig(root, configPath) {
|
|
|
862
916
|
}
|
|
863
917
|
function doctorBlock(json, file, explicit) {
|
|
864
918
|
const j = json;
|
|
865
|
-
if (
|
|
919
|
+
if (path28.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
866
920
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
867
921
|
}
|
|
868
922
|
function isPackageDeclaration(block) {
|
|
869
923
|
if (typeof block === "string") return true;
|
|
870
924
|
if (!isObject2(block)) return false;
|
|
871
925
|
const keys = Object.keys(block).filter((k) => k !== "$comment");
|
|
872
|
-
return keys.some((k) => ["prefer", "primitives", "plugin", "enforce"].includes(k)) && !keys.some((k) => KNOWN.has(k));
|
|
926
|
+
return keys.some((k) => ["prefer", "catalog", "primitives", "plugin", "enforce"].includes(k)) && !keys.some((k) => KNOWN.has(k));
|
|
873
927
|
}
|
|
874
928
|
function readJson(file) {
|
|
875
929
|
try {
|
|
@@ -879,7 +933,7 @@ function readJson(file) {
|
|
|
879
933
|
}
|
|
880
934
|
}
|
|
881
935
|
function readGenesisConfig(root) {
|
|
882
|
-
const file =
|
|
936
|
+
const file = path28.join(root, "genesis.config.json");
|
|
883
937
|
if (!existsSync(file)) return null;
|
|
884
938
|
const raw = readJson(file);
|
|
885
939
|
if (!isObject2(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
@@ -1040,7 +1094,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1040
1094
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1041
1095
|
if (contracts.out !== void 0) {
|
|
1042
1096
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1043
|
-
if (
|
|
1097
|
+
if (path28.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1044
1098
|
}
|
|
1045
1099
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1046
1100
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1177,11 +1231,11 @@ var init_config = __esm({
|
|
|
1177
1231
|
}
|
|
1178
1232
|
});
|
|
1179
1233
|
function findPackageDir(from, name) {
|
|
1180
|
-
let dir =
|
|
1234
|
+
let dir = path28.resolve(from);
|
|
1181
1235
|
for (; ; ) {
|
|
1182
|
-
const candidate =
|
|
1183
|
-
if (existsSync(
|
|
1184
|
-
const parent =
|
|
1236
|
+
const candidate = path28.join(dir, "node_modules", name);
|
|
1237
|
+
if (existsSync(path28.join(candidate, "package.json"))) return candidate;
|
|
1238
|
+
const parent = path28.dirname(dir);
|
|
1185
1239
|
if (parent === dir) return null;
|
|
1186
1240
|
dir = parent;
|
|
1187
1241
|
}
|
|
@@ -1233,37 +1287,50 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1233
1287
|
function readPackageExports(root, uiPackage) {
|
|
1234
1288
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1235
1289
|
if (!uiDir) return null;
|
|
1236
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1290
|
+
const uiPkg = JSON.parse(readFileSync(path28.join(uiDir, "package.json"), "utf8"));
|
|
1291
|
+
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
1292
|
+
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1293
|
+
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
1294
|
+
const entryOf = fromSource ? exportSource : exportTypes;
|
|
1237
1295
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
1238
|
-
const mainTypes =
|
|
1296
|
+
const mainTypes = fromSource ? exportSource(uiPkg.exports?.["."] ?? uiPkg.exports) ?? (isTsSource(uiPkg.main) ? uiPkg.main : void 0) : declared;
|
|
1239
1297
|
if (typeof mainTypes === "string") typeEntries.add(mainTypes);
|
|
1240
|
-
for (const target of
|
|
1241
|
-
const t =
|
|
1298
|
+
for (const target of subpaths) {
|
|
1299
|
+
const t = entryOf(target);
|
|
1242
1300
|
if (typeof t === "string" && !t.includes("*")) typeEntries.add(t);
|
|
1243
1301
|
}
|
|
1244
1302
|
const exportNames = /* @__PURE__ */ new Set();
|
|
1245
1303
|
const reexportedPackages = /* @__PURE__ */ new Set();
|
|
1246
1304
|
let readAny = false;
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
if (!existsSync(file))
|
|
1305
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1306
|
+
const readEntry = (file) => {
|
|
1307
|
+
if (seen.has(file) || !insidePackage(uiDir, file) || !existsSync(file)) return;
|
|
1308
|
+
seen.add(file);
|
|
1250
1309
|
readAny = true;
|
|
1251
|
-
const
|
|
1252
|
-
for (const name of parseExportNames(
|
|
1253
|
-
for (const m of
|
|
1310
|
+
const code = fromSource ? stripComments(readFileSync(file, "utf8")) : readFileSync(file, "utf8");
|
|
1311
|
+
for (const name of fromSource ? parseSourceExportNames(code) : parseExportNames(code)) exportNames.add(name);
|
|
1312
|
+
for (const m of code.matchAll(/export\s+(?:type\s+)?(?:\{[^}]*\}|\*)\s*from\s*["']([^"'.][^"']*)["']/g)) {
|
|
1254
1313
|
reexportedPackages.add(packageName(m[1]));
|
|
1255
1314
|
}
|
|
1256
|
-
|
|
1315
|
+
if (fromSource) {
|
|
1316
|
+
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
1317
|
+
const next = resolveSource(path28.dirname(file), m[1]);
|
|
1318
|
+
if (next) readEntry(next);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1322
|
+
for (const entry of typeEntries) readEntry(path28.join(uiDir, entry));
|
|
1257
1323
|
if (!readAny) {
|
|
1258
|
-
|
|
1324
|
+
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
1325
|
+
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1259
1326
|
}
|
|
1260
1327
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1261
1328
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1262
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1263
|
-
const declFiles = walkDts(declRoot);
|
|
1329
|
+
const declRoot = typeof mainTypes === "string" ? path28.dirname(path28.join(uiDir, mainTypes)) : uiDir;
|
|
1330
|
+
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
1264
1331
|
for (const pkg of reexportedPackages) {
|
|
1265
1332
|
const dir = findPackageDir(uiDir, pkg);
|
|
1266
|
-
if (dir) walkDts(
|
|
1333
|
+
if (dir) walkDts(path28.join(dir, "dist"), declFiles);
|
|
1267
1334
|
}
|
|
1268
1335
|
for (const file of declFiles) {
|
|
1269
1336
|
const text = readFileSync(file, "utf8");
|
|
@@ -1295,6 +1362,70 @@ function packageName(specifier) {
|
|
|
1295
1362
|
const parts = specifier.split("/");
|
|
1296
1363
|
return parts.slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
|
|
1297
1364
|
}
|
|
1365
|
+
function parseSourceExportNames(code) {
|
|
1366
|
+
const names = parseExportNames(code);
|
|
1367
|
+
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]);
|
|
1368
|
+
for (const m of code.matchAll(/export\s+\*\s+as\s+([A-Za-z_$][\w$]*)/g)) names.push(m[1]);
|
|
1369
|
+
return [...new Set(names)];
|
|
1370
|
+
}
|
|
1371
|
+
function exportSource(target) {
|
|
1372
|
+
if (isTsSource(target)) return target;
|
|
1373
|
+
if (!target || typeof target !== "object") return void 0;
|
|
1374
|
+
for (const value of Object.values(target)) {
|
|
1375
|
+
const nested = exportSource(value);
|
|
1376
|
+
if (nested) return nested;
|
|
1377
|
+
}
|
|
1378
|
+
return void 0;
|
|
1379
|
+
}
|
|
1380
|
+
function resolveSource(dir, spec) {
|
|
1381
|
+
const base = path28.resolve(dir, spec.replace(/\.js$/, ""));
|
|
1382
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path28.join(base, i))];
|
|
1383
|
+
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
1384
|
+
}
|
|
1385
|
+
function insidePackage(dir, file) {
|
|
1386
|
+
const rel = path28.relative(path28.resolve(dir), path28.resolve(file));
|
|
1387
|
+
return rel === "" || !rel.startsWith("..") && !path28.isAbsolute(rel);
|
|
1388
|
+
}
|
|
1389
|
+
function stripComments(code) {
|
|
1390
|
+
let out = "";
|
|
1391
|
+
let i = 0;
|
|
1392
|
+
while (i < code.length) {
|
|
1393
|
+
const c = code[i];
|
|
1394
|
+
const next = code[i + 1];
|
|
1395
|
+
if (c === "/" && next === "*") {
|
|
1396
|
+
const end = code.indexOf("*/", i + 2);
|
|
1397
|
+
const stop = end < 0 ? code.length : end + 2;
|
|
1398
|
+
out += code.slice(i, stop).replace(/[^\n]/g, " ");
|
|
1399
|
+
i = stop;
|
|
1400
|
+
} else if (c === "/" && next === "/") {
|
|
1401
|
+
const end = code.indexOf("\n", i);
|
|
1402
|
+
i = end < 0 ? code.length : end;
|
|
1403
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
1404
|
+
let j = i + 1;
|
|
1405
|
+
while (j < code.length && code[j] !== c) {
|
|
1406
|
+
if (code[j] === "\\") j++;
|
|
1407
|
+
else if (c !== "`" && code[j] === "\n") break;
|
|
1408
|
+
j++;
|
|
1409
|
+
}
|
|
1410
|
+
out += code.slice(i, j + 1);
|
|
1411
|
+
i = j + 1;
|
|
1412
|
+
} else {
|
|
1413
|
+
out += c;
|
|
1414
|
+
i++;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
return out;
|
|
1418
|
+
}
|
|
1419
|
+
function walkSource(dir, out = []) {
|
|
1420
|
+
if (!existsSync(dir)) return out;
|
|
1421
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1422
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
1423
|
+
const p = path28.join(dir, entry.name);
|
|
1424
|
+
if (entry.isDirectory()) walkSource(p, out);
|
|
1425
|
+
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1426
|
+
}
|
|
1427
|
+
return out;
|
|
1428
|
+
}
|
|
1298
1429
|
function exportTypes(target) {
|
|
1299
1430
|
if (!target || typeof target !== "object") return void 0;
|
|
1300
1431
|
const t = target;
|
|
@@ -1309,7 +1440,7 @@ function walkDts(dir, out = []) {
|
|
|
1309
1440
|
if (!existsSync(dir)) return out;
|
|
1310
1441
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
1311
1442
|
if (entry.name === "node_modules") continue;
|
|
1312
|
-
const p =
|
|
1443
|
+
const p = path28.join(dir, entry.name);
|
|
1313
1444
|
if (entry.isDirectory()) walkDts(p, out);
|
|
1314
1445
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
1315
1446
|
}
|
|
@@ -1326,27 +1457,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
1326
1457
|
}
|
|
1327
1458
|
const files = [];
|
|
1328
1459
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
1329
|
-
const themes = ds &&
|
|
1460
|
+
const themes = ds && path28.join(ds, "dist", "themes");
|
|
1330
1461
|
if (themes && existsSync(themes)) {
|
|
1331
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
1462
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path28.join(themes, name));
|
|
1332
1463
|
}
|
|
1333
1464
|
if (files.length === 0) {
|
|
1334
1465
|
throw new DoctorConfigError(
|
|
1335
1466
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
1336
1467
|
);
|
|
1337
1468
|
}
|
|
1338
|
-
const uiStyles =
|
|
1469
|
+
const uiStyles = path28.join(uiDir, "dist", "styles.css");
|
|
1339
1470
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
1340
1471
|
return files;
|
|
1341
1472
|
}
|
|
1342
1473
|
function resolveSpec(root, spec) {
|
|
1343
|
-
const local =
|
|
1344
|
-
if (spec.startsWith(".") ||
|
|
1474
|
+
const local = path28.resolve(root, spec);
|
|
1475
|
+
if (spec.startsWith(".") || path28.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
1345
1476
|
const parts = spec.split("/");
|
|
1346
1477
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
1347
1478
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
1348
1479
|
if (dir) {
|
|
1349
|
-
const file =
|
|
1480
|
+
const file = path28.join(dir, ...parts.slice(nameLength));
|
|
1350
1481
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
1351
1482
|
}
|
|
1352
1483
|
return existsSync(local) ? local : null;
|
|
@@ -1354,7 +1485,7 @@ function resolveSpec(root, spec) {
|
|
|
1354
1485
|
function loadPalette(root) {
|
|
1355
1486
|
const names = new Set(TAILWIND_PALETTE);
|
|
1356
1487
|
try {
|
|
1357
|
-
const req = createRequire(
|
|
1488
|
+
const req = createRequire(path28.join(root, "package.json"));
|
|
1358
1489
|
const colors = req("tailwindcss/colors");
|
|
1359
1490
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
1360
1491
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -1363,7 +1494,7 @@ function loadPalette(root) {
|
|
|
1363
1494
|
}
|
|
1364
1495
|
return [...names].sort();
|
|
1365
1496
|
}
|
|
1366
|
-
var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, DEFAULT_COMPONENT_PACKAGES, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE;
|
|
1497
|
+
var DEFAULT_UI_PACKAGE, NATIVE_UI_PACKAGE, DESIGN_SYSTEM_PACKAGE, DEFAULT_COMPONENT_PACKAGES, TAGS, TAG_ALIASES, NON_COMPONENT_SUFFIX, TAILWIND_PALETTE, TS_SOURCE, isTsSource;
|
|
1367
1498
|
var init_genesis = __esm({
|
|
1368
1499
|
"src/doctor/genesis.ts"() {
|
|
1369
1500
|
init_config();
|
|
@@ -1404,21 +1535,405 @@ var init_genesis = __esm({
|
|
|
1404
1535
|
"mist",
|
|
1405
1536
|
"olive"
|
|
1406
1537
|
];
|
|
1538
|
+
TS_SOURCE = /\.(?:[cm]?tsx?)$/;
|
|
1539
|
+
isTsSource = (v) => typeof v === "string" && TS_SOURCE.test(v) && !/\.d\.[cm]?ts$/.test(v);
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
// ../../scripts/lib/color-literals.mjs
|
|
1544
|
+
function stripBlockComments(content, hasLineComments = true) {
|
|
1545
|
+
let result = "";
|
|
1546
|
+
let i = 0;
|
|
1547
|
+
const len = content.length;
|
|
1548
|
+
while (i < len) {
|
|
1549
|
+
const ch = content[i];
|
|
1550
|
+
const next = i + 1 < len ? content[i + 1] : "";
|
|
1551
|
+
const prevIsColon = i > 0 && content[i - 1] === ":";
|
|
1552
|
+
const prevIsBackslash = i > 0 && content[i - 1] === "\\";
|
|
1553
|
+
if (ch === '"') {
|
|
1554
|
+
result += ch;
|
|
1555
|
+
i++;
|
|
1556
|
+
while (i < len) {
|
|
1557
|
+
const c = content[i];
|
|
1558
|
+
result += c;
|
|
1559
|
+
if (c === "\\" && i + 1 < len) {
|
|
1560
|
+
result += content[i + 1];
|
|
1561
|
+
i += 2;
|
|
1562
|
+
} else if (c === '"') {
|
|
1563
|
+
i++;
|
|
1564
|
+
break;
|
|
1565
|
+
} else {
|
|
1566
|
+
i++;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
continue;
|
|
1570
|
+
}
|
|
1571
|
+
if (ch === "'") {
|
|
1572
|
+
result += ch;
|
|
1573
|
+
i++;
|
|
1574
|
+
while (i < len) {
|
|
1575
|
+
const c = content[i];
|
|
1576
|
+
result += c;
|
|
1577
|
+
if (c === "\\" && i + 1 < len) {
|
|
1578
|
+
result += content[i + 1];
|
|
1579
|
+
i += 2;
|
|
1580
|
+
} else if (c === "'") {
|
|
1581
|
+
i++;
|
|
1582
|
+
break;
|
|
1583
|
+
} else {
|
|
1584
|
+
i++;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
continue;
|
|
1588
|
+
}
|
|
1589
|
+
if (ch === "`") {
|
|
1590
|
+
result += ch;
|
|
1591
|
+
i++;
|
|
1592
|
+
while (i < len) {
|
|
1593
|
+
const c = content[i];
|
|
1594
|
+
result += c;
|
|
1595
|
+
if (c === "\\" && i + 1 < len) {
|
|
1596
|
+
result += content[i + 1];
|
|
1597
|
+
i += 2;
|
|
1598
|
+
} else if (c === "`") {
|
|
1599
|
+
i++;
|
|
1600
|
+
break;
|
|
1601
|
+
} else {
|
|
1602
|
+
i++;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
if ((ch === "u" || ch === "U") && content.slice(i, i + 4).toLowerCase() === "url(" && !/[\w$]/.test(content[i - 1] ?? "")) {
|
|
1608
|
+
result += content.slice(i, i + 4);
|
|
1609
|
+
i += 4;
|
|
1610
|
+
while (i < len && content[i] !== ")") {
|
|
1611
|
+
const c = content[i];
|
|
1612
|
+
if (c === '"' || c === "'") {
|
|
1613
|
+
result += c;
|
|
1614
|
+
i++;
|
|
1615
|
+
while (i < len) {
|
|
1616
|
+
const q = content[i];
|
|
1617
|
+
result += q;
|
|
1618
|
+
if (q === "\\" && i + 1 < len) {
|
|
1619
|
+
result += content[i + 1];
|
|
1620
|
+
i += 2;
|
|
1621
|
+
} else if (q === c) {
|
|
1622
|
+
i++;
|
|
1623
|
+
break;
|
|
1624
|
+
} else {
|
|
1625
|
+
i++;
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
} else {
|
|
1629
|
+
result += c;
|
|
1630
|
+
i++;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
if (i < len && content[i] === ")") {
|
|
1634
|
+
result += ")";
|
|
1635
|
+
i++;
|
|
1636
|
+
}
|
|
1637
|
+
continue;
|
|
1638
|
+
}
|
|
1639
|
+
if (hasLineComments && ch === "/" && next === "/" && !prevIsColon && !prevIsBackslash) {
|
|
1640
|
+
let j = i + 2;
|
|
1641
|
+
while (j < len && content[j] !== "\n") {
|
|
1642
|
+
j++;
|
|
1643
|
+
}
|
|
1644
|
+
const commentLen = j - i;
|
|
1645
|
+
const commentText = content.slice(i, i + commentLen);
|
|
1646
|
+
result += commentText.replace(/[^\n]/g, " ");
|
|
1647
|
+
i += commentLen;
|
|
1648
|
+
continue;
|
|
1649
|
+
}
|
|
1650
|
+
if (ch === "/" && next === "*") {
|
|
1651
|
+
let commentLen = 2;
|
|
1652
|
+
let j = i + 2;
|
|
1653
|
+
while (j < len) {
|
|
1654
|
+
if (content[j] === "*" && j + 1 < len && content[j + 1] === "/") {
|
|
1655
|
+
commentLen = j + 2 - i;
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
j++;
|
|
1659
|
+
}
|
|
1660
|
+
const commentText = content.slice(i, i + commentLen);
|
|
1661
|
+
result += commentText.replace(/[^\n]/g, " ");
|
|
1662
|
+
i += commentLen;
|
|
1663
|
+
continue;
|
|
1664
|
+
}
|
|
1665
|
+
result += ch;
|
|
1666
|
+
i++;
|
|
1667
|
+
}
|
|
1668
|
+
return result;
|
|
1669
|
+
}
|
|
1670
|
+
function stripHtmlEntities(line) {
|
|
1671
|
+
return line.replace(HTML_ENTITY_RE, "");
|
|
1672
|
+
}
|
|
1673
|
+
function findHexLiterals(line) {
|
|
1674
|
+
const cleaned = stripHtmlEntities(line);
|
|
1675
|
+
const matches = [];
|
|
1676
|
+
let m;
|
|
1677
|
+
HEX_RE.lastIndex = 0;
|
|
1678
|
+
while ((m = HEX_RE.exec(cleaned)) !== null) {
|
|
1679
|
+
const digits = m[2];
|
|
1680
|
+
if (digits.length <= 4 && !HEX_LETTER_RE.test(digits)) continue;
|
|
1681
|
+
const literal2 = `#${digits}`;
|
|
1682
|
+
const idx = m.index + m[1].length;
|
|
1683
|
+
matches.push({ literal: literal2, column: idx + 1 });
|
|
1684
|
+
}
|
|
1685
|
+
return matches;
|
|
1686
|
+
}
|
|
1687
|
+
function findColorFunctions(line) {
|
|
1688
|
+
const cleaned = stripHtmlEntities(line);
|
|
1689
|
+
const matches = [];
|
|
1690
|
+
let m;
|
|
1691
|
+
COLOR_FN_RE.lastIndex = 0;
|
|
1692
|
+
while ((m = COLOR_FN_RE.exec(cleaned)) !== null) {
|
|
1693
|
+
matches.push({ literal: m[0], column: m.index + 1 });
|
|
1694
|
+
}
|
|
1695
|
+
return matches;
|
|
1696
|
+
}
|
|
1697
|
+
var LINE_COMMENT_EXTS, HTML_ENTITY_RE, HEX_RE, HEX_LETTER_RE, COLOR_FN_RE;
|
|
1698
|
+
var init_color_literals = __esm({
|
|
1699
|
+
"../../scripts/lib/color-literals.mjs"() {
|
|
1700
|
+
LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
|
|
1701
|
+
HTML_ENTITY_RE = /&#\d+;/g;
|
|
1702
|
+
HEX_RE = /(^|[^\w&])#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g;
|
|
1703
|
+
HEX_LETTER_RE = /[a-fA-F]/;
|
|
1704
|
+
COLOR_FN_RE = /\b(rgba?|hsla?)\(\s*[\d.][^)\n]*\)?/gi;
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
|
|
1708
|
+
// src/doctor/glob.ts
|
|
1709
|
+
function globToRegExp(glob) {
|
|
1710
|
+
let g = glob.trim().replace(/^\.\//, "");
|
|
1711
|
+
if (g.endsWith("/")) g += "**";
|
|
1712
|
+
let out = "";
|
|
1713
|
+
for (let i = 0; i < g.length; i++) {
|
|
1714
|
+
const ch = g[i];
|
|
1715
|
+
if (ch === "*") {
|
|
1716
|
+
if (g[i + 1] === "*") {
|
|
1717
|
+
const slash = g[i + 2] === "/";
|
|
1718
|
+
out += slash ? "(?:.*/)?" : ".*";
|
|
1719
|
+
i += slash ? 2 : 1;
|
|
1720
|
+
} else {
|
|
1721
|
+
out += "[^/]*";
|
|
1722
|
+
}
|
|
1723
|
+
} else if (ch === "?") {
|
|
1724
|
+
out += "[^/]";
|
|
1725
|
+
} else {
|
|
1726
|
+
out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return new RegExp(`^${out}$`);
|
|
1730
|
+
}
|
|
1731
|
+
function globMatcher(globs) {
|
|
1732
|
+
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1733
|
+
return (path48) => res.some((re) => re.test(path48));
|
|
1734
|
+
}
|
|
1735
|
+
var init_glob = __esm({
|
|
1736
|
+
"src/doctor/glob.ts"() {
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
1739
|
+
function scanFiles(root, config) {
|
|
1740
|
+
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
1741
|
+
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
1742
|
+
const files = [];
|
|
1743
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1744
|
+
const visit = (abs) => {
|
|
1745
|
+
const rel = toPosix(path28.relative(root, abs));
|
|
1746
|
+
if (seen.has(rel) || ignored(rel)) return;
|
|
1747
|
+
const ext = path28.extname(abs);
|
|
1748
|
+
if (!extensions.has(ext)) return;
|
|
1749
|
+
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
1750
|
+
seen.add(rel);
|
|
1751
|
+
const text = readFileSync(abs, "utf8");
|
|
1752
|
+
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
1753
|
+
};
|
|
1754
|
+
const walk2 = (dir) => {
|
|
1755
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
1756
|
+
if (entry.isDirectory()) {
|
|
1757
|
+
if (!SKIP_DIRS.has(entry.name)) walk2(path28.join(dir, entry.name));
|
|
1758
|
+
} else if (entry.isFile()) {
|
|
1759
|
+
visit(path28.join(dir, entry.name));
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
};
|
|
1763
|
+
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
1764
|
+
const abs = path28.resolve(root, src);
|
|
1765
|
+
if (!existsSync(abs)) continue;
|
|
1766
|
+
if (statSync(abs).isDirectory()) walk2(abs);
|
|
1767
|
+
else visit(abs);
|
|
1768
|
+
}
|
|
1769
|
+
let local = [];
|
|
1770
|
+
try {
|
|
1771
|
+
local = localPackages(root);
|
|
1772
|
+
} catch {
|
|
1773
|
+
local = [];
|
|
1774
|
+
}
|
|
1775
|
+
for (const pkg of local) walk2(pkg.dir);
|
|
1776
|
+
return files;
|
|
1777
|
+
}
|
|
1778
|
+
function lineAt(text, index) {
|
|
1779
|
+
let line = 1;
|
|
1780
|
+
for (let i = 0; i < index && i < text.length; i++) if (text.charCodeAt(i) === 10) line++;
|
|
1781
|
+
return line;
|
|
1782
|
+
}
|
|
1783
|
+
var DEFAULT_SRC, DEFAULT_NATIVE_SRC, DEFAULT_EXTENSIONS, DEFAULT_IGNORE, SKIP_DIRS, MAX_FILE_BYTES, toPosix;
|
|
1784
|
+
var init_scan = __esm({
|
|
1785
|
+
"src/doctor/scan.ts"() {
|
|
1786
|
+
init_local();
|
|
1787
|
+
init_color_literals();
|
|
1788
|
+
init_glob();
|
|
1789
|
+
DEFAULT_SRC = ["src"];
|
|
1790
|
+
DEFAULT_NATIVE_SRC = ["app", "src", "components"];
|
|
1791
|
+
DEFAULT_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".css"];
|
|
1792
|
+
DEFAULT_IGNORE = [
|
|
1793
|
+
"**/*.d.ts",
|
|
1794
|
+
"**/*.gen.*",
|
|
1795
|
+
"**/*.test.*",
|
|
1796
|
+
"**/*.spec.*",
|
|
1797
|
+
"**/__tests__/**",
|
|
1798
|
+
"**/__fixtures__/**",
|
|
1799
|
+
"**/__mocks__/**"
|
|
1800
|
+
];
|
|
1801
|
+
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
1802
|
+
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
1803
|
+
toPosix = (p) => p.split(path28.sep).join("/");
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
function overlayState(name, json) {
|
|
1807
|
+
const raw = json?.genesis?.overlay;
|
|
1808
|
+
if (raw === void 0) return { kind: "none" };
|
|
1809
|
+
const problems = [];
|
|
1810
|
+
const marker = readOverlayMarker(name, raw, problems);
|
|
1811
|
+
return marker ? { kind: "marked", marker } : { kind: "invalid", problems };
|
|
1812
|
+
}
|
|
1813
|
+
function overlaySetupProblems(root, config, dir, name, json) {
|
|
1814
|
+
const problems = [];
|
|
1815
|
+
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
1816
|
+
const rel = path28.relative(path28.resolve(root), path28.resolve(dir)).split(path28.sep).join("/");
|
|
1817
|
+
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
1818
|
+
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
1819
|
+
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})`);
|
|
1820
|
+
return problems;
|
|
1821
|
+
}
|
|
1822
|
+
function markedOverlays(ctx) {
|
|
1823
|
+
const out = /* @__PURE__ */ new Map();
|
|
1824
|
+
for (const p of ctx.packages) {
|
|
1825
|
+
if (!p.local || !p.overlay) continue;
|
|
1826
|
+
if (overlaySetupProblems(ctx.root, ctx.config, p.dir, p.name, { private: p.private }).length) continue;
|
|
1827
|
+
out.set(p.name, { dir: p.dir, marker: p.overlay });
|
|
1828
|
+
}
|
|
1829
|
+
return out;
|
|
1830
|
+
}
|
|
1831
|
+
function insideOverlayOf(overlays, file, packageName3) {
|
|
1832
|
+
const dir = overlays.get(packageName3)?.dir;
|
|
1833
|
+
return dir !== void 0 && inside(dir, file.absolutePath);
|
|
1834
|
+
}
|
|
1835
|
+
function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
|
|
1836
|
+
const [y, m, d] = since.split("-").map(Number);
|
|
1837
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
1838
|
+
return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
|
|
1839
|
+
}
|
|
1840
|
+
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
1841
|
+
let packages;
|
|
1842
|
+
try {
|
|
1843
|
+
packages = localPackages(ctx.root);
|
|
1844
|
+
} catch {
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1847
|
+
for (const pkg of packages) {
|
|
1848
|
+
if (!GENESIS_PACKAGE_NAME.test(pkg.name)) continue;
|
|
1849
|
+
const file = `${pkg.rel}/package.json`;
|
|
1850
|
+
let json;
|
|
1851
|
+
try {
|
|
1852
|
+
json = JSON.parse(readFileSync(path28.join(pkg.dir, "package.json"), "utf8"));
|
|
1853
|
+
} catch {
|
|
1854
|
+
continue;
|
|
1855
|
+
}
|
|
1856
|
+
const state = overlayState(pkg.name, json);
|
|
1857
|
+
if (state.kind === "none") {
|
|
1858
|
+
ctx.report({
|
|
1859
|
+
rule: "overlay-unmarked",
|
|
1860
|
+
file,
|
|
1861
|
+
subject: pkg.name,
|
|
1862
|
+
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`
|
|
1863
|
+
});
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
if (state.kind === "invalid") {
|
|
1867
|
+
for (const problem of state.problems) ctx.report({ rule: "overlay-invalid", file, subject: pkg.name, message: problem });
|
|
1868
|
+
continue;
|
|
1869
|
+
}
|
|
1870
|
+
const { marker } = state;
|
|
1871
|
+
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 });
|
|
1872
|
+
const age = overlayAgeDays(marker.since, now);
|
|
1873
|
+
if (age < -1) {
|
|
1874
|
+
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` });
|
|
1875
|
+
} else if (age > OVERLAY_NOTICE_DAYS) {
|
|
1876
|
+
ctx.report({
|
|
1877
|
+
rule: "overlay-age",
|
|
1878
|
+
level: age > OVERLAY_WARN_DAYS ? "warn" : "info",
|
|
1879
|
+
file,
|
|
1880
|
+
subject: pkg.name,
|
|
1881
|
+
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)`
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
const upstream2 = overlayUpstream(marker).version;
|
|
1885
|
+
const version = typeof json.version === "string" ? json.version : "";
|
|
1886
|
+
if (LOCAL_VERSION.exec(version)?.[1] !== upstream2) {
|
|
1887
|
+
ctx.report({
|
|
1888
|
+
rule: "overlay-version",
|
|
1889
|
+
level: "warn",
|
|
1890
|
+
file,
|
|
1891
|
+
subject: version || "(none)",
|
|
1892
|
+
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream2}+local.N (or ${upstream2} itself) so it reads as a local build of ${upstream2} and still satisfies peer ranges`
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
var GENESIS_PACKAGE_NAME, OVERLAY_NOTICE_DAYS, OVERLAY_WARN_DAYS, LOCAL_VERSION;
|
|
1898
|
+
var init_overlays = __esm({
|
|
1899
|
+
"src/doctor/overlays.ts"() {
|
|
1900
|
+
init_files();
|
|
1901
|
+
init_local();
|
|
1902
|
+
init_scan();
|
|
1903
|
+
GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
1904
|
+
OVERLAY_NOTICE_DAYS = 14;
|
|
1905
|
+
OVERLAY_WARN_DAYS = 30;
|
|
1906
|
+
LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
|
|
1407
1907
|
}
|
|
1408
1908
|
});
|
|
1409
1909
|
function readReleaseManifest(root) {
|
|
1410
1910
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
1411
|
-
const file = dir &&
|
|
1911
|
+
const file = dir && path28.join(dir, "dist", "versions.json");
|
|
1412
1912
|
if (!file || !existsSync(file)) return null;
|
|
1413
1913
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
1414
1914
|
}
|
|
1415
1915
|
function checkVersionSkew(ctx) {
|
|
1416
1916
|
const manifest = readReleaseManifest(ctx.root);
|
|
1417
1917
|
if (!manifest) return;
|
|
1918
|
+
const overlays = markedOverlays(ctx);
|
|
1418
1919
|
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
1920
|
+
const overlay = overlays.get(name);
|
|
1921
|
+
if (overlay) {
|
|
1922
|
+
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
1923
|
+
if (from !== want) {
|
|
1924
|
+
ctx.report({
|
|
1925
|
+
rule: "version-skew",
|
|
1926
|
+
level: "warn",
|
|
1927
|
+
file: "package.json",
|
|
1928
|
+
subject: name,
|
|
1929
|
+
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).`
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
continue;
|
|
1933
|
+
}
|
|
1419
1934
|
const dir = findPackageDir(ctx.root, name);
|
|
1420
1935
|
if (!dir) continue;
|
|
1421
|
-
const have = JSON.parse(readFileSync(
|
|
1936
|
+
const have = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8")).version;
|
|
1422
1937
|
if (have === want) continue;
|
|
1423
1938
|
ctx.report({
|
|
1424
1939
|
rule: "version-skew",
|
|
@@ -1433,17 +1948,18 @@ var UMBRELLA_PACKAGE;
|
|
|
1433
1948
|
var init_versions = __esm({
|
|
1434
1949
|
"src/doctor/versions.ts"() {
|
|
1435
1950
|
init_genesis();
|
|
1951
|
+
init_overlays();
|
|
1436
1952
|
UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
1437
1953
|
}
|
|
1438
1954
|
});
|
|
1439
1955
|
function detectPackageManager(root) {
|
|
1440
|
-
let dir =
|
|
1956
|
+
let dir = path28.resolve(root);
|
|
1441
1957
|
for (; ; ) {
|
|
1442
|
-
if (existsSync(
|
|
1443
|
-
if (existsSync(
|
|
1444
|
-
if (existsSync(
|
|
1445
|
-
if (existsSync(
|
|
1446
|
-
const parent =
|
|
1958
|
+
if (existsSync(path28.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1959
|
+
if (existsSync(path28.join(dir, "bun.lock")) || existsSync(path28.join(dir, "bun.lockb"))) return "bun";
|
|
1960
|
+
if (existsSync(path28.join(dir, "yarn.lock"))) return "yarn";
|
|
1961
|
+
if (existsSync(path28.join(dir, "package-lock.json"))) return "npm";
|
|
1962
|
+
const parent = path28.dirname(dir);
|
|
1447
1963
|
if (parent === dir) return "npm";
|
|
1448
1964
|
dir = parent;
|
|
1449
1965
|
}
|
|
@@ -1479,10 +1995,10 @@ var init_pm = __esm({
|
|
|
1479
1995
|
function walk(dir, exclude = []) {
|
|
1480
1996
|
const out = [];
|
|
1481
1997
|
const visit = (rel) => {
|
|
1482
|
-
for (const name of readdirSync(
|
|
1998
|
+
for (const name of readdirSync(path28.join(dir, rel)).sort()) {
|
|
1483
1999
|
const child = rel ? `${rel}/${name}` : name;
|
|
1484
2000
|
if (exclude.some((r) => r.test(child))) continue;
|
|
1485
|
-
const stat = statSync(
|
|
2001
|
+
const stat = statSync(path28.join(dir, child));
|
|
1486
2002
|
if (stat.isDirectory()) visit(child);
|
|
1487
2003
|
else if (stat.isFile()) out.push(child);
|
|
1488
2004
|
}
|
|
@@ -1511,17 +2027,17 @@ var init_walk = __esm({
|
|
|
1511
2027
|
});
|
|
1512
2028
|
function starterDir() {
|
|
1513
2029
|
const workspace = workspacePackagesDir();
|
|
1514
|
-
const live = workspace &&
|
|
1515
|
-
if (live && existsSync(
|
|
1516
|
-
const packaged =
|
|
1517
|
-
if (existsSync(
|
|
2030
|
+
const live = workspace && path28.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
2031
|
+
if (live && existsSync(path28.join(live, "package.json"))) return live;
|
|
2032
|
+
const packaged = path28.join(cliPackageDir(), "dist", "starter");
|
|
2033
|
+
if (existsSync(path28.join(packaged, "package.json"))) return packaged;
|
|
1518
2034
|
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
1519
2035
|
}
|
|
1520
2036
|
function templatesDir(cliDir = cliPackageDir()) {
|
|
1521
2037
|
const workspace = workspacePackagesDir();
|
|
1522
|
-
const live = workspace && cliDir === cliPackageDir() ?
|
|
1523
|
-
if (live && existsSync(
|
|
1524
|
-
const packaged =
|
|
2038
|
+
const live = workspace && cliDir === cliPackageDir() ? path28.join(workspace, "..", "templates") : null;
|
|
2039
|
+
if (live && existsSync(path28.join(live, "eas"))) return live;
|
|
2040
|
+
const packaged = path28.join(cliDir, "dist", "templates");
|
|
1525
2041
|
if (existsSync(packaged)) return packaged;
|
|
1526
2042
|
throw new Error(`${cliDir} has no templates (dist/templates is missing).`);
|
|
1527
2043
|
}
|
|
@@ -1602,10 +2118,10 @@ function initNative(options) {
|
|
|
1602
2118
|
if (!BUNDLE.test(bundleId)) throw new Error(`"${bundleId}" isn't a bundle id like com.example.app.`);
|
|
1603
2119
|
if (!SCHEME.test(scheme)) throw new Error(`"${scheme}" isn't a URL scheme.`);
|
|
1604
2120
|
if (/["\\\n]/.test(display)) throw new Error("The display name can't contain quotes, backslashes or new lines.");
|
|
1605
|
-
const target =
|
|
2121
|
+
const target = path28.resolve(options.target);
|
|
1606
2122
|
if (existsSync(target) && readdirSync(target).length) throw new Error(`${target} isn't empty; init writes into a new folder and never overwrites.`);
|
|
1607
2123
|
const source = starterDir();
|
|
1608
|
-
const read2 = (rel) => readFileSync(
|
|
2124
|
+
const read2 = (rel) => readFileSync(path28.join(source, rel), "utf8");
|
|
1609
2125
|
const was = starterIdentity(read2("starter.config.ts"));
|
|
1610
2126
|
const substitutions = { [was.bundleId]: bundleId, [was.slug]: slug, [was.scheme]: scheme, [was.name]: display };
|
|
1611
2127
|
const files = /* @__PURE__ */ new Map();
|
|
@@ -1636,14 +2152,14 @@ function initNative(options) {
|
|
|
1636
2152
|
files.set("package.json", `${JSON.stringify(pkg, null, 2)}
|
|
1637
2153
|
`);
|
|
1638
2154
|
files.set("metro.config.js", METRO);
|
|
1639
|
-
const pnpmSettings = [
|
|
2155
|
+
const pnpmSettings = [path28.join(source, "pnpm-workspace.yaml"), path28.join(source, "..", "..", "pnpm-workspace.yaml")].find((f) => existsSync(f));
|
|
1640
2156
|
if (pnpmSettings) files.set("pnpm-workspace.yaml", appPnpmSettings(readFileSync(pnpmSettings, "utf8")));
|
|
1641
2157
|
files.set("README.md", readme(display, slug));
|
|
1642
2158
|
const lock = { ...emptyLock(), substitutions };
|
|
1643
2159
|
const cliVersion2 = pinnedVersion(target, CLI_PACKAGE)?.version;
|
|
1644
2160
|
const templates = templatesDir();
|
|
1645
2161
|
for (const rel of walk(templates)) {
|
|
1646
|
-
const text = substitute(readFileSync(
|
|
2162
|
+
const text = substitute(readFileSync(path28.join(templates, rel), "utf8"), substitutions);
|
|
1647
2163
|
const to = templateTarget(rel, text);
|
|
1648
2164
|
files.set(to, text);
|
|
1649
2165
|
lock.files[to] = { source: `${CLI_PACKAGE}:templates/${rel}`, sha256: sha256(text), ...cliVersion2 ? { version: cliVersion2 } : {} };
|
|
@@ -1654,13 +2170,14 @@ function initNative(options) {
|
|
|
1654
2170
|
const blocks = [];
|
|
1655
2171
|
for (const block of options.blocks) {
|
|
1656
2172
|
const stems = block.migrations.map((m) => stemOf(m.file));
|
|
1657
|
-
const copies = stems.map((s) => migrations.find((f) =>
|
|
2173
|
+
const copies = stems.map((s) => migrations.find((f) => path28.posix.basename(f).replace(/^\d+_/, "") === `${s}.sql`));
|
|
1658
2174
|
if (!stems.length || copies.some((c) => !c)) continue;
|
|
1659
2175
|
blocks.push(block.id);
|
|
1660
2176
|
lock.blocks[block.id] = { package: block.package, ...block.version ? { version: block.version } : {} };
|
|
1661
|
-
block.migrations.forEach((m) => {
|
|
2177
|
+
block.migrations.forEach((m, i) => {
|
|
2178
|
+
lock.migrations = { ...lock.migrations, [migrationKey(m.package, m.file)]: copies[i] };
|
|
1662
2179
|
if (m.test) {
|
|
1663
|
-
const test2 = `${TESTS_DIR}/${
|
|
2180
|
+
const test2 = `${TESTS_DIR}/${path28.posix.basename(m.test).replace(/^\d{4}_/, "")}`;
|
|
1664
2181
|
if (files.has(test2)) lock.files[test2] = { source: `${m.package}:${m.test}`, sha256: sha256(files.get(test2)) };
|
|
1665
2182
|
}
|
|
1666
2183
|
});
|
|
@@ -1673,8 +2190,8 @@ function initNative(options) {
|
|
|
1673
2190
|
}
|
|
1674
2191
|
mkdirSync(target, { recursive: true });
|
|
1675
2192
|
for (const [rel, content] of [...files].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1676
|
-
const file =
|
|
1677
|
-
mkdirSync(
|
|
2193
|
+
const file = path28.join(target, ...rel.split("/"));
|
|
2194
|
+
mkdirSync(path28.dirname(file), { recursive: true });
|
|
1678
2195
|
writeFileSync(file, content, { encoding: "utf8", flag: "wx" });
|
|
1679
2196
|
}
|
|
1680
2197
|
writeLock(target, lock);
|
|
@@ -1905,6 +2422,16 @@ function parse(comment, keys, where2) {
|
|
|
1905
2422
|
if (!kind) {
|
|
1906
2423
|
throw new CommentSettingsError(`${where2}: unknown ${MARKER} setting "${key2}". Allowed: ${Object.keys(keys).join(", ")}.`);
|
|
1907
2424
|
}
|
|
2425
|
+
if (kind === "key") {
|
|
2426
|
+
const list = typeof v === "string" ? [v] : v;
|
|
2427
|
+
if (!Array.isArray(list) || list.length === 0 || !list.every((c) => typeof c === "string" && c !== "")) {
|
|
2428
|
+
throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" must be a column name or a list of them.`);
|
|
2429
|
+
}
|
|
2430
|
+
const twice = list.find((c, i) => list.indexOf(c) !== i);
|
|
2431
|
+
if (twice) throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" names "${twice}" twice.`);
|
|
2432
|
+
settings2[key2] = list;
|
|
2433
|
+
continue;
|
|
2434
|
+
}
|
|
1908
2435
|
if (typeof v !== kind) throw new CommentSettingsError(`${where2}: ${MARKER} "${key2}" must be a ${kind}.`);
|
|
1909
2436
|
settings2[key2] = v;
|
|
1910
2437
|
}
|
|
@@ -1919,11 +2446,22 @@ function parseTableComment(comment, table) {
|
|
|
1919
2446
|
function parseColumnComment(comment, column) {
|
|
1920
2447
|
return parse(comment, FIELD_KEYS, column);
|
|
1921
2448
|
}
|
|
2449
|
+
function withKeySetting(table, warn) {
|
|
2450
|
+
const key2 = table.settings?.key;
|
|
2451
|
+
if (!key2) return table;
|
|
2452
|
+
const columns = new Set(table.columns.map((c) => c.name));
|
|
2453
|
+
const missing = key2.filter((k) => !columns.has(k));
|
|
2454
|
+
if (missing.length) throw new CommentSettingsError(`${table.name}: ${MARKER} key "${missing.join('", "')}" isn't one of its columns.`);
|
|
2455
|
+
if (table.key.length && table.key.join("\0") !== key2.join("\0")) {
|
|
2456
|
+
warn?.(`${table.name}: ${MARKER} key (${key2.join(", ")}) differs from its primary key (${table.key.join(", ")}); the comment's key is used.`);
|
|
2457
|
+
}
|
|
2458
|
+
return { ...table, key: [...key2] };
|
|
2459
|
+
}
|
|
1922
2460
|
var MARKER, TABLE_KEYS, FIELD_KEYS, CommentSettingsError;
|
|
1923
2461
|
var init_comments = __esm({
|
|
1924
2462
|
"src/introspect/comments.ts"() {
|
|
1925
2463
|
MARKER = "@genesis";
|
|
1926
|
-
TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string" };
|
|
2464
|
+
TABLE_KEYS = { label: "string", labelField: "string", description: "string", noun: "string", nounPlural: "string", key: "key" };
|
|
1927
2465
|
FIELD_KEYS = { label: "string", description: "string", widget: "string", readonly: "boolean", sensitive: "boolean" };
|
|
1928
2466
|
CommentSettingsError = class extends Error {
|
|
1929
2467
|
};
|
|
@@ -1954,6 +2492,12 @@ var init_model = __esm({
|
|
|
1954
2492
|
function where(sql, scope) {
|
|
1955
2493
|
return "schemas" in scope ? sql`n.nspname = any(${scope.schemas})` : sql`c.oid = any(${scope.oids}::oid[])`;
|
|
1956
2494
|
}
|
|
2495
|
+
function linkOf(columns, refColumns, refUnique = []) {
|
|
2496
|
+
if (columns.length === 1) return 0;
|
|
2497
|
+
if (columns.length !== refColumns.length) return -1;
|
|
2498
|
+
const own = columns.flatMap((c, i) => c === refColumns[i] ? [] : [i]);
|
|
2499
|
+
return own.length === 1 && refUnique[own[0]] === true ? own[0] : -1;
|
|
2500
|
+
}
|
|
1957
2501
|
async function readRelations(sql, scope, into) {
|
|
1958
2502
|
const columns = await sql`
|
|
1959
2503
|
select c.oid::text as oid, c.relkind::text as relkind, n.nspname as schema, c.relname as table,
|
|
@@ -1985,16 +2529,24 @@ async function readRelations(sql, scope, into) {
|
|
|
1985
2529
|
where con.contype = 'p' and ${where(sql, scope)}
|
|
1986
2530
|
group by c.oid`;
|
|
1987
2531
|
const links = await sql`
|
|
1988
|
-
select c.oid::text as oid, con.conkey[
|
|
1989
|
-
|
|
2532
|
+
select c.oid::text as oid, con.conkey::int[] as attnums,
|
|
2533
|
+
array(select a.attname::text from unnest(con.conkey) with ordinality k(attnum, ord)
|
|
2534
|
+
join pg_attribute a on a.attrelid = c.oid and a.attnum = k.attnum order by k.ord) as columns,
|
|
2535
|
+
array(select ra.attname::text from unnest(con.confkey) with ordinality k(attnum, ord)
|
|
2536
|
+
join pg_attribute ra on ra.attrelid = con.confrelid and ra.attnum = k.attnum order by k.ord) as ref_columns,
|
|
2537
|
+
array(select exists (select 1 from pg_index i
|
|
2538
|
+
where i.indrelid = con.confrelid and i.indisunique and i.indpred is null
|
|
2539
|
+
and i.indnkeyatts = 1 and i.indkey[0] = k.attnum)
|
|
2540
|
+
from unnest(con.confkey) with ordinality k(attnum, ord) order by k.ord) as ref_unique,
|
|
2541
|
+
rn.nspname as ref_schema, rc.relname as ref_table
|
|
1990
2542
|
from pg_constraint con
|
|
1991
2543
|
join pg_class c on c.oid = con.conrelid
|
|
1992
2544
|
join pg_namespace n on n.oid = c.relnamespace
|
|
1993
2545
|
join pg_class rc on rc.oid = con.confrelid
|
|
1994
2546
|
join pg_namespace rn on rn.oid = rc.relnamespace
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
2547
|
+
where con.contype = 'f'
|
|
2548
|
+
and ${where(sql, scope)}
|
|
2549
|
+
order by con.conname`;
|
|
1998
2550
|
const checks = await sql`
|
|
1999
2551
|
select c.oid::text as oid, con.conkey[1]::int as attnum, a.attname as column,
|
|
2000
2552
|
pg_get_constraintdef(con.oid) as definition
|
|
@@ -2059,9 +2611,12 @@ async function readRelations(sql, scope, into) {
|
|
|
2059
2611
|
const relation = into.get(k.oid);
|
|
2060
2612
|
if (relation) relation.key = k.columns;
|
|
2061
2613
|
}
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2614
|
+
const ordered = [...links].sort((a, b) => a.attnums.length - b.attnums.length);
|
|
2615
|
+
for (const l of ordered) {
|
|
2616
|
+
const at = linkOf(l.columns, l.ref_columns, l.ref_unique);
|
|
2617
|
+
if (at < 0) continue;
|
|
2618
|
+
const column = into.get(l.oid)?.columns.get(l.attnums[at]);
|
|
2619
|
+
if (column && !column.references) column.references = { resource: qualifiedName(l.ref_schema, l.ref_table), field: l.ref_columns[at] };
|
|
2065
2620
|
}
|
|
2066
2621
|
const listed = /* @__PURE__ */ new Map();
|
|
2067
2622
|
for (const check of checks) {
|
|
@@ -2110,14 +2665,14 @@ function inherit(own, source) {
|
|
|
2110
2665
|
}
|
|
2111
2666
|
function resolveViews(relations) {
|
|
2112
2667
|
const done = /* @__PURE__ */ new Set();
|
|
2113
|
-
const
|
|
2668
|
+
const resolve26 = (relation, depth) => {
|
|
2114
2669
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
2115
2670
|
done.add(relation.oid);
|
|
2116
2671
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
2117
2672
|
if (sources.size !== 1) return;
|
|
2118
2673
|
const source = relations.get([...sources][0]);
|
|
2119
2674
|
if (!source) return;
|
|
2120
|
-
|
|
2675
|
+
resolve26(source, depth + 1);
|
|
2121
2676
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
2122
2677
|
for (const [attnum, origin] of relation.origins) {
|
|
2123
2678
|
const own = relation.columns.get(attnum);
|
|
@@ -2140,9 +2695,9 @@ function resolveViews(relations) {
|
|
|
2140
2695
|
};
|
|
2141
2696
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
2142
2697
|
};
|
|
2143
|
-
for (const relation of relations.values())
|
|
2698
|
+
for (const relation of relations.values()) resolve26(relation, 0);
|
|
2144
2699
|
}
|
|
2145
|
-
async function introspectPostgres(sql, schemas) {
|
|
2700
|
+
async function introspectPostgres(sql, schemas, options = {}) {
|
|
2146
2701
|
const relations = /* @__PURE__ */ new Map();
|
|
2147
2702
|
const wanted = await readRelations(sql, { schemas: [...schemas] }, relations);
|
|
2148
2703
|
for (let depth = 0; depth < MAX_VIEW_DEPTH; depth++) {
|
|
@@ -2159,7 +2714,7 @@ async function introspectPostgres(sql, schemas) {
|
|
|
2159
2714
|
resolveViews(relations);
|
|
2160
2715
|
return wanted.map((oid) => {
|
|
2161
2716
|
const relation = relations.get(oid);
|
|
2162
|
-
return { ...relation.table, key: relation.key.map((attnum) => relation.columns.get(attnum).name) };
|
|
2717
|
+
return withKeySetting({ ...relation.table, key: relation.key.map((attnum) => relation.columns.get(attnum).name) }, options.warn);
|
|
2163
2718
|
});
|
|
2164
2719
|
}
|
|
2165
2720
|
var MAX_VIEW_DEPTH;
|
|
@@ -2177,7 +2732,7 @@ function clean(description) {
|
|
|
2177
2732
|
if (!description) return void 0;
|
|
2178
2733
|
return description.replace(NOTES, "").trim() || void 0;
|
|
2179
2734
|
}
|
|
2180
|
-
function introspectOpenApi(doc, schema = "public") {
|
|
2735
|
+
function introspectOpenApi(doc, schema = "public", options = {}) {
|
|
2181
2736
|
const definitions = doc.definitions ?? doc.components?.schemas;
|
|
2182
2737
|
if (!definitions) throw new Error("This OpenAPI document has no definitions. Is it a PostgREST (Supabase /rest/v1/) spec?");
|
|
2183
2738
|
return Object.keys(definitions).sort().map((tableName) => {
|
|
@@ -2209,7 +2764,7 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
2209
2764
|
};
|
|
2210
2765
|
});
|
|
2211
2766
|
const comment = parseTableComment(def.description, name);
|
|
2212
|
-
return {
|
|
2767
|
+
return withKeySetting({
|
|
2213
2768
|
name,
|
|
2214
2769
|
schema,
|
|
2215
2770
|
table: tableName,
|
|
@@ -2217,7 +2772,7 @@ function introspectOpenApi(doc, schema = "public") {
|
|
|
2217
2772
|
columns,
|
|
2218
2773
|
...comment.description ? { description: comment.description } : {},
|
|
2219
2774
|
...comment.settings ? { settings: comment.settings } : {}
|
|
2220
|
-
};
|
|
2775
|
+
}, options.warn);
|
|
2221
2776
|
});
|
|
2222
2777
|
}
|
|
2223
2778
|
var PK, FK, NOTES;
|
|
@@ -2272,9 +2827,9 @@ function field(column, indent) {
|
|
|
2272
2827
|
return `${indent}{ ${parts.join(", ")} },`;
|
|
2273
2828
|
}
|
|
2274
2829
|
function emitContracts(tables, options) {
|
|
2275
|
-
const
|
|
2830
|
+
const sorted2 = [...tables].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
2276
2831
|
const seen = /* @__PURE__ */ new Map();
|
|
2277
|
-
for (const table of
|
|
2832
|
+
for (const table of sorted2) {
|
|
2278
2833
|
const id = typeName(table);
|
|
2279
2834
|
const other = seen.get(id);
|
|
2280
2835
|
if (other) throw new EmitError(`${other} and ${table.name} would both be named ${id}; rename one, or introspect them separately.`);
|
|
@@ -2299,7 +2854,7 @@ function emitContracts(tables, options) {
|
|
|
2299
2854
|
'import { defineResource } from "@marktiderman/genesis-core";',
|
|
2300
2855
|
""
|
|
2301
2856
|
];
|
|
2302
|
-
for (const table of
|
|
2857
|
+
for (const table of sorted2) {
|
|
2303
2858
|
const row = typeName(table);
|
|
2304
2859
|
out.push(`/** \`${table.name}\`. */`);
|
|
2305
2860
|
out.push(`export const ${constName(table)} = defineResource<${row}>()({`);
|
|
@@ -2317,11 +2872,11 @@ function emitContracts(tables, options) {
|
|
|
2317
2872
|
out.push("});", "");
|
|
2318
2873
|
}
|
|
2319
2874
|
out.push("export const contracts = {");
|
|
2320
|
-
for (const table of
|
|
2875
|
+
for (const table of sorted2) out.push(` ${quote(table.name)}: ${constName(table)},`);
|
|
2321
2876
|
out.push("} as const;", "");
|
|
2322
2877
|
out.push("/** Every resource in this contract, `schema.table`. */");
|
|
2323
2878
|
out.push("export type GenesisResource = keyof typeof contracts;", "");
|
|
2324
|
-
for (const table of
|
|
2879
|
+
for (const table of sorted2) {
|
|
2325
2880
|
out.push(`/** A row of \`${table.name}\`, as the studio handler returns it. */`);
|
|
2326
2881
|
out.push(`export type ${typeName(table)} = {`);
|
|
2327
2882
|
for (const column of table.columns) out.push(` ${propKey(column.name)}: ${tsType(column)};`);
|
|
@@ -2331,7 +2886,7 @@ function emitContracts(tables, options) {
|
|
|
2331
2886
|
}
|
|
2332
2887
|
out.push("/** Row types by resource. */");
|
|
2333
2888
|
out.push("export interface GenesisRows {");
|
|
2334
|
-
for (const table of
|
|
2889
|
+
for (const table of sorted2) out.push(` ${quote(table.name)}: ${typeName(table)};`);
|
|
2335
2890
|
out.push("}", "");
|
|
2336
2891
|
return out.join("\n");
|
|
2337
2892
|
}
|
|
@@ -2412,7 +2967,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
2412
2967
|
const env = settings2.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
2413
2968
|
let current = null;
|
|
2414
2969
|
try {
|
|
2415
|
-
current = lf(readFileSync(
|
|
2970
|
+
current = lf(readFileSync(path28.join(ctx.root, out), "utf8"));
|
|
2416
2971
|
} catch {
|
|
2417
2972
|
current = null;
|
|
2418
2973
|
}
|
|
@@ -2436,7 +2991,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
2436
2991
|
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}` });
|
|
2437
2992
|
return;
|
|
2438
2993
|
}
|
|
2439
|
-
const target =
|
|
2994
|
+
const target = path28.relative(process.cwd(), path28.join(ctx.root, out)) || out;
|
|
2440
2995
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
2441
2996
|
if (current !== expected) {
|
|
2442
2997
|
ctx.report({
|
|
@@ -2452,317 +3007,75 @@ var init_contracts = __esm({
|
|
|
2452
3007
|
DEFAULT_CONTRACT_OUT = "resources.genesis.ts";
|
|
2453
3008
|
DEFAULT_DATABASE_ENV = "DATABASE_URL";
|
|
2454
3009
|
shellArg = (s) => /^[\w./,@:+=-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`;
|
|
2455
|
-
postgresSource = (schemas) => `Postgres (${schemas.join(", ")})`;
|
|
2456
|
-
lf = (text) => text.replace(/\r\n/g, "\n");
|
|
2457
|
-
}
|
|
2458
|
-
});
|
|
2459
|
-
function buildCommands(root, config) {
|
|
2460
|
-
if (config.build) return config.build;
|
|
2461
|
-
const pkgFile = path26.join(root, "package.json");
|
|
2462
|
-
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
2463
|
-
const pm = packageManager(root);
|
|
2464
|
-
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
2465
|
-
}
|
|
2466
|
-
function packageManager(root) {
|
|
2467
|
-
let dir = path26.resolve(root);
|
|
2468
|
-
for (; ; ) {
|
|
2469
|
-
if (existsSync(path26.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
2470
|
-
if (existsSync(path26.join(dir, "bun.lock")) || existsSync(path26.join(dir, "bun.lockb"))) return "bun";
|
|
2471
|
-
if (existsSync(path26.join(dir, "yarn.lock"))) return "yarn";
|
|
2472
|
-
if (existsSync(path26.join(dir, "package-lock.json"))) return "npm";
|
|
2473
|
-
const parent = path26.dirname(dir);
|
|
2474
|
-
if (parent === dir) return "npm";
|
|
2475
|
-
dir = parent;
|
|
2476
|
-
}
|
|
2477
|
-
}
|
|
2478
|
-
function runBuild(root, commands, quiet) {
|
|
2479
|
-
if (process.env[BUILD_GUARD_ENV]) return null;
|
|
2480
|
-
if (commands.length === 0) {
|
|
2481
|
-
return { rule: "build", level: "warn", file: "package.json", message: "--build found nothing to run: add typecheck/build scripts or doctor.build" };
|
|
2482
|
-
}
|
|
2483
|
-
for (const command of commands) {
|
|
2484
|
-
const r = spawnSync(command, {
|
|
2485
|
-
cwd: root,
|
|
2486
|
-
shell: true,
|
|
2487
|
-
stdio: quiet ? "pipe" : "inherit",
|
|
2488
|
-
env: { ...process.env, [BUILD_GUARD_ENV]: "1" }
|
|
2489
|
-
});
|
|
2490
|
-
if (r.status !== 0) {
|
|
2491
|
-
const tail = quiet ? `
|
|
2492
|
-
${String(r.stderr ?? "").trim().split("\n").slice(-20).join("\n")}` : "";
|
|
2493
|
-
return { rule: "build", file: command, message: `\`${command}\` failed (exit ${r.status ?? r.signal})${tail}` };
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
return null;
|
|
2497
|
-
}
|
|
2498
|
-
var BUILD_GUARD_ENV;
|
|
2499
|
-
var init_build = __esm({
|
|
2500
|
-
"src/doctor/build.ts"() {
|
|
2501
|
-
BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
2502
|
-
}
|
|
2503
|
-
});
|
|
2504
|
-
|
|
2505
|
-
// src/doctor/glob.ts
|
|
2506
|
-
function globToRegExp(glob) {
|
|
2507
|
-
let g = glob.trim().replace(/^\.\//, "");
|
|
2508
|
-
if (g.endsWith("/")) g += "**";
|
|
2509
|
-
let out = "";
|
|
2510
|
-
for (let i = 0; i < g.length; i++) {
|
|
2511
|
-
const ch = g[i];
|
|
2512
|
-
if (ch === "*") {
|
|
2513
|
-
if (g[i + 1] === "*") {
|
|
2514
|
-
const slash = g[i + 2] === "/";
|
|
2515
|
-
out += slash ? "(?:.*/)?" : ".*";
|
|
2516
|
-
i += slash ? 2 : 1;
|
|
2517
|
-
} else {
|
|
2518
|
-
out += "[^/]*";
|
|
2519
|
-
}
|
|
2520
|
-
} else if (ch === "?") {
|
|
2521
|
-
out += "[^/]";
|
|
2522
|
-
} else {
|
|
2523
|
-
out += ch.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
return new RegExp(`^${out}$`);
|
|
2527
|
-
}
|
|
2528
|
-
function globMatcher(globs) {
|
|
2529
|
-
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
2530
|
-
return (path41) => res.some((re) => re.test(path41));
|
|
2531
|
-
}
|
|
2532
|
-
var init_glob = __esm({
|
|
2533
|
-
"src/doctor/glob.ts"() {
|
|
2534
|
-
}
|
|
2535
|
-
});
|
|
2536
|
-
|
|
2537
|
-
// ../../scripts/lib/color-literals.mjs
|
|
2538
|
-
function stripBlockComments(content, hasLineComments = true) {
|
|
2539
|
-
let result = "";
|
|
2540
|
-
let i = 0;
|
|
2541
|
-
const len = content.length;
|
|
2542
|
-
while (i < len) {
|
|
2543
|
-
const ch = content[i];
|
|
2544
|
-
const next = i + 1 < len ? content[i + 1] : "";
|
|
2545
|
-
const prevIsColon = i > 0 && content[i - 1] === ":";
|
|
2546
|
-
const prevIsBackslash = i > 0 && content[i - 1] === "\\";
|
|
2547
|
-
if (ch === '"') {
|
|
2548
|
-
result += ch;
|
|
2549
|
-
i++;
|
|
2550
|
-
while (i < len) {
|
|
2551
|
-
const c = content[i];
|
|
2552
|
-
result += c;
|
|
2553
|
-
if (c === "\\" && i + 1 < len) {
|
|
2554
|
-
result += content[i + 1];
|
|
2555
|
-
i += 2;
|
|
2556
|
-
} else if (c === '"') {
|
|
2557
|
-
i++;
|
|
2558
|
-
break;
|
|
2559
|
-
} else {
|
|
2560
|
-
i++;
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
continue;
|
|
2564
|
-
}
|
|
2565
|
-
if (ch === "'") {
|
|
2566
|
-
result += ch;
|
|
2567
|
-
i++;
|
|
2568
|
-
while (i < len) {
|
|
2569
|
-
const c = content[i];
|
|
2570
|
-
result += c;
|
|
2571
|
-
if (c === "\\" && i + 1 < len) {
|
|
2572
|
-
result += content[i + 1];
|
|
2573
|
-
i += 2;
|
|
2574
|
-
} else if (c === "'") {
|
|
2575
|
-
i++;
|
|
2576
|
-
break;
|
|
2577
|
-
} else {
|
|
2578
|
-
i++;
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
continue;
|
|
2582
|
-
}
|
|
2583
|
-
if (ch === "`") {
|
|
2584
|
-
result += ch;
|
|
2585
|
-
i++;
|
|
2586
|
-
while (i < len) {
|
|
2587
|
-
const c = content[i];
|
|
2588
|
-
result += c;
|
|
2589
|
-
if (c === "\\" && i + 1 < len) {
|
|
2590
|
-
result += content[i + 1];
|
|
2591
|
-
i += 2;
|
|
2592
|
-
} else if (c === "`") {
|
|
2593
|
-
i++;
|
|
2594
|
-
break;
|
|
2595
|
-
} else {
|
|
2596
|
-
i++;
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
continue;
|
|
2600
|
-
}
|
|
2601
|
-
if ((ch === "u" || ch === "U") && content.slice(i, i + 4).toLowerCase() === "url(" && !/[\w$]/.test(content[i - 1] ?? "")) {
|
|
2602
|
-
result += content.slice(i, i + 4);
|
|
2603
|
-
i += 4;
|
|
2604
|
-
while (i < len && content[i] !== ")") {
|
|
2605
|
-
const c = content[i];
|
|
2606
|
-
if (c === '"' || c === "'") {
|
|
2607
|
-
result += c;
|
|
2608
|
-
i++;
|
|
2609
|
-
while (i < len) {
|
|
2610
|
-
const q = content[i];
|
|
2611
|
-
result += q;
|
|
2612
|
-
if (q === "\\" && i + 1 < len) {
|
|
2613
|
-
result += content[i + 1];
|
|
2614
|
-
i += 2;
|
|
2615
|
-
} else if (q === c) {
|
|
2616
|
-
i++;
|
|
2617
|
-
break;
|
|
2618
|
-
} else {
|
|
2619
|
-
i++;
|
|
2620
|
-
}
|
|
2621
|
-
}
|
|
2622
|
-
} else {
|
|
2623
|
-
result += c;
|
|
2624
|
-
i++;
|
|
2625
|
-
}
|
|
2626
|
-
}
|
|
2627
|
-
if (i < len && content[i] === ")") {
|
|
2628
|
-
result += ")";
|
|
2629
|
-
i++;
|
|
2630
|
-
}
|
|
2631
|
-
continue;
|
|
2632
|
-
}
|
|
2633
|
-
if (hasLineComments && ch === "/" && next === "/" && !prevIsColon && !prevIsBackslash) {
|
|
2634
|
-
let j = i + 2;
|
|
2635
|
-
while (j < len && content[j] !== "\n") {
|
|
2636
|
-
j++;
|
|
2637
|
-
}
|
|
2638
|
-
const commentLen = j - i;
|
|
2639
|
-
const commentText = content.slice(i, i + commentLen);
|
|
2640
|
-
result += commentText.replace(/[^\n]/g, " ");
|
|
2641
|
-
i += commentLen;
|
|
2642
|
-
continue;
|
|
2643
|
-
}
|
|
2644
|
-
if (ch === "/" && next === "*") {
|
|
2645
|
-
let commentLen = 2;
|
|
2646
|
-
let j = i + 2;
|
|
2647
|
-
while (j < len) {
|
|
2648
|
-
if (content[j] === "*" && j + 1 < len && content[j + 1] === "/") {
|
|
2649
|
-
commentLen = j + 2 - i;
|
|
2650
|
-
break;
|
|
2651
|
-
}
|
|
2652
|
-
j++;
|
|
2653
|
-
}
|
|
2654
|
-
const commentText = content.slice(i, i + commentLen);
|
|
2655
|
-
result += commentText.replace(/[^\n]/g, " ");
|
|
2656
|
-
i += commentLen;
|
|
2657
|
-
continue;
|
|
2658
|
-
}
|
|
2659
|
-
result += ch;
|
|
2660
|
-
i++;
|
|
2661
|
-
}
|
|
2662
|
-
return result;
|
|
2663
|
-
}
|
|
2664
|
-
function stripHtmlEntities(line) {
|
|
2665
|
-
return line.replace(HTML_ENTITY_RE, "");
|
|
2666
|
-
}
|
|
2667
|
-
function findHexLiterals(line) {
|
|
2668
|
-
const cleaned = stripHtmlEntities(line);
|
|
2669
|
-
const matches = [];
|
|
2670
|
-
let m;
|
|
2671
|
-
HEX_RE.lastIndex = 0;
|
|
2672
|
-
while ((m = HEX_RE.exec(cleaned)) !== null) {
|
|
2673
|
-
const digits = m[2];
|
|
2674
|
-
if (digits.length <= 4 && !HEX_LETTER_RE.test(digits)) continue;
|
|
2675
|
-
const literal2 = `#${digits}`;
|
|
2676
|
-
const idx = m.index + m[1].length;
|
|
2677
|
-
matches.push({ literal: literal2, column: idx + 1 });
|
|
2678
|
-
}
|
|
2679
|
-
return matches;
|
|
2680
|
-
}
|
|
2681
|
-
function findColorFunctions(line) {
|
|
2682
|
-
const cleaned = stripHtmlEntities(line);
|
|
2683
|
-
const matches = [];
|
|
2684
|
-
let m;
|
|
2685
|
-
COLOR_FN_RE.lastIndex = 0;
|
|
2686
|
-
while ((m = COLOR_FN_RE.exec(cleaned)) !== null) {
|
|
2687
|
-
matches.push({ literal: m[0], column: m.index + 1 });
|
|
2688
|
-
}
|
|
2689
|
-
return matches;
|
|
2690
|
-
}
|
|
2691
|
-
var LINE_COMMENT_EXTS, HTML_ENTITY_RE, HEX_RE, HEX_LETTER_RE, COLOR_FN_RE;
|
|
2692
|
-
var init_color_literals = __esm({
|
|
2693
|
-
"../../scripts/lib/color-literals.mjs"() {
|
|
2694
|
-
LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
|
|
2695
|
-
HTML_ENTITY_RE = /&#\d+;/g;
|
|
2696
|
-
HEX_RE = /(^|[^\w&])#([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g;
|
|
2697
|
-
HEX_LETTER_RE = /[a-fA-F]/;
|
|
2698
|
-
COLOR_FN_RE = /\b(rgba?|hsla?)\(\s*[\d.][^)\n]*\)?/gi;
|
|
3010
|
+
postgresSource = (schemas) => `Postgres (${schemas.join(", ")})`;
|
|
3011
|
+
lf = (text) => text.replace(/\r\n/g, "\n");
|
|
2699
3012
|
}
|
|
2700
3013
|
});
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
visit(path26.join(dir, entry.name));
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
};
|
|
2725
|
-
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2726
|
-
const abs = path26.resolve(root, src);
|
|
2727
|
-
if (!existsSync(abs)) continue;
|
|
2728
|
-
if (statSync(abs).isDirectory()) walk2(abs);
|
|
2729
|
-
else visit(abs);
|
|
3014
|
+
|
|
3015
|
+
// src/introspect/settings.ts
|
|
3016
|
+
var settings_exports = {};
|
|
3017
|
+
__export(settings_exports, {
|
|
3018
|
+
introspectSettings: () => introspectSettings
|
|
3019
|
+
});
|
|
3020
|
+
function introspectSettings(flags, root, contracts, readCurrent = () => null) {
|
|
3021
|
+
const out = flags.out ?? contracts?.out ?? DEFAULT_CONTRACT_OUT;
|
|
3022
|
+
const target = path28.resolve(root, out);
|
|
3023
|
+
return { target, label: out, schemas: schemasFor(flags, target, contracts, readCurrent), databaseEnv: flags.databaseEnv ?? contracts?.databaseEnv ?? DEFAULT_DATABASE_ENV };
|
|
3024
|
+
}
|
|
3025
|
+
function schemasFor(flags, target, contracts, readCurrent) {
|
|
3026
|
+
if (flags.schema !== void 0) return flags.schema.split(",").map((s) => s.trim()).filter(Boolean);
|
|
3027
|
+
if (flags.openapi !== void 0) return contracts?.schemas?.length === 1 ? [...contracts.schemas] : ["public"];
|
|
3028
|
+
if (contracts?.schemas?.length) return [...contracts.schemas];
|
|
3029
|
+
return sourceSchemas(contractSource(readCurrent(target) ?? "")) ?? ["public"];
|
|
3030
|
+
}
|
|
3031
|
+
var init_settings = __esm({
|
|
3032
|
+
"src/introspect/settings.ts"() {
|
|
3033
|
+
init_contracts();
|
|
2730
3034
|
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
3035
|
+
});
|
|
3036
|
+
function buildCommands(root, config) {
|
|
3037
|
+
if (config.build) return config.build;
|
|
3038
|
+
const pkgFile = path28.join(root, "package.json");
|
|
3039
|
+
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
3040
|
+
const pm = packageManager(root);
|
|
3041
|
+
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
3042
|
+
}
|
|
3043
|
+
function packageManager(root) {
|
|
3044
|
+
let dir = path28.resolve(root);
|
|
3045
|
+
for (; ; ) {
|
|
3046
|
+
if (existsSync(path28.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
3047
|
+
if (existsSync(path28.join(dir, "bun.lock")) || existsSync(path28.join(dir, "bun.lockb"))) return "bun";
|
|
3048
|
+
if (existsSync(path28.join(dir, "yarn.lock"))) return "yarn";
|
|
3049
|
+
if (existsSync(path28.join(dir, "package-lock.json"))) return "npm";
|
|
3050
|
+
const parent = path28.dirname(dir);
|
|
3051
|
+
if (parent === dir) return "npm";
|
|
3052
|
+
dir = parent;
|
|
2736
3053
|
}
|
|
2737
|
-
for (const pkg of local) walk2(pkg.dir);
|
|
2738
|
-
return files;
|
|
2739
3054
|
}
|
|
2740
|
-
function
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
3055
|
+
function runBuild(root, commands, quiet) {
|
|
3056
|
+
if (process.env[BUILD_GUARD_ENV]) return null;
|
|
3057
|
+
if (commands.length === 0) {
|
|
3058
|
+
return { rule: "build", level: "warn", file: "package.json", message: "--build found nothing to run: add typecheck/build scripts or doctor.build" };
|
|
3059
|
+
}
|
|
3060
|
+
for (const command of commands) {
|
|
3061
|
+
const r = spawnSync(command, {
|
|
3062
|
+
cwd: root,
|
|
3063
|
+
shell: true,
|
|
3064
|
+
stdio: quiet ? "pipe" : "inherit",
|
|
3065
|
+
env: { ...process.env, [BUILD_GUARD_ENV]: "1" }
|
|
3066
|
+
});
|
|
3067
|
+
if (r.status !== 0) {
|
|
3068
|
+
const tail = quiet ? `
|
|
3069
|
+
${String(r.stderr ?? "").trim().split("\n").slice(-20).join("\n")}` : "";
|
|
3070
|
+
return { rule: "build", file: command, message: `\`${command}\` failed (exit ${r.status ?? r.signal})${tail}` };
|
|
3071
|
+
}
|
|
3072
|
+
}
|
|
3073
|
+
return null;
|
|
2744
3074
|
}
|
|
2745
|
-
var
|
|
2746
|
-
var
|
|
2747
|
-
"src/doctor/
|
|
2748
|
-
|
|
2749
|
-
init_color_literals();
|
|
2750
|
-
init_glob();
|
|
2751
|
-
DEFAULT_SRC = ["src"];
|
|
2752
|
-
DEFAULT_NATIVE_SRC = ["app", "src", "components"];
|
|
2753
|
-
DEFAULT_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".css"];
|
|
2754
|
-
DEFAULT_IGNORE = [
|
|
2755
|
-
"**/*.d.ts",
|
|
2756
|
-
"**/*.gen.*",
|
|
2757
|
-
"**/*.test.*",
|
|
2758
|
-
"**/*.spec.*",
|
|
2759
|
-
"**/__tests__/**",
|
|
2760
|
-
"**/__fixtures__/**",
|
|
2761
|
-
"**/__mocks__/**"
|
|
2762
|
-
];
|
|
2763
|
-
SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2764
|
-
MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2765
|
-
toPosix = (p) => p.split(path26.sep).join("/");
|
|
3075
|
+
var BUILD_GUARD_ENV;
|
|
3076
|
+
var init_build = __esm({
|
|
3077
|
+
"src/doctor/build.ts"() {
|
|
3078
|
+
BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
2766
3079
|
}
|
|
2767
3080
|
});
|
|
2768
3081
|
function parseRulesMarkdown(markdown) {
|
|
@@ -2832,7 +3145,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
2832
3145
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2833
3146
|
let all = compiled;
|
|
2834
3147
|
if (rulesDoc) {
|
|
2835
|
-
const file =
|
|
3148
|
+
const file = path28.resolve(root, rulesDoc);
|
|
2836
3149
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2837
3150
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2838
3151
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -2900,14 +3213,14 @@ async function loadPlugins(specs, configDir) {
|
|
|
2900
3213
|
}
|
|
2901
3214
|
function resolvePlugin(id, configDir) {
|
|
2902
3215
|
try {
|
|
2903
|
-
if (id.startsWith(".") ||
|
|
3216
|
+
if (id.startsWith(".") || path28.isAbsolute(id)) return resolveFrom(path28.resolve(configDir, id), configDir);
|
|
2904
3217
|
return resolveFrom(id, configDir);
|
|
2905
3218
|
} catch {
|
|
2906
3219
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2907
3220
|
}
|
|
2908
3221
|
}
|
|
2909
3222
|
function resolveFrom(id, from) {
|
|
2910
|
-
return createRequire(
|
|
3223
|
+
return createRequire(path28.join(from, "noop.js")).resolve(id);
|
|
2911
3224
|
}
|
|
2912
3225
|
var init_plugins = __esm({
|
|
2913
3226
|
"src/doctor/plugins.ts"() {
|
|
@@ -2925,7 +3238,7 @@ function importSpecifiers(file) {
|
|
|
2925
3238
|
}
|
|
2926
3239
|
function checkProjectLayout(ctx) {
|
|
2927
3240
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2928
|
-
if (existsSync(
|
|
3241
|
+
if (existsSync(path28.join(ctx.root, dir))) {
|
|
2929
3242
|
ctx.report({
|
|
2930
3243
|
rule: "local-primitives",
|
|
2931
3244
|
file: dir,
|
|
@@ -2935,7 +3248,7 @@ function checkProjectLayout(ctx) {
|
|
|
2935
3248
|
}
|
|
2936
3249
|
}
|
|
2937
3250
|
for (const file of STARTER_LEFTOVERS) {
|
|
2938
|
-
if (existsSync(
|
|
3251
|
+
if (existsSync(path28.join(ctx.root, file))) {
|
|
2939
3252
|
ctx.report({
|
|
2940
3253
|
rule: "starter-leftover",
|
|
2941
3254
|
level: "warn",
|
|
@@ -2965,8 +3278,9 @@ function checkImports(ctx) {
|
|
|
2965
3278
|
function checkRawTags(ctx) {
|
|
2966
3279
|
const tags = [...ctx.genesis.rawTags].map(([tag, component]) => [tag, component, new RegExp(`<${tag}(?=[\\s>/]|$)`)]);
|
|
2967
3280
|
if (tags.length === 0) return;
|
|
3281
|
+
const overlays = markedOverlays(ctx);
|
|
2968
3282
|
for (const file of ctx.files) {
|
|
2969
|
-
if (!JSX_EXTS.has(file.ext)) continue;
|
|
3283
|
+
if (!JSX_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
2970
3284
|
file.code.split("\n").forEach((text, i) => {
|
|
2971
3285
|
for (const [tag, component, re] of tags) {
|
|
2972
3286
|
if (re.test(text)) {
|
|
@@ -3022,7 +3336,7 @@ function checkTokens(ctx) {
|
|
|
3022
3336
|
}
|
|
3023
3337
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
3024
3338
|
if (/[*?]/.test(pattern)) continue;
|
|
3025
|
-
const abs =
|
|
3339
|
+
const abs = path28.join(ctx.root, pattern);
|
|
3026
3340
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
3027
3341
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
3028
3342
|
}
|
|
@@ -3039,9 +3353,10 @@ function checkTokens(ctx) {
|
|
|
3039
3353
|
}
|
|
3040
3354
|
}
|
|
3041
3355
|
function checkShadowedExports(ctx) {
|
|
3356
|
+
const overlays = markedOverlays(ctx);
|
|
3042
3357
|
const re = /\bexport\s+(?:default\s+)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)/g;
|
|
3043
3358
|
for (const file of ctx.files) {
|
|
3044
|
-
if (!SCRIPT_EXTS.has(file.ext)) continue;
|
|
3359
|
+
if (!SCRIPT_EXTS.has(file.ext) || insideOverlayOf(overlays, file, ctx.genesis.uiPackage)) continue;
|
|
3045
3360
|
file.code.split("\n").forEach((text, i) => {
|
|
3046
3361
|
for (const m of text.matchAll(re)) {
|
|
3047
3362
|
if (!ctx.genesis.values.has(m[1])) continue;
|
|
@@ -3070,6 +3385,7 @@ var init_rules = __esm({
|
|
|
3070
3385
|
init_color_literals();
|
|
3071
3386
|
init_glob();
|
|
3072
3387
|
init_genesis();
|
|
3388
|
+
init_overlays();
|
|
3073
3389
|
BUILTIN_RULES = [
|
|
3074
3390
|
"local-primitives",
|
|
3075
3391
|
"starter-leftover",
|
|
@@ -3095,6 +3411,9 @@ var init_rules = __esm({
|
|
|
3095
3411
|
"studio-server-auth-import",
|
|
3096
3412
|
"removed-scope-name",
|
|
3097
3413
|
"scope-practice-id",
|
|
3414
|
+
// export maturity (stability.ts)
|
|
3415
|
+
"deprecated-import",
|
|
3416
|
+
"beta-import",
|
|
3098
3417
|
// native pack
|
|
3099
3418
|
"native-raw-primitive",
|
|
3100
3419
|
"native-literal-color",
|
|
@@ -3120,6 +3439,11 @@ var init_rules = __esm({
|
|
|
3120
3439
|
"package-block-invalid",
|
|
3121
3440
|
"package-untagged-tests",
|
|
3122
3441
|
"package-doctor-declaration",
|
|
3442
|
+
// overlays (overlays.ts)
|
|
3443
|
+
"overlay-unmarked",
|
|
3444
|
+
"overlay-invalid",
|
|
3445
|
+
"overlay-age",
|
|
3446
|
+
"overlay-version",
|
|
3123
3447
|
// package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
|
|
3124
3448
|
"package-rules-invalid",
|
|
3125
3449
|
"package-rule-override",
|
|
@@ -3215,10 +3539,10 @@ var init_expo = __esm({
|
|
|
3215
3539
|
}
|
|
3216
3540
|
});
|
|
3217
3541
|
function resolveLocal(root, fromFile, spec) {
|
|
3218
|
-
const bases = spec.startsWith(".") ? [
|
|
3542
|
+
const bases = spec.startsWith(".") ? [path28.resolve(path28.dirname(fromFile), spec)] : [path28.join(root, spec.slice(2)), path28.join(root, "src", spec.slice(2))];
|
|
3219
3543
|
for (const base of bases) {
|
|
3220
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
3221
|
-
(p) => SCRIPT_EXTS2.has(
|
|
3544
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path28.join(base, `index${e}`))].find(
|
|
3545
|
+
(p) => SCRIPT_EXTS2.has(path28.extname(p)) && existsSync(p)
|
|
3222
3546
|
);
|
|
3223
3547
|
if (hit) return hit;
|
|
3224
3548
|
}
|
|
@@ -3337,6 +3661,7 @@ function checkNativePack(ctx) {
|
|
|
3337
3661
|
checkStoreReadiness(ctx);
|
|
3338
3662
|
}
|
|
3339
3663
|
function checkRawPrimitives(ctx, pkg) {
|
|
3664
|
+
const overlays = markedOverlays(ctx);
|
|
3340
3665
|
const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
|
|
3341
3666
|
const named = [
|
|
3342
3667
|
// import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
|
|
@@ -3350,7 +3675,7 @@ function checkRawPrimitives(ctx, pkg) {
|
|
|
3350
3675
|
];
|
|
3351
3676
|
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
3352
3677
|
for (const file of ctx.files) {
|
|
3353
|
-
if (!SCRIPT_EXTS3.has(file.ext)) continue;
|
|
3678
|
+
if (!SCRIPT_EXTS3.has(file.ext) || insideOverlayOf(overlays, file, NATIVE_UI_PACKAGE)) continue;
|
|
3354
3679
|
const code = file.code;
|
|
3355
3680
|
const report = (name, at) => {
|
|
3356
3681
|
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
@@ -3399,7 +3724,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3399
3724
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
3400
3725
|
const code = file.code;
|
|
3401
3726
|
const hidden = HIDES_HEADER.exec(code);
|
|
3402
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
3727
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path28.posix.dirname(file.path), file.path);
|
|
3403
3728
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
3404
3729
|
if (hidden && own) {
|
|
3405
3730
|
reported.add(file.path);
|
|
@@ -3427,7 +3752,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3427
3752
|
}
|
|
3428
3753
|
for (const file of ctx.files) {
|
|
3429
3754
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
3430
|
-
const layout = hidingLayouts.get(
|
|
3755
|
+
const layout = hidingLayouts.get(path28.posix.dirname(file.path));
|
|
3431
3756
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
3432
3757
|
if (!layout || !own) continue;
|
|
3433
3758
|
ctx.report({
|
|
@@ -3448,13 +3773,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
3448
3773
|
}
|
|
3449
3774
|
function routerRoot(ctx) {
|
|
3450
3775
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
3451
|
-
return existsSync(
|
|
3776
|
+
return existsSync(path28.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
3452
3777
|
}
|
|
3453
3778
|
function checkScreenLayouts(ctx, pkg) {
|
|
3454
3779
|
const layouts = nativeLayouts(pkg);
|
|
3455
3780
|
if (layouts.length === 0) return;
|
|
3456
3781
|
const rootDir = routerRoot(ctx);
|
|
3457
|
-
if (!existsSync(
|
|
3782
|
+
if (!existsSync(path28.join(ctx.root, rootDir))) {
|
|
3458
3783
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
3459
3784
|
return;
|
|
3460
3785
|
}
|
|
@@ -3491,7 +3816,7 @@ function checkScreenLayouts(ctx, pkg) {
|
|
|
3491
3816
|
function readExpoConfigs(root) {
|
|
3492
3817
|
const out = [];
|
|
3493
3818
|
for (const name of EXPO_CONFIGS) {
|
|
3494
|
-
const abs =
|
|
3819
|
+
const abs = path28.join(root, name);
|
|
3495
3820
|
if (!existsSync(abs)) continue;
|
|
3496
3821
|
const text = readFileSync(abs, "utf8");
|
|
3497
3822
|
let json = null;
|
|
@@ -3525,13 +3850,13 @@ function pluginOptions(json, module) {
|
|
|
3525
3850
|
return null;
|
|
3526
3851
|
}
|
|
3527
3852
|
function dependencies(root) {
|
|
3528
|
-
const file =
|
|
3853
|
+
const file = path28.join(root, "package.json");
|
|
3529
3854
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
3530
3855
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3531
3856
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
3532
3857
|
}
|
|
3533
3858
|
function runtimeDependencies(root) {
|
|
3534
|
-
const file =
|
|
3859
|
+
const file = path28.join(root, "package.json");
|
|
3535
3860
|
if (!existsSync(file)) return {};
|
|
3536
3861
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
3537
3862
|
}
|
|
@@ -3621,6 +3946,7 @@ var init_native = __esm({
|
|
|
3621
3946
|
init_genesis();
|
|
3622
3947
|
init_scan();
|
|
3623
3948
|
init_source();
|
|
3949
|
+
init_overlays();
|
|
3624
3950
|
SCRIPT_EXTS3 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
3625
3951
|
JSX_EXTS3 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
3626
3952
|
LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$|^NativeResourceView$/;
|
|
@@ -3943,14 +4269,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3943
4269
|
seen.add(file);
|
|
3944
4270
|
const json = readJsonc(file);
|
|
3945
4271
|
if (!json) return {};
|
|
3946
|
-
const dir =
|
|
4272
|
+
const dir = path28.dirname(file);
|
|
3947
4273
|
let merged = {};
|
|
3948
4274
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3949
4275
|
for (const ext of parents) {
|
|
3950
4276
|
if (typeof ext !== "string") continue;
|
|
3951
4277
|
let target = null;
|
|
3952
|
-
if (ext.startsWith(".") ||
|
|
3953
|
-
const abs =
|
|
4278
|
+
if (ext.startsWith(".") || path28.isAbsolute(ext)) {
|
|
4279
|
+
const abs = path28.resolve(dir, ext);
|
|
3954
4280
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3955
4281
|
} else {
|
|
3956
4282
|
const parts = ext.split("/");
|
|
@@ -3958,14 +4284,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3958
4284
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3959
4285
|
if (pkgDir) {
|
|
3960
4286
|
const sub = parts.slice(nameLength).join("/");
|
|
3961
|
-
const abs =
|
|
4287
|
+
const abs = path28.join(pkgDir, sub || "tsconfig.json");
|
|
3962
4288
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3963
4289
|
}
|
|
3964
4290
|
}
|
|
3965
4291
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3966
4292
|
}
|
|
3967
4293
|
const opts = json.compilerOptions ?? {};
|
|
3968
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
4294
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path28.resolve(dir, opts.baseUrl);
|
|
3969
4295
|
if (opts.paths && typeof opts.paths === "object") {
|
|
3970
4296
|
merged.paths = opts.paths;
|
|
3971
4297
|
merged.pathsDir = dir;
|
|
@@ -3976,7 +4302,7 @@ function aliases(root) {
|
|
|
3976
4302
|
const table = [];
|
|
3977
4303
|
let baseUrl = null;
|
|
3978
4304
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3979
|
-
const file =
|
|
4305
|
+
const file = path28.join(root, name);
|
|
3980
4306
|
if (!existsSync(file)) continue;
|
|
3981
4307
|
const config = readTsconfig(root, file);
|
|
3982
4308
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -3984,22 +4310,22 @@ function aliases(root) {
|
|
|
3984
4310
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3985
4311
|
if (!Array.isArray(targets)) continue;
|
|
3986
4312
|
const exact = !pattern.endsWith("*");
|
|
3987
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
4313
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path28.join(base, String(t).replace(/\*$/, ""))) });
|
|
3988
4314
|
}
|
|
3989
4315
|
}
|
|
3990
|
-
const pkg = readJsonc(
|
|
4316
|
+
const pkg = readJsonc(path28.join(root, "package.json"));
|
|
3991
4317
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3992
4318
|
if (typeof target !== "string") continue;
|
|
3993
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
4319
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path28.join(root, target.replace(/\*.*$/, ""))] });
|
|
3994
4320
|
}
|
|
3995
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
4321
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path28.join(root, "src") + path28.sep, root + path28.sep] });
|
|
3996
4322
|
return { table, baseUrl };
|
|
3997
4323
|
}
|
|
3998
4324
|
function resolveFile(base) {
|
|
3999
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
4325
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path28.join(base, `index${e}`))];
|
|
4000
4326
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
4001
4327
|
for (const p of tries) {
|
|
4002
|
-
if (SCRIPT_EXTS2.has(
|
|
4328
|
+
if (SCRIPT_EXTS2.has(path28.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
4003
4329
|
}
|
|
4004
4330
|
return null;
|
|
4005
4331
|
}
|
|
@@ -4012,7 +4338,7 @@ function createTrail(ctx) {
|
|
|
4012
4338
|
const { table, baseUrl } = aliases(ctx.root);
|
|
4013
4339
|
let declared = null;
|
|
4014
4340
|
try {
|
|
4015
|
-
const pkg = JSON.parse(readFileSync(
|
|
4341
|
+
const pkg = JSON.parse(readFileSync(path28.join(ctx.root, "package.json"), "utf8"));
|
|
4016
4342
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
4017
4343
|
} catch {
|
|
4018
4344
|
declared = null;
|
|
@@ -4043,17 +4369,17 @@ function createTrail(ctx) {
|
|
|
4043
4369
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
4044
4370
|
let resolved = null;
|
|
4045
4371
|
if (spec.startsWith(".")) {
|
|
4046
|
-
resolved = resolveFile(
|
|
4372
|
+
resolved = resolveFile(path28.resolve(path28.dirname(file.absolutePath), spec));
|
|
4047
4373
|
if (!resolved) lost = true;
|
|
4048
4374
|
} else {
|
|
4049
4375
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
4050
4376
|
if (alias) {
|
|
4051
4377
|
for (const t of alias.targets) {
|
|
4052
|
-
resolved = resolveFile(alias.exact ? t :
|
|
4378
|
+
resolved = resolveFile(alias.exact ? t : path28.join(t, spec.slice(alias.prefix.length)));
|
|
4053
4379
|
if (resolved) break;
|
|
4054
4380
|
}
|
|
4055
4381
|
}
|
|
4056
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
4382
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path28.join(baseUrl, spec));
|
|
4057
4383
|
if (!resolved) {
|
|
4058
4384
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
4059
4385
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -4139,7 +4465,7 @@ var init_trail = __esm({
|
|
|
4139
4465
|
});
|
|
4140
4466
|
function routesDir(ctx) {
|
|
4141
4467
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
4142
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
4468
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path28.join(ctx.root, d))) ?? null;
|
|
4143
4469
|
}
|
|
4144
4470
|
function flavorOf(dir, rels) {
|
|
4145
4471
|
const stems = rels.map((r) => r.split("/").pop());
|
|
@@ -4259,7 +4585,7 @@ function toRegExp2(source, flags = "") {
|
|
|
4259
4585
|
if (source.startsWith("(?i)")) return new RegExp(source.slice(4), flags + "i");
|
|
4260
4586
|
return new RegExp(source, flags);
|
|
4261
4587
|
}
|
|
4262
|
-
function validateDeclaration(raw, packageName3,
|
|
4588
|
+
function validateDeclaration(raw, packageName3, packageDir3, ignored) {
|
|
4263
4589
|
const fail = (msg) => {
|
|
4264
4590
|
throw new PackageDeclarationError(`${packageName3}: genesis.doctor ${msg}`);
|
|
4265
4591
|
};
|
|
@@ -4279,9 +4605,9 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4279
4605
|
}
|
|
4280
4606
|
});
|
|
4281
4607
|
if (typeof raw === "string") {
|
|
4282
|
-
if (!
|
|
4283
|
-
const file =
|
|
4284
|
-
if (!inside(
|
|
4608
|
+
if (!packageDir3) fail(`points at ${raw}, but the package folder is unknown`);
|
|
4609
|
+
const file = path28.resolve(packageDir3, raw);
|
|
4610
|
+
if (!inside(packageDir3, file)) fail(`points outside the package (${raw})`);
|
|
4285
4611
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
4286
4612
|
let parsed;
|
|
4287
4613
|
try {
|
|
@@ -4289,7 +4615,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4289
4615
|
} catch (err) {
|
|
4290
4616
|
return fail(`file ${raw} is not valid JSON: ${err.message}`);
|
|
4291
4617
|
}
|
|
4292
|
-
return validateDeclaration(parsed, packageName3,
|
|
4618
|
+
return validateDeclaration(parsed, packageName3, packageDir3, ignored);
|
|
4293
4619
|
}
|
|
4294
4620
|
if (raw === false) fail(`is false; say why with { "enforce": false, "reason": "\u2026" }`);
|
|
4295
4621
|
if (!isObject3(raw)) fail(`must be an object (or a path to a JSON file in the package)`);
|
|
@@ -4300,8 +4626,10 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4300
4626
|
if (c.reason !== void 0 && (typeof c.reason !== "string" || !c.reason.trim())) fail(`reason must be a sentence`);
|
|
4301
4627
|
const prefer = c.prefer === void 0 ? [] : c.prefer;
|
|
4302
4628
|
if (!Array.isArray(prefer)) fail(`prefer must be a list`);
|
|
4303
|
-
|
|
4304
|
-
|
|
4629
|
+
if (c.catalog !== void 0 && c.primitives !== void 0) fail(`declares both catalog and primitives; keep catalog (primitives is its old name)`);
|
|
4630
|
+
const listKey = c.catalog !== void 0 ? "catalog" : "primitives";
|
|
4631
|
+
const primitives = c[listKey] === void 0 ? [] : c[listKey];
|
|
4632
|
+
if (!Array.isArray(primitives)) fail(`${listKey} must be a list`);
|
|
4305
4633
|
if (c.plugin !== void 0 && (typeof c.plugin !== "string" || !c.plugin.trim())) fail(`plugin must be a module path inside the package`);
|
|
4306
4634
|
if (!enforce) {
|
|
4307
4635
|
if (typeof c.reason !== "string") fail(`turns enforcement off without a reason; add "reason"`);
|
|
@@ -4316,7 +4644,7 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4316
4644
|
ids.add(r.id);
|
|
4317
4645
|
}
|
|
4318
4646
|
const entries = each(primitives, (p, i) => {
|
|
4319
|
-
const where2 =
|
|
4647
|
+
const where2 = `${listKey}[${i}]`;
|
|
4320
4648
|
if (!isObject3(p)) return fail(`${where2} must be an object`);
|
|
4321
4649
|
for (const key2 of Object.keys(p)) if (!PRIMITIVE_KEYS.has(key2)) unknownKey(where2, key2);
|
|
4322
4650
|
for (const key2 of ["need", "use"]) if (typeof p[key2] !== "string" || !p[key2].trim()) fail(`${where2} needs "${key2}"`);
|
|
@@ -4325,10 +4653,10 @@ function validateDeclaration(raw, packageName3, packageDir2, ignored) {
|
|
|
4325
4653
|
});
|
|
4326
4654
|
let plugin;
|
|
4327
4655
|
if (typeof c.plugin === "string") {
|
|
4328
|
-
if (!
|
|
4656
|
+
if (!packageDir3) plugin = c.plugin;
|
|
4329
4657
|
else {
|
|
4330
|
-
plugin =
|
|
4331
|
-
if (!inside(
|
|
4658
|
+
plugin = path28.resolve(packageDir3, c.plugin);
|
|
4659
|
+
if (!inside(packageDir3, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
4332
4660
|
}
|
|
4333
4661
|
}
|
|
4334
4662
|
return {
|
|
@@ -4376,7 +4704,7 @@ function checkPattern(v, where2, fail) {
|
|
|
4376
4704
|
}
|
|
4377
4705
|
}
|
|
4378
4706
|
function readDeclaringPackage(dir, local) {
|
|
4379
|
-
const file =
|
|
4707
|
+
const file = path28.join(dir, "package.json");
|
|
4380
4708
|
let stamp;
|
|
4381
4709
|
let real2;
|
|
4382
4710
|
try {
|
|
@@ -4399,17 +4727,21 @@ ${local}`;
|
|
|
4399
4727
|
const pkg = {
|
|
4400
4728
|
name: json.name,
|
|
4401
4729
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
4402
|
-
dir:
|
|
4730
|
+
dir: path28.resolve(dir),
|
|
4403
4731
|
namespace: ruleNamespace(json.name),
|
|
4404
4732
|
local,
|
|
4405
4733
|
private: json.private === true,
|
|
4406
4734
|
declaration: null
|
|
4407
4735
|
};
|
|
4736
|
+
if (local) {
|
|
4737
|
+
const state = overlayState(json.name, json);
|
|
4738
|
+
if (state.kind === "marked") pkg.overlay = state.marker;
|
|
4739
|
+
}
|
|
4408
4740
|
const raw = json.genesis?.doctor;
|
|
4409
4741
|
if (raw !== void 0) {
|
|
4410
4742
|
const ignored = [];
|
|
4411
4743
|
try {
|
|
4412
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
4744
|
+
pkg.declaration = validateDeclaration(raw, json.name, path28.resolve(dir), ignored);
|
|
4413
4745
|
if (ignored.length) pkg.ignored = ignored;
|
|
4414
4746
|
} catch (err) {
|
|
4415
4747
|
pkg.error = err.message;
|
|
@@ -4428,14 +4760,14 @@ function discoverPackages(root) {
|
|
|
4428
4760
|
for (const dir of installed) {
|
|
4429
4761
|
let scope;
|
|
4430
4762
|
try {
|
|
4431
|
-
scope =
|
|
4763
|
+
scope = path28.dirname(realpathSync(dir));
|
|
4432
4764
|
} catch {
|
|
4433
4765
|
continue;
|
|
4434
4766
|
}
|
|
4435
|
-
if (
|
|
4767
|
+
if (path28.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
4436
4768
|
for (const entry of readdirSync(scope)) {
|
|
4437
4769
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
4438
|
-
const pkg = readDeclaringPackage(
|
|
4770
|
+
const pkg = readDeclaringPackage(path28.join(scope, entry), false);
|
|
4439
4771
|
if (pkg) byName.set(pkg.name, pkg);
|
|
4440
4772
|
}
|
|
4441
4773
|
}
|
|
@@ -4599,7 +4931,7 @@ function unknownPackageRuleSettings(config, packages, reported) {
|
|
|
4599
4931
|
level: "warn",
|
|
4600
4932
|
file: "genesis config",
|
|
4601
4933
|
subject: id,
|
|
4602
|
-
message: `packageRules names ${id}, which no installed package declares; check the id (genesis
|
|
4934
|
+
message: `packageRules names ${id}, which no installed package declares; check the id (genesis catalog lists them) or remove it`
|
|
4603
4935
|
}));
|
|
4604
4936
|
}
|
|
4605
4937
|
function packageRuleIds(packages) {
|
|
@@ -4612,6 +4944,7 @@ var init_package_rules = __esm({
|
|
|
4612
4944
|
init_files();
|
|
4613
4945
|
init_local();
|
|
4614
4946
|
init_glob();
|
|
4947
|
+
init_overlays();
|
|
4615
4948
|
init_plugins();
|
|
4616
4949
|
init_routes();
|
|
4617
4950
|
init_scan();
|
|
@@ -4627,7 +4960,7 @@ var init_package_rules = __esm({
|
|
|
4627
4960
|
FORBID_KEYS = /* @__PURE__ */ new Set(["jsx", "imports", "pattern"]);
|
|
4628
4961
|
UNLESS_KEYS = /* @__PURE__ */ new Set(["renders", "pattern"]);
|
|
4629
4962
|
PRIMITIVE_KEYS = /* @__PURE__ */ new Set(["need", "use", "import", "docs"]);
|
|
4630
|
-
DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "primitives", "plugin", "$comment"]);
|
|
4963
|
+
DECLARATION_KEYS = /* @__PURE__ */ new Set(["enforce", "reason", "prefer", "catalog", "primitives", "plugin", "$comment"]);
|
|
4631
4964
|
SCRIPT_GLOBS = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "**/*.mts", "**/*.cts", "**/*.mjs", "**/*.cjs"];
|
|
4632
4965
|
isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4633
4966
|
isStringList2 = (v) => Array.isArray(v) && v.every((x) => typeof x === "string" && x.trim() !== "");
|
|
@@ -4644,10 +4977,10 @@ var init_package_rules = __esm({
|
|
|
4644
4977
|
});
|
|
4645
4978
|
function sourceFiles(dir, rel = "") {
|
|
4646
4979
|
const out = [];
|
|
4647
|
-
for (const entry of readdirSync(
|
|
4980
|
+
for (const entry of readdirSync(path28.join(dir, rel)).sort()) {
|
|
4648
4981
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
4649
4982
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
4650
|
-
const stat = lstatSync(
|
|
4983
|
+
const stat = lstatSync(path28.join(dir, child));
|
|
4651
4984
|
if (stat.isSymbolicLink()) continue;
|
|
4652
4985
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
4653
4986
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -4670,13 +5003,13 @@ function matchPattern(pattern, spec) {
|
|
|
4670
5003
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
4671
5004
|
}
|
|
4672
5005
|
function tsconfigPaths(dir) {
|
|
4673
|
-
const file =
|
|
5006
|
+
const file = path28.join(dir, "tsconfig.json");
|
|
4674
5007
|
if (!existsSync(file)) return [];
|
|
4675
5008
|
try {
|
|
4676
5009
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
4677
5010
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
4678
|
-
const base =
|
|
4679
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
5011
|
+
const base = path28.resolve(dir, options.baseUrl ?? ".");
|
|
5012
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path28.resolve(base, t)) }));
|
|
4680
5013
|
} catch {
|
|
4681
5014
|
return [];
|
|
4682
5015
|
}
|
|
@@ -4690,8 +5023,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4690
5023
|
const hit = matchPattern(pattern, spec);
|
|
4691
5024
|
if (hit === null) continue;
|
|
4692
5025
|
return targets.some((t) => {
|
|
4693
|
-
const rel =
|
|
4694
|
-
return !rel.startsWith("..") && !
|
|
5026
|
+
const rel = path28.relative(pkg.dir, t.replace("*", hit));
|
|
5027
|
+
return !rel.startsWith("..") && !path28.isAbsolute(rel);
|
|
4695
5028
|
});
|
|
4696
5029
|
}
|
|
4697
5030
|
return null;
|
|
@@ -4704,7 +5037,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4704
5037
|
...Object.keys(json.optionalDependencies ?? {})
|
|
4705
5038
|
]);
|
|
4706
5039
|
for (const file of sourceFiles(pkg.dir)) {
|
|
4707
|
-
const code = stripForImports(readFileSync(
|
|
5040
|
+
const code = stripForImports(readFileSync(path28.join(pkg.dir, file), "utf8"));
|
|
4708
5041
|
if (code === null) continue;
|
|
4709
5042
|
const at = `${pkg.rel}/${file}`;
|
|
4710
5043
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -4729,9 +5062,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4729
5062
|
continue;
|
|
4730
5063
|
}
|
|
4731
5064
|
if (spec.startsWith(".")) {
|
|
4732
|
-
const target =
|
|
4733
|
-
const rel =
|
|
4734
|
-
if (rel.startsWith("..") ||
|
|
5065
|
+
const target = path28.resolve(pkg.dir, path28.dirname(file), spec);
|
|
5066
|
+
const rel = path28.relative(pkg.dir, target);
|
|
5067
|
+
if (rel.startsWith("..") || path28.isAbsolute(rel)) {
|
|
4735
5068
|
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` });
|
|
4736
5069
|
}
|
|
4737
5070
|
continue;
|
|
@@ -4745,20 +5078,34 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4745
5078
|
});
|
|
4746
5079
|
}
|
|
4747
5080
|
}
|
|
4748
|
-
function
|
|
5081
|
+
function migrationHome(pkg, named, locals) {
|
|
5082
|
+
if (named === void 0 || named === pkg.name) return { dir: pkg.dir };
|
|
5083
|
+
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` };
|
|
5084
|
+
const dir = locals.find((l) => l.name === named)?.dir ?? findPackageDir(pkg.dir, named);
|
|
5085
|
+
return dir ? { dir } : { problem: `names the package ${named}, which isn't installed or a local package, so its test can't be checked` };
|
|
5086
|
+
}
|
|
5087
|
+
function checkMigrations(ctx, pkg, json, locals) {
|
|
4749
5088
|
const declaredFiles = /* @__PURE__ */ new Set();
|
|
4750
5089
|
for (const [id, raw] of Object.entries(rawBlocksOf(json))) {
|
|
4751
5090
|
const migrations = raw.migrations ?? [];
|
|
4752
5091
|
for (const m of migrations) {
|
|
4753
|
-
|
|
5092
|
+
const found = migrationHome(pkg, m.package, locals);
|
|
5093
|
+
if ("problem" in found) {
|
|
5094
|
+
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}` });
|
|
5095
|
+
continue;
|
|
5096
|
+
}
|
|
5097
|
+
const home = found.dir;
|
|
5098
|
+
const own = home === pkg.dir;
|
|
5099
|
+
if (own && typeof m.file === "string" && typeof m.test === "string") declaredFiles.add(m.file);
|
|
5100
|
+
const from = own ? "" : ` (in ${m.package})`;
|
|
4754
5101
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
4755
|
-
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` });
|
|
4756
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
4757
|
-
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` });
|
|
5102
|
+
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` });
|
|
5103
|
+
} else if (typeof m.test === "string" && !existsSync(path28.join(home, m.test))) {
|
|
5104
|
+
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` });
|
|
4758
5105
|
}
|
|
4759
5106
|
}
|
|
4760
5107
|
}
|
|
4761
|
-
const dir =
|
|
5108
|
+
const dir = path28.join(pkg.dir, "migrations");
|
|
4762
5109
|
if (!existsSync(dir)) return;
|
|
4763
5110
|
const seen = /* @__PURE__ */ new Map();
|
|
4764
5111
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -4767,7 +5114,7 @@ function checkMigrations(ctx, pkg, json) {
|
|
|
4767
5114
|
const other = seen.get(m[1]);
|
|
4768
5115
|
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` });
|
|
4769
5116
|
else seen.set(m[1], name);
|
|
4770
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
5117
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path28.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
4771
5118
|
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")})` });
|
|
4772
5119
|
}
|
|
4773
5120
|
}
|
|
@@ -4781,7 +5128,7 @@ function checkExports(ctx, pkg, json) {
|
|
|
4781
5128
|
walk2(json.exports);
|
|
4782
5129
|
for (const t of targets) {
|
|
4783
5130
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
4784
|
-
if (!existsSync(
|
|
5131
|
+
if (!existsSync(path28.join(pkg.dir, t))) {
|
|
4785
5132
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
4786
5133
|
}
|
|
4787
5134
|
}
|
|
@@ -4799,11 +5146,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
4799
5146
|
function checkTaggedTests(ctx, pkg) {
|
|
4800
5147
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
4801
5148
|
if (!tests.length) return;
|
|
4802
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
5149
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path28.join(pkg.dir, f), "utf8")));
|
|
4803
5150
|
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>` });
|
|
4804
5151
|
}
|
|
4805
5152
|
function checkRegistered(ctx, pkg) {
|
|
4806
|
-
const file =
|
|
5153
|
+
const file = path28.join(ctx.root, "features.json");
|
|
4807
5154
|
if (!existsSync(file)) return;
|
|
4808
5155
|
let doc;
|
|
4809
5156
|
try {
|
|
@@ -4813,7 +5160,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
4813
5160
|
}
|
|
4814
5161
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4815
5162
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
4816
|
-
if (top) forms.add(
|
|
5163
|
+
if (top) forms.add(path28.relative(top, realpathSync(pkg.dir)).split(path28.sep).join("/"));
|
|
4817
5164
|
const covered = (doc.features ?? []).some(
|
|
4818
5165
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
4819
5166
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -4843,8 +5190,8 @@ function mergeBaseOf(root, base) {
|
|
|
4843
5190
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
4844
5191
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4845
5192
|
if (!top) return;
|
|
4846
|
-
const appRelative = (fromTop) =>
|
|
4847
|
-
const inRepo =
|
|
5193
|
+
const appRelative = (fromTop) => path28.relative(realpathSync(ctx.root), path28.join(top, fromTop)).split(path28.sep).join("/");
|
|
5194
|
+
const inRepo = path28.relative(top, realpathSync(pkg.dir)).split(path28.sep).join("/");
|
|
4848
5195
|
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");
|
|
4849
5196
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
4850
5197
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -4867,11 +5214,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4867
5214
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
4868
5215
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
4869
5216
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
4870
|
-
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) =>
|
|
5217
|
+
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) => path28.join(top, f)) : [];
|
|
4871
5218
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
4872
5219
|
const named = naming.length > 0;
|
|
4873
5220
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
4874
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
5221
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path28.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
4875
5222
|
}
|
|
4876
5223
|
let jsonBefore = null;
|
|
4877
5224
|
try {
|
|
@@ -4881,7 +5228,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4881
5228
|
}
|
|
4882
5229
|
const raw = json;
|
|
4883
5230
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
4884
|
-
const appInRepo =
|
|
5231
|
+
const appInRepo = path28.relative(top, realpathSync(ctx.root)).split(path28.sep).join("/");
|
|
4885
5232
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
4886
5233
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
4887
5234
|
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` });
|
|
@@ -4932,18 +5279,19 @@ function checkPackagesPack(ctx) {
|
|
|
4932
5279
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
4933
5280
|
}
|
|
4934
5281
|
for (const pkg of packages) {
|
|
4935
|
-
const json = JSON.parse(readFileSync(
|
|
5282
|
+
const json = JSON.parse(readFileSync(path28.join(pkg.dir, "package.json"), "utf8"));
|
|
4936
5283
|
checkImports2(ctx, pkg, json);
|
|
4937
5284
|
checkExports(ctx, pkg, json);
|
|
4938
5285
|
checkBlocks(ctx, pkg, json);
|
|
4939
|
-
checkMigrations(ctx, pkg, json);
|
|
5286
|
+
checkMigrations(ctx, pkg, json, packages);
|
|
4940
5287
|
checkTaggedTests(ctx, pkg);
|
|
4941
5288
|
checkRegistered(ctx, pkg);
|
|
4942
5289
|
checkDoctorDeclaration(ctx, pkg, json);
|
|
4943
|
-
|
|
5290
|
+
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;
|
|
5291
|
+
if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
4944
5292
|
}
|
|
4945
5293
|
}
|
|
4946
|
-
var SOURCE, SKIP_DIRS2, BUILTINS, IMPORT, TYPE_ONLY, GENESIS_NAME;
|
|
5294
|
+
var SOURCE, SKIP_DIRS2, BUILTINS, IMPORT, TYPE_ONLY, NPM_NAME, GENESIS_NAME;
|
|
4947
5295
|
var init_packages = __esm({
|
|
4948
5296
|
"src/doctor/packages.ts"() {
|
|
4949
5297
|
init_local();
|
|
@@ -4951,11 +5299,14 @@ var init_packages = __esm({
|
|
|
4951
5299
|
init_semver();
|
|
4952
5300
|
init_trail();
|
|
4953
5301
|
init_package_rules();
|
|
5302
|
+
init_genesis();
|
|
5303
|
+
init_overlays();
|
|
4954
5304
|
SOURCE = /\.(?:[cm]?[jt]sx?)$/;
|
|
4955
5305
|
SKIP_DIRS2 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage", ".turbo"]);
|
|
4956
5306
|
BUILTINS = new Set(builtinModules.flatMap((m) => [m, `node:${m}`]));
|
|
4957
5307
|
IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([^"']+)["']/g;
|
|
4958
5308
|
TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
5309
|
+
NPM_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
4959
5310
|
GENESIS_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
4960
5311
|
}
|
|
4961
5312
|
});
|
|
@@ -5126,9 +5477,9 @@ function gitView(root, dir, base) {
|
|
|
5126
5477
|
function checkSupabasePack(ctx) {
|
|
5127
5478
|
const settings2 = ctx.config.supabase ?? {};
|
|
5128
5479
|
const dir = settings2.migrations ?? DEFAULT_MIGRATIONS;
|
|
5129
|
-
const abs =
|
|
5480
|
+
const abs = path28.join(ctx.root, dir);
|
|
5130
5481
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
5131
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
5482
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path28.join(abs, n), "utf8")) }));
|
|
5132
5483
|
const exposed = new Set((settings2.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
5133
5484
|
const base = settings2.base ?? DEFAULT_BASE;
|
|
5134
5485
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -5145,7 +5496,7 @@ function checkSupabasePack(ctx) {
|
|
|
5145
5496
|
}
|
|
5146
5497
|
}
|
|
5147
5498
|
const since = settings2.since;
|
|
5148
|
-
const afterSince = (file) => since === void 0 ||
|
|
5499
|
+
const afterSince = (file) => since === void 0 || path28.posix.basename(file) >= since;
|
|
5149
5500
|
if ("reason" in view && since === void 0) {
|
|
5150
5501
|
ctx.report({
|
|
5151
5502
|
rule: "migration-grants",
|
|
@@ -5416,18 +5767,18 @@ var init_supabase = __esm({
|
|
|
5416
5767
|
}
|
|
5417
5768
|
});
|
|
5418
5769
|
function nodeModulesOf(dir) {
|
|
5419
|
-
const parent =
|
|
5420
|
-
return
|
|
5770
|
+
const parent = path28.dirname(dir);
|
|
5771
|
+
return path28.basename(parent).startsWith("@") ? path28.dirname(parent) : parent;
|
|
5421
5772
|
}
|
|
5422
5773
|
function packagesIn(nodeModules) {
|
|
5423
5774
|
if (!existsSync(nodeModules)) return [];
|
|
5424
5775
|
const out = [];
|
|
5425
5776
|
for (const entry of readdirSync(nodeModules)) {
|
|
5426
5777
|
if (entry.startsWith(".")) continue;
|
|
5427
|
-
const p =
|
|
5778
|
+
const p = path28.join(nodeModules, entry);
|
|
5428
5779
|
if (entry.startsWith("@")) {
|
|
5429
5780
|
try {
|
|
5430
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5781
|
+
for (const sub of readdirSync(p)) out.push(path28.join(p, sub));
|
|
5431
5782
|
} catch {
|
|
5432
5783
|
}
|
|
5433
5784
|
} else {
|
|
@@ -5439,7 +5790,7 @@ function packagesIn(nodeModules) {
|
|
|
5439
5790
|
function genesisInstalls(root) {
|
|
5440
5791
|
const copies = /* @__PURE__ */ new Map();
|
|
5441
5792
|
const realRoot = real(root);
|
|
5442
|
-
const rel = (abs) =>
|
|
5793
|
+
const rel = (abs) => path28.relative(realRoot, abs).split(path28.sep).join("/") || ".";
|
|
5443
5794
|
const via = /* @__PURE__ */ new Map();
|
|
5444
5795
|
const record = (real2, manifest, by, range, root2) => {
|
|
5445
5796
|
let copy = copies.get(real2);
|
|
@@ -5484,7 +5835,7 @@ function genesisInstalls(root) {
|
|
|
5484
5835
|
if (!dir) return null;
|
|
5485
5836
|
if (!ownInstall || name in declared) return dir;
|
|
5486
5837
|
const realDir = real(dir);
|
|
5487
|
-
if (realDir.startsWith(realRoot +
|
|
5838
|
+
if (realDir.startsWith(realRoot + path28.sep)) return dir;
|
|
5488
5839
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
5489
5840
|
};
|
|
5490
5841
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -5492,7 +5843,7 @@ function genesisInstalls(root) {
|
|
|
5492
5843
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
5493
5844
|
});
|
|
5494
5845
|
const app = readManifest(root);
|
|
5495
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5846
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path28.join(root, f)));
|
|
5496
5847
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
5497
5848
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
5498
5849
|
const runtimeDeps = {
|
|
@@ -5503,11 +5854,11 @@ function genesisInstalls(root) {
|
|
|
5503
5854
|
};
|
|
5504
5855
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
5505
5856
|
walk2("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5506
|
-
const top =
|
|
5857
|
+
const top = path28.join(root, "node_modules");
|
|
5507
5858
|
walk2(
|
|
5508
5859
|
"hoisted",
|
|
5509
5860
|
packagesIn(top).filter((dir) => {
|
|
5510
|
-
const name =
|
|
5861
|
+
const name = path28.relative(top, dir).split(path28.sep).join("/");
|
|
5511
5862
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
5512
5863
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
5513
5864
|
);
|
|
@@ -5549,7 +5900,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
5549
5900
|
}
|
|
5550
5901
|
}
|
|
5551
5902
|
function checkPeerRanges(ctx) {
|
|
5552
|
-
const rel = (abs) =>
|
|
5903
|
+
const rel = (abs) => path28.relative(ctx.root, abs).split(path28.sep).join("/");
|
|
5553
5904
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
5554
5905
|
for (const copy of copies) {
|
|
5555
5906
|
const dir = copy.absolutePath;
|
|
@@ -5582,7 +5933,7 @@ var init_installs = __esm({
|
|
|
5582
5933
|
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)$/;
|
|
5583
5934
|
readManifest = (dir) => {
|
|
5584
5935
|
try {
|
|
5585
|
-
return JSON.parse(readFileSync(
|
|
5936
|
+
return JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
5586
5937
|
} catch {
|
|
5587
5938
|
return null;
|
|
5588
5939
|
}
|
|
@@ -5644,6 +5995,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
5644
5995
|
if (owner.size === 0) return;
|
|
5645
5996
|
const decl = /\b(export\s+(?:default\s+)?)?(?:declare\s+)?(?:async\s+)?(?:function\*?|const|let|var|class)\s+([A-Z][\w$]*)\b/g;
|
|
5646
5997
|
const routes = routesDir(ctx);
|
|
5998
|
+
const overlays = markedOverlays(ctx);
|
|
5647
5999
|
for (const file of ctx.files) {
|
|
5648
6000
|
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
5649
6001
|
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
|
|
@@ -5654,6 +6006,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
5654
6006
|
const [, exported, name] = m;
|
|
5655
6007
|
const pkg = owner.get(name);
|
|
5656
6008
|
if (!pkg || imported.has(name) || routeComponents.has(name)) return;
|
|
6009
|
+
if (insideOverlayOf(overlays, file, pkg)) return;
|
|
5657
6010
|
if (inRoutes && !exported && !new RegExp(`\\bexport\\s*(?:default\\s+${name}\\b|\\{[^}]*\\b${name}\\b)`).test(file.code)) return;
|
|
5658
6011
|
const body = file.code.slice(m.index + m[0].length, decls[i + 1]?.index ?? file.code.length);
|
|
5659
6012
|
if (!rendersJsx(body)) return;
|
|
@@ -5729,6 +6082,7 @@ function checkPageLayouts(ctx) {
|
|
|
5729
6082
|
var SUB_NAV_DOCS, CONTAINER, SWITCHER, SHELL, GENESIS_PACKAGE2, PAGE_LAYOUT, EMBEDDED_RESOURCE_VIEW, PACKAGE_SCREEN, isNative2, rendersRe, routeVia;
|
|
5730
6083
|
var init_structure = __esm({
|
|
5731
6084
|
"src/doctor/structure.ts"() {
|
|
6085
|
+
init_overlays();
|
|
5732
6086
|
init_scan();
|
|
5733
6087
|
init_routes();
|
|
5734
6088
|
init_source();
|
|
@@ -5738,9 +6092,9 @@ var init_structure = __esm({
|
|
|
5738
6092
|
SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
5739
6093
|
SHELL = /<AppShell(?=[\s>/])/;
|
|
5740
6094
|
GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
5741
|
-
PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView)$/;
|
|
6095
|
+
PAGE_LAYOUT = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)|ResourceView|RecordView)$/;
|
|
5742
6096
|
EMBEDDED_RESOURCE_VIEW = /<ResourceView\b[^>]*?\blayout\s*=\s*(?:(["'`]) {8}\1|\{\s*(["'`]) {8}\2\s*\})[^>]*>/g;
|
|
5743
|
-
PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView)$/;
|
|
6097
|
+
PACKAGE_SCREEN = /^(?:(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)|ResourceView|RecordView)$/;
|
|
5744
6098
|
isNative2 = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
5745
6099
|
rendersRe = (names) => {
|
|
5746
6100
|
const list = [...names];
|
|
@@ -6061,11 +6415,11 @@ function appScripts(root) {
|
|
|
6061
6415
|
const out = [];
|
|
6062
6416
|
const walk2 = (dir) => {
|
|
6063
6417
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
6064
|
-
const abs =
|
|
6418
|
+
const abs = path28.join(dir, entry.name);
|
|
6065
6419
|
if (entry.isDirectory()) {
|
|
6066
6420
|
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
6067
6421
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
6068
|
-
out.push(
|
|
6422
|
+
out.push(path28.relative(root, abs).split(path28.sep).join("/"));
|
|
6069
6423
|
}
|
|
6070
6424
|
}
|
|
6071
6425
|
};
|
|
@@ -6105,7 +6459,7 @@ var init_codemods = __esm({
|
|
|
6105
6459
|
let readsId = false;
|
|
6106
6460
|
let augmented = false;
|
|
6107
6461
|
for (const rel of appScripts(root)) {
|
|
6108
|
-
const abs =
|
|
6462
|
+
const abs = path28.join(root, rel);
|
|
6109
6463
|
const text = readFileSync(abs, "utf8");
|
|
6110
6464
|
if (augmentsResourceScope(text)) augmented = true;
|
|
6111
6465
|
if (!IMPORTS_GENESIS.test(text)) continue;
|
|
@@ -6201,7 +6555,7 @@ function checkTreeViews(ctx) {
|
|
|
6201
6555
|
function moduleFiles(ctx) {
|
|
6202
6556
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
6203
6557
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
6204
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
6558
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path28.join(ctx.root, rel), "utf8"), true) }));
|
|
6205
6559
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
6206
6560
|
}
|
|
6207
6561
|
function checkStudioServerImports(ctx) {
|
|
@@ -6231,7 +6585,7 @@ function checkStudioServerImports(ctx) {
|
|
|
6231
6585
|
}
|
|
6232
6586
|
function checkRemovedScopeNames(ctx) {
|
|
6233
6587
|
let augmentedMemo;
|
|
6234
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
6588
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path28.join(ctx.root, rel), "utf8")));
|
|
6235
6589
|
for (const file of ctx.files) {
|
|
6236
6590
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
6237
6591
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -6278,6 +6632,103 @@ var init_api_usage = __esm({
|
|
|
6278
6632
|
};
|
|
6279
6633
|
}
|
|
6280
6634
|
});
|
|
6635
|
+
function stabilityTagsIn(dts) {
|
|
6636
|
+
const tags = /* @__PURE__ */ new Map();
|
|
6637
|
+
for (const m of dts.matchAll(DECLARATION)) {
|
|
6638
|
+
const doc = m[1].replace(/^[ \t]*\*?[ \t]*/gm, "");
|
|
6639
|
+
const deprecated = /^@deprecated\b[ \t]*([\s\S]*?)(?=^@|(?![\s\S]))/m.exec(doc);
|
|
6640
|
+
const stability = /^@stability\s+(Experimental|Beta|Stable|Deprecated)\b/im.exec(doc)?.[1]?.toLowerCase();
|
|
6641
|
+
const note = deprecated?.[1].replace(/\s+/g, " ").trim();
|
|
6642
|
+
if (deprecated) tags.set(m[2], { stability: "deprecated", ...note ? { note } : {} });
|
|
6643
|
+
else if (stability) tags.set(m[2], { stability });
|
|
6644
|
+
}
|
|
6645
|
+
return tags;
|
|
6646
|
+
}
|
|
6647
|
+
function genesisNamedImports(code) {
|
|
6648
|
+
const out = [];
|
|
6649
|
+
const re = /import\s+(?:type\s+)?(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*["']((@marktiderman\/genesis[\w-]*)(?:\/[^"']*)?)["']/g;
|
|
6650
|
+
for (const m of code.matchAll(re)) {
|
|
6651
|
+
const names = m[1].split(",").map((n) => n.trim().replace(/^type\s+/, "").split(/\s+as\s+/)[0].trim()).filter(Boolean);
|
|
6652
|
+
out.push({ pkg: m[3], specifier: m[2], names, line: code.slice(0, m.index).split("\n").length });
|
|
6653
|
+
}
|
|
6654
|
+
return out;
|
|
6655
|
+
}
|
|
6656
|
+
function declarationFiles(dir, out = []) {
|
|
6657
|
+
for (const name of readdirSync(dir)) {
|
|
6658
|
+
const full = path28.join(dir, name);
|
|
6659
|
+
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
6660
|
+
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
6661
|
+
}
|
|
6662
|
+
return out;
|
|
6663
|
+
}
|
|
6664
|
+
function packageDir2(root, pkg) {
|
|
6665
|
+
for (let dir = path28.resolve(root); ; dir = path28.dirname(dir)) {
|
|
6666
|
+
const candidate = path28.join(dir, "node_modules", ...pkg.split("/"));
|
|
6667
|
+
if (existsSync(path28.join(candidate, "package.json"))) return candidate;
|
|
6668
|
+
if (path28.dirname(dir) === dir) return null;
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6671
|
+
function readPackageTags(dir) {
|
|
6672
|
+
const pkg = JSON.parse(readFileSync(path28.join(dir, "package.json"), "utf8"));
|
|
6673
|
+
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
6674
|
+
const dist = path28.join(dir, "dist");
|
|
6675
|
+
if (!existsSync(dist)) return tags;
|
|
6676
|
+
for (const file of declarationFiles(dist)) {
|
|
6677
|
+
const text = readFileSync(file, "utf8");
|
|
6678
|
+
tags.byFile.set(file, stabilityTagsIn(text));
|
|
6679
|
+
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)) {
|
|
6680
|
+
const files = tags.declaredIn.get(m[1]) ?? [];
|
|
6681
|
+
if (!files.includes(file)) files.push(file);
|
|
6682
|
+
tags.declaredIn.set(m[1], files);
|
|
6683
|
+
}
|
|
6684
|
+
}
|
|
6685
|
+
return tags;
|
|
6686
|
+
}
|
|
6687
|
+
function entryFile(tags, pkg, specifier) {
|
|
6688
|
+
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
6689
|
+
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
6690
|
+
const types = typeof target === "object" && target ? target.types : null;
|
|
6691
|
+
return typeof types === "string" ? path28.join(tags.dir, types) : null;
|
|
6692
|
+
}
|
|
6693
|
+
function tagFor(tags, entry, name) {
|
|
6694
|
+
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
6695
|
+
const all = (tags.declaredIn.get(name) ?? []).map((f) => tags.byFile.get(f)?.get(name));
|
|
6696
|
+
if (!all.length || all.some((t) => !t)) return void 0;
|
|
6697
|
+
return all.every((t) => t.stability === all[0].stability) ? all[0] : void 0;
|
|
6698
|
+
}
|
|
6699
|
+
function checkStabilityImports(ctx) {
|
|
6700
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
6701
|
+
const tagsOf = (pkg) => {
|
|
6702
|
+
if (!cache2.has(pkg)) {
|
|
6703
|
+
const dir = packageDir2(ctx.root, pkg);
|
|
6704
|
+
cache2.set(pkg, dir ? readPackageTags(dir) : null);
|
|
6705
|
+
}
|
|
6706
|
+
return cache2.get(pkg);
|
|
6707
|
+
};
|
|
6708
|
+
for (const file of ctx.files) {
|
|
6709
|
+
if (!SCRIPT_EXTS6.has(file.ext)) continue;
|
|
6710
|
+
for (const { pkg, specifier, names, line } of genesisNamedImports(file.code)) {
|
|
6711
|
+
const tags = tagsOf(pkg);
|
|
6712
|
+
if (!tags) continue;
|
|
6713
|
+
const entry = entryFile(tags, pkg, specifier);
|
|
6714
|
+
for (const name of names) {
|
|
6715
|
+
const tag = tagFor(tags, entry, name);
|
|
6716
|
+
if (tag?.stability === "deprecated") {
|
|
6717
|
+
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}` : ""}` });
|
|
6718
|
+
} else if (tag && (tag.stability === "beta" || tag.stability === "experimental")) {
|
|
6719
|
+
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` });
|
|
6720
|
+
}
|
|
6721
|
+
}
|
|
6722
|
+
}
|
|
6723
|
+
}
|
|
6724
|
+
}
|
|
6725
|
+
var SCRIPT_EXTS6, DECLARATION;
|
|
6726
|
+
var init_stability = __esm({
|
|
6727
|
+
"src/doctor/stability.ts"() {
|
|
6728
|
+
SCRIPT_EXTS6 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
6729
|
+
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;
|
|
6730
|
+
}
|
|
6731
|
+
});
|
|
6281
6732
|
function git3(root, args) {
|
|
6282
6733
|
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
6283
6734
|
return r.status === 0 ? r.stdout : null;
|
|
@@ -6298,7 +6749,7 @@ function showAt(dir, rev, file) {
|
|
|
6298
6749
|
function configAtBase(root, base, explicitFile) {
|
|
6299
6750
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
6300
6751
|
if (!mergeBase) return null;
|
|
6301
|
-
const candidates = explicitFile ? [{ dir:
|
|
6752
|
+
const candidates = explicitFile ? [{ dir: path28.dirname(explicitFile), file: path28.basename(explicitFile), explicit: true }] : [
|
|
6302
6753
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
6303
6754
|
{ dir: root, file: "package.json", explicit: false }
|
|
6304
6755
|
];
|
|
@@ -6417,7 +6868,7 @@ function catalogTable(rows, options = {}) {
|
|
|
6417
6868
|
return [head, ...body].join("\n");
|
|
6418
6869
|
}
|
|
6419
6870
|
function formatPrimitives(rows) {
|
|
6420
|
-
const lines = ["Genesis
|
|
6871
|
+
const lines = ["Genesis catalog: what to use for each need (reuse, then extend, then invent).", ""];
|
|
6421
6872
|
for (const r of rows) {
|
|
6422
6873
|
lines.push(`- ${r.need}: ${r.use}`);
|
|
6423
6874
|
if (r.import) lines.push(` import ${r.import}`);
|
|
@@ -6443,7 +6894,7 @@ function renderSkill(rows) {
|
|
|
6443
6894
|
"",
|
|
6444
6895
|
catalogTable(rows, { docs: true }),
|
|
6445
6896
|
"",
|
|
6446
|
-
"`genesis
|
|
6897
|
+
"`genesis catalog` prints the same list; `genesis doctor` enforces the rules named above.",
|
|
6447
6898
|
""
|
|
6448
6899
|
].join("\n");
|
|
6449
6900
|
}
|
|
@@ -6454,7 +6905,7 @@ function renderAgentsBlock(rows) {
|
|
|
6454
6905
|
"",
|
|
6455
6906
|
"Generated by `genesis agents` from the installed Genesis packages. Don't edit this block; run `genesis agents` after upgrading Genesis.",
|
|
6456
6907
|
"",
|
|
6457
|
-
`Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis
|
|
6908
|
+
`Before writing a screen, read \`${SKILL_PATH}\` (or run \`genesis catalog\`).`,
|
|
6458
6909
|
"",
|
|
6459
6910
|
...RULES.map((r) => `- ${r}`),
|
|
6460
6911
|
"",
|
|
@@ -6488,13 +6939,13 @@ function currentAgentsBlock(agents) {
|
|
|
6488
6939
|
function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
6489
6940
|
const rows = primitivesCatalog(packages);
|
|
6490
6941
|
const changed = [];
|
|
6491
|
-
const agents =
|
|
6942
|
+
const agents = path28.join(root, agentsFile);
|
|
6492
6943
|
const before = read(agents);
|
|
6493
6944
|
const after = mergeAgentsBlock(before, renderAgentsBlock(rows));
|
|
6494
|
-
const skill =
|
|
6945
|
+
const skill = path28.join(root, SKILL_PATH);
|
|
6495
6946
|
const skillText = renderSkill(rows);
|
|
6496
6947
|
if (read(skill)?.replace(/\r\n/g, "\n") !== skillText) {
|
|
6497
|
-
mkdirSync(
|
|
6948
|
+
mkdirSync(path28.dirname(skill), { recursive: true });
|
|
6498
6949
|
writeFileSync(skill, skillText);
|
|
6499
6950
|
changed.push(SKILL_PATH);
|
|
6500
6951
|
}
|
|
@@ -6506,8 +6957,8 @@ function writeAgentGuide(root, packages, agentsFile = "AGENTS.md") {
|
|
|
6506
6957
|
}
|
|
6507
6958
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6508
6959
|
const rows = primitivesCatalog(packages);
|
|
6509
|
-
const skill = read(
|
|
6510
|
-
const block = currentAgentsBlock(read(
|
|
6960
|
+
const skill = read(path28.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
6961
|
+
const block = currentAgentsBlock(read(path28.join(root, agentsFile)));
|
|
6511
6962
|
return {
|
|
6512
6963
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6513
6964
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -6543,7 +6994,7 @@ var init_primitives = __esm({
|
|
|
6543
6994
|
},
|
|
6544
6995
|
{
|
|
6545
6996
|
need: "a page inside the app shell",
|
|
6546
|
-
use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` (from `@marktiderman/genesis-ui/data`)",
|
|
6997
|
+
use: "a Genesis page layout (`DashboardPage`, `SettingsPage`, `FormPage`, `DetailPage`, from `@marktiderman/genesis-ui`) or `ResourceView` / `RecordView` (from `@marktiderman/genesis-ui/data`)",
|
|
6547
6998
|
import: "@marktiderman/genesis-ui",
|
|
6548
6999
|
rule: "page-layout",
|
|
6549
7000
|
from: "genesis-cli"
|
|
@@ -6635,7 +7086,7 @@ __export(doctor_exports, {
|
|
|
6635
7086
|
writeAgentGuide: () => writeAgentGuide
|
|
6636
7087
|
});
|
|
6637
7088
|
async function runDoctor(options = {}) {
|
|
6638
|
-
const root =
|
|
7089
|
+
const root = path28.resolve(options.root ?? process.cwd());
|
|
6639
7090
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
6640
7091
|
const config = loaded.config;
|
|
6641
7092
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -6649,7 +7100,7 @@ async function runDoctor(options = {}) {
|
|
|
6649
7100
|
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`);
|
|
6650
7101
|
}
|
|
6651
7102
|
const raw = [];
|
|
6652
|
-
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, report: (f) => raw.push(f) };
|
|
7103
|
+
const ctx = { root, files, genesis, config, packages, ...options.base ? { base: options.base } : {}, ...options.strict ? { strict: true } : {}, report: (f) => raw.push(f) };
|
|
6653
7104
|
for (const plugin of [...builtinChecks(config, { contracts: options.contracts ?? true }), ...packagePlugins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
6654
7105
|
try {
|
|
6655
7106
|
await plugin.check(ctx);
|
|
@@ -6663,10 +7114,11 @@ async function runDoctor(options = {}) {
|
|
|
6663
7114
|
if (failure) raw.push(failure);
|
|
6664
7115
|
}
|
|
6665
7116
|
raw.push(...unknownPackageRuleSettings(config, packages, raw));
|
|
6666
|
-
const newOnly = /* @__PURE__ */ new Set([...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
|
|
7117
|
+
const newOnly = /* @__PURE__ */ new Set([...RATCHETED_BY_DEFAULT, ...patterns?.newOnly ?? [], ...preferRules(packages).filter((r) => r.newOnly).map((r) => r.ruleId)]);
|
|
6667
7118
|
let changed = null;
|
|
6668
7119
|
let skipped = false;
|
|
6669
|
-
|
|
7120
|
+
const ratchetNeeded = newOnly.size > RATCHETED_BY_DEFAULT.length || raw.some((f) => RATCHETED_BY_DEFAULT.includes(f.rule));
|
|
7121
|
+
if (options.base && (ratchetNeeded || config.ratchet)) {
|
|
6670
7122
|
changed = options.changedFiles ? new Set(options.changedFiles) : changedSince(root, options.base);
|
|
6671
7123
|
skipped ||= !changed;
|
|
6672
7124
|
}
|
|
@@ -6688,7 +7140,7 @@ async function runDoctor(options = {}) {
|
|
|
6688
7140
|
}
|
|
6689
7141
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
6690
7142
|
if (options.base && changed) {
|
|
6691
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
7143
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path28.join(root, f)) });
|
|
6692
7144
|
}
|
|
6693
7145
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
6694
7146
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -6730,7 +7182,9 @@ function builtinChecks(config, options = {}) {
|
|
|
6730
7182
|
{ name: "resource-view-trees", check: checkTreeViews },
|
|
6731
7183
|
{ name: "studio-server-imports", check: checkStudioServerImports },
|
|
6732
7184
|
{ name: "removed-scope-names", check: checkRemovedScopeNames },
|
|
7185
|
+
{ name: "stability-imports", check: checkStabilityImports },
|
|
6733
7186
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
7187
|
+
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
6734
7188
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
6735
7189
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
6736
7190
|
];
|
|
@@ -6793,7 +7247,7 @@ function formatReport(result) {
|
|
|
6793
7247
|
lines.push(`${f.level.toUpperCase().padEnd(5)} ${f.file}${f.line ? `:${f.line}` : ""} [${f.rule}] ${f.message}`);
|
|
6794
7248
|
}
|
|
6795
7249
|
lines.push(`Available but unused (${result.unused.length}): ${result.unused.join(", ") || "none"}`);
|
|
6796
|
-
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis
|
|
7250
|
+
lines.push(`Primitives: ${result.primitives.rules} rules from ${result.primitives.packages} packages; see genesis catalog`);
|
|
6797
7251
|
const info = result.infos ? `, ${result.infos} info` : "";
|
|
6798
7252
|
lines.push(result.ok ? `PASS (${result.warnings} warnings${info})` : `FAIL (${result.errors} errors, ${result.warnings} warnings${info})`);
|
|
6799
7253
|
return lines.join("\n");
|
|
@@ -6820,6 +7274,7 @@ function genesisSummary(g) {
|
|
|
6820
7274
|
companions: Object.fromEntries(g.companions.map((c) => [`${c.package}@${c.version}`, c.components]))
|
|
6821
7275
|
};
|
|
6822
7276
|
}
|
|
7277
|
+
var RATCHETED_BY_DEFAULT;
|
|
6823
7278
|
var init_doctor = __esm({
|
|
6824
7279
|
"src/doctor/index.ts"() {
|
|
6825
7280
|
init_build();
|
|
@@ -6838,10 +7293,12 @@ var init_doctor = __esm({
|
|
|
6838
7293
|
init_structure();
|
|
6839
7294
|
init_dates();
|
|
6840
7295
|
init_api_usage();
|
|
7296
|
+
init_stability();
|
|
6841
7297
|
init_package_rules();
|
|
6842
7298
|
init_ratchet();
|
|
6843
7299
|
init_contracts();
|
|
6844
7300
|
init_primitives();
|
|
7301
|
+
init_overlays();
|
|
6845
7302
|
init_config();
|
|
6846
7303
|
init_genesis();
|
|
6847
7304
|
init_patterns();
|
|
@@ -6858,15 +7315,148 @@ var init_doctor = __esm({
|
|
|
6858
7315
|
init_primitives();
|
|
6859
7316
|
init_ratchet();
|
|
6860
7317
|
init_contracts();
|
|
7318
|
+
RATCHETED_BY_DEFAULT = ["deprecated-import"];
|
|
7319
|
+
}
|
|
7320
|
+
});
|
|
7321
|
+
|
|
7322
|
+
// src/agent-rules.ts
|
|
7323
|
+
var agent_rules_exports = {};
|
|
7324
|
+
__export(agent_rules_exports, {
|
|
7325
|
+
checkAgentRules: () => checkAgentRules,
|
|
7326
|
+
pullRequestBranches: () => pullRequestBranches,
|
|
7327
|
+
pullRequestList: () => pullRequestList,
|
|
7328
|
+
runsOnPullRequestsInto: () => runsOnPullRequestsInto
|
|
7329
|
+
});
|
|
7330
|
+
function changesetBumps(root) {
|
|
7331
|
+
const dir = path28.join(root, ".changeset");
|
|
7332
|
+
const bumps = /* @__PURE__ */ new Map();
|
|
7333
|
+
if (!existsSync(dir)) return bumps;
|
|
7334
|
+
for (const name of readdirSync(dir)) {
|
|
7335
|
+
if (!name.endsWith(".md") || name === "README.md") continue;
|
|
7336
|
+
const text = readFileSync(path28.join(dir, name), "utf8");
|
|
7337
|
+
const front = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text)?.[1] ?? "";
|
|
7338
|
+
for (const line of front.split(/\r?\n/)) {
|
|
7339
|
+
const m = /^\s*["']?([^"':]+)["']?\s*:\s*(major|minor|patch)\s*$/.exec(line);
|
|
7340
|
+
if (!m) continue;
|
|
7341
|
+
const list = bumps.get(m[1]) ?? [];
|
|
7342
|
+
list.push({ file: `.changeset/${name}`, bump: m[2] });
|
|
7343
|
+
bumps.set(m[1], list);
|
|
7344
|
+
}
|
|
7345
|
+
}
|
|
7346
|
+
return bumps;
|
|
7347
|
+
}
|
|
7348
|
+
function firstVersionProblems(root) {
|
|
7349
|
+
const packagesDir = path28.join(root, "packages");
|
|
7350
|
+
if (!existsSync(packagesDir)) return [];
|
|
7351
|
+
const bumps = changesetBumps(root);
|
|
7352
|
+
const problems = [];
|
|
7353
|
+
for (const dir of readdirSync(packagesDir)) {
|
|
7354
|
+
const file = path28.join(packagesDir, dir, "package.json");
|
|
7355
|
+
if (!existsSync(file) || existsSync(path28.join(packagesDir, dir, "CHANGELOG.md"))) continue;
|
|
7356
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
7357
|
+
if (pkg.private || !pkg.name) continue;
|
|
7358
|
+
if (pkg.version !== FIRST_VERSION) {
|
|
7359
|
+
problems.push({ rule: "first-version", message: `packages/${dir}: ${pkg.name} has never been released, so it starts at ${FIRST_VERSION}, not ${pkg.version ?? "no version"}` });
|
|
7360
|
+
}
|
|
7361
|
+
for (const b of bumps.get(pkg.name) ?? []) {
|
|
7362
|
+
if (b.bump !== "patch") problems.push({ rule: "first-version", message: `${b.file}: ${pkg.name} is new, so its first changeset is a patch (${FIRST_VERSION} by hand, then CI publishes the next), not a ${b.bump}` });
|
|
7363
|
+
}
|
|
7364
|
+
}
|
|
7365
|
+
return problems;
|
|
7366
|
+
}
|
|
7367
|
+
function uncomment(line) {
|
|
7368
|
+
let quote2 = null;
|
|
7369
|
+
for (let i = 0; i < line.length; i++) {
|
|
7370
|
+
const ch = line[i];
|
|
7371
|
+
if (quote2) {
|
|
7372
|
+
if (ch === quote2) quote2 = null;
|
|
7373
|
+
} else if (ch === '"' || ch === "'") quote2 = ch;
|
|
7374
|
+
else if (ch === "#" && (i === 0 || /\s/.test(line[i - 1]))) return line.slice(0, i).trimEnd();
|
|
7375
|
+
}
|
|
7376
|
+
return line.trimEnd();
|
|
7377
|
+
}
|
|
7378
|
+
function pullRequestBranches(workflow) {
|
|
7379
|
+
return pullRequestList(workflow, "branches");
|
|
7380
|
+
}
|
|
7381
|
+
function pullRequestList(workflow, key2) {
|
|
7382
|
+
const lines = workflow.split(/\r?\n/).map(uncomment);
|
|
7383
|
+
const start = lines.findIndex((l) => /^\s*pull_request(_target)?:\s*$/.test(l));
|
|
7384
|
+
if (start < 0) return void 0;
|
|
7385
|
+
const base = indentOf(lines[start]);
|
|
7386
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
7387
|
+
const line = lines[i];
|
|
7388
|
+
if (!line.trim()) continue;
|
|
7389
|
+
if (indentOf(line) <= base) return void 0;
|
|
7390
|
+
const m = new RegExp(`^(\\s*)${key2}:\\s*(.*)$`).exec(line);
|
|
7391
|
+
if (!m) continue;
|
|
7392
|
+
const inline = /^\[(.*)\]$/.exec(m[2]);
|
|
7393
|
+
if (inline) return inline[1].split(",").map(unquote).filter(Boolean);
|
|
7394
|
+
const at = m[1].length;
|
|
7395
|
+
const out = [];
|
|
7396
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
7397
|
+
const item = lines[j];
|
|
7398
|
+
if (!item.trim()) continue;
|
|
7399
|
+
const dash = /^(\s*)-\s*(.*)$/.exec(item);
|
|
7400
|
+
if (!dash || dash[1].length < at) break;
|
|
7401
|
+
out.push(unquote(dash[2]));
|
|
7402
|
+
}
|
|
7403
|
+
return out;
|
|
7404
|
+
}
|
|
7405
|
+
return void 0;
|
|
7406
|
+
}
|
|
7407
|
+
function globMatches(pattern, branch) {
|
|
7408
|
+
const source = pattern.split(/(\*\*|\*|\?)/).map((part) => part === "**" ? ".*" : part === "*" ? "[^/]*" : part === "?" ? "." : part.replace(/[.+^${}()|[\]\\]/g, "\\$&")).join("");
|
|
7409
|
+
return new RegExp(`^${source}$`).test(branch);
|
|
7410
|
+
}
|
|
7411
|
+
function runsOnPullRequestsInto(workflow, branch) {
|
|
7412
|
+
const branches = pullRequestList(workflow, "branches");
|
|
7413
|
+
if (branches) {
|
|
7414
|
+
let runs = false;
|
|
7415
|
+
for (const p of branches) {
|
|
7416
|
+
if (p.startsWith("!")) {
|
|
7417
|
+
if (globMatches(p.slice(1), branch)) runs = false;
|
|
7418
|
+
} else if (globMatches(p, branch)) runs = true;
|
|
7419
|
+
}
|
|
7420
|
+
return runs;
|
|
7421
|
+
}
|
|
7422
|
+
const ignore = pullRequestList(workflow, "branches-ignore");
|
|
7423
|
+
return ignore ? !ignore.some((p) => globMatches(p, branch)) : void 0;
|
|
7424
|
+
}
|
|
7425
|
+
function batchCiProblems(root, batch) {
|
|
7426
|
+
const dir = path28.join(root, ".github", "workflows");
|
|
7427
|
+
if (!existsSync(dir)) return [];
|
|
7428
|
+
const problems = [];
|
|
7429
|
+
for (const name of readdirSync(dir)) {
|
|
7430
|
+
if (!/\.ya?ml$/.test(name)) continue;
|
|
7431
|
+
const workflow = readFileSync(path28.join(dir, name), "utf8");
|
|
7432
|
+
const main = runsOnPullRequestsInto(workflow, "main");
|
|
7433
|
+
if (main && !runsOnPullRequestsInto(workflow, sampleBranch(batch))) {
|
|
7434
|
+
problems.push({ rule: "batch-ci", message: `.github/workflows/${name}: runs on pull requests into main but not into ${batch}; let pull_request's branch filter include it` });
|
|
7435
|
+
}
|
|
7436
|
+
}
|
|
7437
|
+
return problems;
|
|
7438
|
+
}
|
|
7439
|
+
function checkAgentRules(root, options = {}) {
|
|
7440
|
+
return [...firstVersionProblems(root), ...batchCiProblems(root, options.batch ?? "staging/**")];
|
|
7441
|
+
}
|
|
7442
|
+
var FIRST_VERSION, indentOf, unquote, sampleBranch;
|
|
7443
|
+
var init_agent_rules = __esm({
|
|
7444
|
+
"src/agent-rules.ts"() {
|
|
7445
|
+
FIRST_VERSION = "0.1.0";
|
|
7446
|
+
indentOf = (line) => line.length - line.trimStart().length;
|
|
7447
|
+
unquote = (s) => s.trim().replace(/^(["'])(.*)\1$/, "$2");
|
|
7448
|
+
sampleBranch = (pattern) => pattern.replace(/\*\*/g, "x/y").replace(/\*/g, "x").replace(/\?/g, "x");
|
|
6861
7449
|
}
|
|
6862
7450
|
});
|
|
6863
7451
|
|
|
6864
7452
|
// src/features.ts
|
|
6865
7453
|
var features_exports = {};
|
|
6866
7454
|
__export(features_exports, {
|
|
7455
|
+
findFilters: () => findFilters,
|
|
6867
7456
|
formatFeature: () => formatFeature,
|
|
6868
7457
|
gatherPrEvidence: () => gatherPrEvidence,
|
|
6869
7458
|
loadRegistry: () => loadRegistry,
|
|
7459
|
+
readFeaturePackages: () => readFeaturePackages,
|
|
6870
7460
|
runFeaturesBuild: () => runFeaturesBuild,
|
|
6871
7461
|
runFeaturesCheck: () => runFeaturesCheck,
|
|
6872
7462
|
runFeaturesFind: () => runFeaturesFind
|
|
@@ -6883,20 +7473,20 @@ function readObject(file, key2) {
|
|
|
6883
7473
|
}
|
|
6884
7474
|
}
|
|
6885
7475
|
function settings(root, options) {
|
|
6886
|
-
const fromPackage = readObject(
|
|
6887
|
-
const fromConfig = readObject(
|
|
7476
|
+
const fromPackage = readObject(path28.join(root, "package.json"), "genesisFeatures");
|
|
7477
|
+
const fromConfig = readObject(path28.join(root, "genesis.config.json"), "features");
|
|
6888
7478
|
const given = Object.fromEntries(Object.entries(options).filter(([, v]) => v !== void 0));
|
|
6889
7479
|
return { ...fromPackage, ...fromConfig, ...given };
|
|
6890
7480
|
}
|
|
6891
7481
|
async function loadRegistry(input) {
|
|
6892
|
-
const root =
|
|
7482
|
+
const root = path28.resolve(input.dir);
|
|
6893
7483
|
const options = settings(root, input);
|
|
6894
|
-
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(
|
|
6895
|
-
if (!registry || !existsSync(
|
|
7484
|
+
const registry = options.registry ?? DEFAULT_REGISTRIES.find((p) => existsSync(path28.join(root, p)));
|
|
7485
|
+
if (!registry || !existsSync(path28.join(root, registry))) {
|
|
6896
7486
|
throw new Error(`No feature registry found. Looked for ${options.registry ?? DEFAULT_REGISTRIES.join(" and ")}; pass --registry.`);
|
|
6897
7487
|
}
|
|
6898
|
-
const jiti = createJiti(
|
|
6899
|
-
const load = async (file) => await jiti.import(
|
|
7488
|
+
const jiti = createJiti(path28.join(root, "package.json"), { moduleCache: false });
|
|
7489
|
+
const load = async (file) => await jiti.import(path28.join(root, file));
|
|
6900
7490
|
const mod = await load(registry);
|
|
6901
7491
|
const features2 = mod.features ?? mod.default;
|
|
6902
7492
|
if (!isObject4(features2)) throw new Error(`${registry} must export \`features\` (from defineFeatures).`);
|
|
@@ -6908,7 +7498,7 @@ async function loadRegistry(input) {
|
|
|
6908
7498
|
const project = {
|
|
6909
7499
|
...rest,
|
|
6910
7500
|
root,
|
|
6911
|
-
source: options.source ?? registry.split(
|
|
7501
|
+
source: options.source ?? registry.split(path28.sep).join("/"),
|
|
6912
7502
|
features: features2,
|
|
6913
7503
|
flags
|
|
6914
7504
|
};
|
|
@@ -6956,12 +7546,59 @@ async function runFeaturesCheck(options) {
|
|
|
6956
7546
|
}
|
|
6957
7547
|
return { ...result, summary };
|
|
6958
7548
|
}
|
|
7549
|
+
function readFeaturePackages(root) {
|
|
7550
|
+
const found = [];
|
|
7551
|
+
const read2 = (dir, inRepo) => {
|
|
7552
|
+
const file = path28.join(dir, "package.json");
|
|
7553
|
+
if (!existsSync(file)) return;
|
|
7554
|
+
try {
|
|
7555
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
7556
|
+
const layer = pkg.genesis?.layer;
|
|
7557
|
+
if (typeof pkg.name !== "string" || !PACKAGE_LAYERS.includes(layer)) return;
|
|
7558
|
+
if (found.some((p) => p.name === pkg.name)) return;
|
|
7559
|
+
found.push({ name: pkg.name, layer, ...inRepo ? { dir: path28.relative(root, dir).split(path28.sep).join("/") } : {} });
|
|
7560
|
+
} catch {
|
|
7561
|
+
}
|
|
7562
|
+
};
|
|
7563
|
+
for (const [base, inRepo] of [
|
|
7564
|
+
[path28.join(root, "packages"), true],
|
|
7565
|
+
[path28.join(root, "node_modules", "@marktiderman"), false]
|
|
7566
|
+
]) {
|
|
7567
|
+
if (!existsSync(base)) continue;
|
|
7568
|
+
for (const name of readdirSync(base)) read2(path28.join(base, name), inRepo);
|
|
7569
|
+
}
|
|
7570
|
+
return found;
|
|
7571
|
+
}
|
|
7572
|
+
function findFilters(flags) {
|
|
7573
|
+
const pick = (name, value, allowed) => {
|
|
7574
|
+
if (value === void 0) return void 0;
|
|
7575
|
+
if (allowed.includes(value)) return value;
|
|
7576
|
+
throw new Error(`--${name} must be one of ${allowed.join(", ")}`);
|
|
7577
|
+
};
|
|
7578
|
+
const { layer } = flags;
|
|
7579
|
+
const layerKind = layer === "primitive" ? "element" : FEATURE_KINDS.includes(layer ?? "") ? layer : void 0;
|
|
7580
|
+
if (layerKind && flags.kind && layerKind !== flags.kind) throw new Error(`--layer ${layer} and --kind ${flags.kind} disagree; use --kind alone`);
|
|
7581
|
+
return {
|
|
7582
|
+
filters: {
|
|
7583
|
+
platform: pick("platform", flags.platform, FEATURE_PLATFORMS$1),
|
|
7584
|
+
kind: pick("kind", flags.kind ?? layerKind, FEATURE_KINDS),
|
|
7585
|
+
packageLayer: layerKind ? void 0 : pick("layer", layer, PACKAGE_LAYERS.filter((l) => l !== "primitive")),
|
|
7586
|
+
status: pick("status", flags.status, FEATURE_STATUSES)
|
|
7587
|
+
},
|
|
7588
|
+
...layerKind ? { warning: `--layer ${layer} is deprecated for a kind: use --kind ${layerKind}` } : {}
|
|
7589
|
+
};
|
|
7590
|
+
}
|
|
6959
7591
|
async function runFeaturesFind(options, term, filters = {}) {
|
|
6960
7592
|
const project = await loadRegistry(options);
|
|
6961
|
-
|
|
7593
|
+
const packages = filters.packageLayer && !filters.packages ? readFeaturePackages(project.root) : filters.packages;
|
|
7594
|
+
if (filters.packageLayer && !packages?.length) {
|
|
7595
|
+
throw new Error("--layer needs package layers, and no package here declares one (genesis.layer in packages/* or node_modules/@marktiderman/*)");
|
|
7596
|
+
}
|
|
7597
|
+
return findFeatures(project.features, term, project.flags, { ...filters, ...packages ? { packages } : {} });
|
|
6962
7598
|
}
|
|
6963
7599
|
function formatFeature(r) {
|
|
6964
|
-
const
|
|
7600
|
+
const kindOf = featureKind(r);
|
|
7601
|
+
const kind = kindOf ? ` ${kindOf}` : "";
|
|
6965
7602
|
const lines = [`${r.id} \u2014 ${r.name} [${r.status}${r.horizon ? `, ${r.horizon}` : ""}]${kind} (${r.owner})`, ` ${r.summary}`];
|
|
6966
7603
|
if (r.platforms) lines.push(` platforms: ${Object.entries(r.platforms).map(([p, s]) => `${p} ${s}`).join(", ")}`);
|
|
6967
7604
|
if (r.entry) lines.push(` import: ${Object.entries(r.entry).map(([p, e]) => `${e} (${p})`).join(", ")}`);
|
|
@@ -6982,6 +7619,116 @@ var init_features = __esm({
|
|
|
6982
7619
|
}
|
|
6983
7620
|
});
|
|
6984
7621
|
|
|
7622
|
+
// src/upstream.ts
|
|
7623
|
+
var upstream_exports = {};
|
|
7624
|
+
__export(upstream_exports, {
|
|
7625
|
+
REGISTER_PATH: () => REGISTER_PATH,
|
|
7626
|
+
REGISTER_PATHS: () => REGISTER_PATHS,
|
|
7627
|
+
UPSTREAM_KINDS: () => UPSTREAM_KINDS,
|
|
7628
|
+
UPSTREAM_STATUSES: () => UPSTREAM_STATUSES,
|
|
7629
|
+
cells: () => cells,
|
|
7630
|
+
checkUpstream: () => checkUpstream,
|
|
7631
|
+
exportIssueUrl: () => exportIssueUrl,
|
|
7632
|
+
localPaths: () => localPaths,
|
|
7633
|
+
readRegister: () => readRegister
|
|
7634
|
+
});
|
|
7635
|
+
function cells(line) {
|
|
7636
|
+
const out = [];
|
|
7637
|
+
let cell2 = "";
|
|
7638
|
+
let code = false;
|
|
7639
|
+
const text = line.trim().replace(/^\|/, "").replace(/\|$/, "");
|
|
7640
|
+
for (let i = 0; i < text.length; i++) {
|
|
7641
|
+
const ch = text[i];
|
|
7642
|
+
if (ch === "\\" && text[i + 1] === "|") {
|
|
7643
|
+
cell2 += "|";
|
|
7644
|
+
i++;
|
|
7645
|
+
} else if (ch === "`") {
|
|
7646
|
+
code = !code;
|
|
7647
|
+
cell2 += ch;
|
|
7648
|
+
} else if (ch === "|" && !code) {
|
|
7649
|
+
out.push(cell2);
|
|
7650
|
+
cell2 = "";
|
|
7651
|
+
} else cell2 += ch;
|
|
7652
|
+
}
|
|
7653
|
+
out.push(cell2);
|
|
7654
|
+
return out.map((c) => c.trim()).map((c) => /^`[^`]*`$/.test(c) ? c.slice(1, -1) : c);
|
|
7655
|
+
}
|
|
7656
|
+
function readRegister(markdown) {
|
|
7657
|
+
const problems = [];
|
|
7658
|
+
const entries = [];
|
|
7659
|
+
const lines = markdown.split("\n");
|
|
7660
|
+
const isRow = (l) => l.trim().startsWith("|");
|
|
7661
|
+
const start = lines.findIndex((l) => isRow(l) && COLUMNS.every((c) => cells(l).map((h) => h.toLowerCase()).includes(c)));
|
|
7662
|
+
if (start < 0) {
|
|
7663
|
+
return { entries, problems: [lines.some(isRow) ? `no table has the columns ${COLUMNS.join(", ")}` : `no table: add one with the columns ${COLUMNS.join(", ")}`] };
|
|
7664
|
+
}
|
|
7665
|
+
const after = lines.slice(start + 1).findIndex((l) => !isRow(l));
|
|
7666
|
+
const rows = lines.slice(start, after < 0 ? void 0 : start + 1 + after);
|
|
7667
|
+
const header = cells(rows[0]).map((h) => h.toLowerCase());
|
|
7668
|
+
const at = (row, c) => row[header.indexOf(c)] ?? "";
|
|
7669
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7670
|
+
for (const line of rows.slice(1)) {
|
|
7671
|
+
const row = cells(line);
|
|
7672
|
+
if (row.every((c) => /^:?-+:?$/.test(c))) continue;
|
|
7673
|
+
const id = at(row, "id");
|
|
7674
|
+
const where2 = id || `row "${line.trim().slice(0, 40)}"`;
|
|
7675
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) problems.push(`${where2}: id must be lowercase words and dashes`);
|
|
7676
|
+
else if (ids.has(id)) problems.push(`${id}: listed twice`);
|
|
7677
|
+
ids.add(id);
|
|
7678
|
+
const kind = at(row, "kind");
|
|
7679
|
+
const status = at(row, "status");
|
|
7680
|
+
if (!UPSTREAM_KINDS.includes(kind)) problems.push(`${where2}: kind must be ${UPSTREAM_KINDS.join(", ")}`);
|
|
7681
|
+
if (!UPSTREAM_STATUSES.includes(status)) problems.push(`${where2}: status must be ${UPSTREAM_STATUSES.join(", ")}`);
|
|
7682
|
+
const need = at(row, "need");
|
|
7683
|
+
if (!need || need === "-") problems.push(`${where2}: say the need in one line`);
|
|
7684
|
+
const local = at(row, "local");
|
|
7685
|
+
if (local && local !== "-" && localPaths(local).some((p) => path28.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p) || p.split(/[\\/]/).includes(".."))) {
|
|
7686
|
+
problems.push(`${where2}: local must be paths inside the app, relative to its root`);
|
|
7687
|
+
}
|
|
7688
|
+
const opt = (c) => at(row, c) && at(row, c) !== "-" ? at(row, c) : void 0;
|
|
7689
|
+
entries.push({ id, kind, status, need, ...opt("feature") ? { feature: opt("feature") } : {}, ...opt("package") ? { package: opt("package") } : {}, ...opt("local") ? { local: opt("local") } : {} });
|
|
7690
|
+
}
|
|
7691
|
+
return { entries, problems };
|
|
7692
|
+
}
|
|
7693
|
+
function localPaths(local) {
|
|
7694
|
+
return (local ?? "").split(/,\s+|<br\s*\/?>/i).map((p) => p.trim()).filter((p) => p && p !== "-");
|
|
7695
|
+
}
|
|
7696
|
+
function checkUpstream(root) {
|
|
7697
|
+
const found = REGISTER_PATHS.find((p) => existsSync(path28.join(root, p)));
|
|
7698
|
+
if (!found) return { entries: [], problems: [], warnings: [`no ${REGISTER_PATHS.join(" or ")}: nothing to check (add one when the app first needs something Genesis lacks)`], missing: true };
|
|
7699
|
+
const { entries, problems } = readRegister(readFileSync(path28.join(root, found), "utf8"));
|
|
7700
|
+
const warnings = [];
|
|
7701
|
+
for (const e of entries) {
|
|
7702
|
+
const paths = localPaths(e.local);
|
|
7703
|
+
const absent = paths.filter((p) => !existsSync(path28.join(root, p)));
|
|
7704
|
+
const present = paths.filter((p) => !absent.includes(p));
|
|
7705
|
+
if (absent.length && e.status !== "promoted" && e.status !== "declined") problems.push(`${e.id}: local ${absent.join(", ")} doesn't exist`);
|
|
7706
|
+
if (present.length && e.status === "promoted") {
|
|
7707
|
+
warnings.push(`${e.id}: Genesis ships it now; delete ${present.join(", ")} and use ${e.package ?? e.feature ?? "the Genesis version"}`);
|
|
7708
|
+
}
|
|
7709
|
+
}
|
|
7710
|
+
return { entries, problems, warnings, file: found };
|
|
7711
|
+
}
|
|
7712
|
+
function exportIssueUrl(entry) {
|
|
7713
|
+
const kindOption = { gap: "gap (Genesis has nothing for it)", extension: "extension (a Genesis part is close but has no prop, variant or slot for it)", invention: "invention (the app built it; it may belong in Genesis)" }[entry.kind];
|
|
7714
|
+
const title = `[Gap: ${entry.kind}] ${entry.need}`;
|
|
7715
|
+
const params = new URLSearchParams({ template: "gap.yml", title: title.length > 120 ? `${title.slice(0, 117)}\u2026` : title, kind: kindOption, need: entry.need, register: entry.id });
|
|
7716
|
+
if (entry.feature) params.set("feature", entry.feature);
|
|
7717
|
+
if (entry.package) params.set("package", entry.package);
|
|
7718
|
+
return `${ISSUE_FORM}?${params.toString()}`;
|
|
7719
|
+
}
|
|
7720
|
+
var UPSTREAM_KINDS, UPSTREAM_STATUSES, REGISTER_PATH, REGISTER_PATHS, COLUMNS, ISSUE_FORM;
|
|
7721
|
+
var init_upstream = __esm({
|
|
7722
|
+
"src/upstream.ts"() {
|
|
7723
|
+
UPSTREAM_KINDS = ["gap", "extension", "invention"];
|
|
7724
|
+
UPSTREAM_STATUSES = ["candidate", "proposed", "promoted", "declined"];
|
|
7725
|
+
REGISTER_PATH = "docs/genesis-upstream.md";
|
|
7726
|
+
REGISTER_PATHS = [REGISTER_PATH, "genesis-upstream.md"];
|
|
7727
|
+
COLUMNS = ["id", "kind", "status", "feature", "package", "local", "need"];
|
|
7728
|
+
ISSUE_FORM = "https://github.com/marktiderman/genesis/issues/new";
|
|
7729
|
+
}
|
|
7730
|
+
});
|
|
7731
|
+
|
|
6985
7732
|
// src/studio/wire-route.ts
|
|
6986
7733
|
function routeTags(source) {
|
|
6987
7734
|
const tags = [];
|
|
@@ -7018,8 +7765,8 @@ function routeTags(source) {
|
|
|
7018
7765
|
}
|
|
7019
7766
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
7020
7767
|
const tags = routeTags(source);
|
|
7021
|
-
const
|
|
7022
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
7768
|
+
const relative14 = route.replace(/^\//, "");
|
|
7769
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative14.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
7023
7770
|
if (existing) {
|
|
7024
7771
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
7025
7772
|
}
|
|
@@ -7027,17 +7774,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
7027
7774
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
7028
7775
|
if (roots.length !== 1) {
|
|
7029
7776
|
return {
|
|
7030
|
-
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${
|
|
7777
|
+
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative14}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
7031
7778
|
};
|
|
7032
7779
|
}
|
|
7033
7780
|
const layout = roots[0];
|
|
7034
7781
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
7035
|
-
if (base && !
|
|
7782
|
+
if (base && !relative14.startsWith(`${base}/`)) {
|
|
7036
7783
|
return {
|
|
7037
7784
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
7038
7785
|
};
|
|
7039
7786
|
}
|
|
7040
|
-
const childPath = base ?
|
|
7787
|
+
const childPath = base ? relative14.slice(base.length + 1) : relative14;
|
|
7041
7788
|
const guard = GUARD.exec(source)?.[1];
|
|
7042
7789
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
7043
7790
|
const before = source.slice(0, layout.close);
|
|
@@ -7437,9 +8184,9 @@ function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
|
7437
8184
|
return `${key2} doesn't match its source ${source}`;
|
|
7438
8185
|
}
|
|
7439
8186
|
function mergeThreeWay(mine, base, theirs) {
|
|
7440
|
-
const dir = mkdtempSync(
|
|
8187
|
+
const dir = mkdtempSync(path28.join(tmpdir(), "genesis-merge-"));
|
|
7441
8188
|
try {
|
|
7442
|
-
const [m, b, t] = ["mine", "base", "theirs"].map((n) =>
|
|
8189
|
+
const [m, b, t] = ["mine", "base", "theirs"].map((n) => path28.join(dir, n));
|
|
7443
8190
|
writeFileSync(m, mine);
|
|
7444
8191
|
writeFileSync(b, base);
|
|
7445
8192
|
writeFileSync(t, theirs);
|
|
@@ -7521,8 +8268,6 @@ var init_owned = __esm({
|
|
|
7521
8268
|
CLI = "@marktiderman/genesis-cli";
|
|
7522
8269
|
}
|
|
7523
8270
|
});
|
|
7524
|
-
|
|
7525
|
-
// src/blocks/registry-edit.ts
|
|
7526
8271
|
function literal(value, indent) {
|
|
7527
8272
|
if (Array.isArray(value)) return `[${value.map((v) => literal(v, indent)).join(", ")}]`;
|
|
7528
8273
|
if (value && typeof value === "object") {
|
|
@@ -7534,14 +8279,28 @@ ${indent}}`;
|
|
|
7534
8279
|
}
|
|
7535
8280
|
return JSON.stringify(value);
|
|
7536
8281
|
}
|
|
7537
|
-
function
|
|
8282
|
+
function featureKindField(root) {
|
|
8283
|
+
for (let dir = path28.resolve(root); ; dir = path28.dirname(dir)) {
|
|
8284
|
+
for (const file of [path28.join(dir, "node_modules/@marktiderman/genesis-features/package.json"), path28.join(dir, "packages/features/package.json")]) {
|
|
8285
|
+
try {
|
|
8286
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
8287
|
+
if (pkg.name !== "@marktiderman/genesis-features" || !pkg.version) continue;
|
|
8288
|
+
const [major = 0, minor = 0] = pkg.version.split(".").map(Number);
|
|
8289
|
+
return major > 0 || minor >= 8 ? "kind" : "layer";
|
|
8290
|
+
} catch {
|
|
8291
|
+
}
|
|
8292
|
+
}
|
|
8293
|
+
if (path28.dirname(dir) === dir) return "layer";
|
|
8294
|
+
}
|
|
8295
|
+
}
|
|
8296
|
+
function featureSnippet(manifest, owner, kindField = "kind") {
|
|
7538
8297
|
const apps = manifest.platforms?.length ? manifest.platforms : ["web", "native"];
|
|
7539
8298
|
const entry = {
|
|
7540
8299
|
name: manifest.feature?.name ?? manifest.id,
|
|
7541
8300
|
summary: manifest.feature?.summary ?? `The ${manifest.id} block from ${manifest.package}.`,
|
|
7542
8301
|
// Just added: the app hasn't shipped it yet. Move it on when it has.
|
|
7543
8302
|
status: "building",
|
|
7544
|
-
|
|
8303
|
+
[kindField]: manifest.feature?.kind ?? "block",
|
|
7545
8304
|
...manifest.feature?.keywords?.length ? { keywords: manifest.feature.keywords } : {},
|
|
7546
8305
|
...manifest.requires.length ? { requires: manifest.requires } : {},
|
|
7547
8306
|
owner,
|
|
@@ -7609,12 +8368,12 @@ var init_registry_edit = __esm({
|
|
|
7609
8368
|
});
|
|
7610
8369
|
function routerRoot2(root) {
|
|
7611
8370
|
try {
|
|
7612
|
-
const config = JSON.parse(readFileSync(
|
|
8371
|
+
const config = JSON.parse(readFileSync(path28.join(root, "genesis.config.json"), "utf8"));
|
|
7613
8372
|
const configured = config.doctor?.native?.routerRoot;
|
|
7614
|
-
if (configured && existsSync(
|
|
8373
|
+
if (configured && existsSync(path28.join(root, configured, "_layout.tsx"))) return configured.replace(/\/+$/, "");
|
|
7615
8374
|
} catch {
|
|
7616
8375
|
}
|
|
7617
|
-
for (const dir of ["src/app", "app"]) if (existsSync(
|
|
8376
|
+
for (const dir of ["src/app", "app"]) if (existsSync(path28.join(root, dir, "_layout.tsx"))) return dir;
|
|
7618
8377
|
return null;
|
|
7619
8378
|
}
|
|
7620
8379
|
function routeOf(file) {
|
|
@@ -7668,6 +8427,7 @@ var add_exports = {};
|
|
|
7668
8427
|
__export(add_exports, {
|
|
7669
8428
|
agentsFragment: () => agentsFragment,
|
|
7670
8429
|
ownedWrites: () => ownedWrites,
|
|
8430
|
+
pinGenesisImports: () => pinGenesisImports,
|
|
7671
8431
|
recordOwned: () => recordOwned,
|
|
7672
8432
|
registryFile: () => registryFile,
|
|
7673
8433
|
runAdd: () => runAdd,
|
|
@@ -7675,7 +8435,7 @@ __export(add_exports, {
|
|
|
7675
8435
|
});
|
|
7676
8436
|
function appDependencies(root) {
|
|
7677
8437
|
try {
|
|
7678
|
-
const pkg = JSON.parse(readFileSync(
|
|
8438
|
+
const pkg = JSON.parse(readFileSync(path28.join(root, "package.json"), "utf8"));
|
|
7679
8439
|
return { ...pkg["dependencies"], ...pkg["devDependencies"], ...pkg["optionalDependencies"] };
|
|
7680
8440
|
} catch {
|
|
7681
8441
|
return {};
|
|
@@ -7684,14 +8444,14 @@ function appDependencies(root) {
|
|
|
7684
8444
|
function registryFile(root) {
|
|
7685
8445
|
const read2 = (file, key2) => {
|
|
7686
8446
|
try {
|
|
7687
|
-
const v = JSON.parse(readFileSync(
|
|
8447
|
+
const v = JSON.parse(readFileSync(path28.join(root, file), "utf8"))[key2]?.registry;
|
|
7688
8448
|
return typeof v === "string" ? v : void 0;
|
|
7689
8449
|
} catch {
|
|
7690
8450
|
return void 0;
|
|
7691
8451
|
}
|
|
7692
8452
|
};
|
|
7693
8453
|
const named = read2("genesis.config.json", "features") ?? read2("package.json", "genesisFeatures");
|
|
7694
|
-
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(
|
|
8454
|
+
for (const candidate of named ? [named] : ["src/features.ts", "features.ts"]) if (existsSync(path28.join(root, candidate))) return candidate;
|
|
7695
8455
|
return null;
|
|
7696
8456
|
}
|
|
7697
8457
|
async function registryIds(root, file) {
|
|
@@ -7713,6 +8473,17 @@ function sourceMigrations(root, manifest) {
|
|
|
7713
8473
|
};
|
|
7714
8474
|
});
|
|
7715
8475
|
}
|
|
8476
|
+
function pinGenesisImports(root, text) {
|
|
8477
|
+
const versions = /* @__PURE__ */ new Map();
|
|
8478
|
+
return text.replace(NPM_GENESIS_IMPORT, (whole, name) => {
|
|
8479
|
+
if (!versions.has(name)) {
|
|
8480
|
+
const dir = packageDir(root, name);
|
|
8481
|
+
versions.set(name, dir ? packageVersion(dir) : void 0);
|
|
8482
|
+
}
|
|
8483
|
+
const version = versions.get(name);
|
|
8484
|
+
return version ? `npm:${name}@^${version}` : whole;
|
|
8485
|
+
});
|
|
8486
|
+
}
|
|
7716
8487
|
function ownedWrites(root, manifest, warnings) {
|
|
7717
8488
|
const out = [];
|
|
7718
8489
|
for (const fn of manifest.functions) {
|
|
@@ -7726,7 +8497,7 @@ function ownedWrites(root, manifest, warnings) {
|
|
|
7726
8497
|
continue;
|
|
7727
8498
|
}
|
|
7728
8499
|
const version = packageVersion(dir);
|
|
7729
|
-
for (const f of files) out.push({ path: `supabase/functions/${name}/${f.name}`, source: `${fn.package}:${fn.dir}/${f.name}`, content: f.content, ...version ? { version } : {} });
|
|
8500
|
+
for (const f of files) out.push({ path: `supabase/functions/${name}/${f.name}`, source: `${fn.package}:${fn.dir}/${f.name}`, content: pinGenesisImports(root, f.content), ...version ? { version } : {} });
|
|
7730
8501
|
}
|
|
7731
8502
|
for (const skill of manifest.skills) {
|
|
7732
8503
|
const dir = packageDir(root, skill.package);
|
|
@@ -7768,7 +8539,7 @@ verify_jwt = false
|
|
|
7768
8539
|
return { content: `${config.replace(/\s*$/, "\n")}${add}`, names };
|
|
7769
8540
|
}
|
|
7770
8541
|
async function runAdd(options) {
|
|
7771
|
-
const root =
|
|
8542
|
+
const root = path28.resolve(options.root);
|
|
7772
8543
|
const log = options.log ?? SILENT;
|
|
7773
8544
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
7774
8545
|
const warnings = [];
|
|
@@ -7802,7 +8573,7 @@ async function runAdd(options) {
|
|
|
7802
8573
|
const edited = [];
|
|
7803
8574
|
const makePlan = (manifest2, from) => {
|
|
7804
8575
|
const planWarnings = [];
|
|
7805
|
-
const migrations2 = planMigrations(root, sourceMigrations(root, manifest2), { now });
|
|
8576
|
+
const migrations2 = planMigrations(root, sourceMigrations(root, manifest2), { now, ...lock.migrations ? { copied: lock.migrations } : {} });
|
|
7806
8577
|
const owned2 = ownedWrites(root, manifest2, planWarnings).map((w) => ({ ...w, content: substitute(w.content, lock.substitutions) }));
|
|
7807
8578
|
const fragment2 = agentsFragment(root, manifest2);
|
|
7808
8579
|
if (manifest2.agents && !fragment2) planWarnings.push(`${manifest2.agents.package} ${manifest2.agents.path}: can't read it; AGENTS.md wasn't changed.`);
|
|
@@ -7812,7 +8583,7 @@ async function runAdd(options) {
|
|
|
7812
8583
|
let registryEdit2 = null;
|
|
7813
8584
|
if (!ids?.has(manifest2.id)) {
|
|
7814
8585
|
const owner = JSON.parse(readApp(root, "package.json") ?? "{}").name ?? "app";
|
|
7815
|
-
snippet2 = featureSnippet(manifest2, owner);
|
|
8586
|
+
snippet2 = featureSnippet(manifest2, owner, featureKindField(root));
|
|
7816
8587
|
if (registry) registryEdit2 = addFeatureEntry(readApp(root, registry) ?? "", snippet2);
|
|
7817
8588
|
}
|
|
7818
8589
|
const print = (mark, p, note = "") => log.info(` ${mark} ${p}${note ? ` ${note}` : ""}`);
|
|
@@ -7866,6 +8637,7 @@ ${snippet}`);
|
|
|
7866
8637
|
if (options.dryRun) return { block: manifest, install: command, migrations, created, kept, edited, steps, ...snippet ? { featureSnippet: snippet } : {}, warnings };
|
|
7867
8638
|
created.push(...applyMigrationPlan(root, migrations));
|
|
7868
8639
|
for (const c of migrations.creates) if (c.kind === "test" && c.source) recordOwned(lock, c.path, `${c.source.package}:${c.source.file}`, c.content, root, c.source.package);
|
|
8640
|
+
rememberMigrationCopies(lock, migrations);
|
|
7869
8641
|
for (const w of owned) {
|
|
7870
8642
|
const outcome = copyOwned(root, lock, w);
|
|
7871
8643
|
if (outcome === "created") created.push(w.path);
|
|
@@ -7920,7 +8692,7 @@ function recordOwned(lock, appRel, source, content, root, pkg) {
|
|
|
7920
8692
|
const version = dir ? packageVersion(dir) : void 0;
|
|
7921
8693
|
lock.files[appRel] = { source, sha256: sha256(content), ...version ? { version } : {} };
|
|
7922
8694
|
}
|
|
7923
|
-
var SILENT;
|
|
8695
|
+
var SILENT, NPM_GENESIS_IMPORT;
|
|
7924
8696
|
var init_add = __esm({
|
|
7925
8697
|
"src/blocks/add.ts"() {
|
|
7926
8698
|
init_local();
|
|
@@ -7936,6 +8708,103 @@ var init_add = __esm({
|
|
|
7936
8708
|
SILENT = { info() {
|
|
7937
8709
|
}, warn() {
|
|
7938
8710
|
} };
|
|
8711
|
+
NPM_GENESIS_IMPORT = /\bnpm:(@marktiderman\/genesis-[a-z0-9-]+)@([^/"'`\s]+)/g;
|
|
8712
|
+
}
|
|
8713
|
+
});
|
|
8714
|
+
function sorted(value) {
|
|
8715
|
+
if (Array.isArray(value)) return value.map(sorted);
|
|
8716
|
+
if (value && typeof value === "object") {
|
|
8717
|
+
return Object.fromEntries(
|
|
8718
|
+
Object.keys(value).sort().map((k) => [k, sorted(value[k])])
|
|
8719
|
+
);
|
|
8720
|
+
}
|
|
8721
|
+
return value;
|
|
8722
|
+
}
|
|
8723
|
+
function payload(rows) {
|
|
8724
|
+
const ordered = [...rows].sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(sorted);
|
|
8725
|
+
return JSON.stringify(ordered, null, 2).replace(/['<>\u2028\u2029\0]/g, (c) => UNSAFE[c]);
|
|
8726
|
+
}
|
|
8727
|
+
function notificationTypesSql(rows, registryFile2) {
|
|
8728
|
+
return [
|
|
8729
|
+
`-- genesis-notification-types: ${registryFile2.replace(/[\r\n]+/g, " ")}`,
|
|
8730
|
+
"-- Written by `genesis migrate` from the app's defineNotifications registry, so the types are in place",
|
|
8731
|
+
"-- once the migrations have run, before any deploy-time sync. It adds and updates types and never",
|
|
8732
|
+
"-- retires one (syncNotificationTypes on deploy does). Don't edit it: change the registry and run genesis migrate.",
|
|
8733
|
+
"insert into public.notification_types as t (key, category, channels, critical, transactional, email_delay_seconds, secret_link, push_privacy, ios_category, retired_at, updated_at)",
|
|
8734
|
+
"select x.key, x.category, x.channels, coalesce(x.critical, false), coalesce(x.transactional, false), coalesce(x.email_delay_seconds, 0),",
|
|
8735
|
+
" coalesce(x.secret_link, false), coalesce(x.push_privacy, 'default'), x.ios_category, null, now()",
|
|
8736
|
+
`from jsonb_to_recordset('${payload(rows)}'::jsonb)`,
|
|
8737
|
+
" as x (key text, category text, channels jsonb, critical boolean, transactional boolean, email_delay_seconds integer, secret_link boolean, push_privacy text, ios_category text)",
|
|
8738
|
+
"on conflict (key) do update",
|
|
8739
|
+
" set category = excluded.category, channels = excluded.channels, critical = excluded.critical, transactional = excluded.transactional,",
|
|
8740
|
+
" email_delay_seconds = excluded.email_delay_seconds, secret_link = excluded.secret_link, push_privacy = excluded.push_privacy,",
|
|
8741
|
+
" ios_category = excluded.ios_category, retired_at = null, updated_at = now();",
|
|
8742
|
+
""
|
|
8743
|
+
].join("\n");
|
|
8744
|
+
}
|
|
8745
|
+
function configuredRegistry(root) {
|
|
8746
|
+
try {
|
|
8747
|
+
const raw = JSON.parse(readFileSync(path28.join(root, "genesis.config.json"), "utf8"));
|
|
8748
|
+
return typeof raw.notifications?.registry === "string" ? raw.notifications.registry : void 0;
|
|
8749
|
+
} catch {
|
|
8750
|
+
return void 0;
|
|
8751
|
+
}
|
|
8752
|
+
}
|
|
8753
|
+
async function planNotificationTypes(root, options) {
|
|
8754
|
+
const warnings = [];
|
|
8755
|
+
const file = options.registry ?? configuredRegistry(root);
|
|
8756
|
+
if (!file) {
|
|
8757
|
+
warnings.push(
|
|
8758
|
+
"Notification types: not checked. Name the defineNotifications registry (--notifications <file>, or notifications.registry in genesis.config.json) so genesis migrate mirrors its types at migration time."
|
|
8759
|
+
);
|
|
8760
|
+
return { warnings };
|
|
8761
|
+
}
|
|
8762
|
+
if (options.dryRun) {
|
|
8763
|
+
warnings.push(`Notification types: not checked on a dry run (loading ${file} runs app code).`);
|
|
8764
|
+
return { registry: file, warnings };
|
|
8765
|
+
}
|
|
8766
|
+
const absolute = path28.resolve(root, file);
|
|
8767
|
+
if (!existsSync(absolute)) {
|
|
8768
|
+
warnings.push(`Notification types: ${file} doesn't exist (a relative path is resolved against the app's root, ${root}).`);
|
|
8769
|
+
return { registry: file, warnings };
|
|
8770
|
+
}
|
|
8771
|
+
let mod;
|
|
8772
|
+
try {
|
|
8773
|
+
const jiti = createJiti(path28.join(root, "package.json"), { moduleCache: false });
|
|
8774
|
+
mod = await jiti.import(absolute);
|
|
8775
|
+
} catch (err) {
|
|
8776
|
+
warnings.push(`Notification types: couldn't load ${file} (${err instanceof Error ? err.message : String(err)}).`);
|
|
8777
|
+
return { registry: file, warnings };
|
|
8778
|
+
}
|
|
8779
|
+
const found = isRegistry(mod.notifications) ? mod.notifications : isRegistry(mod.default) ? mod.default : Object.values(mod).find(isRegistry);
|
|
8780
|
+
if (!found) {
|
|
8781
|
+
warnings.push(`Notification types: ${file} exports no defineNotifications registry (export it as \`notifications\`).`);
|
|
8782
|
+
return { registry: file, warnings };
|
|
8783
|
+
}
|
|
8784
|
+
const shown = path28.isAbsolute(file) ? path28.relative(root, absolute) : file;
|
|
8785
|
+
const content = notificationTypesSql(found.toTypeRows(), shown.split(path28.sep).join("/"));
|
|
8786
|
+
const app = readAppMigrations(root);
|
|
8787
|
+
const latest = app.filter((m) => m.name.endsWith(`_${TYPES_STEM}.sql`)).sort((a, b) => a.name < b.name ? -1 : 1).pop();
|
|
8788
|
+
if (latest && payloadOf(latest.content) === payloadOf(content)) return { registry: file, warnings };
|
|
8789
|
+
let stamp;
|
|
8790
|
+
try {
|
|
8791
|
+
[stamp] = nextTimestamps([...app.map((m) => m.name), ...options.pending ?? []], options.now, 1);
|
|
8792
|
+
} catch (err) {
|
|
8793
|
+
warnings.push(`Notification types: no migration written (${err instanceof Error ? err.message : String(err)}).`);
|
|
8794
|
+
return { registry: file, warnings };
|
|
8795
|
+
}
|
|
8796
|
+
return { registry: file, create: { path: `${MIGRATIONS_DIR}/${stamp}_${TYPES_STEM}.sql`, content }, warnings };
|
|
8797
|
+
}
|
|
8798
|
+
var NOTIFICATIONS_PACKAGE, TYPES_STEM, isRegistry, UNSAFE, PAYLOAD, payloadOf;
|
|
8799
|
+
var init_notification_types = __esm({
|
|
8800
|
+
"src/blocks/notification-types.ts"() {
|
|
8801
|
+
init_migrations();
|
|
8802
|
+
NOTIFICATIONS_PACKAGE = "@marktiderman/genesis-notifications";
|
|
8803
|
+
TYPES_STEM = "genesis_notification_types";
|
|
8804
|
+
isRegistry = (v) => !!v && typeof v === "object" && typeof v.toTypeRows === "function";
|
|
8805
|
+
UNSAFE = { "'": "\\u0027", "<": "\\u003C", ">": "\\u003E", "\u2028": "\\u2028", "\u2029": "\\u2029", "\0": "\\u0000" };
|
|
8806
|
+
PAYLOAD = /from jsonb_to_recordset\('([^']*)'::jsonb\)/;
|
|
8807
|
+
payloadOf = (sql) => PAYLOAD.exec(sql.replace(/\r\n/g, "\n"))?.[1] ?? null;
|
|
7939
8808
|
}
|
|
7940
8809
|
});
|
|
7941
8810
|
|
|
@@ -7945,7 +8814,7 @@ __export(migrate_exports, {
|
|
|
7945
8814
|
runMigrate: () => runMigrate
|
|
7946
8815
|
});
|
|
7947
8816
|
async function runMigrate(options) {
|
|
7948
|
-
const root =
|
|
8817
|
+
const root = path28.resolve(options.root);
|
|
7949
8818
|
const lock = readLock(root);
|
|
7950
8819
|
const warnings = [];
|
|
7951
8820
|
const ids = [.../* @__PURE__ */ new Set([...Object.keys(lock.blocks), ...options.blocks ?? []])];
|
|
@@ -7977,13 +8846,27 @@ async function runMigrate(options) {
|
|
|
7977
8846
|
sources.push({ package: t.package, file: t.file, source });
|
|
7978
8847
|
}
|
|
7979
8848
|
if (!ids.length && !sources.length) warnings.push("No blocks in genesis.lock.json and no copied package migrations: nothing to compare. Add a block (genesis add <block>), or pass --block.");
|
|
7980
|
-
const plan = planMigrations(root, sources, { now: options.now ?? /* @__PURE__ */ new Date(), ...options.forward ? { forward: true } : {} });
|
|
8849
|
+
const plan = planMigrations(root, sources, { now: options.now ?? /* @__PURE__ */ new Date(), ...options.forward ? { forward: true } : {}, ...lock.migrations ? { copied: lock.migrations } : {} });
|
|
7981
8850
|
const attention = plan.rows.some(needsAttention);
|
|
7982
|
-
|
|
8851
|
+
const notifies = ids.some((id) => (lock.blocks[id]?.package ?? (id === "notifications" ? NOTIFICATIONS_PACKAGE : "")) === NOTIFICATIONS_PACKAGE);
|
|
8852
|
+
const types = notifies ? await planNotificationTypes(root, {
|
|
8853
|
+
...options.notifications ? { registry: options.notifications } : {},
|
|
8854
|
+
now: options.now ?? /* @__PURE__ */ new Date(),
|
|
8855
|
+
pending: plan.creates.filter((c) => c.kind !== "test").map((c) => c.path.split("/").pop()),
|
|
8856
|
+
...options.dryRun ? { dryRun: true } : {}
|
|
8857
|
+
}) : void 0;
|
|
8858
|
+
warnings.push(...types?.warnings ?? []);
|
|
8859
|
+
const notificationTypes = types?.create ? { notificationTypes: types.create.path } : {};
|
|
8860
|
+
if (options.dryRun) return { plan, written: [], warnings, attention, ...notificationTypes };
|
|
7983
8861
|
const written = applyMigrationPlan(root, plan);
|
|
8862
|
+
if (types?.create) {
|
|
8863
|
+
createApp(root, types.create.path, types.create.content);
|
|
8864
|
+
written.push(types.create.path);
|
|
8865
|
+
}
|
|
7984
8866
|
for (const c of plan.creates) if (c.kind === "test" && c.source) recordOwned(lock, c.path, `${c.source.package}:${c.source.file}`, c.content, root, c.source.package);
|
|
7985
|
-
|
|
7986
|
-
|
|
8867
|
+
const remembered = rememberMigrationCopies(lock, plan);
|
|
8868
|
+
if (remembered || plan.creates.some((c) => c.kind === "test")) writeLock(root, lock);
|
|
8869
|
+
return { plan, written, warnings, attention, ...notificationTypes };
|
|
7987
8870
|
}
|
|
7988
8871
|
var init_migrate = __esm({
|
|
7989
8872
|
"src/blocks/migrate.ts"() {
|
|
@@ -7994,6 +8877,8 @@ var init_migrate = __esm({
|
|
|
7994
8877
|
init_manifest();
|
|
7995
8878
|
init_migrations();
|
|
7996
8879
|
init_add();
|
|
8880
|
+
init_files();
|
|
8881
|
+
init_notification_types();
|
|
7997
8882
|
}
|
|
7998
8883
|
});
|
|
7999
8884
|
|
|
@@ -8013,11 +8898,11 @@ function npmLookup(cwd) {
|
|
|
8013
8898
|
if (!EXACT_OR_TAG.test(target)) throw new Error(`--version must be an exact version or a dist-tag, not "${target}"`);
|
|
8014
8899
|
const version = JSON.parse(npm(["view", `${UMBRELLA}@${target}`, "version", "--json"], cwd) || "null");
|
|
8015
8900
|
if (typeof version !== "string") throw new Error(`${UMBRELLA}@${target} is not one published version`);
|
|
8016
|
-
const tmp = mkdtempSync(
|
|
8901
|
+
const tmp = mkdtempSync(path28.join(tmpdir(), "genesis-umbrella-"));
|
|
8017
8902
|
try {
|
|
8018
8903
|
const [packed] = JSON.parse(npm(["pack", `${UMBRELLA}@${version}`, "--pack-destination", tmp, "--json"], cwd));
|
|
8019
|
-
execFileSync("tar", ["-xzf",
|
|
8020
|
-
const manifest = JSON.parse(readFileSync(
|
|
8904
|
+
execFileSync("tar", ["-xzf", path28.join(tmp, packed.filename), "-C", tmp, "package/dist/versions.json"]);
|
|
8905
|
+
const manifest = JSON.parse(readFileSync(path28.join(tmp, "package/dist/versions.json"), "utf8"));
|
|
8021
8906
|
if (manifest.version !== version) throw new Error(`${UMBRELLA}@${version} ships a versions.json for ${manifest.version}`);
|
|
8022
8907
|
return manifest;
|
|
8023
8908
|
} finally {
|
|
@@ -8044,7 +8929,7 @@ function packageJsons(root) {
|
|
|
8044
8929
|
if (files.length) return files;
|
|
8045
8930
|
} catch {
|
|
8046
8931
|
}
|
|
8047
|
-
return existsSync(
|
|
8932
|
+
return existsSync(path28.join(root, "package.json")) ? ["package.json"] : [];
|
|
8048
8933
|
}
|
|
8049
8934
|
function sourceText(root, source, substitutions) {
|
|
8050
8935
|
const { package: pkg, path: rel } = parseSource(source);
|
|
@@ -8057,17 +8942,18 @@ function sourceText(root, source, substitutions) {
|
|
|
8057
8942
|
return text2 === null ? null : substitute(text2, substitutions);
|
|
8058
8943
|
}
|
|
8059
8944
|
const text = readPackageFile(dir, rel);
|
|
8060
|
-
|
|
8945
|
+
if (text === null) return null;
|
|
8946
|
+
return substitute(rel.startsWith("functions/") ? pinGenesisImports(root, text) : text, substitutions);
|
|
8061
8947
|
} catch {
|
|
8062
8948
|
return null;
|
|
8063
8949
|
}
|
|
8064
8950
|
}
|
|
8065
8951
|
async function runUpgrade(options) {
|
|
8066
|
-
const root =
|
|
8952
|
+
const root = path28.resolve(options.root);
|
|
8067
8953
|
const log = options.log ?? (() => {
|
|
8068
8954
|
});
|
|
8069
8955
|
const lookup = options.lookup ?? npmLookup(root);
|
|
8070
|
-
const release = options.manifest ? JSON.parse(readFileSync(
|
|
8956
|
+
const release = options.manifest ? JSON.parse(readFileSync(path28.resolve(options.manifest), "utf8")) : lookup.release(options.version ?? "latest");
|
|
8071
8957
|
const pinned = { [UMBRELLA]: release.version, ...release.packages };
|
|
8072
8958
|
const wanted = (name) => pinned[name] ?? lookup.latest(name);
|
|
8073
8959
|
const prBase = options.pr && !options.dryRun ? checkPullRequest(root, release.version) : void 0;
|
|
@@ -8123,7 +9009,7 @@ async function runUpgrade(options) {
|
|
|
8123
9009
|
try {
|
|
8124
9010
|
const { manifest } = await findBlock(root, id, { package: entry.package, warnings });
|
|
8125
9011
|
manifests.push(manifest);
|
|
8126
|
-
for (const row of planMigrations(root, sourceMigrations(root, manifest), { now: /* @__PURE__ */ new Date(), tests: false }).rows) {
|
|
9012
|
+
for (const row of planMigrations(root, sourceMigrations(root, manifest), { now: /* @__PURE__ */ new Date(), tests: false, ...lock.migrations ? { copied: lock.migrations } : {} }).rows) {
|
|
8127
9013
|
if (row.state === "new") newMigrations.push(`${row.package} ${row.file}`);
|
|
8128
9014
|
}
|
|
8129
9015
|
if (manifest.version && manifest.version !== entry.version) lock.blocks[id] = { ...entry, version: manifest.version };
|
|
@@ -8203,7 +9089,7 @@ function checkSubstitutions(substitutions) {
|
|
|
8203
9089
|
if (!substitutions || !Object.keys(substitutions).length) return;
|
|
8204
9090
|
let allowed;
|
|
8205
9091
|
try {
|
|
8206
|
-
const was = starterIdentity(readFileSync(
|
|
9092
|
+
const was = starterIdentity(readFileSync(path28.join(starterDir(), "starter.config.ts"), "utf8"));
|
|
8207
9093
|
allowed = [was.name, was.slug, was.scheme, was.bundleId];
|
|
8208
9094
|
} catch {
|
|
8209
9095
|
allowed = [];
|
|
@@ -8236,15 +9122,15 @@ function openPullRequest(root, version, report, base) {
|
|
|
8236
9122
|
git4("switch", "-c", branch);
|
|
8237
9123
|
const top = git4("rev-parse", "--show-toplevel");
|
|
8238
9124
|
const lockfiles = [];
|
|
8239
|
-
for (let dir =
|
|
8240
|
-
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(
|
|
8241
|
-
if (lockfiles.length || dir === top ||
|
|
9125
|
+
for (let dir = path28.resolve(root); ; dir = path28.dirname(dir)) {
|
|
9126
|
+
for (const f of ["pnpm-lock.yaml", "bun.lock", "bun.lockb", "package-lock.json", "yarn.lock"]) if (existsSync(path28.join(dir, f))) lockfiles.push(path28.relative(root, path28.join(dir, f)));
|
|
9127
|
+
if (lockfiles.length || dir === top || path28.dirname(dir) === dir) break;
|
|
8242
9128
|
}
|
|
8243
|
-
const paths = [...report.files.filter((f) => existsSync(
|
|
9129
|
+
const paths = [...report.files.filter((f) => existsSync(path28.join(root, f))), ...lockfiles];
|
|
8244
9130
|
git4("add", "--", ...paths);
|
|
8245
9131
|
git4("commit", "-q", "-m", `chore(deps): upgrade Genesis to ${version}`);
|
|
8246
9132
|
git4("push", "-u", "origin", branch);
|
|
8247
|
-
const body =
|
|
9133
|
+
const body = path28.join(mkdtempSync(path28.join(tmpdir(), "genesis-pr-")), "body.md");
|
|
8248
9134
|
writeFileSync(body, `${report.summary}
|
|
8249
9135
|
|
|
8250
9136
|
Opened by \`genesis upgrade --pr\`.
|
|
@@ -8368,9 +9254,9 @@ async function runScaffold(opts, fs2) {
|
|
|
8368
9254
|
function joinPath(...parts) {
|
|
8369
9255
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
8370
9256
|
}
|
|
8371
|
-
function dirname(
|
|
8372
|
-
const idx =
|
|
8373
|
-
return idx === -1 ? "." :
|
|
9257
|
+
function dirname(path48) {
|
|
9258
|
+
const idx = path48.lastIndexOf("/");
|
|
9259
|
+
return idx === -1 ? "." : path48.slice(0, idx);
|
|
8374
9260
|
}
|
|
8375
9261
|
function brandPackageJson(consumer, genesisVersion) {
|
|
8376
9262
|
return JSON.stringify(
|
|
@@ -8609,7 +9495,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
8609
9495
|
const { runInitNative: runInitNative2 } = await Promise.resolve().then(() => (init_init_native(), init_native_exports));
|
|
8610
9496
|
const result2 = await runInitNative2({
|
|
8611
9497
|
name: consumer,
|
|
8612
|
-
target:
|
|
9498
|
+
target: path28.resolve(opts.target ?? consumer),
|
|
8613
9499
|
...opts.displayName ? { displayName: opts.displayName } : {},
|
|
8614
9500
|
...opts.bundleId ? { bundleId: opts.bundleId } : {},
|
|
8615
9501
|
...opts.scheme ? { scheme: opts.scheme } : {}
|
|
@@ -8619,7 +9505,7 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
8619
9505
|
console.log(` Genesis packages: ${Object.entries(result2.dependencies).map(([n, v]) => `${n}@${v}`).join(", ")}`);
|
|
8620
9506
|
console.log("");
|
|
8621
9507
|
console.log("Next steps:");
|
|
8622
|
-
[`cd ${
|
|
9508
|
+
[`cd ${path28.relative(process.cwd(), result2.target) || "."} && pnpm install (or your package manager)`, ...result2.steps].forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
8623
9509
|
return;
|
|
8624
9510
|
}
|
|
8625
9511
|
opts.target ??= process.cwd();
|
|
@@ -8655,9 +9541,14 @@ program.command("init").description("Scaffold a new Genesis consumer (brand pack
|
|
|
8655
9541
|
console.log(` 2. Install dependencies with your package manager`);
|
|
8656
9542
|
console.log(` 3. Run genesis doctor, and read https://github.com/marktiderman/genesis/blob/main/docs/FRAMEWORK.md`);
|
|
8657
9543
|
});
|
|
8658
|
-
program.command("introspect").description("Write a checked-in contract (resources.genesis.ts) from the Postgres catalog or a PostgREST/Supabase OpenAPI spec").option("--database-env <name>", "Environment variable holding the Postgres URL
|
|
8659
|
-
const schemas = opts.schema.split(",").map((s) => s.trim()).filter(Boolean);
|
|
9544
|
+
program.command("introspect").description("Write a checked-in contract (resources.genesis.ts) from the Postgres catalog or a PostgREST/Supabase OpenAPI spec").option("--database-env <name>", "Environment variable holding the Postgres URL (default: doctor.contracts.databaseEnv, else DATABASE_URL)").option("--openapi <file-or-url>", "Read a PostgREST OpenAPI document (a Supabase project's /rest/v1/) instead of Postgres").option("--header <header...>", "HTTP header for --openapi URLs, for values that aren't secret (repeatable)").option("--apikey-env <name>", "Environment variable holding the API key for --openapi URLs (sent as apikey and Bearer)").option("-s, --schema <schemas>", "Comma-separated schemas (default: doctor.contracts.schemas, else public)").option("-o, --out <file>", "Where to write the contract (default: doctor.contracts.out in genesis.config.json, else resources.genesis.ts)").option("--config <path>", "Config file to read doctor.contracts from (default: genesis.config.json or package.json)").option("--check", "Write nothing; exit 1 if the contract on disk is out of date (for CI)", false).action(async (opts) => {
|
|
8660
9545
|
const { introspectOpenApi: introspectOpenApi2, introspectPostgres: introspectPostgres2, emitContracts: emitContracts2 } = await Promise.resolve().then(() => (init_introspect(), introspect_exports));
|
|
9546
|
+
const { introspectSettings: introspectSettings2 } = await Promise.resolve().then(() => (init_settings(), settings_exports));
|
|
9547
|
+
const { loadConfig: loadConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
9548
|
+
const cwd = process.cwd();
|
|
9549
|
+
const loaded = loadConfig2(cwd, opts.config);
|
|
9550
|
+
const settings2 = introspectSettings2(opts, cwd, loaded.config.contracts, (file) => existsSync(file) ? readFileSync(file, "utf-8") : null);
|
|
9551
|
+
const { schemas, target, label } = settings2;
|
|
8661
9552
|
let tables;
|
|
8662
9553
|
let source;
|
|
8663
9554
|
if (opts.openapi) {
|
|
@@ -8669,38 +9560,37 @@ program.command("introspect").description("Write a checked-in contract (resource
|
|
|
8669
9560
|
headers.push(`apikey: ${key2}`, `Authorization: Bearer ${key2}`);
|
|
8670
9561
|
}
|
|
8671
9562
|
const doc = await readOpenApi(opts.openapi, headers);
|
|
8672
|
-
tables = introspectOpenApi2(doc, schemas[0]);
|
|
9563
|
+
tables = introspectOpenApi2(doc, schemas[0], { warn: (m) => logger.warn(m) });
|
|
8673
9564
|
source = `OpenAPI ${redactUrl(opts.openapi)}`;
|
|
8674
9565
|
} else {
|
|
8675
|
-
const url = process.env[
|
|
8676
|
-
if (!url) throw new Error(`Set ${
|
|
9566
|
+
const url = process.env[settings2.databaseEnv];
|
|
9567
|
+
if (!url) throw new Error(`Set ${settings2.databaseEnv} to the database URL, or pass --openapi.`);
|
|
8677
9568
|
const { default: postgres } = await import('postgres');
|
|
8678
9569
|
const sql = postgres(url, { max: 1, prepare: false, onnotice: () => {
|
|
8679
9570
|
} });
|
|
8680
9571
|
try {
|
|
8681
|
-
tables = await introspectPostgres2(sql, schemas);
|
|
9572
|
+
tables = await introspectPostgres2(sql, schemas, { warn: (m) => logger.warn(m) });
|
|
8682
9573
|
} finally {
|
|
8683
9574
|
await sql.end();
|
|
8684
9575
|
}
|
|
8685
9576
|
source = (await Promise.resolve().then(() => (init_contracts(), contracts_exports))).postgresSource(schemas);
|
|
8686
9577
|
}
|
|
8687
9578
|
const content = emitContracts2(tables, { source });
|
|
8688
|
-
const target = path26.resolve(opts.out);
|
|
8689
9579
|
if (opts.check) {
|
|
8690
9580
|
const current = await fs.readFile(target, "utf-8").catch(() => null);
|
|
8691
9581
|
if (current?.replace(/\r\n/g, "\n") !== content) {
|
|
8692
|
-
console.error(`\u2717 ${
|
|
9582
|
+
console.error(`\u2717 ${label} is out of date. Run \`genesis introspect\` and commit the result.`);
|
|
8693
9583
|
process.exit(1);
|
|
8694
9584
|
}
|
|
8695
|
-
console.log(`\u2714 ${
|
|
9585
|
+
console.log(`\u2714 ${label} is up to date (${tables.length} tables).`);
|
|
8696
9586
|
return;
|
|
8697
9587
|
}
|
|
8698
9588
|
await fs.writeFile(target, content, "utf-8");
|
|
8699
|
-
console.log(`\u2714 Wrote ${
|
|
9589
|
+
console.log(`\u2714 Wrote ${label}: ${tables.length} tables.`);
|
|
8700
9590
|
});
|
|
8701
9591
|
program.command("doctor").description("Check this app against the installed Genesis: components, tokens, imports, colors, plus the app's own rules").option("--strict", "Fail on warnings too", false).option("--json", "Print the report as JSON", false).option("--build", "Also run the app's typecheck and build (doctor.build, or its typecheck/build scripts)", false).option("-c, --config <path>", 'Config file (default: genesis.config.json, then package.json "genesis")').option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--print-genesis", "Print the components, tokens and raw tags read from Genesis, and exit", false).option("--base <ref>", "The git ref change checks compare against (the packages pack's change gate, and the ratchet: newOnly rules report unchanged files as info), e.g. origin/main").action(async (opts) => {
|
|
8702
9592
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
8703
|
-
const root =
|
|
9593
|
+
const root = path28.resolve(opts.dir);
|
|
8704
9594
|
try {
|
|
8705
9595
|
if (opts.printGenesis) {
|
|
8706
9596
|
const { config } = doctor.loadConfig(root, opts.config);
|
|
@@ -8717,9 +9607,24 @@ program.command("doctor").description("Check this app against the installed Gene
|
|
|
8717
9607
|
process.exitCode = 2;
|
|
8718
9608
|
}
|
|
8719
9609
|
});
|
|
8720
|
-
program.command("
|
|
9610
|
+
program.command("catalog").description("Print the Genesis catalog: for each need, what to use, its import and docs, from every installed Genesis package's declarations").option("--json", "Print the catalog as JSON", false).option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
9611
|
+
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
9612
|
+
const packages = doctor.discoverPackages(path28.resolve(opts.dir));
|
|
9613
|
+
const rows = doctor.primitivesCatalog(packages);
|
|
9614
|
+
const broken = packages.filter((p) => p.error);
|
|
9615
|
+
if (opts.json) {
|
|
9616
|
+
console.log(JSON.stringify({ catalog: rows, ...doctor.primitivesSummary(packages), errors: broken.map((p) => p.error) }, null, 2));
|
|
9617
|
+
} else {
|
|
9618
|
+
console.log(doctor.formatPrimitives(rows));
|
|
9619
|
+
}
|
|
9620
|
+
for (const p of broken) console.error(`! ${p.error}`);
|
|
9621
|
+
for (const note of packages.flatMap((p) => p.ignored ?? [])) console.error(`! ${note}`);
|
|
9622
|
+
if (broken.length) process.exitCode = 1;
|
|
9623
|
+
});
|
|
9624
|
+
program.command("primitives").description("Deprecated name of `genesis catalog` (same output; JSON keeps the `primitives` key until the next major)").option("--json", "Print the catalog as JSON", false).option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
9625
|
+
console.error("! `genesis primitives` is now `genesis catalog`; the old name works until the next major.");
|
|
8721
9626
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
8722
|
-
const packages = doctor.discoverPackages(
|
|
9627
|
+
const packages = doctor.discoverPackages(path28.resolve(opts.dir));
|
|
8723
9628
|
const rows = doctor.primitivesCatalog(packages);
|
|
8724
9629
|
const broken = packages.filter((p) => p.error);
|
|
8725
9630
|
if (opts.json) {
|
|
@@ -8731,9 +9636,21 @@ program.command("primitives").description("Print the Genesis primitives catalog:
|
|
|
8731
9636
|
for (const note of packages.flatMap((p) => p.ignored ?? [])) console.error(`! ${note}`);
|
|
8732
9637
|
if (broken.length) process.exitCode = 1;
|
|
8733
9638
|
});
|
|
8734
|
-
program.command("agents").description(`Write the agent guide from the installed Genesis packages: .claude/skills/genesis/SKILL.md and a marked block in AGENTS.md`).option("--check", "Write nothing; exit 1 if either is missing or out of date (for CI)", false).option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
9639
|
+
program.command("agents").description(`Write the agent guide from the installed Genesis packages: .claude/skills/genesis/SKILL.md and a marked block in AGENTS.md`).option("--check", "Write nothing; exit 1 if either is missing or out of date (for CI)", false).option("--rules", "Check the repo against the agent rules of engagement a script can check (docs/agents/RULES.md); exit 1 on a break", false).option("--batch <pattern>", "With --rules: the branch pattern staging batches use in workflow filters", "staging/**").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
9640
|
+
const root = path28.resolve(opts.dir);
|
|
9641
|
+
if (opts.rules && opts.check) return program.error("--rules checks the repo, --check the agent guide: run them one at a time");
|
|
9642
|
+
if (opts.rules) {
|
|
9643
|
+
if (!existsSync(path28.join(root, "packages")) && !existsSync(path28.join(root, ".github", "workflows"))) {
|
|
9644
|
+
return program.error(`--rules checks a repository: ${root} has no packages/ or .github/workflows/. Run it from the repo root or pass --dir.`);
|
|
9645
|
+
}
|
|
9646
|
+
const { checkAgentRules: checkAgentRules2 } = await Promise.resolve().then(() => (init_agent_rules(), agent_rules_exports));
|
|
9647
|
+
const problems = checkAgentRules2(root, { batch: opts.batch });
|
|
9648
|
+
for (const p of problems) console.error(`\u2717 ${p.rule}: ${p.message}`);
|
|
9649
|
+
if (problems.length) process.exitCode = 1;
|
|
9650
|
+
else console.log("\u2714 The repo keeps the checkable rules of engagement (first-version, batch-ci).");
|
|
9651
|
+
return;
|
|
9652
|
+
}
|
|
8735
9653
|
const doctor = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
|
|
8736
|
-
const root = path26.resolve(opts.dir);
|
|
8737
9654
|
const packages = doctor.discoverPackages(root);
|
|
8738
9655
|
const broken = packages.filter((p) => p.error);
|
|
8739
9656
|
if (broken.length) {
|
|
@@ -8781,47 +9698,65 @@ featureOptions(features.command("check").description("Errors fail (stale output,
|
|
|
8781
9698
|
process.exitCode = result.ok ? 0 : 1;
|
|
8782
9699
|
});
|
|
8783
9700
|
featureOptions(
|
|
8784
|
-
features.command("find").description("Search features before building: reuse one, extend one, or add an idea first").argument("[term]", "What to look for (id, alias, name, keyword, summary, import, slot or code path)", "").option("--platform <platform>", "Only features on web, native, server or cli").option("--
|
|
9701
|
+
features.command("find").description("Search features before building: reuse one, extend one, or add an idea first").argument("[term]", "What to look for (id, alias, name, keyword, summary, import, slot or code path)", "").option("--platform <platform>", "Only features on web, native, server or cli").option("--kind <kind>", "Only token, element, pattern, layout, hook, provider, block, service or tool").option("--layer <layer>", "Only features whose package is foundation, module or tooling (a kind here is deprecated: use --kind)").option("--status <status>", "Only idea, planned, building, beta, live, deprecated or retired")
|
|
8785
9702
|
).action(async (term, opts) => {
|
|
8786
|
-
const {
|
|
8787
|
-
const {
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
status: pick("status", status, FEATURE_STATUSES)
|
|
8798
|
-
};
|
|
8799
|
-
if (!term && !filters.platform && !filters.layer && !filters.status) program.error("Give a term, or --platform, --layer or --status");
|
|
9703
|
+
const { findFilters: findFilters2, runFeaturesFind: runFeaturesFind2, formatFeature: formatFeature2 } = await Promise.resolve().then(() => (init_features(), features_exports));
|
|
9704
|
+
const { platform, kind, layer, status, ...rest } = opts;
|
|
9705
|
+
let filters;
|
|
9706
|
+
try {
|
|
9707
|
+
const parsed = findFilters2({ platform, kind, layer, status });
|
|
9708
|
+
if (parsed.warning) console.warn(`! ${parsed.warning}`);
|
|
9709
|
+
filters = parsed.filters;
|
|
9710
|
+
} catch (error) {
|
|
9711
|
+
return program.error(error.message);
|
|
9712
|
+
}
|
|
9713
|
+
if (!term && !filters.platform && !filters.kind && !filters.packageLayer && !filters.status) program.error("Give a term, or --platform, --kind, --layer or --status");
|
|
8800
9714
|
const hits = await runFeaturesFind2(rest, term, filters);
|
|
8801
9715
|
const what = term ? `"${term}"` : "those filters";
|
|
8802
9716
|
console.log(hits.length ? hits.map(formatFeature2).join("\n\n") : `No feature matches ${what}. If this is new work, add it to the registry first (an idea is enough).`);
|
|
8803
9717
|
});
|
|
9718
|
+
var upstream = program.command("upstream").description("The app's register of what it needed from Genesis (docs/genesis-upstream.md)");
|
|
9719
|
+
upstream.command("check").description("Check docs/genesis-upstream.md: kinds, statuses, local paths, and promoted entries whose local copy is still there").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (opts) => {
|
|
9720
|
+
const { checkUpstream: checkUpstream2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
9721
|
+
const result = checkUpstream2(path28.resolve(opts.dir));
|
|
9722
|
+
for (const w of result.warnings) console.warn(`! ${w}`);
|
|
9723
|
+
for (const p of result.problems) console.error(`\u2717 ${p}`);
|
|
9724
|
+
if (result.problems.length) process.exitCode = 1;
|
|
9725
|
+
else if (!result.missing) console.log(`\u2714 ${result.entries.length} register entr${result.entries.length === 1 ? "y" : "ies"} check out.`);
|
|
9726
|
+
});
|
|
9727
|
+
upstream.command("export").description("Print the link that files a register entry with Genesis through the gap form (sends nothing)").argument("<id>", "The entry's id").option("-d, --dir <dir>", "The app's folder", process.cwd()).action(async (id, opts) => {
|
|
9728
|
+
const { checkUpstream: checkUpstream2, exportIssueUrl: exportIssueUrl2 } = await Promise.resolve().then(() => (init_upstream(), upstream_exports));
|
|
9729
|
+
const register = checkUpstream2(path28.resolve(opts.dir));
|
|
9730
|
+
if (register.missing) return program.error("There is no docs/genesis-upstream.md or genesis-upstream.md here; add the register first (see genesis upstream check).");
|
|
9731
|
+
const entry = register.entries.find((e) => e.id === id);
|
|
9732
|
+
if (!entry) return program.error(`No register entry "${id}" in ${register.file}.`);
|
|
9733
|
+
const own = register.problems.filter((p) => p.startsWith(`${id}:`) || p.startsWith(`${id} `));
|
|
9734
|
+
if (own.length) return program.error(`Fix the entry first:
|
|
9735
|
+
${own.map((p) => ` ${p}`).join("\n")}`);
|
|
9736
|
+
console.log(`Open this to file it (check it names no app or customer; Genesis is public), then set its status to proposed:
|
|
9737
|
+
${exportIssueUrl2(entry)}`);
|
|
9738
|
+
});
|
|
8804
9739
|
var studio = program.command("studio").description("The Genesis Data Studio");
|
|
8805
9740
|
studio.command("init").description("Turn the Data Studio on in this app: a server for every table, a page, and one migration to review").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--host <host>", "next, tanstack-start or supabase-function (default: detected)").option("--route <path>", "Where the page lives", "/admin/data").option("--login-role <name>", "The studio's database login", "genesis_studio_login").option("--force", "Overwrite files that already exist", false).action(async (opts) => {
|
|
8806
9741
|
const { planStudioInit: planStudioInit2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
8807
|
-
const root =
|
|
8808
|
-
const packageJson = JSON.parse(await fs.readFile(
|
|
8809
|
-
const
|
|
9742
|
+
const root = path28.resolve(opts.dir);
|
|
9743
|
+
const packageJson = JSON.parse(await fs.readFile(path28.join(root, "package.json"), "utf-8").catch(() => "{}"));
|
|
9744
|
+
const existsSync36 = (await import('fs')).existsSync;
|
|
8810
9745
|
const readSync = (await import('fs')).readFileSync;
|
|
8811
|
-
const
|
|
9746
|
+
const readdirSync17 = (await import('fs')).readdirSync;
|
|
8812
9747
|
if (opts.host && !["next", "tanstack-start", "supabase-function"].includes(opts.host)) {
|
|
8813
9748
|
throw new Error("--host must be next, tanstack-start or supabase-function.");
|
|
8814
9749
|
}
|
|
8815
9750
|
const plan = planStudioInit2(
|
|
8816
9751
|
{
|
|
8817
9752
|
packageJson,
|
|
8818
|
-
exists: (p) =>
|
|
8819
|
-
read: (p) =>
|
|
9753
|
+
exists: (p) => existsSync36(path28.join(root, p)),
|
|
9754
|
+
read: (p) => existsSync36(path28.join(root, p)) ? readSync(path28.join(root, p), "utf-8") : null,
|
|
8820
9755
|
timestamp: (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14),
|
|
8821
9756
|
listDeep: (p) => {
|
|
8822
9757
|
const out = [];
|
|
8823
9758
|
const walk2 = (rel) => {
|
|
8824
|
-
for (const entry of
|
|
9759
|
+
for (const entry of readdirSync17(path28.join(root, rel), { withFileTypes: true })) {
|
|
8825
9760
|
const child = `${rel}/${entry.name}`;
|
|
8826
9761
|
if (entry.isDirectory()) walk2(child);
|
|
8827
9762
|
else out.push(child);
|
|
@@ -8835,7 +9770,7 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
8835
9770
|
},
|
|
8836
9771
|
list: (p) => {
|
|
8837
9772
|
try {
|
|
8838
|
-
return
|
|
9773
|
+
return readdirSync17(path28.join(root, p));
|
|
8839
9774
|
} catch {
|
|
8840
9775
|
return [];
|
|
8841
9776
|
}
|
|
@@ -8844,8 +9779,8 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
8844
9779
|
{ host: opts.host, route: opts.route, loginRole: opts.loginRole }
|
|
8845
9780
|
);
|
|
8846
9781
|
for (const file of plan.files) {
|
|
8847
|
-
const target =
|
|
8848
|
-
await fs.mkdir(
|
|
9782
|
+
const target = path28.join(root, file.path);
|
|
9783
|
+
await fs.mkdir(path28.dirname(target), { recursive: true });
|
|
8849
9784
|
if (file.edit) {
|
|
8850
9785
|
await fs.writeFile(target, file.content, "utf-8");
|
|
8851
9786
|
console.log(`~ ${file.path} (${file.edit})`);
|
|
@@ -8856,14 +9791,14 @@ studio.command("init").description("Turn the Data Studio on in this app: a serve
|
|
|
8856
9791
|
console.log(`+ ${file.path} (appended)`);
|
|
8857
9792
|
continue;
|
|
8858
9793
|
}
|
|
8859
|
-
if (
|
|
9794
|
+
if (existsSync36(target) && !opts.force) {
|
|
8860
9795
|
console.log(`= ${file.path} exists; left as it is (--force to replace)`);
|
|
8861
9796
|
continue;
|
|
8862
9797
|
}
|
|
8863
9798
|
await fs.writeFile(target, file.content, "utf-8");
|
|
8864
9799
|
console.log(`+ ${file.path}`);
|
|
8865
9800
|
}
|
|
8866
|
-
const pm =
|
|
9801
|
+
const pm = existsSync36(path28.join(root, "pnpm-lock.yaml")) ? "pnpm add" : existsSync36(path28.join(root, "yarn.lock")) ? "yarn add" : existsSync36(path28.join(root, "bun.lock")) || existsSync36(path28.join(root, "bun.lockb")) ? "bun add" : "npm install";
|
|
8867
9802
|
console.log("");
|
|
8868
9803
|
console.log(`\u2714 The Data Studio is set up for ${{ next: "Next.js", "tanstack-start": "TanStack Start", "supabase-function": "a Supabase Edge Function" }[plan.host]}. To finish:`);
|
|
8869
9804
|
console.log(` 1. ${pm} ${plan.install.map((p) => /[\s<>|]/.test(p) ? `"${p}"` : p).join(" ")}`);
|
|
@@ -8881,7 +9816,7 @@ async function confirm(question) {
|
|
|
8881
9816
|
}
|
|
8882
9817
|
var logger = { info: (m) => console.log(m), warn: (m) => console.warn(`! ${m}`) };
|
|
8883
9818
|
program.command("add").description("Add a block (a feature an app adds whole) from the Genesis package that declares it: install, migrations, functions, skills, routes, registry entry").argument("[block]", "The block's id, e.g. tenant-features").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--package <name>", "The package that declares it, when two do").option("--list", "List the blocks this app can add, and exit", false).option("--dry-run", "Print the plan; write and install nothing", false).option("-y, --yes", "Don't ask before writing", false).option("--no-install", "Don't install packages (print the command instead)").option("--no-features-build", "Don't run features build after").action(async (block, opts) => {
|
|
8884
|
-
const root =
|
|
9819
|
+
const root = path28.resolve(opts.dir);
|
|
8885
9820
|
if (opts.list || !block) {
|
|
8886
9821
|
const { allBlocks: allBlocks2 } = await Promise.resolve().then(() => (init_discover(), discover_exports));
|
|
8887
9822
|
const { readLock: readLock2 } = await Promise.resolve().then(() => (init_lock(), lock_exports));
|
|
@@ -8907,15 +9842,22 @@ program.command("add").description("Add a block (a feature an app adds whole) fr
|
|
|
8907
9842
|
report.steps.forEach((s, i) => console.log(` ${i + 1}. ${s}`));
|
|
8908
9843
|
}
|
|
8909
9844
|
});
|
|
8910
|
-
program.command("migrate").description("Copy new package migrations of the app's blocks in as new timestamped files; report edited or changed ones (never rewritten)").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--block <id...>", "Also check these blocks (beyond genesis.lock.json's)").option("--dry-run", "Report only", false).option("--forward", "Write a forward migration stub for each edited or changed migration", false).action(async (opts) => {
|
|
9845
|
+
program.command("migrate").description("Copy new package migrations of the app's blocks in as new timestamped files; report edited or changed ones (never rewritten)").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--block <id...>", "Also check these blocks (beyond genesis.lock.json's)").option("--dry-run", "Report only", false).option("--forward", "Write a forward migration stub for each edited or changed migration", false).option("--notifications <file>", "The app's defineNotifications registry (relative to --dir), loaded to write a types migration when the notifications block is installed; default: notifications.registry in genesis.config.json. Runs app code; skipped on --dry-run").action(async (opts) => {
|
|
8911
9846
|
const { runMigrate: runMigrate2 } = await Promise.resolve().then(() => (init_migrate(), migrate_exports));
|
|
8912
9847
|
const { formatMigrationRows: formatMigrationRows2 } = await Promise.resolve().then(() => (init_migrations(), migrations_exports));
|
|
8913
|
-
const report = await runMigrate2({
|
|
9848
|
+
const report = await runMigrate2({
|
|
9849
|
+
root: path28.resolve(opts.dir),
|
|
9850
|
+
...opts.block ? { blocks: opts.block } : {},
|
|
9851
|
+
...opts.notifications ? { notifications: opts.notifications } : {},
|
|
9852
|
+
dryRun: opts.dryRun,
|
|
9853
|
+
forward: opts.forward
|
|
9854
|
+
});
|
|
8914
9855
|
for (const w of report.warnings) logger.warn(w);
|
|
8915
9856
|
console.log(formatMigrationRows2(report.plan.rows));
|
|
8916
9857
|
for (const c of report.plan.creates) if (c.kind !== "migration") console.log(`+ ${c.path} (${c.kind === "test" ? "pgTAP test" : "forward migration: fill it in"})`);
|
|
9858
|
+
if (report.notificationTypes) console.log(`+ ${report.notificationTypes} (the notification types, from the registry)`);
|
|
8917
9859
|
console.log("");
|
|
8918
|
-
const count = report.plan.creates.length;
|
|
9860
|
+
const count = report.plan.creates.length + (report.notificationTypes ? 1 : 0);
|
|
8919
9861
|
console.log(opts.dryRun ? `Dry run: ${count} file${count === 1 ? "" : "s"} would be created.` : `\u2714 ${report.written.length} file${report.written.length === 1 ? "" : "s"} created. Nothing existing was changed.`);
|
|
8920
9862
|
if (report.attention) {
|
|
8921
9863
|
console.log(opts.forward ? "Fill in the forward migrations, review them, then apply them." : "Some migrations need you (above): an applied migration is never rewritten. Run genesis migrate --forward to add a forward migration for each.");
|
|
@@ -8925,7 +9867,7 @@ program.command("migrate").description("Copy new package migrations of the app's
|
|
|
8925
9867
|
program.command("upgrade").description("Move every @marktiderman/genesis* dependency to one Genesis release, refresh the files Genesis owns, run codemods and the doctor").option("-d, --dir <dir>", "The app's folder", process.cwd()).option("--version <v>", "The @marktiderman/genesis release: an exact version or a dist-tag", "latest").option("--manifest <file>", "Read the release from this versions.json instead of npm").option("--dry-run", "Report the bump, and owned files compared with the packages installed now; change nothing", false).option("--no-install", "Don't reinstall after the bump").option("--no-doctor", "Don't run genesis doctor after").option("--keep-mine", "Never merge an owned file you changed; write the new text to .genesis-next", false).option("--pr", "Commit to a genesis-upgrade/<version> branch, push it and open a pull request", false).action(async (opts) => {
|
|
8926
9868
|
const { runUpgrade: runUpgrade2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
8927
9869
|
const report = await runUpgrade2({
|
|
8928
|
-
root:
|
|
9870
|
+
root: path28.resolve(opts.dir),
|
|
8929
9871
|
version: opts.version,
|
|
8930
9872
|
...opts.manifest ? { manifest: opts.manifest } : {},
|
|
8931
9873
|
dryRun: opts.dryRun,
|
|
@@ -8951,7 +9893,7 @@ program.command("codemod [id]").description("Run one of Genesis's codemods by ha
|
|
|
8951
9893
|
}
|
|
8952
9894
|
const mod = codemodById2(id);
|
|
8953
9895
|
if (!mod) throw new Error(`No codemod "${id}". Run genesis codemod to list them.`);
|
|
8954
|
-
const changed = await mod.run({ root:
|
|
9896
|
+
const changed = await mod.run({ root: path28.resolve(opts.dir), dryRun: opts.dryRun, log: (m) => console.log(m) });
|
|
8955
9897
|
console.log(changed.length ? `${opts.dryRun ? "Would change" : "\u2714 Changed"} ${changed.length} file${changed.length === 1 ? "" : "s"}:
|
|
8956
9898
|
${changed.map((f) => ` ${f}`).join("\n")}` : "Nothing to change.");
|
|
8957
9899
|
});
|
|
@@ -9002,7 +9944,7 @@ function redactUrl(location) {
|
|
|
9002
9944
|
const url = new URL(location);
|
|
9003
9945
|
return `${url.origin}${url.pathname}`;
|
|
9004
9946
|
} catch {
|
|
9005
|
-
return
|
|
9947
|
+
return path28.basename(location);
|
|
9006
9948
|
}
|
|
9007
9949
|
}
|
|
9008
9950
|
//# sourceMappingURL=cli.js.map
|