Skip to content

Commit

Permalink
Use Edge Runtime for running Edge Functions locally (#37024)
Browse files Browse the repository at this point in the history
This PR introduces [Edge Runtime](https://edge-runtime.vercel.app/) for emulating [Edge Functions](https://vercel.com/features/edge-functions) locally.

Every time you run a [middleware](https://nextjs.org/docs/advanced-features/middleware) locally via `next dev`, an isolated edge runtime context will be created.

These contexts have the same constraints as production servers, plus they don't pollute the global scope; Instead, all the code run in a vm on top of a Node.js process.

Additionally, `@edge-runtime/jest-environment` has been added to make easier testing Edge Functions in a programmatic way.

It dropped the following polyfills from Next.js codebase, since they are now part of Edge Runtime:

- abort-controller
- formdata
- uuid
- web-crypto
- web-streams

Co-authored-by: Gal Schlezinger <2054772+Schniz@users.noreply.github.com>
  • Loading branch information
Kikobeats and Schniz committed May 30, 2022
1 parent ec572b0 commit fafbea8
Show file tree
Hide file tree
Showing 49 changed files with 22,505 additions and 2,071 deletions.
7 changes: 6 additions & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const escape = require('shell-quote').quote
const { quote } = require('shell-quote')
const { ESLint } = require('eslint')

const eslint = new ESLint()
Expand Down Expand Up @@ -26,3 +26,8 @@ module.exports = {
]
},
}

function escape(str) {
const escaped = quote(str)
return escaped.replace(/\\@/g, '@')
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@babel/plugin-proposal-object-rest-spread": "7.14.7",
"@babel/preset-flow": "7.14.5",
"@babel/preset-react": "7.14.5",
"@edge-runtime/jest-environment": "1.0.1-beta.10",
"@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0",
"@next/bundle-analyzer": "workspace:*",
Expand Down Expand Up @@ -191,7 +192,6 @@
"turbo": "1.2.9",
"typescript": "4.6.3",
"wait-port": "0.2.2",
"web-streams-polyfill": "2.1.1",
"webpack": "link:./node_modules/webpack5",
"webpack-bundle-analyzer": "4.3.0",
"worker-loader": "3.0.7"
Expand Down
Loading

0 comments on commit fafbea8

Please sign in to comment.