@next-community/adapter-vercel 0.0.1-beta.2 → 0.0.1-beta.20

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.
Binary file
@@ -23,16 +23,16 @@ __export(node_handler_exports, {
23
23
  module.exports = __toCommonJS(node_handler_exports);
24
24
  const getHandlerSource = (ctx) => `
25
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
26
  process.chdir(__dirname);
27
+
28
+ require('next/setup-node-env');
29
+
30
+ if (process.env.__PRIVATE_NEXT_ENV_LOADER_PATH) {
31
+ const { loadEnvConfig } = require(
32
+ './' + process.env.__PRIVATE_NEXT_ENV_LOADER_PATH
33
+ );
34
+ loadEnvConfig('.', process.env.NODE_ENV === 'development');
35
+ }
36
36
 
37
37
  const _n_handler = (${ctx.isMiddleware ? () => {
38
38
  const path = require("path");
@@ -43,7 +43,6 @@ const getHandlerSource = (ctx) => `
43
43
  return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
44
44
  }
45
45
  return async function handler(request) {
46
- console.log("middleware handler", request);
47
46
  let middlewareHandler = await require("./" + path.posix.join(relativeDistDir, "server", "middleware.js"));
48
47
  middlewareHandler = middlewareHandler.handler || middlewareHandler;
49
48
  const context = getRequestContext();
@@ -67,17 +66,16 @@ const getHandlerSource = (ctx) => `
67
66
  staticRoutes: staticRoutesRaw,
68
67
  i18n
69
68
  } = 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
69
  const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
77
70
  function escapeStringRegexp(str) {
78
71
  return str.replace(matchOperatorsRegex, "\\$&");
79
72
  }
80
- const dynamicRoutes = dynamicRoutesRaw.map(hydrateRoutesManifestItem);
73
+ const dynamicRoutes = dynamicRoutesRaw.map((item) => {
74
+ return {
75
+ ...item,
76
+ namedRegex: new RegExp(item.namedRegex || item.regex)
77
+ };
78
+ });
81
79
  const staticRoutes = staticRoutesRaw.map((route) => {
82
80
  return {
83
81
  ...route,
@@ -129,7 +127,6 @@ const getHandlerSource = (ctx) => `
129
127
  }
130
128
  function matchUrlToPage(urlPathname) {
131
129
  urlPathname = normalizeDataPath(urlPathname);
132
- console.log("before normalize", urlPathname);
133
130
  for (const suffixRegex of [
134
131
  /\.segments(\/.*)\.segment\.rsc$/,
135
132
  /\.rsc$/
@@ -142,12 +139,10 @@ const getHandlerSource = (ctx) => `
142
139
  i18n?.locales
143
140
  );
144
141
  urlPathname = normalizeResult.pathname;
145
- console.log("after normalize", normalizeResult);
146
142
  urlPathname = urlPathname.replace(/\/$/, "") || "/";
147
143
  const combinedRoutes = [...staticRoutes, ...dynamicRoutes];
148
144
  for (const route of combinedRoutes) {
149
145
  if (route.page === urlPathname) {
150
- console.log("matched direct page", route);
151
146
  return {
152
147
  matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
153
148
  locale: normalizeResult.locale
@@ -155,20 +150,12 @@ const getHandlerSource = (ctx) => `
155
150
  }
156
151
  }
157
152
  for (const route of [...staticRoutes, ...dynamicRoutes]) {
158
- console.log("testing", route.namedRegex, "against", urlPathname);
159
153
  const matches = urlPathname.match(route.namedRegex);
160
154
  if (matches || urlPathname === "/index" && route.namedRegex.test("/")) {
161
155
  const fallbackFalseMap = prerenderFallbackFalseMap[route.page];
162
156
  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
157
  continue;
170
158
  }
171
- console.log("matched route", route, urlPathname, matches);
172
159
  return {
173
160
  matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
174
161
  locale: normalizeResult.locale,
@@ -205,7 +192,6 @@ const getHandlerSource = (ctx) => `
205
192
  `_not-found`,
206
193
  "page.js"
207
194
  ));
208
- console.log("using _not-found.js for render404");
209
195
  } catch {
210
196
  }
211
197
  if (!mod) {
@@ -215,7 +201,6 @@ const getHandlerSource = (ctx) => `
215
201
  "pages",
216
202
  `404.js`
217
203
  ));
218
- console.log("using 404.js for render404");
219
204
  }
220
205
  } catch (_) {
221
206
  mod = await require("./" + path.posix.join(
@@ -224,7 +209,6 @@ const getHandlerSource = (ctx) => `
224
209
  "pages",
225
210
  `_error.js`
226
211
  ));
227
- console.log("using _error for render404");
228
212
  }
229
213
  res.statusCode = 404;
230
214
  if (mod) {
@@ -232,22 +216,24 @@ const getHandlerSource = (ctx) => `
232
216
  waitUntil: getRequestContext().waitUntil
233
217
  });
234
218
  } 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
219
  res.end("This page could not be found");
242
220
  }
243
221
  }
244
222
  };
223
+ function fixMojibake(input) {
224
+ const bytes = new Uint8Array(input.length);
225
+ for (let i = 0; i < input.length; i++) {
226
+ bytes[i] = input.charCodeAt(i);
227
+ }
228
+ const decoder = new TextDecoder("utf-8");
229
+ return decoder.decode(bytes);
230
+ }
245
231
  return async function handler(req, res, internalMetadata) {
246
232
  try {
247
233
  const parsedUrl = new URL(req.url || "/", "http://n");
248
- let urlPathname = req.headers["x-matched-path"];
234
+ const initURL = `https://${req.headers.host || "localhost"}${parsedUrl.pathname}${parsedUrl.search}`;
235
+ let urlPathname = typeof req.headers["x-matched-path"] === "string" ? fixMojibake(req.headers["x-matched-path"]) : void 0;
249
236
  if (typeof urlPathname !== "string") {
250
- console.log("no x-matched-path", { url: req.url });
251
237
  urlPathname = parsedUrl.pathname || "/";
252
238
  }
253
239
  const {
@@ -265,14 +251,8 @@ const getHandlerSource = (ctx) => `
265
251
  }
266
252
  }
267
253
  if (addedMatchesToUrl) {
268
- console.log("updating URL with new matches", matches, req.url);
269
254
  req.url = `${parsedUrl.pathname}${parsedUrl.searchParams.size > 0 ? "?" : ""}${parsedUrl.searchParams.toString()}`;
270
255
  }
271
- console.log("invoking handler", {
272
- page,
273
- url: req.url,
274
- matchedPath: req.headers["x-matched-path"]
275
- });
276
256
  const mod = await require("./" + path.posix.join(
277
257
  relativeDistDir,
278
258
  "server",
@@ -288,7 +268,8 @@ const getHandlerSource = (ctx) => `
288
268
  // to the same directory as the handler file so everything is
289
269
  // relative to that/project dir
290
270
  relativeProjectDir: ".",
291
- locale
271
+ locale,
272
+ initURL
292
273
  }
293
274
  });
294
275
  } catch (error) {
@@ -302,7 +283,6 @@ const getHandlerSource = (ctx) => `
302
283
 
303
284
  ${ctx.isMiddleware ? "" : `
304
285
  module.exports.getRequestHandlerWithMetadata = (metadata) => {
305
- console.log('using getRequestHandlerWithMetadata', metadata)
306
286
  return (req, res) => _n_handler(req, res, metadata)
307
287
  }
308
288
  `}
@@ -316,6 +296,9 @@ const getHandlerSource = (ctx) => `
316
296
  ).replaceAll(
317
297
  "process.env.__PRIVATE_NEXT_CONFIG",
318
298
  JSON.stringify(ctx.nextConfig)
299
+ ).replaceAll(
300
+ "process.env.__PRIVATE_NEXT_ENV_LOADER_PATH",
301
+ JSON.stringify(ctx.nextEnvLoaderPathRelativeToProjectDir || "")
319
302
  );
320
303
  // Annotate the CommonJS export names for ESM import in node:
321
304
  0 && (module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-community/adapter-vercel",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.20",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -16,14 +16,14 @@
16
16
  "@types/node": "14.18.33",
17
17
  "@types/picomatch": "2.3.3",
18
18
  "@types/webpack-sources": "3.2.0",
19
- "@vercel/build-utils": "12.2.2",
19
+ "@vercel/build-utils": "13.6.2",
20
20
  "@vercel/routing-utils": "5.2.1",
21
21
  "async-sema": "3.1.1",
22
22
  "bytes": "3.1.2",
23
23
  "convert-source-map": "1.8.0",
24
24
  "esbuild": "0.25.10",
25
25
  "fs-extra": "11.2.0",
26
- "next": "16.1.1-canary.18",
26
+ "next": "16.2.1-canary.34",
27
27
  "picomatch": "4.0.1",
28
28
  "source-map": "0.7.4",
29
29
  "webpack-sources": "3.2.3"