Skip to content

Commit

Permalink
[node][edge][cli] upgrade Edge Runtime (#10051)
Browse files Browse the repository at this point in the history
We avoided to use `undici.WebSocket` because @jawj found a bug in the
implementation.

The [fix was merged](nodejs/undici#2106) in
[undici@5.22.1](https://github.com/nodejs/undici/releases/tag/v5.22.1),
so we can be back to use it.

The latest version of Edge Runtime exposes `undici.WebSocket` compatible
with node.js 14, 16 & 18

---------

Co-authored-by: Sean Massa <endangeredmassa@gmail.com>
  • Loading branch information
Kikobeats and EndangeredMassa committed Jun 20, 2023
1 parent cfea31e commit 8b3a414
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 283 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-trainers-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vercel/node": patch
---

[node] use `undici.Websocket` when is possible
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"devDependencies": {
"@alex_neo/jest-expect-message": "1.0.5",
"@edge-runtime/node-utils": "2.0.3",
"@edge-runtime/node-utils": "2.1.0",
"@next/env": "11.1.2",
"@sentry/node": "5.5.0",
"@sindresorhus/slugify": "0.11.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build:docs": "typedoc && node scripts/fix-links.js && prettier --write docs/**/*.md docs/*.md"
},
"devDependencies": {
"@edge-runtime/jest-environment": "2.0.0",
"@edge-runtime/jest-environment": "2.2.3",
"@types/jest": "27.4.1",
"ts-node": "8.9.1",
"tsup": "6.1.2",
Expand Down
7 changes: 3 additions & 4 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
"dependencies": {
"@edge-runtime/node-utils": "2.0.3",
"@edge-runtime/primitives": "2.1.2",
"@edge-runtime/vm": "2.0.0",
"@edge-runtime/vm": "3.0.1",
"@types/node": "14.18.33",
"@types/node-fetch": "2.6.3",
"@vercel/build-utils": "6.7.5",
"@vercel/error-utils": "1.0.10",
"@vercel/static-config": "2.0.17",
"async-listen": "3.0.0",
"edge-runtime": "2.1.4",
"edge-runtime": "2.4.3",
"esbuild": "0.14.47",
"exit-hook": "2.2.1",
"node-fetch": "2.6.9",
"path-to-regexp": "6.2.1",
"ts-morph": "12.0.0",
"ts-node": "10.9.1",
"typescript": "4.9.5",
"ws": "8.13.0"
"typescript": "4.9.5"
},
"devDependencies": {
"@babel/core": "7.5.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/node/src/edge-functions/edge-handler.mts
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,13 @@ async function createEdgeRuntimeServer(params?: {

const wasmBindings = await params.wasmAssets.getContext();
const nodeCompatBindings = params.nodeCompatBindings.getContext();
// @ts-ignore
const WebSocket = (await import('ws')).WebSocket;

const runtime = new EdgeRuntime({
initialCode: params.userCode,
extend: context => {
Object.assign(context, {
// This is required for esbuild wrapping logic to resolve
module: {},
WebSocket,

// This is required for environment variable access.
// In production, env var access is provided by static analysis
Expand Down

0 comments on commit 8b3a414

Please sign in to comment.