@vercel/python 4.5.1 → 4.7.0

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 (3) hide show
  1. package/dist/index.js +44 -24
  2. package/package.json +2 -2
  3. package/vc_init.py +19 -3
package/dist/index.js CHANGED
@@ -302,9 +302,9 @@ var require_path_key = __commonJS({
302
302
  }
303
303
  });
304
304
 
305
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/resolveCommand.js
305
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
306
306
  var require_resolveCommand = __commonJS({
307
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module2) {
307
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module2) {
308
308
  "use strict";
309
309
  var path = require("path");
310
310
  var which2 = require_which();
@@ -312,7 +312,8 @@ var require_resolveCommand = __commonJS({
312
312
  function resolveCommandAttempt(parsed, withoutPathExt) {
313
313
  const cwd = process.cwd();
314
314
  const hasCustomCwd = parsed.options.cwd != null;
315
- if (hasCustomCwd) {
315
+ const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0;
316
+ if (shouldSwitchCwd) {
316
317
  try {
317
318
  process.chdir(parsed.options.cwd);
318
319
  } catch (err) {
@@ -326,7 +327,9 @@ var require_resolveCommand = __commonJS({
326
327
  });
327
328
  } catch (e) {
328
329
  } finally {
329
- process.chdir(cwd);
330
+ if (shouldSwitchCwd) {
331
+ process.chdir(cwd);
332
+ }
330
333
  }
331
334
  if (resolved) {
332
335
  resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
@@ -340,9 +343,9 @@ var require_resolveCommand = __commonJS({
340
343
  }
341
344
  });
342
345
 
343
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/escape.js
346
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/escape.js
344
347
  var require_escape = __commonJS({
345
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/escape.js"(exports, module2) {
348
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module2) {
346
349
  "use strict";
347
350
  var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
348
351
  function escapeCommand(arg) {
@@ -351,8 +354,8 @@ var require_escape = __commonJS({
351
354
  }
352
355
  function escapeArgument(arg, doubleEscapeMetaChars) {
353
356
  arg = `${arg}`;
354
- arg = arg.replace(/(\\*)"/g, '$1$1\\"');
355
- arg = arg.replace(/(\\*)$/, "$1$1");
357
+ arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
358
+ arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
356
359
  arg = `"${arg}"`;
357
360
  arg = arg.replace(metaCharsRegExp, "^$1");
358
361
  if (doubleEscapeMetaChars) {
@@ -391,9 +394,9 @@ var require_shebang_command = __commonJS({
391
394
  }
392
395
  });
393
396
 
394
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/readShebang.js
397
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/readShebang.js
395
398
  var require_readShebang = __commonJS({
396
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
399
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
397
400
  "use strict";
398
401
  var fs2 = require("fs");
399
402
  var shebangCommand = require_shebang_command();
@@ -1488,9 +1491,9 @@ var require_semver = __commonJS({
1488
1491
  }
1489
1492
  });
1490
1493
 
1491
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/parse.js
1494
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/parse.js
1492
1495
  var require_parse = __commonJS({
1493
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/parse.js"(exports, module2) {
1496
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module2) {
1494
1497
  "use strict";
1495
1498
  var path = require("path");
1496
1499
  var niceTry = require_src();
@@ -1574,9 +1577,9 @@ var require_parse = __commonJS({
1574
1577
  }
1575
1578
  });
1576
1579
 
1577
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/enoent.js
1580
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/enoent.js
1578
1581
  var require_enoent = __commonJS({
1579
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/enoent.js"(exports, module2) {
1582
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module2) {
1580
1583
  "use strict";
1581
1584
  var isWin = process.platform === "win32";
1582
1585
  function notFoundError(original, syscall) {
@@ -1624,9 +1627,9 @@ var require_enoent = __commonJS({
1624
1627
  }
1625
1628
  });
1626
1629
 
1627
- // ../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/index.js
1630
+ // ../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/index.js
1628
1631
  var require_cross_spawn = __commonJS({
1629
- "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/index.js"(exports, module2) {
1632
+ "../../node_modules/.pnpm/cross-spawn@6.0.6/node_modules/cross-spawn/index.js"(exports, module2) {
1630
1633
  "use strict";
1631
1634
  var cp = require("child_process");
1632
1635
  var parse = require_parse();
@@ -1802,9 +1805,9 @@ var require_once = __commonJS({
1802
1805
  }
1803
1806
  });
1804
1807
 
1805
- // ../../node_modules/.pnpm/end-of-stream@1.4.1/node_modules/end-of-stream/index.js
1808
+ // ../../node_modules/.pnpm/end-of-stream@1.4.4/node_modules/end-of-stream/index.js
1806
1809
  var require_end_of_stream = __commonJS({
1807
- "../../node_modules/.pnpm/end-of-stream@1.4.1/node_modules/end-of-stream/index.js"(exports, module2) {
1810
+ "../../node_modules/.pnpm/end-of-stream@1.4.4/node_modules/end-of-stream/index.js"(exports, module2) {
1808
1811
  var once = require_once();
1809
1812
  var noop = function() {
1810
1813
  };
@@ -1824,6 +1827,7 @@ var require_end_of_stream = __commonJS({
1824
1827
  var rs = stream._readableState;
1825
1828
  var readable = opts.readable || opts.readable !== false && stream.readable;
1826
1829
  var writable = opts.writable || opts.writable !== false && stream.writable;
1830
+ var cancelled = false;
1827
1831
  var onlegacyfinish = function() {
1828
1832
  if (!stream.writable)
1829
1833
  onfinish();
@@ -1845,9 +1849,14 @@ var require_end_of_stream = __commonJS({
1845
1849
  callback.call(stream, err);
1846
1850
  };
1847
1851
  var onclose = function() {
1848
- if (readable && !(rs && rs.ended))
1852
+ process.nextTick(onclosenexttick);
1853
+ };
1854
+ var onclosenexttick = function() {
1855
+ if (cancelled)
1856
+ return;
1857
+ if (readable && !(rs && (rs.ended && !rs.destroyed)))
1849
1858
  return callback.call(stream, new Error("premature close"));
1850
- if (writable && !(ws && ws.ended))
1859
+ if (writable && !(ws && (ws.ended && !ws.destroyed)))
1851
1860
  return callback.call(stream, new Error("premature close"));
1852
1861
  };
1853
1862
  var onrequest = function() {
@@ -1872,6 +1881,7 @@ var require_end_of_stream = __commonJS({
1872
1881
  stream.on("error", onerror);
1873
1882
  stream.on("close", onclose);
1874
1883
  return function() {
1884
+ cancelled = true;
1875
1885
  stream.removeListener("complete", onfinish);
1876
1886
  stream.removeListener("abort", onclose);
1877
1887
  stream.removeListener("request", onrequest);
@@ -1890,12 +1900,16 @@ var require_end_of_stream = __commonJS({
1890
1900
  }
1891
1901
  });
1892
1902
 
1893
- // ../../node_modules/.pnpm/pump@3.0.0/node_modules/pump/index.js
1903
+ // ../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js
1894
1904
  var require_pump = __commonJS({
1895
- "../../node_modules/.pnpm/pump@3.0.0/node_modules/pump/index.js"(exports, module2) {
1905
+ "../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js"(exports, module2) {
1896
1906
  var once = require_once();
1897
1907
  var eos = require_end_of_stream();
1898
- var fs2 = require("fs");
1908
+ var fs2;
1909
+ try {
1910
+ fs2 = require("fs");
1911
+ } catch (e) {
1912
+ }
1899
1913
  var noop = function() {
1900
1914
  };
1901
1915
  var ancient = /^v?\.0/.test(process.version);
@@ -3083,7 +3097,13 @@ var build = async ({
3083
3097
  const handlerPyContents = originalHandlerPyContents.replace(/__VC_HANDLER_MODULE_NAME/g, moduleName).replace(/__VC_HANDLER_ENTRYPOINT/g, entrypointWithSuffix);
3084
3098
  const globOptions = {
3085
3099
  cwd: workPath,
3086
- ignore: config && typeof config.excludeFiles === "string" ? config.excludeFiles : "node_modules/**"
3100
+ ignore: config && typeof config.excludeFiles === "string" ? config.excludeFiles : [
3101
+ ".git/**",
3102
+ ".vercel/**",
3103
+ "**/node_modules/**",
3104
+ "**/.next/**",
3105
+ "**/.nuxt/**"
3106
+ ]
3087
3107
  };
3088
3108
  const files = await (0, import_build_utils3.glob)("**", globOptions);
3089
3109
  const handlerPyFilename = "vc__handler__python";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "4.5.1",
3
+ "version": "4.7.0",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",
@@ -19,7 +19,7 @@
19
19
  "@types/jest": "27.4.1",
20
20
  "@types/node": "14.18.33",
21
21
  "@types/which": "3.0.0",
22
- "@vercel/build-utils": "8.4.12",
22
+ "@vercel/build-utils": "9.0.1",
23
23
  "cross-env": "7.0.3",
24
24
  "execa": "^1.0.0",
25
25
  "fs-extra": "11.1.1",
package/vc_init.py CHANGED
@@ -27,7 +27,7 @@ def format_headers(headers, decode=False):
27
27
  keyToList[key].append(value)
28
28
  return keyToList
29
29
 
30
- if 'VERCEL_IPC_FD' in os.environ:
30
+ if 'VERCEL_IPC_FD' in os.environ or 'VERCEL_IPC_PATH' in os.environ:
31
31
  from http.server import ThreadingHTTPServer
32
32
  import http
33
33
  import time
@@ -36,10 +36,15 @@ if 'VERCEL_IPC_FD' in os.environ:
36
36
  import builtins
37
37
  import logging
38
38
 
39
- ipc_fd = int(os.getenv("VERCEL_IPC_FD", ""))
40
- sock = socket.socket(fileno=ipc_fd)
41
39
  start_time = time.time()
42
40
 
41
+ if 'VERCEL_IPC_FD' in os.environ:
42
+ ipc_fd = int(os.getenv("VERCEL_IPC_FD", ""))
43
+ sock = socket.socket(fileno=ipc_fd)
44
+ else:
45
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
46
+ sock.connect(os.getenv("VERCEL_IPC_PATH", ""))
47
+
43
48
  send_message = lambda message: sock.sendall((json.dumps(message) + '\0').encode())
44
49
  storage = contextvars.ContextVar('storage', default=None)
45
50
 
@@ -178,6 +183,17 @@ if 'VERCEL_IPC_FD' in os.environ:
178
183
  del self.headers['x-vercel-internal-span-id']
179
184
  del self.headers['x-vercel-internal-trace-id']
180
185
 
186
+ send_message({
187
+ "type": "handler-started",
188
+ "payload": {
189
+ "handlerStartedAt": int(time.time() * 1000),
190
+ "context": {
191
+ "invocationId": invocationId,
192
+ "requestId": requestId,
193
+ }
194
+ }
195
+ })
196
+
181
197
  token = storage.set({
182
198
  "invocationId": invocationId,
183
199
  "requestId": requestId,