@next-community/adapter-vercel 0.0.1-beta.1 → 0.0.1-beta.10

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.
package/dist/index.js CHANGED
@@ -2314,9 +2314,9 @@ var require_interop_require_default = __commonJS({
2314
2314
  }
2315
2315
  });
2316
2316
 
2317
- // ../../node_modules/.pnpm/next@16.1.1-canary.18_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/modern-browserslist-target.js
2317
+ // ../../node_modules/.pnpm/next@16.2.0-canary.29_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/modern-browserslist-target.js
2318
2318
  var require_modern_browserslist_target = __commonJS({
2319
- "../../node_modules/.pnpm/next@16.1.1-canary.18_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/modern-browserslist-target.js"(exports2, module2) {
2319
+ "../../node_modules/.pnpm/next@16.2.0-canary.29_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/modern-browserslist-target.js"(exports2, module2) {
2320
2320
  "use strict";
2321
2321
  var MODERN_BROWSERSLIST_TARGET = [
2322
2322
  "chrome 111",
@@ -2328,9 +2328,9 @@ var require_modern_browserslist_target = __commonJS({
2328
2328
  }
2329
2329
  });
2330
2330
 
2331
- // ../../node_modules/.pnpm/next@16.1.1-canary.18_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/entry-constants.js
2331
+ // ../../node_modules/.pnpm/next@16.2.0-canary.29_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/entry-constants.js
2332
2332
  var require_entry_constants = __commonJS({
2333
- "../../node_modules/.pnpm/next@16.1.1-canary.18_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/entry-constants.js"(exports2) {
2333
+ "../../node_modules/.pnpm/next@16.2.0-canary.29_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/entry-constants.js"(exports2) {
2334
2334
  "use strict";
2335
2335
  Object.defineProperty(exports2, "__esModule", {
2336
2336
  value: true
@@ -2362,9 +2362,9 @@ var require_entry_constants = __commonJS({
2362
2362
  }
2363
2363
  });
2364
2364
 
2365
- // ../../node_modules/.pnpm/next@16.1.1-canary.18_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/constants.js
2365
+ // ../../node_modules/.pnpm/next@16.2.0-canary.29_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/constants.js
2366
2366
  var require_constants = __commonJS({
2367
- "../../node_modules/.pnpm/next@16.1.1-canary.18_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/constants.js"(exports2, module2) {
2367
+ "../../node_modules/.pnpm/next@16.2.0-canary.29_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/next/dist/shared/lib/constants.js"(exports2, module2) {
2368
2368
  "use strict";
2369
2369
  Object.defineProperty(exports2, "__esModule", {
2370
2370
  value: true
@@ -2630,7 +2630,7 @@ var require_constants = __commonJS({
2630
2630
  var SERVER_FILES_MANIFEST = "required-server-files";
2631
2631
  var DEV_CLIENT_PAGES_MANIFEST = "_devPagesManifest.json";
2632
2632
  var MIDDLEWARE_MANIFEST = "middleware-manifest.json";
2633
- var TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST = "_clientMiddlewareManifest.json";
2633
+ var TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST = "_clientMiddlewareManifest.js";
2634
2634
  var TURBOPACK_CLIENT_BUILD_MANIFEST = "client-build-manifest.json";
2635
2635
  var DEV_CLIENT_MIDDLEWARE_MANIFEST = "_devMiddlewareManifest.json";
2636
2636
  var REACT_LOADABLE_MANIFEST = "react-loadable-manifest.json";
@@ -2725,95 +2725,6 @@ var require_constants = __commonJS({
2725
2725
  }
2726
2726
  });
2727
2727
 
2728
- // ../../node_modules/.pnpm/bytes@3.1.2/node_modules/bytes/index.js
2729
- var require_bytes = __commonJS({
2730
- "../../node_modules/.pnpm/bytes@3.1.2/node_modules/bytes/index.js"(exports2, module2) {
2731
- "use strict";
2732
- module2.exports = bytes2;
2733
- module2.exports.format = format;
2734
- module2.exports.parse = parse;
2735
- var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
2736
- var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
2737
- var map = {
2738
- b: 1,
2739
- kb: 1 << 10,
2740
- mb: 1 << 20,
2741
- gb: 1 << 30,
2742
- tb: Math.pow(1024, 4),
2743
- pb: Math.pow(1024, 5)
2744
- };
2745
- var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i;
2746
- function bytes2(value, options) {
2747
- if (typeof value === "string") {
2748
- return parse(value);
2749
- }
2750
- if (typeof value === "number") {
2751
- return format(value, options);
2752
- }
2753
- return null;
2754
- }
2755
- function format(value, options) {
2756
- if (!Number.isFinite(value)) {
2757
- return null;
2758
- }
2759
- var mag = Math.abs(value);
2760
- var thousandsSeparator = options && options.thousandsSeparator || "";
2761
- var unitSeparator = options && options.unitSeparator || "";
2762
- var decimalPlaces = options && options.decimalPlaces !== void 0 ? options.decimalPlaces : 2;
2763
- var fixedDecimals = Boolean(options && options.fixedDecimals);
2764
- var unit = options && options.unit || "";
2765
- if (!unit || !map[unit.toLowerCase()]) {
2766
- if (mag >= map.pb) {
2767
- unit = "PB";
2768
- } else if (mag >= map.tb) {
2769
- unit = "TB";
2770
- } else if (mag >= map.gb) {
2771
- unit = "GB";
2772
- } else if (mag >= map.mb) {
2773
- unit = "MB";
2774
- } else if (mag >= map.kb) {
2775
- unit = "KB";
2776
- } else {
2777
- unit = "B";
2778
- }
2779
- }
2780
- var val = value / map[unit.toLowerCase()];
2781
- var str = val.toFixed(decimalPlaces);
2782
- if (!fixedDecimals) {
2783
- str = str.replace(formatDecimalsRegExp, "$1");
2784
- }
2785
- if (thousandsSeparator) {
2786
- str = str.split(".").map(function(s, i) {
2787
- return i === 0 ? s.replace(formatThousandsRegExp, thousandsSeparator) : s;
2788
- }).join(".");
2789
- }
2790
- return str + unitSeparator + unit;
2791
- }
2792
- function parse(val) {
2793
- if (typeof val === "number" && !isNaN(val)) {
2794
- return val;
2795
- }
2796
- if (typeof val !== "string") {
2797
- return null;
2798
- }
2799
- var results = parseRegExp.exec(val);
2800
- var floatValue;
2801
- var unit = "b";
2802
- if (!results) {
2803
- floatValue = parseInt(val, 10);
2804
- unit = "b";
2805
- } else {
2806
- floatValue = parseFloat(results[1]);
2807
- unit = results[4].toLowerCase();
2808
- }
2809
- if (isNaN(floatValue)) {
2810
- return null;
2811
- }
2812
- return Math.floor(map[unit] * floatValue);
2813
- }
2814
- }
2815
- });
2816
-
2817
2728
  // ../../node_modules/.pnpm/webpack-sources@3.2.3/node_modules/webpack-sources/lib/Source.js
2818
2729
  var require_Source = __commonJS({
2819
2730
  "../../node_modules/.pnpm/webpack-sources@3.2.3/node_modules/webpack-sources/lib/Source.js"(exports2, module2) {
@@ -9516,22 +9427,12 @@ var import_node_path = __toESM(require("node:path"));
9516
9427
  var import_build_utils = require("@vercel/build-utils");
9517
9428
  var import_async_sema = __toESM(require_lib());
9518
9429
  var import_fs_extra3 = __toESM(require_lib2());
9519
- var import_constants2 = __toESM(require_constants());
9520
-
9521
- // src/pretty-bytes.ts
9522
- var import_bytes = __toESM(require_bytes());
9523
- var prettyBytes = (n) => (0, import_bytes.default)(n, { unitSeparator: " " });
9524
-
9525
- // src/constants.ts
9526
- var EDGE_FUNCTION_SIZE_LIMIT = 1024 * 1024;
9527
- var INTERNAL_PAGES = ["_app", "_error", "_document"];
9430
+ var import_constants = __toESM(require_constants());
9528
9431
 
9529
9432
  // src/get-edge-function-source.ts
9530
9433
  var import_fs_extra2 = __toESM(require_lib2());
9531
9434
  var import_path = require("path");
9532
- var import_util = require("util");
9533
9435
  var import_webpack_sources2 = __toESM(require_lib3());
9534
- var import_zlib = __toESM(require("zlib"));
9535
9436
 
9536
9437
  // src/edge-function-template.ts
9537
9438
  var template = `var b=Object.create;var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var h=e=>p(e,"__esModule",{value:!0});var _=(e,n)=>{h(e);for(var t in n)p(e,t,{get:n[t],enumerable:!0})},U=(e,n,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of T(n))!L.call(e,i)&&i!=="default"&&p(e,i,{get:()=>n[i],enumerable:!(t=w(n,i))||t.enumerable});return e},A=e=>U(h(p(e!=null?b(P(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);_(exports,{default:()=>N});var R=A(require("async_hooks")),S="@next/request-context",f=Symbol.for(S),C=Symbol.for("internal.storage");function O(){let e=globalThis;if(!e[f]){let n=new R.AsyncLocalStorage,t={get:()=>n.getStore(),[C]:n};e[f]=t}return e[f]}var q=O();function m(e,n){return q[C].run(e,n)}function y(e){let n={};return e&&e.forEach((t,i)=>{n[i]=t,i.toLowerCase()==="set-cookie"&&(n[i]=M(t))}),n}function M(e){let n=[],t=0,i,a,g,o,r;function x(){for(;t<e.length&&/\\s/.test(e.charAt(t));)t+=1;return t<e.length}function s(){return a=e.charAt(t),a!=="="&&a!==";"&&a!==","}for(;t<e.length;){for(i=t,r=!1;x();)if(a=e.charAt(t),a===","){for(g=t,t+=1,x(),o=t;t<e.length&&s();)t+=1;t<e.length&&e.charAt(t)==="="?(r=!0,t=o,n.push(e.substring(i,g)),i=t):t=g+1}else t+=1;(!r||t>=e.length)&&n.push(e.substring(i,e.length))}return n}function N(e){let n=e.staticRoutes.map(i=>({regexp:new RegExp(i.namedRegex),page:i.page})),t=e.dynamicRoutes?.map(i=>({regexp:new RegExp(i.namedRegex),page:i.page}))||[];return async function(a,g){let o=new URL(a.url).pathname,r={};if(e.nextConfig?.basePath&&o.startsWith(e.nextConfig.basePath)&&(o=o.replace(e.nextConfig.basePath,"")||"/"),e.nextConfig?.i18n)for(let s of e.nextConfig.i18n.locales){let u=new RegExp(\`^/\${s}($|/)\`,"i");if(o.match(u)){o=o.replace(u,"/")||"/";break}}for(let s of n)if(s.regexp.exec(o)){r.name=s.page;break}if(!r.name){let s=E(o);for(let u of t||[]){if(s&&!E(u.page))continue;let d=u.regexp.exec(o);if(d){r={name:u.page,params:d.groups};break}}}let x=await m({waitUntil:g.waitUntil},()=>_ENTRIES[\`middleware_\${e.name}\`].default.call({},{request:{url:a.url,method:a.method,headers:y(a.headers),ip:c(a.headers,l.Ip),geo:{city:c(a.headers,l.City,!0),country:c(a.headers,l.Country,!0),latitude:c(a.headers,l.Latitude),longitude:c(a.headers,l.Longitude),region:c(a.headers,l.Region,!0)},nextConfig:e.nextConfig,page:r,body:a.body}}));return x.waitUntil&&g.waitUntil(x.waitUntil),x.response}}function c(e,n,t=!1){let i=e.get(n)||void 0;return t&&i?decodeURIComponent(i):i}function E(e){return e==="/api"||e.startsWith("/api/")}var l;(function(o){o.City="x-vercel-ip-city",o.Country="x-vercel-ip-country",o.Ip="x-real-ip",o.Latitude="x-vercel-ip-latitude",o.Longitude="x-vercel-ip-longitude",o.Region="x-vercel-ip-country-region"})(l||(l={}));`;
@@ -9598,7 +9499,6 @@ function removeInlinedSourceMap(source) {
9598
9499
  }
9599
9500
 
9600
9501
  // src/get-edge-function-source.ts
9601
- var gzip = (0, import_util.promisify)(import_zlib.default.gzip);
9602
9502
  async function getNextjsEdgeFunctionSource(filePaths, params, outputDir, wasm) {
9603
9503
  const chunks = new import_webpack_sources2.ConcatSource(raw(`globalThis._ENTRIES = {};`));
9604
9504
  for (const filePath of filePaths) {
@@ -9608,9 +9508,6 @@ async function getNextjsEdgeFunctionSource(filePaths, params, outputDir, wasm) {
9608
9508
  /**/;`));
9609
9509
  chunks.add(await fileToSource(content, filePath, fullFilePath));
9610
9510
  }
9611
- const text = chunks.source();
9612
- const wasmFiles = Object.values(wasm || {});
9613
- await validateSize(text, wasmFiles);
9614
9511
  const getPageMatchCode = `(function () {
9615
9512
  const module = { exports: {}, loaded: false };
9616
9513
  const fn = (function(module,exports) {${template}
@@ -9631,21 +9528,6 @@ function getWasmImportStatements(wasm) {
9631
9528
  return `const ${name} = require(${JSON.stringify(pathname)});`;
9632
9529
  }).join("\n");
9633
9530
  }
9634
- async function validateSize(script, wasmFiles) {
9635
- const buffers = [Buffer.from(script, "utf8")];
9636
- for (const filePath of wasmFiles) {
9637
- buffers.push(await (0, import_fs_extra2.readFile)(filePath));
9638
- }
9639
- const content = Buffer.concat(buffers);
9640
- const gzipped = await gzip(content);
9641
- if (gzipped.length > EDGE_FUNCTION_SIZE_LIMIT) {
9642
- throw new Error(
9643
- `Exceeds maximum edge function size: ${prettyBytes(
9644
- gzipped.length
9645
- )} / ${prettyBytes(EDGE_FUNCTION_SIZE_LIMIT)}`
9646
- );
9647
- }
9648
- }
9649
9531
 
9650
9532
  // src/outputs.ts
9651
9533
  var import_node_handler = require("./node-handler");
@@ -9733,6 +9615,49 @@ async function handleStaticOutputs(outputs, {
9733
9615
  );
9734
9616
  }
9735
9617
  var vercelConfig = JSON.parse(process.env.NEXT_ADAPTER_VERCEL_CONFIG || "{}");
9618
+ function isGeneratedStep(routeName) {
9619
+ return routeName.includes(".well-known/workflow/v1/step") || routeName.includes("api/generated/steps");
9620
+ }
9621
+ function isGeneratedWorkflow(routeName) {
9622
+ return routeName.includes(".well-known/workflow/v1/flow") || routeName.includes("api/generated/workflows");
9623
+ }
9624
+ async function getGeneratedWorkflowLambdaOptions({
9625
+ projectDir,
9626
+ routeName,
9627
+ sourceFile
9628
+ }) {
9629
+ const generatedStep = isGeneratedStep(routeName);
9630
+ const generatedWorkflow = isGeneratedWorkflow(routeName);
9631
+ if (!generatedStep && !generatedWorkflow) {
9632
+ return;
9633
+ }
9634
+ const isAppRouterRoute = sourceFile.endsWith("/route.js") || sourceFile.endsWith("/route.ts");
9635
+ const configRelativePath = isAppRouterRoute ? "../config.json" : "./config.json";
9636
+ const generatedConfig = JSON.parse(
9637
+ await import_promises.default.readFile(
9638
+ import_node_path.default.join(projectDir, import_node_path.default.dirname(sourceFile), configRelativePath),
9639
+ "utf8"
9640
+ ).catch(() => "{}")
9641
+ );
9642
+ if (generatedStep && generatedConfig.steps) {
9643
+ return generatedConfig.steps;
9644
+ }
9645
+ if (generatedWorkflow && generatedConfig.workflows) {
9646
+ return generatedConfig.workflows;
9647
+ }
9648
+ }
9649
+ async function writeDeterministicRoutesManifest(distDir) {
9650
+ const manifest = require(import_node_path.default.join(distDir, "routes-manifest.json"));
9651
+ manifest.headers = [];
9652
+ manifest.onMatchHeaders = [];
9653
+ delete manifest.deploymentId;
9654
+ const outputManifestPath = import_node_path.default.join(
9655
+ distDir,
9656
+ "routes-manifest-deterministic.json"
9657
+ );
9658
+ await import_promises.default.writeFile(outputManifestPath, JSON.stringify(manifest));
9659
+ return outputManifestPath;
9660
+ }
9736
9661
  async function handleNodeOutputs(nodeOutputs, {
9737
9662
  config,
9738
9663
  distDir,
@@ -9760,6 +9685,14 @@ async function handleNodeOutputs(nodeOutputs, {
9760
9685
  break;
9761
9686
  }
9762
9687
  }
9688
+ const routesManifestDeterministicRelativePath = import_node_path.default.posix.relative(
9689
+ repoRoot,
9690
+ await writeDeterministicRoutesManifest(distDir)
9691
+ );
9692
+ const routesManifestRelativePath = import_node_path.default.posix.join(
9693
+ import_node_path.default.posix.relative(repoRoot, distDir),
9694
+ "routes-manifest.json"
9695
+ );
9763
9696
  await Promise.all(
9764
9697
  nodeOutputs.map(async (output) => {
9765
9698
  await fsSema.acquire();
@@ -9773,7 +9706,7 @@ async function handleNodeOutputs(nodeOutputs, {
9773
9706
  files[relPath] = import_node_path.default.posix.relative(repoRoot, fsPath);
9774
9707
  }
9775
9708
  files[import_node_path.default.posix.relative(repoRoot, output.filePath)] = import_node_path.default.posix.relative(repoRoot, output.filePath);
9776
- if (output.type === import_constants2.AdapterOutputType.PAGES) {
9709
+ if (output.type === import_constants.AdapterOutputType.PAGES) {
9777
9710
  const notFoundOutput = pages404Output || pagesErrorOutput;
9778
9711
  if (notFoundOutput) {
9779
9712
  for (const [relPath, fsPath] of Object.entries(
@@ -9784,6 +9717,9 @@ async function handleNodeOutputs(nodeOutputs, {
9784
9717
  files[import_node_path.default.posix.relative(repoRoot, notFoundOutput.filePath)] = import_node_path.default.posix.relative(repoRoot, notFoundOutput.filePath);
9785
9718
  }
9786
9719
  }
9720
+ if (files[routesManifestRelativePath]) {
9721
+ files[routesManifestRelativePath] = routesManifestDeterministicRelativePath;
9722
+ }
9787
9723
  const handlerFilePath = import_node_path.default.join(
9788
9724
  functionDir,
9789
9725
  handlerRelativeDir,
@@ -9799,7 +9735,7 @@ async function handleNodeOutputs(nodeOutputs, {
9799
9735
  nextConfig: config
9800
9736
  })
9801
9737
  );
9802
- const operationType = output.type === import_constants2.AdapterOutputType.APP_PAGE || import_constants2.AdapterOutputType.PAGES ? "PAGE" : "API";
9738
+ const operationType = output.type === import_constants.AdapterOutputType.APP_PAGE || import_constants.AdapterOutputType.PAGES ? "PAGE" : "API";
9803
9739
  const sourceFile = await getSourceFilePathFromPage({
9804
9740
  workPath: projectDir,
9805
9741
  page: output.sourcePage,
@@ -9809,6 +9745,15 @@ async function handleNodeOutputs(nodeOutputs, {
9809
9745
  sourceFile,
9810
9746
  config: vercelConfig
9811
9747
  });
9748
+ const generatedConfigOpts = await getGeneratedWorkflowLambdaOptions({
9749
+ projectDir,
9750
+ routeName: output.pathname,
9751
+ sourceFile
9752
+ });
9753
+ if (generatedConfigOpts) {
9754
+ Object.assign(vercelConfigOpts, generatedConfigOpts);
9755
+ }
9756
+ const maxDuration = generatedConfigOpts?.maxDuration ?? output.config.maxDuration;
9812
9757
  await writeIfNotExists(
9813
9758
  import_node_path.default.join(functionDir, `.vc-config.json`),
9814
9759
  JSON.stringify(
@@ -9826,7 +9771,7 @@ async function handleNodeOutputs(nodeOutputs, {
9826
9771
  "___next_launcher.cjs"
9827
9772
  ),
9828
9773
  runtime: nodeVersion.runtime,
9829
- maxDuration: output.config.maxDuration,
9774
+ maxDuration,
9830
9775
  supportsResponseStreaming: true,
9831
9776
  experimentalAllowBundling: true,
9832
9777
  // middleware handler always expects Request/Response interface
@@ -10027,7 +9972,8 @@ async function handleEdgeOutputs(edgeOutputs, {
10027
9972
  import_node_path.default.posix.relative(projectDir, output.filePath)
10028
9973
  ];
10029
9974
  const params = {
10030
- name: output.id.replace(/\.rsc$/, ""),
9975
+ // the edge entries has this hardcoded to "middleware" so match that
9976
+ name: output.id.replace(/\.rsc$/, "").replace("_middleware", "middleware").replace(/^\//, ""),
10031
9977
  staticRoutes: [],
10032
9978
  dynamicRoutes: [],
10033
9979
  nextConfig: {
@@ -10183,13 +10129,6 @@ async function getSourceFilePathFromPage({
10183
10129
  if (page === "/_global-error/page") {
10184
10130
  return "";
10185
10131
  }
10186
- if (!INTERNAL_PAGES.includes(page)) {
10187
- console.log(
10188
- `WARNING: Unable to find source file for page ${page} with extensions: ${extensionsToTry.join(
10189
- ", "
10190
- )}, this can cause functions config from \`vercel.json\` to not be applied`
10191
- );
10192
- }
10193
10132
  return "";
10194
10133
  }
10195
10134
 
@@ -11238,13 +11177,3 @@ var myAdapter = {
11238
11177
  }
11239
11178
  };
11240
11179
  module.exports = myAdapter;
11241
- /*! Bundled license information:
11242
-
11243
- bytes/index.js:
11244
- (*!
11245
- * bytes
11246
- * Copyright(c) 2012-2014 TJ Holowaychuk
11247
- * Copyright(c) 2015 Jed Watson
11248
- * MIT Licensed
11249
- *)
11250
- */
Binary file
@@ -23,17 +23,10 @@ __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);
36
27
 
28
+ require('next/setup-node-env')
29
+
37
30
  const _n_handler = (${ctx.isMiddleware ? () => {
38
31
  const path = require("path");
39
32
  const relativeDistDir = process.env.__PRIVATE_RELATIVE_DIST_DIR;
@@ -43,7 +36,6 @@ const getHandlerSource = (ctx) => `
43
36
  return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
44
37
  }
45
38
  return async function handler(request) {
46
- console.log("middleware handler", request);
47
39
  let middlewareHandler = await require("./" + path.posix.join(relativeDistDir, "server", "middleware.js"));
48
40
  middlewareHandler = middlewareHandler.handler || middlewareHandler;
49
41
  const context = getRequestContext();
@@ -67,17 +59,16 @@ const getHandlerSource = (ctx) => `
67
59
  staticRoutes: staticRoutesRaw,
68
60
  i18n
69
61
  } = 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
62
  const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
77
63
  function escapeStringRegexp(str) {
78
64
  return str.replace(matchOperatorsRegex, "\\$&");
79
65
  }
80
- const dynamicRoutes = dynamicRoutesRaw.map(hydrateRoutesManifestItem);
66
+ const dynamicRoutes = dynamicRoutesRaw.map((item) => {
67
+ return {
68
+ ...item,
69
+ namedRegex: new RegExp(item.namedRegex || item.regex)
70
+ };
71
+ });
81
72
  const staticRoutes = staticRoutesRaw.map((route) => {
82
73
  return {
83
74
  ...route,
@@ -129,7 +120,6 @@ const getHandlerSource = (ctx) => `
129
120
  }
130
121
  function matchUrlToPage(urlPathname) {
131
122
  urlPathname = normalizeDataPath(urlPathname);
132
- console.log("before normalize", urlPathname);
133
123
  for (const suffixRegex of [
134
124
  /\.segments(\/.*)\.segment\.rsc$/,
135
125
  /\.rsc$/
@@ -142,12 +132,10 @@ const getHandlerSource = (ctx) => `
142
132
  i18n?.locales
143
133
  );
144
134
  urlPathname = normalizeResult.pathname;
145
- console.log("after normalize", normalizeResult);
146
135
  urlPathname = urlPathname.replace(/\/$/, "") || "/";
147
136
  const combinedRoutes = [...staticRoutes, ...dynamicRoutes];
148
137
  for (const route of combinedRoutes) {
149
138
  if (route.page === urlPathname) {
150
- console.log("matched direct page", route);
151
139
  return {
152
140
  matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
153
141
  locale: normalizeResult.locale
@@ -155,20 +143,12 @@ const getHandlerSource = (ctx) => `
155
143
  }
156
144
  }
157
145
  for (const route of [...staticRoutes, ...dynamicRoutes]) {
158
- console.log("testing", route.namedRegex, "against", urlPathname);
159
146
  const matches = urlPathname.match(route.namedRegex);
160
147
  if (matches || urlPathname === "/index" && route.namedRegex.test("/")) {
161
148
  const fallbackFalseMap = prerenderFallbackFalseMap[route.page];
162
149
  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
150
  continue;
170
151
  }
171
- console.log("matched route", route, urlPathname, matches);
172
152
  return {
173
153
  matchedPathname: inversedAppRoutesManifest[route.page] || route.page,
174
154
  locale: normalizeResult.locale,
@@ -205,7 +185,6 @@ const getHandlerSource = (ctx) => `
205
185
  `_not-found`,
206
186
  "page.js"
207
187
  ));
208
- console.log("using _not-found.js for render404");
209
188
  } catch {
210
189
  }
211
190
  if (!mod) {
@@ -215,7 +194,6 @@ const getHandlerSource = (ctx) => `
215
194
  "pages",
216
195
  `404.js`
217
196
  ));
218
- console.log("using 404.js for render404");
219
197
  }
220
198
  } catch (_) {
221
199
  mod = await require("./" + path.posix.join(
@@ -224,7 +202,6 @@ const getHandlerSource = (ctx) => `
224
202
  "pages",
225
203
  `_error.js`
226
204
  ));
227
- console.log("using _error for render404");
228
205
  }
229
206
  res.statusCode = 404;
230
207
  if (mod) {
@@ -232,22 +209,24 @@ const getHandlerSource = (ctx) => `
232
209
  waitUntil: getRequestContext().waitUntil
233
210
  });
234
211
  } 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
212
  res.end("This page could not be found");
242
213
  }
243
214
  }
244
215
  };
216
+ function fixMojibake(input) {
217
+ const bytes = new Uint8Array(input.length);
218
+ for (let i = 0; i < input.length; i++) {
219
+ bytes[i] = input.charCodeAt(i);
220
+ }
221
+ const decoder = new TextDecoder("utf-8");
222
+ return decoder.decode(bytes);
223
+ }
245
224
  return async function handler(req, res, internalMetadata) {
246
225
  try {
247
226
  const parsedUrl = new URL(req.url || "/", "http://n");
248
- let urlPathname = req.headers["x-matched-path"];
227
+ const initURL = `https://${req.headers.host || "localhost"}${parsedUrl.pathname}${parsedUrl.search}`;
228
+ let urlPathname = typeof req.headers["x-matched-path"] === "string" ? fixMojibake(req.headers["x-matched-path"]) : void 0;
249
229
  if (typeof urlPathname !== "string") {
250
- console.log("no x-matched-path", { url: req.url });
251
230
  urlPathname = parsedUrl.pathname || "/";
252
231
  }
253
232
  const {
@@ -265,14 +244,8 @@ const getHandlerSource = (ctx) => `
265
244
  }
266
245
  }
267
246
  if (addedMatchesToUrl) {
268
- console.log("updating URL with new matches", matches, req.url);
269
247
  req.url = `${parsedUrl.pathname}${parsedUrl.searchParams.size > 0 ? "?" : ""}${parsedUrl.searchParams.toString()}`;
270
248
  }
271
- console.log("invoking handler", {
272
- page,
273
- url: req.url,
274
- matchedPath: req.headers["x-matched-path"]
275
- });
276
249
  const mod = await require("./" + path.posix.join(
277
250
  relativeDistDir,
278
251
  "server",
@@ -288,7 +261,8 @@ const getHandlerSource = (ctx) => `
288
261
  // to the same directory as the handler file so everything is
289
262
  // relative to that/project dir
290
263
  relativeProjectDir: ".",
291
- locale
264
+ locale,
265
+ initURL
292
266
  }
293
267
  });
294
268
  } catch (error) {
@@ -302,7 +276,6 @@ const getHandlerSource = (ctx) => `
302
276
 
303
277
  ${ctx.isMiddleware ? "" : `
304
278
  module.exports.getRequestHandlerWithMetadata = (metadata) => {
305
- console.log('using getRequestHandlerWithMetadata', metadata)
306
279
  return (req, res) => _n_handler(req, res, metadata)
307
280
  }
308
281
  `}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-community/adapter-vercel",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.10",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -23,7 +23,7 @@
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.0-canary.29",
27
27
  "picomatch": "4.0.1",
28
28
  "source-map": "0.7.4",
29
29
  "webpack-sources": "3.2.3"