Skip to content

Commit

Permalink
Upgrade edge-runtime + make EdgeRuntime value overridable with an env…
Browse files Browse the repository at this point in the history
… var on compilation (#38331)

This PR introduces an environment variable that allows to modify the `EdgeRuntime` value on compilation time.
This is done to allow cloud providers like Vercel to have a different value, and enable user code and 3rd party libraries to have different code paths depending on the Edge Functions provider.

## Related

- Related to #30739

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
  • Loading branch information
Schniz committed Jul 12, 2022
1 parent 3ae15e1 commit 62eb16b
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 319 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -55,7 +55,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.1.0-beta.10",
"@edge-runtime/jest-environment": "1.1.0-beta.11",
"@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0",
"@next/bundle-analyzer": "workspace:*",
Expand Down
9 changes: 8 additions & 1 deletion packages/next/build/webpack-config.ts
Expand Up @@ -1497,7 +1497,14 @@ export default async function getBaseWebpackConfig(
...(compilerType !== 'edge-server'
? {}
: {
EdgeRuntime: JSON.stringify('edge-runtime'),
EdgeRuntime: JSON.stringify(
/**
* Cloud providers can set this environment variable to allow users
* and library authors to have different implementations based on
* the runtime they are running with, if it's not using `edge-runtime`
*/
process.env.NEXT_EDGE_RUNTIME_PROVIDER || 'edge-runtime'
),
}),
// TODO: enforce `NODE_ENV` on `process.env`, and add a test:
'process.env.NODE_ENV': JSON.stringify(
Expand Down

0 comments on commit 62eb16b

Please sign in to comment.