@netlify/plugin-nextjs 4.30.4 → 4.31.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.
Files changed (2) hide show
  1. package/lib/helpers/edge.js +85 -78
  2. package/package.json +2 -2
@@ -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 (!(0, destr_1.default)(process.env.NEXT_DISABLE_EDGE_IMAGES) &&
203
- !(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE) &&
204
- !(0, destr_1.default)(process.env.DISABLE_IPX)) {
205
- console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
206
- const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
207
- await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
208
- await copyEdgeSourceFile({ edgeFunctionDir, file: 'ipx.ts', target: 'index.ts' });
209
- await (0, fs_extra_1.copyFile)((0, path_1.join)('.netlify', 'functions-internal', '_ipx', 'imageconfig.json'), (0, path_1.join)(edgeFunctionDir, 'imageconfig.json'));
210
- manifest.functions.push({
211
- function: 'ipx',
212
- name: 'next/image handler',
213
- path: '/_next/image*',
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
- if (!(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
217
- const rscFunctions = await (0, exports.writeRscDataEdgeFunction)({
218
- prerenderManifest: await (0, exports.loadPrerenderManifest)(netlifyConfig),
219
- appPathRoutesManifest: await (0, exports.loadAppPathRoutesManifest)(netlifyConfig),
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
- manifest.functions.push(...rscFunctions);
222
- const middlewareManifest = await (0, exports.loadMiddlewareManifest)(netlifyConfig);
223
- if (!middlewareManifest) {
224
- console.error("Couldn't find the middleware manifest");
225
- return;
226
- }
227
- let usesEdge = false;
228
- for (const middleware of middlewareManifest.sortedMiddleware) {
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
- manifest.functions.push(...matchers.map((matcher) => middlewareMatcherToEdgeFunctionDefinition(matcher, functionName)));
246
- }
247
- // Functions (i.e. not middleware, but edge SSR and API routes)
248
- if (typeof middlewareManifest.functions === 'object') {
249
- // When using the app dir, we also need to check if the EF matches a page
250
- const appPathRoutesManifest = await (0, exports.loadAppPathRoutesManifest)(netlifyConfig);
251
- // A map of all route pages to their page regex. This is used for pages dir and appDir.
252
- const pageRegexMap = new Map([...(routesManifest.dynamicRoutes || []), ...(routesManifest.staticRoutes || [])].map((route) => [
253
- route.page,
254
- route.regex,
255
- ]));
256
- // Create a map of pages-dir routes to their data route regex (appDir uses the same route as the HTML)
257
- const dataRoutesMap = new Map([...(routesManifest.dataRoutes || [])].map((route) => [route.page, route.dataRouteRegex]));
258
- for (const edgeFunctionDefinition of Object.values(middlewareManifest.functions)) {
259
- usesEdge = true;
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
- if (usesEdge) {
292
- console.log((0, outdent_1.outdent) `
293
- ✨ Deploying middleware and functions to ${(0, chalk_1.greenBright) `Netlify Edge Functions`} ✨
294
- This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
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.30.4",
3
+ "version": "4.31.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.5.4",
39
+ "@netlify/build": "^29.6.4",
40
40
  "@types/fs-extra": "^9.0.13",
41
41
  "@types/jest": "^27.4.1",
42
42
  "@types/merge-stream": "^1.1.2",