@marktiderman/genesis-cli 1.17.3 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -17
- package/dist/cli.js +2099 -747
- package/dist/cli.js.map +1 -1
- package/dist/{config-1jP8eCZy.d.ts → config-Dj_f9T7J.d.ts} +14 -1
- package/dist/doctor.d.ts +3 -3
- package/dist/doctor.js +944 -361
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js +18 -0
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +29 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +944 -361
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +9 -0
- package/dist/starter/__tests__/components/gestures.test.tsx +64 -0
- package/dist/starter/__tests__/components/resolver.js +14 -2
- package/dist/starter/__tests__/components/setup.ts +5 -0
- package/dist/starter/__tests__/starter.test.ts +56 -22
- package/dist/starter/genesis.config.json +10 -0
- package/dist/starter/jest.config.js +3 -0
- package/dist/starter/package.json +2 -0
- package/dist/starter/src/lib/link-hosts.ts +12 -0
- package/dist/starter/src/lib/links.ts +2 -1
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +7 -2
- package/dist/starter/supabase/migrations/20261024000700_genesis_support_findings.sql +339 -0
- package/dist/starter/supabase/tests/database/genesis_notifications.test.sql +5 -3
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +1 -1
- package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +219 -0
- package/dist/templates/ci/genesis-upgrade.yml +1 -0
- package/dist/vite.js +945 -362
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { createRequire, builtinModules } from 'module';
|
|
2
2
|
import { studioSetupSql } from '@marktiderman/genesis-studio-server';
|
|
3
|
-
import * as
|
|
3
|
+
import * as path20 from 'path';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
5
|
import { existsSync, readFileSync, statSync, realpathSync, readdirSync, lstatSync } from 'fs';
|
|
6
|
-
import 'crypto';
|
|
6
|
+
import { createHash } from 'crypto';
|
|
7
7
|
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
8
|
-
import { pathToFileURL } from 'url';
|
|
8
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
9
9
|
import { overlayUpstream, readOverlayMarker } from '@marktiderman/genesis-features';
|
|
10
|
-
import 'jiti';
|
|
10
|
+
import { createJiti } from 'jiti';
|
|
11
|
+
import 'os';
|
|
11
12
|
|
|
12
13
|
var __defProp = Object.defineProperty;
|
|
13
14
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -455,14 +456,14 @@ function inherit(own, source) {
|
|
|
455
456
|
}
|
|
456
457
|
function resolveViews(relations) {
|
|
457
458
|
const done = /* @__PURE__ */ new Set();
|
|
458
|
-
const
|
|
459
|
+
const resolve16 = (relation, depth) => {
|
|
459
460
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
460
461
|
done.add(relation.oid);
|
|
461
462
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
462
463
|
if (sources.size !== 1) return;
|
|
463
464
|
const source = relations.get([...sources][0]);
|
|
464
465
|
if (!source) return;
|
|
465
|
-
|
|
466
|
+
resolve16(source, depth + 1);
|
|
466
467
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
467
468
|
for (const [attnum, origin] of relation.origins) {
|
|
468
469
|
const own = relation.columns.get(attnum);
|
|
@@ -485,7 +486,7 @@ function resolveViews(relations) {
|
|
|
485
486
|
};
|
|
486
487
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
487
488
|
};
|
|
488
|
-
for (const relation of relations.values())
|
|
489
|
+
for (const relation of relations.values()) resolve16(relation, 0);
|
|
489
490
|
}
|
|
490
491
|
async function introspectPostgres(sql, schemas, options = {}) {
|
|
491
492
|
const relations = /* @__PURE__ */ new Map();
|
|
@@ -815,9 +816,9 @@ async function runScaffold(opts, fs) {
|
|
|
815
816
|
function joinPath(...parts) {
|
|
816
817
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
817
818
|
}
|
|
818
|
-
function dirname(
|
|
819
|
-
const idx =
|
|
820
|
-
return idx === -1 ? "." :
|
|
819
|
+
function dirname(path39) {
|
|
820
|
+
const idx = path39.lastIndexOf("/");
|
|
821
|
+
return idx === -1 ? "." : path39.slice(0, idx);
|
|
821
822
|
}
|
|
822
823
|
function brandPackageJson(consumer, genesisVersion) {
|
|
823
824
|
return JSON.stringify(
|
|
@@ -1408,19 +1409,19 @@ ${line}
|
|
|
1408
1409
|
var BUILD_GUARD_ENV = "GENESIS_DOCTOR_BUILDING";
|
|
1409
1410
|
function buildCommands(root, config) {
|
|
1410
1411
|
if (config.build) return config.build;
|
|
1411
|
-
const pkgFile =
|
|
1412
|
+
const pkgFile = path20.join(root, "package.json");
|
|
1412
1413
|
const scripts = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile, "utf8")).scripts ?? {} : {};
|
|
1413
1414
|
const pm = packageManager(root);
|
|
1414
1415
|
return ["typecheck", "build"].filter((s) => scripts[s]).map((s) => `${pm} run ${s}`);
|
|
1415
1416
|
}
|
|
1416
1417
|
function packageManager(root) {
|
|
1417
|
-
let dir =
|
|
1418
|
+
let dir = path20.resolve(root);
|
|
1418
1419
|
for (; ; ) {
|
|
1419
|
-
if (existsSync(
|
|
1420
|
-
if (existsSync(
|
|
1421
|
-
if (existsSync(
|
|
1422
|
-
if (existsSync(
|
|
1423
|
-
const parent =
|
|
1420
|
+
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
1421
|
+
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return "bun";
|
|
1422
|
+
if (existsSync(path20.join(dir, "yarn.lock"))) return "yarn";
|
|
1423
|
+
if (existsSync(path20.join(dir, "package-lock.json"))) return "npm";
|
|
1424
|
+
const parent = path20.dirname(dir);
|
|
1424
1425
|
if (parent === dir) return "npm";
|
|
1425
1426
|
dir = parent;
|
|
1426
1427
|
}
|
|
@@ -1535,25 +1536,25 @@ var PACK_KEYS = {
|
|
|
1535
1536
|
};
|
|
1536
1537
|
function appPath(v, where2, fail) {
|
|
1537
1538
|
if (typeof v !== "string" || !v.trim()) return fail(`${where2} must be a non-empty path`);
|
|
1538
|
-
if (
|
|
1539
|
-
const norm =
|
|
1539
|
+
if (path20.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where2} must be relative to the app, not absolute ("${v}")`);
|
|
1540
|
+
const norm = path20.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
1540
1541
|
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where2} must be a folder inside the app ("${v}")`);
|
|
1541
1542
|
return norm;
|
|
1542
1543
|
}
|
|
1543
1544
|
function loadConfig(root, configPath) {
|
|
1544
1545
|
if (configPath) {
|
|
1545
|
-
const file =
|
|
1546
|
+
const file = path20.resolve(root, configPath);
|
|
1546
1547
|
if (!existsSync(file)) throw new DoctorConfigError(`Config file not found: ${configPath}`);
|
|
1547
1548
|
const json = readJson(file);
|
|
1548
|
-
const block =
|
|
1549
|
-
return { config: validateConfig(block ?? {}, file), file, dir:
|
|
1549
|
+
const block = path20.basename(file) === "package.json" ? json?.genesis?.doctor : json?.doctor ?? json;
|
|
1550
|
+
return { config: validateConfig(block ?? {}, file), file, dir: path20.dirname(file) };
|
|
1550
1551
|
}
|
|
1551
|
-
const own =
|
|
1552
|
+
const own = path20.join(root, "genesis.config.json");
|
|
1552
1553
|
if (existsSync(own)) {
|
|
1553
1554
|
const block = readGenesisConfig(root)?.raw.doctor;
|
|
1554
1555
|
return { config: validateConfig(block ?? {}, own), file: own, dir: root };
|
|
1555
1556
|
}
|
|
1556
|
-
const pkg =
|
|
1557
|
+
const pkg = path20.join(root, "package.json");
|
|
1557
1558
|
if (existsSync(pkg)) {
|
|
1558
1559
|
const block = readJson(pkg)?.genesis?.doctor;
|
|
1559
1560
|
if (block !== void 0 && !isPackageDeclaration(block)) return { config: validateConfig(block, pkg), file: pkg, dir: root };
|
|
@@ -1562,7 +1563,7 @@ function loadConfig(root, configPath) {
|
|
|
1562
1563
|
}
|
|
1563
1564
|
function doctorBlock(json, file, explicit) {
|
|
1564
1565
|
const j = json;
|
|
1565
|
-
if (
|
|
1566
|
+
if (path20.basename(file) === "package.json") return j?.genesis?.doctor;
|
|
1566
1567
|
return explicit ? j?.doctor ?? j : j?.doctor;
|
|
1567
1568
|
}
|
|
1568
1569
|
function isPackageDeclaration(block) {
|
|
@@ -1579,15 +1580,33 @@ function readJson(file) {
|
|
|
1579
1580
|
}
|
|
1580
1581
|
}
|
|
1581
1582
|
function readGenesisConfig(root) {
|
|
1582
|
-
const file =
|
|
1583
|
+
const file = path20.join(root, "genesis.config.json");
|
|
1583
1584
|
if (!existsSync(file)) return null;
|
|
1584
1585
|
const raw = readJson(file);
|
|
1585
1586
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
1586
1587
|
const out = { raw };
|
|
1587
1588
|
if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
|
|
1588
1589
|
if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
|
|
1590
|
+
if (raw.supabase !== void 0) {
|
|
1591
|
+
const supabase = validateSupabase(raw.supabase, file);
|
|
1592
|
+
if (supabase !== true) out.supabase = supabase;
|
|
1593
|
+
}
|
|
1589
1594
|
return out;
|
|
1590
1595
|
}
|
|
1596
|
+
function validateSupabase(raw, source = "config") {
|
|
1597
|
+
const fail = (msg) => {
|
|
1598
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
1599
|
+
};
|
|
1600
|
+
if (typeof raw === "boolean") return raw ? true : false;
|
|
1601
|
+
if (!isObject(raw)) return fail(`"supabase" must be false or { "app": "<the folder of the app that holds supabase/>" }`);
|
|
1602
|
+
for (const key2 of Object.keys(raw)) if (key2 !== "app" && key2 !== "$comment") fail(`supabase: unknown setting "${key2}" (known: app)`);
|
|
1603
|
+
const app = raw.app;
|
|
1604
|
+
if (typeof app !== "string" || !app.trim()) return fail(`supabase.app must be the folder of the app that holds supabase/, relative to this one (e.g. "../app")`);
|
|
1605
|
+
if (path20.isAbsolute(app) || /^[A-Za-z]:[\\/]/.test(app) || app.includes("\\")) fail(`supabase.app must be relative to this app, with forward slashes ("${app}")`);
|
|
1606
|
+
const norm = path20.posix.normalize(app).replace(/\/+$/, "");
|
|
1607
|
+
if (norm === "." || norm === "") fail(`supabase.app names this app itself; leave "supabase" out instead`);
|
|
1608
|
+
return { app: norm };
|
|
1609
|
+
}
|
|
1591
1610
|
var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
|
|
1592
1611
|
var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
|
|
1593
1612
|
function validatePrivacy(raw, source = "config") {
|
|
@@ -1744,7 +1763,7 @@ function validateConfig(raw, source = "config") {
|
|
|
1744
1763
|
if (!(c.packs ?? []).includes("supabase")) fail(`"contracts" is set but the supabase pack is not in "packs"`);
|
|
1745
1764
|
if (contracts.out !== void 0) {
|
|
1746
1765
|
if (typeof contracts.out !== "string" || !contracts.out.trim()) fail(`contracts.out must be a file path`);
|
|
1747
|
-
if (
|
|
1766
|
+
if (path20.isAbsolute(contracts.out) || contracts.out.replace(/\\/g, "/").split("/").includes("..")) fail(`contracts.out must be a file inside the app`);
|
|
1748
1767
|
}
|
|
1749
1768
|
if (contracts.schemas !== void 0 && !isStringList(contracts.schemas)) fail(`contracts.schemas must be a list of schema names`);
|
|
1750
1769
|
if (contracts.databaseEnv !== void 0 && (typeof contracts.databaseEnv !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(contracts.databaseEnv))) {
|
|
@@ -1812,7 +1831,7 @@ function globToRegExp(glob) {
|
|
|
1812
1831
|
}
|
|
1813
1832
|
function globMatcher(globs) {
|
|
1814
1833
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1815
|
-
return (
|
|
1834
|
+
return (path39) => res.some((re) => re.test(path39));
|
|
1816
1835
|
}
|
|
1817
1836
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1818
1837
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
@@ -1852,11 +1871,11 @@ var TAILWIND_PALETTE = [
|
|
|
1852
1871
|
"olive"
|
|
1853
1872
|
];
|
|
1854
1873
|
function findPackageDir(from, name) {
|
|
1855
|
-
let dir =
|
|
1874
|
+
let dir = path20.resolve(from);
|
|
1856
1875
|
for (; ; ) {
|
|
1857
|
-
const candidate =
|
|
1858
|
-
if (existsSync(
|
|
1859
|
-
const parent =
|
|
1876
|
+
const candidate = path20.join(dir, "node_modules", name);
|
|
1877
|
+
if (existsSync(path20.join(candidate, "package.json"))) return candidate;
|
|
1878
|
+
const parent = path20.dirname(dir);
|
|
1860
1879
|
if (parent === dir) return null;
|
|
1861
1880
|
dir = parent;
|
|
1862
1881
|
}
|
|
@@ -1908,7 +1927,7 @@ function loadCompanions(root, config, uiPackage) {
|
|
|
1908
1927
|
function readPackageExports(root, uiPackage) {
|
|
1909
1928
|
const uiDir = findPackageDir(root, uiPackage);
|
|
1910
1929
|
if (!uiDir) return null;
|
|
1911
|
-
const uiPkg = JSON.parse(readFileSync(
|
|
1930
|
+
const uiPkg = JSON.parse(readFileSync(path20.join(uiDir, "package.json"), "utf8"));
|
|
1912
1931
|
const subpaths = Object.values(uiPkg.exports ?? {});
|
|
1913
1932
|
const declared = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
1914
1933
|
const fromSource = typeof declared !== "string" && !subpaths.some((t) => typeof exportTypes(t) === "string");
|
|
@@ -1935,23 +1954,23 @@ function readPackageExports(root, uiPackage) {
|
|
|
1935
1954
|
}
|
|
1936
1955
|
if (fromSource) {
|
|
1937
1956
|
for (const m of code.matchAll(/export\s+\*\s+from\s*["'](\.[^"']*)["']/g)) {
|
|
1938
|
-
const next = resolveSource(
|
|
1957
|
+
const next = resolveSource(path20.dirname(file), m[1]);
|
|
1939
1958
|
if (next) readEntry(next);
|
|
1940
1959
|
}
|
|
1941
1960
|
}
|
|
1942
1961
|
};
|
|
1943
|
-
for (const entry of typeEntries) readEntry(
|
|
1962
|
+
for (const entry of typeEntries) readEntry(path20.join(uiDir, entry));
|
|
1944
1963
|
if (!readAny) {
|
|
1945
1964
|
const what = fromSource ? "type declarations or TypeScript source" : "type declarations";
|
|
1946
1965
|
throw new DoctorConfigError(`${uiPackage} has no ${what} to read (is it built?). Looked for: ${[...typeEntries].join(", ") || "none"}`);
|
|
1947
1966
|
}
|
|
1948
1967
|
const valueDecls = /* @__PURE__ */ new Set();
|
|
1949
1968
|
const typeDecls = /* @__PURE__ */ new Set();
|
|
1950
|
-
const declRoot = typeof mainTypes === "string" ?
|
|
1969
|
+
const declRoot = typeof mainTypes === "string" ? path20.dirname(path20.join(uiDir, mainTypes)) : uiDir;
|
|
1951
1970
|
const declFiles = fromSource ? walkSource(declRoot) : walkDts(declRoot);
|
|
1952
1971
|
for (const pkg of reexportedPackages) {
|
|
1953
1972
|
const dir = findPackageDir(uiDir, pkg);
|
|
1954
|
-
if (dir) walkDts(
|
|
1973
|
+
if (dir) walkDts(path20.join(dir, "dist"), declFiles);
|
|
1955
1974
|
}
|
|
1956
1975
|
for (const file of declFiles) {
|
|
1957
1976
|
const text = readFileSync(file, "utf8");
|
|
@@ -2001,13 +2020,13 @@ function exportSource(target) {
|
|
|
2001
2020
|
return void 0;
|
|
2002
2021
|
}
|
|
2003
2022
|
function resolveSource(dir, spec) {
|
|
2004
|
-
const base =
|
|
2005
|
-
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) =>
|
|
2023
|
+
const base = path20.resolve(dir, spec.replace(/\.js$/, ""));
|
|
2024
|
+
const candidates = [base, ...[".ts", ".tsx", ".mts", ".cts"].map((e) => base + e), ...["index.ts", "index.tsx"].map((i) => path20.join(base, i))];
|
|
2006
2025
|
return candidates.find((f) => TS_SOURCE.test(f) && existsSync(f) && statSync(f).isFile()) ?? null;
|
|
2007
2026
|
}
|
|
2008
2027
|
function insidePackage(dir, file) {
|
|
2009
|
-
const rel =
|
|
2010
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
2028
|
+
const rel = path20.relative(path20.resolve(dir), path20.resolve(file));
|
|
2029
|
+
return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
2011
2030
|
}
|
|
2012
2031
|
function stripComments(code) {
|
|
2013
2032
|
let out = "";
|
|
@@ -2043,7 +2062,7 @@ function walkSource(dir, out = []) {
|
|
|
2043
2062
|
if (!existsSync(dir)) return out;
|
|
2044
2063
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2045
2064
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
2046
|
-
const p =
|
|
2065
|
+
const p = path20.join(dir, entry.name);
|
|
2047
2066
|
if (entry.isDirectory()) walkSource(p, out);
|
|
2048
2067
|
else if (isTsSource(entry.name) || /\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
2049
2068
|
}
|
|
@@ -2063,7 +2082,7 @@ function walkDts(dir, out = []) {
|
|
|
2063
2082
|
if (!existsSync(dir)) return out;
|
|
2064
2083
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
2065
2084
|
if (entry.name === "node_modules") continue;
|
|
2066
|
-
const p =
|
|
2085
|
+
const p = path20.join(dir, entry.name);
|
|
2067
2086
|
if (entry.isDirectory()) walkDts(p, out);
|
|
2068
2087
|
else if (/\.d\.[cm]?ts$/.test(entry.name)) out.push(p);
|
|
2069
2088
|
}
|
|
@@ -2080,27 +2099,27 @@ function resolveThemeFiles(root, config, uiDir) {
|
|
|
2080
2099
|
}
|
|
2081
2100
|
const files = [];
|
|
2082
2101
|
const ds = findPackageDir(root, DESIGN_SYSTEM_PACKAGE);
|
|
2083
|
-
const themes = ds &&
|
|
2102
|
+
const themes = ds && path20.join(ds, "dist", "themes");
|
|
2084
2103
|
if (themes && existsSync(themes)) {
|
|
2085
|
-
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(
|
|
2104
|
+
for (const name of readdirSync(themes).sort()) if (name.endsWith(".css")) files.push(path20.join(themes, name));
|
|
2086
2105
|
}
|
|
2087
2106
|
if (files.length === 0) {
|
|
2088
2107
|
throw new DoctorConfigError(
|
|
2089
2108
|
`No Genesis theme stylesheet found (${DESIGN_SYSTEM_PACKAGE}/dist/themes/*.css). Install the design system, or set doctor.themeCss.`
|
|
2090
2109
|
);
|
|
2091
2110
|
}
|
|
2092
|
-
const uiStyles =
|
|
2111
|
+
const uiStyles = path20.join(uiDir, "dist", "styles.css");
|
|
2093
2112
|
if (existsSync(uiStyles)) files.push(uiStyles);
|
|
2094
2113
|
return files;
|
|
2095
2114
|
}
|
|
2096
2115
|
function resolveSpec(root, spec) {
|
|
2097
|
-
const local =
|
|
2098
|
-
if (spec.startsWith(".") ||
|
|
2116
|
+
const local = path20.resolve(root, spec);
|
|
2117
|
+
if (spec.startsWith(".") || path20.isAbsolute(spec)) return existsSync(local) ? local : null;
|
|
2099
2118
|
const parts = spec.split("/");
|
|
2100
2119
|
const nameLength = spec.startsWith("@") ? 2 : 1;
|
|
2101
2120
|
const dir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2102
2121
|
if (dir) {
|
|
2103
|
-
const file =
|
|
2122
|
+
const file = path20.join(dir, ...parts.slice(nameLength));
|
|
2104
2123
|
if (existsSync(file) && statSync(file).isFile()) return file;
|
|
2105
2124
|
}
|
|
2106
2125
|
return existsSync(local) ? local : null;
|
|
@@ -2108,7 +2127,7 @@ function resolveSpec(root, spec) {
|
|
|
2108
2127
|
function loadPalette(root) {
|
|
2109
2128
|
const names = new Set(TAILWIND_PALETTE);
|
|
2110
2129
|
try {
|
|
2111
|
-
const req = createRequire(
|
|
2130
|
+
const req = createRequire(path20.join(root, "package.json"));
|
|
2112
2131
|
const colors = req("tailwindcss/colors");
|
|
2113
2132
|
for (const key2 of Object.keys(colors?.default ?? colors ?? {})) {
|
|
2114
2133
|
if (/^[a-z]+$/.test(key2) && !["inherit", "current", "transparent"].includes(key2)) names.add(key2);
|
|
@@ -2198,6 +2217,26 @@ function parseManifest(home, id, raw, version, options = {}) {
|
|
|
2198
2217
|
const file = pathOf(m["file"], `${where2}.file`);
|
|
2199
2218
|
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
2200
2219
|
const out = { package: pkgOf(m["package"], where2), file };
|
|
2220
|
+
if (m["provides"] !== void 0) {
|
|
2221
|
+
if (!Array.isArray(m["provides"])) problems.push(`${where2}.provides: must be a list of { package, file }`);
|
|
2222
|
+
else {
|
|
2223
|
+
out.provides = m["provides"].map((p, j) => {
|
|
2224
|
+
const at2 = `${where2}.provides[${j}]`;
|
|
2225
|
+
if (!isObject2(p)) {
|
|
2226
|
+
problems.push(`${at2}: must be an object`);
|
|
2227
|
+
return { package: home, file: "" };
|
|
2228
|
+
}
|
|
2229
|
+
const provided = { package: pkgOf(p["package"], at2), file: pathOf(p["file"], `${at2}.file`) };
|
|
2230
|
+
if (p["functions"] !== void 0) {
|
|
2231
|
+
if (!Array.isArray(p["functions"])) problems.push(`${at2}.functions: must be a list of function folders`);
|
|
2232
|
+
else provided.functions = p["functions"].map((f, k) => pathOf(f, `${at2}.functions[${k}]`));
|
|
2233
|
+
}
|
|
2234
|
+
if (provided.file && !MIGRATION_FILE.test(provided.file.split("/").pop())) problems.push(`${at2}.file: "${provided.file}" must be named NNNN_name.sql`);
|
|
2235
|
+
if (provided.package === out.package && provided.file === file) problems.push(`${at2}: a migration can't provide itself`);
|
|
2236
|
+
return provided;
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2201
2240
|
if (m["test"] !== void 0) {
|
|
2202
2241
|
out.test = pathOf(m["test"], `${where2}.test`);
|
|
2203
2242
|
if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where2}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
|
|
@@ -2294,11 +2333,52 @@ function rawBlocksOf(packageJson) {
|
|
|
2294
2333
|
const blocks = packageJson["genesis"]["blocks"];
|
|
2295
2334
|
return isObject2(blocks) ? blocks : {};
|
|
2296
2335
|
}
|
|
2336
|
+
function declarationFields(block) {
|
|
2337
|
+
const c = block.contributes ?? {};
|
|
2338
|
+
return {
|
|
2339
|
+
...block.requires ? { requires: [...block.requires] } : {},
|
|
2340
|
+
...block.platforms ? { platforms: [...block.platforms] } : {},
|
|
2341
|
+
...c.migrations ? { migrations: c.migrations.map((m) => ({ ...m })) } : {},
|
|
2342
|
+
...c.routes ? { routes: c.routes.map((r) => ({ ...r })) } : {},
|
|
2343
|
+
...c.skills ? { skills: [...c.skills] } : {},
|
|
2344
|
+
...c.privacy ? { privacy: c.privacy } : {}
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
function isBlockDef(value) {
|
|
2348
|
+
return isObject2(value) && typeof value["id"] === "string" && BLOCK_ID.test(value["id"]) && (value["contributes"] === void 0 || isObject2(value["contributes"])) && (isObject2(value["contributes"]) || Array.isArray(value["requires"]));
|
|
2349
|
+
}
|
|
2297
2350
|
|
|
2298
2351
|
// src/blocks/files.ts
|
|
2352
|
+
var sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
2299
2353
|
function inside(parent, child) {
|
|
2300
|
-
const rel =
|
|
2301
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
2354
|
+
const rel = path20.relative(parent, child);
|
|
2355
|
+
return rel === "" || !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
2356
|
+
}
|
|
2357
|
+
function appPath2(root, rel) {
|
|
2358
|
+
const safe = safeRelative(rel.replace(/^\.\//, ""));
|
|
2359
|
+
if (!safe) throw new Error(`"${rel}" is not a plain path inside the app`);
|
|
2360
|
+
if (safe.split("/").some((s) => s.toLowerCase() === ".git")) throw new Error(`"${rel}" is inside .git; refused`);
|
|
2361
|
+
const realRoot = realpathSync(root);
|
|
2362
|
+
const target = path20.join(realRoot, ...safe.split("/"));
|
|
2363
|
+
const there = (p) => {
|
|
2364
|
+
try {
|
|
2365
|
+
lstatSync(p);
|
|
2366
|
+
return true;
|
|
2367
|
+
} catch {
|
|
2368
|
+
return false;
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
let probe = path20.dirname(target);
|
|
2372
|
+
while (!there(probe)) probe = path20.dirname(probe);
|
|
2373
|
+
let real2;
|
|
2374
|
+
try {
|
|
2375
|
+
real2 = realpathSync(probe);
|
|
2376
|
+
} catch {
|
|
2377
|
+
throw new Error(`${rel} goes through a broken symlink (${path20.relative(realRoot, probe)}); refused`);
|
|
2378
|
+
}
|
|
2379
|
+
if (!inside(realRoot, real2)) throw new Error(`${rel} is outside the app (a symlinked folder?)`);
|
|
2380
|
+
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
2381
|
+
return target;
|
|
2302
2382
|
}
|
|
2303
2383
|
|
|
2304
2384
|
// src/blocks/local.ts
|
|
@@ -2311,8 +2391,8 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
2311
2391
|
return raw.map((entry, i) => {
|
|
2312
2392
|
const where2 = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
2313
2393
|
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where2} must be a non-empty folder`);
|
|
2314
|
-
if (
|
|
2315
|
-
const norm =
|
|
2394
|
+
if (path20.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where2} must be relative to the app ("${entry}")`);
|
|
2395
|
+
const norm = path20.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
2316
2396
|
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where2} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
2317
2397
|
const parts = norm.split("/");
|
|
2318
2398
|
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
@@ -2323,7 +2403,7 @@ function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
|
2323
2403
|
});
|
|
2324
2404
|
}
|
|
2325
2405
|
function localPackageGlobs(root) {
|
|
2326
|
-
const file =
|
|
2406
|
+
const file = path20.join(root, "genesis.config.json");
|
|
2327
2407
|
if (!existsSync(file)) return [];
|
|
2328
2408
|
let raw;
|
|
2329
2409
|
try {
|
|
@@ -2337,14 +2417,14 @@ function localPackageGlobs(root) {
|
|
|
2337
2417
|
var cache = /* @__PURE__ */ new Map();
|
|
2338
2418
|
function repositoryRoot(appRoot) {
|
|
2339
2419
|
for (let dir = appRoot; ; ) {
|
|
2340
|
-
if (existsSync(
|
|
2341
|
-
const parent =
|
|
2420
|
+
if (existsSync(path20.join(dir, ".git"))) return dir;
|
|
2421
|
+
const parent = path20.dirname(dir);
|
|
2342
2422
|
if (parent === dir) return appRoot;
|
|
2343
2423
|
dir = parent;
|
|
2344
2424
|
}
|
|
2345
2425
|
}
|
|
2346
2426
|
function localPackages(root) {
|
|
2347
|
-
const appRoot =
|
|
2427
|
+
const appRoot = path20.resolve(root);
|
|
2348
2428
|
const globs = localPackageGlobs(appRoot);
|
|
2349
2429
|
const key2 = `${appRoot}
|
|
2350
2430
|
${globs.join("\n")}`;
|
|
@@ -2353,24 +2433,24 @@ ${globs.join("\n")}`;
|
|
|
2353
2433
|
const dirs = /* @__PURE__ */ new Set();
|
|
2354
2434
|
for (const glob of globs) {
|
|
2355
2435
|
if (glob.endsWith("/*") || glob === "*") {
|
|
2356
|
-
const parent =
|
|
2436
|
+
const parent = path20.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
2357
2437
|
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
2358
2438
|
for (const entry of readdirSync(parent).sort()) {
|
|
2359
2439
|
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
2360
|
-
dirs.add(
|
|
2440
|
+
dirs.add(path20.join(parent, entry));
|
|
2361
2441
|
}
|
|
2362
2442
|
} else {
|
|
2363
|
-
dirs.add(
|
|
2443
|
+
dirs.add(path20.join(appRoot, glob));
|
|
2364
2444
|
}
|
|
2365
2445
|
}
|
|
2366
2446
|
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
2367
2447
|
const out = [];
|
|
2368
2448
|
const byName = /* @__PURE__ */ new Map();
|
|
2369
2449
|
for (const dir of [...dirs].sort()) {
|
|
2370
|
-
const manifest =
|
|
2450
|
+
const manifest = path20.join(dir, "package.json");
|
|
2371
2451
|
if (!existsSync(manifest)) continue;
|
|
2372
2452
|
if (!inside(real2, realpathSync(dir))) {
|
|
2373
|
-
throw new LocalPackagesError(`${
|
|
2453
|
+
throw new LocalPackagesError(`${path20.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
2374
2454
|
}
|
|
2375
2455
|
let pkg;
|
|
2376
2456
|
try {
|
|
@@ -2379,7 +2459,7 @@ ${globs.join("\n")}`;
|
|
|
2379
2459
|
continue;
|
|
2380
2460
|
}
|
|
2381
2461
|
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
2382
|
-
const rel =
|
|
2462
|
+
const rel = path20.relative(appRoot, dir).split(path20.sep).join("/");
|
|
2383
2463
|
const other = byName.get(pkg.name);
|
|
2384
2464
|
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
2385
2465
|
byName.set(pkg.name, rel);
|
|
@@ -2388,6 +2468,9 @@ ${globs.join("\n")}`;
|
|
|
2388
2468
|
cache.set(key2, out);
|
|
2389
2469
|
return out;
|
|
2390
2470
|
}
|
|
2471
|
+
function localPackageNames(root) {
|
|
2472
|
+
return new Set(localPackages(root).map((p) => p.name));
|
|
2473
|
+
}
|
|
2391
2474
|
|
|
2392
2475
|
// ../../scripts/lib/color-literals.mjs
|
|
2393
2476
|
var LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
|
|
@@ -2564,35 +2647,35 @@ var DEFAULT_IGNORE = [
|
|
|
2564
2647
|
];
|
|
2565
2648
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", "coverage"]);
|
|
2566
2649
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
2567
|
-
var toPosix = (p) => p.split(
|
|
2650
|
+
var toPosix = (p) => p.split(path20.sep).join("/");
|
|
2568
2651
|
function scanFiles(root, config) {
|
|
2569
2652
|
const extensions = new Set(config.extensions ?? DEFAULT_EXTENSIONS);
|
|
2570
2653
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...config.ignore ?? []]);
|
|
2571
2654
|
const files = [];
|
|
2572
2655
|
const seen = /* @__PURE__ */ new Set();
|
|
2573
2656
|
const visit = (abs) => {
|
|
2574
|
-
const rel = toPosix(
|
|
2657
|
+
const rel = toPosix(path20.relative(root, abs));
|
|
2575
2658
|
if (seen.has(rel) || ignored(rel)) return;
|
|
2576
|
-
const ext =
|
|
2659
|
+
const ext = path20.extname(abs);
|
|
2577
2660
|
if (!extensions.has(ext)) return;
|
|
2578
2661
|
if (statSync(abs).size > MAX_FILE_BYTES) return;
|
|
2579
2662
|
seen.add(rel);
|
|
2580
2663
|
const text = readFileSync(abs, "utf8");
|
|
2581
2664
|
files.push({ path: rel, absolutePath: abs, ext, text, code: stripBlockComments(text, LINE_COMMENT_EXTS.has(ext)) });
|
|
2582
2665
|
};
|
|
2583
|
-
const
|
|
2666
|
+
const walk2 = (dir) => {
|
|
2584
2667
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2585
2668
|
if (entry.isDirectory()) {
|
|
2586
|
-
if (!SKIP_DIRS.has(entry.name))
|
|
2669
|
+
if (!SKIP_DIRS.has(entry.name)) walk2(path20.join(dir, entry.name));
|
|
2587
2670
|
} else if (entry.isFile()) {
|
|
2588
|
-
visit(
|
|
2671
|
+
visit(path20.join(dir, entry.name));
|
|
2589
2672
|
}
|
|
2590
2673
|
}
|
|
2591
2674
|
};
|
|
2592
2675
|
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
2593
|
-
const abs =
|
|
2676
|
+
const abs = path20.resolve(root, src);
|
|
2594
2677
|
if (!existsSync(abs)) continue;
|
|
2595
|
-
if (statSync(abs).isDirectory())
|
|
2678
|
+
if (statSync(abs).isDirectory()) walk2(abs);
|
|
2596
2679
|
else visit(abs);
|
|
2597
2680
|
}
|
|
2598
2681
|
let local = [];
|
|
@@ -2601,7 +2684,7 @@ function scanFiles(root, config) {
|
|
|
2601
2684
|
} catch {
|
|
2602
2685
|
local = [];
|
|
2603
2686
|
}
|
|
2604
|
-
for (const pkg of local)
|
|
2687
|
+
for (const pkg of local) walk2(pkg.dir);
|
|
2605
2688
|
return files;
|
|
2606
2689
|
}
|
|
2607
2690
|
function lineAt(text, index) {
|
|
@@ -2678,7 +2761,7 @@ function loadPatternRules(root, patterns, rulesDoc) {
|
|
|
2678
2761
|
const compiled = compilePatternRules(patterns ?? [], "doctor.patterns");
|
|
2679
2762
|
let all = compiled;
|
|
2680
2763
|
if (rulesDoc) {
|
|
2681
|
-
const file =
|
|
2764
|
+
const file = path20.resolve(root, rulesDoc);
|
|
2682
2765
|
if (!existsSync(file)) throw new DoctorConfigError(`doctor.rulesDoc: ${rulesDoc} not found`);
|
|
2683
2766
|
const fromDoc = compilePatternRules(parseRulesMarkdown(readFileSync(file, "utf8")), rulesDoc);
|
|
2684
2767
|
const clash = fromDoc.find((d) => compiled.some((c) => c.rule.id === d.rule.id));
|
|
@@ -2739,15 +2822,177 @@ async function loadPlugins(specs, configDir) {
|
|
|
2739
2822
|
}
|
|
2740
2823
|
function resolvePlugin(id, configDir) {
|
|
2741
2824
|
try {
|
|
2742
|
-
if (id.startsWith(".") ||
|
|
2825
|
+
if (id.startsWith(".") || path20.isAbsolute(id)) return resolveFrom(path20.resolve(configDir, id), configDir);
|
|
2743
2826
|
return resolveFrom(id, configDir);
|
|
2744
2827
|
} catch {
|
|
2745
2828
|
throw new DoctorConfigError(`doctor.plugins: cannot find ${id} (relative paths resolve from ${configDir})`);
|
|
2746
2829
|
}
|
|
2747
2830
|
}
|
|
2748
2831
|
function resolveFrom(id, from) {
|
|
2749
|
-
return createRequire(
|
|
2832
|
+
return createRequire(path20.join(from, "noop.js")).resolve(id);
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
// src/doctor/semver.ts
|
|
2836
|
+
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
2837
|
+
function parseVersion(v) {
|
|
2838
|
+
const m = VERSION.exec(v.trim());
|
|
2839
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2840
|
+
}
|
|
2841
|
+
function compareVersions(a, b) {
|
|
2842
|
+
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
2843
|
+
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
2844
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
2845
|
+
const x = a.pre[i];
|
|
2846
|
+
const y = b.pre[i];
|
|
2847
|
+
if (x === void 0) return -1;
|
|
2848
|
+
if (y === void 0) return 1;
|
|
2849
|
+
if (x === y) continue;
|
|
2850
|
+
const nx = /^\d+$/.test(x);
|
|
2851
|
+
const ny = /^\d+$/.test(y);
|
|
2852
|
+
if (nx && ny) return +x < +y ? -1 : 1;
|
|
2853
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
2854
|
+
return x < y ? -1 : 1;
|
|
2855
|
+
}
|
|
2856
|
+
return 0;
|
|
2750
2857
|
}
|
|
2858
|
+
function partial(s) {
|
|
2859
|
+
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
2860
|
+
if (!m) return null;
|
|
2861
|
+
const nums = [];
|
|
2862
|
+
let wild = false;
|
|
2863
|
+
for (const part of [m[1], m[2], m[3]]) {
|
|
2864
|
+
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
2865
|
+
wild = true;
|
|
2866
|
+
nums.push(null);
|
|
2867
|
+
} else nums.push(+part);
|
|
2868
|
+
}
|
|
2869
|
+
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
2870
|
+
}
|
|
2871
|
+
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
2872
|
+
function comparators(token) {
|
|
2873
|
+
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
2874
|
+
if (!m) return null;
|
|
2875
|
+
const op = m[1] ?? "";
|
|
2876
|
+
const p = partial(m[2]);
|
|
2877
|
+
if (!p) return null;
|
|
2878
|
+
const [major, mi, pa] = p.nums;
|
|
2879
|
+
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
2880
|
+
const M = major;
|
|
2881
|
+
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
2882
|
+
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
2883
|
+
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
2884
|
+
const out = switchOp();
|
|
2885
|
+
if (p.pre.length) {
|
|
2886
|
+
for (const c of out) if (c.v === lo) c.pre = true;
|
|
2887
|
+
}
|
|
2888
|
+
return out;
|
|
2889
|
+
function switchOp() {
|
|
2890
|
+
switch (op) {
|
|
2891
|
+
case "^": {
|
|
2892
|
+
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
2893
|
+
return [
|
|
2894
|
+
{ op: ">=", v: lo },
|
|
2895
|
+
{ op: "<", v: bound }
|
|
2896
|
+
];
|
|
2897
|
+
}
|
|
2898
|
+
case "~":
|
|
2899
|
+
case "~>":
|
|
2900
|
+
return [
|
|
2901
|
+
{ op: ">=", v: lo },
|
|
2902
|
+
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
2903
|
+
];
|
|
2904
|
+
case ">":
|
|
2905
|
+
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
2906
|
+
case ">=":
|
|
2907
|
+
return [{ op: ">=", v: lo }];
|
|
2908
|
+
case "<":
|
|
2909
|
+
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
2910
|
+
case "<=":
|
|
2911
|
+
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
2912
|
+
default:
|
|
2913
|
+
return upper ? [
|
|
2914
|
+
{ op: ">=", v: lo },
|
|
2915
|
+
{ op: "<", v: upper }
|
|
2916
|
+
] : [{ op: "=", v: lo }];
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
function test(c, v) {
|
|
2921
|
+
const d = compareVersions(v, c.v);
|
|
2922
|
+
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
2923
|
+
}
|
|
2924
|
+
function parseRange(range) {
|
|
2925
|
+
const alts = [];
|
|
2926
|
+
for (const raw of range.trim().split("||")) {
|
|
2927
|
+
const alt = raw.trim();
|
|
2928
|
+
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
2929
|
+
if (hyphen) {
|
|
2930
|
+
const from = comparators(`>=${hyphen[1]}`);
|
|
2931
|
+
const to = comparators(`<=${hyphen[2]}`);
|
|
2932
|
+
if (!from || !to) return null;
|
|
2933
|
+
alts.push([...from, ...to]);
|
|
2934
|
+
continue;
|
|
2935
|
+
}
|
|
2936
|
+
const set = [];
|
|
2937
|
+
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
2938
|
+
const cs = comparators(token);
|
|
2939
|
+
if (!cs) return null;
|
|
2940
|
+
set.push(...cs);
|
|
2941
|
+
}
|
|
2942
|
+
alts.push(set);
|
|
2943
|
+
}
|
|
2944
|
+
return alts;
|
|
2945
|
+
}
|
|
2946
|
+
function satisfies(version, range) {
|
|
2947
|
+
const v = parseVersion(version);
|
|
2948
|
+
const alts = parseRange(range);
|
|
2949
|
+
if (!v || !alts) return null;
|
|
2950
|
+
return alts.some(
|
|
2951
|
+
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
2952
|
+
);
|
|
2953
|
+
}
|
|
2954
|
+
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
2955
|
+
function readReleaseManifest(root) {
|
|
2956
|
+
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
2957
|
+
const file = dir && path20.join(dir, "dist", "versions.json");
|
|
2958
|
+
if (!file || !existsSync(file)) return null;
|
|
2959
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
2960
|
+
}
|
|
2961
|
+
function checkVersionSkew(ctx) {
|
|
2962
|
+
const manifest = readReleaseManifest(ctx.root);
|
|
2963
|
+
if (!manifest) return;
|
|
2964
|
+
const overlays = markedOverlays(ctx);
|
|
2965
|
+
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
2966
|
+
const overlay = overlays.get(name);
|
|
2967
|
+
if (overlay) {
|
|
2968
|
+
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
2969
|
+
const behind = parseVersion(from) && parseVersion(want) && compareVersions(parseVersion(from), parseVersion(want)) < 0;
|
|
2970
|
+
if (from !== want && !behind) {
|
|
2971
|
+
ctx.report({
|
|
2972
|
+
rule: "version-skew",
|
|
2973
|
+
level: "warn",
|
|
2974
|
+
file: "package.json",
|
|
2975
|
+
subject: name,
|
|
2976
|
+
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).`
|
|
2977
|
+
});
|
|
2978
|
+
}
|
|
2979
|
+
continue;
|
|
2980
|
+
}
|
|
2981
|
+
const dir = findPackageDir(ctx.root, name);
|
|
2982
|
+
if (!dir) continue;
|
|
2983
|
+
const have = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8")).version;
|
|
2984
|
+
if (have === want) continue;
|
|
2985
|
+
ctx.report({
|
|
2986
|
+
rule: "version-skew",
|
|
2987
|
+
level: "warn",
|
|
2988
|
+
file: "package.json",
|
|
2989
|
+
subject: name,
|
|
2990
|
+
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2991
|
+
});
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
// src/doctor/overlays.ts
|
|
2751
2996
|
var GENESIS_PACKAGE_NAME = /^@marktiderman\/genesis(?:-[a-z0-9-]+)?$/;
|
|
2752
2997
|
var OVERLAY_NOTICE_DAYS = 14;
|
|
2753
2998
|
var OVERLAY_WARN_DAYS = 30;
|
|
@@ -2761,7 +3006,7 @@ function overlayState(name, json) {
|
|
|
2761
3006
|
function overlaySetupProblems(root, config, dir, name, json) {
|
|
2762
3007
|
const problems = [];
|
|
2763
3008
|
if (json.private !== true) problems.push(`${name}: an overlay is the app's own copy and never publishes; set "private": true`);
|
|
2764
|
-
const rel =
|
|
3009
|
+
const rel = path20.relative(path20.resolve(root), path20.resolve(dir)).split(path20.sep).join("/");
|
|
2765
3010
|
const sources = (config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)).map((s) => s.replace(/^\.\//, "").replace(/\/+$/, ""));
|
|
2766
3011
|
const holds = sources.find((s) => rel === "" || s === rel || s.startsWith(`${rel}/`));
|
|
2767
3012
|
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})`);
|
|
@@ -2786,6 +3031,31 @@ function overlayAgeDays(since, now = /* @__PURE__ */ new Date()) {
|
|
|
2786
3031
|
return Math.floor((today - Date.UTC(y, m - 1, d)) / 864e5);
|
|
2787
3032
|
}
|
|
2788
3033
|
var LOCAL_VERSION = /^(\d+\.\d+\.\d+(?:-(?!local\.)[0-9A-Za-z.-]+?)?)(?:[+-]local\.(?:0|[1-9]\d*))?$/;
|
|
3034
|
+
function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
3035
|
+
let manifest = null;
|
|
3036
|
+
try {
|
|
3037
|
+
manifest = readReleaseManifest(root);
|
|
3038
|
+
} catch {
|
|
3039
|
+
}
|
|
3040
|
+
const released = manifest?.packages[name];
|
|
3041
|
+
if (released && parseVersion(released)) return released;
|
|
3042
|
+
let best = null;
|
|
3043
|
+
for (const file of manifests) {
|
|
3044
|
+
let json;
|
|
3045
|
+
try {
|
|
3046
|
+
json = JSON.parse(readFileSync(path20.join(root, file), "utf8"));
|
|
3047
|
+
} catch {
|
|
3048
|
+
continue;
|
|
3049
|
+
}
|
|
3050
|
+
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
3051
|
+
const spec = json[section]?.[name];
|
|
3052
|
+
const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
|
|
3053
|
+
const parsed = v && parseVersion(v);
|
|
3054
|
+
if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
return best;
|
|
3058
|
+
}
|
|
2789
3059
|
function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
2790
3060
|
let packages;
|
|
2791
3061
|
try {
|
|
@@ -2798,7 +3068,7 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
|
2798
3068
|
const file = `${pkg.rel}/package.json`;
|
|
2799
3069
|
let json;
|
|
2800
3070
|
try {
|
|
2801
|
-
json = JSON.parse(readFileSync(
|
|
3071
|
+
json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
2802
3072
|
} catch {
|
|
2803
3073
|
continue;
|
|
2804
3074
|
}
|
|
@@ -2841,6 +3111,18 @@ function checkOverlays(ctx, now = /* @__PURE__ */ new Date()) {
|
|
|
2841
3111
|
message: `the overlay of ${marker.upstream} is version ${version || "(none)"}; use ${upstream}+local.N (or ${upstream} itself) so it reads as a local build of ${upstream} and still satisfies peer ranges`
|
|
2842
3112
|
});
|
|
2843
3113
|
}
|
|
3114
|
+
const pinned = pinnedVersion(ctx.root, pkg.name);
|
|
3115
|
+
const from = parseVersion(upstream);
|
|
3116
|
+
const to = pinned ? parseVersion(pinned) : null;
|
|
3117
|
+
if (from && to && compareVersions(from, to) < 0) {
|
|
3118
|
+
ctx.report({
|
|
3119
|
+
rule: "overlay-behind",
|
|
3120
|
+
level: "warn",
|
|
3121
|
+
file,
|
|
3122
|
+
subject: pkg.name,
|
|
3123
|
+
message: `the overlay of ${marker.upstream} is behind ${pkg.name}@${pinned}, the version the app now pins; run genesis upgrade, which rebases the overlay onto it (dropping what Genesis now ships) and moves the marker's upstream, or rebase it by hand`
|
|
3124
|
+
});
|
|
3125
|
+
}
|
|
2844
3126
|
}
|
|
2845
3127
|
}
|
|
2846
3128
|
|
|
@@ -2904,6 +3186,7 @@ var BUILTIN_RULES = [
|
|
|
2904
3186
|
"overlay-invalid",
|
|
2905
3187
|
"overlay-age",
|
|
2906
3188
|
"overlay-version",
|
|
3189
|
+
"overlay-behind",
|
|
2907
3190
|
// package rules (package-rules.ts): the rules themselves are namespaced, e.g. ui/lists-use-resource-view
|
|
2908
3191
|
"package-rules-invalid",
|
|
2909
3192
|
"package-rule-override",
|
|
@@ -2914,7 +3197,11 @@ var BUILTIN_RULES = [
|
|
|
2914
3197
|
// agent guide (primitives.ts)
|
|
2915
3198
|
"agent-guide-stale",
|
|
2916
3199
|
// supabase pack: contracts (contracts.ts)
|
|
2917
|
-
"contracts-stale"
|
|
3200
|
+
"contracts-stale",
|
|
3201
|
+
// genesis.lock.json against the files (lock-files.ts)
|
|
3202
|
+
"lock-files",
|
|
3203
|
+
// an app whose database files live in another app (database.ts)
|
|
3204
|
+
"database-elsewhere"
|
|
2918
3205
|
];
|
|
2919
3206
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
2920
3207
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -2932,7 +3219,7 @@ function importSpecifiers(file) {
|
|
|
2932
3219
|
}
|
|
2933
3220
|
function checkProjectLayout(ctx) {
|
|
2934
3221
|
for (const dir of ctx.config.localPrimitiveDirs ?? DEFAULT_LOCAL_PRIMITIVE_DIRS) {
|
|
2935
|
-
if (existsSync(
|
|
3222
|
+
if (existsSync(path20.join(ctx.root, dir))) {
|
|
2936
3223
|
ctx.report({
|
|
2937
3224
|
rule: "local-primitives",
|
|
2938
3225
|
file: dir,
|
|
@@ -2942,7 +3229,7 @@ function checkProjectLayout(ctx) {
|
|
|
2942
3229
|
}
|
|
2943
3230
|
}
|
|
2944
3231
|
for (const file of STARTER_LEFTOVERS) {
|
|
2945
|
-
if (existsSync(
|
|
3232
|
+
if (existsSync(path20.join(ctx.root, file))) {
|
|
2946
3233
|
ctx.report({
|
|
2947
3234
|
rule: "starter-leftover",
|
|
2948
3235
|
level: "warn",
|
|
@@ -3032,7 +3319,7 @@ function checkTokens(ctx) {
|
|
|
3032
3319
|
}
|
|
3033
3320
|
for (const pattern of ctx.config.tokenFiles ?? []) {
|
|
3034
3321
|
if (/[*?]/.test(pattern)) continue;
|
|
3035
|
-
const abs =
|
|
3322
|
+
const abs = path20.join(ctx.root, pattern);
|
|
3036
3323
|
if (!ctx.files.some((f) => f.absolutePath === abs) && existsSync(abs)) {
|
|
3037
3324
|
for (const t of declaredTokens(readFileSync(abs, "utf8"))) defined.add(t);
|
|
3038
3325
|
}
|
|
@@ -3132,14 +3419,33 @@ var appFunctionality = (type, ...more) => ({
|
|
|
3132
3419
|
function privacyApisFor(dependencies2) {
|
|
3133
3420
|
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
3134
3421
|
}
|
|
3422
|
+
|
|
3423
|
+
// src/eas-placeholders.ts
|
|
3424
|
+
var EAS_PLACEHOLDERS = {
|
|
3425
|
+
REPLACE_WITH_APP_STORE_CONNECT_APP_ID: "the app's Apple ID from App Store Connect (create the app there, then App Information \u2192 General Information \u2192 Apple ID, a number)",
|
|
3426
|
+
REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
|
|
3427
|
+
REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the Google Play service account key uploaded to EAS, not a local path (deploy-production.yml submits on EAS, where a local file isn't there): create a Google Cloud service account and its JSON key, invite it in Play Console \u2192 Users and permissions, upload the key with `eas credentials` (Android \u2192 Google Service Account), then remove only this serviceAccountKeyPath line (https://docs.expo.dev/submit/android/). Until you ship to Google Play, remove the submit_android job from deploy-production.yml instead, and keep submit.production.android as it is (the internal track, as a draft)",
|
|
3428
|
+
REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
|
|
3429
|
+
};
|
|
3430
|
+
function placeholderKey(line, placeholder) {
|
|
3431
|
+
return new RegExp(`"([A-Za-z0-9_]+)"\\s*:\\s*"${placeholder}"`).exec(line)?.[1] ?? null;
|
|
3432
|
+
}
|
|
3433
|
+
function findPlaceholders(file, text) {
|
|
3434
|
+
const out = [];
|
|
3435
|
+
text.split("\n").forEach((line, i) => {
|
|
3436
|
+
if (!file.endsWith(".json") && /^\s*#/.test(line)) return;
|
|
3437
|
+
for (const m of line.matchAll(/\bREPLACE_WITH_[A-Z0-9_]+/g)) out.push({ line: i + 1, text: line, placeholder: m[0] });
|
|
3438
|
+
});
|
|
3439
|
+
return out;
|
|
3440
|
+
}
|
|
3135
3441
|
var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
3136
3442
|
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
3137
3443
|
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
3138
3444
|
function resolveLocal(root, fromFile, spec) {
|
|
3139
|
-
const bases = spec.startsWith(".") ? [
|
|
3445
|
+
const bases = spec.startsWith(".") ? [path20.resolve(path20.dirname(fromFile), spec)] : [path20.join(root, spec.slice(2)), path20.join(root, "src", spec.slice(2))];
|
|
3140
3446
|
for (const base of bases) {
|
|
3141
|
-
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) =>
|
|
3142
|
-
(p) => SCRIPT_EXTS2.has(
|
|
3447
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path20.join(base, `index${e}`))].find(
|
|
3448
|
+
(p) => SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p)
|
|
3143
3449
|
);
|
|
3144
3450
|
if (hit) return hit;
|
|
3145
3451
|
}
|
|
@@ -3258,29 +3564,26 @@ function checkNativePack(ctx) {
|
|
|
3258
3564
|
checkStoreReadiness(ctx);
|
|
3259
3565
|
checkEasPlaceholders(ctx);
|
|
3260
3566
|
}
|
|
3261
|
-
var EAS_PLACEHOLDER = /\bREPLACE_WITH_[A-Z0-9_]+/g;
|
|
3262
3567
|
function checkEasPlaceholders(ctx) {
|
|
3263
3568
|
const files = [];
|
|
3264
|
-
if (existsSync(
|
|
3265
|
-
const workflows =
|
|
3569
|
+
if (existsSync(path20.join(ctx.root, "eas.json"))) files.push("eas.json");
|
|
3570
|
+
const workflows = path20.join(ctx.root, ".eas", "workflows");
|
|
3266
3571
|
if (existsSync(workflows)) {
|
|
3267
3572
|
for (const name of readdirSync(workflows).sort()) if (/\.ya?ml$/.test(name)) files.push(`.eas/workflows/${name}`);
|
|
3268
3573
|
}
|
|
3269
3574
|
for (const file of files) {
|
|
3270
|
-
const
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
}
|
|
3283
|
-
});
|
|
3575
|
+
for (const hit of findPlaceholders(file, readFileSync(path20.join(ctx.root, file), "utf8"))) {
|
|
3576
|
+
const key2 = placeholderKey(hit.text, hit.placeholder);
|
|
3577
|
+
const what = EAS_PLACEHOLDERS[hit.placeholder];
|
|
3578
|
+
ctx.report({
|
|
3579
|
+
rule: "eas-placeholder",
|
|
3580
|
+
level: "warn",
|
|
3581
|
+
file,
|
|
3582
|
+
line: hit.line,
|
|
3583
|
+
subject: hit.placeholder,
|
|
3584
|
+
message: hit.placeholder === "REPLACE_WITH_APP_FOLDER" ? `still names REPLACE_WITH_APP_FOLDER, so only config changes start a preview; replace it with ${what}` : `${key2 ? `${key2} is` : "still has"} the template placeholder ${hit.placeholder}; replace it with ${what ?? "its value (see docs/NATIVE-RELEASE.md in the Genesis repository)"} before the job that reads it runs`
|
|
3585
|
+
});
|
|
3586
|
+
}
|
|
3284
3587
|
}
|
|
3285
3588
|
}
|
|
3286
3589
|
var RN = String.raw`["']react-native["']`;
|
|
@@ -3348,7 +3651,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3348
3651
|
if (!JSX_EXTS3.has(file.ext)) continue;
|
|
3349
3652
|
const code = file.code;
|
|
3350
3653
|
const hidden = HIDES_HEADER.exec(code);
|
|
3351
|
-
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(
|
|
3654
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path20.posix.dirname(file.path), file.path);
|
|
3352
3655
|
const own = hidden ? ownHeader(code, pkg) : null;
|
|
3353
3656
|
if (hidden && own) {
|
|
3354
3657
|
reported.add(file.path);
|
|
@@ -3376,7 +3679,7 @@ function checkCustomHeaders(ctx, pkg) {
|
|
|
3376
3679
|
}
|
|
3377
3680
|
for (const file of ctx.files) {
|
|
3378
3681
|
if (!JSX_EXTS3.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
3379
|
-
const layout = hidingLayouts.get(
|
|
3682
|
+
const layout = hidingLayouts.get(path20.posix.dirname(file.path));
|
|
3380
3683
|
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
3381
3684
|
if (!layout || !own) continue;
|
|
3382
3685
|
ctx.report({
|
|
@@ -3398,13 +3701,13 @@ function isLoadingOnlyRoute(code) {
|
|
|
3398
3701
|
}
|
|
3399
3702
|
function routerRoot(ctx) {
|
|
3400
3703
|
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
3401
|
-
return existsSync(
|
|
3704
|
+
return existsSync(path20.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
3402
3705
|
}
|
|
3403
3706
|
function checkScreenLayouts(ctx, pkg) {
|
|
3404
3707
|
const layouts = nativeLayouts(pkg);
|
|
3405
3708
|
if (layouts.length === 0) return;
|
|
3406
3709
|
const rootDir = routerRoot(ctx);
|
|
3407
|
-
if (!existsSync(
|
|
3710
|
+
if (!existsSync(path20.join(ctx.root, rootDir))) {
|
|
3408
3711
|
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
3409
3712
|
return;
|
|
3410
3713
|
}
|
|
@@ -3460,7 +3763,7 @@ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\
|
|
|
3460
3763
|
function readExpoConfigs(root) {
|
|
3461
3764
|
const out = [];
|
|
3462
3765
|
for (const name of EXPO_CONFIGS) {
|
|
3463
|
-
const abs =
|
|
3766
|
+
const abs = path20.join(root, name);
|
|
3464
3767
|
if (!existsSync(abs)) continue;
|
|
3465
3768
|
const text = readFileSync(abs, "utf8");
|
|
3466
3769
|
let json = null;
|
|
@@ -3494,13 +3797,13 @@ function pluginOptions(json, module) {
|
|
|
3494
3797
|
return null;
|
|
3495
3798
|
}
|
|
3496
3799
|
function dependencies(root) {
|
|
3497
|
-
const file =
|
|
3800
|
+
const file = path20.join(root, "package.json");
|
|
3498
3801
|
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
3499
3802
|
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
3500
3803
|
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
3501
3804
|
}
|
|
3502
3805
|
function runtimeDependencies(root) {
|
|
3503
|
-
const file =
|
|
3806
|
+
const file = path20.join(root, "package.json");
|
|
3504
3807
|
if (!existsSync(file)) return {};
|
|
3505
3808
|
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
3506
3809
|
}
|
|
@@ -3581,126 +3884,6 @@ function checkStoreReadiness(ctx) {
|
|
|
3581
3884
|
});
|
|
3582
3885
|
}
|
|
3583
3886
|
}
|
|
3584
|
-
|
|
3585
|
-
// src/doctor/semver.ts
|
|
3586
|
-
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
3587
|
-
function parseVersion(v) {
|
|
3588
|
-
const m = VERSION.exec(v.trim());
|
|
3589
|
-
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
3590
|
-
}
|
|
3591
|
-
function compareVersions(a, b) {
|
|
3592
|
-
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
3593
|
-
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
3594
|
-
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
3595
|
-
const x = a.pre[i];
|
|
3596
|
-
const y = b.pre[i];
|
|
3597
|
-
if (x === void 0) return -1;
|
|
3598
|
-
if (y === void 0) return 1;
|
|
3599
|
-
if (x === y) continue;
|
|
3600
|
-
const nx = /^\d+$/.test(x);
|
|
3601
|
-
const ny = /^\d+$/.test(y);
|
|
3602
|
-
if (nx && ny) return +x < +y ? -1 : 1;
|
|
3603
|
-
if (nx !== ny) return nx ? -1 : 1;
|
|
3604
|
-
return x < y ? -1 : 1;
|
|
3605
|
-
}
|
|
3606
|
-
return 0;
|
|
3607
|
-
}
|
|
3608
|
-
function partial(s) {
|
|
3609
|
-
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
3610
|
-
if (!m) return null;
|
|
3611
|
-
const nums = [];
|
|
3612
|
-
let wild = false;
|
|
3613
|
-
for (const part of [m[1], m[2], m[3]]) {
|
|
3614
|
-
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
3615
|
-
wild = true;
|
|
3616
|
-
nums.push(null);
|
|
3617
|
-
} else nums.push(+part);
|
|
3618
|
-
}
|
|
3619
|
-
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
3620
|
-
}
|
|
3621
|
-
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
3622
|
-
function comparators(token) {
|
|
3623
|
-
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
3624
|
-
if (!m) return null;
|
|
3625
|
-
const op = m[1] ?? "";
|
|
3626
|
-
const p = partial(m[2]);
|
|
3627
|
-
if (!p) return null;
|
|
3628
|
-
const [major, mi, pa] = p.nums;
|
|
3629
|
-
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
3630
|
-
const M = major;
|
|
3631
|
-
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
3632
|
-
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
3633
|
-
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
3634
|
-
const out = switchOp();
|
|
3635
|
-
if (p.pre.length) {
|
|
3636
|
-
for (const c of out) if (c.v === lo) c.pre = true;
|
|
3637
|
-
}
|
|
3638
|
-
return out;
|
|
3639
|
-
function switchOp() {
|
|
3640
|
-
switch (op) {
|
|
3641
|
-
case "^": {
|
|
3642
|
-
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
3643
|
-
return [
|
|
3644
|
-
{ op: ">=", v: lo },
|
|
3645
|
-
{ op: "<", v: bound }
|
|
3646
|
-
];
|
|
3647
|
-
}
|
|
3648
|
-
case "~":
|
|
3649
|
-
case "~>":
|
|
3650
|
-
return [
|
|
3651
|
-
{ op: ">=", v: lo },
|
|
3652
|
-
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
3653
|
-
];
|
|
3654
|
-
case ">":
|
|
3655
|
-
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
3656
|
-
case ">=":
|
|
3657
|
-
return [{ op: ">=", v: lo }];
|
|
3658
|
-
case "<":
|
|
3659
|
-
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
3660
|
-
case "<=":
|
|
3661
|
-
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
3662
|
-
default:
|
|
3663
|
-
return upper ? [
|
|
3664
|
-
{ op: ">=", v: lo },
|
|
3665
|
-
{ op: "<", v: upper }
|
|
3666
|
-
] : [{ op: "=", v: lo }];
|
|
3667
|
-
}
|
|
3668
|
-
}
|
|
3669
|
-
}
|
|
3670
|
-
function test(c, v) {
|
|
3671
|
-
const d = compareVersions(v, c.v);
|
|
3672
|
-
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
3673
|
-
}
|
|
3674
|
-
function parseRange(range) {
|
|
3675
|
-
const alts = [];
|
|
3676
|
-
for (const raw of range.trim().split("||")) {
|
|
3677
|
-
const alt = raw.trim();
|
|
3678
|
-
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
3679
|
-
if (hyphen) {
|
|
3680
|
-
const from = comparators(`>=${hyphen[1]}`);
|
|
3681
|
-
const to = comparators(`<=${hyphen[2]}`);
|
|
3682
|
-
if (!from || !to) return null;
|
|
3683
|
-
alts.push([...from, ...to]);
|
|
3684
|
-
continue;
|
|
3685
|
-
}
|
|
3686
|
-
const set = [];
|
|
3687
|
-
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
3688
|
-
const cs = comparators(token);
|
|
3689
|
-
if (!cs) return null;
|
|
3690
|
-
set.push(...cs);
|
|
3691
|
-
}
|
|
3692
|
-
alts.push(set);
|
|
3693
|
-
}
|
|
3694
|
-
return alts;
|
|
3695
|
-
}
|
|
3696
|
-
function satisfies(version, range) {
|
|
3697
|
-
const v = parseVersion(version);
|
|
3698
|
-
const alts = parseRange(range);
|
|
3699
|
-
if (!v || !alts) return null;
|
|
3700
|
-
return alts.some(
|
|
3701
|
-
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
3702
|
-
);
|
|
3703
|
-
}
|
|
3704
3887
|
var TRAIL_DEPTH = 6;
|
|
3705
3888
|
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
3706
3889
|
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
@@ -3874,14 +4057,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3874
4057
|
seen.add(file);
|
|
3875
4058
|
const json = readJsonc(file);
|
|
3876
4059
|
if (!json) return {};
|
|
3877
|
-
const dir =
|
|
4060
|
+
const dir = path20.dirname(file);
|
|
3878
4061
|
let merged = {};
|
|
3879
4062
|
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
3880
4063
|
for (const ext of parents) {
|
|
3881
4064
|
if (typeof ext !== "string") continue;
|
|
3882
4065
|
let target = null;
|
|
3883
|
-
if (ext.startsWith(".") ||
|
|
3884
|
-
const abs =
|
|
4066
|
+
if (ext.startsWith(".") || path20.isAbsolute(ext)) {
|
|
4067
|
+
const abs = path20.resolve(dir, ext);
|
|
3885
4068
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3886
4069
|
} else {
|
|
3887
4070
|
const parts = ext.split("/");
|
|
@@ -3889,14 +4072,14 @@ function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
|
3889
4072
|
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
3890
4073
|
if (pkgDir) {
|
|
3891
4074
|
const sub = parts.slice(nameLength).join("/");
|
|
3892
|
-
const abs =
|
|
4075
|
+
const abs = path20.join(pkgDir, sub || "tsconfig.json");
|
|
3893
4076
|
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
3894
4077
|
}
|
|
3895
4078
|
}
|
|
3896
4079
|
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
3897
4080
|
}
|
|
3898
4081
|
const opts = json.compilerOptions ?? {};
|
|
3899
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl =
|
|
4082
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path20.resolve(dir, opts.baseUrl);
|
|
3900
4083
|
if (opts.paths && typeof opts.paths === "object") {
|
|
3901
4084
|
merged.paths = opts.paths;
|
|
3902
4085
|
merged.pathsDir = dir;
|
|
@@ -3907,7 +4090,7 @@ function aliases(root) {
|
|
|
3907
4090
|
const table = [];
|
|
3908
4091
|
let baseUrl = null;
|
|
3909
4092
|
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
3910
|
-
const file =
|
|
4093
|
+
const file = path20.join(root, name);
|
|
3911
4094
|
if (!existsSync(file)) continue;
|
|
3912
4095
|
const config = readTsconfig(root, file);
|
|
3913
4096
|
baseUrl ??= config.baseUrl ?? null;
|
|
@@ -3915,22 +4098,22 @@ function aliases(root) {
|
|
|
3915
4098
|
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
3916
4099
|
if (!Array.isArray(targets)) continue;
|
|
3917
4100
|
const exact = !pattern.endsWith("*");
|
|
3918
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) =>
|
|
4101
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path20.join(base, String(t).replace(/\*$/, ""))) });
|
|
3919
4102
|
}
|
|
3920
4103
|
}
|
|
3921
|
-
const pkg = readJsonc(
|
|
4104
|
+
const pkg = readJsonc(path20.join(root, "package.json"));
|
|
3922
4105
|
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
3923
4106
|
if (typeof target !== "string") continue;
|
|
3924
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [
|
|
4107
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path20.join(root, target.replace(/\*.*$/, ""))] });
|
|
3925
4108
|
}
|
|
3926
|
-
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [
|
|
4109
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path20.join(root, "src") + path20.sep, root + path20.sep] });
|
|
3927
4110
|
return { table, baseUrl };
|
|
3928
4111
|
}
|
|
3929
4112
|
function resolveFile(base) {
|
|
3930
|
-
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) =>
|
|
4113
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path20.join(base, `index${e}`))];
|
|
3931
4114
|
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
3932
4115
|
for (const p of tries) {
|
|
3933
|
-
if (SCRIPT_EXTS2.has(
|
|
4116
|
+
if (SCRIPT_EXTS2.has(path20.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
3934
4117
|
}
|
|
3935
4118
|
return null;
|
|
3936
4119
|
}
|
|
@@ -3944,7 +4127,7 @@ function createTrail(ctx) {
|
|
|
3944
4127
|
const { table, baseUrl } = aliases(ctx.root);
|
|
3945
4128
|
let declared = null;
|
|
3946
4129
|
try {
|
|
3947
|
-
const pkg = JSON.parse(readFileSync(
|
|
4130
|
+
const pkg = JSON.parse(readFileSync(path20.join(ctx.root, "package.json"), "utf8"));
|
|
3948
4131
|
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3949
4132
|
} catch {
|
|
3950
4133
|
declared = null;
|
|
@@ -3975,17 +4158,17 @@ function createTrail(ctx) {
|
|
|
3975
4158
|
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
3976
4159
|
let resolved = null;
|
|
3977
4160
|
if (spec.startsWith(".")) {
|
|
3978
|
-
resolved = resolveFile(
|
|
4161
|
+
resolved = resolveFile(path20.resolve(path20.dirname(file.absolutePath), spec));
|
|
3979
4162
|
if (!resolved) lost = true;
|
|
3980
4163
|
} else {
|
|
3981
4164
|
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
3982
4165
|
if (alias) {
|
|
3983
4166
|
for (const t of alias.targets) {
|
|
3984
|
-
resolved = resolveFile(alias.exact ? t :
|
|
4167
|
+
resolved = resolveFile(alias.exact ? t : path20.join(t, spec.slice(alias.prefix.length)));
|
|
3985
4168
|
if (resolved) break;
|
|
3986
4169
|
}
|
|
3987
4170
|
}
|
|
3988
|
-
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(
|
|
4171
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path20.join(baseUrl, spec));
|
|
3989
4172
|
if (!resolved) {
|
|
3990
4173
|
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
3991
4174
|
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
@@ -4056,27 +4239,159 @@ function createTrail(ctx) {
|
|
|
4056
4239
|
};
|
|
4057
4240
|
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
4058
4241
|
}
|
|
4242
|
+
function buildCatalog(packagesDir) {
|
|
4243
|
+
const packages = {};
|
|
4244
|
+
for (const dir of readdirSync(packagesDir).sort()) {
|
|
4245
|
+
const file = path20.join(packagesDir, dir, "package.json");
|
|
4246
|
+
if (!existsSync(file)) continue;
|
|
4247
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
4248
|
+
if (!pkg.name || !pkg.version || pkg.private || !pkg.name.startsWith("@marktiderman/genesis")) continue;
|
|
4249
|
+
packages[pkg.name] = { version: pkg.version, ...pkg.genesis?.blocks ? { blocks: pkg.genesis.blocks } : {} };
|
|
4250
|
+
}
|
|
4251
|
+
return { packages };
|
|
4252
|
+
}
|
|
4059
4253
|
|
|
4060
4254
|
// src/blocks/discover.ts
|
|
4255
|
+
var CLI_PACKAGE = "@marktiderman/genesis-cli";
|
|
4256
|
+
function cliPackageDir() {
|
|
4257
|
+
let dir = path20.dirname(fileURLToPath(import.meta.url));
|
|
4258
|
+
for (; ; ) {
|
|
4259
|
+
const file = path20.join(dir, "package.json");
|
|
4260
|
+
if (existsSync(file) && JSON.parse(readFileSync(file, "utf8")).name === CLI_PACKAGE) return dir;
|
|
4261
|
+
const parent = path20.dirname(dir);
|
|
4262
|
+
if (parent === dir) throw new Error("Can't find the genesis-cli package folder.");
|
|
4263
|
+
dir = parent;
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
function workspacePackagesDir() {
|
|
4267
|
+
const dir = path20.resolve(cliPackageDir(), "..");
|
|
4268
|
+
return existsSync(path20.join(dir, "features", "package.json")) && existsSync(path20.join(dir, "..", "pnpm-workspace.yaml")) ? dir : null;
|
|
4269
|
+
}
|
|
4270
|
+
var catalogCache;
|
|
4271
|
+
function readCatalog() {
|
|
4272
|
+
if (catalogCache) return catalogCache;
|
|
4273
|
+
const workspace = workspacePackagesDir();
|
|
4274
|
+
if (workspace) return catalogCache = buildCatalog(workspace);
|
|
4275
|
+
const file = path20.join(cliPackageDir(), "dist", "genesis-catalog.json");
|
|
4276
|
+
catalogCache = existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : { packages: {} };
|
|
4277
|
+
return catalogCache;
|
|
4278
|
+
}
|
|
4061
4279
|
var INSTALL_ROOT_MARKERS = [".git", "pnpm-lock.yaml", "pnpm-workspace.yaml", "bun.lock", "bun.lockb", "yarn.lock", "package-lock.json"];
|
|
4062
4280
|
function installedGenesis(root) {
|
|
4063
4281
|
const found = /* @__PURE__ */ new Map();
|
|
4064
|
-
let dir =
|
|
4282
|
+
let dir = path20.resolve(root);
|
|
4065
4283
|
for (; ; ) {
|
|
4066
|
-
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(
|
|
4067
|
-
const scope =
|
|
4284
|
+
const atInstallRoot = INSTALL_ROOT_MARKERS.some((m) => existsSync(path20.join(dir, m)));
|
|
4285
|
+
const scope = path20.join(dir, "node_modules", "@marktiderman");
|
|
4068
4286
|
if (existsSync(scope)) {
|
|
4069
4287
|
for (const entry of readdirSync(scope)) {
|
|
4070
4288
|
const name = `@marktiderman/${entry}`;
|
|
4071
4289
|
if (!GENESIS_PACKAGE.test(name) || found.has(name)) continue;
|
|
4072
|
-
if (existsSync(
|
|
4290
|
+
if (existsSync(path20.join(scope, entry, "package.json"))) found.set(name, path20.join(scope, entry));
|
|
4073
4291
|
}
|
|
4074
4292
|
}
|
|
4075
|
-
const parent =
|
|
4293
|
+
const parent = path20.dirname(dir);
|
|
4076
4294
|
if (atInstallRoot || parent === dir) return found;
|
|
4077
4295
|
dir = parent;
|
|
4078
4296
|
}
|
|
4079
4297
|
}
|
|
4298
|
+
var declarationCache = /* @__PURE__ */ new Map();
|
|
4299
|
+
function declarationsOf(dir, warnings) {
|
|
4300
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4301
|
+
const key2 = `${realpathSync(dir)}@${pkg.version ?? ""}`;
|
|
4302
|
+
let cached = declarationCache.get(key2);
|
|
4303
|
+
if (!cached) {
|
|
4304
|
+
cached = loadDeclarations(dir, warnings);
|
|
4305
|
+
declarationCache.set(key2, cached);
|
|
4306
|
+
}
|
|
4307
|
+
return cached;
|
|
4308
|
+
}
|
|
4309
|
+
async function loadDeclarations(dir, warnings) {
|
|
4310
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4311
|
+
const entry = pkg.exports?.["./blocks"];
|
|
4312
|
+
const target = typeof entry === "string" ? entry : entry && typeof entry === "object" ? entry["import"] ?? entry["default"] : void 0;
|
|
4313
|
+
if (typeof target !== "string") return {};
|
|
4314
|
+
const rel = safeRelative(target.replace(/^\.\//, ""));
|
|
4315
|
+
const file = rel && path20.join(dir, ...rel.split("/"));
|
|
4316
|
+
if (!file || !inside(dir, file) || !existsSync(file)) return {};
|
|
4317
|
+
try {
|
|
4318
|
+
const jiti = createJiti(path20.join(dir, "package.json"), { moduleCache: false });
|
|
4319
|
+
const mod = await jiti.import(file);
|
|
4320
|
+
const out = {};
|
|
4321
|
+
for (const value of Object.values(mod)) if (isBlockDef(value)) out[value.id] = declarationFields(value);
|
|
4322
|
+
return out;
|
|
4323
|
+
} catch (err) {
|
|
4324
|
+
warnings.push(`${pkg.name}/blocks didn't load in Node (${err instanceof Error ? err.message.split("\n")[0] : String(err)}); using its package.json manifest only.`);
|
|
4325
|
+
return {};
|
|
4326
|
+
}
|
|
4327
|
+
}
|
|
4328
|
+
async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
4329
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
4330
|
+
const raw = rawBlocksOf(pkg);
|
|
4331
|
+
const declared = await declarationsOf(dir, warnings);
|
|
4332
|
+
const ids = /* @__PURE__ */ new Set([...Object.keys(raw), ...Object.keys(declared)]);
|
|
4333
|
+
const out = [];
|
|
4334
|
+
for (const id of [...ids].sort()) {
|
|
4335
|
+
const fromJson = raw[id] ?? {};
|
|
4336
|
+
const merged = { ...fromJson, ...declared[id] };
|
|
4337
|
+
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
4338
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
4339
|
+
if (manifest) out.push(manifest);
|
|
4340
|
+
}
|
|
4341
|
+
return out;
|
|
4342
|
+
}
|
|
4343
|
+
function withProvides(declared, json) {
|
|
4344
|
+
if (!Array.isArray(declared)) return declared;
|
|
4345
|
+
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
4346
|
+
return declared.map((m) => {
|
|
4347
|
+
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
4348
|
+
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
4349
|
+
});
|
|
4350
|
+
}
|
|
4351
|
+
async function allBlocks(root, warnings = []) {
|
|
4352
|
+
const out = [];
|
|
4353
|
+
for (const local of localPackages(root)) {
|
|
4354
|
+
for (const manifest of await blocksOfInstalled(local.dir, warnings, { local: true })) out.push({ manifest, from: "local" });
|
|
4355
|
+
}
|
|
4356
|
+
const installed = installedGenesis(root);
|
|
4357
|
+
for (const [, dir] of installed) for (const manifest of await blocksOfInstalled(dir, warnings)) out.push({ manifest, from: "installed" });
|
|
4358
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
4359
|
+
if (installed.has(name)) continue;
|
|
4360
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
4361
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
4362
|
+
if (manifest) out.push({ manifest, from: "catalog" });
|
|
4363
|
+
}
|
|
4364
|
+
}
|
|
4365
|
+
return out;
|
|
4366
|
+
}
|
|
4367
|
+
function tryParse(parse2, warnings) {
|
|
4368
|
+
try {
|
|
4369
|
+
return parse2();
|
|
4370
|
+
} catch (err) {
|
|
4371
|
+
if (!(err instanceof ManifestError)) throw err;
|
|
4372
|
+
warnings.push(err.message);
|
|
4373
|
+
return null;
|
|
4374
|
+
}
|
|
4375
|
+
}
|
|
4376
|
+
function catalogBlocks(warnings = []) {
|
|
4377
|
+
const out = [];
|
|
4378
|
+
for (const [name, entry] of Object.entries(readCatalog().packages)) {
|
|
4379
|
+
for (const [id, raw] of Object.entries(entry.blocks ?? {})) {
|
|
4380
|
+
const manifest = tryParse(() => parseManifest(name, id, raw, entry.version), warnings);
|
|
4381
|
+
if (manifest) out.push(manifest);
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
return out;
|
|
4385
|
+
}
|
|
4386
|
+
async function findBlock(root, id, options = {}) {
|
|
4387
|
+
const all = (await allBlocks(root, options.warnings)).filter((b) => b.manifest.id === id && (!options.package || b.manifest.package === options.package));
|
|
4388
|
+
if (all.length === 0) {
|
|
4389
|
+
const known = [...new Set((await allBlocks(root)).map((b) => b.manifest.id))].sort();
|
|
4390
|
+
throw new Error(`No Genesis or local package declares a block "${id}"${options.package ? ` in ${options.package}` : ""}. Known blocks: ${known.join(", ") || "none"}.`);
|
|
4391
|
+
}
|
|
4392
|
+
if (all.length > 1) throw new Error(`"${id}" is declared by ${all.map((b) => b.manifest.package).join(" and ")}; pass --package to pick one.`);
|
|
4393
|
+
return all[0];
|
|
4394
|
+
}
|
|
4080
4395
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
4081
4396
|
var STEMS = {
|
|
4082
4397
|
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
@@ -4094,7 +4409,7 @@ var RENDERS_OUTLET = (code) => /<Outlet(?=[\s>/])/.test(code);
|
|
|
4094
4409
|
var OWN_CONTENT = /(?<![=-])>\s*[A-Za-z][^<>{}]*</.source + "|" + /(?<![\w$.])<(?:h[1-6]|ul|ol|table|dl|H[1-6]|[A-Z]\w*(?:Heading|Title|Table|List|Grid))(?=[\s>/])/.source;
|
|
4095
4410
|
function routesDir(ctx) {
|
|
4096
4411
|
if (ctx.config.routesDir) return ctx.config.routesDir;
|
|
4097
|
-
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(
|
|
4412
|
+
return ROUTES_DIR_CANDIDATES.find((d) => existsSync(path20.join(ctx.root, d))) ?? null;
|
|
4098
4413
|
}
|
|
4099
4414
|
var key = (segments) => segments.map((s) => s.replace(/_$/, "")).join("/");
|
|
4100
4415
|
function flavorOf(dir, rels) {
|
|
@@ -4229,7 +4544,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
4229
4544
|
});
|
|
4230
4545
|
if (typeof raw === "string") {
|
|
4231
4546
|
if (!packageDir) fail(`points at ${raw}, but the package folder is unknown`);
|
|
4232
|
-
const file =
|
|
4547
|
+
const file = path20.resolve(packageDir, raw);
|
|
4233
4548
|
if (!inside(packageDir, file)) fail(`points outside the package (${raw})`);
|
|
4234
4549
|
if (!existsSync(file)) fail(`points at ${raw}, which doesn't exist (is it in package.json "files"?)`);
|
|
4235
4550
|
let parsed;
|
|
@@ -4278,7 +4593,7 @@ function validateDeclaration(raw, packageName3, packageDir, ignored) {
|
|
|
4278
4593
|
if (typeof c.plugin === "string") {
|
|
4279
4594
|
if (!packageDir) plugin = c.plugin;
|
|
4280
4595
|
else {
|
|
4281
|
-
plugin =
|
|
4596
|
+
plugin = path20.resolve(packageDir, c.plugin);
|
|
4282
4597
|
if (!inside(packageDir, plugin)) fail(`plugin points outside the package (${c.plugin})`);
|
|
4283
4598
|
}
|
|
4284
4599
|
}
|
|
@@ -4328,7 +4643,7 @@ function checkPattern(v, where2, fail) {
|
|
|
4328
4643
|
}
|
|
4329
4644
|
var discoveryCache = /* @__PURE__ */ new Map();
|
|
4330
4645
|
function readDeclaringPackage(dir, local) {
|
|
4331
|
-
const file =
|
|
4646
|
+
const file = path20.join(dir, "package.json");
|
|
4332
4647
|
let stamp;
|
|
4333
4648
|
let real2;
|
|
4334
4649
|
try {
|
|
@@ -4351,7 +4666,7 @@ ${local}`;
|
|
|
4351
4666
|
const pkg = {
|
|
4352
4667
|
name: json.name,
|
|
4353
4668
|
version: typeof json.version === "string" ? json.version : "0.0.0",
|
|
4354
|
-
dir:
|
|
4669
|
+
dir: path20.resolve(dir),
|
|
4355
4670
|
namespace: ruleNamespace(json.name),
|
|
4356
4671
|
local,
|
|
4357
4672
|
private: json.private === true,
|
|
@@ -4365,7 +4680,7 @@ ${local}`;
|
|
|
4365
4680
|
if (raw !== void 0) {
|
|
4366
4681
|
const ignored = [];
|
|
4367
4682
|
try {
|
|
4368
|
-
pkg.declaration = validateDeclaration(raw, json.name,
|
|
4683
|
+
pkg.declaration = validateDeclaration(raw, json.name, path20.resolve(dir), ignored);
|
|
4369
4684
|
if (ignored.length) pkg.ignored = ignored;
|
|
4370
4685
|
} catch (err) {
|
|
4371
4686
|
pkg.error = err.message;
|
|
@@ -4384,14 +4699,14 @@ function discoverPackages(root) {
|
|
|
4384
4699
|
for (const dir of installed) {
|
|
4385
4700
|
let scope;
|
|
4386
4701
|
try {
|
|
4387
|
-
scope =
|
|
4702
|
+
scope = path20.dirname(realpathSync(dir));
|
|
4388
4703
|
} catch {
|
|
4389
4704
|
continue;
|
|
4390
4705
|
}
|
|
4391
|
-
if (
|
|
4706
|
+
if (path20.basename(scope) !== "@marktiderman" || !existsSync(scope)) continue;
|
|
4392
4707
|
for (const entry of readdirSync(scope)) {
|
|
4393
4708
|
if (byName.has(`@marktiderman/${entry}`) || !GENESIS.test(`@marktiderman/${entry}`)) continue;
|
|
4394
|
-
const pkg = readDeclaringPackage(
|
|
4709
|
+
const pkg = readDeclaringPackage(path20.join(scope, entry), false);
|
|
4395
4710
|
if (pkg) byName.set(pkg.name, pkg);
|
|
4396
4711
|
}
|
|
4397
4712
|
}
|
|
@@ -4575,10 +4890,10 @@ var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([
|
|
|
4575
4890
|
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
4576
4891
|
function sourceFiles(dir, rel = "") {
|
|
4577
4892
|
const out = [];
|
|
4578
|
-
for (const entry of readdirSync(
|
|
4893
|
+
for (const entry of readdirSync(path20.join(dir, rel)).sort()) {
|
|
4579
4894
|
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
4580
4895
|
const child = rel ? `${rel}/${entry}` : entry;
|
|
4581
|
-
const stat = lstatSync(
|
|
4896
|
+
const stat = lstatSync(path20.join(dir, child));
|
|
4582
4897
|
if (stat.isSymbolicLink()) continue;
|
|
4583
4898
|
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
4584
4899
|
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
@@ -4601,13 +4916,13 @@ function matchPattern(pattern, spec) {
|
|
|
4601
4916
|
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
4602
4917
|
}
|
|
4603
4918
|
function tsconfigPaths(dir) {
|
|
4604
|
-
const file =
|
|
4919
|
+
const file = path20.join(dir, "tsconfig.json");
|
|
4605
4920
|
if (!existsSync(file)) return [];
|
|
4606
4921
|
try {
|
|
4607
4922
|
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
4608
4923
|
const options = JSON.parse(text).compilerOptions ?? {};
|
|
4609
|
-
const base =
|
|
4610
|
-
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) =>
|
|
4924
|
+
const base = path20.resolve(dir, options.baseUrl ?? ".");
|
|
4925
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path20.resolve(base, t)) }));
|
|
4611
4926
|
} catch {
|
|
4612
4927
|
return [];
|
|
4613
4928
|
}
|
|
@@ -4621,8 +4936,8 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4621
4936
|
const hit = matchPattern(pattern, spec);
|
|
4622
4937
|
if (hit === null) continue;
|
|
4623
4938
|
return targets.some((t) => {
|
|
4624
|
-
const rel =
|
|
4625
|
-
return !rel.startsWith("..") && !
|
|
4939
|
+
const rel = path20.relative(pkg.dir, t.replace("*", hit));
|
|
4940
|
+
return !rel.startsWith("..") && !path20.isAbsolute(rel);
|
|
4626
4941
|
});
|
|
4627
4942
|
}
|
|
4628
4943
|
return null;
|
|
@@ -4635,7 +4950,7 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4635
4950
|
...Object.keys(json.optionalDependencies ?? {})
|
|
4636
4951
|
]);
|
|
4637
4952
|
for (const file of sourceFiles(pkg.dir)) {
|
|
4638
|
-
const code = stripForImports(readFileSync(
|
|
4953
|
+
const code = stripForImports(readFileSync(path20.join(pkg.dir, file), "utf8"));
|
|
4639
4954
|
if (code === null) continue;
|
|
4640
4955
|
const at = `${pkg.rel}/${file}`;
|
|
4641
4956
|
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
@@ -4660,9 +4975,9 @@ function checkImports2(ctx, pkg, json) {
|
|
|
4660
4975
|
continue;
|
|
4661
4976
|
}
|
|
4662
4977
|
if (spec.startsWith(".")) {
|
|
4663
|
-
const target =
|
|
4664
|
-
const rel =
|
|
4665
|
-
if (rel.startsWith("..") ||
|
|
4978
|
+
const target = path20.resolve(pkg.dir, path20.dirname(file), spec);
|
|
4979
|
+
const rel = path20.relative(pkg.dir, target);
|
|
4980
|
+
if (rel.startsWith("..") || path20.isAbsolute(rel)) {
|
|
4666
4981
|
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` });
|
|
4667
4982
|
}
|
|
4668
4983
|
continue;
|
|
@@ -4699,12 +5014,12 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4699
5014
|
const from = own ? "" : ` (in ${m.package})`;
|
|
4700
5015
|
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
4701
5016
|
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` });
|
|
4702
|
-
} else if (typeof m.test === "string" && !existsSync(
|
|
5017
|
+
} else if (typeof m.test === "string" && !existsSync(path20.join(home, m.test))) {
|
|
4703
5018
|
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` });
|
|
4704
5019
|
}
|
|
4705
5020
|
}
|
|
4706
5021
|
}
|
|
4707
|
-
const dir =
|
|
5022
|
+
const dir = path20.join(pkg.dir, "migrations");
|
|
4708
5023
|
if (!existsSync(dir)) return;
|
|
4709
5024
|
const seen = /* @__PURE__ */ new Map();
|
|
4710
5025
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -4713,21 +5028,21 @@ function checkMigrations(ctx, pkg, json, locals) {
|
|
|
4713
5028
|
const other = seen.get(m[1]);
|
|
4714
5029
|
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` });
|
|
4715
5030
|
else seen.set(m[1], name);
|
|
4716
|
-
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(
|
|
5031
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path20.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
4717
5032
|
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")})` });
|
|
4718
5033
|
}
|
|
4719
5034
|
}
|
|
4720
5035
|
}
|
|
4721
5036
|
function checkExports(ctx, pkg, json) {
|
|
4722
5037
|
const targets = [];
|
|
4723
|
-
const
|
|
5038
|
+
const walk2 = (v) => {
|
|
4724
5039
|
if (typeof v === "string") targets.push(v);
|
|
4725
|
-
else if (v && typeof v === "object") for (const x of Object.values(v))
|
|
5040
|
+
else if (v && typeof v === "object") for (const x of Object.values(v)) walk2(x);
|
|
4726
5041
|
};
|
|
4727
|
-
|
|
5042
|
+
walk2(json.exports);
|
|
4728
5043
|
for (const t of targets) {
|
|
4729
5044
|
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
4730
|
-
if (!existsSync(
|
|
5045
|
+
if (!existsSync(path20.join(pkg.dir, t))) {
|
|
4731
5046
|
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
4732
5047
|
}
|
|
4733
5048
|
}
|
|
@@ -4745,11 +5060,11 @@ function checkBlocks(ctx, pkg, json) {
|
|
|
4745
5060
|
function checkTaggedTests(ctx, pkg) {
|
|
4746
5061
|
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
4747
5062
|
if (!tests.length) return;
|
|
4748
|
-
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(
|
|
5063
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path20.join(pkg.dir, f), "utf8")));
|
|
4749
5064
|
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>` });
|
|
4750
5065
|
}
|
|
4751
5066
|
function checkRegistered(ctx, pkg) {
|
|
4752
|
-
const file =
|
|
5067
|
+
const file = path20.join(ctx.root, "features.json");
|
|
4753
5068
|
if (!existsSync(file)) return;
|
|
4754
5069
|
let doc;
|
|
4755
5070
|
try {
|
|
@@ -4759,7 +5074,7 @@ function checkRegistered(ctx, pkg) {
|
|
|
4759
5074
|
}
|
|
4760
5075
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4761
5076
|
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
4762
|
-
if (top) forms.add(
|
|
5077
|
+
if (top) forms.add(path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/"));
|
|
4763
5078
|
const covered = (doc.features ?? []).some(
|
|
4764
5079
|
(f) => (f.links?.code ?? []).some((c) => {
|
|
4765
5080
|
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
@@ -4789,8 +5104,8 @@ function mergeBaseOf(root, base) {
|
|
|
4789
5104
|
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
4790
5105
|
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
4791
5106
|
if (!top) return;
|
|
4792
|
-
const appRelative = (fromTop) =>
|
|
4793
|
-
const inRepo =
|
|
5107
|
+
const appRelative = (fromTop) => path20.relative(realpathSync(ctx.root), path20.join(top, fromTop)).split(path20.sep).join("/");
|
|
5108
|
+
const inRepo = path20.relative(top, realpathSync(pkg.dir)).split(path20.sep).join("/");
|
|
4794
5109
|
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");
|
|
4795
5110
|
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
4796
5111
|
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
@@ -4813,11 +5128,11 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4813
5128
|
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
4814
5129
|
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
4815
5130
|
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
4816
|
-
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) =>
|
|
5131
|
+
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path20.join(top, f)) : [];
|
|
4817
5132
|
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
4818
5133
|
const named = naming.length > 0;
|
|
4819
5134
|
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
4820
|
-
ctx.report({ rule: "package-unversioned-change", level: "warn", file:
|
|
5135
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path20.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
4821
5136
|
}
|
|
4822
5137
|
let jsonBefore = null;
|
|
4823
5138
|
try {
|
|
@@ -4827,7 +5142,7 @@ function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
|
4827
5142
|
}
|
|
4828
5143
|
const raw = json;
|
|
4829
5144
|
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
4830
|
-
const appInRepo =
|
|
5145
|
+
const appInRepo = path20.relative(top, realpathSync(ctx.root)).split(path20.sep).join("/");
|
|
4831
5146
|
const candidates = [.../* @__PURE__ */ new Set(["features.ts", "src/features.ts", ...appInRepo ? [`${appInRepo}/features.ts`, `${appInRepo}/src/features.ts`] : []])];
|
|
4832
5147
|
const registry = (git(top, ["diff", "--name-only", mergeBase, "--", ...candidates]) ?? "").trim();
|
|
4833
5148
|
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` });
|
|
@@ -4879,7 +5194,7 @@ function checkPackagesPack(ctx) {
|
|
|
4879
5194
|
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
4880
5195
|
}
|
|
4881
5196
|
for (const pkg of packages) {
|
|
4882
|
-
const json = JSON.parse(readFileSync(
|
|
5197
|
+
const json = JSON.parse(readFileSync(path20.join(pkg.dir, "package.json"), "utf8"));
|
|
4883
5198
|
checkImports2(ctx, pkg, json);
|
|
4884
5199
|
checkExports(ctx, pkg, json);
|
|
4885
5200
|
checkBlocks(ctx, pkg, json);
|
|
@@ -4891,6 +5206,45 @@ function checkPackagesPack(ctx) {
|
|
|
4891
5206
|
if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
4892
5207
|
}
|
|
4893
5208
|
}
|
|
5209
|
+
var LOCK_FILE = "genesis.lock.json";
|
|
5210
|
+
function emptyLock() {
|
|
5211
|
+
return { version: 1, blocks: {}, files: {} };
|
|
5212
|
+
}
|
|
5213
|
+
function readLock(root) {
|
|
5214
|
+
const file = path20.join(root, LOCK_FILE);
|
|
5215
|
+
if (!existsSync(file)) return emptyLock();
|
|
5216
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
5217
|
+
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
5218
|
+
return {
|
|
5219
|
+
version: 1,
|
|
5220
|
+
...raw.substitutions ? { substitutions: raw.substitutions } : {},
|
|
5221
|
+
blocks: raw.blocks ?? {},
|
|
5222
|
+
files: raw.files ?? {},
|
|
5223
|
+
...raw.migrations ? { migrations: raw.migrations } : {}
|
|
5224
|
+
};
|
|
5225
|
+
}
|
|
5226
|
+
function parseSource(source) {
|
|
5227
|
+
const at = source.indexOf(":");
|
|
5228
|
+
if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
|
|
5229
|
+
return { package: source.slice(0, at), path: source.slice(at + 1) };
|
|
5230
|
+
}
|
|
5231
|
+
|
|
5232
|
+
// src/blocks/database.ts
|
|
5233
|
+
function databaseElsewhere(root) {
|
|
5234
|
+
const setting = readGenesisConfig(root)?.supabase;
|
|
5235
|
+
if (setting === void 0) return null;
|
|
5236
|
+
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
5237
|
+
const resolved = path20.resolve(root, setting.app);
|
|
5238
|
+
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
5239
|
+
const dir = real2(resolved);
|
|
5240
|
+
if (dir === real2(path20.resolve(root))) throw new GenesisConfigError(`${path20.join(root, "genesis.config.json")}: supabase.app "${setting.app}" is this app itself; leave "supabase" out instead`);
|
|
5241
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path20.join(dir, "supabase")) };
|
|
5242
|
+
}
|
|
5243
|
+
function isSupabasePath(rel) {
|
|
5244
|
+
return rel === "supabase" || rel.startsWith("supabase/");
|
|
5245
|
+
}
|
|
5246
|
+
|
|
5247
|
+
// src/doctor/supabase.ts
|
|
4894
5248
|
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
4895
5249
|
var DEFAULT_BASE = "origin/main";
|
|
4896
5250
|
var DEFAULT_EXPOSED = ["public"];
|
|
@@ -5071,11 +5425,12 @@ function gitView(root, dir, base) {
|
|
|
5071
5425
|
return { touched: touched2, edited };
|
|
5072
5426
|
}
|
|
5073
5427
|
function checkSupabasePack(ctx) {
|
|
5428
|
+
if (databaseElsewhere(ctx.root)) return;
|
|
5074
5429
|
const settings = ctx.config.supabase ?? {};
|
|
5075
5430
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
5076
|
-
const abs =
|
|
5431
|
+
const abs = path20.join(ctx.root, dir);
|
|
5077
5432
|
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
5078
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(
|
|
5433
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path20.join(abs, n), "utf8")) }));
|
|
5079
5434
|
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
5080
5435
|
const base = settings.base ?? DEFAULT_BASE;
|
|
5081
5436
|
const view = gitView(ctx.root, dir, base);
|
|
@@ -5092,7 +5447,7 @@ function checkSupabasePack(ctx) {
|
|
|
5092
5447
|
}
|
|
5093
5448
|
}
|
|
5094
5449
|
const since = settings.since;
|
|
5095
|
-
const afterSince = (file) => since === void 0 ||
|
|
5450
|
+
const afterSince = (file) => since === void 0 || path20.posix.basename(file) >= since;
|
|
5096
5451
|
if ("reason" in view && since === void 0) {
|
|
5097
5452
|
ctx.report({
|
|
5098
5453
|
rule: "migration-grants",
|
|
@@ -5370,51 +5725,12 @@ function checkDefinerSearchPath(ctx, migrations) {
|
|
|
5370
5725
|
});
|
|
5371
5726
|
}
|
|
5372
5727
|
}
|
|
5373
|
-
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
5374
|
-
function readReleaseManifest(root) {
|
|
5375
|
-
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
5376
|
-
const file = dir && path19.join(dir, "dist", "versions.json");
|
|
5377
|
-
if (!file || !existsSync(file)) return null;
|
|
5378
|
-
return JSON.parse(readFileSync(file, "utf8"));
|
|
5379
|
-
}
|
|
5380
|
-
function checkVersionSkew(ctx) {
|
|
5381
|
-
const manifest = readReleaseManifest(ctx.root);
|
|
5382
|
-
if (!manifest) return;
|
|
5383
|
-
const overlays = markedOverlays(ctx);
|
|
5384
|
-
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
5385
|
-
const overlay = overlays.get(name);
|
|
5386
|
-
if (overlay) {
|
|
5387
|
-
const from = overlay.marker.upstream.slice(overlay.marker.upstream.lastIndexOf("@") + 1);
|
|
5388
|
-
if (from !== want) {
|
|
5389
|
-
ctx.report({
|
|
5390
|
-
rule: "version-skew",
|
|
5391
|
-
level: "warn",
|
|
5392
|
-
file: "package.json",
|
|
5393
|
-
subject: name,
|
|
5394
|
-
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).`
|
|
5395
|
-
});
|
|
5396
|
-
}
|
|
5397
|
-
continue;
|
|
5398
|
-
}
|
|
5399
|
-
const dir = findPackageDir(ctx.root, name);
|
|
5400
|
-
if (!dir) continue;
|
|
5401
|
-
const have = JSON.parse(readFileSync(path19.join(dir, "package.json"), "utf8")).version;
|
|
5402
|
-
if (have === want) continue;
|
|
5403
|
-
ctx.report({
|
|
5404
|
-
rule: "version-skew",
|
|
5405
|
-
level: "warn",
|
|
5406
|
-
file: "package.json",
|
|
5407
|
-
subject: name,
|
|
5408
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
5409
|
-
});
|
|
5410
|
-
}
|
|
5411
|
-
}
|
|
5412
5728
|
var GENESIS2 = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
5413
5729
|
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
5414
5730
|
var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
5415
5731
|
var readManifest = (dir) => {
|
|
5416
5732
|
try {
|
|
5417
|
-
return JSON.parse(readFileSync(
|
|
5733
|
+
return JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
5418
5734
|
} catch {
|
|
5419
5735
|
return null;
|
|
5420
5736
|
}
|
|
@@ -5428,18 +5744,18 @@ var real = (p) => {
|
|
|
5428
5744
|
};
|
|
5429
5745
|
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
5430
5746
|
function nodeModulesOf(dir) {
|
|
5431
|
-
const parent =
|
|
5432
|
-
return
|
|
5747
|
+
const parent = path20.dirname(dir);
|
|
5748
|
+
return path20.basename(parent).startsWith("@") ? path20.dirname(parent) : parent;
|
|
5433
5749
|
}
|
|
5434
5750
|
function packagesIn(nodeModules) {
|
|
5435
5751
|
if (!existsSync(nodeModules)) return [];
|
|
5436
5752
|
const out = [];
|
|
5437
5753
|
for (const entry of readdirSync(nodeModules)) {
|
|
5438
5754
|
if (entry.startsWith(".")) continue;
|
|
5439
|
-
const p =
|
|
5755
|
+
const p = path20.join(nodeModules, entry);
|
|
5440
5756
|
if (entry.startsWith("@")) {
|
|
5441
5757
|
try {
|
|
5442
|
-
for (const sub of readdirSync(p)) out.push(
|
|
5758
|
+
for (const sub of readdirSync(p)) out.push(path20.join(p, sub));
|
|
5443
5759
|
} catch {
|
|
5444
5760
|
}
|
|
5445
5761
|
} else {
|
|
@@ -5451,7 +5767,7 @@ function packagesIn(nodeModules) {
|
|
|
5451
5767
|
function genesisInstalls(root) {
|
|
5452
5768
|
const copies = /* @__PURE__ */ new Map();
|
|
5453
5769
|
const realRoot = real(root);
|
|
5454
|
-
const rel = (abs) =>
|
|
5770
|
+
const rel = (abs) => path20.relative(realRoot, abs).split(path20.sep).join("/") || ".";
|
|
5455
5771
|
const via = /* @__PURE__ */ new Map();
|
|
5456
5772
|
const record = (real2, manifest, by, range, root2) => {
|
|
5457
5773
|
let copy = copies.get(real2);
|
|
@@ -5463,7 +5779,7 @@ function genesisInstalls(root) {
|
|
|
5463
5779
|
via.get(real2).add(root2);
|
|
5464
5780
|
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
5465
5781
|
};
|
|
5466
|
-
const
|
|
5782
|
+
const walk2 = (kind, roots) => {
|
|
5467
5783
|
const expanded = /* @__PURE__ */ new Set();
|
|
5468
5784
|
const queue = [];
|
|
5469
5785
|
const visit = (dir, by, range) => {
|
|
@@ -5496,7 +5812,7 @@ function genesisInstalls(root) {
|
|
|
5496
5812
|
if (!dir) return null;
|
|
5497
5813
|
if (!ownInstall || name in declared) return dir;
|
|
5498
5814
|
const realDir = real(dir);
|
|
5499
|
-
if (realDir.startsWith(realRoot +
|
|
5815
|
+
if (realDir.startsWith(realRoot + path20.sep)) return dir;
|
|
5500
5816
|
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
5501
5817
|
};
|
|
5502
5818
|
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
@@ -5504,7 +5820,7 @@ function genesisInstalls(root) {
|
|
|
5504
5820
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
5505
5821
|
});
|
|
5506
5822
|
const app = readManifest(root);
|
|
5507
|
-
const ownInstall = LOCKFILES.some((f) => existsSync(
|
|
5823
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path20.join(root, f)));
|
|
5508
5824
|
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
5509
5825
|
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
5510
5826
|
const runtimeDeps = {
|
|
@@ -5514,18 +5830,18 @@ function genesisInstalls(root) {
|
|
|
5514
5830
|
...app?.dependencies
|
|
5515
5831
|
};
|
|
5516
5832
|
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
5517
|
-
|
|
5518
|
-
const top =
|
|
5519
|
-
|
|
5833
|
+
walk2("runtime", rootsOf(runtimeDeps, "the app"));
|
|
5834
|
+
const top = path20.join(root, "node_modules");
|
|
5835
|
+
walk2(
|
|
5520
5836
|
"hoisted",
|
|
5521
5837
|
packagesIn(top).filter((dir) => {
|
|
5522
|
-
const name =
|
|
5838
|
+
const name = path20.relative(top, dir).split(path20.sep).join("/");
|
|
5523
5839
|
return !(name in runtimeDeps) && !(name in devDeps);
|
|
5524
5840
|
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
5525
5841
|
);
|
|
5526
5842
|
const devRoots = { ...devDeps };
|
|
5527
5843
|
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
5528
|
-
|
|
5844
|
+
walk2("dev", rootsOf(devRoots, "the app (dev)"));
|
|
5529
5845
|
for (const [key2, copy] of copies) {
|
|
5530
5846
|
const kinds = via.get(key2);
|
|
5531
5847
|
copy.runtime = kinds.has("runtime");
|
|
@@ -5561,7 +5877,7 @@ function checkDuplicatePackages(ctx) {
|
|
|
5561
5877
|
}
|
|
5562
5878
|
}
|
|
5563
5879
|
function checkPeerRanges(ctx) {
|
|
5564
|
-
const rel = (abs) =>
|
|
5880
|
+
const rel = (abs) => path20.relative(ctx.root, abs).split(path20.sep).join("/");
|
|
5565
5881
|
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
5566
5882
|
for (const copy of copies) {
|
|
5567
5883
|
const dir = copy.absolutePath;
|
|
@@ -5943,17 +6259,17 @@ var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
|
5943
6259
|
var MAX_BYTES = 2 * 1024 * 1024;
|
|
5944
6260
|
function appScripts(root) {
|
|
5945
6261
|
const out = [];
|
|
5946
|
-
const
|
|
6262
|
+
const walk2 = (dir) => {
|
|
5947
6263
|
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5948
|
-
const abs =
|
|
6264
|
+
const abs = path20.join(dir, entry.name);
|
|
5949
6265
|
if (entry.isDirectory()) {
|
|
5950
|
-
if (!SKIP_DIRS3.has(entry.name))
|
|
6266
|
+
if (!SKIP_DIRS3.has(entry.name)) walk2(abs);
|
|
5951
6267
|
} else if (entry.isFile() && SCRIPT2.test(entry.name) && statSync(abs).size <= MAX_BYTES) {
|
|
5952
|
-
out.push(
|
|
6268
|
+
out.push(path20.relative(root, abs).split(path20.sep).join("/"));
|
|
5953
6269
|
}
|
|
5954
6270
|
}
|
|
5955
6271
|
};
|
|
5956
|
-
|
|
6272
|
+
walk2(root);
|
|
5957
6273
|
return out;
|
|
5958
6274
|
}
|
|
5959
6275
|
|
|
@@ -6037,7 +6353,7 @@ var ROOT_REQUIRE = /\brequire\s*\(\s*["']@marktiderman\/genesis-studio-server["'
|
|
|
6037
6353
|
function moduleFiles(ctx) {
|
|
6038
6354
|
const scanned = new Set(ctx.files.map((f) => f.path));
|
|
6039
6355
|
const ignored = globMatcher([...DEFAULT_IGNORE, ...ctx.config.ignore ?? []]);
|
|
6040
|
-
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(
|
|
6356
|
+
const extra = appScripts(ctx.root).filter((rel) => /\.(c|m)js$/.test(rel) && !scanned.has(rel) && !ignored(rel)).map((rel) => ({ path: rel, code: stripBlockComments(readFileSync(path20.join(ctx.root, rel), "utf8"), true) }));
|
|
6041
6357
|
return [...ctx.files.filter((f) => SCRIPT_EXTS5.has(f.ext)), ...extra];
|
|
6042
6358
|
}
|
|
6043
6359
|
function checkStudioServerImports(ctx) {
|
|
@@ -6073,7 +6389,7 @@ var REMOVED_WORDS = {
|
|
|
6073
6389
|
};
|
|
6074
6390
|
function checkRemovedScopeNames(ctx) {
|
|
6075
6391
|
let augmentedMemo;
|
|
6076
|
-
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(
|
|
6392
|
+
const augmented = () => augmentedMemo ??= ctx.files.some((f) => augmentsResourceScope(f.code)) || appScripts(ctx.root).filter((rel) => rel.endsWith(".d.ts")).some((rel) => augmentsResourceScope(readFileSync(path20.join(ctx.root, rel), "utf8")));
|
|
6077
6393
|
for (const file of ctx.files) {
|
|
6078
6394
|
if (!SCRIPT_EXTS5.has(file.ext)) continue;
|
|
6079
6395
|
for (const hit of findRemovedScopeNames(file.code)) {
|
|
@@ -6145,16 +6461,16 @@ function genesisNamedImports(source) {
|
|
|
6145
6461
|
}
|
|
6146
6462
|
function declarationFiles(dir, out = []) {
|
|
6147
6463
|
for (const name of readdirSync(dir)) {
|
|
6148
|
-
const full =
|
|
6464
|
+
const full = path20.join(dir, name);
|
|
6149
6465
|
if (statSync(full).isDirectory()) declarationFiles(full, out);
|
|
6150
6466
|
else if (/\.d\.[cm]?ts$/.test(name)) out.push(full);
|
|
6151
6467
|
}
|
|
6152
6468
|
return out;
|
|
6153
6469
|
}
|
|
6154
6470
|
function readPackageTags(dir) {
|
|
6155
|
-
const pkg = JSON.parse(readFileSync(
|
|
6471
|
+
const pkg = JSON.parse(readFileSync(path20.join(dir, "package.json"), "utf8"));
|
|
6156
6472
|
const tags = { dir, byFile: /* @__PURE__ */ new Map(), declaredIn: /* @__PURE__ */ new Map(), exports: typeof pkg.exports === "object" && pkg.exports ? pkg.exports : {} };
|
|
6157
|
-
const dist =
|
|
6473
|
+
const dist = path20.join(dir, "dist");
|
|
6158
6474
|
if (!existsSync(dist)) return tags;
|
|
6159
6475
|
for (const file of declarationFiles(dist)) {
|
|
6160
6476
|
const text = readFileSync(file, "utf8");
|
|
@@ -6172,7 +6488,7 @@ function entryFile(tags, pkg, specifier) {
|
|
|
6172
6488
|
const subpath = `.${specifier.slice(pkg.length)}` || ".";
|
|
6173
6489
|
const target = tags.exports[subpath === "." ? "." : subpath];
|
|
6174
6490
|
const types = typeof target === "object" && target ? target.types : null;
|
|
6175
|
-
return typeof types === "string" ?
|
|
6491
|
+
return typeof types === "string" ? path20.join(tags.dir, types) : null;
|
|
6176
6492
|
}
|
|
6177
6493
|
function tagFor(tags, entry, name) {
|
|
6178
6494
|
if (entry && tags.declaredIn.get(name)?.includes(entry)) return tags.byFile.get(entry)?.get(name);
|
|
@@ -6227,7 +6543,7 @@ function showAt(dir, rev, file) {
|
|
|
6227
6543
|
function configAtBase(root, base, explicitFile) {
|
|
6228
6544
|
const mergeBase = git3(root, ["merge-base", base, "HEAD"])?.trim();
|
|
6229
6545
|
if (!mergeBase) return null;
|
|
6230
|
-
const candidates = explicitFile ? [{ dir:
|
|
6546
|
+
const candidates = explicitFile ? [{ dir: path20.dirname(explicitFile), file: path20.basename(explicitFile), explicit: true }] : [
|
|
6231
6547
|
{ dir: root, file: "genesis.config.json", explicit: false },
|
|
6232
6548
|
{ dir: root, file: "package.json", explicit: false }
|
|
6233
6549
|
];
|
|
@@ -6339,7 +6655,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6339
6655
|
const env = settings.databaseEnv ?? DEFAULT_DATABASE_ENV;
|
|
6340
6656
|
let current = null;
|
|
6341
6657
|
try {
|
|
6342
|
-
current = lf(readFileSync(
|
|
6658
|
+
current = lf(readFileSync(path20.join(ctx.root, out), "utf8"));
|
|
6343
6659
|
} catch {
|
|
6344
6660
|
current = null;
|
|
6345
6661
|
}
|
|
@@ -6363,7 +6679,7 @@ async function checkContracts(ctx, read2 = postgresContract) {
|
|
|
6363
6679
|
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}` });
|
|
6364
6680
|
return;
|
|
6365
6681
|
}
|
|
6366
|
-
const target =
|
|
6682
|
+
const target = path20.relative(process.cwd(), path20.join(ctx.root, out)) || out;
|
|
6367
6683
|
const command = `genesis introspect -o ${shellArg(target)} -s ${shellArg(schemas.join(","))}${env === DEFAULT_DATABASE_ENV ? "" : ` --database-env ${shellArg(env)}`}`;
|
|
6368
6684
|
if (current !== expected) {
|
|
6369
6685
|
ctx.report({
|
|
@@ -6506,8 +6822,8 @@ function currentAgentsBlock(agents) {
|
|
|
6506
6822
|
var read = (file) => existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
6507
6823
|
function agentGuideState(root, packages, agentsFile = "AGENTS.md") {
|
|
6508
6824
|
const rows = primitivesCatalog(packages);
|
|
6509
|
-
const skill = read(
|
|
6510
|
-
const block = currentAgentsBlock(read(
|
|
6825
|
+
const skill = read(path20.join(root, SKILL_PATH))?.replace(/\r\n/g, "\n") ?? null;
|
|
6826
|
+
const block = currentAgentsBlock(read(path20.join(root, agentsFile)));
|
|
6511
6827
|
return {
|
|
6512
6828
|
skill: skill === null ? "missing" : skill === renderSkill(rows) ? "ok" : "stale",
|
|
6513
6829
|
agents: block === null || block === "broken" ? block ?? "missing" : block === renderAgentsBlock(rows) ? "ok" : "stale"
|
|
@@ -6529,9 +6845,274 @@ function checkAgentGuide(ctx) {
|
|
|
6529
6845
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6530
6846
|
}
|
|
6531
6847
|
}
|
|
6848
|
+
var CLI = "@marktiderman/genesis-cli";
|
|
6849
|
+
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6850
|
+
let parsed;
|
|
6851
|
+
try {
|
|
6852
|
+
parsed = parseSource(source);
|
|
6853
|
+
} catch (err) {
|
|
6854
|
+
return err instanceof Error ? err.message : String(err);
|
|
6855
|
+
}
|
|
6856
|
+
const { package: pkg, path: rel } = parsed;
|
|
6857
|
+
if (!GENESIS_PACKAGE.test(pkg) && !localNames.has(pkg)) return `${key2}'s source ${pkg} isn't a Genesis or local package`;
|
|
6858
|
+
if (!safeRelative(rel) || !safeRelative(key2)) return `${key2} or its source isn't a plain path`;
|
|
6859
|
+
if (key2.startsWith("supabase/migrations/")) return `${key2} is a migration; migrations are never refreshed`;
|
|
6860
|
+
const base = rel.split("/").pop();
|
|
6861
|
+
if (pkg === CLI && rel.startsWith("templates/")) {
|
|
6862
|
+
return /^(eas\.json|\.eas\/[\w./-]+|\.maestro\/[\w./-]+|\.github\/workflows\/[\w.-]+\.ya?ml)$/.test(key2) ? null : `${key2} isn't where a template goes`;
|
|
6863
|
+
}
|
|
6864
|
+
const fn = /^functions\/([a-z0-9][a-z0-9_-]*)\/([A-Za-z0-9][A-Za-z0-9._-]*)$/.exec(rel);
|
|
6865
|
+
if (fn) return key2 === `supabase/functions/${fn[1]}/${fn[2]}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6866
|
+
if (/\.test\.sql$/.test(base)) return key2 === `supabase/tests/database/${base.replace(/^\d{4}_/, "")}` ? null : `${key2} isn't where ${rel} goes`;
|
|
6867
|
+
if (/^\.claude\/skills\/[a-z0-9][a-z0-9_-]*\/[A-Za-z0-9][A-Za-z0-9._-]*$/.test(key2) && key2.endsWith(`/${base}`)) return null;
|
|
6868
|
+
return `${key2} doesn't match its source ${source}`;
|
|
6869
|
+
}
|
|
6870
|
+
|
|
6871
|
+
// src/blocks/templates.ts
|
|
6872
|
+
function starterDir() {
|
|
6873
|
+
const workspace = workspacePackagesDir();
|
|
6874
|
+
const live = workspace && path20.join(workspace, "..", "apps", "genesis-rn-starter");
|
|
6875
|
+
if (live && existsSync(path20.join(live, "package.json"))) return live;
|
|
6876
|
+
const packaged = path20.join(cliPackageDir(), "dist", "starter");
|
|
6877
|
+
if (existsSync(path20.join(packaged, "package.json"))) return packaged;
|
|
6878
|
+
throw new Error("This genesis-cli has no starter (dist/starter is missing): reinstall @marktiderman/genesis-cli.");
|
|
6879
|
+
}
|
|
6880
|
+
|
|
6881
|
+
// src/blocks/starter-features.ts
|
|
6882
|
+
var STARTER_CONFIG = "starter.config.ts";
|
|
6883
|
+
var GENESIS_CONFIG = "genesis.config.json";
|
|
6884
|
+
var SWITCH = /^[a-zA-Z][a-zA-Z0-9]*$/;
|
|
6885
|
+
var BLOCK_ID2 = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
6886
|
+
function featuresBody(text) {
|
|
6887
|
+
const m = /\bfeatures:\s*\{/.exec(text);
|
|
6888
|
+
if (!m) return null;
|
|
6889
|
+
const start = m.index + m[0].length;
|
|
6890
|
+
let depth = 1;
|
|
6891
|
+
for (let i = start; i < text.length; i++) {
|
|
6892
|
+
const c = text[i];
|
|
6893
|
+
if (c === "/" && text[i + 1] === "/") {
|
|
6894
|
+
const nl = text.indexOf("\n", i);
|
|
6895
|
+
if (nl < 0) return null;
|
|
6896
|
+
i = nl;
|
|
6897
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
6898
|
+
const close = text.indexOf("*/", i + 2);
|
|
6899
|
+
if (close < 0) return null;
|
|
6900
|
+
i = close + 1;
|
|
6901
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
6902
|
+
let j = i + 1;
|
|
6903
|
+
while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
|
|
6904
|
+
i = j;
|
|
6905
|
+
} else if (c === "{") depth++;
|
|
6906
|
+
else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
|
|
6907
|
+
}
|
|
6908
|
+
return null;
|
|
6909
|
+
}
|
|
6910
|
+
function parseStarterFeatures(text) {
|
|
6911
|
+
const found = featuresBody(text);
|
|
6912
|
+
if (!found) return null;
|
|
6913
|
+
const out = {};
|
|
6914
|
+
for (const line of found.body.split("\n")) {
|
|
6915
|
+
const m = /^\s*([a-zA-Z][a-zA-Z0-9]*)\s*:\s*(true|false)\s*,?\s*(?:\/\/.*)?$/.exec(line);
|
|
6916
|
+
if (m) out[m[1]] = m[2] === "true";
|
|
6917
|
+
}
|
|
6918
|
+
return out;
|
|
6919
|
+
}
|
|
6920
|
+
function parseStarterBlocks(json, source = GENESIS_CONFIG) {
|
|
6921
|
+
let raw;
|
|
6922
|
+
try {
|
|
6923
|
+
raw = JSON.parse(json);
|
|
6924
|
+
} catch (err) {
|
|
6925
|
+
throw new Error(`${source} is not valid JSON: ${err.message}`);
|
|
6926
|
+
}
|
|
6927
|
+
const starter = raw?.starter;
|
|
6928
|
+
if (starter === void 0) return null;
|
|
6929
|
+
const blocks = starter?.blocks;
|
|
6930
|
+
if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
|
|
6931
|
+
if (typeof blocks !== "object" || blocks === null || Array.isArray(blocks)) throw new Error(`${source}: starter.blocks must map each feature switch to a list of block ids`);
|
|
6932
|
+
const out = {};
|
|
6933
|
+
for (const [name, ids] of Object.entries(blocks)) {
|
|
6934
|
+
if (name === "$comment") continue;
|
|
6935
|
+
if (!SWITCH.test(name) || !Array.isArray(ids) || !ids.every((id) => typeof id === "string" && BLOCK_ID2.test(id))) {
|
|
6936
|
+
throw new Error(`${source}: starter.blocks.${name} must be a list of block ids`);
|
|
6937
|
+
}
|
|
6938
|
+
out[name] = ids;
|
|
6939
|
+
}
|
|
6940
|
+
return out;
|
|
6941
|
+
}
|
|
6942
|
+
function readText(file) {
|
|
6943
|
+
try {
|
|
6944
|
+
return readFileSync(file, "utf8");
|
|
6945
|
+
} catch {
|
|
6946
|
+
return null;
|
|
6947
|
+
}
|
|
6948
|
+
}
|
|
6949
|
+
function starterBlockMap(root) {
|
|
6950
|
+
if (root) {
|
|
6951
|
+
const file = path20.join(root, GENESIS_CONFIG);
|
|
6952
|
+
const text2 = readText(file);
|
|
6953
|
+
const own = text2 === null ? null : parseStarterBlocks(text2, file);
|
|
6954
|
+
if (own) return own;
|
|
6955
|
+
}
|
|
6956
|
+
let dir;
|
|
6957
|
+
try {
|
|
6958
|
+
dir = starterDir();
|
|
6959
|
+
} catch {
|
|
6960
|
+
return {};
|
|
6961
|
+
}
|
|
6962
|
+
const text = readText(path20.join(dir, GENESIS_CONFIG));
|
|
6963
|
+
return (text === null ? null : parseStarterBlocks(text)) ?? {};
|
|
6964
|
+
}
|
|
6965
|
+
function blocksSwitchedOff(switches, map, manifests, present) {
|
|
6966
|
+
const ids = new Set(present);
|
|
6967
|
+
const off = /* @__PURE__ */ new Map();
|
|
6968
|
+
for (const [name, carried] of Object.entries(map)) if (switches[name] === false) {
|
|
6969
|
+
for (const id of carried) if (ids.has(id)) off.set(id, name);
|
|
6970
|
+
}
|
|
6971
|
+
const requires = new Map(manifests.map((m) => [m.id, m.requires]));
|
|
6972
|
+
const keep = [...ids].filter((id) => !off.has(id));
|
|
6973
|
+
for (let i = 0; i < keep.length; i++) {
|
|
6974
|
+
for (const r of requires.get(keep[i]) ?? []) {
|
|
6975
|
+
off.delete(r);
|
|
6976
|
+
if (!keep.includes(r)) keep.push(r);
|
|
6977
|
+
}
|
|
6978
|
+
}
|
|
6979
|
+
return off;
|
|
6980
|
+
}
|
|
6981
|
+
function appBlocksSwitchedOff(root, manifests, present) {
|
|
6982
|
+
const text = readText(path20.join(root, STARTER_CONFIG));
|
|
6983
|
+
const switches = text === null ? null : parseStarterFeatures(text);
|
|
6984
|
+
if (!switches) return /* @__PURE__ */ new Map();
|
|
6985
|
+
return blocksSwitchedOff(switches, starterBlockMap(existsSync(path20.join(root, GENESIS_CONFIG)) ? root : void 0), manifests, present);
|
|
6986
|
+
}
|
|
6987
|
+
function blockOfSource(source, manifests) {
|
|
6988
|
+
const at = source.indexOf(":");
|
|
6989
|
+
if (at < 1) return null;
|
|
6990
|
+
const pkg = source.slice(0, at);
|
|
6991
|
+
const rel = source.slice(at + 1);
|
|
6992
|
+
for (const m of manifests) {
|
|
6993
|
+
if (m.functions.some((fn) => fn.package === pkg && rel.startsWith(`${fn.dir}/`))) return m.id;
|
|
6994
|
+
if (m.migrations.some((mig) => mig.package === pkg && mig.test === rel)) return m.id;
|
|
6995
|
+
}
|
|
6996
|
+
return null;
|
|
6997
|
+
}
|
|
6998
|
+
|
|
6999
|
+
// src/doctor/lock-files.ts
|
|
7000
|
+
async function checkLockFiles(ctx) {
|
|
7001
|
+
if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
|
|
7002
|
+
let lock;
|
|
7003
|
+
try {
|
|
7004
|
+
lock = readLock(ctx.root);
|
|
7005
|
+
} catch (err) {
|
|
7006
|
+
ctx.report({ rule: "lock-files", level: "warn", file: LOCK_FILE, message: `can't be read (${err instanceof Error ? err.message : String(err)}); genesis upgrade and migrate can't either` });
|
|
7007
|
+
return;
|
|
7008
|
+
}
|
|
7009
|
+
const catalog = catalogBlocks();
|
|
7010
|
+
const off = appBlocksSwitchedOff(ctx.root, catalog, Object.keys(lock.blocks));
|
|
7011
|
+
const offManifests = [];
|
|
7012
|
+
for (const [id, entry] of Object.entries(lock.blocks)) {
|
|
7013
|
+
const feature = off.get(id);
|
|
7014
|
+
if (!feature) continue;
|
|
7015
|
+
try {
|
|
7016
|
+
offManifests.push((await findBlock(ctx.root, id, { package: entry.package })).manifest);
|
|
7017
|
+
} catch {
|
|
7018
|
+
offManifests.push(...catalog.filter((m) => m.id === id));
|
|
7019
|
+
}
|
|
7020
|
+
ctx.report({
|
|
7021
|
+
rule: "lock-files",
|
|
7022
|
+
level: "info",
|
|
7023
|
+
file: LOCK_FILE,
|
|
7024
|
+
subject: id,
|
|
7025
|
+
message: `lists the ${id} block, but features.${feature} is off in ${STARTER_CONFIG}: genesis upgrade and migrate leave it out (delete its entry if it's gone for good)`
|
|
7026
|
+
});
|
|
7027
|
+
}
|
|
7028
|
+
const local = localPackageNames(ctx.root);
|
|
7029
|
+
let home = null;
|
|
7030
|
+
try {
|
|
7031
|
+
home = databaseElsewhere(ctx.root);
|
|
7032
|
+
} catch {
|
|
7033
|
+
}
|
|
7034
|
+
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
7035
|
+
if (home && elsewhere.length) {
|
|
7036
|
+
ctx.report({
|
|
7037
|
+
rule: "lock-files",
|
|
7038
|
+
level: "info",
|
|
7039
|
+
file: LOCK_FILE,
|
|
7040
|
+
subject: "supabase/",
|
|
7041
|
+
message: `lists ${elsewhere.length} file${elsewhere.length === 1 ? "" : "s"} under supabase/, but this app's database files live ${home.app ? `in ${home.app}` : "nowhere"} (genesis.config.json supabase): genesis upgrade leaves them alone, so delete those entries`
|
|
7042
|
+
});
|
|
7043
|
+
}
|
|
7044
|
+
for (const [rel, entry] of Object.entries(lock.files)) {
|
|
7045
|
+
if (home && isSupabasePath(rel)) continue;
|
|
7046
|
+
if (ownedKeyProblem(rel, entry.source, local)) continue;
|
|
7047
|
+
if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
|
|
7048
|
+
let file;
|
|
7049
|
+
try {
|
|
7050
|
+
file = appPath2(ctx.root, rel);
|
|
7051
|
+
} catch {
|
|
7052
|
+
continue;
|
|
7053
|
+
}
|
|
7054
|
+
let text;
|
|
7055
|
+
try {
|
|
7056
|
+
text = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
7057
|
+
} catch (err) {
|
|
7058
|
+
ctx.report({
|
|
7059
|
+
rule: "lock-files",
|
|
7060
|
+
level: "warn",
|
|
7061
|
+
file: rel,
|
|
7062
|
+
subject: rel,
|
|
7063
|
+
message: `is in ${LOCK_FILE} (from ${entry.source}) but can't be read (${err instanceof Error ? err.message : String(err)}), so genesis upgrade can't refresh it. Make it a file again, or remove its entry from ${LOCK_FILE}`
|
|
7064
|
+
});
|
|
7065
|
+
continue;
|
|
7066
|
+
}
|
|
7067
|
+
if (text === null) {
|
|
7068
|
+
if (entry.deleted) continue;
|
|
7069
|
+
ctx.report({
|
|
7070
|
+
rule: "lock-files",
|
|
7071
|
+
level: "warn",
|
|
7072
|
+
file: rel,
|
|
7073
|
+
subject: rel,
|
|
7074
|
+
message: `is in ${LOCK_FILE} (from ${entry.source}) but not on disk, and genesis upgrade won't bring it back. Deleted on purpose: add "deleted": true to its entry in ${LOCK_FILE}. Otherwise restore it (git checkout, or copy it from ${entry.source})`
|
|
7075
|
+
});
|
|
7076
|
+
continue;
|
|
7077
|
+
}
|
|
7078
|
+
if (entry.deleted) {
|
|
7079
|
+
ctx.report({ rule: "lock-files", level: "info", file: rel, subject: rel, message: `is marked "deleted": true in ${LOCK_FILE} but is on disk; remove the marker` });
|
|
7080
|
+
}
|
|
7081
|
+
if (sha256(text) === entry.sha256) continue;
|
|
7082
|
+
ctx.report({
|
|
7083
|
+
rule: "lock-files",
|
|
7084
|
+
level: "info",
|
|
7085
|
+
file: rel,
|
|
7086
|
+
subject: rel,
|
|
7087
|
+
message: entry.pending ? `differs from ${LOCK_FILE}: the last upgrade's version is waiting in ${rel}.genesis-next; resolve it into this file and delete it` : `differs from ${LOCK_FILE} (edited in the app); genesis upgrade three-way merges the next version into your edits`
|
|
7088
|
+
});
|
|
7089
|
+
}
|
|
7090
|
+
}
|
|
7091
|
+
function checkDatabaseHome(ctx) {
|
|
7092
|
+
const home = databaseElsewhere(ctx.root);
|
|
7093
|
+
if (!home) return;
|
|
7094
|
+
if (home.app && !home.hasSupabase) {
|
|
7095
|
+
ctx.report({
|
|
7096
|
+
rule: "database-elsewhere",
|
|
7097
|
+
level: "warn",
|
|
7098
|
+
file: "genesis.config.json",
|
|
7099
|
+
subject: home.app,
|
|
7100
|
+
message: `supabase.app is ${home.app}, which has no supabase folder; name the app that holds this app's database (its migrations, tests and Edge Functions)`
|
|
7101
|
+
});
|
|
7102
|
+
}
|
|
7103
|
+
if (existsSync(path20.join(ctx.root, "supabase"))) {
|
|
7104
|
+
ctx.report({
|
|
7105
|
+
rule: "database-elsewhere",
|
|
7106
|
+
level: "warn",
|
|
7107
|
+
file: "supabase",
|
|
7108
|
+
subject: "supabase/",
|
|
7109
|
+
message: `is here, but genesis.config.json says this app's database files live ${home.app ? `in ${home.app}/supabase` : "nowhere"}: genesis add, migrate and upgrade never plan it, so it is a second, unused copy. Delete it`
|
|
7110
|
+
});
|
|
7111
|
+
}
|
|
7112
|
+
}
|
|
6532
7113
|
var RATCHETED_BY_DEFAULT = ["deprecated-import"];
|
|
6533
7114
|
async function runDoctor(options = {}) {
|
|
6534
|
-
const root =
|
|
7115
|
+
const root = path20.resolve(options.root ?? process.cwd());
|
|
6535
7116
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
6536
7117
|
const config = loaded.config;
|
|
6537
7118
|
const genesis = options.genesis ?? loadGenesis(root, config);
|
|
@@ -6585,7 +7166,7 @@ async function runDoctor(options = {}) {
|
|
|
6585
7166
|
}
|
|
6586
7167
|
let findings = applyConfig(raw, config, packageRuleIds(packages));
|
|
6587
7168
|
if (options.base && changed) {
|
|
6588
|
-
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(
|
|
7169
|
+
findings = applyRatchet(findings, { config, newOnly, changed, base: options.base, isAppPath: (f) => existsSync(path20.join(root, f)) });
|
|
6589
7170
|
}
|
|
6590
7171
|
const errors = findings.filter((f) => f.level === "error").length;
|
|
6591
7172
|
const warnings = findings.filter((f) => f.level === "warn").length;
|
|
@@ -6630,6 +7211,8 @@ function builtinChecks(config, options = {}) {
|
|
|
6630
7211
|
{ name: "stability-imports", check: checkStabilityImports },
|
|
6631
7212
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
6632
7213
|
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
7214
|
+
{ name: "lock-files", check: checkLockFiles },
|
|
7215
|
+
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
6633
7216
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
6634
7217
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
6635
7218
|
];
|