@marktiderman/genesis-cli 1.10.0 → 1.11.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 +5 -2
- package/dist/cli.js +143 -29
- package/dist/cli.js.map +1 -1
- package/dist/doctor.d.ts +7 -7
- package/dist/doctor.js +142 -28
- package/dist/doctor.js.map +1 -1
- package/dist/genesis-catalog.json +31 -4
- package/dist/index.js +142 -28
- package/dist/index.js.map +1 -1
- package/dist/vite.js +142 -28
- package/dist/vite.js.map +1 -1
- package/package.json +2 -2
package/dist/vite.js
CHANGED
|
@@ -963,7 +963,8 @@ var BUILTIN_RULES = [
|
|
|
963
963
|
"migration-rls",
|
|
964
964
|
"migration-definer-search-path",
|
|
965
965
|
"migration-edited",
|
|
966
|
-
"migration-testing-kit"
|
|
966
|
+
"migration-testing-kit",
|
|
967
|
+
"migration-view-rls"
|
|
967
968
|
];
|
|
968
969
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
969
970
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -1792,6 +1793,7 @@ function checkSupabasePack(ctx) {
|
|
|
1792
1793
|
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
1793
1794
|
}
|
|
1794
1795
|
checkRls(ctx, migrations, exposed);
|
|
1796
|
+
checkViewInvoker(ctx, migrations, exposed);
|
|
1795
1797
|
checkDefinerSearchPath(ctx, migrations);
|
|
1796
1798
|
checkTestingKit(ctx, migrations);
|
|
1797
1799
|
}
|
|
@@ -1921,6 +1923,50 @@ function checkRls(ctx, migrations, exposed) {
|
|
|
1921
1923
|
});
|
|
1922
1924
|
}
|
|
1923
1925
|
}
|
|
1926
|
+
function checkViewInvoker(ctx, migrations, exposed) {
|
|
1927
|
+
const views = /* @__PURE__ */ new Map();
|
|
1928
|
+
const name = String.raw`([\w$.]+)`;
|
|
1929
|
+
const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
|
|
1930
|
+
for (const { file, statements } of migrations) {
|
|
1931
|
+
for (const { sql, line } of statements) {
|
|
1932
|
+
const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
|
|
1933
|
+
if (create) {
|
|
1934
|
+
if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
|
|
1935
|
+
const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
|
|
1936
|
+
views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
|
|
1937
|
+
continue;
|
|
1938
|
+
}
|
|
1939
|
+
const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
|
|
1940
|
+
if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
|
|
1941
|
+
const state = views.get(qualify(alter[1]));
|
|
1942
|
+
if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
|
|
1946
|
+
if (rename) {
|
|
1947
|
+
const from = qualify(rename[1]);
|
|
1948
|
+
const state = views.get(from);
|
|
1949
|
+
if (state) {
|
|
1950
|
+
views.delete(from);
|
|
1951
|
+
views.set(`${schemaOf(from)}.${rename[2]}`, state);
|
|
1952
|
+
}
|
|
1953
|
+
continue;
|
|
1954
|
+
}
|
|
1955
|
+
const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1956
|
+
if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
for (const [v, at] of views) {
|
|
1960
|
+
if (at.invoker || !exposed.has(schemaOf(v))) continue;
|
|
1961
|
+
ctx.report({
|
|
1962
|
+
rule: "migration-view-rls",
|
|
1963
|
+
file: at.file,
|
|
1964
|
+
line: at.line,
|
|
1965
|
+
subject: v,
|
|
1966
|
+
message: `${v} runs as its owner, so it reads past row level security; create it "with (security_invoker = true)" or add "alter view ${v} set (security_invoker = true);"`
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1924
1970
|
function checkDefinerSearchPath(ctx, migrations) {
|
|
1925
1971
|
const fns = /* @__PURE__ */ new Map();
|
|
1926
1972
|
const keysFor = (sql, nameEnd, fnName) => {
|
|
@@ -2131,6 +2177,7 @@ function satisfies(version, range) {
|
|
|
2131
2177
|
// src/doctor/installs.ts
|
|
2132
2178
|
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
2133
2179
|
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
2180
|
+
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)$/;
|
|
2134
2181
|
var readManifest = (dir) => {
|
|
2135
2182
|
try {
|
|
2136
2183
|
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
@@ -2205,12 +2252,14 @@ function genesisInstalls(root) {
|
|
|
2205
2252
|
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
2206
2253
|
});
|
|
2207
2254
|
const app = readManifest(root);
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2255
|
+
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
2256
|
+
const runtimeDeps = {
|
|
2257
|
+
...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
|
|
2258
|
+
...app?.peerDependencies,
|
|
2259
|
+
...app?.optionalDependencies,
|
|
2260
|
+
...app?.dependencies
|
|
2261
|
+
};
|
|
2262
|
+
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
2214
2263
|
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
2215
2264
|
const top = path14.join(root, "node_modules");
|
|
2216
2265
|
walk(
|
|
@@ -2293,11 +2342,21 @@ function stripForImports(code) {
|
|
|
2293
2342
|
const templates = [];
|
|
2294
2343
|
let depth = 0;
|
|
2295
2344
|
let i = 0;
|
|
2345
|
+
let sure = true;
|
|
2296
2346
|
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
2297
|
-
const
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2347
|
+
const before = () => out.slice(-24).join("");
|
|
2348
|
+
const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
|
|
2349
|
+
const startsExpression = (b) => {
|
|
2350
|
+
const t = b.replace(/\s+$/, "");
|
|
2351
|
+
if (!t) return true;
|
|
2352
|
+
if (KEYWORD.test(b)) return true;
|
|
2353
|
+
return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
|
|
2354
|
+
};
|
|
2355
|
+
const exprStart = () => startsExpression(before());
|
|
2356
|
+
const taggedTemplate = () => {
|
|
2357
|
+
const b = out.slice(-48).join("");
|
|
2358
|
+
const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
|
|
2359
|
+
return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
|
|
2301
2360
|
};
|
|
2302
2361
|
const templateBody = () => {
|
|
2303
2362
|
while (i < n) {
|
|
@@ -2320,8 +2379,9 @@ function stripForImports(code) {
|
|
|
2320
2379
|
i++;
|
|
2321
2380
|
}
|
|
2322
2381
|
}
|
|
2382
|
+
sure = false;
|
|
2323
2383
|
};
|
|
2324
|
-
while (i < n) {
|
|
2384
|
+
while (i < n && sure) {
|
|
2325
2385
|
const ch = code[i];
|
|
2326
2386
|
const next = code[i + 1];
|
|
2327
2387
|
if (ch === "/" && next === "/") {
|
|
@@ -2340,7 +2400,45 @@ function stripForImports(code) {
|
|
|
2340
2400
|
out.push(" ");
|
|
2341
2401
|
i += 2;
|
|
2342
2402
|
}
|
|
2343
|
-
} else if (
|
|
2403
|
+
} else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
|
|
2404
|
+
const afterBrace = /[}>]\s*$/.test(before());
|
|
2405
|
+
const start = i;
|
|
2406
|
+
const mark = out.length;
|
|
2407
|
+
out.push("/");
|
|
2408
|
+
i++;
|
|
2409
|
+
let inClass = false;
|
|
2410
|
+
for (; ; ) {
|
|
2411
|
+
const c = code[i];
|
|
2412
|
+
if (c === void 0 || c === "\n") {
|
|
2413
|
+
if (afterBrace) {
|
|
2414
|
+
out.length = mark;
|
|
2415
|
+
out.push("/");
|
|
2416
|
+
i = start + 1;
|
|
2417
|
+
} else sure = false;
|
|
2418
|
+
break;
|
|
2419
|
+
}
|
|
2420
|
+
if (c === "\\") {
|
|
2421
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2422
|
+
i += 2;
|
|
2423
|
+
continue;
|
|
2424
|
+
}
|
|
2425
|
+
i++;
|
|
2426
|
+
if (c === "[") inClass = true;
|
|
2427
|
+
else if (c === "]") inClass = false;
|
|
2428
|
+
else if (c === "/" && !inClass) {
|
|
2429
|
+
if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
|
|
2430
|
+
out.length = mark;
|
|
2431
|
+
out.push("/");
|
|
2432
|
+
i = start + 1;
|
|
2433
|
+
break;
|
|
2434
|
+
}
|
|
2435
|
+
out.push("/");
|
|
2436
|
+
break;
|
|
2437
|
+
}
|
|
2438
|
+
out.push(" ");
|
|
2439
|
+
}
|
|
2440
|
+
if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
|
|
2441
|
+
} else if ((ch === '"' || ch === "'") && exprStart()) {
|
|
2344
2442
|
const keep = isSpecifier();
|
|
2345
2443
|
out.push(ch);
|
|
2346
2444
|
i++;
|
|
@@ -2353,11 +2451,12 @@ function stripForImports(code) {
|
|
|
2353
2451
|
i++;
|
|
2354
2452
|
}
|
|
2355
2453
|
}
|
|
2356
|
-
if (i
|
|
2454
|
+
if (code[i] !== ch) sure = false;
|
|
2455
|
+
else {
|
|
2357
2456
|
out.push(code[i]);
|
|
2358
2457
|
i++;
|
|
2359
2458
|
}
|
|
2360
|
-
} else if (ch === "`") {
|
|
2459
|
+
} else if (ch === "`" && (exprStart() || taggedTemplate())) {
|
|
2361
2460
|
out.push("`");
|
|
2362
2461
|
i++;
|
|
2363
2462
|
templateBody();
|
|
@@ -2374,7 +2473,7 @@ function stripForImports(code) {
|
|
|
2374
2473
|
i++;
|
|
2375
2474
|
}
|
|
2376
2475
|
}
|
|
2377
|
-
return out.join("");
|
|
2476
|
+
return sure && templates.length === 0 ? out.join("") : null;
|
|
2378
2477
|
}
|
|
2379
2478
|
function bindings(clause) {
|
|
2380
2479
|
const out = [];
|
|
@@ -2488,6 +2587,11 @@ function createTrail(ctx) {
|
|
|
2488
2587
|
const files = [];
|
|
2489
2588
|
let lost = false;
|
|
2490
2589
|
const code = stripped(file);
|
|
2590
|
+
if (code === null) {
|
|
2591
|
+
const out2 = { files: [], lost: true };
|
|
2592
|
+
importsCache.set(file.absolutePath, out2);
|
|
2593
|
+
return out2;
|
|
2594
|
+
}
|
|
2491
2595
|
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
2492
2596
|
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2493
2597
|
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
@@ -2524,20 +2628,23 @@ function createTrail(ctx) {
|
|
|
2524
2628
|
};
|
|
2525
2629
|
const strippedCache = /* @__PURE__ */ new Map();
|
|
2526
2630
|
const stripped = (file) => {
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
return c;
|
|
2631
|
+
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
2632
|
+
return strippedCache.get(file.absolutePath);
|
|
2530
2633
|
};
|
|
2531
2634
|
const memo = /* @__PURE__ */ new WeakMap();
|
|
2532
2635
|
const reach = (file, test2, depth, seen) => {
|
|
2533
2636
|
let cache = memo.get(test2);
|
|
2534
|
-
if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
|
|
2637
|
+
if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
2535
2638
|
const k = `${file.absolutePath}\0${depth}`;
|
|
2536
|
-
const
|
|
2537
|
-
if (
|
|
2639
|
+
const free = cache.free.get(k);
|
|
2640
|
+
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
2641
|
+
const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
2642
|
+
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
2538
2643
|
let result;
|
|
2539
|
-
|
|
2540
|
-
|
|
2644
|
+
const cut = /* @__PURE__ */ new Set();
|
|
2645
|
+
const code = stripped(file);
|
|
2646
|
+
if (code === null) result = "unknown";
|
|
2647
|
+
else if (test2(code)) result = "yes";
|
|
2541
2648
|
else {
|
|
2542
2649
|
const { files, lost } = importsOf(file);
|
|
2543
2650
|
let unknown = lost && depth > 0;
|
|
@@ -2546,7 +2653,7 @@ function createTrail(ctx) {
|
|
|
2546
2653
|
seen.add(file.absolutePath);
|
|
2547
2654
|
for (const abs of files) {
|
|
2548
2655
|
if (seen.has(abs)) {
|
|
2549
|
-
cut
|
|
2656
|
+
cut.add(abs);
|
|
2550
2657
|
continue;
|
|
2551
2658
|
}
|
|
2552
2659
|
const target = read(abs);
|
|
@@ -2555,7 +2662,7 @@ function createTrail(ctx) {
|
|
|
2555
2662
|
continue;
|
|
2556
2663
|
}
|
|
2557
2664
|
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
2558
|
-
|
|
2665
|
+
for (const m of c) cut.add(m);
|
|
2559
2666
|
if (r === "yes") {
|
|
2560
2667
|
result = "yes";
|
|
2561
2668
|
break;
|
|
@@ -2563,11 +2670,18 @@ function createTrail(ctx) {
|
|
|
2563
2670
|
if (r === "unknown") unknown = true;
|
|
2564
2671
|
}
|
|
2565
2672
|
seen.delete(file.absolutePath);
|
|
2673
|
+
cut.delete(file.absolutePath);
|
|
2566
2674
|
}
|
|
2567
2675
|
if (result === "no" && unknown) result = "unknown";
|
|
2568
2676
|
}
|
|
2569
|
-
if (result === "yes" ||
|
|
2570
|
-
|
|
2677
|
+
if (result === "yes" || cut.size === 0) {
|
|
2678
|
+
cache.free.set(k, result);
|
|
2679
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
2680
|
+
}
|
|
2681
|
+
const entries = cache.cut.get(k) ?? [];
|
|
2682
|
+
entries.push({ cut: [...cut], result });
|
|
2683
|
+
cache.cut.set(k, entries);
|
|
2684
|
+
return [result, cut];
|
|
2571
2685
|
};
|
|
2572
2686
|
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
2573
2687
|
}
|