@vercel/node 3.0.17 → 3.0.19

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/dev-server.mjs +28 -23
  2. package/package.json +9 -7
@@ -251,6 +251,7 @@ __export(helpers_web_exports, {
251
251
  getWebExportsHandler: () => getWebExportsHandler
252
252
  });
253
253
  import { buildToNodeHandler } from "@edge-runtime/node-utils";
254
+ import Edge from "@edge-runtime/primitives";
254
255
  function getWebExportsHandler(listener, methods) {
255
256
  const handlerByMethod = {};
256
257
  for (const key of methods) {
@@ -261,45 +262,32 @@ function getWebExportsHandler(listener, methods) {
261
262
  handlerByMethod[method](req, res);
262
263
  };
263
264
  }
264
- function addDuplexToInit(init) {
265
- if (typeof init === "undefined" || typeof init === "object") {
266
- return { duplex: "half", ...init };
265
+ function addDuplexToInit(init2) {
266
+ if (typeof init2 === "undefined" || typeof init2 === "object") {
267
+ return { duplex: "half", ...init2 };
267
268
  }
268
- return init;
269
+ return init2;
269
270
  }
270
271
  function defaultHttpHandler(_, res) {
271
272
  res.statusCode = 405;
272
273
  res.end();
273
274
  }
274
- var FetchEvent, webHandlerToNodeHandler;
275
+ var webHandlerToNodeHandler;
275
276
  var init_helpers_web = __esm({
276
277
  "src/serverless-functions/helpers-web.ts"() {
277
278
  "use strict";
278
- FetchEvent = class {
279
- constructor(request) {
280
- this.request = request;
281
- this.response = null;
282
- this.awaiting = /* @__PURE__ */ new Set();
283
- }
284
- respondWith(response) {
285
- this.response = response;
286
- }
287
- waitUntil() {
288
- throw new Error("waitUntil is not implemented yet for Node.js");
289
- }
290
- };
291
279
  webHandlerToNodeHandler = buildToNodeHandler(
292
280
  {
293
281
  Headers,
294
282
  ReadableStream,
295
283
  // @ts-expect-error Property 'duplex' is missing in type 'Request'
296
284
  Request: class extends Request {
297
- constructor(input, init) {
298
- super(input, addDuplexToInit(init));
285
+ constructor(input, init2) {
286
+ super(input, addDuplexToInit(init2));
299
287
  }
300
288
  },
301
289
  Uint8Array,
302
- FetchEvent
290
+ FetchEvent: Edge.FetchEvent
303
291
  },
304
292
  { defaultOrigin: "https://vercel.com" }
305
293
  );
@@ -742,8 +730,9 @@ async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath
742
730
  process.exit(1);
743
731
  }
744
732
  const body = await serializeBody(request);
745
- if (body !== void 0)
733
+ if (body !== void 0 && body.length) {
746
734
  request.headers["content-length"] = String(body.length);
735
+ }
747
736
  const url = new URL(request.url ?? "/", server.url);
748
737
  const response = await undiciRequest(url, {
749
738
  body,
@@ -1073,9 +1062,12 @@ async function createServerlessEventHandler(entrypointPath, options) {
1073
1062
  }
1074
1063
 
1075
1064
  // src/dev-server.mts
1065
+ import { init, parse as parseEsm } from "es-module-lexer";
1066
+ import { parse as parseCjs } from "cjs-module-lexer";
1076
1067
  import { getConfig } from "@vercel/static-config";
1077
1068
  import { Project } from "ts-morph";
1078
1069
  import { listen as listen2 } from "async-listen";
1070
+ import { readFile } from "fs/promises";
1079
1071
  var entrypoint = process.env.VERCEL_DEV_ENTRYPOINT;
1080
1072
  delete process.env.VERCEL_DEV_ENTRYPOINT;
1081
1073
  if (!entrypoint) {
@@ -1095,11 +1087,24 @@ async function createEventHandler(entrypoint2, config, options) {
1095
1087
  config.zeroConfig
1096
1088
  );
1097
1089
  }
1090
+ const content = await readFile(entrypointPath, "utf8");
1091
+ const isStreaming = staticConfig?.supportsResponseStreaming || await hasWebHandlers(async () => parseCjs(content).exports) || await hasWebHandlers(
1092
+ async () => init.then(() => parseEsm(content)[1].map((specifier) => specifier.n))
1093
+ );
1098
1094
  return createServerlessEventHandler(entrypointPath, {
1099
- mode: staticConfig?.supportsResponseStreaming ? "streaming" : "buffer",
1095
+ mode: isStreaming ? "streaming" : "buffer",
1100
1096
  shouldAddHelpers: options.shouldAddHelpers
1101
1097
  });
1102
1098
  }
1099
+ async function hasWebHandlers(getExports) {
1100
+ const exports = await getExports().catch(() => []);
1101
+ for (const name of exports) {
1102
+ if (HTTP_METHODS.includes(name)) {
1103
+ return true;
1104
+ }
1105
+ }
1106
+ return false;
1107
+ }
1103
1108
  var handleEvent;
1104
1109
  var handlerEventError;
1105
1110
  var onExit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/node",
3
- "version": "3.0.17",
3
+ "version": "3.0.19",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
@@ -13,16 +13,18 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@edge-runtime/node-utils": "2.2.1",
17
- "@edge-runtime/primitives": "4.0.5",
18
- "@edge-runtime/vm": "3.1.7",
16
+ "@edge-runtime/node-utils": "2.3.0",
17
+ "@edge-runtime/primitives": "4.1.0",
18
+ "@edge-runtime/vm": "3.2.0",
19
19
  "@types/node": "14.18.33",
20
- "@vercel/build-utils": "7.5.1",
20
+ "@vercel/build-utils": "7.7.0",
21
21
  "@vercel/error-utils": "2.0.2",
22
- "@vercel/nft": "0.26.2",
22
+ "@vercel/nft": "0.26.3",
23
23
  "@vercel/static-config": "3.0.0",
24
24
  "async-listen": "3.0.0",
25
- "edge-runtime": "2.5.7",
25
+ "cjs-module-lexer": "1.2.3",
26
+ "edge-runtime": "2.5.9",
27
+ "es-module-lexer": "1.4.1",
26
28
  "esbuild": "0.14.47",
27
29
  "etag": "1.8.1",
28
30
  "node-fetch": "2.6.9",