@netlify/plugin-nextjs 4.24.3 → 4.26.0
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/index.js +1 -0
- package/lib/helpers/edge.js +18 -8
- package/lib/templates/getHandler.js +3 -2
- package/package.json +5 -4
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib')
|
package/lib/helpers/edge.js
CHANGED
|
@@ -27,26 +27,34 @@ const sanitizeName = (name) => `next_${name.replace(/\W/g, '_')}`;
|
|
|
27
27
|
/**
|
|
28
28
|
* Initialization added to the top of the edge function bundle
|
|
29
29
|
*/
|
|
30
|
-
const
|
|
30
|
+
const preamble = /* js */ `
|
|
31
|
+
|
|
31
32
|
globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT_PRIVATE_MINIMAL_MODE': '1' } }
|
|
32
|
-
|
|
33
|
+
let _ENTRIES = {}
|
|
33
34
|
// Deno defines "window", but naughty libraries think this means it's a browser
|
|
34
35
|
delete globalThis.window
|
|
35
|
-
|
|
36
|
+
// Next uses "self" as a function-scoped global-like object
|
|
37
|
+
const self = {}
|
|
36
38
|
`;
|
|
39
|
+
// Slightly different spacing in different versions!
|
|
40
|
+
const IMPORT_UNSUPPORTED = [
|
|
41
|
+
`Object.defineProperty(globalThis,"__import_unsupported"`,
|
|
42
|
+
` Object.defineProperty(globalThis, "__import_unsupported"`,
|
|
43
|
+
];
|
|
37
44
|
/**
|
|
38
45
|
* Concatenates the Next edge function code with the required chunks and adds an export
|
|
39
46
|
*/
|
|
40
47
|
const getMiddlewareBundle = async ({ edgeFunctionDefinition, netlifyConfig, }) => {
|
|
41
48
|
const { publish } = netlifyConfig.build;
|
|
42
|
-
const chunks = [
|
|
49
|
+
const chunks = [preamble];
|
|
43
50
|
for (const file of edgeFunctionDefinition.files) {
|
|
44
51
|
const filePath = (0, path_1.join)(publish, file);
|
|
45
|
-
|
|
52
|
+
let data = await fs_1.promises.readFile(filePath, 'utf8');
|
|
53
|
+
// Next defines an immutable global variable, which is fine unless you have more than one in the bundle
|
|
54
|
+
// This adds a check to see if the global is already defined
|
|
55
|
+
data = IMPORT_UNSUPPORTED.reduce((acc, val) => acc.replace(val, `('__import_unsupported' in globalThis)||${val}`), data);
|
|
46
56
|
chunks.push('{', data, '}');
|
|
47
57
|
}
|
|
48
|
-
const middleware = await fs_1.promises.readFile((0, path_1.join)(publish, `server`, `${edgeFunctionDefinition.name}.js`), 'utf8');
|
|
49
|
-
chunks.push(middleware);
|
|
50
58
|
const exports = /* js */ `export default _ENTRIES["middleware_${edgeFunctionDefinition.name}"].default;`;
|
|
51
59
|
chunks.push(exports);
|
|
52
60
|
return chunks.join('\n');
|
|
@@ -79,7 +87,7 @@ const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, net
|
|
|
79
87
|
// We add a defintion for each matching path
|
|
80
88
|
return matchers.map((matcher) => {
|
|
81
89
|
const pattern = matcher.regexp;
|
|
82
|
-
return { function: name, pattern };
|
|
90
|
+
return { function: name, pattern, name: edgeFunctionDefinition.name };
|
|
83
91
|
});
|
|
84
92
|
};
|
|
85
93
|
const cleanupEdgeFunctions = ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions', }) => (0, fs_extra_1.emptyDir)(INTERNAL_EDGE_FUNCTIONS_SRC);
|
|
@@ -89,6 +97,7 @@ const writeDevEdgeFunction = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/ed
|
|
|
89
97
|
functions: [
|
|
90
98
|
{
|
|
91
99
|
function: 'next-dev',
|
|
100
|
+
name: 'netlify dev handler',
|
|
92
101
|
path: '/*',
|
|
93
102
|
},
|
|
94
103
|
],
|
|
@@ -128,6 +137,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
|
|
|
128
137
|
await (0, fs_extra_1.copyFile)((0, path_1.join)('.netlify', 'functions-internal', '_ipx', 'imageconfig.json'), (0, path_1.join)(edgeFunctionDir, 'imageconfig.json'));
|
|
129
138
|
manifest.functions.push({
|
|
130
139
|
function: 'ipx',
|
|
140
|
+
name: 'next/image handler',
|
|
131
141
|
path: '/_next/image*',
|
|
132
142
|
});
|
|
133
143
|
}
|
|
@@ -105,8 +105,9 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
|
|
|
105
105
|
// ODBs currently have a minimum TTL of 60 seconds
|
|
106
106
|
result.ttl = Math.max(ttl, 60);
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
if (ttl === ONE_YEAR_IN_SECONDS && result.statusCode
|
|
108
|
+
const ephemeralCodes = [301, 302, 307, 308, 404];
|
|
109
|
+
if (ttl === ONE_YEAR_IN_SECONDS && ephemeralCodes.includes(result.statusCode)) {
|
|
110
|
+
// Only cache for 60s if default TTL provided
|
|
110
111
|
result.ttl = 60;
|
|
111
112
|
}
|
|
112
113
|
if (result.ttl > 0) {
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.26.0",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/**/*",
|
|
8
8
|
"src/templates/edge/*",
|
|
9
9
|
"src/templates/edge-shared/*",
|
|
10
|
+
"index.js",
|
|
10
11
|
"manifest.yml"
|
|
11
12
|
],
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"@netlify/esbuild": "0.14.39",
|
|
14
15
|
"@netlify/functions": "^1.3.0",
|
|
15
|
-
"@netlify/ipx": "^1.3.
|
|
16
|
+
"@netlify/ipx": "^1.3.1",
|
|
16
17
|
"@vercel/node-bridge": "^2.1.0",
|
|
17
18
|
"chalk": "^4.1.2",
|
|
18
19
|
"destr": "^1.1.1",
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@delucis/if-env": "^1.1.2",
|
|
36
|
-
"@netlify/build": "^27.20.
|
|
37
|
+
"@netlify/build": "^27.20.6",
|
|
37
38
|
"@types/fs-extra": "^9.0.13",
|
|
38
39
|
"@types/jest": "^27.4.1",
|
|
39
40
|
"@types/merge-stream": "^1.1.2",
|