@netlify/plugin-nextjs 4.30.5-setcookie.0 → 4.32.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/lib/helpers/edge.js +85 -78
- package/package.json +2 -2
- package/src/templates/edge/next-dev.js +9 -17
package/lib/helpers/edge.js
CHANGED
|
@@ -199,101 +199,108 @@ const writeEdgeFunctions = async ({ netlifyConfig, routesManifest, }) => {
|
|
|
199
199
|
await (0, fs_extra_1.copy)(getEdgeTemplatePath('../edge-shared'), (0, path_1.join)(edgeFunctionRoot, 'edge-shared'));
|
|
200
200
|
await (0, fs_extra_1.writeJSON)((0, path_1.join)(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig);
|
|
201
201
|
await (0, fs_extra_1.copy)((0, path_1.join)(publish, 'prerender-manifest.json'), (0, path_1.join)(edgeFunctionRoot, 'edge-shared', 'prerender-manifest.json'));
|
|
202
|
-
if
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
await
|
|
209
|
-
await (0,
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
202
|
+
// early return if edge is disabled
|
|
203
|
+
if ((0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
|
|
204
|
+
console.log('Environment variable NEXT_DISABLE_NETLIFY_EDGE has been set, skipping Netlify Edge Function creation.');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const rscFunctions = await (0, exports.writeRscDataEdgeFunction)({
|
|
208
|
+
prerenderManifest: await (0, exports.loadPrerenderManifest)(netlifyConfig),
|
|
209
|
+
appPathRoutesManifest: await (0, exports.loadAppPathRoutesManifest)(netlifyConfig),
|
|
210
|
+
});
|
|
211
|
+
manifest.functions.push(...rscFunctions);
|
|
212
|
+
const middlewareManifest = await (0, exports.loadMiddlewareManifest)(netlifyConfig);
|
|
213
|
+
if (!middlewareManifest) {
|
|
214
|
+
console.error("Couldn't find the middleware manifest");
|
|
215
|
+
return;
|
|
215
216
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
let usesEdge = false;
|
|
218
|
+
for (const middleware of middlewareManifest.sortedMiddleware) {
|
|
219
|
+
usesEdge = true;
|
|
220
|
+
const edgeFunctionDefinition = middlewareManifest.middleware[middleware];
|
|
221
|
+
const functionName = sanitizeName(edgeFunctionDefinition.name);
|
|
222
|
+
const matchers = generateEdgeFunctionMiddlewareMatchers({
|
|
223
|
+
edgeFunctionDefinition,
|
|
224
|
+
edgeFunctionRoot,
|
|
225
|
+
nextConfig,
|
|
220
226
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
await writeEdgeFunction({
|
|
228
|
+
edgeFunctionDefinition,
|
|
229
|
+
edgeFunctionRoot,
|
|
230
|
+
netlifyConfig,
|
|
231
|
+
functionName,
|
|
232
|
+
matchers,
|
|
233
|
+
middleware: true,
|
|
234
|
+
});
|
|
235
|
+
manifest.functions.push(...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName)));
|
|
236
|
+
}
|
|
237
|
+
// Functions (i.e. not middleware, but edge SSR and API routes)
|
|
238
|
+
if (typeof middlewareManifest.functions === 'object') {
|
|
239
|
+
// When using the app dir, we also need to check if the EF matches a page
|
|
240
|
+
const appPathRoutesManifest = await (0, exports.loadAppPathRoutesManifest)(netlifyConfig);
|
|
241
|
+
// A map of all route pages to their page regex. This is used for pages dir and appDir.
|
|
242
|
+
const pageRegexMap = new Map([...(routesManifest.dynamicRoutes || []), ...(routesManifest.staticRoutes || [])].map((route) => [
|
|
243
|
+
route.page,
|
|
244
|
+
route.regex,
|
|
245
|
+
]));
|
|
246
|
+
// Create a map of pages-dir routes to their data route regex (appDir uses the same route as the HTML)
|
|
247
|
+
const dataRoutesMap = new Map([...(routesManifest.dataRoutes || [])].map((route) => [route.page, route.dataRouteRegex]));
|
|
248
|
+
for (const edgeFunctionDefinition of Object.values(middlewareManifest.functions)) {
|
|
229
249
|
usesEdge = true;
|
|
230
|
-
const edgeFunctionDefinition = middlewareManifest.middleware[middleware];
|
|
231
250
|
const functionName = sanitizeName(edgeFunctionDefinition.name);
|
|
232
|
-
const matchers = generateEdgeFunctionMiddlewareMatchers({
|
|
233
|
-
edgeFunctionDefinition,
|
|
234
|
-
edgeFunctionRoot,
|
|
235
|
-
nextConfig,
|
|
236
|
-
});
|
|
237
251
|
await writeEdgeFunction({
|
|
238
252
|
edgeFunctionDefinition,
|
|
239
253
|
edgeFunctionRoot,
|
|
240
254
|
netlifyConfig,
|
|
241
255
|
functionName,
|
|
242
|
-
matchers,
|
|
243
|
-
middleware: true,
|
|
244
256
|
});
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const functionName = sanitizeName(edgeFunctionDefinition.name);
|
|
261
|
-
await writeEdgeFunction({
|
|
262
|
-
edgeFunctionDefinition,
|
|
263
|
-
edgeFunctionRoot,
|
|
264
|
-
netlifyConfig,
|
|
265
|
-
functionName,
|
|
266
|
-
});
|
|
267
|
-
const pattern = (0, exports.getEdgeFunctionPatternForPage)({
|
|
268
|
-
edgeFunctionDefinition,
|
|
269
|
-
pageRegexMap,
|
|
270
|
-
appPathRoutesManifest,
|
|
271
|
-
});
|
|
257
|
+
const pattern = (0, exports.getEdgeFunctionPatternForPage)({
|
|
258
|
+
edgeFunctionDefinition,
|
|
259
|
+
pageRegexMap,
|
|
260
|
+
appPathRoutesManifest,
|
|
261
|
+
});
|
|
262
|
+
manifest.functions.push({
|
|
263
|
+
function: functionName,
|
|
264
|
+
name: edgeFunctionDefinition.name,
|
|
265
|
+
pattern,
|
|
266
|
+
// cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir
|
|
267
|
+
cache: usesAppDir ? 'manual' : undefined,
|
|
268
|
+
});
|
|
269
|
+
// pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too
|
|
270
|
+
const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page);
|
|
271
|
+
if (dataRoute) {
|
|
272
272
|
manifest.functions.push({
|
|
273
273
|
function: functionName,
|
|
274
274
|
name: edgeFunctionDefinition.name,
|
|
275
|
-
pattern,
|
|
276
|
-
// cache: "manual" is currently experimental, so we restrict it to sites that use experimental appDir
|
|
275
|
+
pattern: dataRoute,
|
|
277
276
|
cache: usesAppDir ? 'manual' : undefined,
|
|
278
277
|
});
|
|
279
|
-
// pages-dir page routes also have a data route. If there's a match, add an entry mapping that to the function too
|
|
280
|
-
const dataRoute = dataRoutesMap.get(edgeFunctionDefinition.page);
|
|
281
|
-
if (dataRoute) {
|
|
282
|
-
manifest.functions.push({
|
|
283
|
-
function: functionName,
|
|
284
|
-
name: edgeFunctionDefinition.name,
|
|
285
|
-
pattern: dataRoute,
|
|
286
|
-
cache: usesAppDir ? 'manual' : undefined,
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
278
|
}
|
|
290
279
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
280
|
+
}
|
|
281
|
+
if ((0, destr_1.default)(process.env.NEXT_FORCE_EDGE_IMAGES) &&
|
|
282
|
+
!(0, destr_1.default)(process.env.NEXT_DISABLE_EDGE_IMAGES) &&
|
|
283
|
+
!(0, destr_1.default)(process.env.DISABLE_IPX)) {
|
|
284
|
+
usesEdge = true;
|
|
285
|
+
console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
|
|
286
|
+
const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
|
|
287
|
+
await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
|
|
288
|
+
await copyEdgeSourceFile({ edgeFunctionDir, file: 'ipx.ts', target: 'index.ts' });
|
|
289
|
+
await (0, fs_extra_1.copyFile)((0, path_1.join)('.netlify', 'functions-internal', '_ipx', 'imageconfig.json'), (0, path_1.join)(edgeFunctionDir, 'imageconfig.json'));
|
|
290
|
+
manifest.functions.push({
|
|
291
|
+
function: 'ipx',
|
|
292
|
+
name: 'next/image handler',
|
|
293
|
+
path: '/_next/image*',
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
console.log('You are not using Netlify Edge Functions for image format detection. Set env var "NEXT_FORCE_EDGE_IMAGES=true" to enable.');
|
|
298
|
+
}
|
|
299
|
+
if (usesEdge) {
|
|
300
|
+
console.log((0, outdent_1.outdent) `
|
|
301
|
+
✨ Deploying middleware and functions to ${(0, chalk_1.greenBright) `Netlify Edge Functions`} ✨
|
|
302
|
+
This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
|
|
303
|
+
`);
|
|
297
304
|
}
|
|
298
305
|
await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionRoot, 'manifest.json'), manifest);
|
|
299
306
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.32.0",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@delucis/if-env": "^1.1.2",
|
|
39
|
-
"@netlify/build": "^29.6.
|
|
39
|
+
"@netlify/build": "^29.6.7",
|
|
40
40
|
"@types/fs-extra": "^9.0.13",
|
|
41
41
|
"@types/jest": "^27.4.1",
|
|
42
42
|
"@types/merge-stream": "^1.1.2",
|
|
@@ -18,19 +18,6 @@ if (!('getAll' in Headers.prototype)) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// Check if a file exists, given a relative path
|
|
22
|
-
const exists = async (relativePath) => {
|
|
23
|
-
const path = fromFileUrl(new URL(relativePath, import.meta.url))
|
|
24
|
-
try {
|
|
25
|
-
await Deno.stat(path)
|
|
26
|
-
return true
|
|
27
|
-
} catch (error) {
|
|
28
|
-
if (error instanceof Deno.errors.NotFound) {
|
|
29
|
-
return false
|
|
30
|
-
}
|
|
31
|
-
throw error
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
21
|
let idx = 0
|
|
35
22
|
|
|
36
23
|
const handler = async (req, context) => {
|
|
@@ -45,14 +32,19 @@ const handler = async (req, context) => {
|
|
|
45
32
|
// We don't want to just try importing and use that to test,
|
|
46
33
|
// because that would also throw if there's an error in the middleware,
|
|
47
34
|
// which we would want to surface not ignore.
|
|
48
|
-
|
|
35
|
+
try {
|
|
49
36
|
// We need to cache-bust the import because otherwise it will claim it
|
|
50
37
|
// doesn't exist if the user creates it after the server starts
|
|
51
38
|
const nextMiddleware = await import(`../../middleware.js#${idx++}`)
|
|
52
39
|
middleware = nextMiddleware.middleware
|
|
53
|
-
}
|
|
54
|
-
//
|
|
55
|
-
|
|
40
|
+
} catch (importError) {
|
|
41
|
+
// Error message is `Module not found "file://<path>/middleware.js#123456".` in Deno
|
|
42
|
+
if (importError.code === 'ERR_MODULE_NOT_FOUND' && importError.message.includes(`middleware.js#${idx}`)) {
|
|
43
|
+
// No middleware, so we silently return
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw importError
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
// This is the format expected by Next.js along with the timezone which we support.
|