@netlify/plugin-nextjs 4.30.3 → 4.30.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/edge.js +3 -49
- package/package.json +3 -3
- package/src/templates/edge/shims.js +53 -0
package/lib/helpers/edge.js
CHANGED
|
@@ -14,7 +14,7 @@ const config_1 = require("./config");
|
|
|
14
14
|
const matchers_1 = require("./matchers");
|
|
15
15
|
const maybeLoadJson = (path) => {
|
|
16
16
|
if ((0, fs_1.existsSync)(path)) {
|
|
17
|
-
return (0, fs_extra_1.
|
|
17
|
+
return (0, fs_extra_1.readJSON)(path);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
const isAppDirRoute = (route, appPathRoutesManifest) => Boolean(appPathRoutesManifest) && Object.values(appPathRoutesManifest).includes(route);
|
|
@@ -29,53 +29,6 @@ exports.loadPrerenderManifest = loadPrerenderManifest;
|
|
|
29
29
|
* Convert the Next middleware name into a valid Edge Function name
|
|
30
30
|
*/
|
|
31
31
|
const sanitizeName = (name) => `next_${name.replace(/\W/g, '_')}`;
|
|
32
|
-
/**
|
|
33
|
-
* Initialization added to the top of the edge function bundle
|
|
34
|
-
*/
|
|
35
|
-
const preamble = /* js */ `
|
|
36
|
-
import {
|
|
37
|
-
decode as _base64Decode,
|
|
38
|
-
} from "https://deno.land/std@0.159.0/encoding/base64.ts";
|
|
39
|
-
// Deno defines "window", but naughty libraries think this means it's a browser
|
|
40
|
-
delete globalThis.window
|
|
41
|
-
globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT_PRIVATE_MINIMAL_MODE': '1' } }
|
|
42
|
-
globalThis.EdgeRuntime = "netlify-edge"
|
|
43
|
-
let _ENTRIES = {}
|
|
44
|
-
|
|
45
|
-
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
|
|
46
|
-
if(!('getAll' in Headers.prototype)) {
|
|
47
|
-
Headers.prototype.getAll = function getAll(name) {
|
|
48
|
-
name = name.toLowerCase();
|
|
49
|
-
if (name !== "set-cookie") {
|
|
50
|
-
throw new Error("Headers.getAll is only supported for Set-Cookie");
|
|
51
|
-
}
|
|
52
|
-
return [...this.entries()]
|
|
53
|
-
.filter(([key]) => key === name)
|
|
54
|
-
.map(([, value]) => value);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
// Next uses blob: urls to refer to local assets, so we need to intercept these
|
|
58
|
-
const _fetch = globalThis.fetch
|
|
59
|
-
const fetch = async (url, init) => {
|
|
60
|
-
try {
|
|
61
|
-
if (typeof url === 'object' && url.href?.startsWith('blob:')) {
|
|
62
|
-
const key = url.href.slice(5)
|
|
63
|
-
if (key in _ASSETS) {
|
|
64
|
-
return new Response(_base64Decode(_ASSETS[key]))
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return await _fetch(url, init)
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error(error)
|
|
70
|
-
throw error
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Next edge runtime uses "self" as a function-scoped global-like object, but some of the older polyfills expect it to equal globalThis
|
|
75
|
-
// See https://nextjs.org/docs/basic-features/supported-browsers-features#polyfills
|
|
76
|
-
const self = { ...globalThis, fetch }
|
|
77
|
-
|
|
78
|
-
`;
|
|
79
32
|
// Slightly different spacing in different versions!
|
|
80
33
|
const IMPORT_UNSUPPORTED = [
|
|
81
34
|
`Object.defineProperty(globalThis,"__import_unsupported"`,
|
|
@@ -86,7 +39,8 @@ const IMPORT_UNSUPPORTED = [
|
|
|
86
39
|
*/
|
|
87
40
|
const getMiddlewareBundle = async ({ edgeFunctionDefinition, netlifyConfig, }) => {
|
|
88
41
|
const { publish } = netlifyConfig.build;
|
|
89
|
-
const
|
|
42
|
+
const shims = await fs_1.promises.readFile(getEdgeTemplatePath('shims.js'), 'utf8');
|
|
43
|
+
const chunks = [shims];
|
|
90
44
|
chunks.push(`export const _DEFINITION = ${JSON.stringify(edgeFunctionDefinition)}`);
|
|
91
45
|
if ('wasm' in edgeFunctionDefinition) {
|
|
92
46
|
for (const { name, filePath } of edgeFunctionDefinition.wasm) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.30.
|
|
3
|
+
"version": "4.30.4",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@delucis/if-env": "^1.1.2",
|
|
39
|
-
"@netlify/build": "^29.5.
|
|
39
|
+
"@netlify/build": "^29.5.4",
|
|
40
40
|
"@types/fs-extra": "^9.0.13",
|
|
41
41
|
"@types/jest": "^27.4.1",
|
|
42
42
|
"@types/merge-stream": "^1.1.2",
|
|
43
43
|
"@types/node": "^17.0.25",
|
|
44
|
-
"next": "^13.
|
|
44
|
+
"next": "^13.1.6",
|
|
45
45
|
"npm-run-all": "^4.1.5",
|
|
46
46
|
"typescript": "^4.6.3"
|
|
47
47
|
},
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// deno-lint-ignore-file no-var prefer-const no-unused-vars no-explicit-any
|
|
3
|
+
import { decode as _base64Decode } from 'https://deno.land/std@0.175.0/encoding/base64.ts'
|
|
4
|
+
import { AsyncLocalStorage as ALSCompat } from 'https://deno.land/std@0.175.0/node/async_hooks.ts'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* These are the shims, polyfills and other kludges to make Next.js work in standards-compliant runtime.
|
|
8
|
+
* This file isn't imported, but is instead inlined along with other chunks into the edge bundle.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Deno defines "window", but naughty libraries think this means it's a browser
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
delete globalThis.window
|
|
14
|
+
globalThis.process = {
|
|
15
|
+
env: { ...Deno.env.toObject(), NEXT_RUNTIME: 'edge', NEXT_PRIVATE_MINIMAL_MODE: '1' },
|
|
16
|
+
}
|
|
17
|
+
globalThis.EdgeRuntime = 'netlify-edge'
|
|
18
|
+
let _ENTRIES = {}
|
|
19
|
+
|
|
20
|
+
// Next.js expects this as a global
|
|
21
|
+
globalThis.AsyncLocalStorage = ALSCompat
|
|
22
|
+
|
|
23
|
+
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
|
|
24
|
+
if (!('getAll' in Headers.prototype)) {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
Headers.prototype.getAll = function getAll(name) {
|
|
27
|
+
name = name.toLowerCase()
|
|
28
|
+
if (name !== 'set-cookie') {
|
|
29
|
+
throw new Error('Headers.getAll is only supported for Set-Cookie')
|
|
30
|
+
}
|
|
31
|
+
return [...this.entries()].filter(([key]) => key === name).map(([, value]) => value)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Next uses blob: urls to refer to local assets, so we need to intercept these
|
|
35
|
+
const _fetch = globalThis.fetch
|
|
36
|
+
const fetch /* type {typeof globalThis.fetch} */ = async (url, init) => {
|
|
37
|
+
try {
|
|
38
|
+
if (url instanceof URL && url.href?.startsWith('blob:')) {
|
|
39
|
+
const key = url.href.slice(5)
|
|
40
|
+
if (key in _ASSETS) {
|
|
41
|
+
return new Response(_base64Decode(_ASSETS[key]))
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return await _fetch(url, init)
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(error)
|
|
47
|
+
throw error
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Next edge runtime uses "self" as a function-scoped global-like object, but some of the older polyfills expect it to equal globalThis
|
|
52
|
+
// See https://nextjs.org/docs/basic-features/supported-browsers-features#polyfills
|
|
53
|
+
const self = { ...globalThis, fetch }
|