@vercel/next 3.0.0 → 3.0.1

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.
@@ -1,23 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT = void 0;
3
+ exports.EDGE_FUNCTION_SIZE_LIMIT = void 0;
4
4
  const KIB = 1024;
5
5
  const MIB = 1024 * KIB;
6
6
  /**
7
- * The limit after compression. it has to be kibibyte instead of kilobyte
8
- * See https://github.com/cloudflare/wrangler/blob/8907b12add3d70ee21ac597b69cd66f6807571f4/src/wranglerjs/output.rs#L44
7
+ * The maximum size of a *compressed* edge function.
9
8
  */
10
- const EDGE_FUNCTION_SCRIPT_SIZE_LIMIT = MIB;
11
- /**
12
- * This safety buffer must cover the size of our whole runtime layer compressed
13
- * plus some extra space to allow it to grow in the future. At the time of
14
- * writing this comment the compressed size size is ~7KiB so 20KiB should
15
- * be more than enough.
16
- */
17
- const EDGE_FUNCTION_SCRIPT_SIZE_BUFFER = 20 * KIB;
18
- /**
19
- * The max size we allow for compressed user code is the compressed script
20
- * limit minus the compressed safety buffer. We must check this limit after
21
- * compressing the user code.
22
- */
23
- exports.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT = EDGE_FUNCTION_SCRIPT_SIZE_LIMIT - EDGE_FUNCTION_SCRIPT_SIZE_BUFFER;
9
+ exports.EDGE_FUNCTION_SIZE_LIMIT = MIB;
@@ -66,7 +66,7 @@ function getWasmImportStatements(wasm = []) {
66
66
  }
67
67
  async function validateScript(content) {
68
68
  const gzipped = await gzip(content);
69
- if (gzipped.length > constants_1.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT) {
70
- throw new Error(`Exceeds maximum edge function script size: ${(0, pretty_bytes_1.default)(gzipped.length)} / ${(0, pretty_bytes_1.default)(constants_1.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT)}`);
69
+ if (gzipped.length > constants_1.EDGE_FUNCTION_SIZE_LIMIT) {
70
+ throw new Error(`Exceeds maximum edge function script size: ${(0, pretty_bytes_1.default)(gzipped.length)} / ${(0, pretty_bytes_1.default)(constants_1.EDGE_FUNCTION_SIZE_LIMIT)}`);
71
71
  }
72
72
  }
package/dist/index.js CHANGED
@@ -15907,214 +15907,6 @@ exports.getRoot = function getRoot(file) {
15907
15907
  };
15908
15908
 
15909
15909
 
15910
- /***/ }),
15911
-
15912
- /***/ 3197:
15913
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
15914
-
15915
- var concatMap = __webpack_require__(4527);
15916
- var balanced = __webpack_require__(3353);
15917
-
15918
- module.exports = expandTop;
15919
-
15920
- var escSlash = '\0SLASH'+Math.random()+'\0';
15921
- var escOpen = '\0OPEN'+Math.random()+'\0';
15922
- var escClose = '\0CLOSE'+Math.random()+'\0';
15923
- var escComma = '\0COMMA'+Math.random()+'\0';
15924
- var escPeriod = '\0PERIOD'+Math.random()+'\0';
15925
-
15926
- function numeric(str) {
15927
- return parseInt(str, 10) == str
15928
- ? parseInt(str, 10)
15929
- : str.charCodeAt(0);
15930
- }
15931
-
15932
- function escapeBraces(str) {
15933
- return str.split('\\\\').join(escSlash)
15934
- .split('\\{').join(escOpen)
15935
- .split('\\}').join(escClose)
15936
- .split('\\,').join(escComma)
15937
- .split('\\.').join(escPeriod);
15938
- }
15939
-
15940
- function unescapeBraces(str) {
15941
- return str.split(escSlash).join('\\')
15942
- .split(escOpen).join('{')
15943
- .split(escClose).join('}')
15944
- .split(escComma).join(',')
15945
- .split(escPeriod).join('.');
15946
- }
15947
-
15948
-
15949
- // Basically just str.split(","), but handling cases
15950
- // where we have nested braced sections, which should be
15951
- // treated as individual members, like {a,{b,c},d}
15952
- function parseCommaParts(str) {
15953
- if (!str)
15954
- return [''];
15955
-
15956
- var parts = [];
15957
- var m = balanced('{', '}', str);
15958
-
15959
- if (!m)
15960
- return str.split(',');
15961
-
15962
- var pre = m.pre;
15963
- var body = m.body;
15964
- var post = m.post;
15965
- var p = pre.split(',');
15966
-
15967
- p[p.length-1] += '{' + body + '}';
15968
- var postParts = parseCommaParts(post);
15969
- if (post.length) {
15970
- p[p.length-1] += postParts.shift();
15971
- p.push.apply(p, postParts);
15972
- }
15973
-
15974
- parts.push.apply(parts, p);
15975
-
15976
- return parts;
15977
- }
15978
-
15979
- function expandTop(str) {
15980
- if (!str)
15981
- return [];
15982
-
15983
- // I don't know why Bash 4.3 does this, but it does.
15984
- // Anything starting with {} will have the first two bytes preserved
15985
- // but *only* at the top level, so {},a}b will not expand to anything,
15986
- // but a{},b}c will be expanded to [a}c,abc].
15987
- // One could argue that this is a bug in Bash, but since the goal of
15988
- // this module is to match Bash's rules, we escape a leading {}
15989
- if (str.substr(0, 2) === '{}') {
15990
- str = '\\{\\}' + str.substr(2);
15991
- }
15992
-
15993
- return expand(escapeBraces(str), true).map(unescapeBraces);
15994
- }
15995
-
15996
- function identity(e) {
15997
- return e;
15998
- }
15999
-
16000
- function embrace(str) {
16001
- return '{' + str + '}';
16002
- }
16003
- function isPadded(el) {
16004
- return /^-?0\d/.test(el);
16005
- }
16006
-
16007
- function lte(i, y) {
16008
- return i <= y;
16009
- }
16010
- function gte(i, y) {
16011
- return i >= y;
16012
- }
16013
-
16014
- function expand(str, isTop) {
16015
- var expansions = [];
16016
-
16017
- var m = balanced('{', '}', str);
16018
- if (!m || /\$$/.test(m.pre)) return [str];
16019
-
16020
- var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
16021
- var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
16022
- var isSequence = isNumericSequence || isAlphaSequence;
16023
- var isOptions = m.body.indexOf(',') >= 0;
16024
- if (!isSequence && !isOptions) {
16025
- // {a},b}
16026
- if (m.post.match(/,.*\}/)) {
16027
- str = m.pre + '{' + m.body + escClose + m.post;
16028
- return expand(str);
16029
- }
16030
- return [str];
16031
- }
16032
-
16033
- var n;
16034
- if (isSequence) {
16035
- n = m.body.split(/\.\./);
16036
- } else {
16037
- n = parseCommaParts(m.body);
16038
- if (n.length === 1) {
16039
- // x{{a,b}}y ==> x{a}y x{b}y
16040
- n = expand(n[0], false).map(embrace);
16041
- if (n.length === 1) {
16042
- var post = m.post.length
16043
- ? expand(m.post, false)
16044
- : [''];
16045
- return post.map(function(p) {
16046
- return m.pre + n[0] + p;
16047
- });
16048
- }
16049
- }
16050
- }
16051
-
16052
- // at this point, n is the parts, and we know it's not a comma set
16053
- // with a single entry.
16054
-
16055
- // no need to expand pre, since it is guaranteed to be free of brace-sets
16056
- var pre = m.pre;
16057
- var post = m.post.length
16058
- ? expand(m.post, false)
16059
- : [''];
16060
-
16061
- var N;
16062
-
16063
- if (isSequence) {
16064
- var x = numeric(n[0]);
16065
- var y = numeric(n[1]);
16066
- var width = Math.max(n[0].length, n[1].length)
16067
- var incr = n.length == 3
16068
- ? Math.abs(numeric(n[2]))
16069
- : 1;
16070
- var test = lte;
16071
- var reverse = y < x;
16072
- if (reverse) {
16073
- incr *= -1;
16074
- test = gte;
16075
- }
16076
- var pad = n.some(isPadded);
16077
-
16078
- N = [];
16079
-
16080
- for (var i = x; test(i, y); i += incr) {
16081
- var c;
16082
- if (isAlphaSequence) {
16083
- c = String.fromCharCode(i);
16084
- if (c === '\\')
16085
- c = '';
16086
- } else {
16087
- c = String(i);
16088
- if (pad) {
16089
- var need = width - c.length;
16090
- if (need > 0) {
16091
- var z = new Array(need + 1).join('0');
16092
- if (i < 0)
16093
- c = '-' + z + c.slice(1);
16094
- else
16095
- c = z + c;
16096
- }
16097
- }
16098
- }
16099
- N.push(c);
16100
- }
16101
- } else {
16102
- N = concatMap(n, function(el) { return expand(el, false) });
16103
- }
16104
-
16105
- for (var j = 0; j < N.length; j++) {
16106
- for (var k = 0; k < post.length; k++) {
16107
- var expansion = pre + N[j] + post[k];
16108
- if (!isTop || isSequence || expansion)
16109
- expansions.push(expansion);
16110
- }
16111
- }
16112
-
16113
- return expansions;
16114
- }
16115
-
16116
-
16117
-
16118
15910
  /***/ }),
16119
15911
 
16120
15912
  /***/ 538:
@@ -22714,7 +22506,7 @@ try {
22714
22506
  } catch (er) {}
22715
22507
 
22716
22508
  var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {}
22717
- var expand = __webpack_require__(3197)
22509
+ var expand = __webpack_require__(1561)
22718
22510
 
22719
22511
  var plTypes = {
22720
22512
  '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
@@ -23630,6 +23422,214 @@ function regExpEscape (s) {
23630
23422
  }
23631
23423
 
23632
23424
 
23425
+ /***/ }),
23426
+
23427
+ /***/ 1561:
23428
+ /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
23429
+
23430
+ var concatMap = __webpack_require__(4527);
23431
+ var balanced = __webpack_require__(3353);
23432
+
23433
+ module.exports = expandTop;
23434
+
23435
+ var escSlash = '\0SLASH'+Math.random()+'\0';
23436
+ var escOpen = '\0OPEN'+Math.random()+'\0';
23437
+ var escClose = '\0CLOSE'+Math.random()+'\0';
23438
+ var escComma = '\0COMMA'+Math.random()+'\0';
23439
+ var escPeriod = '\0PERIOD'+Math.random()+'\0';
23440
+
23441
+ function numeric(str) {
23442
+ return parseInt(str, 10) == str
23443
+ ? parseInt(str, 10)
23444
+ : str.charCodeAt(0);
23445
+ }
23446
+
23447
+ function escapeBraces(str) {
23448
+ return str.split('\\\\').join(escSlash)
23449
+ .split('\\{').join(escOpen)
23450
+ .split('\\}').join(escClose)
23451
+ .split('\\,').join(escComma)
23452
+ .split('\\.').join(escPeriod);
23453
+ }
23454
+
23455
+ function unescapeBraces(str) {
23456
+ return str.split(escSlash).join('\\')
23457
+ .split(escOpen).join('{')
23458
+ .split(escClose).join('}')
23459
+ .split(escComma).join(',')
23460
+ .split(escPeriod).join('.');
23461
+ }
23462
+
23463
+
23464
+ // Basically just str.split(","), but handling cases
23465
+ // where we have nested braced sections, which should be
23466
+ // treated as individual members, like {a,{b,c},d}
23467
+ function parseCommaParts(str) {
23468
+ if (!str)
23469
+ return [''];
23470
+
23471
+ var parts = [];
23472
+ var m = balanced('{', '}', str);
23473
+
23474
+ if (!m)
23475
+ return str.split(',');
23476
+
23477
+ var pre = m.pre;
23478
+ var body = m.body;
23479
+ var post = m.post;
23480
+ var p = pre.split(',');
23481
+
23482
+ p[p.length-1] += '{' + body + '}';
23483
+ var postParts = parseCommaParts(post);
23484
+ if (post.length) {
23485
+ p[p.length-1] += postParts.shift();
23486
+ p.push.apply(p, postParts);
23487
+ }
23488
+
23489
+ parts.push.apply(parts, p);
23490
+
23491
+ return parts;
23492
+ }
23493
+
23494
+ function expandTop(str) {
23495
+ if (!str)
23496
+ return [];
23497
+
23498
+ // I don't know why Bash 4.3 does this, but it does.
23499
+ // Anything starting with {} will have the first two bytes preserved
23500
+ // but *only* at the top level, so {},a}b will not expand to anything,
23501
+ // but a{},b}c will be expanded to [a}c,abc].
23502
+ // One could argue that this is a bug in Bash, but since the goal of
23503
+ // this module is to match Bash's rules, we escape a leading {}
23504
+ if (str.substr(0, 2) === '{}') {
23505
+ str = '\\{\\}' + str.substr(2);
23506
+ }
23507
+
23508
+ return expand(escapeBraces(str), true).map(unescapeBraces);
23509
+ }
23510
+
23511
+ function identity(e) {
23512
+ return e;
23513
+ }
23514
+
23515
+ function embrace(str) {
23516
+ return '{' + str + '}';
23517
+ }
23518
+ function isPadded(el) {
23519
+ return /^-?0\d/.test(el);
23520
+ }
23521
+
23522
+ function lte(i, y) {
23523
+ return i <= y;
23524
+ }
23525
+ function gte(i, y) {
23526
+ return i >= y;
23527
+ }
23528
+
23529
+ function expand(str, isTop) {
23530
+ var expansions = [];
23531
+
23532
+ var m = balanced('{', '}', str);
23533
+ if (!m || /\$$/.test(m.pre)) return [str];
23534
+
23535
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
23536
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
23537
+ var isSequence = isNumericSequence || isAlphaSequence;
23538
+ var isOptions = m.body.indexOf(',') >= 0;
23539
+ if (!isSequence && !isOptions) {
23540
+ // {a},b}
23541
+ if (m.post.match(/,.*\}/)) {
23542
+ str = m.pre + '{' + m.body + escClose + m.post;
23543
+ return expand(str);
23544
+ }
23545
+ return [str];
23546
+ }
23547
+
23548
+ var n;
23549
+ if (isSequence) {
23550
+ n = m.body.split(/\.\./);
23551
+ } else {
23552
+ n = parseCommaParts(m.body);
23553
+ if (n.length === 1) {
23554
+ // x{{a,b}}y ==> x{a}y x{b}y
23555
+ n = expand(n[0], false).map(embrace);
23556
+ if (n.length === 1) {
23557
+ var post = m.post.length
23558
+ ? expand(m.post, false)
23559
+ : [''];
23560
+ return post.map(function(p) {
23561
+ return m.pre + n[0] + p;
23562
+ });
23563
+ }
23564
+ }
23565
+ }
23566
+
23567
+ // at this point, n is the parts, and we know it's not a comma set
23568
+ // with a single entry.
23569
+
23570
+ // no need to expand pre, since it is guaranteed to be free of brace-sets
23571
+ var pre = m.pre;
23572
+ var post = m.post.length
23573
+ ? expand(m.post, false)
23574
+ : [''];
23575
+
23576
+ var N;
23577
+
23578
+ if (isSequence) {
23579
+ var x = numeric(n[0]);
23580
+ var y = numeric(n[1]);
23581
+ var width = Math.max(n[0].length, n[1].length)
23582
+ var incr = n.length == 3
23583
+ ? Math.abs(numeric(n[2]))
23584
+ : 1;
23585
+ var test = lte;
23586
+ var reverse = y < x;
23587
+ if (reverse) {
23588
+ incr *= -1;
23589
+ test = gte;
23590
+ }
23591
+ var pad = n.some(isPadded);
23592
+
23593
+ N = [];
23594
+
23595
+ for (var i = x; test(i, y); i += incr) {
23596
+ var c;
23597
+ if (isAlphaSequence) {
23598
+ c = String.fromCharCode(i);
23599
+ if (c === '\\')
23600
+ c = '';
23601
+ } else {
23602
+ c = String(i);
23603
+ if (pad) {
23604
+ var need = width - c.length;
23605
+ if (need > 0) {
23606
+ var z = new Array(need + 1).join('0');
23607
+ if (i < 0)
23608
+ c = '-' + z + c.slice(1);
23609
+ else
23610
+ c = z + c;
23611
+ }
23612
+ }
23613
+ }
23614
+ N.push(c);
23615
+ }
23616
+ } else {
23617
+ N = concatMap(n, function(el) { return expand(el, false) });
23618
+ }
23619
+
23620
+ for (var j = 0; j < N.length; j++) {
23621
+ for (var k = 0; k < post.length; k++) {
23622
+ var expansion = pre + N[j] + post[k];
23623
+ if (!isTop || isSequence || expansion)
23624
+ expansions.push(expansion);
23625
+ }
23626
+ }
23627
+
23628
+ return expansions;
23629
+ }
23630
+
23631
+
23632
+
23633
23633
  /***/ }),
23634
23634
 
23635
23635
  /***/ 3277:
@@ -44725,27 +44725,13 @@ exports.default = createServerlessConfig;
44725
44725
  "use strict";
44726
44726
 
44727
44727
  Object.defineProperty(exports, "__esModule", ({ value: true }));
44728
- exports.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT = void 0;
44728
+ exports.EDGE_FUNCTION_SIZE_LIMIT = void 0;
44729
44729
  const KIB = 1024;
44730
44730
  const MIB = 1024 * KIB;
44731
44731
  /**
44732
- * The limit after compression. it has to be kibibyte instead of kilobyte
44733
- * See https://github.com/cloudflare/wrangler/blob/8907b12add3d70ee21ac597b69cd66f6807571f4/src/wranglerjs/output.rs#L44
44734
- */
44735
- const EDGE_FUNCTION_SCRIPT_SIZE_LIMIT = MIB;
44736
- /**
44737
- * This safety buffer must cover the size of our whole runtime layer compressed
44738
- * plus some extra space to allow it to grow in the future. At the time of
44739
- * writing this comment the compressed size size is ~7KiB so 20KiB should
44740
- * be more than enough.
44732
+ * The maximum size of a *compressed* edge function.
44741
44733
  */
44742
- const EDGE_FUNCTION_SCRIPT_SIZE_BUFFER = 20 * KIB;
44743
- /**
44744
- * The max size we allow for compressed user code is the compressed script
44745
- * limit minus the compressed safety buffer. We must check this limit after
44746
- * compressing the user code.
44747
- */
44748
- exports.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT = EDGE_FUNCTION_SCRIPT_SIZE_LIMIT - EDGE_FUNCTION_SCRIPT_SIZE_BUFFER;
44734
+ exports.EDGE_FUNCTION_SIZE_LIMIT = MIB;
44749
44735
 
44750
44736
 
44751
44737
  /***/ }),
@@ -44822,8 +44808,8 @@ function getWasmImportStatements(wasm = []) {
44822
44808
  }
44823
44809
  async function validateScript(content) {
44824
44810
  const gzipped = await gzip(content);
44825
- if (gzipped.length > constants_1.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT) {
44826
- throw new Error(`Exceeds maximum edge function script size: ${(0, pretty_bytes_1.default)(gzipped.length)} / ${(0, pretty_bytes_1.default)(constants_1.EDGE_FUNCTION_USER_SCRIPT_SIZE_LIMIT)}`);
44811
+ if (gzipped.length > constants_1.EDGE_FUNCTION_SIZE_LIMIT) {
44812
+ throw new Error(`Exceeds maximum edge function script size: ${(0, pretty_bytes_1.default)(gzipped.length)} / ${(0, pretty_bytes_1.default)(constants_1.EDGE_FUNCTION_SIZE_LIMIT)}`);
44827
44813
  }
44828
44814
  }
44829
44815
 
@@ -44857,6 +44843,7 @@ const create_serverless_config_1 = __importDefault(__webpack_require__(9892));
44857
44843
  const legacy_versions_1 = __importDefault(__webpack_require__(1207));
44858
44844
  const server_build_1 = __webpack_require__(5840);
44859
44845
  const utils_1 = __webpack_require__(4411);
44846
+ const assert_1 = __importDefault(__webpack_require__(2357));
44860
44847
  exports.version = 2;
44861
44848
  exports.htmlContentType = 'text/html; charset=utf-8';
44862
44849
  const SERVER_BUILD_MINIMUM_NEXT_VERSION = 'v10.0.9-canary.4';
@@ -45532,7 +45519,11 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
45532
45519
  nextFiles['next.config.js'] = filesAfterBuild['next.config.js'];
45533
45520
  }
45534
45521
  const pagesDir = path_1.default.join(entryPath, outputDirectory, 'server', 'static', buildId, 'pages');
45535
- const pages = await (0, build_utils_1.glob)('**/!(_middleware).js', pagesDir);
45522
+ const pages = await getServerlessPages({
45523
+ pagesDir,
45524
+ entryPath,
45525
+ outputDirectory,
45526
+ });
45536
45527
  const launcherPath = path_1.default.join(__dirname, 'legacy-launcher.js');
45537
45528
  const launcherData = await (0, fs_extra_1.readFile)(launcherPath, 'utf8');
45538
45529
  await Promise.all(Object.keys(pages).map(async (page) => {
@@ -45578,7 +45569,11 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
45578
45569
  else {
45579
45570
  (0, build_utils_1.debug)('Preparing serverless function files...');
45580
45571
  const pagesDir = path_1.default.join(entryPath, outputDirectory, isServerMode ? 'server' : 'serverless', 'pages');
45581
- const pages = await (0, build_utils_1.glob)('**/!(_middleware).js', pagesDir);
45572
+ const pages = await getServerlessPages({
45573
+ pagesDir,
45574
+ entryPath,
45575
+ outputDirectory,
45576
+ });
45582
45577
  const isApiPage = (page) => page
45583
45578
  .replace(/\\/g, '/')
45584
45579
  .match(/(serverless|server)\/pages\/api(\/|\.js$)/);
@@ -46637,6 +46632,23 @@ const prepareCache = async ({ workPath, repoRootPath, entrypoint, config = {}, }
46637
46632
  return cache;
46638
46633
  };
46639
46634
  exports.prepareCache = prepareCache;
46635
+ async function getServerlessPages(params) {
46636
+ const [pages, middlewareManifest] = await Promise.all([
46637
+ (0, build_utils_1.glob)('**/!(_middleware).js', params.pagesDir),
46638
+ (0, utils_1.getMiddlewareManifest)(params.entryPath, params.outputDirectory),
46639
+ ]);
46640
+ // Edge Functions do not consider as Serverless Functions
46641
+ for (const edgeFunctionFile of Object.keys(middlewareManifest?.functions ?? {})) {
46642
+ // `getStaticProps` are expecting `Prerender` output which is a Serverless function
46643
+ // and not an Edge Function. Therefore we only remove API endpoints for now, as they
46644
+ // don't have `getStaticProps`.
46645
+ //
46646
+ // Context: https://github.com/vercel/vercel/pull/7905#discussion_r890213165
46647
+ (0, assert_1.default)(edgeFunctionFile.startsWith('/api/'), `Only API endpoints are currently supported for Edge endpoints.`);
46648
+ delete pages[edgeFunctionFile.slice(1) + '.js'];
46649
+ }
46650
+ return pages;
46651
+ }
46640
46652
 
46641
46653
 
46642
46654
  /***/ }),
@@ -47010,6 +47022,7 @@ const escape_string_regexp_1 = __importDefault(__webpack_require__(1426));
47010
47022
  const pretty_bytes_1 = __importDefault(__webpack_require__(539));
47011
47023
  // related PR: https://github.com/vercel/next.js/pull/30046
47012
47024
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
47025
+ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
47013
47026
  async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
47014
47027
  const lambdas = {};
47015
47028
  const prerenders = {};
@@ -47017,6 +47030,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47017
47030
  const internalPages = ['_app.js', '_error.js', '_document.js'];
47018
47031
  const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
47019
47032
  const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
47033
+ const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
47020
47034
  let hasStatic500 = !!staticPages[path_1.default.join(entryDirectory, '500')];
47021
47035
  if (lambdaPageKeys.length === 0) {
47022
47036
  throw new build_utils_1.NowBuildError({
@@ -47406,6 +47420,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47406
47420
  entryPath,
47407
47421
  outputDirectory,
47408
47422
  routesManifest,
47423
+ isCorrectMiddlewareOrder,
47409
47424
  });
47410
47425
  const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes));
47411
47426
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
@@ -47572,6 +47587,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47572
47587
  ...notFoundPreviewRoutes,
47573
47588
  ...headers,
47574
47589
  ...redirects,
47590
+ // middleware comes directly after redirects but before
47591
+ // beforeFiles rewrites as middleware is not a "file" route
47592
+ ...(isCorrectMiddlewareOrder ? middleware.staticRoutes : []),
47575
47593
  ...beforeFilesRewrites,
47576
47594
  // Make sure to 404 for the /404 path itself
47577
47595
  ...(i18n
@@ -47611,7 +47629,10 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47611
47629
  continue: true,
47612
47630
  },
47613
47631
  ]),
47614
- ...middleware.staticRoutes,
47632
+ // while middleware was in beta the order came right before
47633
+ // handle: 'filesystem' we maintain this for older versions
47634
+ // to prevent a local/deploy mismatch
47635
+ ...(!isCorrectMiddlewareOrder ? middleware.staticRoutes : []),
47615
47636
  // Next.js page lambdas, `static/` folder, reserved assets, and `public/`
47616
47637
  // folder
47617
47638
  { handle: 'filesystem' },
@@ -47911,7 +47932,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
47911
47932
  return (mod && mod.__esModule) ? mod : { "default": mod };
47912
47933
  };
47913
47934
  Object.defineProperty(exports, "__esModule", ({ value: true }));
47914
- exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = void 0;
47935
+ exports.getMiddlewareManifest = exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = void 0;
47915
47936
  const build_utils_1 = __webpack_require__(3445);
47916
47937
  const async_sema_1 = __webpack_require__(7916);
47917
47938
  const buffer_crc32_1 = __importDefault(__webpack_require__(360));
@@ -49223,27 +49244,43 @@ async function getPrivateOutputs(dir, entries) {
49223
49244
  return { files, routes };
49224
49245
  }
49225
49246
  exports.getPrivateOutputs = getPrivateOutputs;
49226
- async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, }) {
49247
+ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, }) {
49227
49248
  const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
49228
- if (middlewareManifest && middlewareManifest?.sortedMiddleware.length > 0) {
49229
- const workerConfigs = await Promise.all(middlewareManifest.sortedMiddleware.map(async (key) => {
49230
- const middleware = middlewareManifest.middleware[key];
49249
+ const sortedFunctions = [
49250
+ ...(!middlewareManifest
49251
+ ? []
49252
+ : middlewareManifest.sortedMiddleware.map(key => ({
49253
+ key,
49254
+ edgeFunction: middlewareManifest?.middleware[key],
49255
+ type: 'middleware',
49256
+ }))),
49257
+ ...Object.entries(middlewareManifest?.functions ?? {}).map(([key, edgeFunction]) => {
49258
+ return {
49259
+ key,
49260
+ edgeFunction,
49261
+ type: 'function',
49262
+ };
49263
+ }),
49264
+ ];
49265
+ if (middlewareManifest && sortedFunctions.length > 0) {
49266
+ const workerConfigs = await Promise.all(sortedFunctions.map(async ({ key, edgeFunction, type }) => {
49231
49267
  try {
49232
- const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(middleware.files, {
49233
- name: middleware.name,
49268
+ const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(edgeFunction.files, {
49269
+ name: edgeFunction.name,
49234
49270
  staticRoutes: routesManifest.staticRoutes,
49235
49271
  dynamicRoutes: routesManifest.dynamicRoutes.filter(r => !('isMiddleware' in r)),
49236
49272
  nextConfig: {
49237
49273
  basePath: routesManifest.basePath,
49238
49274
  i18n: routesManifest.i18n,
49239
49275
  },
49240
- }, path_1.default.resolve(entryPath, outputDirectory), middleware.wasm);
49276
+ }, path_1.default.resolve(entryPath, outputDirectory), edgeFunction.wasm);
49241
49277
  return {
49242
- page: middlewareManifest.middleware[key].page,
49278
+ type,
49279
+ page: edgeFunction.page,
49243
49280
  edgeFunction: (() => {
49244
49281
  const { source, map } = wrappedModuleSource.sourceAndMap();
49245
49282
  const transformedMap = (0, sourcemapped_1.stringifySourceMap)(transformSourceMap(map));
49246
- const wasmFiles = (middleware.wasm ?? []).reduce((acc, { filePath, name }) => {
49283
+ const wasmFiles = (edgeFunction.wasm ?? []).reduce((acc, { filePath, name }) => {
49247
49284
  const fullFilePath = path_1.default.join(entryPath, outputDirectory, filePath);
49248
49285
  acc[`wasm/${name}.wasm`] = new build_utils_1.FileFsRef({
49249
49286
  mode: 0o644,
@@ -49254,7 +49291,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
49254
49291
  }, {});
49255
49292
  return new build_utils_1.EdgeFunction({
49256
49293
  deploymentTarget: 'v8-worker',
49257
- name: middleware.name,
49294
+ name: edgeFunction.name,
49258
49295
  files: {
49259
49296
  'index.js': new build_utils_1.FileBlob({
49260
49297
  data: source,
@@ -49271,10 +49308,10 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
49271
49308
  ...wasmFiles,
49272
49309
  },
49273
49310
  entrypoint: 'index.js',
49274
- envVarsInUse: middleware.env,
49311
+ envVarsInUse: edgeFunction.env,
49275
49312
  });
49276
49313
  })(),
49277
- routeSrc: getRouteSrc(middlewareManifest.middleware[key], routesManifest),
49314
+ routeSrc: getRouteSrc(edgeFunction, routesManifest),
49278
49315
  };
49279
49316
  }
49280
49317
  catch (e) {
@@ -49289,14 +49326,22 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
49289
49326
  };
49290
49327
  for (const worker of workerConfigs.values()) {
49291
49328
  const edgeFile = worker.edgeFunction.name;
49292
- worker.edgeFunction.name = edgeFile.replace(/^pages\//, '');
49293
- source.edgeFunctions[edgeFile] = worker.edgeFunction;
49329
+ const shortPath = edgeFile.replace(/^pages\//, '');
49330
+ worker.edgeFunction.name = shortPath;
49331
+ source.edgeFunctions[shortPath] = worker.edgeFunction;
49294
49332
  const route = {
49295
49333
  continue: true,
49296
- override: true,
49297
- middlewarePath: edgeFile,
49298
49334
  src: worker.routeSrc,
49299
49335
  };
49336
+ if (worker.type === 'function') {
49337
+ route.dest = shortPath;
49338
+ }
49339
+ else {
49340
+ route.middlewarePath = shortPath;
49341
+ if (isCorrectMiddlewareOrder) {
49342
+ route.override = true;
49343
+ }
49344
+ }
49300
49345
  if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
49301
49346
  source.dynamicRouteMap.set(worker.page, route);
49302
49347
  }
@@ -49329,6 +49374,7 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
49329
49374
  }
49330
49375
  return fs_extra_1.default.readJSON(middlewareManifestPath);
49331
49376
  }
49377
+ exports.getMiddlewareManifest = getMiddlewareManifest;
49332
49378
  /**
49333
49379
  * For an object containing middleware info and a routes manifest this will
49334
49380
  * generate a string with the route that will activate the middleware on
@@ -17,6 +17,7 @@ const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
17
17
  const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
18
18
  // related PR: https://github.com/vercel/next.js/pull/30046
19
19
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
20
+ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
20
21
  async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
21
22
  const lambdas = {};
22
23
  const prerenders = {};
@@ -24,6 +25,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
24
25
  const internalPages = ['_app.js', '_error.js', '_document.js'];
25
26
  const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
26
27
  const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
28
+ const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
27
29
  let hasStatic500 = !!staticPages[path_1.default.join(entryDirectory, '500')];
28
30
  if (lambdaPageKeys.length === 0) {
29
31
  throw new build_utils_1.NowBuildError({
@@ -413,6 +415,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
413
415
  entryPath,
414
416
  outputDirectory,
415
417
  routesManifest,
418
+ isCorrectMiddlewareOrder,
416
419
  });
417
420
  const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes));
418
421
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
@@ -579,6 +582,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
579
582
  ...notFoundPreviewRoutes,
580
583
  ...headers,
581
584
  ...redirects,
585
+ // middleware comes directly after redirects but before
586
+ // beforeFiles rewrites as middleware is not a "file" route
587
+ ...(isCorrectMiddlewareOrder ? middleware.staticRoutes : []),
582
588
  ...beforeFilesRewrites,
583
589
  // Make sure to 404 for the /404 path itself
584
590
  ...(i18n
@@ -618,7 +624,10 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
618
624
  continue: true,
619
625
  },
620
626
  ]),
621
- ...middleware.staticRoutes,
627
+ // while middleware was in beta the order came right before
628
+ // handle: 'filesystem' we maintain this for older versions
629
+ // to prevent a local/deploy mismatch
630
+ ...(!isCorrectMiddlewareOrder ? middleware.staticRoutes : []),
622
631
  // Next.js page lambdas, `static/` folder, reserved assets, and `public/`
623
632
  // folder
624
633
  { handle: 'filesystem' },
package/dist/utils.js CHANGED
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = void 0;
25
+ exports.getMiddlewareManifest = exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = void 0;
26
26
  const build_utils_1 = require("@vercel/build-utils");
27
27
  const async_sema_1 = require("async-sema");
28
28
  const buffer_crc32_1 = __importDefault(require("buffer-crc32"));
@@ -1334,27 +1334,43 @@ async function getPrivateOutputs(dir, entries) {
1334
1334
  return { files, routes };
1335
1335
  }
1336
1336
  exports.getPrivateOutputs = getPrivateOutputs;
1337
- async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, }) {
1337
+ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, }) {
1338
1338
  const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
1339
- if (middlewareManifest && middlewareManifest?.sortedMiddleware.length > 0) {
1340
- const workerConfigs = await Promise.all(middlewareManifest.sortedMiddleware.map(async (key) => {
1341
- const middleware = middlewareManifest.middleware[key];
1339
+ const sortedFunctions = [
1340
+ ...(!middlewareManifest
1341
+ ? []
1342
+ : middlewareManifest.sortedMiddleware.map(key => ({
1343
+ key,
1344
+ edgeFunction: middlewareManifest?.middleware[key],
1345
+ type: 'middleware',
1346
+ }))),
1347
+ ...Object.entries(middlewareManifest?.functions ?? {}).map(([key, edgeFunction]) => {
1348
+ return {
1349
+ key,
1350
+ edgeFunction,
1351
+ type: 'function',
1352
+ };
1353
+ }),
1354
+ ];
1355
+ if (middlewareManifest && sortedFunctions.length > 0) {
1356
+ const workerConfigs = await Promise.all(sortedFunctions.map(async ({ key, edgeFunction, type }) => {
1342
1357
  try {
1343
- const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(middleware.files, {
1344
- name: middleware.name,
1358
+ const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(edgeFunction.files, {
1359
+ name: edgeFunction.name,
1345
1360
  staticRoutes: routesManifest.staticRoutes,
1346
1361
  dynamicRoutes: routesManifest.dynamicRoutes.filter(r => !('isMiddleware' in r)),
1347
1362
  nextConfig: {
1348
1363
  basePath: routesManifest.basePath,
1349
1364
  i18n: routesManifest.i18n,
1350
1365
  },
1351
- }, path_1.default.resolve(entryPath, outputDirectory), middleware.wasm);
1366
+ }, path_1.default.resolve(entryPath, outputDirectory), edgeFunction.wasm);
1352
1367
  return {
1353
- page: middlewareManifest.middleware[key].page,
1368
+ type,
1369
+ page: edgeFunction.page,
1354
1370
  edgeFunction: (() => {
1355
1371
  const { source, map } = wrappedModuleSource.sourceAndMap();
1356
1372
  const transformedMap = (0, sourcemapped_1.stringifySourceMap)(transformSourceMap(map));
1357
- const wasmFiles = (middleware.wasm ?? []).reduce((acc, { filePath, name }) => {
1373
+ const wasmFiles = (edgeFunction.wasm ?? []).reduce((acc, { filePath, name }) => {
1358
1374
  const fullFilePath = path_1.default.join(entryPath, outputDirectory, filePath);
1359
1375
  acc[`wasm/${name}.wasm`] = new build_utils_1.FileFsRef({
1360
1376
  mode: 0o644,
@@ -1365,7 +1381,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1365
1381
  }, {});
1366
1382
  return new build_utils_1.EdgeFunction({
1367
1383
  deploymentTarget: 'v8-worker',
1368
- name: middleware.name,
1384
+ name: edgeFunction.name,
1369
1385
  files: {
1370
1386
  'index.js': new build_utils_1.FileBlob({
1371
1387
  data: source,
@@ -1382,10 +1398,10 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1382
1398
  ...wasmFiles,
1383
1399
  },
1384
1400
  entrypoint: 'index.js',
1385
- envVarsInUse: middleware.env,
1401
+ envVarsInUse: edgeFunction.env,
1386
1402
  });
1387
1403
  })(),
1388
- routeSrc: getRouteSrc(middlewareManifest.middleware[key], routesManifest),
1404
+ routeSrc: getRouteSrc(edgeFunction, routesManifest),
1389
1405
  };
1390
1406
  }
1391
1407
  catch (e) {
@@ -1400,14 +1416,22 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1400
1416
  };
1401
1417
  for (const worker of workerConfigs.values()) {
1402
1418
  const edgeFile = worker.edgeFunction.name;
1403
- worker.edgeFunction.name = edgeFile.replace(/^pages\//, '');
1404
- source.edgeFunctions[edgeFile] = worker.edgeFunction;
1419
+ const shortPath = edgeFile.replace(/^pages\//, '');
1420
+ worker.edgeFunction.name = shortPath;
1421
+ source.edgeFunctions[shortPath] = worker.edgeFunction;
1405
1422
  const route = {
1406
1423
  continue: true,
1407
- override: true,
1408
- middlewarePath: edgeFile,
1409
1424
  src: worker.routeSrc,
1410
1425
  };
1426
+ if (worker.type === 'function') {
1427
+ route.dest = shortPath;
1428
+ }
1429
+ else {
1430
+ route.middlewarePath = shortPath;
1431
+ if (isCorrectMiddlewareOrder) {
1432
+ route.override = true;
1433
+ }
1434
+ }
1411
1435
  if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
1412
1436
  source.dynamicRouteMap.set(worker.page, route);
1413
1437
  }
@@ -1440,6 +1464,7 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
1440
1464
  }
1441
1465
  return fs_extra_1.default.readJSON(middlewareManifestPath);
1442
1466
  }
1467
+ exports.getMiddlewareManifest = getMiddlewareManifest;
1443
1468
  /**
1444
1469
  * For an object containing middleware info and a routes manifest this will
1445
1470
  * generate a string with the route that will activate the middleware on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -45,7 +45,7 @@
45
45
  "@types/semver": "6.0.0",
46
46
  "@types/text-table": "0.2.1",
47
47
  "@types/webpack-sources": "3.2.0",
48
- "@vercel/build-utils": "4.0.0",
48
+ "@vercel/build-utils": "4.1.0",
49
49
  "@vercel/nft": "0.19.1",
50
50
  "@vercel/routing-utils": "1.13.4",
51
51
  "async-sema": "3.0.1",
@@ -70,5 +70,5 @@
70
70
  "typescript": "4.5.2",
71
71
  "webpack-sources": "3.2.3"
72
72
  },
73
- "gitHead": "de0d2fba0b32588726a2799015eaff4e6bb65ffb"
73
+ "gitHead": "0c7b54edad6adf48505abf2cbec01691b85963bb"
74
74
  }