-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This PR implements `edge-light` as a main field for bundling edge functions as defined in https://runtime-keys.proposal.wintercg.org Resolves EC-614 ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ---------
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import edgeLightPackage from 'my-edge-light-package' | ||
import edgeLightPackageExports from 'my-edge-light-package-exports' | ||
|
||
export const runtime = 'edge' | ||
|
||
export default function AppDirPage() { | ||
return ( | ||
<pre id="result"> | ||
{JSON.stringify({ edgeLightPackage, edgeLightPackageExports }, null, 2)} | ||
</pre> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html> | ||
<head /> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'edge-runtime uses edge-light import specifier for packages', | ||
{ | ||
files: __dirname, | ||
packageJson: { | ||
scripts: { | ||
setup: 'cp -r ./node_modules_bak/* ./node_modules', | ||
build: 'yarn setup && next build', | ||
dev: 'yarn setup && next dev', | ||
start: 'next start', | ||
}, | ||
}, | ||
installCommand: 'yarn', | ||
startCommand: (global as any).isNextDev ? 'yarn dev' : 'yarn start', | ||
buildCommand: 'yarn build', | ||
skipDeployment: true, | ||
}, | ||
({ next }) => { | ||
// In case you need to test the response object | ||
it('pages/api endpoints import the correct module', async () => { | ||
const res = await next.fetch('/api/edge') | ||
const html = await res.json() | ||
expect(html).toEqual({ | ||
edgeLightPackage: 'edge-light', | ||
edgeLightPackageExports: 'edge-light', | ||
}) | ||
}) | ||
|
||
it('pages import the correct module', async () => { | ||
const $ = await next.render$('/') | ||
const text = JSON.parse($('pre#result').text()) | ||
expect(text).toEqual({ | ||
edgeLightPackage: 'edge-light', | ||
edgeLightPackageExports: 'edge-light', | ||
}) | ||
}) | ||
|
||
it('app-dir imports the correct module', async () => { | ||
const $ = await next.render$('/app-dir') | ||
const text = JSON.parse($('pre#result').text()) | ||
expect(text).toEqual({ | ||
edgeLightPackage: 'edge-light', | ||
edgeLightPackageExports: 'edge-light', | ||
}) | ||
}) | ||
} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'edge-light' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'import' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "my-edge-light-package-exports", | ||
"main": "./require.js", | ||
"exports": { | ||
"edge-light": "./edge-light.js", | ||
"require": "./require.js", | ||
"import": "./import.js" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'require' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'edge-light' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'import' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "my-edge-light-package", | ||
"main": "./require.js", | ||
"module": "./import.js", | ||
"edge-light": "./edge-light.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'require' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import edgeLightPackage from 'my-edge-light-package' | ||
import edgeLightPackageExports from 'my-edge-light-package-exports' | ||
import { NextResponse } from 'next/server' | ||
|
||
export const config = { runtime: 'edge' } | ||
|
||
export default function MyEdgeFunction() { | ||
return NextResponse.json({ | ||
edgeLightPackage, | ||
edgeLightPackageExports, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import edgeLightPackage from 'my-edge-light-package' | ||
import edgeLightPackageExports from 'my-edge-light-package-exports' | ||
|
||
export const config = { runtime: 'experimental-edge' } | ||
|
||
export default function Index() { | ||
return ( | ||
<pre id="result"> | ||
{JSON.stringify({ edgeLightPackage, edgeLightPackageExports }, null, 2)} | ||
</pre> | ||
) | ||
} |