Commit 6b7c2d7
Use project's installed envio binary in e2e tests (#1157)
* Use project-installed envio in isolated dependency test
After #1116 moved the CLI into in-process bin.mjs, running envio via the
e2e-tests workspace's bin.mjs while the handler imports `generated` →
`envio` resolved to the project's freshly installed envio produced two
distinct envio module instances in one process. HandlerRegister state
lives per-instance, so `indexer.onEvent` wrote to the project's dict
while `applyRegistrations` read the e2e-tests dict, causing every event
to surface as "no event handler" and chain 1 to fail with "Nothing to
fetch".
Invoke envio through `<projectDir>/node_modules/envio/bin.mjs` so bin.mjs
and the handlers resolve to the same physical envio, matching the real
`npx envio dev` flow.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
* Remove temporary PR build workflow
The NAPI migration (#1116) is merged to main, so the stopgap
`build_and_verify_pr.yml` (which ran on `pull_request` so PR-modified
build steps were exercised) is no longer needed. `build_and_verify.yml`
already covers PRs via `pull_request_target`.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
* Share HandlerRegister state via globalThis
When the CLI's bin.mjs resolves envio from one path (e.g. a globally
installed or test-resolved copy) and the user's handlers resolve
`import "envio"` from a different path (e.g. their project's
node_modules), Node treats them as two separate ESM module instances.
HandlerRegister's module-local state then lives per-instance: the
handler's `indexer.onEvent` writes to one dict while
`HandlerLoader.applyRegistrations` reads the other, so every event ends
up "without an event handler" and chains with no other registrations
fail with "Nothing to fetch".
Stash `eventRegistrations`, `activeRegistration`, and `preRegistered` on
`globalThis` so all envio instances in a single process share one
registry. This is the same trick `react` and `@apollo/client` use to
guard against the "two copies of the package" footgun.
Revert the install.test.ts workaround that routed `envio dev` through
the project-local bin.mjs — with the globalThis fix, the original
`config.envioCommand` invocation works.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
* Version-gate HandlerRegister globalThis registry
Stashing the registry on unversioned globalThis keys would silently
blend state if two envio majors ended up in one process (monorepo with
divergent pins, a transitive dep shipping its own copy, an in-flight
upgrade). The record shapes evolve between majors, so silent sharing
would corrupt handlers/config reads later with opaque errors.
Collapse the three globalThis slots into a single \`__envioRegistry\`
object tagged with the envio package version. On load, if a registry
already exists we accept it only when versions match; otherwise we
throw with a deduplication hint pointing at the real problem
(\`node_modules/envio\` duplication) rather than a random decode failure.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
* Rewrite HandlerRegister globalThis init in ReScript
Drop the %raw IIFE that boxed the globalThis lookup + version check in a
JS string, and replace it with a typed ReScript match. `globalThis` is
now bound via `@val external` with an open `{..}` type so bracket access
(\`globalThis["__envioRegistry"]\`) stays syntactically light; the slot's
real shape is encoded as a typed record (\`registryShape\`). The version
check becomes a plain pattern match with a guard.
Behavior unchanged; generated JS is equivalent. Payoff is that the
string-embedded JS no longer shadows types, and future edits (e.g.
adding a field to the registry) are caught by the compiler.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
* Tighten globalThis external binding to a typed record
Replace \`{..}\` with a \`mutable __envioRegistry\` record so both the
lookup and the assignment are statically typed, and drop the local
\`Nullable.t<registryShape>\` annotation. Typo in the slot name now
surfaces at compile time instead of silently creating a new globalThis
property.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
* Align version-gate comment with the strict-equality check
Comment said shapes "evolve between envio majors" but the guard is
full-version equality, so a patch/pre-release mismatch also throws.
Keep the stricter check (safer default) and reword the comment so a
future reader doesn't assume major-only matching.
https://claude.ai/code/session_011rsp7McDiNshdkTLCnP6eT
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a7ca442 commit 6b7c2d7
2 files changed
Lines changed: 55 additions & 224 deletions
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
14 | 66 | | |
15 | 67 | | |
16 | 68 | | |
| |||
25 | 77 | | |
26 | 78 | | |
27 | 79 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 80 | + | |
38 | 81 | | |
39 | 82 | | |
40 | 83 | | |
| |||
43 | 86 | | |
44 | 87 | | |
45 | 88 | | |
46 | | - | |
| 89 | + | |
47 | 90 | | |
48 | 91 | | |
49 | 92 | | |
| |||
0 commit comments