@netlify/plugin-nextjs 5.2.0 → 5.2.2

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.
@@ -58,7 +58,7 @@ var mapHeaderValues = (header, callback) => {
58
58
  };
59
59
  var setVaryHeaders = (headers, request, { basePath, i18n }) => {
60
60
  const netlifyVaryValues = {
61
- header: ["x-nextjs-data"],
61
+ header: ["x-nextjs-data", "x-next-debug-logging"],
62
62
  language: [],
63
63
  cookie: ["__prerender_bypass", "__next_preview_data"],
64
64
  query: [],
package/dist/run/next.cjs CHANGED
@@ -38,12 +38,9 @@ var require_lists = __commonJS({
38
38
  value: true
39
39
  });
40
40
  exports2.fsSyncMethods = exports2.fsProps = exports2.fsAsyncMethods = void 0;
41
- var fsProps = ["constants", "F_OK", "R_OK", "W_OK", "X_OK", "Stats"];
42
- exports2.fsProps = fsProps;
43
- var fsSyncMethods = ["renameSync", "ftruncateSync", "truncateSync", "chownSync", "fchownSync", "lchownSync", "chmodSync", "fchmodSync", "lchmodSync", "statSync", "lstatSync", "fstatSync", "linkSync", "symlinkSync", "readlinkSync", "realpathSync", "unlinkSync", "rmdirSync", "mkdirSync", "mkdirpSync", "readdirSync", "closeSync", "openSync", "utimesSync", "futimesSync", "fsyncSync", "writeSync", "readSync", "readFileSync", "writeFileSync", "appendFileSync", "existsSync", "accessSync", "fdatasyncSync", "mkdtempSync", "copyFileSync", "rmSync", "createReadStream", "createWriteStream"];
44
- exports2.fsSyncMethods = fsSyncMethods;
45
- var fsAsyncMethods = ["rename", "ftruncate", "truncate", "chown", "fchown", "lchown", "chmod", "fchmod", "lchmod", "stat", "lstat", "fstat", "link", "symlink", "readlink", "realpath", "unlink", "rmdir", "mkdir", "mkdirp", "readdir", "close", "open", "utimes", "futimes", "fsync", "write", "read", "readFile", "writeFile", "appendFile", "exists", "access", "fdatasync", "mkdtemp", "copyFile", "rm", "watchFile", "unwatchFile", "watch"];
46
- exports2.fsAsyncMethods = fsAsyncMethods;
41
+ var fsProps = exports2.fsProps = ["constants", "F_OK", "R_OK", "W_OK", "X_OK", "Stats"];
42
+ var fsSyncMethods = exports2.fsSyncMethods = ["renameSync", "ftruncateSync", "truncateSync", "chownSync", "fchownSync", "lchownSync", "chmodSync", "fchmodSync", "lchmodSync", "statSync", "lstatSync", "fstatSync", "linkSync", "symlinkSync", "readlinkSync", "realpathSync", "unlinkSync", "rmdirSync", "mkdirSync", "mkdirpSync", "readdirSync", "closeSync", "openSync", "utimesSync", "futimesSync", "fsyncSync", "writeSync", "readSync", "readFileSync", "writeFileSync", "appendFileSync", "existsSync", "accessSync", "fdatasyncSync", "mkdtempSync", "copyFileSync", "rmSync", "createReadStream", "createWriteStream"];
43
+ var fsAsyncMethods = exports2.fsAsyncMethods = ["rename", "ftruncate", "truncate", "chown", "fchown", "lchown", "chmod", "fchmod", "lchmod", "stat", "lstat", "fstat", "link", "symlink", "readlink", "realpath", "unlink", "rmdir", "mkdir", "mkdirp", "readdir", "close", "open", "utimes", "futimes", "fsync", "write", "read", "readFile", "writeFile", "appendFile", "exists", "access", "fdatasync", "mkdtemp", "copyFile", "rm", "watchFile", "unwatchFile", "watch"];
47
44
  }
48
45
  });
49
46
 
@@ -235,56 +232,42 @@ var require_correctPath = __commonJS({
235
232
  var require_patchRequire = __commonJS({
236
233
  "node_modules/fs-monkey/lib/patchRequire.js"(exports2) {
237
234
  "use strict";
238
- function _typeof(obj) {
235
+ function _typeof(o) {
239
236
  "@babel/helpers - typeof";
240
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
241
- return typeof obj2;
242
- } : function(obj2) {
243
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
244
- }, _typeof(obj);
237
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
238
+ return typeof o2;
239
+ } : function(o2) {
240
+ return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
241
+ }, _typeof(o);
245
242
  }
246
243
  Object.defineProperty(exports2, "__esModule", {
247
244
  value: true
248
245
  });
249
246
  exports2["default"] = patchRequire;
250
247
  var path = _interopRequireWildcard(require("path"));
251
- function _getRequireWildcardCache(nodeInterop) {
252
- if (typeof WeakMap !== "function")
248
+ function _getRequireWildcardCache(e) {
249
+ if ("function" != typeof WeakMap)
253
250
  return null;
254
- var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
255
- var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
256
- return (_getRequireWildcardCache = function _getRequireWildcardCache2(nodeInterop2) {
257
- return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
258
- })(nodeInterop);
251
+ var r = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakMap();
252
+ return (_getRequireWildcardCache = function _getRequireWildcardCache2(e2) {
253
+ return e2 ? t : r;
254
+ })(e);
259
255
  }
260
- function _interopRequireWildcard(obj, nodeInterop) {
261
- if (!nodeInterop && obj && obj.__esModule) {
262
- return obj;
263
- }
264
- if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
265
- return { "default": obj };
266
- }
267
- var cache = _getRequireWildcardCache(nodeInterop);
268
- if (cache && cache.has(obj)) {
269
- return cache.get(obj);
270
- }
271
- var newObj = {};
272
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
273
- for (var key in obj) {
274
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
275
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
276
- if (desc && (desc.get || desc.set)) {
277
- Object.defineProperty(newObj, key, desc);
278
- } else {
279
- newObj[key] = obj[key];
280
- }
256
+ function _interopRequireWildcard(e, r) {
257
+ if (!r && e && e.__esModule)
258
+ return e;
259
+ if (null === e || "object" != _typeof(e) && "function" != typeof e)
260
+ return { "default": e };
261
+ var t = _getRequireWildcardCache(r);
262
+ if (t && t.has(e))
263
+ return t.get(e);
264
+ var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor;
265
+ for (var u in e)
266
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
267
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
268
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
281
269
  }
282
- }
283
- newObj["default"] = obj;
284
- if (cache) {
285
- cache.set(obj, newObj);
286
- }
287
- return newObj;
270
+ return n["default"] = e, t && t.set(e, n), n;
288
271
  }
289
272
  var isWin32 = process.platform === "win32";
290
273
  var correctPath = isWin32 ? require_correctPath().correctPath : function(p) {
@@ -470,13 +453,13 @@ var require_patchRequire = __commonJS({
470
453
  var require_lib = __commonJS({
471
454
  "node_modules/fs-monkey/lib/index.js"(exports2) {
472
455
  "use strict";
473
- function _typeof(obj) {
456
+ function _typeof(o) {
474
457
  "@babel/helpers - typeof";
475
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
476
- return typeof obj2;
477
- } : function(obj2) {
478
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
479
- }, _typeof(obj);
458
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
459
+ return typeof o2;
460
+ } : function(o2) {
461
+ return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
462
+ }, _typeof(o);
480
463
  }
481
464
  Object.defineProperty(exports2, "__esModule", {
482
465
  value: true
@@ -505,43 +488,29 @@ var require_lib = __commonJS({
505
488
  var _correctPath = require_correctPath();
506
489
  var util = _interopRequireWildcard(require_lists());
507
490
  exports2.util = util;
508
- function _getRequireWildcardCache(nodeInterop) {
509
- if (typeof WeakMap !== "function")
491
+ function _getRequireWildcardCache(e) {
492
+ if ("function" != typeof WeakMap)
510
493
  return null;
511
- var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
512
- var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
513
- return (_getRequireWildcardCache = function _getRequireWildcardCache2(nodeInterop2) {
514
- return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
515
- })(nodeInterop);
494
+ var r = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakMap();
495
+ return (_getRequireWildcardCache = function _getRequireWildcardCache2(e2) {
496
+ return e2 ? t : r;
497
+ })(e);
516
498
  }
517
- function _interopRequireWildcard(obj, nodeInterop) {
518
- if (!nodeInterop && obj && obj.__esModule) {
519
- return obj;
520
- }
521
- if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
522
- return { "default": obj };
523
- }
524
- var cache = _getRequireWildcardCache(nodeInterop);
525
- if (cache && cache.has(obj)) {
526
- return cache.get(obj);
527
- }
528
- var newObj = {};
529
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
530
- for (var key in obj) {
531
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
532
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
533
- if (desc && (desc.get || desc.set)) {
534
- Object.defineProperty(newObj, key, desc);
535
- } else {
536
- newObj[key] = obj[key];
537
- }
499
+ function _interopRequireWildcard(e, r) {
500
+ if (!r && e && e.__esModule)
501
+ return e;
502
+ if (null === e || "object" != _typeof(e) && "function" != typeof e)
503
+ return { "default": e };
504
+ var t = _getRequireWildcardCache(r);
505
+ if (t && t.has(e))
506
+ return t.get(e);
507
+ var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor;
508
+ for (var u in e)
509
+ if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
510
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
511
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
538
512
  }
539
- }
540
- newObj["default"] = obj;
541
- if (cache) {
542
- cache.set(obj, newObj);
543
- }
544
- return newObj;
513
+ return n["default"] = e, t && t.set(e, n), n;
545
514
  }
546
515
  function _interopRequireDefault(obj) {
547
516
  return obj && obj.__esModule ? obj : { "default": obj };
@@ -4,104 +4,75 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
- import {
8
- __commonJS,
9
- __require,
10
- __toESM
11
- } from "../esm-chunks/chunk-5JVNISGM.js";
7
+ import "../esm-chunks/chunk-5JVNISGM.js";
12
8
 
13
- // node_modules/@netlify/functions/dist/lib/system_logger.js
14
- var require_system_logger = __commonJS({
15
- "node_modules/@netlify/functions/dist/lib/system_logger.js"(exports) {
16
- "use strict";
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.systemLogger = exports.LogLevel = void 0;
19
- var process_1 = __require("process");
20
- var systemLogTag = "__nfSystemLog";
21
- var serializeError = (error) => {
22
- const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
23
- return {
24
- error: error.message,
25
- error_cause: cause,
26
- error_stack: error.stack
27
- };
28
- };
29
- var LogLevel2;
30
- (function(LogLevel3) {
31
- LogLevel3[LogLevel3["Debug"] = 1] = "Debug";
32
- LogLevel3[LogLevel3["Log"] = 2] = "Log";
33
- LogLevel3[LogLevel3["Error"] = 3] = "Error";
34
- })(LogLevel2 = exports.LogLevel || (exports.LogLevel = {}));
35
- var SystemLogger = class _SystemLogger {
36
- fields;
37
- logLevel;
38
- constructor(fields = {}, logLevel = LogLevel2.Log) {
39
- this.fields = fields;
40
- this.logLevel = logLevel;
41
- }
42
- doLog(logger, message) {
43
- if (process_1.env.NETLIFY_DEV && !process_1.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
44
- return;
45
- }
46
- logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
47
- }
48
- log(message) {
49
- if (this.logLevel > LogLevel2.Log) {
50
- return;
51
- }
52
- this.doLog(console.log, message);
53
- }
54
- debug(message) {
55
- if (this.logLevel > LogLevel2.Debug) {
56
- return;
57
- }
58
- this.doLog(console.debug, message);
59
- }
60
- error(message) {
61
- if (this.logLevel > LogLevel2.Error) {
62
- return;
63
- }
64
- this.doLog(console.error, message);
65
- }
66
- withLogLevel(level) {
67
- return new _SystemLogger(this.fields, level);
68
- }
69
- withFields(fields) {
70
- return new _SystemLogger({
71
- ...this.fields,
72
- ...fields
73
- }, this.logLevel);
74
- }
75
- withError(error) {
76
- const fields = error instanceof Error ? serializeError(error) : { error };
77
- return this.withFields(fields);
78
- }
79
- };
80
- exports.systemLogger = new SystemLogger();
9
+ // node_modules/@netlify/functions/dist/chunk-HYMERDCV.mjs
10
+ import { env } from "process";
11
+ var systemLogTag = "__nfSystemLog";
12
+ var serializeError = (error) => {
13
+ const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
14
+ return {
15
+ error: error.message,
16
+ error_cause: cause,
17
+ error_stack: error.stack
18
+ };
19
+ };
20
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
21
+ LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
22
+ LogLevel2[LogLevel2["Log"] = 2] = "Log";
23
+ LogLevel2[LogLevel2["Error"] = 3] = "Error";
24
+ return LogLevel2;
25
+ })(LogLevel || {});
26
+ var SystemLogger = class _SystemLogger {
27
+ fields;
28
+ logLevel;
29
+ constructor(fields = {}, logLevel = 2) {
30
+ this.fields = fields;
31
+ this.logLevel = logLevel;
81
32
  }
82
- });
83
-
84
- // node_modules/@netlify/functions/dist/internal.js
85
- var require_internal = __commonJS({
86
- "node_modules/@netlify/functions/dist/internal.js"(exports) {
87
- "use strict";
88
- Object.defineProperty(exports, "__esModule", { value: true });
89
- exports.LogLevel = exports.systemLogger = void 0;
90
- var system_logger_js_1 = require_system_logger();
91
- Object.defineProperty(exports, "systemLogger", { enumerable: true, get: function() {
92
- return system_logger_js_1.systemLogger;
93
- } });
94
- Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function() {
95
- return system_logger_js_1.LogLevel;
96
- } });
33
+ doLog(logger, message) {
34
+ if (env.NETLIFY_DEV && !env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
35
+ return;
36
+ }
37
+ logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
97
38
  }
98
- });
99
-
100
- // src/run/systemlog.ts
101
- var import_internal = __toESM(require_internal(), 1);
102
- var export_LogLevel = import_internal.LogLevel;
103
- var export_logger = import_internal.systemLogger;
39
+ log(message) {
40
+ if (this.logLevel > 2) {
41
+ return;
42
+ }
43
+ this.doLog(console.log, message);
44
+ }
45
+ debug(message) {
46
+ if (this.logLevel > 1) {
47
+ return;
48
+ }
49
+ this.doLog(console.debug, message);
50
+ }
51
+ error(message) {
52
+ if (this.logLevel > 3) {
53
+ return;
54
+ }
55
+ this.doLog(console.error, message);
56
+ }
57
+ withLogLevel(level) {
58
+ return new _SystemLogger(this.fields, level);
59
+ }
60
+ withFields(fields) {
61
+ return new _SystemLogger(
62
+ {
63
+ ...this.fields,
64
+ ...fields
65
+ },
66
+ this.logLevel
67
+ );
68
+ }
69
+ withError(error) {
70
+ const fields = error instanceof Error ? serializeError(error) : { error };
71
+ return this.withFields(fields);
72
+ }
73
+ };
74
+ var systemLogger = new SystemLogger();
104
75
  export {
105
- export_LogLevel as LogLevel,
106
- export_logger as logger
76
+ LogLevel,
77
+ systemLogger as logger
107
78
  };
@@ -3,6 +3,8 @@ import { HTMLRewriter } from '../vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/
3
3
 
4
4
  import { updateModifiedHeaders } from './headers.ts'
5
5
  import type { StructuredLogger } from './logging.ts'
6
+ import { addMiddlewareHeaders, isMiddlewareRequest, isMiddlewareResponse } from './middleware.ts'
7
+ import { RequestData } from './next-request.ts'
6
8
  import {
7
9
  addBasePath,
8
10
  normalizeDataUrl,
@@ -10,8 +12,6 @@ import {
10
12
  normalizeTrailingSlash,
11
13
  relativizeURL,
12
14
  } from './util.ts'
13
- import { addMiddlewareHeaders, isMiddlewareRequest, isMiddlewareResponse } from './middleware.ts'
14
- import { RequestData } from './next-request.ts'
15
15
 
16
16
  export interface FetchEventResult {
17
17
  response: Response
@@ -118,11 +118,12 @@ export const buildResponse = async ({
118
118
 
119
119
  let rewrite = res.headers.get('x-middleware-rewrite')
120
120
  let redirect = res.headers.get('location')
121
+ let nextRedirect = res.headers.get('x-nextjs-redirect')
121
122
 
122
123
  // Data requests (i.e. requests for /_next/data ) need special handling
123
124
  const isDataReq = request.headers.has('x-nextjs-data')
124
125
  // Data requests need to be normalized to the route path
125
- if (isDataReq && !redirect && !rewrite) {
126
+ if (isDataReq && !redirect && !rewrite && !nextRedirect) {
126
127
  const requestUrl = new URL(request.url)
127
128
  const normalizedDataUrl = normalizeDataUrl(requestUrl.pathname)
128
129
  // Don't rewrite unless the URL has changed
@@ -181,8 +182,11 @@ export const buildResponse = async ({
181
182
  // The rewrite target is a data request, but a middleware rewrite target is always for the page route,
182
183
  // so we need to tell the server this is a data request. Setting the `x-nextjs-data` header is not enough. 🤷
183
184
  rewriteUrl.searchParams.set('__nextDataReq', '1')
184
- rewriteUrl.pathname = normalizeTrailingSlash(rewriteUrl.pathname, nextConfig?.trailingSlash)
185
185
  }
186
+
187
+ // respect trailing slash rules to prevent 308s
188
+ rewriteUrl.pathname = normalizeTrailingSlash(rewriteUrl.pathname, nextConfig?.trailingSlash)
189
+
186
190
  const target = normalizeLocalizedTarget({ target: rewriteUrl.toString(), request, nextConfig })
187
191
  if (target === request.url) {
188
192
  logger.withFields({ rewrite_url: rewrite }).debug('Rewrite url is same as original url')
@@ -209,7 +213,7 @@ export const buildResponse = async ({
209
213
  res.headers.set('x-nextjs-redirect', relativizeURL(redirect, request.url))
210
214
  }
211
215
 
212
- const nextRedirect = res.headers.get('x-nextjs-redirect')
216
+ nextRedirect = res.headers.get('x-nextjs-redirect')
213
217
 
214
218
  if (nextRedirect && isDataReq) {
215
219
  res.headers.set('x-nextjs-redirect', normalizeDataUrl(nextRedirect))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",