@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.
Files changed (38) hide show
  1. package/README.md +147 -2
  2. package/dist/cli.js +1363 -456
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{config-1jP8eCZy.d.ts → config-Dj_f9T7J.d.ts} +14 -1
  5. package/dist/doctor.d.ts +3 -3
  6. package/dist/doctor.js +402 -40
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/eslint.cjs +99 -0
  9. package/dist/eslint.cjs.map +1 -0
  10. package/dist/eslint.d.cts +68 -0
  11. package/dist/eslint.d.ts +68 -0
  12. package/dist/eslint.js +72 -0
  13. package/dist/eslint.js.map +1 -0
  14. package/dist/expo.d.ts +2 -2
  15. package/dist/expo.js +18 -0
  16. package/dist/expo.js.map +1 -1
  17. package/dist/genesis-catalog.json +30 -14
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +410 -48
  20. package/dist/index.js.map +1 -1
  21. package/dist/starter/README.md +18 -0
  22. package/dist/starter/__tests__/components/gestures.test.tsx +64 -0
  23. package/dist/starter/__tests__/components/resolver.js +14 -2
  24. package/dist/starter/__tests__/components/setup.ts +5 -0
  25. package/dist/starter/__tests__/starter.test.ts +27 -7
  26. package/dist/starter/eslint.config.js +8 -1
  27. package/dist/starter/jest.config.js +3 -0
  28. package/dist/starter/nativewind-env.d.ts +1 -0
  29. package/dist/starter/package.json +3 -0
  30. package/dist/starter/src/lib/link-hosts.ts +7 -3
  31. package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +7 -2
  32. package/dist/starter/supabase/migrations/20261024000700_genesis_support_findings.sql +339 -0
  33. package/dist/starter/supabase/tests/database/genesis_support.test.sql +1 -1
  34. package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +219 -0
  35. package/dist/templates/ci/genesis-upgrade.yml +1 -0
  36. package/dist/vite.js +402 -40
  37. package/dist/vite.js.map +1 -1
  38. package/package.json +18 -4
@@ -208,6 +208,24 @@ sign-in, the tabs, Settings and account deletion. Supabase is the fake in
208
208
  native modules use jest-expo's mocks or their library's own. A test fails when the app reports an
209
209
  error (`[push]`, `[updates]`, `[observability]`) or React warns about act(); see `reports.ts`.
210
210
  Add a screen's test there; tests that only read files stay in vitest, outside that folder.
211
+ In React Native Testing Library 14, `render`, `renderHook`, `fireEvent`, `act`, `rerender` and
212
+ `unmount` return promises: always `await` them, or the test reads a stale screen and React logs
213
+ "overlapping act() calls". `pnpm lint` catches a missed one in test files: `eslint.config.js`
214
+ spreads `genesis("native")` from `@marktiderman/genesis-cli/eslint`, which brings testing-library's
215
+ `await-async-events` and a `no-restricted-syntax` rule for the render calls, `act`, `rerender` and
216
+ `unmount` (it needs `eslint-plugin-testing-library` in devDependencies). The rules ship with the
217
+ CLI, so `genesis upgrade` brings new and changed ones without an edit here; a render helper of your
218
+ own goes in `genesis("native", { renders: ["renderWithStore"] })`. See the
219
+ [genesis-cli README](../../packages/genesis-cli/README.md#lint-rules).
220
+
221
+ Gestures and animations run in these tests as they are written, on Gesture Handler's mocks
222
+ (`react-native-gesture-handler/jestSetup.js`, in `jest.config.js`) and Reanimated's test mode
223
+ (`setUpTests()` in `setup.ts`, its resolver in `resolver.js`): worklets run on the JS thread with
224
+ Reanimated's web build, so what only the native UI runtime does (frame timing, native-driven
225
+ gestures, cross-thread races) still needs a device or Maestro run. Fire a gesture by its
226
+ `testID` with `fireGestureHandler` and `getByGestureTestId` from
227
+ `react-native-gesture-handler/jest-utils`, and read an animated style with `getAnimatedStyle`;
228
+ `gestures.test.tsx` drags a Pan gesture and checks the shared value it moves.
211
229
 
212
230
  ## Releasing
213
231
 
@@ -0,0 +1,64 @@
1
+ // @feat:native-starter
2
+ /**
3
+ * Gestures in Jest: Gesture Handler's mocks (`jestSetup.js`, from jest.config.js) and Reanimated's
4
+ * test mode (`setUpTests()` in setup.ts, its resolver in resolver.js). A Pan gesture fires from
5
+ * the test with `fireGestureHandler`, its worklets write a shared value, and the animated style
6
+ * follows: no device, no UI thread, and no rewriting the component onto the JS thread to test it.
7
+ */
8
+ import { describe, expect, it } from "@jest/globals";
9
+ import { act, render, screen } from "@testing-library/react-native";
10
+ import { useState } from "react";
11
+ import { Text } from "react-native";
12
+ import { GestureDetector, GestureHandlerRootView, State, usePanGesture } from "react-native-gesture-handler";
13
+ import { fireGestureHandler, getByGestureTestId } from "react-native-gesture-handler/jest-utils";
14
+ import Animated, { getAnimatedStyle, useAnimatedStyle, useSharedValue } from "react-native-reanimated";
15
+ import { scheduleOnRN } from "react-native-worklets";
16
+
17
+ // Reanimated types its Jest helpers in index.native.d.ts; TypeScript reads the web stub, which takes nothing.
18
+ const animatedStyle = getAnimatedStyle as unknown as (element: unknown) => unknown;
19
+
20
+ /** A card dragged sideways: the offset lives in a shared value, the drop is reported to React. */
21
+ function DraggableCard() {
22
+ const offset = useSharedValue(0);
23
+ const [dropped, setDropped] = useState<number | null>(null);
24
+ const pan = usePanGesture({
25
+ testID: "card-pan",
26
+ onUpdate: (event) => {
27
+ "worklet";
28
+ offset.value = event.translationX;
29
+ },
30
+ onDeactivate: () => {
31
+ "worklet";
32
+ scheduleOnRN(setDropped, offset.value);
33
+ },
34
+ });
35
+ const style = useAnimatedStyle(() => ({ transform: [{ translateX: offset.value }] }));
36
+ return (
37
+ <GestureHandlerRootView>
38
+ <GestureDetector gesture={pan}>
39
+ <Animated.View testID="card" style={style}>
40
+ <Text>{dropped === null ? "Drag me" : `Dropped at ${dropped}`}</Text>
41
+ </Animated.View>
42
+ </GestureDetector>
43
+ </GestureHandlerRootView>
44
+ );
45
+ }
46
+
47
+ describe("gestures in Jest", () => {
48
+ it("drives a Pan gesture's shared value and animated style from the test", async () => {
49
+ await render(<DraggableCard />);
50
+ expect(animatedStyle(screen.getByTestId("card"))).toEqual({ transform: [{ translateX: 0 }] });
51
+
52
+ await act(async () => {
53
+ fireGestureHandler(getByGestureTestId("card-pan"), [
54
+ { state: State.BEGAN, translationX: 0 },
55
+ { state: State.ACTIVE, translationX: 40 },
56
+ { translationX: 120 },
57
+ { state: State.END, translationX: 120 },
58
+ ]);
59
+ });
60
+
61
+ expect(animatedStyle(screen.getByTestId("card"))).toEqual({ transform: [{ translateX: 120 }] });
62
+ expect(await screen.findByText("Dropped at 120")).toBeOnTheScreen();
63
+ });
64
+ });
@@ -3,10 +3,22 @@
3
3
  * one. jest-expo resolves with the `require` and `react-native` conditions only, so it would
4
4
  * find nothing; for `@marktiderman/*` (and only those) this adds `import`. Babel turns the
5
5
  * module into CommonJS on the way in (`alsoTransform` in jest.config.js).
6
+ *
7
+ * Everything then goes through Reanimated's resolver (its Jest guide), which picks the web
8
+ * builds of Reanimated and Worklets: shared values, animated styles and gesture callbacks run
9
+ * in Jest without a UI thread.
6
10
  */
11
+ const reanimatedResolver = require("react-native-reanimated/jest/resolver");
12
+
7
13
  module.exports = (request, options) => {
14
+ // Gesture Handler's native build hands Worklets' UI runtime to its native module once loaded.
15
+ // Jest runs the web Worklets, which has no UI runtime and throws, so that one step takes Gesture
16
+ // Handler's web build (a no-op), as it does on the web. Its gestures still run on its Jest mocks.
17
+ if (request.endsWith("/installUIRuntimeBindings") && options.basedir.includes("react-native-gesture-handler")) {
18
+ return reanimatedResolver(`${request}.web`, options);
19
+ }
8
20
  if (request.startsWith("@marktiderman/")) {
9
- return options.defaultResolver(request, { ...options, conditions: [...(options.conditions ?? []), "import"] });
21
+ return reanimatedResolver(request, { ...options, conditions: [...(options.conditions ?? []), "import"] });
10
22
  }
11
- return options.defaultResolver(request, options);
23
+ return reanimatedResolver(request, options);
12
24
  };
@@ -8,6 +8,11 @@ import { expectedReports } from "./reports";
8
8
  process.env.EXPO_PUBLIC_SUPABASE_URL = "https://test.supabase.invalid";
9
9
  process.env.EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY = "test-publishable-key";
10
10
 
11
+ // Reanimated's test mode (its Jest guide, with the resolver in resolver.js): animations run on
12
+ // Jest's timers, and `toHaveAnimatedStyle` checks an animated style. Gesture Handler's mocks load
13
+ // from jest.config.js (`setupFiles`); `__tests__/components/gestures.test.tsx` shows both.
14
+ require("react-native-reanimated").setUpTests();
15
+
11
16
  // Native modules jest-expo has no mock for: each library's own Jest mock.
12
17
  jest.mock("@react-native-async-storage/async-storage", () => require("@react-native-async-storage/async-storage/jest/async-storage-mock"));
13
18
  jest.mock("@react-native-community/netinfo", () => require("@react-native-community/netinfo/jest/netinfo-mock.js"));
@@ -1,5 +1,5 @@
1
1
  // @feat:native-starter @feat:app-updates @feat:push @feat:observability @feat:devtools-overlay @feat:support-feedback @feat:chat @feat:product-roadmap
2
- import { readFileSync, readdirSync, statSync } from "node:fs";
2
+ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
3
3
  import { createRequire } from "node:module";
4
4
  import { dirname, join } from "node:path";
5
5
  import { describe, expect, it } from "vitest";
@@ -21,6 +21,9 @@ const chatSql = (path: string) => readFileSync(join(chatPackage, "migrations", p
21
21
  // `genesis init --without <switch>` has none of that block's migrations, tests or functions, so
22
22
  // the checks of those files run only while it's on.
23
23
  const { updates, push, notifications, support, chat } = starter.features;
24
+ // An app made with `genesis init --beside <web-app>` has no supabase/ folder: its database files
25
+ // are the web app's, so the checks of them run only where the folder is.
26
+ const database = existsSync(join(root, "supabase"));
24
27
 
25
28
  function filesUnder(dir: string): string[] {
26
29
  return readdirSync(join(root, dir)).flatMap((name) => {
@@ -37,7 +40,7 @@ describe("root layout", () => {
37
40
  });
38
41
  });
39
42
 
40
- describe("migrations", () => {
43
+ describe.runIf(database)("migrations", () => {
41
44
  it("each has its own version, so a new app's database applies every one", () => {
42
45
  const versions = filesUnder("supabase/migrations").map((f) => f.split("/").pop()!.split("_")[0]!);
43
46
  expect(new Set(versions).size).toBe(versions.length);
@@ -99,6 +102,12 @@ describe("deep links", () => {
99
102
  expect(linkHosts({ links: null })).toEqual([]);
100
103
  expect(linkHosts({ links: {} })).toEqual([]);
101
104
  });
105
+
106
+ it("accepts a genesis.config.json with other keys and no links block (it typechecks)", () => {
107
+ // What a JSON import infers once `links` is removed: no key in common with `links`.
108
+ const noLinks = { doctor: { packs: ["native"] }, starter: { blocks: { push: ["push"] } } };
109
+ expect(linkHosts(noLinks)).toEqual([]);
110
+ });
102
111
  });
103
112
 
104
113
  describe("EAS config", () => {
@@ -223,7 +232,7 @@ describe("copy catalog", () => {
223
232
  });
224
233
  });
225
234
 
226
- describe("supabase/migrations", () => {
235
+ describe.runIf(database)("supabase/migrations", () => {
227
236
  it("carries @marktiderman/genesis-supabase's account-deletion migration unchanged", () => {
228
237
  const shipped = shippedSql("0001_genesis_account_deletion.sql");
229
238
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_account_deletion.sql"));
@@ -290,9 +299,20 @@ describe("supabase/migrations", () => {
290
299
  const order = filesUnder("supabase/migrations").sort();
291
300
  expect(order.indexOf(copies[0]!)).toBeGreaterThan(order.findIndex((f) => f.endsWith("_genesis_push.sql")));
292
301
  });
302
+
303
+ it.runIf(support)("carries genesis-support's findings migration and its pgTAP test unchanged, after the support one", () => {
304
+ const supportPackage = dirname(createRequire(join(root, "package.json")).resolve("@marktiderman/genesis-support/package.json"));
305
+ const shipped = (rel: string) => readFileSync(join(supportPackage, "migrations", rel), "utf8");
306
+ const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_support_findings.sql"));
307
+ expect(copies).toHaveLength(1);
308
+ expect(read(copies[0]!)).toBe(shipped("0003_genesis_support_findings.sql"));
309
+ expect(read("supabase/tests/database/genesis_support_findings.test.sql")).toBe(shipped("tests/0003_genesis_support_findings.test.sql"));
310
+ const order = filesUnder("supabase/migrations").sort();
311
+ expect(order.indexOf(copies[0]!)).toBeGreaterThan(order.findIndex((f) => f.endsWith("_genesis_support.sql")));
312
+ });
293
313
  });
294
314
 
295
- describe("supabase/functions", () => {
315
+ describe.runIf(database)("supabase/functions", () => {
296
316
  it("carries @marktiderman/genesis-supabase's genesis-apple-revoke function unchanged", () => {
297
317
  const shipped = join(supabasePackage, "functions", "genesis-apple-revoke");
298
318
  const names = readdirSync(shipped).sort();
@@ -357,7 +377,7 @@ describe("support", () => {
357
377
  });
358
378
 
359
379
  describe("chat", () => {
360
- it.runIf(chat)("carries chat's migration and pgTAP test unchanged after the support one, and serves genesis_chat through the API", () => {
380
+ it.runIf(chat && database)("carries chat's migration and pgTAP test unchanged after the support one, and serves genesis_chat through the API", () => {
361
381
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_chat.sql"));
362
382
  expect(copies).toHaveLength(1);
363
383
  expect(read(copies[0]!)).toBe(chatSql("0001_genesis_chat.sql"));
@@ -378,7 +398,7 @@ describe("chat", () => {
378
398
  expect(JSON.parse(read("genesis.config.json")).doctor.supabase.exposedSchemas).toContain("genesis_chat");
379
399
  });
380
400
 
381
- it.runIf(chat)("carries chat's 0002 migration (topics, scheduled send, availability, broadcast, search) and its pgTAP test unchanged, after 0001", () => {
401
+ it.runIf(chat && database)("carries chat's 0002 migration (topics, scheduled send, availability, broadcast, search) and its pgTAP test unchanged, after 0001", () => {
382
402
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_chat_coaching.sql"));
383
403
  expect(copies).toHaveLength(1);
384
404
  expect(read(copies[0]!)).toBe(chatSql("0002_genesis_chat_coaching.sql"));
@@ -423,7 +443,7 @@ describe("chat", () => {
423
443
  expect(read("src/lib/chat.tsx")).toContain("starter.features.chat && starter.features.push");
424
444
  });
425
445
 
426
- it.runIf(chat)("names people from their auth metadata through chat_people, after the chat migration, with its pgTAP test", () => {
446
+ it.runIf(chat && database)("names people from their auth metadata through chat_people, after the chat migration, with its pgTAP test", () => {
427
447
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_chat_people.sql"));
428
448
  expect(copies).toHaveLength(1);
429
449
  const order = filesUnder("supabase/migrations").sort();
@@ -1,5 +1,12 @@
1
1
  // https://docs.expo.dev/guides/using-eslint/
2
2
  const { defineConfig } = require("eslint/config");
3
3
  const expoConfig = require("eslint-config-expo/flat");
4
+ // Genesis's lint rules, shipped with the CLI so `genesis upgrade` brings new ones (React Native
5
+ // Testing Library 14's await rules today; they need eslint-plugin-testing-library).
6
+ const { genesis } = require("@marktiderman/genesis-cli/eslint");
4
7
 
5
- module.exports = defineConfig([expoConfig, { ignores: ["dist/*", ".expo/*", "supabase/functions/**"] }]);
8
+ module.exports = defineConfig([
9
+ expoConfig,
10
+ { ignores: ["dist/*", ".expo/*", "supabase/functions/**"] },
11
+ ...genesis("native"),
12
+ ]);
@@ -22,6 +22,9 @@ module.exports = {
22
22
  preset: "jest-expo",
23
23
  // Every test file here is jest's, `.ts` or `.tsx`; vitest.config.mts leaves this folder out.
24
24
  testMatch: ["<rootDir>/__tests__/components/**/*.test.{ts,tsx}"],
25
+ // Gesture Handler's own mocks (its Jest guide), after jest-expo's: gestures fire from tests
26
+ // with `fireGestureHandler` (react-native-gesture-handler/jest-utils), no native module.
27
+ setupFiles: [...expoPreset.setupFiles, "react-native-gesture-handler/jestSetup.js"],
25
28
  setupFilesAfterEnv: ["<rootDir>/__tests__/components/setup.ts"],
26
29
  resolver: "<rootDir>/__tests__/components/resolver.js",
27
30
  moduleNameMapper: {
@@ -0,0 +1 @@
1
+ /// <reference types="nativewind/types" />
@@ -72,6 +72,7 @@
72
72
  "react-hook-form": "^7.56.4",
73
73
  "react-native": "0.88.0",
74
74
  "react-native-css-interop": "^0.2.7",
75
+ "react-native-gesture-handler": "~3.3.0",
75
76
  "react-native-keyboard-controller": "1.22.7",
76
77
  "react-native-reanimated": "4.7.1",
77
78
  "react-native-safe-area-context": "~5.10.1",
@@ -84,6 +85,7 @@
84
85
  "zod": "^4.6.6"
85
86
  },
86
87
  "devDependencies": {
88
+ "@jest/globals": "~30.5.2",
87
89
  "@marktiderman/genesis-cli": "workspace:^",
88
90
  "@react-native/jest-preset": "0.88.0",
89
91
  "@testing-library/react-native": "^14.1.0",
@@ -92,6 +94,7 @@
92
94
  "babel-plugin-react-compiler": "^1.0.0",
93
95
  "eslint": "^9.0.0",
94
96
  "eslint-config-expo": "~58.0.4",
97
+ "eslint-plugin-testing-library": "^7.16.2",
95
98
  "jest": "~30.5.2",
96
99
  "jest-expo": "~58.0.12",
97
100
  "tailwindcss": "^3.4.17",
@@ -1,8 +1,12 @@
1
1
  /**
2
2
  * The web hosts whose links open in the app: genesis.config.json's `links.hosts`. An app with no
3
- * domain yet has no `links` block (or no hosts in it), so it has no app links and only its
4
- * schemes open it. Kept free of React Native imports so the tests can read it.
3
+ * domain yet has no `links` block: remove the whole block, since the Expo config plugin rejects
4
+ * one with an empty `hosts` list. It then has no app links and only its schemes open it. Kept
5
+ * free of React Native imports so the tests can read it.
5
6
  */
6
- export function linkHosts(config: { links?: { hosts?: readonly string[] } | null }): string[] {
7
+ export type LinkHostsConfig = { readonly links?: { readonly hosts?: readonly string[] } | null; readonly [key: string]: unknown };
8
+
9
+ /** Takes the whole genesis.config.json, so a config with other keys and no `links` still typechecks. */
10
+ export function linkHosts(config: LinkHostsConfig): string[] {
7
11
  return [...(config.links?.hosts ?? [])];
8
12
  }
@@ -39,6 +39,11 @@ export interface AppleConfig {
39
39
 
40
40
  const TEN_CHARS = /^[A-Z0-9]{10}$/;
41
41
  const CLIENT_ID = /^[A-Za-z0-9][A-Za-z0-9.-]{0,254}$/;
42
+ // The PKCS#8 PEM armour, with the dashes counted (`-{5}`) rather than written out: the literal
43
+ // header is what secret scanners (gitleaks' private-key rule) look for, and every app that installs
44
+ // this function scans it.
45
+ const PEM_KEY = /-{5}BEGIN PRIVATE KEY-{5}[\s\S]+-{5}END PRIVATE KEY-{5}/;
46
+ const PEM_MARKER = /-{5}(?:BEGIN|END) PRIVATE KEY-{5}/g;
42
47
 
43
48
  /**
44
49
  * Reads the Apple settings from the environment. Returns the names that are
@@ -55,7 +60,7 @@ export function readAppleConfig(env: (name: string) => string | undefined): { co
55
60
  .filter(Boolean);
56
61
  if (!TEN_CHARS.test(teamId)) problems.push("APPLE_TEAM_ID (10 capital letters or digits)");
57
62
  if (!TEN_CHARS.test(keyId)) problems.push("APPLE_KEY_ID (10 capital letters or digits)");
58
- if (!/-----BEGIN PRIVATE KEY-----[\s\S]+-----END PRIVATE KEY-----/.test(privateKey)) problems.push("APPLE_PRIVATE_KEY (the .p8 file's PEM text)");
63
+ if (!PEM_KEY.test(privateKey)) problems.push("APPLE_PRIVATE_KEY (the .p8 file's PEM text)");
59
64
  if (clientIds.length === 0 || !clientIds.every((id) => CLIENT_ID.test(id))) problems.push("APPLE_CLIENT_IDS (comma-separated bundle ids or Services IDs)");
60
65
  return problems.length ? { problems } : { config: { teamId, keyId, privateKey, clientIds } };
61
66
  }
@@ -85,7 +90,7 @@ const keyCache = new Map<string, Promise<CryptoKey>>();
85
90
  function signingKey(pem: string): Promise<CryptoKey> {
86
91
  let key = keyCache.get(pem);
87
92
  if (!key) {
88
- const body = pem.replace(/-----(BEGIN|END) PRIVATE KEY-----/g, "").replace(/\s+/g, "");
93
+ const body = pem.replace(PEM_MARKER, "").replace(/\s+/g, "");
89
94
  const der = Uint8Array.from(atob(body), (c) => c.charCodeAt(0));
90
95
  key = crypto.subtle.importKey("pkcs8", der, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
91
96
  // A bad key must not stay cached as a rejected promise.