@vercel/next 3.1.21 → 3.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +102 -42
  2. package/dist/utils.js +80 -35
  3. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -12114,7 +12114,7 @@ async function analyze(id, code, job) {
12114
12114
  .filter(name => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
12115
12115
  !excludeAssetFiles.has(path_1.default.basename(name)) &&
12116
12116
  !name.endsWith('/'))
12117
- .forEach(file => assets.add(file));
12117
+ .forEach(file => deps.add(file));
12118
12118
  });
12119
12119
  }
12120
12120
  async function processRequireArg(expression, isImport = false) {
@@ -12147,7 +12147,7 @@ async function analyze(id, code, job) {
12147
12147
  let scope = rollup_pluginutils_1.attachScopes(ast, 'scope');
12148
12148
  if (isAst(ast)) {
12149
12149
  wrappers_1.handleWrappers(ast);
12150
- await special_cases_1.default({ id, ast, emitAsset: path => assets.add(path), emitAssetDirectory, job });
12150
+ await special_cases_1.default({ id, ast, emitDependency: path => deps.add(path), emitAsset: path => assets.add(path), emitAssetDirectory, job });
12151
12151
  }
12152
12152
  async function backtrack(parent, context) {
12153
12153
  // computing a static expression outward
@@ -12234,6 +12234,18 @@ async function analyze(id, code, job) {
12234
12234
  await processRequireArg(node.arguments[0]);
12235
12235
  return;
12236
12236
  }
12237
+ else if ((!isESM || job.mixedModules) &&
12238
+ node.callee.type === 'MemberExpression' &&
12239
+ node.callee.object.type === 'Identifier' &&
12240
+ node.callee.object.name === 'require' &&
12241
+ knownBindings.require.shadowDepth === 0 &&
12242
+ node.callee.property.type === 'Identifier' &&
12243
+ !node.callee.computed &&
12244
+ node.callee.property.name === 'resolve' &&
12245
+ node.arguments.length) {
12246
+ await processRequireArg(node.arguments[0]);
12247
+ return;
12248
+ }
12237
12249
  const calleeValue = job.analysis.evaluatePureExpressions && await computePureStaticValue(node.callee, false);
12238
12250
  // if we have a direct pure static function,
12239
12251
  // and that function has a [TRIGGER] symbol -> trigger asset emission from it
@@ -12933,6 +12945,9 @@ class Job {
12933
12945
  const source = await this.readFile(path);
12934
12946
  if (source === null)
12935
12947
  throw new Error('File ' + path + ' does not exist.');
12948
+ // analyze should not have any side-effects e.g. calling `job.emitFile`
12949
+ // directly as this will not be included in the cachedAnalysis and won't
12950
+ // be emit for successive runs that leverage the cache
12936
12951
  analyzeResult = await analyze_1.default(path, source.toString(), this);
12937
12952
  this.analysisCache.set(path, analyzeResult);
12938
12953
  }
@@ -13777,18 +13792,18 @@ const specialCases = {
13777
13792
  emitAsset(path_1.resolve(path_1.dirname(id), '../data/geo.dat'));
13778
13793
  }
13779
13794
  },
13780
- 'pixelmatch'({ id, emitAsset }) {
13795
+ 'pixelmatch'({ id, emitDependency }) {
13781
13796
  if (id.endsWith('pixelmatch/index.js')) {
13782
- emitAsset(path_1.resolve(path_1.dirname(id), 'bin/pixelmatch'));
13797
+ emitDependency(path_1.resolve(path_1.dirname(id), 'bin/pixelmatch'));
13783
13798
  }
13784
13799
  }
13785
13800
  };
13786
- async function handleSpecialCases({ id, ast, emitAsset, emitAssetDirectory, job }) {
13801
+ async function handleSpecialCases({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job }) {
13787
13802
  const pkgName = get_package_base_1.getPackageName(id);
13788
13803
  const specialCase = specialCases[pkgName || ''];
13789
13804
  id = id.replace(/\\/g, '/');
13790
13805
  if (specialCase)
13791
- await specialCase({ id, ast, emitAsset, emitAssetDirectory, job });
13806
+ await specialCase({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job });
13792
13807
  }
13793
13808
  exports.default = handleSpecialCases;
13794
13809
  ;
@@ -44457,7 +44472,7 @@ async function getServerlessPages(params) {
44457
44472
  const normalizedAppPaths = {};
44458
44473
  if (params.appPathRoutesManifest) {
44459
44474
  for (const [entry, normalizedEntry] of Object.entries(params.appPathRoutesManifest)) {
44460
- const normalizedPath = `${path_1.default.join('.', normalizedEntry)}.js`;
44475
+ const normalizedPath = `${path_1.default.join('.', normalizedEntry === '/' ? '/index' : normalizedEntry)}.js`;
44461
44476
  const globPath = `${path_1.default.join('.', entry)}.js`;
44462
44477
  if (appPaths[globPath]) {
44463
44478
  normalizedAppPaths[normalizedPath] = appPaths[globPath];
@@ -46006,7 +46021,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
46006
46021
  return (mod && mod.__esModule) ? mod : { "default": mod };
46007
46022
  };
46008
46023
  Object.defineProperty(exports, "__esModule", ({ value: true }));
46009
- 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;
46024
+ exports.upgradeMiddlewareManifest = 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;
46010
46025
  const build_utils_1 = __webpack_require__(3445);
46011
46026
  const async_sema_1 = __webpack_require__(7916);
46012
46027
  const buffer_crc32_1 = __importDefault(__webpack_require__(360));
@@ -47423,7 +47438,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
47423
47438
  }),
47424
47439
  });
47425
47440
  })(),
47426
- routeSrc: getRouteSrc(edgeFunction, routesManifest),
47441
+ routeMatchers: getRouteMatchers(edgeFunction, routesManifest),
47427
47442
  };
47428
47443
  }
47429
47444
  catch (e) {
@@ -47446,26 +47461,29 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
47446
47461
  if (worker.type === 'function') {
47447
47462
  continue;
47448
47463
  }
47449
- const route = {
47450
- continue: true,
47451
- src: worker.routeSrc,
47452
- missing: [
47453
- {
47454
- type: 'header',
47455
- key: 'x-prerender-revalidate',
47456
- value: prerenderBypassToken,
47457
- },
47458
- ],
47459
- };
47460
- route.middlewarePath = shortPath;
47461
- if (isCorrectMiddlewareOrder) {
47462
- route.override = true;
47463
- }
47464
- if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
47465
- source.dynamicRouteMap.set(worker.page, route);
47466
- }
47467
- else {
47468
- source.staticRoutes.push(route);
47464
+ for (const matcher of worker.routeMatchers) {
47465
+ const route = {
47466
+ continue: true,
47467
+ src: matcher.regexp,
47468
+ has: matcher.has,
47469
+ missing: [
47470
+ {
47471
+ type: 'header',
47472
+ key: 'x-prerender-revalidate',
47473
+ value: prerenderBypassToken,
47474
+ },
47475
+ ],
47476
+ };
47477
+ route.middlewarePath = shortPath;
47478
+ if (isCorrectMiddlewareOrder) {
47479
+ route.override = true;
47480
+ }
47481
+ if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
47482
+ source.dynamicRouteMap.set(worker.page, route);
47483
+ }
47484
+ else {
47485
+ source.staticRoutes.push(route);
47486
+ }
47469
47487
  }
47470
47488
  }
47471
47489
  return source;
@@ -47491,28 +47509,70 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
47491
47509
  if (!hasManifest) {
47492
47510
  return;
47493
47511
  }
47494
- return fs_extra_1.default.readJSON(middlewareManifestPath);
47512
+ const manifest = (await fs_extra_1.default.readJSON(middlewareManifestPath));
47513
+ return manifest.version === 1
47514
+ ? upgradeMiddlewareManifest(manifest)
47515
+ : manifest;
47495
47516
  }
47496
47517
  exports.getMiddlewareManifest = getMiddlewareManifest;
47518
+ function upgradeMiddlewareManifest(v1) {
47519
+ function updateInfo(v1Info) {
47520
+ const { regexp, ...rest } = v1Info;
47521
+ return {
47522
+ ...rest,
47523
+ matchers: [{ regexp }],
47524
+ };
47525
+ }
47526
+ const middleware = Object.fromEntries(Object.entries(v1.middleware).map(([p, info]) => [p, updateInfo(info)]));
47527
+ const functions = v1.functions
47528
+ ? Object.fromEntries(Object.entries(v1.functions).map(([p, info]) => [p, updateInfo(info)]))
47529
+ : undefined;
47530
+ return {
47531
+ ...v1,
47532
+ version: 2,
47533
+ middleware,
47534
+ functions,
47535
+ };
47536
+ }
47537
+ exports.upgradeMiddlewareManifest = upgradeMiddlewareManifest;
47497
47538
  /**
47498
47539
  * For an object containing middleware info and a routes manifest this will
47499
47540
  * generate a string with the route that will activate the middleware on
47500
47541
  * Vercel Proxy.
47501
47542
  *
47502
- * @param param0 The middleware info including regexp and page.
47543
+ * @param param0 The middleware info including matchers and page.
47503
47544
  * @param param1 The routes manifest
47504
- * @returns A regexp string for the middleware route.
47545
+ * @returns matchers for the middleware route.
47505
47546
  */
47506
- function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
47507
- if (page === '/') {
47508
- return regexp.replace('_next', `${basePath?.substring(1) ? `${basePath?.substring(1)}/` : ''}_next`);
47509
- }
47510
- const locale = i18n?.locales.length
47511
- ? `(?:/(${i18n.locales
47512
- .map(locale => (0, escape_string_regexp_1.default)(locale))
47513
- .join('|')}))?`
47514
- : '';
47515
- return `(?:^${basePath}${locale}${regexp.substring(1)})`;
47547
+ function getRouteMatchers(info, { basePath = '', i18n }) {
47548
+ function getRegexp(regexp) {
47549
+ if (info.page === '/') {
47550
+ return regexp;
47551
+ }
47552
+ const locale = i18n?.locales.length
47553
+ ? `(?:/(${i18n.locales
47554
+ .map(locale => (0, escape_string_regexp_1.default)(locale))
47555
+ .join('|')}))?`
47556
+ : '';
47557
+ return `(?:^${basePath}${locale}${regexp.substring(1)})`;
47558
+ }
47559
+ function normalizeHas(has) {
47560
+ return has.map(v => v.type === 'header'
47561
+ ? {
47562
+ ...v,
47563
+ key: v.key.toLowerCase(),
47564
+ }
47565
+ : v);
47566
+ }
47567
+ return info.matchers.map(matcher => {
47568
+ const m = {
47569
+ regexp: getRegexp(matcher.regexp),
47570
+ };
47571
+ if (matcher.has) {
47572
+ m.has = normalizeHas(matcher.has);
47573
+ }
47574
+ return m;
47575
+ });
47516
47576
  }
47517
47577
  /**
47518
47578
  * Makes the sources more human-readable in the source map
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.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;
25
+ exports.upgradeMiddlewareManifest = 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"));
@@ -1439,7 +1439,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1439
1439
  }),
1440
1440
  });
1441
1441
  })(),
1442
- routeSrc: getRouteSrc(edgeFunction, routesManifest),
1442
+ routeMatchers: getRouteMatchers(edgeFunction, routesManifest),
1443
1443
  };
1444
1444
  }
1445
1445
  catch (e) {
@@ -1462,26 +1462,29 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1462
1462
  if (worker.type === 'function') {
1463
1463
  continue;
1464
1464
  }
1465
- const route = {
1466
- continue: true,
1467
- src: worker.routeSrc,
1468
- missing: [
1469
- {
1470
- type: 'header',
1471
- key: 'x-prerender-revalidate',
1472
- value: prerenderBypassToken,
1473
- },
1474
- ],
1475
- };
1476
- route.middlewarePath = shortPath;
1477
- if (isCorrectMiddlewareOrder) {
1478
- route.override = true;
1479
- }
1480
- if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
1481
- source.dynamicRouteMap.set(worker.page, route);
1482
- }
1483
- else {
1484
- source.staticRoutes.push(route);
1465
+ for (const matcher of worker.routeMatchers) {
1466
+ const route = {
1467
+ continue: true,
1468
+ src: matcher.regexp,
1469
+ has: matcher.has,
1470
+ missing: [
1471
+ {
1472
+ type: 'header',
1473
+ key: 'x-prerender-revalidate',
1474
+ value: prerenderBypassToken,
1475
+ },
1476
+ ],
1477
+ };
1478
+ route.middlewarePath = shortPath;
1479
+ if (isCorrectMiddlewareOrder) {
1480
+ route.override = true;
1481
+ }
1482
+ if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
1483
+ source.dynamicRouteMap.set(worker.page, route);
1484
+ }
1485
+ else {
1486
+ source.staticRoutes.push(route);
1487
+ }
1485
1488
  }
1486
1489
  }
1487
1490
  return source;
@@ -1507,28 +1510,70 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
1507
1510
  if (!hasManifest) {
1508
1511
  return;
1509
1512
  }
1510
- return fs_extra_1.default.readJSON(middlewareManifestPath);
1513
+ const manifest = (await fs_extra_1.default.readJSON(middlewareManifestPath));
1514
+ return manifest.version === 1
1515
+ ? upgradeMiddlewareManifest(manifest)
1516
+ : manifest;
1511
1517
  }
1512
1518
  exports.getMiddlewareManifest = getMiddlewareManifest;
1519
+ function upgradeMiddlewareManifest(v1) {
1520
+ function updateInfo(v1Info) {
1521
+ const { regexp, ...rest } = v1Info;
1522
+ return {
1523
+ ...rest,
1524
+ matchers: [{ regexp }],
1525
+ };
1526
+ }
1527
+ const middleware = Object.fromEntries(Object.entries(v1.middleware).map(([p, info]) => [p, updateInfo(info)]));
1528
+ const functions = v1.functions
1529
+ ? Object.fromEntries(Object.entries(v1.functions).map(([p, info]) => [p, updateInfo(info)]))
1530
+ : undefined;
1531
+ return {
1532
+ ...v1,
1533
+ version: 2,
1534
+ middleware,
1535
+ functions,
1536
+ };
1537
+ }
1538
+ exports.upgradeMiddlewareManifest = upgradeMiddlewareManifest;
1513
1539
  /**
1514
1540
  * For an object containing middleware info and a routes manifest this will
1515
1541
  * generate a string with the route that will activate the middleware on
1516
1542
  * Vercel Proxy.
1517
1543
  *
1518
- * @param param0 The middleware info including regexp and page.
1544
+ * @param param0 The middleware info including matchers and page.
1519
1545
  * @param param1 The routes manifest
1520
- * @returns A regexp string for the middleware route.
1546
+ * @returns matchers for the middleware route.
1521
1547
  */
1522
- function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
1523
- if (page === '/') {
1524
- return regexp.replace('_next', `${basePath?.substring(1) ? `${basePath?.substring(1)}/` : ''}_next`);
1525
- }
1526
- const locale = i18n?.locales.length
1527
- ? `(?:/(${i18n.locales
1528
- .map(locale => (0, escape_string_regexp_1.default)(locale))
1529
- .join('|')}))?`
1530
- : '';
1531
- return `(?:^${basePath}${locale}${regexp.substring(1)})`;
1548
+ function getRouteMatchers(info, { basePath = '', i18n }) {
1549
+ function getRegexp(regexp) {
1550
+ if (info.page === '/') {
1551
+ return regexp;
1552
+ }
1553
+ const locale = i18n?.locales.length
1554
+ ? `(?:/(${i18n.locales
1555
+ .map(locale => (0, escape_string_regexp_1.default)(locale))
1556
+ .join('|')}))?`
1557
+ : '';
1558
+ return `(?:^${basePath}${locale}${regexp.substring(1)})`;
1559
+ }
1560
+ function normalizeHas(has) {
1561
+ return has.map(v => v.type === 'header'
1562
+ ? {
1563
+ ...v,
1564
+ key: v.key.toLowerCase(),
1565
+ }
1566
+ : v);
1567
+ }
1568
+ return info.matchers.map(matcher => {
1569
+ const m = {
1570
+ regexp: getRegexp(matcher.regexp),
1571
+ };
1572
+ if (matcher.has) {
1573
+ m.has = normalizeHas(matcher.has);
1574
+ }
1575
+ return m;
1576
+ });
1532
1577
  }
1533
1578
  /**
1534
1579
  * Makes the sources more human-readable in the source map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.1.21",
3
+ "version": "3.1.24",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -44,8 +44,8 @@
44
44
  "@types/semver": "6.0.0",
45
45
  "@types/text-table": "0.2.1",
46
46
  "@types/webpack-sources": "3.2.0",
47
- "@vercel/build-utils": "5.3.2",
48
- "@vercel/nft": "0.21.0",
47
+ "@vercel/build-utils": "5.4.1",
48
+ "@vercel/nft": "0.22.1",
49
49
  "@vercel/routing-utils": "2.0.2",
50
50
  "async-sema": "3.0.1",
51
51
  "buffer-crc32": "0.2.13",
@@ -69,5 +69,5 @@
69
69
  "typescript": "4.5.2",
70
70
  "webpack-sources": "3.2.3"
71
71
  },
72
- "gitHead": "6700630feb23bdb4e94ea727911a9e10aa546361"
72
+ "gitHead": "3ff93279cd53bbfb620d27c93ca59d28917a5598"
73
73
  }