@marktiderman/genesis-cli 1.18.0 → 1.20.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 +147 -2
- package/dist/cli.js +1363 -456
- 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 +402 -40
- package/dist/doctor.js.map +1 -1
- package/dist/eslint.cjs +99 -0
- package/dist/eslint.cjs.map +1 -0
- package/dist/eslint.d.cts +68 -0
- package/dist/eslint.d.ts +68 -0
- package/dist/eslint.js +72 -0
- package/dist/eslint.js.map +1 -0
- 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 +30 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +410 -48
- package/dist/index.js.map +1 -1
- package/dist/starter/README.md +18 -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 +27 -7
- package/dist/starter/eslint.config.js +8 -1
- package/dist/starter/jest.config.js +3 -0
- package/dist/starter/nativewind-env.d.ts +1 -0
- package/dist/starter/package.json +3 -0
- package/dist/starter/src/lib/link-hosts.ts +7 -3
- 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_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 +402 -40
- package/dist/vite.js.map +1 -1
- package/package.json +18 -4
package/dist/index.js
CHANGED
|
@@ -456,14 +456,14 @@ function inherit(own, source) {
|
|
|
456
456
|
}
|
|
457
457
|
function resolveViews(relations) {
|
|
458
458
|
const done = /* @__PURE__ */ new Set();
|
|
459
|
-
const
|
|
459
|
+
const resolve17 = (relation, depth) => {
|
|
460
460
|
if (done.has(relation.oid) || !relation.origins || depth > MAX_VIEW_DEPTH) return;
|
|
461
461
|
done.add(relation.oid);
|
|
462
462
|
const sources = new Set([...relation.origins.values()].map((o) => o.relation));
|
|
463
463
|
if (sources.size !== 1) return;
|
|
464
464
|
const source = relations.get([...sources][0]);
|
|
465
465
|
if (!source) return;
|
|
466
|
-
|
|
466
|
+
resolve17(source, depth + 1);
|
|
467
467
|
const viewAttnumOf = /* @__PURE__ */ new Map();
|
|
468
468
|
for (const [attnum, origin] of relation.origins) {
|
|
469
469
|
const own = relation.columns.get(attnum);
|
|
@@ -486,7 +486,7 @@ function resolveViews(relations) {
|
|
|
486
486
|
};
|
|
487
487
|
if (Object.keys(inherited).length) relation.table.settings = { ...inherited, ...relation.table.settings };
|
|
488
488
|
};
|
|
489
|
-
for (const relation of relations.values())
|
|
489
|
+
for (const relation of relations.values()) resolve17(relation, 0);
|
|
490
490
|
}
|
|
491
491
|
async function introspectPostgres(sql, schemas, options = {}) {
|
|
492
492
|
const relations = /* @__PURE__ */ new Map();
|
|
@@ -816,9 +816,9 @@ async function runScaffold(opts, fs) {
|
|
|
816
816
|
function joinPath(...parts) {
|
|
817
817
|
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
818
818
|
}
|
|
819
|
-
function dirname(
|
|
820
|
-
const idx =
|
|
821
|
-
return idx === -1 ? "." :
|
|
819
|
+
function dirname(path43) {
|
|
820
|
+
const idx = path43.lastIndexOf("/");
|
|
821
|
+
return idx === -1 ? "." : path43.slice(0, idx);
|
|
822
822
|
}
|
|
823
823
|
function brandPackageJson(consumer, genesisVersion) {
|
|
824
824
|
return JSON.stringify(
|
|
@@ -1076,8 +1076,8 @@ function routeTags(source) {
|
|
|
1076
1076
|
var GUARD = /<((?:[A-Z]\w*)?(?:Admin|Staff)\w*(?:Guard|Route|Only)|RequireAdmin|RequireStaff)>/;
|
|
1077
1077
|
function wireStudioRoute(source, route, pageImportPath) {
|
|
1078
1078
|
const tags = routeTags(source);
|
|
1079
|
-
const
|
|
1080
|
-
const existing = tags.find((t) => new RegExp(`path=["'](/?${
|
|
1079
|
+
const relative11 = route.replace(/^\//, "");
|
|
1080
|
+
const existing = tags.find((t) => new RegExp(`path=["'](/?${relative11.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})["']`).test(t.text));
|
|
1081
1081
|
if (existing) {
|
|
1082
1082
|
return { skipped: `Your router already has a page at ${route}. Replace its element with <DataStudioPage /> to use the studio there.` };
|
|
1083
1083
|
}
|
|
@@ -1085,17 +1085,17 @@ function wireStudioRoute(source, route, pageImportPath) {
|
|
|
1085
1085
|
const roots = layouts.length ? layouts : tags.filter((t) => !t.selfClosing && t.close !== void 0 && /path=["']\/["']/.test(t.text));
|
|
1086
1086
|
if (roots.length !== 1) {
|
|
1087
1087
|
return {
|
|
1088
|
-
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${
|
|
1088
|
+
skipped: roots.length === 0 ? `No layout route found to put the page under. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.` : `More than one layout route; add <Route path="${relative11}" element={<DataStudioPage />} /> inside the one your other admin pages use.`
|
|
1089
1089
|
};
|
|
1090
1090
|
}
|
|
1091
1091
|
const layout = roots[0];
|
|
1092
1092
|
const base = (/\bpath=["']([^"']*)["']/.exec(layout.text)?.[1] ?? "").replace(/^\/+|\/+$/g, "");
|
|
1093
|
-
if (base && !
|
|
1093
|
+
if (base && !relative11.startsWith(`${base}/`)) {
|
|
1094
1094
|
return {
|
|
1095
1095
|
skipped: `Your layout route lives at /${base}, outside ${route}. Add <Route path="${route}" element={<DataStudioPage />} /> where your app's other pages are.`
|
|
1096
1096
|
};
|
|
1097
1097
|
}
|
|
1098
|
-
const childPath = base ?
|
|
1098
|
+
const childPath = base ? relative11.slice(base.length + 1) : relative11;
|
|
1099
1099
|
const guard = GUARD.exec(source)?.[1];
|
|
1100
1100
|
const element = guard ? `<${guard}><DataStudioPage /></${guard}>` : "<DataStudioPage />";
|
|
1101
1101
|
const before = source.slice(0, layout.close);
|
|
@@ -1587,8 +1587,26 @@ function readGenesisConfig(root) {
|
|
|
1587
1587
|
const out = { raw };
|
|
1588
1588
|
if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
|
|
1589
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
|
+
}
|
|
1590
1594
|
return out;
|
|
1591
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
|
+
}
|
|
1592
1610
|
var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
|
|
1593
1611
|
var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
|
|
1594
1612
|
function validatePrivacy(raw, source = "config") {
|
|
@@ -1813,7 +1831,7 @@ function globToRegExp(glob) {
|
|
|
1813
1831
|
}
|
|
1814
1832
|
function globMatcher(globs) {
|
|
1815
1833
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
1816
|
-
return (
|
|
1834
|
+
return (path43) => res.some((re) => re.test(path43));
|
|
1817
1835
|
}
|
|
1818
1836
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
1819
1837
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
@@ -2199,6 +2217,26 @@ function parseManifest(home, id, raw, version, options = {}) {
|
|
|
2199
2217
|
const file = pathOf(m["file"], `${where2}.file`);
|
|
2200
2218
|
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where2}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
2201
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
|
+
}
|
|
2202
2240
|
if (m["test"] !== void 0) {
|
|
2203
2241
|
out.test = pathOf(m["test"], `${where2}.test`);
|
|
2204
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`);
|
|
@@ -2342,10 +2380,6 @@ function appPath2(root, rel) {
|
|
|
2342
2380
|
if (there(target) && lstatSync(target).isSymbolicLink()) throw new Error(`${rel} is a symlink; left alone`);
|
|
2343
2381
|
return target;
|
|
2344
2382
|
}
|
|
2345
|
-
function readApp(root, rel) {
|
|
2346
|
-
const file = appPath2(root, rel);
|
|
2347
|
-
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
2348
|
-
}
|
|
2349
2383
|
|
|
2350
2384
|
// src/blocks/local.ts
|
|
2351
2385
|
var LOCAL_PACKAGES_KEY = "localPackages";
|
|
@@ -3013,8 +3047,8 @@ function pinnedVersion(root, name, manifests = ["package.json"]) {
|
|
|
3013
3047
|
} catch {
|
|
3014
3048
|
continue;
|
|
3015
3049
|
}
|
|
3016
|
-
for (const
|
|
3017
|
-
const spec = json[
|
|
3050
|
+
for (const section2 of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
3051
|
+
const spec = json[section2]?.[name];
|
|
3018
3052
|
const v = typeof spec === "string" ? /^[\^~=]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(spec)?.[1] : void 0;
|
|
3019
3053
|
const parsed = v && parseVersion(v);
|
|
3020
3054
|
if (parsed && (!best || compareVersions(parsed, parseVersion(best)) > 0)) best = v;
|
|
@@ -3165,7 +3199,11 @@ var BUILTIN_RULES = [
|
|
|
3165
3199
|
// supabase pack: contracts (contracts.ts)
|
|
3166
3200
|
"contracts-stale",
|
|
3167
3201
|
// genesis.lock.json against the files (lock-files.ts)
|
|
3168
|
-
"lock-files"
|
|
3202
|
+
"lock-files",
|
|
3203
|
+
// an app whose database files live in another app (database.ts)
|
|
3204
|
+
"database-elsewhere",
|
|
3205
|
+
// the app's eslint config loads Genesis's lint rules (eslint-config.ts)
|
|
3206
|
+
"genesis-eslint-config"
|
|
3169
3207
|
];
|
|
3170
3208
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
3171
3209
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -3388,7 +3426,7 @@ function privacyApisFor(dependencies2) {
|
|
|
3388
3426
|
var EAS_PLACEHOLDERS = {
|
|
3389
3427
|
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)",
|
|
3390
3428
|
REPLACE_WITH_APPLE_TEAM_ID: "your Apple Developer Team ID (developer.apple.com \u2192 Account \u2192 Membership details, 10 characters)",
|
|
3391
|
-
REPLACE_WITH_PATH_TO_GOOGLE_SERVICE_ACCOUNT_JSON: "the
|
|
3429
|
+
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)",
|
|
3392
3430
|
REPLACE_WITH_APP_FOLDER: "the app's code folder (src, or apps/<name> in a monorepo)"
|
|
3393
3431
|
};
|
|
3394
3432
|
function placeholderKey(line, placeholder) {
|
|
@@ -4297,11 +4335,21 @@ async function blocksOfInstalled(dir, warnings = [], options = {}) {
|
|
|
4297
4335
|
const out = [];
|
|
4298
4336
|
for (const id of [...ids].sort()) {
|
|
4299
4337
|
const fromJson = raw[id] ?? {};
|
|
4300
|
-
const
|
|
4338
|
+
const merged = { ...fromJson, ...declared[id] };
|
|
4339
|
+
if (declared[id]?.["migrations"] && Array.isArray(fromJson["migrations"])) merged["migrations"] = withProvides(declared[id]["migrations"], fromJson["migrations"]);
|
|
4340
|
+
const manifest = tryParse(() => parseManifest(pkg.name, id, merged, pkg.version, options), warnings);
|
|
4301
4341
|
if (manifest) out.push(manifest);
|
|
4302
4342
|
}
|
|
4303
4343
|
return out;
|
|
4304
4344
|
}
|
|
4345
|
+
function withProvides(declared, json) {
|
|
4346
|
+
if (!Array.isArray(declared)) return declared;
|
|
4347
|
+
const fileOf = (m) => m && typeof m === "object" ? m["file"] : void 0;
|
|
4348
|
+
return declared.map((m) => {
|
|
4349
|
+
const same = json.find((j) => fileOf(j) === fileOf(m));
|
|
4350
|
+
return same?.["provides"] !== void 0 && m && typeof m === "object" && !("provides" in m) ? { ...m, provides: same["provides"] } : m;
|
|
4351
|
+
});
|
|
4352
|
+
}
|
|
4305
4353
|
async function allBlocks(root, warnings = []) {
|
|
4306
4354
|
const out = [];
|
|
4307
4355
|
for (const local of localPackages(root)) {
|
|
@@ -5160,6 +5208,45 @@ function checkPackagesPack(ctx) {
|
|
|
5160
5208
|
if (base && "sha" in merge && !overlay) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
5161
5209
|
}
|
|
5162
5210
|
}
|
|
5211
|
+
var LOCK_FILE = "genesis.lock.json";
|
|
5212
|
+
function emptyLock() {
|
|
5213
|
+
return { version: 1, blocks: {}, files: {} };
|
|
5214
|
+
}
|
|
5215
|
+
function readLock(root) {
|
|
5216
|
+
const file = path20.join(root, LOCK_FILE);
|
|
5217
|
+
if (!existsSync(file)) return emptyLock();
|
|
5218
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
5219
|
+
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
5220
|
+
return {
|
|
5221
|
+
version: 1,
|
|
5222
|
+
...raw.substitutions ? { substitutions: raw.substitutions } : {},
|
|
5223
|
+
blocks: raw.blocks ?? {},
|
|
5224
|
+
files: raw.files ?? {},
|
|
5225
|
+
...raw.migrations ? { migrations: raw.migrations } : {}
|
|
5226
|
+
};
|
|
5227
|
+
}
|
|
5228
|
+
function parseSource(source) {
|
|
5229
|
+
const at = source.indexOf(":");
|
|
5230
|
+
if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
|
|
5231
|
+
return { package: source.slice(0, at), path: source.slice(at + 1) };
|
|
5232
|
+
}
|
|
5233
|
+
|
|
5234
|
+
// src/blocks/database.ts
|
|
5235
|
+
function databaseElsewhere(root) {
|
|
5236
|
+
const setting = readGenesisConfig(root)?.supabase;
|
|
5237
|
+
if (setting === void 0) return null;
|
|
5238
|
+
if (setting === false) return { app: null, dir: null, hasSupabase: false };
|
|
5239
|
+
const resolved = path20.resolve(root, setting.app);
|
|
5240
|
+
const real2 = (p) => existsSync(p) ? realpathSync(p) : p;
|
|
5241
|
+
const dir = real2(resolved);
|
|
5242
|
+
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`);
|
|
5243
|
+
return { app: setting.app, dir, hasSupabase: existsSync(path20.join(dir, "supabase")) };
|
|
5244
|
+
}
|
|
5245
|
+
function isSupabasePath(rel) {
|
|
5246
|
+
return rel === "supabase" || rel.startsWith("supabase/");
|
|
5247
|
+
}
|
|
5248
|
+
|
|
5249
|
+
// src/doctor/supabase.ts
|
|
5163
5250
|
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
5164
5251
|
var DEFAULT_BASE = "origin/main";
|
|
5165
5252
|
var DEFAULT_EXPOSED = ["public"];
|
|
@@ -5340,6 +5427,7 @@ function gitView(root, dir, base) {
|
|
|
5340
5427
|
return { touched: touched2, edited };
|
|
5341
5428
|
}
|
|
5342
5429
|
function checkSupabasePack(ctx) {
|
|
5430
|
+
if (databaseElsewhere(ctx.root)) return;
|
|
5343
5431
|
const settings = ctx.config.supabase ?? {};
|
|
5344
5432
|
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
5345
5433
|
const abs = path20.join(ctx.root, dir);
|
|
@@ -6167,6 +6255,31 @@ function readsPracticeId(text) {
|
|
|
6167
6255
|
var augmentsResourceScope = (text) => /\binterface\s+ResourceScope\b/.test(text);
|
|
6168
6256
|
var PRACTICE_ID_AUGMENTATION = 'declare module "@marktiderman/genesis-core" { interface ResourceScope { practiceId?: string } }';
|
|
6169
6257
|
|
|
6258
|
+
// src/upgrade/eslint-config.ts
|
|
6259
|
+
var ESLINT_EXPORT = "@marktiderman/genesis-cli/eslint";
|
|
6260
|
+
var TESTING_LIBRARY = "eslint-plugin-testing-library";
|
|
6261
|
+
var FLAT_CONFIG_FILES = ["eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", "eslint.config.ts", "eslint.config.mts", "eslint.config.cts"];
|
|
6262
|
+
function findEslintConfig(root) {
|
|
6263
|
+
return FLAT_CONFIG_FILES.find((name) => existsSync(path20.join(root, name))) ?? null;
|
|
6264
|
+
}
|
|
6265
|
+
function readPackageJson(root) {
|
|
6266
|
+
try {
|
|
6267
|
+
return JSON.parse(readFileSync(path20.join(root, "package.json"), "utf8"));
|
|
6268
|
+
} catch {
|
|
6269
|
+
return null;
|
|
6270
|
+
}
|
|
6271
|
+
}
|
|
6272
|
+
var declares = (pkg, name) => Boolean(pkg?.dependencies?.[name] ?? pkg?.devDependencies?.[name] ?? pkg?.peerDependencies?.[name]);
|
|
6273
|
+
function appPlatform(pkg) {
|
|
6274
|
+
return declares(pkg, "expo") || declares(pkg, "react-native") ? "native" : "web";
|
|
6275
|
+
}
|
|
6276
|
+
function hasTestingLibrary(pkg) {
|
|
6277
|
+
return declares(pkg, TESTING_LIBRARY);
|
|
6278
|
+
}
|
|
6279
|
+
function usesGenesisLint(text) {
|
|
6280
|
+
return text.includes(ESLINT_EXPORT);
|
|
6281
|
+
}
|
|
6282
|
+
|
|
6170
6283
|
// src/upgrade/codemods.ts
|
|
6171
6284
|
var SKIP_DIRS3 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", ".git", ".next", ".output", ".turbo", ".expo", "coverage", "ios", "android"]);
|
|
6172
6285
|
var SCRIPT2 = /\.(?:[cm]?[jt]sx?)$/;
|
|
@@ -6759,28 +6872,6 @@ function checkAgentGuide(ctx) {
|
|
|
6759
6872
|
ctx.report({ rule: "agent-guide-stale", level: "warn", file: "AGENTS.md", message });
|
|
6760
6873
|
}
|
|
6761
6874
|
}
|
|
6762
|
-
var LOCK_FILE = "genesis.lock.json";
|
|
6763
|
-
function emptyLock() {
|
|
6764
|
-
return { version: 1, blocks: {}, files: {} };
|
|
6765
|
-
}
|
|
6766
|
-
function readLock(root) {
|
|
6767
|
-
const file = path20.join(root, LOCK_FILE);
|
|
6768
|
-
if (!existsSync(file)) return emptyLock();
|
|
6769
|
-
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
6770
|
-
if (raw.version !== 1) throw new Error(`${LOCK_FILE} has version ${String(raw.version)}; this CLI reads version 1.`);
|
|
6771
|
-
return {
|
|
6772
|
-
version: 1,
|
|
6773
|
-
...raw.substitutions ? { substitutions: raw.substitutions } : {},
|
|
6774
|
-
blocks: raw.blocks ?? {},
|
|
6775
|
-
files: raw.files ?? {},
|
|
6776
|
-
...raw.migrations ? { migrations: raw.migrations } : {}
|
|
6777
|
-
};
|
|
6778
|
-
}
|
|
6779
|
-
function parseSource(source) {
|
|
6780
|
-
const at = source.indexOf(":");
|
|
6781
|
-
if (at < 1) throw new Error(`${LOCK_FILE}: "${source}" is not <package>:<path>`);
|
|
6782
|
-
return { package: source.slice(0, at), path: source.slice(at + 1) };
|
|
6783
|
-
}
|
|
6784
6875
|
var CLI = "@marktiderman/genesis-cli";
|
|
6785
6876
|
function ownedKeyProblem(key2, source, localNames = /* @__PURE__ */ new Set()) {
|
|
6786
6877
|
let parsed;
|
|
@@ -6823,8 +6914,25 @@ function featuresBody(text) {
|
|
|
6823
6914
|
const m = /\bfeatures:\s*\{/.exec(text);
|
|
6824
6915
|
if (!m) return null;
|
|
6825
6916
|
const start = m.index + m[0].length;
|
|
6826
|
-
|
|
6827
|
-
|
|
6917
|
+
let depth = 1;
|
|
6918
|
+
for (let i = start; i < text.length; i++) {
|
|
6919
|
+
const c = text[i];
|
|
6920
|
+
if (c === "/" && text[i + 1] === "/") {
|
|
6921
|
+
const nl = text.indexOf("\n", i);
|
|
6922
|
+
if (nl < 0) return null;
|
|
6923
|
+
i = nl;
|
|
6924
|
+
} else if (c === "/" && text[i + 1] === "*") {
|
|
6925
|
+
const close = text.indexOf("*/", i + 2);
|
|
6926
|
+
if (close < 0) return null;
|
|
6927
|
+
i = close + 1;
|
|
6928
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
6929
|
+
let j = i + 1;
|
|
6930
|
+
while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1;
|
|
6931
|
+
i = j;
|
|
6932
|
+
} else if (c === "{") depth++;
|
|
6933
|
+
else if (c === "}" && --depth === 0) return { start, body: text.slice(start, i) };
|
|
6934
|
+
}
|
|
6935
|
+
return null;
|
|
6828
6936
|
}
|
|
6829
6937
|
function parseStarterFeatures(text) {
|
|
6830
6938
|
const found = featuresBody(text);
|
|
@@ -6846,6 +6954,7 @@ function parseStarterBlocks(json, source = GENESIS_CONFIG) {
|
|
|
6846
6954
|
const starter = raw?.starter;
|
|
6847
6955
|
if (starter === void 0) return null;
|
|
6848
6956
|
const blocks = starter?.blocks;
|
|
6957
|
+
if (blocks === void 0 && typeof starter === "object" && starter !== null && !Array.isArray(starter)) return null;
|
|
6849
6958
|
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`);
|
|
6850
6959
|
const out = {};
|
|
6851
6960
|
for (const [name, ids] of Object.entries(blocks)) {
|
|
@@ -6913,9 +7022,179 @@ function blockOfSource(source, manifests) {
|
|
|
6913
7022
|
}
|
|
6914
7023
|
return null;
|
|
6915
7024
|
}
|
|
7025
|
+
var BUN_LOCK = "bun.lock";
|
|
7026
|
+
var GENESIS_TAIL = /(?:^|\/)(@marktiderman\/genesis(?:-[a-z0-9-]+)?)$/;
|
|
7027
|
+
var PLAIN_VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]+)?$/;
|
|
7028
|
+
function skipSpace(text, i) {
|
|
7029
|
+
for (; ; ) {
|
|
7030
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
7031
|
+
if (text.startsWith("//", i)) {
|
|
7032
|
+
const nl = text.indexOf("\n", i);
|
|
7033
|
+
i = nl === -1 ? text.length : nl + 1;
|
|
7034
|
+
} else if (text.startsWith("/*", i)) {
|
|
7035
|
+
const close = text.indexOf("*/", i + 2);
|
|
7036
|
+
i = close === -1 ? text.length : close + 2;
|
|
7037
|
+
} else return i;
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
function skipString(text, i) {
|
|
7041
|
+
for (let j = i + 1; j < text.length; j++) {
|
|
7042
|
+
if (text[j] === "\\") j++;
|
|
7043
|
+
else if (text[j] === '"') return j + 1;
|
|
7044
|
+
}
|
|
7045
|
+
throw new Error("an unterminated string");
|
|
7046
|
+
}
|
|
7047
|
+
function skipValue(text, i) {
|
|
7048
|
+
const c = text[i];
|
|
7049
|
+
if (c === '"') return skipString(text, i);
|
|
7050
|
+
if (c === "{" || c === "[") {
|
|
7051
|
+
let depth = 0;
|
|
7052
|
+
for (let j2 = i; j2 < text.length; ) {
|
|
7053
|
+
const d = text[j2];
|
|
7054
|
+
if (d === '"') {
|
|
7055
|
+
j2 = skipString(text, j2);
|
|
7056
|
+
continue;
|
|
7057
|
+
}
|
|
7058
|
+
if (text.startsWith("//", j2) || text.startsWith("/*", j2)) {
|
|
7059
|
+
j2 = skipSpace(text, j2);
|
|
7060
|
+
continue;
|
|
7061
|
+
}
|
|
7062
|
+
if (d === "{" || d === "[") depth++;
|
|
7063
|
+
else if (d === "}" || d === "]") {
|
|
7064
|
+
depth--;
|
|
7065
|
+
if (depth === 0) return j2 + 1;
|
|
7066
|
+
}
|
|
7067
|
+
j2++;
|
|
7068
|
+
}
|
|
7069
|
+
throw new Error("an unclosed object or array");
|
|
7070
|
+
}
|
|
7071
|
+
let j = i;
|
|
7072
|
+
while (j < text.length && !/[\s,}\]]/.test(text[j])) j++;
|
|
7073
|
+
if (j === i) throw new Error(`an unexpected ${JSON.stringify(c ?? "end")} at ${i}`);
|
|
7074
|
+
return j;
|
|
7075
|
+
}
|
|
7076
|
+
function members(text, open) {
|
|
7077
|
+
const out = [];
|
|
7078
|
+
let i = skipSpace(text, open + 1);
|
|
7079
|
+
while (text[i] !== "}") {
|
|
7080
|
+
if (text[i] !== '"') throw new Error(`a key expected at ${i}`);
|
|
7081
|
+
const keyEnd = skipString(text, i);
|
|
7082
|
+
const key2 = JSON.parse(text.slice(i, keyEnd));
|
|
7083
|
+
let j = skipSpace(text, keyEnd);
|
|
7084
|
+
if (text[j] !== ":") throw new Error(`":" expected at ${j}`);
|
|
7085
|
+
const value = skipSpace(text, j + 1);
|
|
7086
|
+
const end = skipValue(text, value);
|
|
7087
|
+
out.push({ key: key2, start: i, end, value });
|
|
7088
|
+
j = skipSpace(text, end);
|
|
7089
|
+
if (text[j] === ",") j = skipSpace(text, j + 1);
|
|
7090
|
+
i = j;
|
|
7091
|
+
if (i >= text.length) throw new Error("an unclosed object");
|
|
7092
|
+
}
|
|
7093
|
+
return out;
|
|
7094
|
+
}
|
|
7095
|
+
function section(text, name) {
|
|
7096
|
+
const open = skipSpace(text, 0);
|
|
7097
|
+
if (text[open] !== "{") throw new Error("not an object");
|
|
7098
|
+
const m = members(text, open).find((x) => x.key === name);
|
|
7099
|
+
return m && text[m.value] === "{" ? m : null;
|
|
7100
|
+
}
|
|
7101
|
+
function parseLoose(fragment) {
|
|
7102
|
+
let out = "";
|
|
7103
|
+
for (let i = 0; i < fragment.length; ) {
|
|
7104
|
+
const c = fragment[i];
|
|
7105
|
+
if (c === '"') {
|
|
7106
|
+
const end = skipString(fragment, i);
|
|
7107
|
+
out += fragment.slice(i, end);
|
|
7108
|
+
i = end;
|
|
7109
|
+
} else if (c === ",") {
|
|
7110
|
+
const next = skipSpace(fragment, i + 1);
|
|
7111
|
+
if (fragment[next] !== "}" && fragment[next] !== "]") out += c;
|
|
7112
|
+
i++;
|
|
7113
|
+
} else if (fragment.startsWith("//", i) || fragment.startsWith("/*", i)) {
|
|
7114
|
+
i = skipSpace(fragment, i);
|
|
7115
|
+
} else {
|
|
7116
|
+
out += c;
|
|
7117
|
+
i++;
|
|
7118
|
+
}
|
|
7119
|
+
}
|
|
7120
|
+
return JSON.parse(out);
|
|
7121
|
+
}
|
|
7122
|
+
function resolution(value) {
|
|
7123
|
+
const first = Array.isArray(value) ? value[0] : null;
|
|
7124
|
+
if (typeof first !== "string") return null;
|
|
7125
|
+
const at = first.lastIndexOf("@");
|
|
7126
|
+
if (at <= 0) return null;
|
|
7127
|
+
return { name: first.slice(0, at), spec: first.slice(at + 1) };
|
|
7128
|
+
}
|
|
7129
|
+
function staleNestedEntries(text, want = () => null) {
|
|
7130
|
+
const packages = section(text, "packages");
|
|
7131
|
+
if (!packages) return [];
|
|
7132
|
+
const list = members(text, packages.value);
|
|
7133
|
+
const value = (m) => parseLoose(text.slice(m.value, m.end));
|
|
7134
|
+
const byKey = new Map(list.map((m) => [m.key, m]));
|
|
7135
|
+
const out = [];
|
|
7136
|
+
for (const m of list) {
|
|
7137
|
+
const tail = GENESIS_TAIL.exec(m.key);
|
|
7138
|
+
if (!tail || tail[1] === m.key) continue;
|
|
7139
|
+
const name = tail[1];
|
|
7140
|
+
const nested = resolution(value(m));
|
|
7141
|
+
if (!nested || nested.name !== name || !PLAIN_VERSION.test(nested.spec)) continue;
|
|
7142
|
+
const rootEntry = byKey.get(name);
|
|
7143
|
+
const rootRes = rootEntry ? resolution(value(rootEntry)) : null;
|
|
7144
|
+
const target = want(name) ?? (rootRes && PLAIN_VERSION.test(rootRes.spec) ? rootRes.spec : null);
|
|
7145
|
+
if (!rootEntry || !target || target === nested.spec) continue;
|
|
7146
|
+
const parent = m.key.slice(0, m.key.length - name.length - 1);
|
|
7147
|
+
const parentEntry = byKey.get(parent);
|
|
7148
|
+
const meta = parentEntry ? value(parentEntry)[2] : void 0;
|
|
7149
|
+
const declared = meta && typeof meta === "object" ? meta : {};
|
|
7150
|
+
const range = ["dependencies", "peerDependencies", "optionalDependencies"].map((s) => declared[s]?.[name]).find((r) => typeof r === "string");
|
|
7151
|
+
if (!range || satisfies(target, range) !== true) continue;
|
|
7152
|
+
out.push({ key: m.key, name, parent, version: nested.spec, root: target, range });
|
|
7153
|
+
}
|
|
7154
|
+
return out;
|
|
7155
|
+
}
|
|
7156
|
+
function readBunLock(dir) {
|
|
7157
|
+
const file = path20.join(dir, BUN_LOCK);
|
|
7158
|
+
return existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
7159
|
+
}
|
|
7160
|
+
function findLockfile(root) {
|
|
7161
|
+
let dir = path20.resolve(root);
|
|
7162
|
+
for (; ; ) {
|
|
7163
|
+
if (existsSync(path20.join(dir, "pnpm-lock.yaml"))) return { pm: "pnpm", dir };
|
|
7164
|
+
if (existsSync(path20.join(dir, "bun.lock")) || existsSync(path20.join(dir, "bun.lockb"))) return { pm: "bun", dir };
|
|
7165
|
+
if (existsSync(path20.join(dir, "yarn.lock"))) return { pm: "yarn", dir };
|
|
7166
|
+
if (existsSync(path20.join(dir, "package-lock.json"))) return { pm: "npm", dir };
|
|
7167
|
+
const parent = path20.dirname(dir);
|
|
7168
|
+
if (parent === dir) return null;
|
|
7169
|
+
dir = parent;
|
|
7170
|
+
}
|
|
7171
|
+
}
|
|
6916
7172
|
|
|
6917
7173
|
// src/doctor/lock-files.ts
|
|
7174
|
+
function checkBunLock(ctx) {
|
|
7175
|
+
const found = findLockfile(ctx.root);
|
|
7176
|
+
if (found?.pm !== "bun") return;
|
|
7177
|
+
const text = readBunLock(found.dir);
|
|
7178
|
+
if (text === null) return;
|
|
7179
|
+
const file = path20.relative(ctx.root, path20.join(found.dir, BUN_LOCK)).split(path20.sep).join("/");
|
|
7180
|
+
let stale;
|
|
7181
|
+
try {
|
|
7182
|
+
stale = staleNestedEntries(text);
|
|
7183
|
+
} catch {
|
|
7184
|
+
return;
|
|
7185
|
+
}
|
|
7186
|
+
for (const s of stale) {
|
|
7187
|
+
ctx.report({
|
|
7188
|
+
rule: "lock-files",
|
|
7189
|
+
level: "warn",
|
|
7190
|
+
file,
|
|
7191
|
+
subject: s.key,
|
|
7192
|
+
message: `keeps a nested copy of ${s.name}@${s.version} under ${s.parent} beside the root's ${s.root}, which satisfies its ${s.range}: Bun keeps it across installs, so the app runs two copies (a provider from one is invisible to hooks from the other). Delete the "${s.key}" entry from ${file}'s packages, then reinstall (bun install); genesis upgrade does both`
|
|
7193
|
+
});
|
|
7194
|
+
}
|
|
7195
|
+
}
|
|
6918
7196
|
async function checkLockFiles(ctx) {
|
|
7197
|
+
checkBunLock(ctx);
|
|
6919
7198
|
if (!existsSync(path20.join(ctx.root, LOCK_FILE))) return;
|
|
6920
7199
|
let lock;
|
|
6921
7200
|
try {
|
|
@@ -6944,15 +7223,44 @@ async function checkLockFiles(ctx) {
|
|
|
6944
7223
|
});
|
|
6945
7224
|
}
|
|
6946
7225
|
const local = localPackageNames(ctx.root);
|
|
7226
|
+
let home = null;
|
|
7227
|
+
try {
|
|
7228
|
+
home = databaseElsewhere(ctx.root);
|
|
7229
|
+
} catch {
|
|
7230
|
+
}
|
|
7231
|
+
const elsewhere = home ? Object.keys(lock.files).filter(isSupabasePath) : [];
|
|
7232
|
+
if (home && elsewhere.length) {
|
|
7233
|
+
ctx.report({
|
|
7234
|
+
rule: "lock-files",
|
|
7235
|
+
level: "info",
|
|
7236
|
+
file: LOCK_FILE,
|
|
7237
|
+
subject: "supabase/",
|
|
7238
|
+
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`
|
|
7239
|
+
});
|
|
7240
|
+
}
|
|
6947
7241
|
for (const [rel, entry] of Object.entries(lock.files)) {
|
|
7242
|
+
if (home && isSupabasePath(rel)) continue;
|
|
6948
7243
|
if (ownedKeyProblem(rel, entry.source, local)) continue;
|
|
6949
7244
|
if (offManifests.length && blockOfSource(entry.source, offManifests)) continue;
|
|
6950
|
-
let
|
|
7245
|
+
let file;
|
|
6951
7246
|
try {
|
|
6952
|
-
|
|
7247
|
+
file = appPath2(ctx.root, rel);
|
|
6953
7248
|
} catch {
|
|
6954
7249
|
continue;
|
|
6955
7250
|
}
|
|
7251
|
+
let text;
|
|
7252
|
+
try {
|
|
7253
|
+
text = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
7254
|
+
} catch (err) {
|
|
7255
|
+
ctx.report({
|
|
7256
|
+
rule: "lock-files",
|
|
7257
|
+
level: "warn",
|
|
7258
|
+
file: rel,
|
|
7259
|
+
subject: rel,
|
|
7260
|
+
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}`
|
|
7261
|
+
});
|
|
7262
|
+
continue;
|
|
7263
|
+
}
|
|
6956
7264
|
if (text === null) {
|
|
6957
7265
|
if (entry.deleted) continue;
|
|
6958
7266
|
ctx.report({
|
|
@@ -6977,7 +7285,59 @@ async function checkLockFiles(ctx) {
|
|
|
6977
7285
|
});
|
|
6978
7286
|
}
|
|
6979
7287
|
}
|
|
6980
|
-
|
|
7288
|
+
function checkDatabaseHome(ctx) {
|
|
7289
|
+
const home = databaseElsewhere(ctx.root);
|
|
7290
|
+
if (!home) return;
|
|
7291
|
+
if (home.app && !home.hasSupabase) {
|
|
7292
|
+
ctx.report({
|
|
7293
|
+
rule: "database-elsewhere",
|
|
7294
|
+
level: "warn",
|
|
7295
|
+
file: "genesis.config.json",
|
|
7296
|
+
subject: home.app,
|
|
7297
|
+
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)`
|
|
7298
|
+
});
|
|
7299
|
+
}
|
|
7300
|
+
if (existsSync(path20.join(ctx.root, "supabase"))) {
|
|
7301
|
+
ctx.report({
|
|
7302
|
+
rule: "database-elsewhere",
|
|
7303
|
+
level: "warn",
|
|
7304
|
+
file: "supabase",
|
|
7305
|
+
subject: "supabase/",
|
|
7306
|
+
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`
|
|
7307
|
+
});
|
|
7308
|
+
}
|
|
7309
|
+
}
|
|
7310
|
+
function checkEslintConfig(ctx) {
|
|
7311
|
+
const pkg = readPackageJson(ctx.root);
|
|
7312
|
+
const native = appPlatform(pkg) === "native" || (ctx.config.packs?.includes("native") ?? false);
|
|
7313
|
+
if (!native) return;
|
|
7314
|
+
const file = findEslintConfig(ctx.root);
|
|
7315
|
+
if (!file) return;
|
|
7316
|
+
let text;
|
|
7317
|
+
try {
|
|
7318
|
+
text = readFileSync(path20.join(ctx.root, file), "utf8");
|
|
7319
|
+
} catch {
|
|
7320
|
+
return;
|
|
7321
|
+
}
|
|
7322
|
+
if (!usesGenesisLint(text)) {
|
|
7323
|
+
ctx.report({
|
|
7324
|
+
rule: "genesis-eslint-config",
|
|
7325
|
+
level: "warn",
|
|
7326
|
+
file,
|
|
7327
|
+
subject: "@marktiderman/genesis-cli/eslint",
|
|
7328
|
+
message: `doesn't load Genesis's lint rules, so genesis upgrade can't bring new ones (React Native Testing Library 14's await rules today). Run genesis codemod genesis-cli-eslint-config, or add const { genesis } = require("@marktiderman/genesis-cli/eslint") (import { genesis } from \u2026 in an ES module) and ...genesis("native") last in the array the config exports, with ${TESTING_LIBRARY} in devDependencies`
|
|
7329
|
+
});
|
|
7330
|
+
} else if (!hasTestingLibrary(pkg)) {
|
|
7331
|
+
ctx.report({
|
|
7332
|
+
rule: "genesis-eslint-config",
|
|
7333
|
+
level: "warn",
|
|
7334
|
+
file: "package.json",
|
|
7335
|
+
subject: TESTING_LIBRARY,
|
|
7336
|
+
message: `${file} loads Genesis's native lint rules, which need ${TESTING_LIBRARY}: add it to devDependencies (pnpm add -D ${TESTING_LIBRARY}), or the lint can't load its config`
|
|
7337
|
+
});
|
|
7338
|
+
}
|
|
7339
|
+
}
|
|
7340
|
+
var RATCHETED_BY_DEFAULT = ["deprecated-import", "genesis-eslint-config"];
|
|
6981
7341
|
async function runDoctor(options = {}) {
|
|
6982
7342
|
const root = path20.resolve(options.root ?? process.cwd());
|
|
6983
7343
|
const loaded = options.config ? { config: options.config, dir: root } : loadConfig(root, options.configPath);
|
|
@@ -7079,6 +7439,8 @@ function builtinChecks(config, options = {}) {
|
|
|
7079
7439
|
{ name: "agent-guide", check: checkAgentGuide },
|
|
7080
7440
|
{ name: "overlays", check: (ctx) => checkOverlays(ctx) },
|
|
7081
7441
|
{ name: "lock-files", check: checkLockFiles },
|
|
7442
|
+
{ name: "database-elsewhere", check: checkDatabaseHome },
|
|
7443
|
+
{ name: "eslint-config", check: checkEslintConfig },
|
|
7082
7444
|
...(config.packs ?? []).map((p) => packs[p]),
|
|
7083
7445
|
...config.packs?.includes("supabase") && config.contracts && options.contracts !== false ? [{ name: "contracts", check: (ctx) => checkContracts(ctx) }] : []
|
|
7084
7446
|
];
|