@vercel/next 4.11.0 → 4.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +116 -27
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -11963,6 +11963,30 @@ async function getPageLambdaGroups({
11963
11963
  });
11964
11964
  opts = { ...vercelConfigOpts, ...opts };
11965
11965
  }
11966
+ const isGeneratedSteps = routeName.includes("api/generated/steps");
11967
+ const isGeneratedWorkflows = routeName.includes("api/generated/workflows");
11968
+ if (isGeneratedSteps || isGeneratedWorkflows) {
11969
+ const sourceFile = await getSourceFilePathFromPage({
11970
+ workPath: entryPath,
11971
+ page: normalizeSourceFilePageFromManifest(
11972
+ routeName,
11973
+ page,
11974
+ inversedAppPathManifest
11975
+ ),
11976
+ pageExtensions
11977
+ });
11978
+ const config2 = JSON.parse(
11979
+ await import_fs_extra3.default.readFile(
11980
+ import_path2.default.join(entryPath, import_path2.default.dirname(sourceFile), "../config.json"),
11981
+ "utf8"
11982
+ ).catch(() => "{}")
11983
+ );
11984
+ if (isGeneratedSteps && config2.steps) {
11985
+ Object.assign(opts, config2.steps);
11986
+ } else if (isGeneratedWorkflows && config2.workflows) {
11987
+ Object.assign(opts, config2.workflows);
11988
+ }
11989
+ }
11966
11990
  let matchingGroup = experimentalAllowBundling ? void 0 : groups.find((group) => {
11967
11991
  const matches = group.maxDuration === opts.maxDuration && group.memory === opts.memory && group.isPrerenders === isPrerenderRoute && group.isExperimentalPPR === isExperimentalPPR && JSON.stringify(group.experimentalTriggers) === JSON.stringify(opts.experimentalTriggers);
11968
11992
  if (matches) {
@@ -13448,6 +13472,55 @@ function getHTMLPostponedState({
13448
13472
  }
13449
13473
  return meta.postponed;
13450
13474
  }
13475
+ async function getServerActionMetaRoutes(distDir) {
13476
+ const manifestPath = import_path2.default.join(
13477
+ distDir,
13478
+ "server",
13479
+ "server-reference-manifest.json"
13480
+ );
13481
+ try {
13482
+ const manifestContent = await import_fs_extra3.default.readFile(manifestPath, "utf8");
13483
+ const manifest = JSON.parse(manifestContent);
13484
+ const routes = [];
13485
+ for (const runtimeType of ["node", "edge"]) {
13486
+ const runtime = manifest[runtimeType];
13487
+ if (!runtime)
13488
+ continue;
13489
+ for (const [id, entry] of Object.entries(runtime)) {
13490
+ if (!entry.filename || !entry.exportedName)
13491
+ continue;
13492
+ let exportedName = entry.exportedName;
13493
+ if (exportedName === "$$RSC_SERVER_ACTION_0") {
13494
+ exportedName = "anonymous_fn";
13495
+ }
13496
+ const route = {
13497
+ src: "/(.*)",
13498
+ has: [
13499
+ {
13500
+ type: "header",
13501
+ key: "next-action",
13502
+ value: id
13503
+ }
13504
+ ],
13505
+ transforms: [
13506
+ {
13507
+ type: "request.headers",
13508
+ op: "append",
13509
+ target: {
13510
+ key: "x-server-action-name"
13511
+ },
13512
+ args: `${entry.filename}#${exportedName}`
13513
+ }
13514
+ ]
13515
+ };
13516
+ routes.push(route);
13517
+ }
13518
+ }
13519
+ return routes;
13520
+ } catch (error) {
13521
+ return [];
13522
+ }
13523
+ }
13451
13524
 
13452
13525
  // src/create-serverless-config.ts
13453
13526
  function getCustomData(importName, target) {
@@ -13960,7 +14033,6 @@ async function serverBuild({
13960
14033
  const lambdas = {};
13961
14034
  const prerenders = {};
13962
14035
  const lambdaPageKeys = Object.keys(lambdaPages);
13963
- const internalPages = [...INTERNAL_PAGES];
13964
14036
  const pageBuildTraces = await (0, import_build_utils2.glob)("**/*.js.nft.json", pagesDir);
13965
14037
  const isEmptyAllowQueryForPrendered = import_semver3.default.gte(
13966
14038
  nextVersion,
@@ -14092,6 +14164,9 @@ async function serverBuild({
14092
14164
  const lstatResults = {};
14093
14165
  const nonLambdaSsgPages = /* @__PURE__ */ new Set();
14094
14166
  const static404Pages = new Set(static404Page ? [static404Page] : []);
14167
+ const internalPages = [...INTERNAL_PAGES].filter((page) => {
14168
+ return lambdaPages[page];
14169
+ });
14095
14170
  Object.keys(prerenderManifest.staticRoutes).forEach((route) => {
14096
14171
  const result = onPrerenderRouteInitial(
14097
14172
  prerenderManifest,
@@ -14448,7 +14523,7 @@ ${JSON.stringify(
14448
14523
  for (const page of mergedPageKeys) {
14449
14524
  const originalPagePath = getOriginalPagePath(page);
14450
14525
  const pageBuildTrace = getBuildTraceFile(originalPagePath);
14451
- let fileList;
14526
+ let fileList = [];
14452
14527
  let reasons;
14453
14528
  if (pageBuildTrace) {
14454
14529
  const { files } = JSON.parse(
@@ -14486,16 +14561,10 @@ ${JSON.stringify(
14486
14561
  });
14487
14562
  reasons = /* @__PURE__ */ new Map();
14488
14563
  } else {
14564
+ const lambdaPage = lambdaPages[page];
14489
14565
  fileList = Array.from(
14490
- parentFilesMap?.get(
14491
- import_path4.default.relative(baseDir, lambdaPages[page].fsPath)
14492
- ) || []
14566
+ parentFilesMap?.get(import_path4.default.relative(baseDir, lambdaPage.fsPath)) || []
14493
14567
  );
14494
- if (!fileList) {
14495
- throw new Error(
14496
- `Invariant: Failed to trace ${page}, missing fileList`
14497
- );
14498
- }
14499
14568
  reasons = traceResult?.reasons || /* @__PURE__ */ new Map();
14500
14569
  }
14501
14570
  const tracedFiles = Object.fromEntries(
@@ -15194,6 +15263,9 @@ ${JSON.stringify(
15194
15263
  const shouldHandleSegmentToRsc = Boolean(
15195
15264
  isAppClientSegmentCacheEnabled && rscPrefetchHeader && prefetchSegmentHeader && prefetchSegmentDirSuffix && prefetchSegmentSuffix
15196
15265
  );
15266
+ const serverActionMetaRoutes = await getServerActionMetaRoutes(
15267
+ import_path4.default.join(entryPath, outputDirectory)
15268
+ );
15197
15269
  return {
15198
15270
  wildcard: wildcardConfig,
15199
15271
  images: getImagesConfig(imagesManifest),
@@ -15212,7 +15284,18 @@ ${JSON.stringify(
15212
15284
  ...nodeMiddleware?.lambdas,
15213
15285
  ...isNextDataServerResolving ? {
15214
15286
  __next_data_catchall: nextDataCatchallOutput
15215
- } : {}
15287
+ } : {},
15288
+ // When bots crawl a site, they may render the page after awhile (e.g. re-sync),
15289
+ // and the sub-assets may not be available then. In this case, the link to
15290
+ // static assets could be not found, and return a 404 HTML. This behavior can
15291
+ // bait the bots as if they found 404 pages. In Next.js it is handled on the
15292
+ // server to return a plain text "Not Found". However, as we handle the "_next/static/"
15293
+ // routes in Vercel CLI, the Next.js behavior is overwritten. Therefore, create a
15294
+ // ".txt" file with "Not Found" content and rewrite any not found static assets to it.
15295
+ [import_path4.default.posix.join(".", entryDirectory, "_next/static/not-found.txt")]: new import_build_utils2.FileBlob({
15296
+ data: "Not Found",
15297
+ contentType: "text/plain"
15298
+ })
15216
15299
  },
15217
15300
  routes: [
15218
15301
  /*
@@ -15339,6 +15422,7 @@ ${JSON.stringify(
15339
15422
  ] : [],
15340
15423
  ...headers,
15341
15424
  ...redirects,
15425
+ ...serverActionMetaRoutes,
15342
15426
  // middleware comes directly after redirects but before
15343
15427
  // beforeFiles rewrites as middleware is not a "file" route
15344
15428
  ...routesManifest?.skipMiddlewareUrlNormalize ? denormalizeNextDataRoute(true) : [],
@@ -15616,14 +15700,17 @@ ${JSON.stringify(
15616
15700
  // We need to make sure to 404 for /_next after handle: miss since
15617
15701
  // handle: miss is called before rewrites and to prevent rewriting /_next
15618
15702
  {
15619
- src: import_path4.default.posix.join(
15703
+ src: import_path4.default.posix.join("/", entryDirectory, "_next/static/.+"),
15704
+ status: 404,
15705
+ check: true,
15706
+ dest: import_path4.default.posix.join(
15620
15707
  "/",
15621
15708
  entryDirectory,
15622
- "_next/static/(?:[^/]+/pages|pages|chunks|runtime|css|image|media)/.+"
15709
+ "_next/static/not-found.txt"
15623
15710
  ),
15624
- status: 404,
15625
- check: true,
15626
- dest: "$0"
15711
+ headers: {
15712
+ "content-type": "text/plain; charset=utf-8"
15713
+ }
15627
15714
  },
15628
15715
  // remove locale prefixes to check public files and
15629
15716
  // to allow checking non-prefixed lambda outputs
@@ -16580,14 +16667,17 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16580
16667
  // /_next
16581
16668
  { handle: "miss" },
16582
16669
  {
16583
- src: import_path5.default.posix.join(
16670
+ src: import_path5.default.posix.join("/", entryDirectory, "_next/static/.+"),
16671
+ status: 404,
16672
+ check: true,
16673
+ dest: import_path5.default.posix.join(
16584
16674
  "/",
16585
16675
  entryDirectory,
16586
- "_next/static/(?:[^/]+/pages|pages|chunks|runtime|css|image|media)/.+"
16676
+ "_next/static/not-found.txt"
16587
16677
  ),
16588
- status: 404,
16589
- check: true,
16590
- dest: "$0"
16678
+ headers: {
16679
+ "content-type": "text/plain; charset=utf-8"
16680
+ }
16591
16681
  },
16592
16682
  // Dynamic routes
16593
16683
  // TODO: do we want to do this?: ...dynamicRoutes,
@@ -17828,14 +17918,13 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
17828
17918
  // handle: miss is called before rewrites and to prevent rewriting /_next
17829
17919
  { handle: "miss" },
17830
17920
  {
17831
- src: import_path5.default.join(
17832
- "/",
17833
- entryDirectory,
17834
- "_next/static/(?:[^/]+/pages|pages|chunks|runtime|css|image|media)/.+"
17835
- ),
17921
+ src: import_path5.default.join("/", entryDirectory, "_next/static/.+"),
17836
17922
  status: 404,
17837
17923
  check: true,
17838
- dest: "$0"
17924
+ dest: import_path5.default.join("/", entryDirectory, "_next/static/not-found.txt"),
17925
+ headers: {
17926
+ "content-type": "text/plain; charset=utf-8"
17927
+ }
17839
17928
  },
17840
17929
  // remove locale prefixes to check public files
17841
17930
  ...i18n ? [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.11.0",
3
+ "version": "4.11.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -30,7 +30,7 @@
30
30
  "@types/semver": "6.0.0",
31
31
  "@types/text-table": "0.2.1",
32
32
  "@types/webpack-sources": "3.2.0",
33
- "@vercel/build-utils": "11.0.0",
33
+ "@vercel/build-utils": "11.0.1",
34
34
  "@vercel/routing-utils": "5.1.1",
35
35
  "async-sema": "3.0.1",
36
36
  "buffer-crc32": "0.2.13",