Repository navigation
Fix viem imports under SES lockdown() - #5306
Conversation
…in build output
TypeScript emits `export namespace getAllowance { export function call() }`
as `getAllowance.call = call`. Under frozen intrinsics (SES `lockdown()`),
`Function.prototype.call` is read-only, so the assignment throws on import
of `viem`, `viem/actions`, `viem/chains`, and other entrypoints.
`scripts/hardenNamespaces.ts` runs after `build:esm` and `build:cjs`. It
rewrites each emitted namespace member assignment whose name shadows a
`Function.prototype` or `Object.prototype` property into
`Object.defineProperty`, with the same descriptor. The source, the public
API, and the `.d.ts` output do not change. `environments/ses` imports every
entrypoint (CJS and ESM) after `lockdown()`.
Addresses the import crash in #5248.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01USP6moK1yHGUDpsGiNTiKR
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: eb0d67c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb0d67cebb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
What is this PR solving?
This PR fixes importing viem and its entrypoints (
viem/actions,viem/chains, etc.) when running under SESlockdown(), which freezes intrinsic prototypes. Previously, this would throwCannot assign to read only property 'call'because the emitted code attempted to assign namespace members that shadow intrinsic prototype properties (e.g.,getAllowance.call = call).Solution
The fix involves two main changes:
New
hardenNamespaces.tsscript: A TypeScript utility that post-processes emitted JavaScript files to rewrite namespace member assignments that shadow intrinsic properties. Instead of direct assignment (which fails under frozen intrinsics), it usesObject.defineProperty()with identical property descriptors, which succeeds even with frozen prototypes.Build pipeline integration: The script is now run during both CJS and ESM builds to harden all emitted namespace members.
SES test environment: Added a new test environment (
environments/ses/) that validates viem works correctly under SESlockdown()by:token.getAllowance.call())The CI workflow has been updated to run this new SES test environment as part of the verification matrix.
Test Plan
The new SES test environment (
environments/ses/) is automatically run in CI and validates that viem can be imported and used under frozen intrinsics. Existing tests continue to pass.https://claude.ai/code/session_01USP6moK1yHGUDpsGiNTiKR