@netlify/plugin-nextjs 5.11.0 → 5.11.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.
@@ -13,7 +13,7 @@ import {
13
13
  } from "../../esm-chunks/chunk-YUXQHOYO.js";
14
14
  import {
15
15
  require_semver
16
- } from "../../esm-chunks/chunk-PFLHY2KD.js";
16
+ } from "../../esm-chunks/chunk-TLQCAGE2.js";
17
17
  import {
18
18
  __toESM
19
19
  } from "../../esm-chunks/chunk-6BT4RYQJ.js";
@@ -59,6 +59,12 @@ var Queue = class {
59
59
  this.#size--;
60
60
  return current.value;
61
61
  }
62
+ peek() {
63
+ if (!this.#head) {
64
+ return;
65
+ }
66
+ return this.#head.value;
67
+ }
62
68
  clear() {
63
69
  this.#head = void 0;
64
70
  this.#tail = void 0;
@@ -74,24 +80,29 @@ var Queue = class {
74
80
  current = current.next;
75
81
  }
76
82
  }
83
+ *drain() {
84
+ while (this.#head) {
85
+ yield this.dequeue();
86
+ }
87
+ }
77
88
  };
78
89
 
79
90
  // node_modules/p-limit/index.js
80
- import { AsyncResource } from "async_hooks";
81
91
  function pLimit(concurrency) {
82
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
83
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
84
- }
92
+ validateConcurrency(concurrency);
85
93
  const queue = new Queue();
86
94
  let activeCount = 0;
87
- const next = () => {
88
- activeCount--;
89
- if (queue.size > 0) {
95
+ const resumeNext = () => {
96
+ if (activeCount < concurrency && queue.size > 0) {
90
97
  queue.dequeue()();
98
+ activeCount++;
91
99
  }
92
100
  };
101
+ const next = () => {
102
+ activeCount--;
103
+ resumeNext();
104
+ };
93
105
  const run = async (function_, resolve, arguments_) => {
94
- activeCount++;
95
106
  const result = (async () => function_(...arguments_))();
96
107
  resolve(result);
97
108
  try {
@@ -101,13 +112,15 @@ function pLimit(concurrency) {
101
112
  next();
102
113
  };
103
114
  const enqueue = (function_, resolve, arguments_) => {
104
- queue.enqueue(
105
- AsyncResource.bind(run.bind(void 0, function_, resolve, arguments_))
115
+ new Promise((internalResolve) => {
116
+ queue.enqueue(internalResolve);
117
+ }).then(
118
+ run.bind(void 0, function_, resolve, arguments_)
106
119
  );
107
120
  (async () => {
108
121
  await Promise.resolve();
109
- if (activeCount < concurrency && queue.size > 0) {
110
- queue.dequeue()();
122
+ if (activeCount < concurrency) {
123
+ resumeNext();
111
124
  }
112
125
  })();
113
126
  };
@@ -125,10 +138,27 @@ function pLimit(concurrency) {
125
138
  value() {
126
139
  queue.clear();
127
140
  }
141
+ },
142
+ concurrency: {
143
+ get: () => concurrency,
144
+ set(newConcurrency) {
145
+ validateConcurrency(newConcurrency);
146
+ concurrency = newConcurrency;
147
+ queueMicrotask(() => {
148
+ while (activeCount < concurrency && queue.size > 0) {
149
+ resumeNext();
150
+ }
151
+ });
152
+ }
128
153
  }
129
154
  });
130
155
  return generator;
131
156
  }
157
+ function validateConcurrency(concurrency) {
158
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
159
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
160
+ }
161
+ }
132
162
 
133
163
  // src/build/content/prerendered.ts
134
164
  var import_semver = __toESM(require_semver(), 1);
@@ -13,7 +13,7 @@ import {
13
13
  } from "../../esm-chunks/chunk-YUXQHOYO.js";
14
14
  import {
15
15
  require_semver
16
- } from "../../esm-chunks/chunk-PFLHY2KD.js";
16
+ } from "../../esm-chunks/chunk-TLQCAGE2.js";
17
17
  import {
18
18
  __toESM
19
19
  } from "../../esm-chunks/chunk-6BT4RYQJ.js";
@@ -32,16 +32,18 @@ var copyStaticContent = async (ctx) => {
32
32
  extglob: true
33
33
  });
34
34
  const fallbacks = ctx.getFallbacks(await ctx.getPrerenderManifest());
35
+ const fullyStaticPages = await ctx.getFullyStaticHtmlPages();
35
36
  try {
36
37
  await mkdir(destDir, { recursive: true });
37
38
  await Promise.all(
38
- paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
39
+ paths.filter((path) => !path.endsWith(".json") && !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
39
40
  const html = await readFile(join(srcDir, path), "utf-8");
40
41
  verifyNetlifyForms(ctx, html);
41
42
  const isFallback = fallbacks.includes(path.slice(0, -5));
43
+ const isFullyStaticPage = !isFallback && fullyStaticPages.includes(path);
42
44
  await writeFile(
43
45
  join(destDir, await encodeBlobKey(path)),
44
- JSON.stringify({ html, isFallback }),
46
+ JSON.stringify({ html, isFullyStaticPage }),
45
47
  "utf-8"
46
48
  );
47
49
  })
@@ -487,7 +487,7 @@ var writeHandlerFile = async (ctx, { matchers, name }) => {
487
487
  `
488
488
  );
489
489
  };
490
- var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
490
+ var copyHandlerDependencies = async (ctx, { name, env, files, wasm }) => {
491
491
  const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
492
492
  const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }));
493
493
  const edgeRuntimeDir = join(ctx.pluginDir, "edge-runtime");
@@ -495,6 +495,11 @@ var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
495
495
  const shim = await readFile(shimPath, "utf8");
496
496
  const parts = [shim];
497
497
  const outputFile = join(destDir, `server/${name}.js`);
498
+ if (env) {
499
+ for (const [key, value] of Object.entries(env)) {
500
+ parts.push(`process.env.${key} = '${value}';`);
501
+ }
502
+ }
498
503
  if (wasm?.length) {
499
504
  for (const wasmChunk of wasm ?? []) {
500
505
  const data = await readFile(join(srcDir, wasmChunk.filePath));
@@ -516,13 +521,13 @@ var createEdgeHandler = async (ctx, definition) => {
516
521
  };
517
522
  var getHandlerName = ({ name }) => `${EDGE_HANDLER_NAME}-${name.replace(/\W/g, "-")}`;
518
523
  var buildHandlerDefinition = (ctx, { name, matchers, page }) => {
519
- const fun = getHandlerName({ name });
520
- const funName = name.endsWith("middleware") ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`;
524
+ const functionHandlerName = getHandlerName({ name });
525
+ const functionName = name.endsWith("middleware") ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`;
521
526
  const cache = name.endsWith("middleware") ? void 0 : "manual";
522
527
  const generator = `${ctx.pluginName}@${ctx.pluginVersion}`;
523
528
  return augmentMatchers(matchers, ctx).map((matcher) => ({
524
- function: fun,
525
- name: funName,
529
+ function: functionHandlerName,
530
+ name: functionName,
526
531
  pattern: matcher.regexp,
527
532
  cache,
528
533
  generator
@@ -533,10 +538,7 @@ var clearStaleEdgeHandlers = async (ctx) => {
533
538
  };
534
539
  var createEdgeHandlers = async (ctx) => {
535
540
  const nextManifest = await ctx.getMiddlewareManifest();
536
- const nextDefinitions = [
537
- ...Object.values(nextManifest.middleware)
538
- // ...Object.values(nextManifest.functions)
539
- ];
541
+ const nextDefinitions = [...Object.values(nextManifest.middleware)];
540
542
  await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)));
541
543
  const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def));
542
544
  const netlifyManifest = {
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {
8
8
  require_semver
9
- } from "../esm-chunks/chunk-PFLHY2KD.js";
9
+ } from "../esm-chunks/chunk-TLQCAGE2.js";
10
10
  import {
11
11
  __toESM
12
12
  } from "../esm-chunks/chunk-6BT4RYQJ.js";
@@ -17,7 +17,7 @@ import { existsSync, readFileSync } from "node:fs";
17
17
  import { readFile } from "node:fs/promises";
18
18
  import { createRequire } from "node:module";
19
19
  import { join, relative, resolve } from "node:path";
20
- import { join as posixJoin } from "node:path/posix";
20
+ import { join as posixJoin, relative as posixRelative } from "node:path/posix";
21
21
  import { fileURLToPath } from "node:url";
22
22
  var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
23
23
  var PLUGIN_DIR = join(MODULE_DIR, "../..");
@@ -292,6 +292,29 @@ var PluginContext = class {
292
292
  }
293
293
  return this.#fallbacks;
294
294
  }
295
+ #fullyStaticHtmlPages = null;
296
+ /**
297
+ * Get an array of fully static pages router pages (no `getServerSideProps` or `getStaticProps`).
298
+ * Those are being served as-is without involving CacheHandler, so we need to keep track of them
299
+ * to make sure we apply permanent caching headers for responses that use them.
300
+ */
301
+ async getFullyStaticHtmlPages() {
302
+ if (!this.#fullyStaticHtmlPages) {
303
+ const pagesManifest = JSON.parse(
304
+ await readFile(join(this.publishDir, "server/pages-manifest.json"), "utf-8")
305
+ );
306
+ this.#fullyStaticHtmlPages = Object.values(pagesManifest).filter(
307
+ (filePath) => (
308
+ // Limit handling to pages router files (App Router pages should not be included in pages-manifest.json
309
+ // as they have their own app-paths-manifest.json)
310
+ filePath.startsWith("pages/") && // Fully static pages will have entries in the pages-manifest.json pointing to .html files.
311
+ // Pages with data fetching exports will point to .js files.
312
+ filePath.endsWith(".html")
313
+ )
314
+ ).map((filePath) => posixRelative("pages", filePath));
315
+ }
316
+ return this.#fullyStaticHtmlPages;
317
+ }
295
318
  /** Fails a build with a message and an optional error */
296
319
  failBuild(message, error) {
297
320
  return this.utils.build.failBuild(message, error instanceof Error ? { error } : void 0);
@@ -9,7 +9,7 @@ import {
9
9
  } from "../esm-chunks/chunk-YUXQHOYO.js";
10
10
  import {
11
11
  require_semver
12
- } from "../esm-chunks/chunk-PFLHY2KD.js";
12
+ } from "../esm-chunks/chunk-TLQCAGE2.js";
13
13
  import {
14
14
  __toESM
15
15
  } from "../esm-chunks/chunk-6BT4RYQJ.js";
@@ -11,6 +11,7 @@ import {
11
11
  // node_modules/semver/internal/constants.js
12
12
  var require_constants = __commonJS({
13
13
  "node_modules/semver/internal/constants.js"(exports, module) {
14
+ "use strict";
14
15
  var SEMVER_SPEC_VERSION = "2.0.0";
15
16
  var MAX_LENGTH = 256;
16
17
  var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
@@ -42,6 +43,7 @@ var require_constants = __commonJS({
42
43
  // node_modules/semver/internal/debug.js
43
44
  var require_debug = __commonJS({
44
45
  "node_modules/semver/internal/debug.js"(exports, module) {
46
+ "use strict";
45
47
  var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
46
48
  };
47
49
  module.exports = debug;
@@ -51,6 +53,7 @@ var require_debug = __commonJS({
51
53
  // node_modules/semver/internal/re.js
52
54
  var require_re = __commonJS({
53
55
  "node_modules/semver/internal/re.js"(exports, module) {
56
+ "use strict";
54
57
  var {
55
58
  MAX_SAFE_COMPONENT_LENGTH,
56
59
  MAX_SAFE_BUILD_LENGTH,
@@ -61,6 +64,7 @@ var require_re = __commonJS({
61
64
  var re = exports.re = [];
62
65
  var safeRe = exports.safeRe = [];
63
66
  var src = exports.src = [];
67
+ var safeSrc = exports.safeSrc = [];
64
68
  var t = exports.t = {};
65
69
  var R = 0;
66
70
  var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
@@ -81,6 +85,7 @@ var require_re = __commonJS({
81
85
  debug(name, index, value);
82
86
  t[name] = index;
83
87
  src[index] = value;
88
+ safeSrc[index] = safe;
84
89
  re[index] = new RegExp(value, isGlobal ? "g" : void 0);
85
90
  safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
86
91
  };
@@ -89,8 +94,8 @@ var require_re = __commonJS({
89
94
  createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
90
95
  createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
91
96
  createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
92
- createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NUMERICIDENTIFIER]}|${src[t.NONNUMERICIDENTIFIER]})`);
93
- createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NUMERICIDENTIFIERLOOSE]}|${src[t.NONNUMERICIDENTIFIER]})`);
97
+ createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
98
+ createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
94
99
  createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
95
100
  createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
96
101
  createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
@@ -136,6 +141,7 @@ var require_re = __commonJS({
136
141
  // node_modules/semver/internal/parse-options.js
137
142
  var require_parse_options = __commonJS({
138
143
  "node_modules/semver/internal/parse-options.js"(exports, module) {
144
+ "use strict";
139
145
  var looseOption = Object.freeze({ loose: true });
140
146
  var emptyOpts = Object.freeze({});
141
147
  var parseOptions = (options) => {
@@ -154,6 +160,7 @@ var require_parse_options = __commonJS({
154
160
  // node_modules/semver/internal/identifiers.js
155
161
  var require_identifiers = __commonJS({
156
162
  "node_modules/semver/internal/identifiers.js"(exports, module) {
163
+ "use strict";
157
164
  var numeric = /^[0-9]+$/;
158
165
  var compareIdentifiers = (a, b) => {
159
166
  const anum = numeric.test(a);
@@ -175,6 +182,7 @@ var require_identifiers = __commonJS({
175
182
  // node_modules/semver/classes/semver.js
176
183
  var require_semver = __commonJS({
177
184
  "node_modules/semver/classes/semver.js"(exports, module) {
185
+ "use strict";
178
186
  var debug = require_debug();
179
187
  var { MAX_LENGTH, MAX_SAFE_INTEGER } = require_constants();
180
188
  var { safeRe: re, t } = require_re();
@@ -317,6 +325,17 @@ var require_semver = __commonJS({
317
325
  // preminor will bump the version up to the next minor release, and immediately
318
326
  // down to pre-release. premajor and prepatch work the same way.
319
327
  inc(release, identifier, identifierBase) {
328
+ if (release.startsWith("pre")) {
329
+ if (!identifier && identifierBase === false) {
330
+ throw new Error("invalid increment argument: identifier is empty");
331
+ }
332
+ if (identifier) {
333
+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
334
+ if (!match || match[1] !== identifier) {
335
+ throw new Error(`invalid identifier: ${identifier}`);
336
+ }
337
+ }
338
+ }
320
339
  switch (release) {
321
340
  case "premajor":
322
341
  this.prerelease.length = 0;
@@ -344,6 +363,12 @@ var require_semver = __commonJS({
344
363
  }
345
364
  this.inc("pre", identifier, identifierBase);
346
365
  break;
366
+ case "release":
367
+ if (this.prerelease.length === 0) {
368
+ throw new Error(`version ${this.raw} is not a prerelease`);
369
+ }
370
+ this.prerelease.length = 0;
371
+ break;
347
372
  case "major":
348
373
  if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) {
349
374
  this.major++;
@@ -369,9 +394,6 @@ var require_semver = __commonJS({
369
394
  // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
370
395
  case "pre": {
371
396
  const base = Number(identifierBase) ? 1 : 0;
372
- if (!identifier && identifierBase === false) {
373
- throw new Error("invalid increment argument: identifier is empty");
374
- }
375
397
  if (this.prerelease.length === 0) {
376
398
  this.prerelease = [base];
377
399
  } else {
@@ -421,6 +443,7 @@ var require_semver = __commonJS({
421
443
  // node_modules/semver/functions/parse.js
422
444
  var require_parse = __commonJS({
423
445
  "node_modules/semver/functions/parse.js"(exports, module) {
446
+ "use strict";
424
447
  var SemVer = require_semver();
425
448
  var parse = (version, options, throwErrors = false) => {
426
449
  if (version instanceof SemVer) {
@@ -442,6 +465,7 @@ var require_parse = __commonJS({
442
465
  // node_modules/semver/functions/valid.js
443
466
  var require_valid = __commonJS({
444
467
  "node_modules/semver/functions/valid.js"(exports, module) {
468
+ "use strict";
445
469
  var parse = require_parse();
446
470
  var valid = (version, options) => {
447
471
  const v = parse(version, options);
@@ -454,6 +478,7 @@ var require_valid = __commonJS({
454
478
  // node_modules/semver/functions/clean.js
455
479
  var require_clean = __commonJS({
456
480
  "node_modules/semver/functions/clean.js"(exports, module) {
481
+ "use strict";
457
482
  var parse = require_parse();
458
483
  var clean = (version, options) => {
459
484
  const s = parse(version.trim().replace(/^[=v]+/, ""), options);
@@ -466,6 +491,7 @@ var require_clean = __commonJS({
466
491
  // node_modules/semver/functions/inc.js
467
492
  var require_inc = __commonJS({
468
493
  "node_modules/semver/functions/inc.js"(exports, module) {
494
+ "use strict";
469
495
  var SemVer = require_semver();
470
496
  var inc = (version, release, options, identifier, identifierBase) => {
471
497
  if (typeof options === "string") {
@@ -489,6 +515,7 @@ var require_inc = __commonJS({
489
515
  // node_modules/semver/functions/diff.js
490
516
  var require_diff = __commonJS({
491
517
  "node_modules/semver/functions/diff.js"(exports, module) {
518
+ "use strict";
492
519
  var parse = require_parse();
493
520
  var diff = (version1, version2) => {
494
521
  const v1 = parse(version1, null, true);
@@ -506,13 +533,12 @@ var require_diff = __commonJS({
506
533
  if (!lowVersion.patch && !lowVersion.minor) {
507
534
  return "major";
508
535
  }
509
- if (highVersion.patch) {
536
+ if (lowVersion.compareMain(highVersion) === 0) {
537
+ if (lowVersion.minor && !lowVersion.patch) {
538
+ return "minor";
539
+ }
510
540
  return "patch";
511
541
  }
512
- if (highVersion.minor) {
513
- return "minor";
514
- }
515
- return "major";
516
542
  }
517
543
  const prefix = highHasPre ? "pre" : "";
518
544
  if (v1.major !== v2.major) {
@@ -533,6 +559,7 @@ var require_diff = __commonJS({
533
559
  // node_modules/semver/functions/major.js
534
560
  var require_major = __commonJS({
535
561
  "node_modules/semver/functions/major.js"(exports, module) {
562
+ "use strict";
536
563
  var SemVer = require_semver();
537
564
  var major = (a, loose) => new SemVer(a, loose).major;
538
565
  module.exports = major;
@@ -542,6 +569,7 @@ var require_major = __commonJS({
542
569
  // node_modules/semver/functions/minor.js
543
570
  var require_minor = __commonJS({
544
571
  "node_modules/semver/functions/minor.js"(exports, module) {
572
+ "use strict";
545
573
  var SemVer = require_semver();
546
574
  var minor = (a, loose) => new SemVer(a, loose).minor;
547
575
  module.exports = minor;
@@ -551,6 +579,7 @@ var require_minor = __commonJS({
551
579
  // node_modules/semver/functions/patch.js
552
580
  var require_patch = __commonJS({
553
581
  "node_modules/semver/functions/patch.js"(exports, module) {
582
+ "use strict";
554
583
  var SemVer = require_semver();
555
584
  var patch = (a, loose) => new SemVer(a, loose).patch;
556
585
  module.exports = patch;
@@ -560,6 +589,7 @@ var require_patch = __commonJS({
560
589
  // node_modules/semver/functions/prerelease.js
561
590
  var require_prerelease = __commonJS({
562
591
  "node_modules/semver/functions/prerelease.js"(exports, module) {
592
+ "use strict";
563
593
  var parse = require_parse();
564
594
  var prerelease = (version, options) => {
565
595
  const parsed = parse(version, options);
@@ -572,6 +602,7 @@ var require_prerelease = __commonJS({
572
602
  // node_modules/semver/functions/compare.js
573
603
  var require_compare = __commonJS({
574
604
  "node_modules/semver/functions/compare.js"(exports, module) {
605
+ "use strict";
575
606
  var SemVer = require_semver();
576
607
  var compare = (a, b, loose) => new SemVer(a, loose).compare(new SemVer(b, loose));
577
608
  module.exports = compare;
@@ -581,6 +612,7 @@ var require_compare = __commonJS({
581
612
  // node_modules/semver/functions/rcompare.js
582
613
  var require_rcompare = __commonJS({
583
614
  "node_modules/semver/functions/rcompare.js"(exports, module) {
615
+ "use strict";
584
616
  var compare = require_compare();
585
617
  var rcompare = (a, b, loose) => compare(b, a, loose);
586
618
  module.exports = rcompare;
@@ -590,6 +622,7 @@ var require_rcompare = __commonJS({
590
622
  // node_modules/semver/functions/compare-loose.js
591
623
  var require_compare_loose = __commonJS({
592
624
  "node_modules/semver/functions/compare-loose.js"(exports, module) {
625
+ "use strict";
593
626
  var compare = require_compare();
594
627
  var compareLoose = (a, b) => compare(a, b, true);
595
628
  module.exports = compareLoose;
@@ -599,6 +632,7 @@ var require_compare_loose = __commonJS({
599
632
  // node_modules/semver/functions/compare-build.js
600
633
  var require_compare_build = __commonJS({
601
634
  "node_modules/semver/functions/compare-build.js"(exports, module) {
635
+ "use strict";
602
636
  var SemVer = require_semver();
603
637
  var compareBuild = (a, b, loose) => {
604
638
  const versionA = new SemVer(a, loose);
@@ -612,6 +646,7 @@ var require_compare_build = __commonJS({
612
646
  // node_modules/semver/functions/sort.js
613
647
  var require_sort = __commonJS({
614
648
  "node_modules/semver/functions/sort.js"(exports, module) {
649
+ "use strict";
615
650
  var compareBuild = require_compare_build();
616
651
  var sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
617
652
  module.exports = sort;
@@ -621,6 +656,7 @@ var require_sort = __commonJS({
621
656
  // node_modules/semver/functions/rsort.js
622
657
  var require_rsort = __commonJS({
623
658
  "node_modules/semver/functions/rsort.js"(exports, module) {
659
+ "use strict";
624
660
  var compareBuild = require_compare_build();
625
661
  var rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
626
662
  module.exports = rsort;
@@ -630,6 +666,7 @@ var require_rsort = __commonJS({
630
666
  // node_modules/semver/functions/gt.js
631
667
  var require_gt = __commonJS({
632
668
  "node_modules/semver/functions/gt.js"(exports, module) {
669
+ "use strict";
633
670
  var compare = require_compare();
634
671
  var gt = (a, b, loose) => compare(a, b, loose) > 0;
635
672
  module.exports = gt;
@@ -639,6 +676,7 @@ var require_gt = __commonJS({
639
676
  // node_modules/semver/functions/lt.js
640
677
  var require_lt = __commonJS({
641
678
  "node_modules/semver/functions/lt.js"(exports, module) {
679
+ "use strict";
642
680
  var compare = require_compare();
643
681
  var lt = (a, b, loose) => compare(a, b, loose) < 0;
644
682
  module.exports = lt;
@@ -648,6 +686,7 @@ var require_lt = __commonJS({
648
686
  // node_modules/semver/functions/eq.js
649
687
  var require_eq = __commonJS({
650
688
  "node_modules/semver/functions/eq.js"(exports, module) {
689
+ "use strict";
651
690
  var compare = require_compare();
652
691
  var eq = (a, b, loose) => compare(a, b, loose) === 0;
653
692
  module.exports = eq;
@@ -657,6 +696,7 @@ var require_eq = __commonJS({
657
696
  // node_modules/semver/functions/neq.js
658
697
  var require_neq = __commonJS({
659
698
  "node_modules/semver/functions/neq.js"(exports, module) {
699
+ "use strict";
660
700
  var compare = require_compare();
661
701
  var neq = (a, b, loose) => compare(a, b, loose) !== 0;
662
702
  module.exports = neq;
@@ -666,6 +706,7 @@ var require_neq = __commonJS({
666
706
  // node_modules/semver/functions/gte.js
667
707
  var require_gte = __commonJS({
668
708
  "node_modules/semver/functions/gte.js"(exports, module) {
709
+ "use strict";
669
710
  var compare = require_compare();
670
711
  var gte = (a, b, loose) => compare(a, b, loose) >= 0;
671
712
  module.exports = gte;
@@ -675,6 +716,7 @@ var require_gte = __commonJS({
675
716
  // node_modules/semver/functions/lte.js
676
717
  var require_lte = __commonJS({
677
718
  "node_modules/semver/functions/lte.js"(exports, module) {
719
+ "use strict";
678
720
  var compare = require_compare();
679
721
  var lte = (a, b, loose) => compare(a, b, loose) <= 0;
680
722
  module.exports = lte;
@@ -684,6 +726,7 @@ var require_lte = __commonJS({
684
726
  // node_modules/semver/functions/cmp.js
685
727
  var require_cmp = __commonJS({
686
728
  "node_modules/semver/functions/cmp.js"(exports, module) {
729
+ "use strict";
687
730
  var eq = require_eq();
688
731
  var neq = require_neq();
689
732
  var gt = require_gt();
@@ -733,6 +776,7 @@ var require_cmp = __commonJS({
733
776
  // node_modules/semver/functions/coerce.js
734
777
  var require_coerce = __commonJS({
735
778
  "node_modules/semver/functions/coerce.js"(exports, module) {
779
+ "use strict";
736
780
  var SemVer = require_semver();
737
781
  var parse = require_parse();
738
782
  var { safeRe: re, t } = require_re();
@@ -778,6 +822,7 @@ var require_coerce = __commonJS({
778
822
  // node_modules/semver/internal/lrucache.js
779
823
  var require_lrucache = __commonJS({
780
824
  "node_modules/semver/internal/lrucache.js"(exports, module) {
825
+ "use strict";
781
826
  var LRUCache = class {
782
827
  constructor() {
783
828
  this.max = 1e3;
@@ -815,6 +860,7 @@ var require_lrucache = __commonJS({
815
860
  // node_modules/semver/classes/range.js
816
861
  var require_range = __commonJS({
817
862
  "node_modules/semver/classes/range.js"(exports, module) {
863
+ "use strict";
818
864
  var SPACE_CHARACTERS = /\s+/g;
819
865
  var Range = class _Range {
820
866
  constructor(range, options) {
@@ -1190,6 +1236,7 @@ var require_range = __commonJS({
1190
1236
  // node_modules/semver/classes/comparator.js
1191
1237
  var require_comparator = __commonJS({
1192
1238
  "node_modules/semver/classes/comparator.js"(exports, module) {
1239
+ "use strict";
1193
1240
  var ANY = Symbol("SemVer ANY");
1194
1241
  var Comparator = class _Comparator {
1195
1242
  static get ANY() {
@@ -1302,6 +1349,7 @@ var require_comparator = __commonJS({
1302
1349
  // node_modules/semver/functions/satisfies.js
1303
1350
  var require_satisfies = __commonJS({
1304
1351
  "node_modules/semver/functions/satisfies.js"(exports, module) {
1352
+ "use strict";
1305
1353
  var Range = require_range();
1306
1354
  var satisfies = (version, range, options) => {
1307
1355
  try {
@@ -1318,6 +1366,7 @@ var require_satisfies = __commonJS({
1318
1366
  // node_modules/semver/ranges/to-comparators.js
1319
1367
  var require_to_comparators = __commonJS({
1320
1368
  "node_modules/semver/ranges/to-comparators.js"(exports, module) {
1369
+ "use strict";
1321
1370
  var Range = require_range();
1322
1371
  var toComparators = (range, options) => new Range(range, options).set.map((comp) => comp.map((c) => c.value).join(" ").trim().split(" "));
1323
1372
  module.exports = toComparators;
@@ -1327,6 +1376,7 @@ var require_to_comparators = __commonJS({
1327
1376
  // node_modules/semver/ranges/max-satisfying.js
1328
1377
  var require_max_satisfying = __commonJS({
1329
1378
  "node_modules/semver/ranges/max-satisfying.js"(exports, module) {
1379
+ "use strict";
1330
1380
  var SemVer = require_semver();
1331
1381
  var Range = require_range();
1332
1382
  var maxSatisfying = (versions, range, options) => {
@@ -1355,6 +1405,7 @@ var require_max_satisfying = __commonJS({
1355
1405
  // node_modules/semver/ranges/min-satisfying.js
1356
1406
  var require_min_satisfying = __commonJS({
1357
1407
  "node_modules/semver/ranges/min-satisfying.js"(exports, module) {
1408
+ "use strict";
1358
1409
  var SemVer = require_semver();
1359
1410
  var Range = require_range();
1360
1411
  var minSatisfying = (versions, range, options) => {
@@ -1383,6 +1434,7 @@ var require_min_satisfying = __commonJS({
1383
1434
  // node_modules/semver/ranges/min-version.js
1384
1435
  var require_min_version = __commonJS({
1385
1436
  "node_modules/semver/ranges/min-version.js"(exports, module) {
1437
+ "use strict";
1386
1438
  var SemVer = require_semver();
1387
1439
  var Range = require_range();
1388
1440
  var gt = require_gt();
@@ -1441,6 +1493,7 @@ var require_min_version = __commonJS({
1441
1493
  // node_modules/semver/ranges/valid.js
1442
1494
  var require_valid2 = __commonJS({
1443
1495
  "node_modules/semver/ranges/valid.js"(exports, module) {
1496
+ "use strict";
1444
1497
  var Range = require_range();
1445
1498
  var validRange = (range, options) => {
1446
1499
  try {
@@ -1456,6 +1509,7 @@ var require_valid2 = __commonJS({
1456
1509
  // node_modules/semver/ranges/outside.js
1457
1510
  var require_outside = __commonJS({
1458
1511
  "node_modules/semver/ranges/outside.js"(exports, module) {
1512
+ "use strict";
1459
1513
  var SemVer = require_semver();
1460
1514
  var Comparator = require_comparator();
1461
1515
  var { ANY } = Comparator;
@@ -1524,6 +1578,7 @@ var require_outside = __commonJS({
1524
1578
  // node_modules/semver/ranges/gtr.js
1525
1579
  var require_gtr = __commonJS({
1526
1580
  "node_modules/semver/ranges/gtr.js"(exports, module) {
1581
+ "use strict";
1527
1582
  var outside = require_outside();
1528
1583
  var gtr = (version, range, options) => outside(version, range, ">", options);
1529
1584
  module.exports = gtr;
@@ -1533,6 +1588,7 @@ var require_gtr = __commonJS({
1533
1588
  // node_modules/semver/ranges/ltr.js
1534
1589
  var require_ltr = __commonJS({
1535
1590
  "node_modules/semver/ranges/ltr.js"(exports, module) {
1591
+ "use strict";
1536
1592
  var outside = require_outside();
1537
1593
  var ltr = (version, range, options) => outside(version, range, "<", options);
1538
1594
  module.exports = ltr;
@@ -1542,6 +1598,7 @@ var require_ltr = __commonJS({
1542
1598
  // node_modules/semver/ranges/intersects.js
1543
1599
  var require_intersects = __commonJS({
1544
1600
  "node_modules/semver/ranges/intersects.js"(exports, module) {
1601
+ "use strict";
1545
1602
  var Range = require_range();
1546
1603
  var intersects = (r1, r2, options) => {
1547
1604
  r1 = new Range(r1, options);
@@ -1555,6 +1612,7 @@ var require_intersects = __commonJS({
1555
1612
  // node_modules/semver/ranges/simplify.js
1556
1613
  var require_simplify = __commonJS({
1557
1614
  "node_modules/semver/ranges/simplify.js"(exports, module) {
1615
+ "use strict";
1558
1616
  var satisfies = require_satisfies();
1559
1617
  var compare = require_compare();
1560
1618
  module.exports = (versions, range, options) => {
@@ -1604,6 +1662,7 @@ var require_simplify = __commonJS({
1604
1662
  // node_modules/semver/ranges/subset.js
1605
1663
  var require_subset = __commonJS({
1606
1664
  "node_modules/semver/ranges/subset.js"(exports, module) {
1665
+ "use strict";
1607
1666
  var Range = require_range();
1608
1667
  var Comparator = require_comparator();
1609
1668
  var { ANY } = Comparator;
@@ -1765,6 +1824,7 @@ var require_subset = __commonJS({
1765
1824
  // node_modules/semver/index.js
1766
1825
  var require_semver2 = __commonJS({
1767
1826
  "node_modules/semver/index.js"(exports, module) {
1827
+ "use strict";
1768
1828
  var internalRe = require_re();
1769
1829
  var constants = require_constants();
1770
1830
  var SemVer = require_semver();
@@ -86,7 +86,7 @@ var pipeline = (0, import_node_util.promisify)(import_node_stream.pipeline);
86
86
 
87
87
  // package.json
88
88
  var name = "@netlify/plugin-nextjs";
89
- var version = "5.11.0";
89
+ var version = "5.11.2";
90
90
 
91
91
  // src/run/handlers/tags-handler.cts
92
92
  var import_storage = require("../storage/storage.cjs");
package/dist/run/next.cjs CHANGED
@@ -488,8 +488,9 @@ __export(next_exports, {
488
488
  getMockedRequestHandler: () => getMockedRequestHandler
489
489
  });
490
490
  module.exports = __toCommonJS(next_exports);
491
- var import_promises = __toESM(require("fs/promises"));
492
- var import_path = require("path");
491
+ var import_node_async_hooks = require("node:async_hooks");
492
+ var import_promises = __toESM(require("node:fs/promises"));
493
+ var import_node_path = require("node:path");
493
494
  var import_fs_monkey = __toESM(require_lib());
494
495
  var import_request_context = require("./handlers/request-context.cjs");
495
496
  var import_tracer = require("./handlers/tracer.cjs");
@@ -540,6 +541,8 @@ ResponseCache.prototype.get = function get(...getArgs) {
540
541
  return originalGet.apply(this, getArgs);
541
542
  };
542
543
  async function getMockedRequestHandler(...args) {
544
+ const initContext = { initializingServer: true };
545
+ const initAsyncLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
543
546
  const tracer = (0, import_tracer.getTracer)();
544
547
  return tracer.withActiveSpan("mocked request handler", async () => {
545
548
  const ofs = { ...import_promises.default };
@@ -550,12 +553,13 @@ async function getMockedRequestHandler(...args) {
550
553
  } catch (error) {
551
554
  if (typeof path === "string" && path.endsWith(".html")) {
552
555
  const cacheStore = (0, import_storage.getMemoizedKeyValueStoreBackedByRegionalBlobStore)();
553
- const relPath = (0, import_path.relative)((0, import_path.resolve)(".next/server/pages"), path);
556
+ const relPath = (0, import_node_path.relative)((0, import_node_path.resolve)(".next/server/pages"), path);
554
557
  const file = await cacheStore.get(relPath, "staticHtml.get");
555
558
  if (file !== null) {
556
- if (!file.isFallback) {
559
+ if (file.isFullyStaticPage) {
557
560
  const requestContext = (0, import_request_context.getRequestContext)();
558
- if (requestContext) {
561
+ const { initializingServer } = initAsyncLocalStorage.getStore() ?? {};
562
+ if (!initializingServer && requestContext) {
559
563
  requestContext.usedFsReadForNonFallback = true;
560
564
  }
561
565
  }
@@ -572,7 +576,9 @@ async function getMockedRequestHandler(...args) {
572
576
  // eslint-disable-next-line n/global-require, @typescript-eslint/no-var-requires
573
577
  require("fs").promises
574
578
  );
575
- const requestHandlers = await getRequestHandlers(...args);
579
+ const requestHandlers = await initAsyncLocalStorage.run(initContext, async () => {
580
+ return await getRequestHandlers(...args);
581
+ });
576
582
  return Array.isArray(requestHandlers) ? requestHandlers[0] : requestHandlers.requestHandler;
577
583
  });
578
584
  }
@@ -28,7 +28,7 @@ var isTagManifest = (value) => {
28
28
  return typeof value === "object" && value !== null && "revalidatedAt" in value && typeof value.revalidatedAt === "number" && Object.keys(value).length === 1;
29
29
  };
30
30
  var isHtmlBlob = (value) => {
31
- return typeof value === "object" && value !== null && "html" in value && "isFallback" in value && typeof value.html === "string" && typeof value.isFallback === "boolean" && Object.keys(value).length === 2;
31
+ return typeof value === "object" && value !== null && "html" in value && "isFullyStaticPage" in value && typeof value.html === "string" && typeof value.isFullyStaticPage === "boolean" && Object.keys(value).length === 2;
32
32
  };
33
33
  // Annotate the CommonJS export names for ESM import in node:
34
34
  0 && (module.exports = {
@@ -67,6 +67,10 @@ export function mergeMiddlewareCookies(middlewareResponse: Response, lambdaReque
67
67
  const middlewareCookies = middlewareResponse.headers.get('x-middleware-set-cookie')
68
68
 
69
69
  if (middlewareCookies) {
70
+ // Next expects internal headers to be omitted when cookies are set by the middleware
71
+ // See: https://github.com/vercel/next.js/blob/005db43079c7b59fd8c2594e8362761dc4cb3211/test/e2e/app-dir/app-middleware/app-middleware.test.ts#L197-L207
72
+ middlewareResponse.headers.delete('x-middleware-set-cookie')
73
+
70
74
  // Targets commas that are not followed by whitespace
71
75
  // See: https://github.com/vercel/next.js/blob/e6145d3a37bb4c7b481fd58e05cdff9046ace8ad/packages/next/src/server/web/spec-extension/response.ts#L58-L66
72
76
  const regex = new RegExp(/,(?!\s)/)
@@ -163,25 +163,13 @@ export const buildResponse = async ({
163
163
 
164
164
  if (rewriteUrl.origin !== baseUrl.origin) {
165
165
  logger.withFields({ rewrite_url: rewrite }).debug('Rewriting to external url')
166
- let proxyRequest: Request
166
+ const proxyRequest = await cloneRequest(rewriteUrl, request)
167
167
 
168
168
  // Remove Netlify internal headers
169
- const headers = new Headers(
170
- [...request.headers.entries()].filter(([key]) => !key.startsWith('x-nf-')),
171
- )
172
- if (request.body && !request.bodyUsed) {
173
- // This is not ideal, but streaming to an external URL doesn't work
174
- const body = await request.arrayBuffer()
175
- proxyRequest = new Request(rewriteUrl, {
176
- headers,
177
- method: request.method,
178
- body,
179
- })
180
- } else {
181
- proxyRequest = new Request(rewriteUrl, {
182
- headers,
183
- method: request.method,
184
- })
169
+ for (const key of request.headers.keys()) {
170
+ if (key.startsWith('x-nf-')) {
171
+ proxyRequest.headers.delete(key)
172
+ }
185
173
  }
186
174
 
187
175
  return addMiddlewareHeaders(fetch(proxyRequest, { redirect: 'manual' }), edgeResponse)
@@ -207,7 +195,7 @@ export const buildResponse = async ({
207
195
  request.headers.set('x-middleware-rewrite', target)
208
196
 
209
197
  // coookies set in middleware need to be available during the lambda request
210
- const newRequest = new Request(target, request)
198
+ const newRequest = await cloneRequest(target, request)
211
199
  const newRequestCookies = mergeMiddlewareCookies(edgeResponse, newRequest)
212
200
  if (newRequestCookies) {
213
201
  newRequest.headers.set('Cookie', newRequestCookies)
@@ -241,7 +229,7 @@ export const buildResponse = async ({
241
229
  edgeResponse.headers.delete('x-middleware-next')
242
230
 
243
231
  // coookies set in middleware need to be available during the lambda request
244
- const newRequest = new Request(request)
232
+ const newRequest = await cloneRequest(request.url, request)
245
233
  const newRequestCookies = mergeMiddlewareCookies(edgeResponse, newRequest)
246
234
  if (newRequestCookies) {
247
235
  newRequest.headers.set('Cookie', newRequestCookies)
@@ -284,3 +272,13 @@ function normalizeLocalizedTarget({
284
272
  }
285
273
  return targetUrl.toString()
286
274
  }
275
+
276
+ async function cloneRequest(url, request: Request) {
277
+ // This is not ideal, but streaming to an external URL doesn't work
278
+ const body = request.body && !request.bodyUsed ? await request.arrayBuffer() : undefined
279
+ return new Request(url, {
280
+ headers: request.headers,
281
+ method: request.method,
282
+ body,
283
+ })
284
+ }
@@ -424,14 +424,24 @@ export interface MiddlewareMatcher {
424
424
  missing?: RouteHas[]
425
425
  }
426
426
 
427
+ const decodeMaybeEncodedPath = (path: string): string => {
428
+ try {
429
+ return decodeURIComponent(path)
430
+ } catch {
431
+ return path
432
+ }
433
+ }
434
+
427
435
  export function getMiddlewareRouteMatcher(matchers: MiddlewareMatcher[]): MiddlewareRouteMatch {
428
436
  return (
429
- pathname: string | null | undefined,
437
+ unsafePathname: string | null | undefined,
430
438
  req: Pick<Request, 'headers' | 'url'>,
431
439
  query: Params,
432
440
  ) => {
441
+ const pathname = decodeMaybeEncodedPath(unsafePathname ?? '')
442
+
433
443
  for (const matcher of matchers) {
434
- const routeMatch = new RegExp(matcher.regexp).exec(pathname!)
444
+ const routeMatch = new RegExp(matcher.regexp).exec(pathname)
435
445
  if (!routeMatch) {
436
446
  continue
437
447
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.11.0",
3
+ "version": "5.11.2",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",