@vercel/next 4.15.14 → 4.15.16

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.
@@ -0,0 +1,323 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var node_handler_exports = {};
20
+ __export(node_handler_exports, {
21
+ getHandlerSource: () => getHandlerSource
22
+ });
23
+ module.exports = __toCommonJS(node_handler_exports);
24
+ const getHandlerSource = (ctx) => `
25
+ process.env.NODE_ENV = 'production';
26
+ require('next/dist/server/node-environment');
27
+ require('next/dist/server/node-polyfill-crypto');
28
+
29
+ try {
30
+ // this can fail to install if styled-jsx is not discoverable
31
+ // but this is tolerable as the require-hook is handling edge cases
32
+ require('next/dist/server/require-hook');
33
+ } catch (_) {}
34
+
35
+ process.chdir(__dirname);
36
+
37
+ const _n_handler = (${ctx.isMiddleware ? () => {
38
+ const path = require("path");
39
+ const relativeDistDir = process.env.__PRIVATE_RELATIVE_DIST_DIR;
40
+ const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
41
+ function getRequestContext() {
42
+ const fromSymbol = globalThis;
43
+ return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
44
+ }
45
+ return async function handler(request) {
46
+ console.log("middleware handler", request);
47
+ let middlewareHandler = await require("./" + path.posix.join(relativeDistDir, "server", "middleware.js"));
48
+ middlewareHandler = middlewareHandler.handler || middlewareHandler;
49
+ const context = getRequestContext();
50
+ const response = await middlewareHandler(request, {
51
+ waitUntil: context.waitUntil,
52
+ requestMeta: {
53
+ // we use '.' for relative project dir since we process.chdir
54
+ // to the same directory as the handler file so everything is
55
+ // relative to that/project dir
56
+ relativeProjectDir: "."
57
+ }
58
+ });
59
+ return response;
60
+ };
61
+ } : (() => {
62
+ const path = require("path");
63
+ const relativeDistDir = process.env.__PRIVATE_RELATIVE_DIST_DIR;
64
+ const prerenderFallbackFalseMap = process.env.__PRIVATE_PRERENDER_FALLBACK_MAP;
65
+ const {
66
+ dynamicRoutes: dynamicRoutesRaw,
67
+ staticRoutes: staticRoutesRaw,
68
+ i18n
69
+ } = require("./" + path.posix.join(relativeDistDir, "routes-manifest.json"));
70
+ const hydrateRoutesManifestItem = (item) => {
71
+ return {
72
+ ...item,
73
+ namedRegex: new RegExp(item.namedRegex || item.regex)
74
+ };
75
+ };
76
+ const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
77
+ function escapeStringRegexp(str) {
78
+ return str.replace(matchOperatorsRegex, "\\$&");
79
+ }
80
+ const dynamicRoutes = dynamicRoutesRaw.map(hydrateRoutesManifestItem);
81
+ const staticRoutes = staticRoutesRaw.map((route) => {
82
+ return {
83
+ ...route,
84
+ namedRegex: new RegExp(
85
+ "^" + escapeStringRegexp(route.page) + "$"
86
+ )
87
+ };
88
+ });
89
+ let appPathRoutesManifest = {};
90
+ try {
91
+ appPathRoutesManifest = require("./" + path.posix.join(
92
+ relativeDistDir,
93
+ "app-path-routes-manifest.json"
94
+ ));
95
+ } catch (_) {
96
+ }
97
+ const inversedAppRoutesManifest = Object.entries(
98
+ appPathRoutesManifest
99
+ ).reduce(
100
+ (manifest, [originalKey, normalizedKey]) => {
101
+ manifest[normalizedKey] = originalKey;
102
+ return manifest;
103
+ },
104
+ {}
105
+ );
106
+ function normalizeLocalePath(pathname, locales) {
107
+ if (!locales) return { pathname };
108
+ const lowercasedLocales = locales.map(
109
+ (locale) => locale.toLowerCase()
110
+ );
111
+ const segments = pathname.split("/", 2);
112
+ if (!segments[1]) return { pathname };
113
+ const segment = segments[1].toLowerCase();
114
+ const index = lowercasedLocales.indexOf(segment);
115
+ if (index < 0) return { pathname };
116
+ const detectedLocale = locales[index];
117
+ pathname = pathname.slice(detectedLocale.length + 1) || "/";
118
+ return { pathname, locale: detectedLocale };
119
+ }
120
+ function normalizeDataPath(pathname) {
121
+ if (!(pathname || "/").startsWith("/_next/data")) {
122
+ return pathname;
123
+ }
124
+ pathname = pathname.replace(/\/_next\/data\/[^/]{1,}/, "").replace(/\.json$/, "");
125
+ if (pathname === "/index") {
126
+ return "/";
127
+ }
128
+ return pathname;
129
+ }
130
+ function matchUrlToPage(urlPathname) {
131
+ urlPathname = normalizeDataPath(urlPathname);
132
+ console.log("before normalize", urlPathname);
133
+ for (const suffixRegex of [
134
+ /\.segments(\/.*)\.segment\.rsc$/,
135
+ /\.rsc$/
136
+ ]) {
137
+ urlPathname = urlPathname.replace(suffixRegex, "");
138
+ }
139
+ const urlPathnameWithLocale = urlPathname;
140
+ const normalizeResult = normalizeLocalePath(
141
+ urlPathname,
142
+ i18n?.locales
143
+ );
144
+ urlPathname = normalizeResult.pathname;
145
+ console.log("after normalize", normalizeResult);
146
+ urlPathname = urlPathname.replace(/\/$/, "") || "/";
147
+ const combinedRoutes = [...staticRoutes, ...dynamicRoutes];
148
+ for (const route of combinedRoutes) {
149
+ if (route.page === urlPathname) {
150
+ console.log("matched direct page", route);
151
+ return {
152
+ matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
153
+ locale: normalizeResult.locale
154
+ };
155
+ }
156
+ }
157
+ for (const route of [...staticRoutes, ...dynamicRoutes]) {
158
+ console.log("testing", route.namedRegex, "against", urlPathname);
159
+ const matches = urlPathname.match(route.namedRegex);
160
+ if (matches || urlPathname === "/index" && route.namedRegex.test("/")) {
161
+ const fallbackFalseMap = prerenderFallbackFalseMap[route.page];
162
+ if (fallbackFalseMap && !(fallbackFalseMap.includes(urlPathname) || fallbackFalseMap.includes(urlPathnameWithLocale))) {
163
+ console.log("fallback: false but not prerendered", {
164
+ page: route.page,
165
+ urlPathname,
166
+ urlPathnameWithLocale,
167
+ paths: Object.values(fallbackFalseMap)
168
+ });
169
+ continue;
170
+ }
171
+ console.log("matched route", route, urlPathname, matches);
172
+ return {
173
+ matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
174
+ locale: normalizeResult.locale,
175
+ matches
176
+ };
177
+ }
178
+ }
179
+ return {
180
+ matchedPathname: inversedAppRoutesManifest[urlPathname] || urlPathname,
181
+ locale: normalizeResult.locale
182
+ };
183
+ }
184
+ const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
185
+ function getRequestContext() {
186
+ const fromSymbol = globalThis;
187
+ return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
188
+ }
189
+ const RouterServerContextSymbol = Symbol.for(
190
+ "@next/router-server-methods"
191
+ );
192
+ const routerServerGlobal = globalThis;
193
+ if (!routerServerGlobal[RouterServerContextSymbol]) {
194
+ routerServerGlobal[RouterServerContextSymbol] = {};
195
+ }
196
+ routerServerGlobal[RouterServerContextSymbol]["."] = {
197
+ async render404(req, res) {
198
+ let mod;
199
+ try {
200
+ try {
201
+ mod = await require("./" + path.posix.join(
202
+ relativeDistDir,
203
+ "server",
204
+ "app",
205
+ `_not-found`,
206
+ "page.js"
207
+ ));
208
+ console.log("using _not-found.js for render404");
209
+ } catch {
210
+ }
211
+ if (!mod) {
212
+ mod = await require("./" + path.posix.join(
213
+ relativeDistDir,
214
+ "server",
215
+ "pages",
216
+ `404.js`
217
+ ));
218
+ console.log("using 404.js for render404");
219
+ }
220
+ } catch (_) {
221
+ mod = await require("./" + path.posix.join(
222
+ relativeDistDir,
223
+ "server",
224
+ "pages",
225
+ `_error.js`
226
+ ));
227
+ console.log("using _error for render404");
228
+ }
229
+ res.statusCode = 404;
230
+ if (mod) {
231
+ await mod.handler(req, res, {
232
+ waitUntil: getRequestContext().waitUntil
233
+ });
234
+ } else {
235
+ console.log(
236
+ "failed to find 404 module",
237
+ await require("fs").promises.readdir(
238
+ path.posix.join(relativeDistDir, "server", "pages")
239
+ ).catch((err) => err)
240
+ );
241
+ res.end("This page could not be found");
242
+ }
243
+ }
244
+ };
245
+ return async function handler(req, res, internalMetadata) {
246
+ try {
247
+ const parsedUrl = new URL(req.url || "/", "http://n");
248
+ let urlPathname = req.headers["x-matched-path"];
249
+ if (typeof urlPathname !== "string") {
250
+ console.log("no x-matched-path", { url: req.url });
251
+ urlPathname = parsedUrl.pathname || "/";
252
+ }
253
+ const {
254
+ matchedPathname: page,
255
+ locale,
256
+ matches
257
+ } = matchUrlToPage(urlPathname);
258
+ const isAppDir = page.match(/\/(page|route)$/);
259
+ let addedMatchesToUrl = false;
260
+ for (const matchKey in matches?.groups || {}) {
261
+ const matchValue = matches?.groups?.[matchKey];
262
+ if (!parsedUrl.searchParams.has(matchKey) && matchValue) {
263
+ parsedUrl.searchParams.set(matchKey, matchValue);
264
+ addedMatchesToUrl = true;
265
+ }
266
+ }
267
+ if (addedMatchesToUrl) {
268
+ console.log("updating URL with new matches", matches, req.url);
269
+ req.url = `${parsedUrl.pathname}${parsedUrl.searchParams.size > 0 ? "?" : ""}${parsedUrl.searchParams.toString()}`;
270
+ }
271
+ console.log("invoking handler", {
272
+ page,
273
+ url: req.url,
274
+ matchedPath: req.headers["x-matched-path"]
275
+ });
276
+ const mod = await require("./" + path.posix.join(
277
+ relativeDistDir,
278
+ "server",
279
+ isAppDir ? "app" : "pages",
280
+ `${page === "/" ? "index" : page}.js`
281
+ ));
282
+ await mod.handler(req, res, {
283
+ waitUntil: getRequestContext().waitUntil,
284
+ requestMeta: {
285
+ ...internalMetadata,
286
+ minimalMode: true,
287
+ // we use '.' for relative project dir since we process.chdir
288
+ // to the same directory as the handler file so everything is
289
+ // relative to that/project dir
290
+ relativeProjectDir: ".",
291
+ locale
292
+ }
293
+ });
294
+ } catch (error) {
295
+ console.error(`Failed to handle ${req.url}`, error);
296
+ throw error;
297
+ }
298
+ };
299
+ }).toString()})()
300
+
301
+ module.exports = _n_handler
302
+
303
+ ${ctx.isMiddleware ? "" : `
304
+ module.exports.getRequestHandlerWithMetadata = (metadata) => {
305
+ console.log('using getRequestHandlerWithMetadata', metadata)
306
+ return (req, res) => _n_handler(req, res, metadata)
307
+ }
308
+ `}
309
+
310
+ `.replaceAll(
311
+ "process.env.__PRIVATE_RELATIVE_DIST_DIR",
312
+ `"${ctx.projectRelativeDistDir}"`
313
+ ).replaceAll(
314
+ "process.env.__PRIVATE_PRERENDER_FALLBACK_MAP",
315
+ JSON.stringify(ctx.prerenderFallbackFalseMap)
316
+ ).replaceAll(
317
+ "process.env.__PRIVATE_NEXT_CONFIG",
318
+ JSON.stringify(ctx.nextConfig)
319
+ );
320
+ // Annotate the CommonJS export names for ESM import in node:
321
+ 0 && (module.exports = {
322
+ getHandlerSource
323
+ });
package/dist/index.js CHANGED
@@ -11815,20 +11815,15 @@ async function getRequiredServerFilesManifest(entryPath, outputDirectory) {
11815
11815
  const manifestData = JSON.parse(
11816
11816
  await import_fs_extra3.default.readFile(pathRequiredServerFilesManifest, "utf8")
11817
11817
  );
11818
- const requiredServerFiles = {
11819
- files: [],
11820
- ignore: [],
11821
- config: {},
11822
- appDir: manifestData.appDir,
11823
- relativeAppDir: manifestData.relativeAppDir
11824
- };
11825
11818
  switch (manifestData.version) {
11826
11819
  case 1: {
11827
- requiredServerFiles.files = manifestData.files;
11828
- requiredServerFiles.ignore = manifestData.ignore;
11829
- requiredServerFiles.config = manifestData.config;
11830
- requiredServerFiles.appDir = manifestData.appDir;
11831
- break;
11820
+ return {
11821
+ files: manifestData.files,
11822
+ ignore: manifestData.ignore,
11823
+ config: manifestData.config,
11824
+ appDir: manifestData.appDir,
11825
+ relativeAppDir: manifestData.relativeAppDir
11826
+ };
11832
11827
  }
11833
11828
  default: {
11834
11829
  throw new Error(
@@ -11836,7 +11831,6 @@ async function getRequiredServerFilesManifest(entryPath, outputDirectory) {
11836
11831
  );
11837
11832
  }
11838
11833
  }
11839
- return requiredServerFiles;
11840
11834
  }
11841
11835
  async function getPrerenderManifest(entryPath, outputDirectory) {
11842
11836
  const pathPrerenderManifest = import_path3.default.join(
@@ -12986,7 +12980,8 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
12986
12980
  segmentPath
12987
12981
  ) + prefetchSegmentSuffix;
12988
12982
  let fallback = null;
12989
- if (segmentAllowQuery && segmentAllowQuery.length === 0) {
12983
+ const shouldAttachSegmentFallback = segmentAllowQuery && (segmentAllowQuery.length === 0 || isAppClientParamParsingEnabled);
12984
+ if (shouldAttachSegmentFallback) {
12990
12985
  const fsPath = import_path3.default.join(
12991
12986
  segmentsDir,
12992
12987
  segmentPath + prefetchSegmentSuffix
@@ -16499,12 +16494,7 @@ var build = async (buildOptions) => {
16499
16494
  }
16500
16495
  let pkg = await readPackageJson(entryPath);
16501
16496
  const nextVersionRange = await getNextVersionRange(entryPath);
16502
- const nodeVersion = await (0, import_build_utils3.getRuntimeNodeVersion)(
16503
- entryPath,
16504
- void 0,
16505
- config,
16506
- meta
16507
- );
16497
+ const nodeVersion = await (0, import_build_utils3.getNodeVersion)(entryPath, void 0, config, meta);
16508
16498
  const {
16509
16499
  cliType,
16510
16500
  lockfileVersion,
@@ -16674,6 +16664,13 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16674
16664
  if (isServerMode) {
16675
16665
  env.NODE_ENV = "production";
16676
16666
  }
16667
+ if (
16668
+ // integration tests expect outputs object
16669
+ !process.env.NEXT_BUILDER_INTEGRATION && process.env.NEXT_ENABLE_ADAPTER
16670
+ ) {
16671
+ env.NEXT_ADAPTER_PATH = import_path6.default.join(__dirname, "adapter/index.js");
16672
+ env.NEXT_ADAPTER_VERCEL_CONFIG = JSON.stringify(config);
16673
+ }
16677
16674
  const shouldRunCompileStep = Boolean(buildCommand) || Boolean(buildScriptName);
16678
16675
  builderSpan.setAttributes({
16679
16676
  build: JSON.stringify(shouldRunCompileStep)
@@ -16729,7 +16726,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16729
16726
  }
16730
16727
  if (buildOutputVersion) {
16731
16728
  return {
16732
- buildOutputPath: import_path6.default.join(outputDirectory, "output"),
16729
+ buildOutputPath: import_path6.default.join(entryPath, outputDirectory, "output"),
16733
16730
  buildOutputVersion
16734
16731
  };
16735
16732
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.15.14",
3
+ "version": "4.15.16",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -16,6 +16,7 @@
16
16
  "@vercel/nft": "1.1.1"
17
17
  },
18
18
  "devDependencies": {
19
+ "@next-community/adapter-vercel": "0.0.1-beta.1",
19
20
  "@types/aws-lambda": "8.10.19",
20
21
  "@types/buffer-crc32": "0.2.0",
21
22
  "@types/bytes": "3.1.1",
@@ -25,7 +26,7 @@
25
26
  "@types/glob": "7.1.3",
26
27
  "@types/jest": "29.5.5",
27
28
  "@types/next-server": "8.0.0",
28
- "@types/node": "14.18.33",
29
+ "@types/node": "20.11.0",
29
30
  "@types/resolve-from": "5.0.1",
30
31
  "@types/semver": "6.0.0",
31
32
  "@types/text-table": "0.2.1",
@@ -52,8 +53,8 @@
52
53
  "test-listen": "1.1.0",
53
54
  "text-table": "0.2.0",
54
55
  "webpack-sources": "3.2.3",
55
- "@vercel/routing-utils": "5.3.2",
56
- "@vercel/build-utils": "13.2.8"
56
+ "@vercel/build-utils": "13.2.15",
57
+ "@vercel/routing-utils": "5.3.2"
57
58
  },
58
59
  "scripts": {
59
60
  "build": "node build.mjs",