@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 CHANGED
@@ -358,7 +358,7 @@ Exit codes: `0` pass, `1` findings, `2` the doctor couldn't run (bad config, Gen
358
358
  | `raw-color` | error | Hex and `rgb()/hsl()` literals in code and CSS, via the same lexer as the repo's `check:token-usage` (comments, issue refs and `hsl(var(--x))` are fine). A brand file that defines token values needs an `allow` entry. |
359
359
  | `undefined-token` | error | `var(--x)` where the theme doesn't define `--x`. Tokens declared in the app's CSS (or only `tokenFiles`) and inline style custom properties count as defined; `--tw-*` and `--radix-*` are ignored. |
360
360
  | `shadowed-export` | error | An exported value named like a Genesis export (`export function Button`). Reuse or extend it. |
361
- | `duplicate-genesis-package` | warn | More than one copy of a `@marktiderman/genesis-*` package that the app can load, with each copy's path, version and the ranges that asked for it. Found by resolving dependencies the way Node does, from each package's real folder, so npm/yarn/bun hoisted and nested trees, pnpm's `.pnpm` store (in the app, or at the workspace root above a sub-app) and bun's isolated `.bun` store all count; a store entry nothing resolves to is ignored. Two copies are two module instances: a `DataProvider` from one is invisible to hooks from the other. A copy reached only through dev tooling (the app's `devDependencies`, or anything under `@marktiderman/genesis-cli`, wherever it's listed) is `[dev only]`: every path to it from the app runs through a declared devDependency (or the CLI). When exactly one copy is reached from a declared runtime dependency and every other copy is dev-only, the finding is `info` (it can't split the app's contexts). Anything else warns, a copy reached through an undeclared hoisted package included. An app with no runtime dependencies at all (a bundled SPA listing everything in `devDependencies`) has its devDependencies taken as runtime. |
361
+ | `duplicate-genesis-package` | warn | More than one copy of a `@marktiderman/genesis-*` package that the app can load, with each copy's path, version and the ranges that asked for it. Found by resolving dependencies the way Node does, from each package's real folder, so npm/yarn/bun hoisted and nested trees, pnpm's `.pnpm` store (in the app, or at the workspace root above a sub-app) and bun's isolated `.bun` store all count; a store entry nothing resolves to is ignored. Two copies are two module instances: a `DataProvider` from one is invisible to hooks from the other. A copy reached only through dev tooling (the app's `devDependencies`, or anything under `@marktiderman/genesis-cli`, wherever it's listed) is `[dev only]`: every path to it from the app runs through declared tooling (test runners, `@types/*`, linters and formatters, compilers and bundlers, Storybook, release tools, or the CLI). Other devDependencies count as runtime: a bundler ships what the app imports from them. When exactly one copy is reached from a declared runtime dependency and every other copy is dev-only, the finding is `info` (it can't split the app's contexts). Anything else warns, a copy reached through an undeclared hoisted package included. An app with no runtime dependencies at all (a bundled SPA listing everything in `devDependencies`) has its devDependencies taken as runtime. |
362
362
  | `peer-range-mismatch` | warn | An installed Genesis package's `peerDependencies` range on another Genesis package that the copy it resolves (looked up from its own folder, as Node does) doesn't satisfy: the package, the range and the installed version. Missing peers and non-semver ranges (`workspace:*`) are skipped. Ranges are read with npm's grammar (`^ ~ x - ||`, prereleases only when the range names one). A mismatch inside a dev-only copy (the CLI's own tree) is `info`. |
363
363
  | `hand-rolled-sub-nav` | warn | A route under the layout that renders `AppShell` that switches its sections with its own page-level `<TabsList>` or `<SubNavTabs>`, when the installed Genesis has `useAppShellSubNav`. Tabs inside a card, dialog, sheet, popover, accordion, panel, table or another tab's content are fine, as are pages that call the hook. Use `useAppShellSubNav(items, { mode: "tabs" })`, `AppShellPageHeader` and `AppShellSubNavEnd` from `@marktiderman/genesis-ui/layout` ([sub-navigation](../ui/SKILL.md)). |
364
364
  | `local-genesis-copy` | warn | An app component definition named like a component of `uiPackage` or of `componentPackages` (forms-studio's `ResourceHeader`, `SettingsSection`, `ResourceSettingsPage`, `HeadlineNumbers`, `SummaryCard`, `ShareDialog`, …): "Genesis already has X". A definition renders JSX, isn't in a file that imports the Genesis one, and is exported or lives outside the routes folder; a route's own non-exported functions and anything passed as `component` / `errorComponent` / `pendingComponent` / `notFoundComponent` (TanStack's `FormError`) are not copies. An exported genesis-ui value is `shadowed-export` instead; `const X = lazy(() => import("@marktiderman/genesis-…"))` is fine. |
@@ -396,7 +396,9 @@ components it renders (or names as `component:`), `lazy(() => import(…))` /
396
396
  `lazyRouteComponent(…)`, re-exports and barrels, through relative paths, tsconfig/jsconfig
397
397
  `paths` and `baseUrl` (following `extends`, to a file or a package's config), package.json
398
398
  `imports` and the `@/`, `~/`, `#/` defaults. Imports it only calls (data helpers, hooks) aren't
399
- followed, and an `import(…)` inside a string or comment isn't one. An import that is neither an
399
+ followed, and an `import(…)` inside a string, comment, template or regex literal isn't one (the
400
+ tokenizer reads regex literals and JSX text such as `Rock 'n roll`; a file it can't read for sure
401
+ is treated as unknown). An import that is neither an
400
402
  app file nor an installed or declared package makes that route unsure, and the route rules don't
401
403
  report it; it never makes a route a layout. Past six modules the trail stops as a one-hop check
402
404
  would: the route is reported.
@@ -463,6 +465,7 @@ bodies blanked, so text inside a function body never matches; the one exception
463
465
  | `migration-definer-search-path` | error | A `security definer` function or procedure without `set search_path`. Functions are keyed by name and argument types, so overloads are separate; `alter function … security definer` makes one definer, `alter function … set search_path` fixes it, and renames, replaces and drops are followed. |
464
466
  | `migration-edited` | error | A `.sql` migration that already exists at the merge base with `supabase.base` (default `origin/main`) was modified, deleted or renamed. Applied migrations are never edited; add a new one. Skipped outside a git repo; a **warn** when the base ref isn't available. |
465
467
  | `migration-testing-kit` | error | A migration that uses `genesis_testing`, genesis-supabase's pgTAP kit for test databases only (it signs in as anyone and resets roles). Keep it in `supabase/tests/database/000_genesis_testing.test.sql`. |
468
+ | `migration-view-rls` | error | A view in an exposed schema that runs as its owner once every migration has run: created without `with (security_invoker = true)`, replaced without it, or reset by `alter view … reset (security_invoker)`. A plain view reads past row level security on every table it selects from. `alter view … set (security_invoker = true)`, renames and drops are followed. A view that runs as its owner on purpose (it filters rows itself) takes an `allow` entry: `{ "rule": "migration-view-rls", "match": "public.profile_cards", "reason": "…" }`. |
466
469
 
467
470
  **Which migrations are new.** In a git repo with the base ref, a migration is new when it was
468
471
  added, modified or is untracked since the merge base. `since` (a file name or timestamp prefix)
package/dist/cli.js CHANGED
@@ -2503,7 +2503,8 @@ var init_rules = __esm({
2503
2503
  "migration-rls",
2504
2504
  "migration-definer-search-path",
2505
2505
  "migration-edited",
2506
- "migration-testing-kit"
2506
+ "migration-testing-kit",
2507
+ "migration-view-rls"
2507
2508
  ];
2508
2509
  DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
2509
2510
  STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -3199,6 +3200,7 @@ function checkSupabasePack(ctx) {
3199
3200
  checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
3200
3201
  }
3201
3202
  checkRls(ctx, migrations, exposed);
3203
+ checkViewInvoker(ctx, migrations, exposed);
3202
3204
  checkDefinerSearchPath(ctx, migrations);
3203
3205
  checkTestingKit(ctx, migrations);
3204
3206
  }
@@ -3328,6 +3330,50 @@ function checkRls(ctx, migrations, exposed) {
3328
3330
  });
3329
3331
  }
3330
3332
  }
3333
+ function checkViewInvoker(ctx, migrations, exposed) {
3334
+ const views = /* @__PURE__ */ new Map();
3335
+ const name = String.raw`([\w$.]+)`;
3336
+ const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
3337
+ for (const { file, statements } of migrations) {
3338
+ for (const { sql, line } of statements) {
3339
+ const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
3340
+ if (create) {
3341
+ if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
3342
+ const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
3343
+ views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
3344
+ continue;
3345
+ }
3346
+ const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
3347
+ if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
3348
+ const state = views.get(qualify(alter[1]));
3349
+ if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
3350
+ continue;
3351
+ }
3352
+ const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
3353
+ if (rename) {
3354
+ const from = qualify(rename[1]);
3355
+ const state = views.get(from);
3356
+ if (state) {
3357
+ views.delete(from);
3358
+ views.set(`${schemaOf(from)}.${rename[2]}`, state);
3359
+ }
3360
+ continue;
3361
+ }
3362
+ const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
3363
+ if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
3364
+ }
3365
+ }
3366
+ for (const [v, at] of views) {
3367
+ if (at.invoker || !exposed.has(schemaOf(v))) continue;
3368
+ ctx.report({
3369
+ rule: "migration-view-rls",
3370
+ file: at.file,
3371
+ line: at.line,
3372
+ subject: v,
3373
+ 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);"`
3374
+ });
3375
+ }
3376
+ }
3331
3377
  function checkDefinerSearchPath(ctx, migrations) {
3332
3378
  const fns = /* @__PURE__ */ new Map();
3333
3379
  const keysFor = (sql, nameEnd, fnName) => {
@@ -3596,12 +3642,14 @@ function genesisInstalls(root) {
3596
3642
  return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
3597
3643
  });
3598
3644
  const app = readManifest(root);
3599
- let runtimeDeps = { ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
3600
- let devDeps = Object.fromEntries(Object.entries(app?.devDependencies ?? {}).filter(([n]) => !(n in runtimeDeps)));
3601
- if (Object.keys(runtimeDeps).length === 0) {
3602
- runtimeDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => !DEV_TOOLS.has(n)));
3603
- devDeps = Object.fromEntries(Object.entries(devDeps).filter(([n]) => DEV_TOOLS.has(n)));
3604
- }
3645
+ const declaredDev = Object.entries(app?.devDependencies ?? {});
3646
+ const runtimeDeps = {
3647
+ ...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
3648
+ ...app?.peerDependencies,
3649
+ ...app?.optionalDependencies,
3650
+ ...app?.dependencies
3651
+ };
3652
+ const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
3605
3653
  walk2("runtime", rootsOf(runtimeDeps, "the app"));
3606
3654
  const top = path32.join(root, "node_modules");
3607
3655
  walk2(
@@ -3672,13 +3720,14 @@ function checkPeerRanges(ctx) {
3672
3720
  }
3673
3721
  }
3674
3722
  }
3675
- var GENESIS, DEV_TOOLS, readManifest, real;
3723
+ var GENESIS, DEV_TOOLS, NON_SHIPPING, readManifest, real;
3676
3724
  var init_installs = __esm({
3677
3725
  "src/doctor/installs.ts"() {
3678
3726
  init_genesis();
3679
3727
  init_semver();
3680
3728
  GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
3681
3729
  DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
3730
+ 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)$/;
3682
3731
  readManifest = (dir) => {
3683
3732
  try {
3684
3733
  return JSON.parse(readFileSync(path32.join(dir, "package.json"), "utf8"));
@@ -3702,11 +3751,21 @@ function stripForImports(code) {
3702
3751
  const templates = [];
3703
3752
  let depth = 0;
3704
3753
  let i = 0;
3754
+ let sure = true;
3705
3755
  const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
3706
- const opensString = () => {
3707
- const before = out.slice(-12).join("");
3708
- if (!/[\w$]$/.test(before)) return true;
3709
- return /(?:^|[^\w$])(?:return|from|import|case|typeof|in|of|else|yield|await|export|default|void|require)$/.test(before);
3756
+ const before = () => out.slice(-24).join("");
3757
+ const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
3758
+ const startsExpression = (b) => {
3759
+ const t = b.replace(/\s+$/, "");
3760
+ if (!t) return true;
3761
+ if (KEYWORD.test(b)) return true;
3762
+ return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
3763
+ };
3764
+ const exprStart = () => startsExpression(before());
3765
+ const taggedTemplate = () => {
3766
+ const b = out.slice(-48).join("");
3767
+ const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
3768
+ return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
3710
3769
  };
3711
3770
  const templateBody = () => {
3712
3771
  while (i < n) {
@@ -3729,8 +3788,9 @@ function stripForImports(code) {
3729
3788
  i++;
3730
3789
  }
3731
3790
  }
3791
+ sure = false;
3732
3792
  };
3733
- while (i < n) {
3793
+ while (i < n && sure) {
3734
3794
  const ch = code[i];
3735
3795
  const next = code[i + 1];
3736
3796
  if (ch === "/" && next === "/") {
@@ -3749,7 +3809,45 @@ function stripForImports(code) {
3749
3809
  out.push(" ");
3750
3810
  i += 2;
3751
3811
  }
3752
- } else if ((ch === '"' || ch === "'") && opensString()) {
3812
+ } else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
3813
+ const afterBrace = /[}>]\s*$/.test(before());
3814
+ const start = i;
3815
+ const mark = out.length;
3816
+ out.push("/");
3817
+ i++;
3818
+ let inClass = false;
3819
+ for (; ; ) {
3820
+ const c = code[i];
3821
+ if (c === void 0 || c === "\n") {
3822
+ if (afterBrace) {
3823
+ out.length = mark;
3824
+ out.push("/");
3825
+ i = start + 1;
3826
+ } else sure = false;
3827
+ break;
3828
+ }
3829
+ if (c === "\\") {
3830
+ out.push(" ", blank(code[i + 1] ?? ""));
3831
+ i += 2;
3832
+ continue;
3833
+ }
3834
+ i++;
3835
+ if (c === "[") inClass = true;
3836
+ else if (c === "]") inClass = false;
3837
+ else if (c === "/" && !inClass) {
3838
+ if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
3839
+ out.length = mark;
3840
+ out.push("/");
3841
+ i = start + 1;
3842
+ break;
3843
+ }
3844
+ out.push("/");
3845
+ break;
3846
+ }
3847
+ out.push(" ");
3848
+ }
3849
+ if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
3850
+ } else if ((ch === '"' || ch === "'") && exprStart()) {
3753
3851
  const keep = isSpecifier();
3754
3852
  out.push(ch);
3755
3853
  i++;
@@ -3762,11 +3860,12 @@ function stripForImports(code) {
3762
3860
  i++;
3763
3861
  }
3764
3862
  }
3765
- if (i < n) {
3863
+ if (code[i] !== ch) sure = false;
3864
+ else {
3766
3865
  out.push(code[i]);
3767
3866
  i++;
3768
3867
  }
3769
- } else if (ch === "`") {
3868
+ } else if (ch === "`" && (exprStart() || taggedTemplate())) {
3770
3869
  out.push("`");
3771
3870
  i++;
3772
3871
  templateBody();
@@ -3783,7 +3882,7 @@ function stripForImports(code) {
3783
3882
  i++;
3784
3883
  }
3785
3884
  }
3786
- return out.join("");
3885
+ return sure && templates.length === 0 ? out.join("") : null;
3787
3886
  }
3788
3887
  function bindings(clause) {
3789
3888
  const out = [];
@@ -3896,6 +3995,11 @@ function createTrail(ctx) {
3896
3995
  const files = [];
3897
3996
  let lost = false;
3898
3997
  const code = stripped(file);
3998
+ if (code === null) {
3999
+ const out2 = { files: [], lost: true };
4000
+ importsCache.set(file.absolutePath, out2);
4001
+ return out2;
4002
+ }
3899
4003
  const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
3900
4004
  for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
3901
4005
  for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
@@ -3932,20 +4036,23 @@ function createTrail(ctx) {
3932
4036
  };
3933
4037
  const strippedCache = /* @__PURE__ */ new Map();
3934
4038
  const stripped = (file) => {
3935
- let c = strippedCache.get(file.absolutePath);
3936
- if (c === void 0) strippedCache.set(file.absolutePath, c = stripForImports(file.code));
3937
- return c;
4039
+ if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
4040
+ return strippedCache.get(file.absolutePath);
3938
4041
  };
3939
4042
  const memo = /* @__PURE__ */ new WeakMap();
3940
4043
  const reach = (file, test2, depth, seen) => {
3941
4044
  let cache = memo.get(test2);
3942
- if (!cache) memo.set(test2, cache = /* @__PURE__ */ new Map());
4045
+ if (!cache) memo.set(test2, cache = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
3943
4046
  const k = `${file.absolutePath}\0${depth}`;
3944
- const cached = cache.get(k);
3945
- if (cached) return [cached, false];
4047
+ const free = cache.free.get(k);
4048
+ if (free) return [free, /* @__PURE__ */ new Set()];
4049
+ const reusable = cache.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
4050
+ if (reusable) return [reusable.result, new Set(reusable.cut)];
3946
4051
  let result;
3947
- let cut = false;
3948
- if (test2(stripped(file))) result = "yes";
4052
+ const cut = /* @__PURE__ */ new Set();
4053
+ const code = stripped(file);
4054
+ if (code === null) result = "unknown";
4055
+ else if (test2(code)) result = "yes";
3949
4056
  else {
3950
4057
  const { files, lost } = importsOf(file);
3951
4058
  let unknown = lost && depth > 0;
@@ -3954,7 +4061,7 @@ function createTrail(ctx) {
3954
4061
  seen.add(file.absolutePath);
3955
4062
  for (const abs of files) {
3956
4063
  if (seen.has(abs)) {
3957
- cut = true;
4064
+ cut.add(abs);
3958
4065
  continue;
3959
4066
  }
3960
4067
  const target = read(abs);
@@ -3963,7 +4070,7 @@ function createTrail(ctx) {
3963
4070
  continue;
3964
4071
  }
3965
4072
  const [r, c] = reach(target, test2, depth - 1, seen);
3966
- if (c) cut = true;
4073
+ for (const m of c) cut.add(m);
3967
4074
  if (r === "yes") {
3968
4075
  result = "yes";
3969
4076
  break;
@@ -3971,11 +4078,18 @@ function createTrail(ctx) {
3971
4078
  if (r === "unknown") unknown = true;
3972
4079
  }
3973
4080
  seen.delete(file.absolutePath);
4081
+ cut.delete(file.absolutePath);
3974
4082
  }
3975
4083
  if (result === "no" && unknown) result = "unknown";
3976
4084
  }
3977
- if (result === "yes" || !cut) cache.set(k, result);
3978
- return [result, cut && result !== "yes"];
4085
+ if (result === "yes" || cut.size === 0) {
4086
+ cache.free.set(k, result);
4087
+ return [result, /* @__PURE__ */ new Set()];
4088
+ }
4089
+ const entries = cache.cut.get(k) ?? [];
4090
+ entries.push({ cut: [...cut], result });
4091
+ cache.cut.set(k, entries);
4092
+ return [result, cut];
3979
4093
  };
3980
4094
  return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
3981
4095
  }