Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract primitives/load function #327

Merged
merged 4 commits into from
May 9, 2023

Conversation

Schniz
Copy link
Collaborator

@Schniz Schniz commented May 4, 2023

when trying to upgrade Next.js a test failed that showed that Uint8Array usage is problematic
with the crypto module. This is because the crypto polyfill is checking instanceof of the
input values, and sadly, the Uint8Arrays constructed frmo the EdgeVM context do not satisfy
that condition.

In order to change it, I decided to use the requireWithFakeGlobalScope yet again in the VM
module, but instead of re-implementing it, I extracted the load function, which is just
like the primitives entrypoint, only lazy--and receives the scopedContext, which will
act as a global context for the requires

The types that are being used in the scopedContext are the same ones we patch for the
instanceof checks ourselves, which makes sense!

This fixes the test so we should be safer now!

when trying to upgrade Next.js a test failed that showed that Uint8Array usage is problematic
with the crypto module. This is because the crypto polyfill is checking `instanceof` of the
input values, and sadly, the Uint8Arrays constructed frmo the EdgeVM context do not satisfy
that condition.

In order to change it, I decided to use the requireWithFakeGlobalScope yet again in the VM
module, but instead of re-implementing it, I extracted the `load` function, which is just
like the `primitives` entrypoint, only lazy--and receives the scopedContext, which will
act as a global context for the requires

The types that are being used in the scopedContext are the same ones we patch for the
`instanceof` checks ourselves, which makes sense!

This fixes the test so we should be safer now!
@Schniz Schniz self-assigned this May 4, 2023
@changeset-bot
Copy link

changeset-bot bot commented May 4, 2023

🦋 Changeset detected

Latest commit: b70b456

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
edge-runtime Patch
@edge-runtime/primitives Patch
@edge-runtime/vm Patch
@edge-runtime/types Patch
@edge-runtime/jest-environment Patch

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

@vercel
Copy link

vercel bot commented May 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
edge-runtime ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2023 11:15am

@Schniz Schniz merged commit 9f35416 into main May 9, 2023
@Schniz Schniz deleted the extract-load-function-to-shadow-over-globals branch May 9, 2023 12:56
@github-actions github-actions bot mentioned this pull request May 9, 2023
@github-actions github-actions bot mentioned this pull request May 29, 2023
jridgewell pushed a commit to jridgewell/edge-runtime that referenced this pull request Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant