@vercel/python 6.43.3 → 6.44.1

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/index.js +747 -410
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ var require_windows = __commonJS({
48
48
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module2) {
49
49
  module2.exports = isexe;
50
50
  isexe.sync = sync;
51
- var fs12 = require("fs");
51
+ var fs13 = require("fs");
52
52
  function checkPathExt(path, options) {
53
53
  var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
54
54
  if (!pathext) {
@@ -73,12 +73,12 @@ var require_windows = __commonJS({
73
73
  return checkPathExt(path, options);
74
74
  }
75
75
  function isexe(path, options, cb) {
76
- fs12.stat(path, function(er, stat) {
76
+ fs13.stat(path, function(er, stat) {
77
77
  cb(er, er ? false : checkStat(stat, path, options));
78
78
  });
79
79
  }
80
80
  function sync(path, options) {
81
- return checkStat(fs12.statSync(path), path, options);
81
+ return checkStat(fs13.statSync(path), path, options);
82
82
  }
83
83
  }
84
84
  });
@@ -88,14 +88,14 @@ var require_mode = __commonJS({
88
88
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module2) {
89
89
  module2.exports = isexe;
90
90
  isexe.sync = sync;
91
- var fs12 = require("fs");
91
+ var fs13 = require("fs");
92
92
  function isexe(path, options, cb) {
93
- fs12.stat(path, function(er, stat) {
93
+ fs13.stat(path, function(er, stat) {
94
94
  cb(er, er ? false : checkStat(stat, options));
95
95
  });
96
96
  }
97
97
  function sync(path, options) {
98
- return checkStat(fs12.statSync(path), options);
98
+ return checkStat(fs13.statSync(path), options);
99
99
  }
100
100
  function checkStat(stat, options) {
101
101
  return stat.isFile() && checkMode(stat, options);
@@ -119,7 +119,7 @@ var require_mode = __commonJS({
119
119
  // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
120
120
  var require_isexe = __commonJS({
121
121
  "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module2) {
122
- var fs12 = require("fs");
122
+ var fs13 = require("fs");
123
123
  var core;
124
124
  if (process.platform === "win32" || global.TESTING_WINDOWS) {
125
125
  core = require_windows();
@@ -395,7 +395,7 @@ var require_shebang_command = __commonJS({
395
395
  var require_readShebang = __commonJS({
396
396
  "../../node_modules/.pnpm/cross-spawn@6.0.5/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
397
397
  "use strict";
398
- var fs12 = require("fs");
398
+ var fs13 = require("fs");
399
399
  var shebangCommand = require_shebang_command();
400
400
  function readShebang(command) {
401
401
  const size = 150;
@@ -408,9 +408,9 @@ var require_readShebang = __commonJS({
408
408
  }
409
409
  let fd;
410
410
  try {
411
- fd = fs12.openSync(command, "r");
412
- fs12.readSync(fd, buffer, 0, size, 0);
413
- fs12.closeSync(fd);
411
+ fd = fs13.openSync(command, "r");
412
+ fs13.readSync(fd, buffer, 0, size, 0);
413
+ fs13.closeSync(fd);
414
414
  } catch (e) {
415
415
  }
416
416
  return shebangCommand(buffer.toString());
@@ -423,15 +423,15 @@ var require_readShebang = __commonJS({
423
423
  var require_semver = __commonJS({
424
424
  "../../node_modules/.pnpm/semver@5.7.2/node_modules/semver/semver.js"(exports, module2) {
425
425
  exports = module2.exports = SemVer;
426
- var debug12;
426
+ var debug13;
427
427
  if (typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
428
- debug12 = function() {
428
+ debug13 = function() {
429
429
  var args = Array.prototype.slice.call(arguments, 0);
430
430
  args.unshift("SEMVER");
431
431
  console.log.apply(console, args);
432
432
  };
433
433
  } else {
434
- debug12 = function() {
434
+ debug13 = function() {
435
435
  };
436
436
  }
437
437
  exports.SEMVER_SPEC_VERSION = "2.0.0";
@@ -540,7 +540,7 @@ var require_semver = __commonJS({
540
540
  var STAR = R++;
541
541
  src[STAR] = "(<|>)?=?\\s*\\*";
542
542
  for (i = 0; i < R; i++) {
543
- debug12(i, src[i]);
543
+ debug13(i, src[i]);
544
544
  if (!re[i]) {
545
545
  re[i] = new RegExp(src[i]);
546
546
  safeRe[i] = new RegExp(makeSafeRe(src[i]));
@@ -607,7 +607,7 @@ var require_semver = __commonJS({
607
607
  if (!(this instanceof SemVer)) {
608
608
  return new SemVer(version2, options);
609
609
  }
610
- debug12("SemVer", version2, options);
610
+ debug13("SemVer", version2, options);
611
611
  this.options = options;
612
612
  this.loose = !!options.loose;
613
613
  var m = version2.trim().match(options.loose ? safeRe[LOOSE] : safeRe[FULL]);
@@ -654,7 +654,7 @@ var require_semver = __commonJS({
654
654
  return this.version;
655
655
  };
656
656
  SemVer.prototype.compare = function(other) {
657
- debug12("SemVer.compare", this.version, this.options, other);
657
+ debug13("SemVer.compare", this.version, this.options, other);
658
658
  if (!(other instanceof SemVer)) {
659
659
  other = new SemVer(other, this.options);
660
660
  }
@@ -681,7 +681,7 @@ var require_semver = __commonJS({
681
681
  do {
682
682
  var a = this.prerelease[i2];
683
683
  var b = other.prerelease[i2];
684
- debug12("prerelease compare", i2, a, b);
684
+ debug13("prerelease compare", i2, a, b);
685
685
  if (a === void 0 && b === void 0) {
686
686
  return 0;
687
687
  } else if (b === void 0) {
@@ -935,7 +935,7 @@ var require_semver = __commonJS({
935
935
  return new Comparator(comp, options);
936
936
  }
937
937
  comp = comp.trim().split(/\s+/).join(" ");
938
- debug12("comparator", comp, options);
938
+ debug13("comparator", comp, options);
939
939
  this.options = options;
940
940
  this.loose = !!options.loose;
941
941
  this.parse(comp);
@@ -944,7 +944,7 @@ var require_semver = __commonJS({
944
944
  } else {
945
945
  this.value = this.operator + this.semver.version;
946
946
  }
947
- debug12("comp", this);
947
+ debug13("comp", this);
948
948
  }
949
949
  var ANY = {};
950
950
  Comparator.prototype.parse = function(comp) {
@@ -967,7 +967,7 @@ var require_semver = __commonJS({
967
967
  return this.value;
968
968
  };
969
969
  Comparator.prototype.test = function(version2) {
970
- debug12("Comparator.test", version2, this.options.loose);
970
+ debug13("Comparator.test", version2, this.options.loose);
971
971
  if (this.semver === ANY) {
972
972
  return true;
973
973
  }
@@ -1050,9 +1050,9 @@ var require_semver = __commonJS({
1050
1050
  var loose = this.options.loose;
1051
1051
  var hr = loose ? safeRe[HYPHENRANGELOOSE] : safeRe[HYPHENRANGE];
1052
1052
  range = range.replace(hr, hyphenReplace);
1053
- debug12("hyphen replace", range);
1053
+ debug13("hyphen replace", range);
1054
1054
  range = range.replace(safeRe[COMPARATORTRIM], comparatorTrimReplace);
1055
- debug12("comparator trim", range, safeRe[COMPARATORTRIM]);
1055
+ debug13("comparator trim", range, safeRe[COMPARATORTRIM]);
1056
1056
  range = range.replace(safeRe[TILDETRIM], tildeTrimReplace);
1057
1057
  range = range.replace(safeRe[CARETTRIM], caretTrimReplace);
1058
1058
  var compRe = loose ? safeRe[COMPARATORLOOSE] : safeRe[COMPARATOR];
@@ -1092,15 +1092,15 @@ var require_semver = __commonJS({
1092
1092
  });
1093
1093
  }
1094
1094
  function parseComparator(comp, options) {
1095
- debug12("comp", comp, options);
1095
+ debug13("comp", comp, options);
1096
1096
  comp = replaceCarets(comp, options);
1097
- debug12("caret", comp);
1097
+ debug13("caret", comp);
1098
1098
  comp = replaceTildes(comp, options);
1099
- debug12("tildes", comp);
1099
+ debug13("tildes", comp);
1100
1100
  comp = replaceXRanges(comp, options);
1101
- debug12("xrange", comp);
1101
+ debug13("xrange", comp);
1102
1102
  comp = replaceStars(comp, options);
1103
- debug12("stars", comp);
1103
+ debug13("stars", comp);
1104
1104
  return comp;
1105
1105
  }
1106
1106
  function isX(id) {
@@ -1114,7 +1114,7 @@ var require_semver = __commonJS({
1114
1114
  function replaceTilde(comp, options) {
1115
1115
  var r = options.loose ? safeRe[TILDELOOSE] : safeRe[TILDE];
1116
1116
  return comp.replace(r, function(_, M, m, p, pr) {
1117
- debug12("tilde", comp, _, M, m, p, pr);
1117
+ debug13("tilde", comp, _, M, m, p, pr);
1118
1118
  var ret;
1119
1119
  if (isX(M)) {
1120
1120
  ret = "";
@@ -1123,12 +1123,12 @@ var require_semver = __commonJS({
1123
1123
  } else if (isX(p)) {
1124
1124
  ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
1125
1125
  } else if (pr) {
1126
- debug12("replaceTilde pr", pr);
1126
+ debug13("replaceTilde pr", pr);
1127
1127
  ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + (+m + 1) + ".0";
1128
1128
  } else {
1129
1129
  ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
1130
1130
  }
1131
- debug12("tilde return", ret);
1131
+ debug13("tilde return", ret);
1132
1132
  return ret;
1133
1133
  });
1134
1134
  }
@@ -1138,10 +1138,10 @@ var require_semver = __commonJS({
1138
1138
  }).join(" ");
1139
1139
  }
1140
1140
  function replaceCaret(comp, options) {
1141
- debug12("caret", comp, options);
1141
+ debug13("caret", comp, options);
1142
1142
  var r = options.loose ? safeRe[CARETLOOSE] : safeRe[CARET];
1143
1143
  return comp.replace(r, function(_, M, m, p, pr) {
1144
- debug12("caret", comp, _, M, m, p, pr);
1144
+ debug13("caret", comp, _, M, m, p, pr);
1145
1145
  var ret;
1146
1146
  if (isX(M)) {
1147
1147
  ret = "";
@@ -1154,7 +1154,7 @@ var require_semver = __commonJS({
1154
1154
  ret = ">=" + M + "." + m + ".0 <" + (+M + 1) + ".0.0";
1155
1155
  }
1156
1156
  } else if (pr) {
1157
- debug12("replaceCaret pr", pr);
1157
+ debug13("replaceCaret pr", pr);
1158
1158
  if (M === "0") {
1159
1159
  if (m === "0") {
1160
1160
  ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + m + "." + (+p + 1);
@@ -1165,7 +1165,7 @@ var require_semver = __commonJS({
1165
1165
  ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + (+M + 1) + ".0.0";
1166
1166
  }
1167
1167
  } else {
1168
- debug12("no pr");
1168
+ debug13("no pr");
1169
1169
  if (M === "0") {
1170
1170
  if (m === "0") {
1171
1171
  ret = ">=" + M + "." + m + "." + p + " <" + M + "." + m + "." + (+p + 1);
@@ -1176,12 +1176,12 @@ var require_semver = __commonJS({
1176
1176
  ret = ">=" + M + "." + m + "." + p + " <" + (+M + 1) + ".0.0";
1177
1177
  }
1178
1178
  }
1179
- debug12("caret return", ret);
1179
+ debug13("caret return", ret);
1180
1180
  return ret;
1181
1181
  });
1182
1182
  }
1183
1183
  function replaceXRanges(comp, options) {
1184
- debug12("replaceXRanges", comp, options);
1184
+ debug13("replaceXRanges", comp, options);
1185
1185
  return comp.split(/\s+/).map(function(comp2) {
1186
1186
  return replaceXRange(comp2, options);
1187
1187
  }).join(" ");
@@ -1190,7 +1190,7 @@ var require_semver = __commonJS({
1190
1190
  comp = comp.trim();
1191
1191
  var r = options.loose ? safeRe[XRANGELOOSE] : safeRe[XRANGE];
1192
1192
  return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
1193
- debug12("xRange", comp, ret, gtlt, M, m, p, pr);
1193
+ debug13("xRange", comp, ret, gtlt, M, m, p, pr);
1194
1194
  var xM = isX(M);
1195
1195
  var xm = xM || isX(m);
1196
1196
  var xp = xm || isX(p);
@@ -1233,12 +1233,12 @@ var require_semver = __commonJS({
1233
1233
  } else if (xp) {
1234
1234
  ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
1235
1235
  }
1236
- debug12("xRange return", ret);
1236
+ debug13("xRange return", ret);
1237
1237
  return ret;
1238
1238
  });
1239
1239
  }
1240
1240
  function replaceStars(comp, options) {
1241
- debug12("replaceStars", comp, options);
1241
+ debug13("replaceStars", comp, options);
1242
1242
  return comp.trim().replace(safeRe[STAR], "");
1243
1243
  }
1244
1244
  function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
@@ -1286,7 +1286,7 @@ var require_semver = __commonJS({
1286
1286
  }
1287
1287
  if (version2.prerelease.length && !options.includePrerelease) {
1288
1288
  for (i2 = 0; i2 < set.length; i2++) {
1289
- debug12(set[i2].semver);
1289
+ debug13(set[i2].semver);
1290
1290
  if (set[i2].semver === ANY) {
1291
1291
  continue;
1292
1292
  }
@@ -1890,28 +1890,28 @@ var require_end_of_stream = __commonJS({
1890
1890
  }
1891
1891
  });
1892
1892
 
1893
- // ../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js
1893
+ // ../../node_modules/.pnpm/pump@3.0.4/node_modules/pump/index.js
1894
1894
  var require_pump = __commonJS({
1895
- "../../node_modules/.pnpm/pump@3.0.2/node_modules/pump/index.js"(exports, module2) {
1895
+ "../../node_modules/.pnpm/pump@3.0.4/node_modules/pump/index.js"(exports, module2) {
1896
1896
  var once = require_once();
1897
1897
  var eos = require_end_of_stream();
1898
- var fs12;
1898
+ var fs13;
1899
1899
  try {
1900
- fs12 = require("fs");
1900
+ fs13 = require("fs");
1901
1901
  } catch (e) {
1902
1902
  }
1903
1903
  var noop = function() {
1904
1904
  };
1905
- var ancient = /^v?\.0/.test(process.version);
1905
+ var ancient = typeof process === "undefined" ? false : /^v?\.0/.test(process.version);
1906
1906
  var isFn = function(fn) {
1907
1907
  return typeof fn === "function";
1908
1908
  };
1909
1909
  var isFS = function(stream) {
1910
1910
  if (!ancient)
1911
1911
  return false;
1912
- if (!fs12)
1912
+ if (!fs13)
1913
1913
  return false;
1914
- return (stream instanceof (fs12.ReadStream || noop) || stream instanceof (fs12.WriteStream || noop)) && isFn(stream.close);
1914
+ return (stream instanceof (fs13.ReadStream || noop) || stream instanceof (fs13.WriteStream || noop)) && isFn(stream.close);
1915
1915
  };
1916
1916
  var isRequest = function(stream) {
1917
1917
  return stream.setHeader && isFn(stream.abort);
@@ -2651,9 +2651,9 @@ ${stderr}${stdout}`;
2651
2651
  var require_lib = __commonJS({
2652
2652
  "../../node_modules/.pnpm/which@3.0.0/node_modules/which/lib/index.js"(exports, module2) {
2653
2653
  var isexe = require_isexe();
2654
- var { join: join13, delimiter: delimiter2, sep: sep2, posix } = require("path");
2654
+ var { join: join14, delimiter: delimiter2, sep: sep3, posix } = require("path");
2655
2655
  var isWindows = process.platform === "win32";
2656
- var rSlash = new RegExp(`[${posix.sep}${sep2 === posix.sep ? "" : sep2}]`.replace(/(\\)/g, "\\$1"));
2656
+ var rSlash = new RegExp(`[${posix.sep}${sep3 === posix.sep ? "" : sep3}]`.replace(/(\\)/g, "\\$1"));
2657
2657
  var rRel = new RegExp(`^\\.${rSlash.source}`);
2658
2658
  var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
2659
2659
  var getPathInfo = (cmd, {
@@ -2680,7 +2680,7 @@ var require_lib = __commonJS({
2680
2680
  var getPathPart = (raw, cmd) => {
2681
2681
  const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw;
2682
2682
  const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : "";
2683
- return prefix + join13(pathPart, cmd);
2683
+ return prefix + join14(pathPart, cmd);
2684
2684
  };
2685
2685
  var which2 = async (cmd, opt = {}) => {
2686
2686
  const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
@@ -2762,27 +2762,27 @@ var require_process = __commonJS({
2762
2762
  var require_filesystem = __commonJS({
2763
2763
  "../../node_modules/.pnpm/detect-libc@2.1.2/node_modules/detect-libc/lib/filesystem.js"(exports, module2) {
2764
2764
  "use strict";
2765
- var fs12 = require("fs");
2765
+ var fs13 = require("fs");
2766
2766
  var LDD_PATH = "/usr/bin/ldd";
2767
2767
  var SELF_PATH = "/proc/self/exe";
2768
2768
  var MAX_LENGTH = 2048;
2769
2769
  var readFileSync2 = (path) => {
2770
- const fd = fs12.openSync(path, "r");
2770
+ const fd = fs13.openSync(path, "r");
2771
2771
  const buffer = Buffer.alloc(MAX_LENGTH);
2772
- const bytesRead = fs12.readSync(fd, buffer, 0, MAX_LENGTH, 0);
2773
- fs12.close(fd, () => {
2772
+ const bytesRead = fs13.readSync(fd, buffer, 0, MAX_LENGTH, 0);
2773
+ fs13.close(fd, () => {
2774
2774
  });
2775
2775
  return buffer.subarray(0, bytesRead);
2776
2776
  };
2777
2777
  var readFile2 = (path) => new Promise((resolve3, reject) => {
2778
- fs12.open(path, "r", (err, fd) => {
2778
+ fs13.open(path, "r", (err, fd) => {
2779
2779
  if (err) {
2780
2780
  reject(err);
2781
2781
  } else {
2782
2782
  const buffer = Buffer.alloc(MAX_LENGTH);
2783
- fs12.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
2783
+ fs13.read(fd, buffer, 0, MAX_LENGTH, 0, (_, bytesRead) => {
2784
2784
  resolve3(buffer.subarray(0, bytesRead));
2785
- fs12.close(fd, () => {
2785
+ fs13.close(fd, () => {
2786
2786
  });
2787
2787
  });
2788
2788
  }
@@ -3227,15 +3227,15 @@ __export(src_exports, {
3227
3227
  module.exports = __toCommonJS(src_exports);
3228
3228
  var import_assert = __toESM(require("assert"));
3229
3229
  var import_child_process3 = require("child_process");
3230
- var import_fs13 = __toESM(require("fs"));
3231
- var import_path13 = require("path");
3230
+ var import_fs14 = __toESM(require("fs"));
3231
+ var import_path14 = require("path");
3232
3232
 
3233
3233
  // src/package-versions.ts
3234
- var VERCEL_RUNTIME_VERSION = "0.14.1";
3234
+ var VERCEL_RUNTIME_VERSION = "0.14.2";
3235
3235
  var VERCEL_WORKERS_VERSION = "0.0.24";
3236
3236
 
3237
3237
  // src/index.ts
3238
- var import_build_utils17 = require("@vercel/build-utils");
3238
+ var import_build_utils18 = require("@vercel/build-utils");
3239
3239
 
3240
3240
  // src/install.ts
3241
3241
  var import_execa3 = __toESM(require_execa());
@@ -4455,12 +4455,143 @@ async function installRequirementsFile({
4455
4455
  }
4456
4456
 
4457
4457
  // src/dependency-externalizer.ts
4458
- var import_fs5 = __toESM(require("fs"));
4458
+ var import_fs6 = __toESM(require("fs"));
4459
4459
  var import_util = require("util");
4460
- var import_path6 = require("path");
4461
- var import_build_utils6 = require("@vercel/build-utils");
4460
+ var import_path7 = require("path");
4461
+ var import_build_utils7 = require("@vercel/build-utils");
4462
4462
  var import_python_analysis3 = require("@vercel/python-analysis");
4463
- var readFile = (0, import_util.promisify)(import_fs5.default.readFile);
4463
+
4464
+ // src/compileall.ts
4465
+ var import_execa4 = __toESM(require_execa());
4466
+ var import_build_utils6 = require("@vercel/build-utils");
4467
+ var import_fs5 = __toESM(require("fs"));
4468
+ var import_path6 = require("path");
4469
+ function isCompileAllEnabled() {
4470
+ const val = process.env.VERCEL_PYTHON_COMPILEALL;
4471
+ if (val !== void 0 && val !== "") {
4472
+ const lower = val.toLowerCase();
4473
+ return lower === "1" || lower === "true";
4474
+ }
4475
+ const hive = process.env.VERCEL_PYTHON_ON_HIVE;
4476
+ if (hive === "1" || hive === "true") {
4477
+ return true;
4478
+ }
4479
+ return false;
4480
+ }
4481
+ function shouldUseCompileAll({
4482
+ isDev,
4483
+ hasCustomCommand
4484
+ }) {
4485
+ if (isDev)
4486
+ return false;
4487
+ const val = process.env.VERCEL_PYTHON_COMPILEALL;
4488
+ if (val !== void 0 && val !== "") {
4489
+ const lower = val.toLowerCase();
4490
+ return lower === "1" || lower === "true";
4491
+ }
4492
+ if (hasCustomCommand)
4493
+ return false;
4494
+ return isCompileAllEnabled();
4495
+ }
4496
+ async function runCompileAll({
4497
+ pythonBin,
4498
+ filesOrDirectories,
4499
+ env,
4500
+ excludeRegex
4501
+ }) {
4502
+ if (filesOrDirectories.length === 0)
4503
+ return;
4504
+ const args = [
4505
+ "-m",
4506
+ "compileall",
4507
+ "-q",
4508
+ "-j",
4509
+ "0",
4510
+ "-f",
4511
+ "--invalidation-mode",
4512
+ "unchecked-hash",
4513
+ ...excludeRegex ? ["-x", excludeRegex] : [],
4514
+ ...filesOrDirectories
4515
+ ];
4516
+ try {
4517
+ await (0, import_execa4.default)(pythonBin, args, { env: env || process.env });
4518
+ } catch (err) {
4519
+ (0, import_build_utils6.debug)(`compileall error details: ${JSON.stringify(err)}`);
4520
+ }
4521
+ }
4522
+ function derivePycPath(pyRelPath, pythonMajor, pythonMinor) {
4523
+ if (!pyRelPath.endsWith(".py"))
4524
+ return null;
4525
+ const lastSlash = pyRelPath.lastIndexOf("/");
4526
+ const dir = lastSlash === -1 ? "" : pyRelPath.slice(0, lastSlash + 1);
4527
+ const baseName = pyRelPath.slice(lastSlash + 1, -3);
4528
+ return `${dir}__pycache__/${baseName}.cpython-${pythonMajor}${pythonMinor}.pyc`;
4529
+ }
4530
+ var COMPILEALL_APP_EXCLUDED_DIRS = [
4531
+ ".git",
4532
+ ".vercel",
4533
+ ".pnpm-store",
4534
+ "node_modules",
4535
+ ".next",
4536
+ ".nuxt",
4537
+ ".venv",
4538
+ "venv",
4539
+ "__pycache__",
4540
+ ".mypy_cache",
4541
+ ".ruff_cache",
4542
+ "public"
4543
+ ];
4544
+ function escapePythonRegex(value) {
4545
+ return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
4546
+ }
4547
+ function getCompileAllAppExcludeRegex(workPath) {
4548
+ const excludedDirs = COMPILEALL_APP_EXCLUDED_DIRS.map(escapePythonRegex).join("|");
4549
+ return `${escapePythonRegex(workPath)}[/\\\\](?:${excludedDirs})(?:[/\\\\]|$)`;
4550
+ }
4551
+ async function collectAppBytecodeFiles({
4552
+ workPath,
4553
+ files: appFiles,
4554
+ pythonMajor,
4555
+ pythonMinor
4556
+ }) {
4557
+ const pending = [];
4558
+ for (const bundlePath of Object.keys(appFiles)) {
4559
+ const pycRel = derivePycPath(bundlePath, pythonMajor, pythonMinor);
4560
+ if (!pycRel)
4561
+ continue;
4562
+ pending.push({
4563
+ bundlePath: pycRel,
4564
+ srcFsPath: (0, import_path6.join)(workPath, pycRel.replaceAll("/", import_path6.sep))
4565
+ });
4566
+ }
4567
+ const results = await Promise.all(
4568
+ pending.map(async ({ bundlePath, srcFsPath }) => {
4569
+ try {
4570
+ const stats = await import_fs5.default.promises.stat(srcFsPath);
4571
+ return { bundlePath, srcFsPath, size: stats.size };
4572
+ } catch {
4573
+ return null;
4574
+ }
4575
+ })
4576
+ );
4577
+ const files = {};
4578
+ const perItemSizes = /* @__PURE__ */ new Map();
4579
+ let totalSize = 0;
4580
+ for (const result of results) {
4581
+ if (!result)
4582
+ continue;
4583
+ files[result.bundlePath] = new import_build_utils6.FileFsRef({
4584
+ fsPath: result.srcFsPath,
4585
+ size: result.size
4586
+ });
4587
+ perItemSizes.set(result.bundlePath, result.size);
4588
+ totalSize += result.size;
4589
+ }
4590
+ return { files, totalSize, perItemSizes };
4591
+ }
4592
+
4593
+ // src/dependency-externalizer.ts
4594
+ var readFile = (0, import_util.promisify)(import_fs6.default.readFile);
4464
4595
  var STRIP_BASENAMES = /* @__PURE__ */ new Set([
4465
4596
  "py.typed",
4466
4597
  "WHEEL",
@@ -4468,7 +4599,7 @@ var STRIP_BASENAMES = /* @__PURE__ */ new Set([
4468
4599
  "direct_url.json"
4469
4600
  ]);
4470
4601
  function shouldStripVendorFile(filePath) {
4471
- const segments = filePath.split(import_path6.sep);
4602
+ const segments = filePath.split(import_path7.sep);
4472
4603
  if (segments.includes("__pycache__"))
4473
4604
  return true;
4474
4605
  const name = segments[segments.length - 1] ?? "";
@@ -4533,7 +4664,7 @@ var PythonDependencyExternalizer = class {
4533
4664
  this.distributions = /* @__PURE__ */ new Map();
4534
4665
  for (const dir of this.sitePackageDirs) {
4535
4666
  try {
4536
- await import_fs5.default.promises.access(dir);
4667
+ await import_fs6.default.promises.access(dir);
4537
4668
  } catch {
4538
4669
  continue;
4539
4670
  }
@@ -4549,12 +4680,12 @@ var PythonDependencyExternalizer = class {
4549
4680
  this.totalBundleSize = await calculateBundleSize(tempFilesForSizing);
4550
4681
  this.analyzed = true;
4551
4682
  const totalBundleSizeMB = (this.totalBundleSize / (1024 * 1024)).toFixed(2);
4552
- (0, import_build_utils6.debug)(`Total bundle size: ${totalBundleSizeMB} MB`);
4683
+ (0, import_build_utils7.debug)(`Total bundle size: ${totalBundleSizeMB} MB`);
4553
4684
  const runtimeInstallEnabled = this.shouldEnableRuntimeInstall();
4554
4685
  const pythonOnHiveEnabled = process.env.VERCEL_PYTHON_ON_HIVE === "1" || process.env.VERCEL_PYTHON_ON_HIVE === "true";
4555
4686
  if (this.totalBundleSize > LAMBDA_SIZE_THRESHOLD_BYTES && this.hasCustomCommand && !pythonOnHiveEnabled) {
4556
4687
  const limitMB = (LAMBDA_SIZE_THRESHOLD_BYTES / (1024 * 1024)).toFixed(0);
4557
- throw new import_build_utils6.NowBuildError({
4688
+ throw new import_build_utils7.NowBuildError({
4558
4689
  code: "LAMBDA_SIZE_EXCEEDED",
4559
4690
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${totalBundleSizeMB} MB) exceeds the size limit (${limitMB} MB).
4560
4691
 
@@ -4572,7 +4703,7 @@ dependencies, you can:
4572
4703
  }
4573
4704
  if (pythonOnHiveEnabled && this.totalBundleSize > HIVE_LAMBDA_SIZE_BYTES) {
4574
4705
  const limitMB = (HIVE_LAMBDA_SIZE_BYTES / (1024 * 1024)).toFixed(0);
4575
- throw new import_build_utils6.NowBuildError({
4706
+ throw new import_build_utils7.NowBuildError({
4576
4707
  code: "LAMBDA_SIZE_EXCEEDED",
4577
4708
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${totalBundleSizeMB} MB) exceeds the extended function size limit (${limitMB} MB).
4578
4709
 
@@ -4603,7 +4734,7 @@ application into smaller functions.`,
4603
4734
  );
4604
4735
  }
4605
4736
  if (!this.uvLockPath || !this.uvProjectDir) {
4606
- throw new import_build_utils6.NowBuildError({
4737
+ throw new import_build_utils7.NowBuildError({
4607
4738
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4608
4739
  message: "Runtime dependency installation requires a uv.lock file and project directory."
4609
4740
  });
@@ -4614,7 +4745,7 @@ application into smaller functions.`,
4614
4745
  );
4615
4746
  if (this.totalBundleSize > LAMBDA_EPHEMERAL_STORAGE_BYTES) {
4616
4747
  const ephemeralLimitMB = (LAMBDA_EPHEMERAL_STORAGE_BYTES / (1024 * 1024)).toFixed(0);
4617
- throw new import_build_utils6.NowBuildError({
4748
+ throw new import_build_utils7.NowBuildError({
4618
4749
  code: "LAMBDA_SIZE_EXCEEDED",
4619
4750
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${totalBundleSizeMB} MB) exceeds the ephemeral storage limit (${ephemeralLimitMB} MB).
4620
4751
 
@@ -4641,7 +4772,7 @@ your application into smaller functions.`,
4641
4772
  `Failed to read uv.lock file at "${this.uvLockPath}": ${String(error)}`
4642
4773
  );
4643
4774
  }
4644
- throw new import_build_utils6.NowBuildError({
4775
+ throw new import_build_utils7.NowBuildError({
4645
4776
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4646
4777
  message: `Failed to read uv.lock file at "${this.uvLockPath}"`
4647
4778
  });
@@ -4657,7 +4788,7 @@ your application into smaller functions.`,
4657
4788
  ${error.fileContent}`
4658
4789
  );
4659
4790
  }
4660
- throw new import_build_utils6.NowBuildError({
4791
+ throw new import_build_utils7.NowBuildError({
4661
4792
  code: error.code,
4662
4793
  message: error.message
4663
4794
  });
@@ -4667,7 +4798,7 @@ ${error.fileContent}`
4667
4798
  const excludePackages = [];
4668
4799
  if (this.projectName) {
4669
4800
  excludePackages.push(this.projectName);
4670
- (0, import_build_utils6.debug)(
4801
+ (0, import_build_utils7.debug)(
4671
4802
  `Excluding project package "${this.projectName}" from runtime installation`
4672
4803
  );
4673
4804
  }
@@ -4675,7 +4806,7 @@ ${error.fileContent}`
4675
4806
  lockFile,
4676
4807
  excludePackages
4677
4808
  });
4678
- (0, import_build_utils6.debug)(
4809
+ (0, import_build_utils7.debug)(
4679
4810
  `Package classification: ${classification.privatePackages.length} private, ${classification.publicPackages.length} public`
4680
4811
  );
4681
4812
  const forceBundledDueToWheels = await this.findPackagesWithoutCompatibleWheels(
@@ -4694,7 +4825,7 @@ ${error.fileContent}`
4694
4825
  (name) => !forceBundledSet.has((0, import_python_analysis3.normalizePackageName)(name))
4695
4826
  );
4696
4827
  if (externalizablePublic.length === 0) {
4697
- throw new import_build_utils6.NowBuildError({
4828
+ throw new import_build_utils7.NowBuildError({
4698
4829
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4699
4830
  message: `Bundle size exceeds the Lambda limit and requires runtime
4700
4831
  dependency installation, but no public packages have compatible
@@ -4729,26 +4860,26 @@ To fix this, either:
4729
4860
  let runtimeToolingOverhead = 0;
4730
4861
  try {
4731
4862
  const uvBinaryPath = await this.resolveUvBinaryForBundling();
4732
- const uvStats = await import_fs5.default.promises.stat(uvBinaryPath);
4863
+ const uvStats = await import_fs6.default.promises.stat(uvBinaryPath);
4733
4864
  runtimeToolingOverhead = uvStats.size;
4734
4865
  } catch {
4735
4866
  runtimeToolingOverhead = 50 * 1024 * 1024;
4736
4867
  }
4737
4868
  runtimeToolingOverhead += 4 * 1024;
4738
- const projectDirRel = (0, import_path6.relative)(this.workPath, this.uvProjectDir);
4739
- const uvLockRel = (0, import_path6.relative)(this.workPath, this.uvLockPath);
4869
+ const projectDirRel = (0, import_path7.relative)(this.workPath, this.uvProjectDir);
4870
+ const uvLockRel = (0, import_path7.relative)(this.workPath, this.uvLockPath);
4740
4871
  const isOutsideWorkPath = projectDirRel.startsWith("..") || uvLockRel.startsWith("..");
4741
4872
  if (isOutsideWorkPath) {
4742
- const pyprojectPath = (0, import_path6.join)(this.uvProjectDir, "pyproject.toml");
4743
- const pyprojectStats = await import_fs5.default.promises.stat(pyprojectPath).catch(() => null);
4744
- const uvLockStats = await import_fs5.default.promises.stat(this.uvLockPath).catch(() => null);
4873
+ const pyprojectPath = (0, import_path7.join)(this.uvProjectDir, "pyproject.toml");
4874
+ const pyprojectStats = await import_fs6.default.promises.stat(pyprojectPath).catch(() => null);
4875
+ const uvLockStats = await import_fs6.default.promises.stat(this.uvLockPath).catch(() => null);
4745
4876
  if (pyprojectStats)
4746
4877
  runtimeToolingOverhead += pyprojectStats.size;
4747
4878
  if (uvLockStats)
4748
4879
  runtimeToolingOverhead += uvLockStats.size;
4749
4880
  }
4750
4881
  const remainingCapacity = LAMBDA_SIZE_THRESHOLD_BYTES - fixedOverhead - runtimeToolingOverhead;
4751
- (0, import_build_utils6.debug)(
4882
+ (0, import_build_utils7.debug)(
4752
4883
  `Fixed overhead: ${(fixedOverhead / (1024 * 1024)).toFixed(2)} MB, runtime tooling: ${(runtimeToolingOverhead / (1024 * 1024)).toFixed(2)} MB, remaining capacity for public packages: ${(remainingCapacity / (1024 * 1024)).toFixed(2)} MB`
4753
4884
  );
4754
4885
  const externalizableSet = new Set(
@@ -4775,11 +4906,11 @@ To fix this, either:
4775
4906
  ...forceBundledDueToWheels
4776
4907
  ];
4777
4908
  if (isOutsideWorkPath) {
4778
- const srcPyproject = (0, import_path6.join)(this.uvProjectDir, "pyproject.toml");
4779
- files[`${UV_BUNDLE_DIR}/pyproject.toml`] = new import_build_utils6.FileFsRef({
4909
+ const srcPyproject = (0, import_path7.join)(this.uvProjectDir, "pyproject.toml");
4910
+ files[`${UV_BUNDLE_DIR}/pyproject.toml`] = new import_build_utils7.FileFsRef({
4780
4911
  fsPath: srcPyproject
4781
4912
  });
4782
- files[`${UV_BUNDLE_DIR}/uv.lock`] = new import_build_utils6.FileFsRef({
4913
+ files[`${UV_BUNDLE_DIR}/uv.lock`] = new import_build_utils7.FileFsRef({
4783
4914
  fsPath: this.uvLockPath
4784
4915
  });
4785
4916
  }
@@ -4787,24 +4918,24 @@ To fix this, either:
4787
4918
  projectDir: isOutsideWorkPath ? UV_BUNDLE_DIR : projectDirRel,
4788
4919
  bundledPackages: bundledPackagesForConfig
4789
4920
  });
4790
- files[`${UV_BUNDLE_DIR}/_runtime_config.json`] = new import_build_utils6.FileBlob({
4921
+ files[`${UV_BUNDLE_DIR}/_runtime_config.json`] = new import_build_utils7.FileBlob({
4791
4922
  data: runtimeConfigData
4792
4923
  });
4793
4924
  try {
4794
4925
  const uvBinaryPath = await this.resolveUvBinaryForBundling();
4795
- const uvBundleDir = (0, import_path6.join)(this.workPath, UV_BUNDLE_DIR);
4796
- const uvLocalPath = (0, import_path6.join)(uvBundleDir, "uv");
4797
- await import_fs5.default.promises.mkdir(uvBundleDir, { recursive: true });
4798
- await import_fs5.default.promises.copyFile(uvBinaryPath, uvLocalPath);
4799
- await import_fs5.default.promises.chmod(uvLocalPath, 493);
4926
+ const uvBundleDir = (0, import_path7.join)(this.workPath, UV_BUNDLE_DIR);
4927
+ const uvLocalPath = (0, import_path7.join)(uvBundleDir, "uv");
4928
+ await import_fs6.default.promises.mkdir(uvBundleDir, { recursive: true });
4929
+ await import_fs6.default.promises.copyFile(uvBinaryPath, uvLocalPath);
4930
+ await import_fs6.default.promises.chmod(uvLocalPath, 493);
4800
4931
  const uvBundlePath = `${UV_BUNDLE_DIR}/uv`;
4801
- files[uvBundlePath] = new import_build_utils6.FileFsRef({
4932
+ files[uvBundlePath] = new import_build_utils7.FileFsRef({
4802
4933
  fsPath: uvLocalPath,
4803
4934
  mode: 33261
4804
4935
  });
4805
- (0, import_build_utils6.debug)(`Bundled uv binary from ${uvBinaryPath} to ${uvLocalPath}`);
4936
+ (0, import_build_utils7.debug)(`Bundled uv binary from ${uvBinaryPath} to ${uvLocalPath}`);
4806
4937
  } catch (err) {
4807
- throw new import_build_utils6.NowBuildError({
4938
+ throw new import_build_utils7.NowBuildError({
4808
4939
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4809
4940
  message: `Failed to bundle uv binary for runtime installation: ${err instanceof Error ? err.message : String(err)}`
4810
4941
  });
@@ -4813,7 +4944,7 @@ To fix this, either:
4813
4944
  if (finalBundleSize > LAMBDA_SIZE_THRESHOLD_BYTES + 100 * 1024) {
4814
4945
  const finalSizeMB = (finalBundleSize / (1024 * 1024)).toFixed(2);
4815
4946
  const limitMB = (LAMBDA_SIZE_THRESHOLD_BYTES / (1024 * 1024)).toFixed(0);
4816
- throw new import_build_utils6.NowBuildError({
4947
+ throw new import_build_utils7.NowBuildError({
4817
4948
  code: "LAMBDA_SIZE_EXCEEDED",
4818
4949
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${finalSizeMB} MB) exceeds the size limit (${limitMB} MB).
4819
4950
 
@@ -4841,7 +4972,7 @@ splitting your application.`,
4841
4972
  async findPackagesWithoutCompatibleWheels(lockFile, publicPackageNames) {
4842
4973
  const platform = detectTargetPlatform();
4843
4974
  if (this.pythonMajor === void 0 || this.pythonMinor === void 0) {
4844
- (0, import_build_utils6.debug)("Skipping wheel compatibility check: dev mode");
4975
+ (0, import_build_utils7.debug)("Skipping wheel compatibility check: dev mode");
4845
4976
  return [];
4846
4977
  }
4847
4978
  const reachable = await getPackagesReachableOnPlatform(
@@ -4856,7 +4987,7 @@ splitting your application.`,
4856
4987
  (name) => reachable.has((0, import_python_analysis3.normalizePackageName)(name))
4857
4988
  ) : publicPackageNames;
4858
4989
  if (relevantPackages.length < publicPackageNames.length) {
4859
- (0, import_build_utils6.debug)(
4990
+ (0, import_build_utils7.debug)(
4860
4991
  `Skipping wheel check for ${publicPackageNames.length - relevantPackages.length} package(s) not reachable on the target platform`
4861
4992
  );
4862
4993
  }
@@ -4896,7 +5027,7 @@ splitting your application.`,
4896
5027
  break;
4897
5028
  }
4898
5029
  } catch (err) {
4899
- (0, import_build_utils6.debug)(
5030
+ (0, import_build_utils7.debug)(
4900
5031
  `Failed to check wheel compatibility for ${filename}: ${err instanceof Error ? err.message : String(err)}`
4901
5032
  );
4902
5033
  }
@@ -4913,7 +5044,7 @@ splitting your application.`,
4913
5044
  return getUvBinaryForBundling(this.pythonPath);
4914
5045
  }
4915
5046
  return downloadUvBinaryForTarget(
4916
- (0, import_path6.join)(this.workPath, ".vercel", "python", "cache")
5047
+ (0, import_path7.join)(this.workPath, ".vercel", "python", "cache")
4917
5048
  );
4918
5049
  }
4919
5050
  /**
@@ -4940,21 +5071,21 @@ splitting your application.`,
4940
5071
  const dirDistributions = this.distributions.get(dir);
4941
5072
  if (!dirDistributions)
4942
5073
  continue;
4943
- const resolvedDir = (0, import_path6.resolve)(dir);
4944
- const dirPrefix = resolvedDir + import_path6.sep;
5074
+ const resolvedDir = (0, import_path7.resolve)(dir);
5075
+ const dirPrefix = resolvedDir + import_path7.sep;
4945
5076
  for (const [name, dist] of dirDistributions) {
4946
5077
  if (includeSet && !includeSet.has(name))
4947
5078
  continue;
4948
5079
  for (const { path: rawPath, size: recordSize } of dist.files) {
4949
- const filePath = rawPath.replaceAll("/", import_path6.sep);
4950
- if (!(0, import_path6.resolve)(resolvedDir, filePath).startsWith(dirPrefix)) {
5080
+ const filePath = rawPath.replaceAll("/", import_path7.sep);
5081
+ if (!(0, import_path7.resolve)(resolvedDir, filePath).startsWith(dirPrefix)) {
4951
5082
  continue;
4952
5083
  }
4953
5084
  if (shouldStripVendorFile(filePath)) {
4954
5085
  continue;
4955
5086
  }
4956
- const srcFsPath = (0, import_path6.join)(dir, filePath);
4957
- const bundlePath = (0, import_path6.join)(vendorDirName, filePath).replace(/\\/g, "/");
5087
+ const srcFsPath = (0, import_path7.join)(dir, filePath);
5088
+ const bundlePath = (0, import_path7.join)(vendorDirName, filePath).replace(/\\/g, "/");
4958
5089
  pending.push({
4959
5090
  bundlePath,
4960
5091
  srcFsPath,
@@ -4968,14 +5099,14 @@ splitting your application.`,
4968
5099
  pending.map(async ({ bundlePath, srcFsPath, recordSize }) => {
4969
5100
  if (recordSize !== void 0) {
4970
5101
  try {
4971
- await import_fs5.default.promises.access(srcFsPath);
5102
+ await import_fs6.default.promises.access(srcFsPath);
4972
5103
  return { bundlePath, srcFsPath, size: recordSize };
4973
5104
  } catch {
4974
5105
  return null;
4975
5106
  }
4976
5107
  } else {
4977
5108
  try {
4978
- const stats = await import_fs5.default.promises.stat(srcFsPath);
5109
+ const stats = await import_fs6.default.promises.stat(srcFsPath);
4979
5110
  return { bundlePath, srcFsPath, size: stats.size };
4980
5111
  } catch {
4981
5112
  return null;
@@ -4985,13 +5116,13 @@ splitting your application.`,
4985
5116
  );
4986
5117
  for (const result of results) {
4987
5118
  if (result) {
4988
- vendorFiles[result.bundlePath] = new import_build_utils6.FileFsRef({
5119
+ vendorFiles[result.bundlePath] = new import_build_utils7.FileFsRef({
4989
5120
  fsPath: result.srcFsPath,
4990
5121
  size: result.size
4991
5122
  });
4992
5123
  }
4993
5124
  }
4994
- (0, import_build_utils6.debug)(
5125
+ (0, import_build_utils7.debug)(
4995
5126
  `Mirrored ${Object.keys(vendorFiles).length} files` + (includePackages ? ` from ${includePackages.length} packages` : "")
4996
5127
  );
4997
5128
  return vendorFiles;
@@ -5009,14 +5140,14 @@ splitting your application.`,
5009
5140
  const dirDistributions = this.distributions.get(dir);
5010
5141
  if (!dirDistributions)
5011
5142
  continue;
5012
- const resolvedDir = (0, import_path6.resolve)(dir);
5013
- const dirPrefix = resolvedDir + import_path6.sep;
5143
+ const resolvedDir = (0, import_path7.resolve)(dir);
5144
+ const dirPrefix = resolvedDir + import_path7.sep;
5014
5145
  for (const [name, dist] of dirDistributions) {
5015
5146
  let knownSize = 0;
5016
5147
  const statPromises = [];
5017
5148
  for (const { path: rawPath, size: recordSize } of dist.files) {
5018
- const filePath = rawPath.replaceAll("/", import_path6.sep);
5019
- if (!(0, import_path6.resolve)(resolvedDir, filePath).startsWith(dirPrefix)) {
5149
+ const filePath = rawPath.replaceAll("/", import_path7.sep);
5150
+ if (!(0, import_path7.resolve)(resolvedDir, filePath).startsWith(dirPrefix)) {
5020
5151
  continue;
5021
5152
  }
5022
5153
  if (shouldStripVendorFile(filePath)) {
@@ -5026,7 +5157,7 @@ splitting your application.`,
5026
5157
  knownSize += Number(recordSize);
5027
5158
  } else {
5028
5159
  statPromises.push(
5029
- import_fs5.default.promises.stat((0, import_path6.join)(dir, filePath)).then((stats) => stats.size).catch(() => 0)
5160
+ import_fs6.default.promises.stat((0, import_path7.join)(dir, filePath)).then((stats) => stats.size).catch(() => 0)
5030
5161
  );
5031
5162
  }
5032
5163
  }
@@ -5040,6 +5171,85 @@ splitting your application.`,
5040
5171
  }
5041
5172
  return sizes;
5042
5173
  }
5174
+ /**
5175
+ * Collect pre-compiled `.pyc` bytecode files for vendor packages.
5176
+ *
5177
+ * For each `.py` file listed in a package's RECORD, derives the expected
5178
+ * `__pycache__/*.cpython-XY.pyc` path and checks whether it exists on
5179
+ * disk (i.e. whether `compileall` produced it). Files that do not exist
5180
+ * are silently skipped.
5181
+ *
5182
+ * Must be called after `analyze()` which populates `sitePackageDirs` and
5183
+ * `distributions`.
5184
+ */
5185
+ async collectBytecodeFiles({
5186
+ vendorDirName,
5187
+ includePackages
5188
+ }) {
5189
+ if (!this.sitePackageDirs || !this.distributions) {
5190
+ throw new Error("collectBytecodeFiles() must be called after analyze()");
5191
+ }
5192
+ if (this.pythonMajor == null || this.pythonMinor == null) {
5193
+ return { files: {}, totalSize: 0, perItemSizes: /* @__PURE__ */ new Map() };
5194
+ }
5195
+ const includeSet = includePackages ? new Set(includePackages.map(import_python_analysis3.normalizePackageName)) : null;
5196
+ const pending = [];
5197
+ for (const dir of this.sitePackageDirs) {
5198
+ const dirDistributions = this.distributions.get(dir);
5199
+ if (!dirDistributions)
5200
+ continue;
5201
+ for (const [name, dist] of dirDistributions) {
5202
+ if (includeSet && !includeSet.has(name))
5203
+ continue;
5204
+ for (const { path: rawPath } of dist.files) {
5205
+ const pycRel = derivePycPath(
5206
+ rawPath,
5207
+ this.pythonMajor,
5208
+ this.pythonMinor
5209
+ );
5210
+ if (!pycRel)
5211
+ continue;
5212
+ const pycFilePath = pycRel.replaceAll("/", import_path7.sep);
5213
+ const srcFsPath = (0, import_path7.join)(dir, pycFilePath);
5214
+ const bundlePath = (0, import_path7.join)(vendorDirName, pycFilePath).replace(
5215
+ /\\/g,
5216
+ "/"
5217
+ );
5218
+ pending.push({ bundlePath, srcFsPath, packageName: name });
5219
+ }
5220
+ }
5221
+ }
5222
+ const results = await Promise.all(
5223
+ pending.map(async ({ bundlePath, srcFsPath, packageName }) => {
5224
+ try {
5225
+ const stats = await import_fs6.default.promises.stat(srcFsPath);
5226
+ return { bundlePath, srcFsPath, size: stats.size, packageName };
5227
+ } catch {
5228
+ return null;
5229
+ }
5230
+ })
5231
+ );
5232
+ const files = {};
5233
+ let totalSize = 0;
5234
+ const perItemSizes = /* @__PURE__ */ new Map();
5235
+ for (const result of results) {
5236
+ if (!result)
5237
+ continue;
5238
+ files[result.bundlePath] = new import_build_utils7.FileFsRef({
5239
+ fsPath: result.srcFsPath,
5240
+ size: result.size
5241
+ });
5242
+ totalSize += result.size;
5243
+ perItemSizes.set(
5244
+ result.packageName,
5245
+ (perItemSizes.get(result.packageName) ?? 0) + result.size
5246
+ );
5247
+ }
5248
+ (0, import_build_utils7.debug)(
5249
+ `Collected ${Object.keys(files).length} bytecode files (${(totalSize / (1024 * 1024)).toFixed(2)} MB)` + (includePackages ? ` from ${includePackages.length} packages` : "")
5250
+ );
5251
+ return { files, totalSize, perItemSizes };
5252
+ }
5043
5253
  };
5044
5254
  async function getPackagesReachableOnPlatform(lockFile, projectName, pythonMajor, pythonMinor, sysPlatform, platformMachine) {
5045
5255
  if (!projectName)
@@ -5072,13 +5282,13 @@ async function getPackagesReachableOnPlatform(lockFile, projectName, pythonMajor
5072
5282
  platformMachine
5073
5283
  );
5074
5284
  if (!compatible) {
5075
- (0, import_build_utils6.debug)(
5285
+ (0, import_build_utils7.debug)(
5076
5286
  `Skipping dependency ${dep.name}: marker "${dep.marker}" not satisfied on ${sysPlatform}`
5077
5287
  );
5078
5288
  continue;
5079
5289
  }
5080
5290
  } catch (err) {
5081
- (0, import_build_utils6.debug)(
5291
+ (0, import_build_utils7.debug)(
5082
5292
  `Failed to evaluate marker "${dep.marker}" for ${dep.name}, including conservatively: ${err instanceof Error ? err.message : String(err)}`
5083
5293
  );
5084
5294
  }
@@ -5110,7 +5320,7 @@ async function calculateBundleSize(files) {
5110
5320
  knownSize += fsRef.size;
5111
5321
  } else {
5112
5322
  statPromises.push(
5113
- import_fs5.default.promises.stat(fsRef.fsPath).then((stats) => stats.size).catch((err) => {
5323
+ import_fs6.default.promises.stat(fsRef.fsPath).then((stats) => stats.size).catch((err) => {
5114
5324
  console.warn(
5115
5325
  `Warning: Failed to stat file ${fsRef.fsPath}, size will not be included in bundle calculation: ${err}`
5116
5326
  );
@@ -5147,8 +5357,8 @@ function lambdaKnapsack(packages, capacity) {
5147
5357
  }
5148
5358
 
5149
5359
  // src/diagnostics.ts
5150
- var import_fs6 = __toESM(require("fs"));
5151
- var import_build_utils7 = require("@vercel/build-utils");
5360
+ var import_fs7 = __toESM(require("fs"));
5361
+ var import_build_utils8 = require("@vercel/build-utils");
5152
5362
  var import_python_analysis4 = require("@vercel/python-analysis");
5153
5363
  function isDependencyGroupInclude(entry) {
5154
5364
  return typeof entry === "object" && "include-group" in entry;
@@ -5262,7 +5472,7 @@ async function generateProjectManifest({
5262
5472
  const directEntries = [];
5263
5473
  const transitiveEntries = [];
5264
5474
  {
5265
- const content = await import_fs6.default.promises.readFile(uvLockPath, "utf-8");
5475
+ const content = await import_fs7.default.promises.readFile(uvLockPath, "utf-8");
5266
5476
  const uvLock = (0, import_python_analysis4.parseUvLock)(content, uvLockPath);
5267
5477
  const projectName = project?.name;
5268
5478
  const excludeSet = new Set(
@@ -5353,7 +5563,7 @@ async function generateProjectManifest({
5353
5563
  }
5354
5564
  }
5355
5565
  const manifest = {
5356
- version: import_build_utils7.MANIFEST_VERSION,
5566
+ version: import_build_utils8.MANIFEST_VERSION,
5357
5567
  runtime: "python",
5358
5568
  ...framework ? { framework } : {},
5359
5569
  ...serviceType ? { serviceType } : {},
@@ -5367,22 +5577,22 @@ async function generateProjectManifest({
5367
5577
  ...transitiveEntries.sort((a, b) => a.name.localeCompare(b.name))
5368
5578
  ]
5369
5579
  };
5370
- await (0, import_build_utils7.writeProjectManifest)(manifest, workPath, "python");
5580
+ await (0, import_build_utils8.writeProjectManifest)(manifest, workPath, "python");
5371
5581
  }
5372
- var diagnostics = (0, import_build_utils7.createDiagnostics)("python");
5582
+ var diagnostics = (0, import_build_utils8.createDiagnostics)("python");
5373
5583
 
5374
5584
  // src/crons.ts
5375
- var import_fs8 = __toESM(require("fs"));
5376
- var import_path8 = require("path");
5377
- var import_execa4 = __toESM(require_execa());
5378
- var import_build_utils11 = require("@vercel/build-utils");
5585
+ var import_fs9 = __toESM(require("fs"));
5586
+ var import_path9 = require("path");
5587
+ var import_execa5 = __toESM(require_execa());
5588
+ var import_build_utils12 = require("@vercel/build-utils");
5379
5589
 
5380
5590
  // src/entrypoint.ts
5381
- var import_fs7 = __toESM(require("fs"));
5382
- var import_path7 = require("path");
5383
- var import_build_utils8 = require("@vercel/build-utils");
5591
+ var import_fs8 = __toESM(require("fs"));
5592
+ var import_path8 = require("path");
5384
5593
  var import_build_utils9 = require("@vercel/build-utils");
5385
5594
  var import_build_utils10 = require("@vercel/build-utils");
5595
+ var import_build_utils11 = require("@vercel/build-utils");
5386
5596
  var import_python_analysis5 = require("@vercel/python-analysis");
5387
5597
  var PYTHON_ENTRYPOINT_FILENAMES = [
5388
5598
  "app",
@@ -5401,13 +5611,13 @@ var SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", "node_modules"]);
5401
5611
  function getCandidateEntrypointsInDirs(dirs) {
5402
5612
  return dirs.flatMap(
5403
5613
  (dir) => PYTHON_ENTRYPOINT_FILENAMES.map(
5404
- (filename) => import_path7.posix.join(dir, `${filename}.py`)
5614
+ (filename) => import_path8.posix.join(dir, `${filename}.py`)
5405
5615
  )
5406
5616
  );
5407
5617
  }
5408
5618
  async function fileExists(filePath) {
5409
5619
  try {
5410
- const stat = await import_fs7.default.promises.stat(filePath);
5620
+ const stat = await import_fs8.default.promises.stat(filePath);
5411
5621
  return stat.isFile();
5412
5622
  } catch {
5413
5623
  return false;
@@ -5462,28 +5672,28 @@ function entrypointToModule(entrypoint) {
5462
5672
  return entrypoint.replace(/\\/g, "/").replace(/\.py$/i, "").replace(/\//g, ".");
5463
5673
  }
5464
5674
  async function checkEntrypoint(workPath, relPath) {
5465
- const absPath = (0, import_path7.join)(workPath, relPath);
5675
+ const absPath = (0, import_path8.join)(workPath, relPath);
5466
5676
  if (!await fileExists(absPath))
5467
5677
  return null;
5468
- const content = await import_fs7.default.promises.readFile(absPath, "utf-8");
5678
+ const content = await import_fs8.default.promises.readFile(absPath, "utf-8");
5469
5679
  return (0, import_python_analysis5.findAppOrHandler)(content);
5470
5680
  }
5471
5681
  async function findPythonFilesRecursive(dir, rootDir) {
5472
5682
  const results = [];
5473
5683
  let entries;
5474
5684
  try {
5475
- entries = await import_fs7.default.promises.readdir(dir, { withFileTypes: true });
5685
+ entries = await import_fs8.default.promises.readdir(dir, { withFileTypes: true });
5476
5686
  } catch {
5477
5687
  return results;
5478
5688
  }
5479
5689
  for (const entry of entries) {
5480
5690
  if (entry.name.startsWith(".") || SKIP_DIRS.has(entry.name))
5481
5691
  continue;
5482
- const fullPath = (0, import_path7.join)(dir, entry.name);
5692
+ const fullPath = (0, import_path8.join)(dir, entry.name);
5483
5693
  if (entry.isDirectory()) {
5484
5694
  results.push(...await findPythonFilesRecursive(fullPath, rootDir));
5485
5695
  } else if (entry.isFile() && entry.name.endsWith(".py")) {
5486
- results.push((0, import_path7.relative)(rootDir, fullPath).replace(/\\/g, "/"));
5696
+ results.push((0, import_path8.relative)(rootDir, fullPath).replace(/\\/g, "/"));
5487
5697
  }
5488
5698
  }
5489
5699
  return results;
@@ -5493,8 +5703,8 @@ async function findEntrypointCandidates(workPath) {
5493
5703
  const candidates = [];
5494
5704
  for (const relPath of pyFiles) {
5495
5705
  try {
5496
- const content = await import_fs7.default.promises.readFile(
5497
- (0, import_path7.join)(workPath, relPath),
5706
+ const content = await import_fs8.default.promises.readFile(
5707
+ (0, import_path8.join)(workPath, relPath),
5498
5708
  "utf-8"
5499
5709
  );
5500
5710
  const varName = await (0, import_python_analysis5.findAppOrHandler)(content);
@@ -5529,14 +5739,14 @@ async function resolveModuleAttrEntrypoint(workPath, value) {
5529
5739
  const relPath = modulePath.replace(/\./g, "/");
5530
5740
  const candidates = [`${relPath}.py`, `${relPath}/__init__.py`];
5531
5741
  for (const candidate of candidates) {
5532
- if (await fileExists((0, import_path7.join)(workPath, candidate))) {
5742
+ if (await fileExists((0, import_path8.join)(workPath, candidate))) {
5533
5743
  return { entrypoint: candidate, variableName };
5534
5744
  }
5535
5745
  }
5536
5746
  return null;
5537
5747
  }
5538
5748
  async function getVercelToolsEntrypoint(workPath) {
5539
- const pyprojectData = await (0, import_build_utils10.readConfigFile)((0, import_path7.join)(workPath, "pyproject.toml"));
5749
+ const pyprojectData = await (0, import_build_utils11.readConfigFile)((0, import_path8.join)(workPath, "pyproject.toml"));
5540
5750
  if (!pyprojectData)
5541
5751
  return null;
5542
5752
  const vercelEntrypoint = pyprojectData.tool?.vercel?.entrypoint;
@@ -5545,7 +5755,7 @@ async function getVercelToolsEntrypoint(workPath) {
5545
5755
  return resolveModuleAttrEntrypoint(workPath, vercelEntrypoint);
5546
5756
  }
5547
5757
  async function getPyprojectEntrypointWithDiagnostics(workPath) {
5548
- const pyprojectData = await (0, import_build_utils10.readConfigFile)((0, import_path7.join)(workPath, "pyproject.toml"));
5758
+ const pyprojectData = await (0, import_build_utils11.readConfigFile)((0, import_path8.join)(workPath, "pyproject.toml"));
5549
5759
  if (!pyprojectData)
5550
5760
  return { entrypoint: null };
5551
5761
  const scripts = pyprojectData.project?.scripts;
@@ -5560,7 +5770,7 @@ async function getPyprojectEntrypointWithDiagnostics(workPath) {
5560
5770
  const relPath = modulePath.replace(/\./g, "/");
5561
5771
  const candidates = [`${relPath}.py`, `${relPath}/__init__.py`];
5562
5772
  for (const candidate of candidates) {
5563
- if (await fileExists((0, import_path7.join)(workPath, candidate))) {
5773
+ if (await fileExists((0, import_path8.join)(workPath, candidate))) {
5564
5774
  return { entrypoint: { entrypoint: candidate, variableName } };
5565
5775
  }
5566
5776
  }
@@ -5569,13 +5779,13 @@ async function getPyprojectEntrypointWithDiagnostics(workPath) {
5569
5779
  async function findValidEntrypoint(workPath, candidates) {
5570
5780
  const existingWithoutEntrypoint = [];
5571
5781
  for (const candidate of candidates) {
5572
- const absPath = (0, import_path7.join)(workPath, candidate);
5782
+ const absPath = (0, import_path8.join)(workPath, candidate);
5573
5783
  if (!await fileExists(absPath))
5574
5784
  continue;
5575
- const content = await import_fs7.default.promises.readFile(absPath, "utf-8");
5785
+ const content = await import_fs8.default.promises.readFile(absPath, "utf-8");
5576
5786
  const varName = await (0, import_python_analysis5.findAppOrHandler)(content);
5577
5787
  if (varName) {
5578
- (0, import_build_utils9.debug)(`Detected Python entrypoint: ${candidate} (variable: ${varName})`);
5788
+ (0, import_build_utils10.debug)(`Detected Python entrypoint: ${candidate} (variable: ${varName})`);
5579
5789
  return {
5580
5790
  entrypoint: { entrypoint: candidate, variableName: varName },
5581
5791
  existingWithoutEntrypoint
@@ -5586,12 +5796,12 @@ async function findValidEntrypoint(workPath, candidates) {
5586
5796
  return { entrypoint: null, existingWithoutEntrypoint };
5587
5797
  }
5588
5798
  async function checkDjangoManage(workPath) {
5589
- const managePath = (0, import_path7.join)(workPath, "manage.py");
5799
+ const managePath = (0, import_path8.join)(workPath, "manage.py");
5590
5800
  try {
5591
- const content = await import_fs7.default.promises.readFile(managePath, "utf-8");
5801
+ const content = await import_fs8.default.promises.readFile(managePath, "utf-8");
5592
5802
  if (!content.includes("DJANGO_SETTINGS_MODULE"))
5593
5803
  return false;
5594
- (0, import_build_utils9.debug)(`Found Django manage.py with DJANGO_SETTINGS_MODULE at ${workPath}`);
5804
+ (0, import_build_utils10.debug)(`Found Django manage.py with DJANGO_SETTINGS_MODULE at ${workPath}`);
5595
5805
  return true;
5596
5806
  } catch {
5597
5807
  return false;
@@ -5599,7 +5809,7 @@ async function checkDjangoManage(workPath) {
5599
5809
  }
5600
5810
  async function getSubdirectories(workPath) {
5601
5811
  try {
5602
- const entries = await import_fs7.default.promises.readdir(workPath, {
5812
+ const entries = await import_fs8.default.promises.readdir(workPath, {
5603
5813
  withFileTypes: true
5604
5814
  });
5605
5815
  return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name).sort();
@@ -5644,7 +5854,7 @@ ${suggestion}`;
5644
5854
  const searchedList = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
5645
5855
  message = `No ${displayName} entrypoint found. Set "tool.vercel.entrypoint" in pyproject.toml or define an entrypoint in one of: ${searchedList}.`;
5646
5856
  }
5647
- return new import_build_utils8.NowBuildError({ code, message, link, action });
5857
+ return new import_build_utils9.NowBuildError({ code, message, link, action });
5648
5858
  }
5649
5859
  async function detectGenericPythonEntrypoint(workPath) {
5650
5860
  try {
@@ -5657,7 +5867,7 @@ async function detectGenericPythonEntrypoint(workPath) {
5657
5867
  findDiagnostics: result
5658
5868
  };
5659
5869
  } catch {
5660
- (0, import_build_utils9.debug)("Failed to discover Python entrypoint");
5870
+ (0, import_build_utils10.debug)("Failed to discover Python entrypoint");
5661
5871
  return {
5662
5872
  detected: null,
5663
5873
  findDiagnostics: { entrypoint: null, existingWithoutEntrypoint: [] }
@@ -5676,7 +5886,7 @@ async function detectDjangoPythonEntrypoint(workPath) {
5676
5886
  const subdirs = await getSubdirectories(workPath);
5677
5887
  const rootDirs = ["", ...subdirs];
5678
5888
  for (const rootDir of rootDirs) {
5679
- const currPath = (0, import_path7.join)(workPath, rootDir);
5889
+ const currPath = (0, import_path8.join)(workPath, rootDir);
5680
5890
  const isDjango = await checkDjangoManage(currPath);
5681
5891
  if (isDjango) {
5682
5892
  return {
@@ -5692,7 +5902,7 @@ async function detectDjangoPythonEntrypoint(workPath) {
5692
5902
  findDiagnostics: result
5693
5903
  };
5694
5904
  } catch {
5695
- (0, import_build_utils9.debug)("Failed to discover Django Python entrypoint");
5905
+ (0, import_build_utils10.debug)("Failed to discover Django Python entrypoint");
5696
5906
  return emptyResult;
5697
5907
  }
5698
5908
  }
@@ -5700,10 +5910,10 @@ async function detectPythonEntrypoint(framework, workPath, configuredEntrypoint,
5700
5910
  if (configuredEntrypoint) {
5701
5911
  const { filePath: configEntryFile, varName: configEntryVar } = configuredEntrypoint;
5702
5912
  const entrypoint = configEntryFile.endsWith(".py") ? configEntryFile : `${configEntryFile}.py`;
5703
- const entrypointExists = await fileExists((0, import_path7.join)(workPath, entrypoint));
5913
+ const entrypointExists = await fileExists((0, import_path8.join)(workPath, entrypoint));
5704
5914
  if (!entrypointExists) {
5705
5915
  return {
5706
- error: new import_build_utils8.NowBuildError({
5916
+ error: new import_build_utils9.NowBuildError({
5707
5917
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
5708
5918
  message: `Configured Python entrypoint "${entrypoint}" was not found.`,
5709
5919
  link: PYTHON_ENTRYPOINT_DOCS_URL,
@@ -5713,17 +5923,17 @@ async function detectPythonEntrypoint(framework, workPath, configuredEntrypoint,
5713
5923
  }
5714
5924
  let varName = configEntryVar ?? await checkEntrypoint(workPath, entrypoint);
5715
5925
  if (!varName) {
5716
- const needsDynamicApp = !!service && ((0, import_build_utils8.isScheduleTriggeredService)(service) || (0, import_build_utils8.isQueueTriggeredService)(service) || (0, import_build_utils8.isWorkflowTriggeredService)(service));
5926
+ const needsDynamicApp = !!service && ((0, import_build_utils9.isScheduleTriggeredService)(service) || (0, import_build_utils9.isQueueTriggeredService)(service) || (0, import_build_utils9.isWorkflowTriggeredService)(service));
5717
5927
  if (needsDynamicApp) {
5718
5928
  varName = "app";
5719
5929
  }
5720
5930
  }
5721
5931
  if (varName) {
5722
- (0, import_build_utils9.debug)(`Using configured Python entrypoint: ${entrypoint}`);
5932
+ (0, import_build_utils10.debug)(`Using configured Python entrypoint: ${entrypoint}`);
5723
5933
  return { entrypoint: { entrypoint, variableName: varName } };
5724
5934
  } else {
5725
5935
  return {
5726
- error: new import_build_utils8.NowBuildError({
5936
+ error: new import_build_utils9.NowBuildError({
5727
5937
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
5728
5938
  message: `Could not find a top-level "app", "application", or "handler" in "${entrypoint}".`,
5729
5939
  link: PYTHON_ENTRYPOINT_DOCS_URL,
@@ -5773,7 +5983,7 @@ var detectEntrypoint = async ({
5773
5983
  workPath,
5774
5984
  framework
5775
5985
  }) => {
5776
- if (!(0, import_build_utils8.isPythonFramework)(framework))
5986
+ if (!(0, import_build_utils9.isPythonFramework)(framework))
5777
5987
  return null;
5778
5988
  const detected = await detectPythonEntrypoint(
5779
5989
  framework,
@@ -5790,8 +6000,8 @@ var detectEntrypoint = async ({
5790
6000
 
5791
6001
  // src/crons.ts
5792
6002
  var DYNAMIC_SCHEDULE = "<dynamic>";
5793
- var scriptPath = (0, import_path8.join)(__dirname, "..", "templates", "vc_cron_detect.py");
5794
- var script = import_fs8.default.readFileSync(scriptPath, "utf-8");
6003
+ var scriptPath = (0, import_path9.join)(__dirname, "..", "templates", "vc_cron_detect.py");
6004
+ var script = import_fs9.default.readFileSync(scriptPath, "utf-8");
5795
6005
  function buildCronRouteTable(crons) {
5796
6006
  const table = {};
5797
6007
  for (const cron of crons) {
@@ -5801,13 +6011,13 @@ function buildCronRouteTable(crons) {
5801
6011
  }
5802
6012
  async function getServiceCrons(opts) {
5803
6013
  const { service, entrypoint, rawEntrypoint, handlerFunction } = opts;
5804
- const isScheduledService = !!service && (0, import_build_utils11.isScheduleTriggeredService)(service);
6014
+ const isScheduledService = !!service && (0, import_build_utils12.isScheduleTriggeredService)(service);
5805
6015
  if (!isScheduledService || !service.name || typeof service.schedule !== "string" && !Array.isArray(service.schedule)) {
5806
6016
  return void 0;
5807
6017
  }
5808
6018
  const cronEntrypoint = entrypoint || rawEntrypoint;
5809
6019
  if (!cronEntrypoint) {
5810
- throw new import_build_utils11.NowBuildError({
6020
+ throw new import_build_utils12.NowBuildError({
5811
6021
  code: "PYTHON_CRON_NO_ENTRYPOINT",
5812
6022
  message: "Cron service is missing an entrypoint."
5813
6023
  });
@@ -5822,7 +6032,7 @@ async function getServiceCrons(opts) {
5822
6032
  workPath: opts.workPath
5823
6033
  });
5824
6034
  }
5825
- const cronPath = (0, import_build_utils11.getInternalServiceCronPath)(
6035
+ const cronPath = (0, import_build_utils12.getInternalServiceCronPath)(
5826
6036
  service.name,
5827
6037
  cronEntrypoint,
5828
6038
  handlerFunction || "cron"
@@ -5846,7 +6056,7 @@ async function getServiceCronsDynamic(opts) {
5846
6056
  workPath
5847
6057
  } = opts;
5848
6058
  if (!handlerFunction) {
5849
- throw new import_build_utils11.NowBuildError({
6059
+ throw new import_build_utils12.NowBuildError({
5850
6060
  code: "PYTHON_DYNAMIC_CRON_NO_HANDLER",
5851
6061
  message: 'Dynamic cron detection requires a "module:object" entrypoint where the object has a get_crons() method.'
5852
6062
  });
@@ -5863,7 +6073,7 @@ async function getServiceCronsDynamic(opts) {
5863
6073
  `Detected ${entries.length} cron entry(s): ${entries.map((e) => `${e.module_function} (${e.schedule})`).join(", ")}`
5864
6074
  );
5865
6075
  if (entries.length === 0) {
5866
- throw new import_build_utils11.NowBuildError({
6076
+ throw new import_build_utils12.NowBuildError({
5867
6077
  code: "PYTHON_DYNAMIC_CRON_EMPTY",
5868
6078
  message: `Dynamic cron detection returned no entries. "${moduleName}.${handlerFunction}.get_crons()" returned an empty iterable.`
5869
6079
  });
@@ -5884,7 +6094,7 @@ async function detectDynamicCrons(opts) {
5884
6094
  const { pythonBin, env, workPath, moduleName, attrName } = opts;
5885
6095
  let stdout;
5886
6096
  try {
5887
- const result = await (0, import_execa4.default)(
6097
+ const result = await (0, import_execa5.default)(
5888
6098
  pythonBin,
5889
6099
  ["-c", script, moduleName, attrName],
5890
6100
  { env, cwd: workPath }
@@ -5898,7 +6108,7 @@ async function detectDynamicCrons(opts) {
5898
6108
  detail = parsed2.error;
5899
6109
  } catch {
5900
6110
  }
5901
- throw new import_build_utils11.NowBuildError({
6111
+ throw new import_build_utils12.NowBuildError({
5902
6112
  code: "PYTHON_DYNAMIC_CRON_DETECTION_FAILED",
5903
6113
  message: `Failed to detect dynamic cron entries: ${detail}`
5904
6114
  });
@@ -5907,7 +6117,7 @@ async function detectDynamicCrons(opts) {
5907
6117
  try {
5908
6118
  parsed = JSON.parse(stdout);
5909
6119
  } catch {
5910
- throw new import_build_utils11.NowBuildError({
6120
+ throw new import_build_utils12.NowBuildError({
5911
6121
  code: "PYTHON_DYNAMIC_CRON_DETECTION_FAILED",
5912
6122
  message: `Dynamic cron detection returned invalid JSON: ${stdout}`
5913
6123
  });
@@ -5917,7 +6127,7 @@ async function detectDynamicCrons(opts) {
5917
6127
  function moduleColonFuncToCronPath(serviceName, moduleFunction) {
5918
6128
  const colonIdx = moduleFunction.indexOf(":");
5919
6129
  if (colonIdx === -1) {
5920
- throw new import_build_utils11.NowBuildError({
6130
+ throw new import_build_utils12.NowBuildError({
5921
6131
  code: "PYTHON_DYNAMIC_CRON_INVALID_FORMAT",
5922
6132
  message: `Dynamic cron entry must use "module:function" format, got: "${moduleFunction}"`
5923
6133
  });
@@ -5925,14 +6135,14 @@ function moduleColonFuncToCronPath(serviceName, moduleFunction) {
5925
6135
  const modulePart = moduleFunction.slice(0, colonIdx);
5926
6136
  const funcPart = moduleFunction.slice(colonIdx + 1);
5927
6137
  const entrypointPath = modulePart.replace(/\./g, "/");
5928
- return (0, import_build_utils11.getInternalServiceCronPath)(serviceName, entrypointPath, funcPart);
6138
+ return (0, import_build_utils12.getInternalServiceCronPath)(serviceName, entrypointPath, funcPart);
5929
6139
  }
5930
6140
 
5931
6141
  // src/start-dev-server.ts
5932
6142
  var import_child_process2 = require("child_process");
5933
- var import_fs9 = require("fs");
5934
- var import_path9 = require("path");
5935
- var import_build_utils12 = require("@vercel/build-utils");
6143
+ var import_fs10 = require("fs");
6144
+ var import_path10 = require("path");
6145
+ var import_build_utils13 = require("@vercel/build-utils");
5936
6146
  var import_get_port = __toESM(require_get_port());
5937
6147
  var import_is_port_reachable = __toESM(require_is_port_reachable());
5938
6148
  var import_python_analysis6 = require("@vercel/python-analysis");
@@ -6021,17 +6231,17 @@ async function syncDependencies({
6021
6231
  let { manifestPath } = installInfo;
6022
6232
  const manifest = pythonPackage.manifest;
6023
6233
  if (!manifestType || !manifestPath) {
6024
- (0, import_build_utils12.debug)("No Python project manifest found, skipping dependency sync");
6234
+ (0, import_build_utils13.debug)("No Python project manifest found, skipping dependency sync");
6025
6235
  return;
6026
6236
  }
6027
6237
  if (manifest?.origin && manifestType === "pyproject.toml") {
6028
- const syncDir = (0, import_path9.join)(workPath, ".vercel", "python", "sync");
6029
- (0, import_fs9.mkdirSync)(syncDir, { recursive: true });
6030
- const tempPyproject = (0, import_path9.join)(syncDir, "pyproject.toml");
6238
+ const syncDir = (0, import_path10.join)(workPath, ".vercel", "python", "sync");
6239
+ (0, import_fs10.mkdirSync)(syncDir, { recursive: true });
6240
+ const tempPyproject = (0, import_path10.join)(syncDir, "pyproject.toml");
6031
6241
  const content = (0, import_python_analysis6.stringifyManifest)(manifest.data);
6032
- (0, import_fs9.writeFileSync)(tempPyproject, content, "utf8");
6242
+ (0, import_fs10.writeFileSync)(tempPyproject, content, "utf8");
6033
6243
  manifestPath = tempPyproject;
6034
- (0, import_build_utils12.debug)(
6244
+ (0, import_build_utils13.debug)(
6035
6245
  `Wrote converted ${manifest.origin.kind} manifest to ${tempPyproject}`
6036
6246
  );
6037
6247
  }
@@ -6064,7 +6274,7 @@ async function syncDependencies({
6064
6274
  for (const [channel, chunk] of captured) {
6065
6275
  (channel === "stdout" ? writeOut : writeErr)(chunk.toString());
6066
6276
  }
6067
- throw new import_build_utils12.NowBuildError({
6277
+ throw new import_build_utils13.NowBuildError({
6068
6278
  code: "PYTHON_DEPENDENCY_SYNC_FAILED",
6069
6279
  message: `Failed to install Python dependencies from ${manifestType}: ${err instanceof Error ? err.message : String(err)}`
6070
6280
  });
@@ -6079,14 +6289,14 @@ async function runSync({
6079
6289
  onStdout,
6080
6290
  onStderr
6081
6291
  }) {
6082
- const projectDir = (0, import_path9.dirname)(manifestPath);
6292
+ const projectDir = (0, import_path10.dirname)(manifestPath);
6083
6293
  const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
6084
6294
  let spawnCmd;
6085
6295
  let spawnArgs;
6086
6296
  switch (manifestType) {
6087
6297
  case "uv.lock": {
6088
6298
  if (!uvPath) {
6089
- throw new import_build_utils12.NowBuildError({
6299
+ throw new import_build_utils13.NowBuildError({
6090
6300
  code: "PYTHON_DEPENDENCY_SYNC_FAILED",
6091
6301
  message: "uv is required to install dependencies from uv.lock.",
6092
6302
  link: "https://docs.astral.sh/uv/getting-started/installation/",
@@ -6108,11 +6318,11 @@ async function runSync({
6108
6318
  break;
6109
6319
  }
6110
6320
  default:
6111
- (0, import_build_utils12.debug)(`Unknown manifest type: ${manifestType}`);
6321
+ (0, import_build_utils13.debug)(`Unknown manifest type: ${manifestType}`);
6112
6322
  return;
6113
6323
  }
6114
6324
  await new Promise((resolve3, reject) => {
6115
- (0, import_build_utils12.debug)(`Running "${spawnCmd} ${spawnArgs.join(" ")}" in ${projectDir}...`);
6325
+ (0, import_build_utils13.debug)(`Running "${spawnCmd} ${spawnArgs.join(" ")}" in ${projectDir}...`);
6116
6326
  const child = (0, import_child_process2.spawn)(spawnCmd, spawnArgs, {
6117
6327
  cwd: projectDir,
6118
6328
  env: getProtectedUvEnv(env),
@@ -6156,7 +6366,7 @@ async function installVercelRuntime({
6156
6366
  onStdout,
6157
6367
  onStderr
6158
6368
  }) {
6159
- const targetDir = (0, import_path9.join)(workPath, ".vercel", "python");
6369
+ const targetDir = (0, import_path10.join)(workPath, ".vercel", "python");
6160
6370
  let pending = PENDING_RUNTIME_INSTALLS.get(targetDir);
6161
6371
  if (!pending) {
6162
6372
  pending = doInstallVercelRuntime({
@@ -6182,8 +6392,8 @@ async function doInstallVercelRuntime({
6182
6392
  onStdout,
6183
6393
  onStderr
6184
6394
  }) {
6185
- (0, import_fs9.mkdirSync)(targetDir, { recursive: true });
6186
- const localRuntimeDir = (0, import_path9.join)(
6395
+ (0, import_fs10.mkdirSync)(targetDir, { recursive: true });
6396
+ const localRuntimeDir = (0, import_path10.join)(
6187
6397
  __dirname,
6188
6398
  "..",
6189
6399
  "..",
@@ -6191,21 +6401,21 @@ async function doInstallVercelRuntime({
6191
6401
  "python",
6192
6402
  "vercel-runtime"
6193
6403
  );
6194
- const isLocalDev = (0, import_fs9.existsSync)((0, import_path9.join)(localRuntimeDir, "pyproject.toml"));
6404
+ const isLocalDev = (0, import_fs10.existsSync)((0, import_path10.join)(localRuntimeDir, "pyproject.toml"));
6195
6405
  const runtimeDep = env.VERCEL_RUNTIME_PYTHON || (isLocalDev ? localRuntimeDir : `vercel-runtime==${VERCEL_RUNTIME_VERSION}`);
6196
6406
  if (!isLocalDev && !env.VERCEL_RUNTIME_PYTHON) {
6197
- const distInfo = (0, import_path9.join)(
6407
+ const distInfo = (0, import_path10.join)(
6198
6408
  targetDir,
6199
6409
  `vercel_runtime-${VERCEL_RUNTIME_VERSION}.dist-info`
6200
6410
  );
6201
- if ((0, import_fs9.existsSync)(distInfo)) {
6202
- (0, import_build_utils12.debug)(
6411
+ if ((0, import_fs10.existsSync)(distInfo)) {
6412
+ (0, import_build_utils13.debug)(
6203
6413
  `vercel-runtime ${VERCEL_RUNTIME_VERSION} already installed, skipping`
6204
6414
  );
6205
6415
  return;
6206
6416
  }
6207
6417
  }
6208
- (0, import_build_utils12.debug)(
6418
+ (0, import_build_utils13.debug)(
6209
6419
  `Installing vercel-runtime into ${targetDir} (type: ${isLocalDev ? "local" : "pypi"}, source: ${runtimeDep})`
6210
6420
  );
6211
6421
  const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
@@ -6220,14 +6430,14 @@ async function doInstallVercelRuntime({
6220
6430
  if (onStdout) {
6221
6431
  onStdout(data);
6222
6432
  } else {
6223
- (0, import_build_utils12.debug)(data.toString());
6433
+ (0, import_build_utils13.debug)(data.toString());
6224
6434
  }
6225
6435
  });
6226
6436
  child.stderr?.on("data", (data) => {
6227
6437
  if (onStderr) {
6228
6438
  onStderr(data);
6229
6439
  } else {
6230
- (0, import_build_utils12.debug)(data.toString());
6440
+ (0, import_build_utils13.debug)(data.toString());
6231
6441
  }
6232
6442
  });
6233
6443
  child.on("error", reject);
@@ -6252,7 +6462,7 @@ async function installVercelWorkers({
6252
6462
  onStdout,
6253
6463
  onStderr
6254
6464
  }) {
6255
- const targetDir = (0, import_path9.join)(workPath, ".vercel", "python");
6465
+ const targetDir = (0, import_path10.join)(workPath, ".vercel", "python");
6256
6466
  let pending = PENDING_WORKERS_INSTALLS.get(targetDir);
6257
6467
  if (!pending) {
6258
6468
  pending = doInstallVercelWorkers({
@@ -6278,8 +6488,8 @@ async function doInstallVercelWorkers({
6278
6488
  onStdout,
6279
6489
  onStderr
6280
6490
  }) {
6281
- (0, import_fs9.mkdirSync)(targetDir, { recursive: true });
6282
- const localWorkersDir = (0, import_path9.join)(
6491
+ (0, import_fs10.mkdirSync)(targetDir, { recursive: true });
6492
+ const localWorkersDir = (0, import_path10.join)(
6283
6493
  __dirname,
6284
6494
  "..",
6285
6495
  "..",
@@ -6287,21 +6497,21 @@ async function doInstallVercelWorkers({
6287
6497
  "python",
6288
6498
  "vercel-workers"
6289
6499
  );
6290
- const isLocalDev = (0, import_fs9.existsSync)((0, import_path9.join)(localWorkersDir, "pyproject.toml"));
6500
+ const isLocalDev = (0, import_fs10.existsSync)((0, import_path10.join)(localWorkersDir, "pyproject.toml"));
6291
6501
  const workersDep = env.VERCEL_WORKERS_PYTHON || (isLocalDev ? localWorkersDir : `vercel-workers==${VERCEL_WORKERS_VERSION}`);
6292
6502
  if (!isLocalDev && !env.VERCEL_WORKERS_PYTHON) {
6293
- const distInfo = (0, import_path9.join)(
6503
+ const distInfo = (0, import_path10.join)(
6294
6504
  targetDir,
6295
6505
  `vercel_workers-${VERCEL_WORKERS_VERSION}.dist-info`
6296
6506
  );
6297
- if ((0, import_fs9.existsSync)(distInfo)) {
6298
- (0, import_build_utils12.debug)(
6507
+ if ((0, import_fs10.existsSync)(distInfo)) {
6508
+ (0, import_build_utils13.debug)(
6299
6509
  `vercel-workers ${VERCEL_WORKERS_VERSION} already installed, skipping`
6300
6510
  );
6301
6511
  return;
6302
6512
  }
6303
6513
  }
6304
- (0, import_build_utils12.debug)(
6514
+ (0, import_build_utils13.debug)(
6305
6515
  `Installing vercel-workers into ${targetDir} (type: ${isLocalDev ? "local" : "pypi"}, source: ${workersDep})`
6306
6516
  );
6307
6517
  const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
@@ -6316,14 +6526,14 @@ async function doInstallVercelWorkers({
6316
6526
  if (onStdout) {
6317
6527
  onStdout(data);
6318
6528
  } else {
6319
- (0, import_build_utils12.debug)(data.toString());
6529
+ (0, import_build_utils13.debug)(data.toString());
6320
6530
  }
6321
6531
  });
6322
6532
  child.stderr?.on("data", (data) => {
6323
6533
  if (onStderr) {
6324
6534
  onStderr(data);
6325
6535
  } else {
6326
- (0, import_build_utils12.debug)(data.toString());
6536
+ (0, import_build_utils13.debug)(data.toString());
6327
6537
  }
6328
6538
  });
6329
6539
  child.on("error", reject);
@@ -6353,12 +6563,12 @@ function installGlobalCleanupHandlers() {
6353
6563
  try {
6354
6564
  process.kill(info.pid, "SIGTERM");
6355
6565
  } catch (err) {
6356
- (0, import_build_utils12.debug)(`Error sending SIGTERM to ${info.pid}: ${err}`);
6566
+ (0, import_build_utils13.debug)(`Error sending SIGTERM to ${info.pid}: ${err}`);
6357
6567
  }
6358
6568
  try {
6359
6569
  process.kill(info.pid, "SIGKILL");
6360
6570
  } catch (err) {
6361
- (0, import_build_utils12.debug)(`Error sending SIGKILL to ${info.pid}: ${err}`);
6571
+ (0, import_build_utils13.debug)(`Error sending SIGKILL to ${info.pid}: ${err}`);
6362
6572
  }
6363
6573
  PERSISTENT_SERVERS.delete(key);
6364
6574
  }
@@ -6366,7 +6576,7 @@ function installGlobalCleanupHandlers() {
6366
6576
  try {
6367
6577
  restoreWarnings();
6368
6578
  } catch (err) {
6369
- (0, import_build_utils12.debug)(`Error restoring warnings: ${err}`);
6579
+ (0, import_build_utils13.debug)(`Error restoring warnings: ${err}`);
6370
6580
  }
6371
6581
  restoreWarnings = null;
6372
6582
  }
@@ -6383,55 +6593,55 @@ function installGlobalCleanupHandlers() {
6383
6593
  }
6384
6594
  function createDevShim(workPath, entry, modulePath, serviceName, framework, variableName) {
6385
6595
  try {
6386
- const vercelPythonDir = serviceName ? (0, import_path9.join)(workPath, ".vercel", "python", "services", serviceName) : (0, import_path9.join)(workPath, ".vercel", "python");
6387
- (0, import_fs9.mkdirSync)(vercelPythonDir, { recursive: true });
6596
+ const vercelPythonDir = serviceName ? (0, import_path10.join)(workPath, ".vercel", "python", "services", serviceName) : (0, import_path10.join)(workPath, ".vercel", "python");
6597
+ (0, import_fs10.mkdirSync)(vercelPythonDir, { recursive: true });
6388
6598
  let qualifiedModule = modulePath;
6389
6599
  let extraPythonPath;
6390
- if ((0, import_fs9.existsSync)((0, import_path9.join)(workPath, "__init__.py"))) {
6391
- const pkgName = (0, import_path9.basename)(workPath);
6600
+ if ((0, import_fs10.existsSync)((0, import_path10.join)(workPath, "__init__.py"))) {
6601
+ const pkgName = (0, import_path10.basename)(workPath);
6392
6602
  qualifiedModule = `${pkgName}.${modulePath}`;
6393
- extraPythonPath = (0, import_path9.dirname)(workPath);
6603
+ extraPythonPath = (0, import_path10.dirname)(workPath);
6394
6604
  }
6395
- const entryAbs = (0, import_path9.join)(workPath, entry);
6396
- const shimPath = (0, import_path9.join)(vercelPythonDir, `${DEV_SHIM_MODULE}.py`);
6397
- const templatePath = (0, import_path9.join)(
6605
+ const entryAbs = (0, import_path10.join)(workPath, entry);
6606
+ const shimPath = (0, import_path10.join)(vercelPythonDir, `${DEV_SHIM_MODULE}.py`);
6607
+ const templatePath = (0, import_path10.join)(
6398
6608
  __dirname,
6399
6609
  "..",
6400
6610
  "templates",
6401
6611
  `${DEV_SHIM_MODULE}.py`
6402
6612
  );
6403
- const template = (0, import_fs9.readFileSync)(templatePath, "utf8");
6613
+ const template = (0, import_fs10.readFileSync)(templatePath, "utf8");
6404
6614
  const shimSource = template.replace(/__VC_DEV_MODULE_NAME__/g, qualifiedModule).replace(/__VC_DEV_ENTRY_ABS__/g, entryAbs).replace(/__VC_DEV_FRAMEWORK__/g, framework).replace(/__VC_DEV_VARIABLE_NAME__/g, variableName);
6405
- (0, import_fs9.writeFileSync)(shimPath, shimSource, "utf8");
6406
- (0, import_build_utils12.debug)(`Prepared Python dev shim at ${shimPath}`);
6615
+ (0, import_fs10.writeFileSync)(shimPath, shimSource, "utf8");
6616
+ (0, import_build_utils13.debug)(`Prepared Python dev shim at ${shimPath}`);
6407
6617
  return {
6408
6618
  module: DEV_SHIM_MODULE,
6409
6619
  extraPythonPath,
6410
6620
  shimDir: vercelPythonDir
6411
6621
  };
6412
6622
  } catch (err) {
6413
- (0, import_build_utils12.debug)(`Failed to prepare dev shim: ${err?.message || err}`);
6623
+ (0, import_build_utils13.debug)(`Failed to prepare dev shim: ${err?.message || err}`);
6414
6624
  return null;
6415
6625
  }
6416
6626
  }
6417
6627
  async function getMultiServicePythonRunner(workPath, env, systemPython, uvPath) {
6418
6628
  const { pythonCmd, venvRoot } = useVirtualEnv(workPath, env, systemPython);
6419
6629
  if (venvRoot) {
6420
- (0, import_build_utils12.debug)(`Using existing virtualenv at ${venvRoot} for multi-service dev`);
6630
+ (0, import_build_utils13.debug)(`Using existing virtualenv at ${venvRoot} for multi-service dev`);
6421
6631
  return { command: pythonCmd, args: [] };
6422
6632
  }
6423
- const venvPath = (0, import_path9.join)(workPath, ".venv");
6633
+ const venvPath = (0, import_path10.join)(workPath, ".venv");
6424
6634
  await ensureVenv({
6425
6635
  pythonVersion: { pythonPath: systemPython },
6426
6636
  venvPath,
6427
6637
  uvPath,
6428
6638
  quiet: true
6429
6639
  });
6430
- (0, import_build_utils12.debug)(`Created virtualenv at ${venvPath} for multi-service dev`);
6640
+ (0, import_build_utils13.debug)(`Created virtualenv at ${venvPath} for multi-service dev`);
6431
6641
  const pythonBin = getVenvPythonBin(venvPath);
6432
6642
  const binDir = getVenvBinDir(venvPath);
6433
6643
  env.VIRTUAL_ENV = venvPath;
6434
- env.PATH = `${binDir}${import_path9.delimiter}${env.PATH || ""}`;
6644
+ env.PATH = `${binDir}${import_path10.delimiter}${env.PATH || ""}`;
6435
6645
  return { command: pythonBin, args: [] };
6436
6646
  }
6437
6647
  var startDevServer = async (opts) => {
@@ -6485,7 +6695,7 @@ var startDevServer = async (opts) => {
6485
6695
  filePath: entrypoint,
6486
6696
  // Schedule-triggered services create their own "app" wrapper dynamically.
6487
6697
  // Other services use handlerFunction as the entrypoint variable name.
6488
- varName: service && (0, import_build_utils12.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
6698
+ varName: service && (0, import_build_utils13.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
6489
6699
  } : void 0,
6490
6700
  service
6491
6701
  );
@@ -6494,7 +6704,7 @@ var startDevServer = async (opts) => {
6494
6704
  } else {
6495
6705
  const hookResult = await runFrameworkHook(framework, {
6496
6706
  pythonEnv: env,
6497
- projectDir: (0, import_path9.join)(workPath, detected?.baseDir ?? ""),
6707
+ projectDir: (0, import_path10.join)(workPath, detected?.baseDir ?? ""),
6498
6708
  workPath,
6499
6709
  entrypoint,
6500
6710
  detected: detected ?? void 0
@@ -6505,7 +6715,7 @@ var startDevServer = async (opts) => {
6505
6715
  if (detected?.error) {
6506
6716
  throw detected.error;
6507
6717
  }
6508
- throw new import_build_utils12.NowBuildError({
6718
+ throw new import_build_utils13.NowBuildError({
6509
6719
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
6510
6720
  message: "No Python entrypoint could be detected. Please specify an entrypoint file."
6511
6721
  });
@@ -6534,7 +6744,7 @@ var startDevServer = async (opts) => {
6534
6744
  const yellow = "\x1B[33m";
6535
6745
  const white = "\x1B[1m";
6536
6746
  const reset = "\x1B[0m";
6537
- throw new import_build_utils12.NowBuildError({
6747
+ throw new import_build_utils13.NowBuildError({
6538
6748
  code: "PYTHON_EXTERNAL_VENV_DETECTED",
6539
6749
  message: `Detected activated venv at ${yellow}${venv}${reset}, ${white}vercel dev${reset} manages virtual environments automatically.
6540
6750
  Run ${white}deactivate${reset} and try again.`
@@ -6551,11 +6761,11 @@ Run ${white}deactivate${reset} and try again.`
6551
6761
  );
6552
6762
  spawnCommand = runner.command;
6553
6763
  spawnArgsPrefix = runner.args;
6554
- (0, import_build_utils12.debug)(
6764
+ (0, import_build_utils13.debug)(
6555
6765
  `Multi-service Python runner: ${spawnCommand} ${spawnArgsPrefix.join(" ")}`
6556
6766
  );
6557
6767
  } else if (venv) {
6558
- (0, import_build_utils12.debug)(`Running in virtualenv at ${venv}`);
6768
+ (0, import_build_utils13.debug)(`Running in virtualenv at ${venv}`);
6559
6769
  } else {
6560
6770
  const { pythonCmd: venvPythonCmd, venvRoot } = useVirtualEnv(
6561
6771
  workPath,
@@ -6564,9 +6774,9 @@ Run ${white}deactivate${reset} and try again.`
6564
6774
  );
6565
6775
  spawnCommand = venvPythonCmd;
6566
6776
  if (venvRoot) {
6567
- (0, import_build_utils12.debug)(`Using virtualenv at ${venvRoot}`);
6777
+ (0, import_build_utils13.debug)(`Using virtualenv at ${venvRoot}`);
6568
6778
  } else {
6569
- (0, import_build_utils12.debug)("No virtualenv found");
6779
+ (0, import_build_utils13.debug)("No virtualenv found");
6570
6780
  try {
6571
6781
  const yellow = "\x1B[33m";
6572
6782
  const reset = "\x1B[0m";
@@ -6630,7 +6840,7 @@ If you are using a virtual environment, activate it before running "vercel dev",
6630
6840
  const port = typeof meta.port === "number" ? meta.port : await (0, import_get_port.default)();
6631
6841
  env.PORT = `${port}`;
6632
6842
  if (entry) {
6633
- env.__VC_HANDLER_ENTRYPOINT_ABS = (0, import_path9.join)(workPath, entry);
6843
+ env.__VC_HANDLER_ENTRYPOINT_ABS = (0, import_path10.join)(workPath, entry);
6634
6844
  }
6635
6845
  const devShim = createDevShim(
6636
6846
  workPath,
@@ -6641,8 +6851,8 @@ If you are using a virtual environment, activate it before running "vercel dev",
6641
6851
  variableName ?? ""
6642
6852
  );
6643
6853
  if (devShim) {
6644
- const shimDir = devShim.shimDir || (0, import_path9.join)(workPath, ".vercel", "python");
6645
- const runtimeDir = (0, import_path9.join)(workPath, ".vercel", "python");
6854
+ const shimDir = devShim.shimDir || (0, import_path10.join)(workPath, ".vercel", "python");
6855
+ const runtimeDir = (0, import_path10.join)(workPath, ".vercel", "python");
6646
6856
  const pathParts = shimDir !== runtimeDir ? [shimDir, runtimeDir] : [shimDir];
6647
6857
  if (devShim.extraPythonPath) {
6648
6858
  pathParts.push(devShim.extraPythonPath);
@@ -6651,12 +6861,12 @@ If you are using a virtual environment, activate it before running "vercel dev",
6651
6861
  if (existingPythonPath) {
6652
6862
  pathParts.push(existingPythonPath);
6653
6863
  }
6654
- env.PYTHONPATH = pathParts.join(import_path9.delimiter);
6864
+ env.PYTHONPATH = pathParts.join(import_path10.delimiter);
6655
6865
  }
6656
6866
  const moduleToRun = devShim?.module || modulePath;
6657
6867
  const pythonArgs = ["-u", "-m", moduleToRun];
6658
6868
  const argv = [...spawnArgsPrefix, ...pythonArgs];
6659
- (0, import_build_utils12.debug)(
6869
+ (0, import_build_utils13.debug)(
6660
6870
  `Starting Python dev server (${framework}): ${spawnCommand} ${argv.join(" ")} [PORT=${port}]`
6661
6871
  );
6662
6872
  if (process.stdout.columns) {
@@ -6710,7 +6920,7 @@ If you are using a virtual environment, activate it before running "vercel dev",
6710
6920
  };
6711
6921
 
6712
6922
  // src/quirks/index.ts
6713
- var import_build_utils15 = require("@vercel/build-utils");
6923
+ var import_build_utils16 = require("@vercel/build-utils");
6714
6924
  var import_python_analysis8 = require("@vercel/python-analysis");
6715
6925
 
6716
6926
  // src/quirks/matplotlib.ts
@@ -6724,9 +6934,9 @@ var matplotlibQuirk = {
6724
6934
  };
6725
6935
 
6726
6936
  // src/quirks/litellm.ts
6727
- var import_fs10 = __toESM(require("fs"));
6728
- var import_path10 = require("path");
6729
- var import_build_utils13 = require("@vercel/build-utils");
6937
+ var import_fs11 = __toESM(require("fs"));
6938
+ var import_path11 = require("path");
6939
+ var import_build_utils14 = require("@vercel/build-utils");
6730
6940
  var LAMBDA_ROOT = "/var/task";
6731
6941
  var CONFIG_CANDIDATES = [
6732
6942
  "litellm_config.yaml",
@@ -6736,9 +6946,9 @@ var CONFIG_CANDIDATES = [
6736
6946
  ];
6737
6947
  async function findConfigFile(workPath) {
6738
6948
  for (const name of CONFIG_CANDIDATES) {
6739
- const candidate = (0, import_path10.join)(workPath, name);
6949
+ const candidate = (0, import_path11.join)(workPath, name);
6740
6950
  try {
6741
- await import_fs10.default.promises.access(candidate);
6951
+ await import_fs11.default.promises.access(candidate);
6742
6952
  return name;
6743
6953
  } catch {
6744
6954
  }
@@ -6753,32 +6963,32 @@ var litellmQuirk = {
6753
6963
  const env = {};
6754
6964
  const sitePackagesDirs = await getVenvSitePackagesDirs(ctx.venvPath);
6755
6965
  for (const sitePackages of sitePackagesDirs) {
6756
- const schemaPath = (0, import_path10.join)(
6966
+ const schemaPath = (0, import_path11.join)(
6757
6967
  sitePackages,
6758
6968
  "litellm",
6759
6969
  "proxy",
6760
6970
  "schema.prisma"
6761
6971
  );
6762
6972
  try {
6763
- await import_fs10.default.promises.access(schemaPath);
6764
- (0, import_build_utils13.debug)(`LiteLLM quirk: found schema at ${schemaPath}`);
6973
+ await import_fs11.default.promises.access(schemaPath);
6974
+ (0, import_build_utils14.debug)(`LiteLLM quirk: found schema at ${schemaPath}`);
6765
6975
  buildEnv.PRISMA_SCHEMA_PATH = schemaPath;
6766
6976
  break;
6767
6977
  } catch {
6768
6978
  }
6769
6979
  }
6770
6980
  if (!buildEnv.PRISMA_SCHEMA_PATH) {
6771
- (0, import_build_utils13.debug)("LiteLLM quirk: schema.prisma not found in any site-packages");
6981
+ (0, import_build_utils14.debug)("LiteLLM quirk: schema.prisma not found in any site-packages");
6772
6982
  }
6773
6983
  if (!process.env.CONFIG_FILE_PATH) {
6774
6984
  const configName = await findConfigFile(ctx.workPath);
6775
6985
  if (configName) {
6776
- (0, import_build_utils13.debug)(`LiteLLM quirk: found config at ${configName}`);
6777
- buildEnv.CONFIG_FILE_PATH = (0, import_path10.join)(ctx.workPath, configName);
6778
- env.CONFIG_FILE_PATH = (0, import_path10.join)(LAMBDA_ROOT, configName);
6986
+ (0, import_build_utils14.debug)(`LiteLLM quirk: found config at ${configName}`);
6987
+ buildEnv.CONFIG_FILE_PATH = (0, import_path11.join)(ctx.workPath, configName);
6988
+ env.CONFIG_FILE_PATH = (0, import_path11.join)(LAMBDA_ROOT, configName);
6779
6989
  }
6780
6990
  } else {
6781
- (0, import_build_utils13.debug)(
6991
+ (0, import_build_utils14.debug)(
6782
6992
  `LiteLLM quirk: CONFIG_FILE_PATH already set to ${process.env.CONFIG_FILE_PATH}`
6783
6993
  );
6784
6994
  }
@@ -6787,10 +6997,10 @@ var litellmQuirk = {
6787
6997
  };
6788
6998
 
6789
6999
  // src/quirks/prisma.ts
6790
- var import_fs11 = __toESM(require("fs"));
6791
- var import_path11 = require("path");
6792
- var import_execa5 = __toESM(require_execa());
6793
- var import_build_utils14 = require("@vercel/build-utils");
7000
+ var import_fs12 = __toESM(require("fs"));
7001
+ var import_path12 = require("path");
7002
+ var import_execa6 = __toESM(require_execa());
7003
+ var import_build_utils15 = require("@vercel/build-utils");
6794
7004
  var import_python_analysis7 = require("@vercel/python-analysis");
6795
7005
  function execErrorMessage(err) {
6796
7006
  if (err != null && typeof err === "object" && "stderr" in err) {
@@ -6828,22 +7038,22 @@ model DummyModel {
6828
7038
  async function findUserSchema(workPath) {
6829
7039
  const envPath = process.env.PRISMA_SCHEMA_PATH;
6830
7040
  if (envPath) {
6831
- const resolved = (0, import_path11.isAbsolute)(envPath) ? envPath : (0, import_path11.join)(workPath, envPath);
7041
+ const resolved = (0, import_path12.isAbsolute)(envPath) ? envPath : (0, import_path12.join)(workPath, envPath);
6832
7042
  try {
6833
- await import_fs11.default.promises.access(resolved);
7043
+ await import_fs12.default.promises.access(resolved);
6834
7044
  return resolved;
6835
7045
  } catch {
6836
- (0, import_build_utils14.debug)(`PRISMA_SCHEMA_PATH=${envPath} not found at ${resolved}`);
7046
+ (0, import_build_utils15.debug)(`PRISMA_SCHEMA_PATH=${envPath} not found at ${resolved}`);
6837
7047
  return null;
6838
7048
  }
6839
7049
  }
6840
7050
  const candidates = [
6841
- (0, import_path11.join)(workPath, "schema.prisma"),
6842
- (0, import_path11.join)(workPath, "prisma", "schema.prisma")
7051
+ (0, import_path12.join)(workPath, "schema.prisma"),
7052
+ (0, import_path12.join)(workPath, "prisma", "schema.prisma")
6843
7053
  ];
6844
7054
  for (const candidate of candidates) {
6845
7055
  try {
6846
- await import_fs11.default.promises.access(candidate);
7056
+ await import_fs12.default.promises.access(candidate);
6847
7057
  return candidate;
6848
7058
  } catch {
6849
7059
  }
@@ -6854,32 +7064,32 @@ async function collectFiles(dir, base) {
6854
7064
  const result = [];
6855
7065
  let entries;
6856
7066
  try {
6857
- entries = await import_fs11.default.promises.readdir(dir, { withFileTypes: true });
7067
+ entries = await import_fs12.default.promises.readdir(dir, { withFileTypes: true });
6858
7068
  } catch {
6859
7069
  return result;
6860
7070
  }
6861
7071
  for (const entry of entries) {
6862
7072
  if (entry.name === "__pycache__")
6863
7073
  continue;
6864
- const full = (0, import_path11.join)(dir, entry.name);
7074
+ const full = (0, import_path12.join)(dir, entry.name);
6865
7075
  if (entry.isDirectory()) {
6866
7076
  result.push(...await collectFiles(full, base));
6867
7077
  } else {
6868
- result.push((0, import_path11.relative)(base, full));
7078
+ result.push((0, import_path12.relative)(base, full));
6869
7079
  }
6870
7080
  }
6871
7081
  return result;
6872
7082
  }
6873
7083
  async function cleanCacheArtifacts(cacheDir, extras = []) {
6874
7084
  const paths = [
6875
- (0, import_path11.join)(cacheDir, "node_modules"),
6876
- (0, import_path11.join)(cacheDir, "package.json"),
6877
- (0, import_path11.join)(cacheDir, "package-lock.json"),
7085
+ (0, import_path12.join)(cacheDir, "node_modules"),
7086
+ (0, import_path12.join)(cacheDir, "package.json"),
7087
+ (0, import_path12.join)(cacheDir, "package-lock.json"),
6878
7088
  ...extras
6879
7089
  ];
6880
7090
  for (const p of paths) {
6881
7091
  try {
6882
- await import_fs11.default.promises.rm(p, { recursive: true, force: true });
7092
+ await import_fs12.default.promises.rm(p, { recursive: true, force: true });
6883
7093
  } catch (err) {
6884
7094
  console.warn(
6885
7095
  `could not clean up ${p}: ${err instanceof Error ? err.message : String(err)}`
@@ -6889,7 +7099,7 @@ async function cleanCacheArtifacts(cacheDir, extras = []) {
6889
7099
  }
6890
7100
  async function isClientGenerated(pythonPath, env) {
6891
7101
  try {
6892
- await (0, import_execa5.default)(pythonPath, ["-c", "import prisma.client"], {
7102
+ await (0, import_execa6.default)(pythonPath, ["-c", "import prisma.client"], {
6893
7103
  env,
6894
7104
  stdio: "pipe"
6895
7105
  });
@@ -6903,7 +7113,7 @@ var prismaQuirk = {
6903
7113
  async run(ctx) {
6904
7114
  const { venvPath, pythonEnv, workPath } = ctx;
6905
7115
  const pythonPath = getVenvPythonBin(venvPath);
6906
- const runtimeCacheDir = (0, import_path11.join)(
7116
+ const runtimeCacheDir = (0, import_path12.join)(
6907
7117
  LAMBDA_ROOT2,
6908
7118
  resolveVendorDir(),
6909
7119
  "prisma",
@@ -6913,7 +7123,7 @@ var prismaQuirk = {
6913
7123
  let sitePackages;
6914
7124
  for (const dir of sitePackagesDirs) {
6915
7125
  try {
6916
- await import_fs11.default.promises.access((0, import_path11.join)(dir, "prisma"));
7126
+ await import_fs12.default.promises.access((0, import_path12.join)(dir, "prisma"));
6917
7127
  sitePackages = dir;
6918
7128
  break;
6919
7129
  } catch {
@@ -6925,21 +7135,21 @@ var prismaQuirk = {
6925
7135
  );
6926
7136
  return {};
6927
7137
  }
6928
- const cacheDir = (0, import_path11.join)(sitePackages, "prisma", "__bincache__");
6929
- await import_fs11.default.promises.mkdir(cacheDir, { recursive: true });
7138
+ const cacheDir = (0, import_path12.join)(sitePackages, "prisma", "__bincache__");
7139
+ await import_fs12.default.promises.mkdir(cacheDir, { recursive: true });
6930
7140
  const generateEnv = {
6931
7141
  ...pythonEnv,
6932
7142
  PRISMA_BINARY_CACHE_DIR: cacheDir
6933
7143
  };
6934
- const generatedDir = (0, import_path11.join)(workPath, "_prisma_generated");
6935
- const dummySchemaPath = (0, import_path11.join)(workPath, DUMMY_SCHEMA_NAME);
6936
- await import_fs11.default.promises.writeFile(
7144
+ const generatedDir = (0, import_path12.join)(workPath, "_prisma_generated");
7145
+ const dummySchemaPath = (0, import_path12.join)(workPath, DUMMY_SCHEMA_NAME);
7146
+ await import_fs12.default.promises.writeFile(
6937
7147
  dummySchemaPath,
6938
7148
  buildDummySchema(generatedDir)
6939
7149
  );
6940
- (0, import_build_utils14.debug)(`Running prisma generate (dummy) with cache dir: ${cacheDir}`);
7150
+ (0, import_build_utils15.debug)(`Running prisma generate (dummy) with cache dir: ${cacheDir}`);
6941
7151
  try {
6942
- const dummyResult = await (0, import_execa5.default)(
7152
+ const dummyResult = await (0, import_execa6.default)(
6943
7153
  pythonPath,
6944
7154
  ["-m", "prisma", "generate", `--schema=${dummySchemaPath}`],
6945
7155
  {
@@ -6949,11 +7159,11 @@ var prismaQuirk = {
6949
7159
  }
6950
7160
  );
6951
7161
  if (dummyResult.stdout)
6952
- (0, import_build_utils14.debug)(`prisma generate (dummy) stdout: ${dummyResult.stdout}`);
7162
+ (0, import_build_utils15.debug)(`prisma generate (dummy) stdout: ${dummyResult.stdout}`);
6953
7163
  if (dummyResult.stderr)
6954
- (0, import_build_utils14.debug)(`prisma generate (dummy) stderr: ${dummyResult.stderr}`);
7164
+ (0, import_build_utils15.debug)(`prisma generate (dummy) stderr: ${dummyResult.stderr}`);
6955
7165
  } catch (err) {
6956
- throw new import_build_utils14.NowBuildError({
7166
+ throw new import_build_utils15.NowBuildError({
6957
7167
  code: "PRISMA_GENERATE_FAILED",
6958
7168
  message: `Prisma engine download failed during \`prisma generate\`. Check that your prisma version is compatible with this Python version.
6959
7169
  ` + execErrorMessage(err)
@@ -6961,47 +7171,47 @@ var prismaQuirk = {
6961
7171
  }
6962
7172
  const srcBinaryPrefix = `query-engine-${getLambdaBinaryTarget()}`;
6963
7173
  const runtimeName = `prisma-query-engine-rhel-openssl-${RUNTIME_OPENSSL_VERSION}.x`;
6964
- const nodeModulesDir = (0, import_path11.join)(cacheDir, "node_modules", "prisma");
7174
+ const nodeModulesDir = (0, import_path12.join)(cacheDir, "node_modules", "prisma");
6965
7175
  let engineCopied = false;
6966
7176
  try {
6967
- const entries = await import_fs11.default.promises.readdir(nodeModulesDir);
7177
+ const entries = await import_fs12.default.promises.readdir(nodeModulesDir);
6968
7178
  for (const entry of entries) {
6969
7179
  if (!entry.startsWith(srcBinaryPrefix))
6970
7180
  continue;
6971
- const srcPath = (0, import_path11.join)(nodeModulesDir, entry);
6972
- const destPath = (0, import_path11.join)(cacheDir, runtimeName);
7181
+ const srcPath = (0, import_path12.join)(nodeModulesDir, entry);
7182
+ const destPath = (0, import_path12.join)(cacheDir, runtimeName);
6973
7183
  try {
6974
- await import_fs11.default.promises.access(destPath);
6975
- (0, import_build_utils14.debug)(`Engine binary: ${runtimeName} already exists, skipping`);
7184
+ await import_fs12.default.promises.access(destPath);
7185
+ (0, import_build_utils15.debug)(`Engine binary: ${runtimeName} already exists, skipping`);
6976
7186
  } catch {
6977
- (0, import_build_utils14.debug)(`Engine binary: copying ${entry} -> ${runtimeName}`);
6978
- await import_fs11.default.promises.copyFile(srcPath, destPath);
7187
+ (0, import_build_utils15.debug)(`Engine binary: copying ${entry} -> ${runtimeName}`);
7188
+ await import_fs12.default.promises.copyFile(srcPath, destPath);
6979
7189
  }
6980
7190
  engineCopied = true;
6981
7191
  }
6982
7192
  } catch (err) {
6983
- throw new import_build_utils14.NowBuildError({
7193
+ throw new import_build_utils15.NowBuildError({
6984
7194
  code: "PRISMA_ENGINE_NOT_FOUND",
6985
7195
  message: `could not read Prisma engine directory "${nodeModulesDir}". This may indicate an incompatible prisma version.
6986
7196
  ` + (err instanceof Error ? err.message : String(err))
6987
7197
  });
6988
7198
  }
6989
7199
  if (!engineCopied) {
6990
- throw new import_build_utils14.NowBuildError({
7200
+ throw new import_build_utils15.NowBuildError({
6991
7201
  code: "PRISMA_ENGINE_NOT_FOUND",
6992
7202
  message: `could not find engine binary matching "${srcBinaryPrefix}*" in "${nodeModulesDir}". This may indicate an incompatible prisma version or an unsupported platform (${process.arch}).`
6993
7203
  });
6994
7204
  }
6995
- const shimPath = (0, import_path11.join)(cacheDir, "openssl");
6996
- await import_fs11.default.promises.writeFile(
7205
+ const shimPath = (0, import_path12.join)(cacheDir, "openssl");
7206
+ await import_fs12.default.promises.writeFile(
6997
7207
  shimPath,
6998
7208
  `#!/bin/sh
6999
7209
  echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIME_OPENSSL_VERSION}.0)"
7000
7210
  `
7001
7211
  );
7002
- await import_fs11.default.promises.chmod(shimPath, 493);
7212
+ await import_fs12.default.promises.chmod(shimPath, 493);
7003
7213
  for (const p of [generatedDir, dummySchemaPath]) {
7004
- await import_fs11.default.promises.rm(p, { recursive: true, force: true });
7214
+ await import_fs12.default.promises.rm(p, { recursive: true, force: true });
7005
7215
  }
7006
7216
  await cleanCacheArtifacts(cacheDir);
7007
7217
  const generateMode = (process.env.VERCEL_PRISMA_GENERATE_CLIENT ?? "auto").toLowerCase();
@@ -7014,16 +7224,16 @@ echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIM
7014
7224
  pythonEnv
7015
7225
  );
7016
7226
  if (clientAlreadyGenerated) {
7017
- (0, import_build_utils14.debug)(
7227
+ (0, import_build_utils15.debug)(
7018
7228
  "Prisma quirk: client already generated, skipping user schema generate"
7019
7229
  );
7020
7230
  shouldGenerate = false;
7021
7231
  }
7022
7232
  }
7023
7233
  if (shouldGenerate) {
7024
- (0, import_build_utils14.debug)(`Running prisma generate with user schema: ${userSchema}`);
7234
+ (0, import_build_utils15.debug)(`Running prisma generate with user schema: ${userSchema}`);
7025
7235
  try {
7026
- const userResult = await (0, import_execa5.default)(
7236
+ const userResult = await (0, import_execa6.default)(
7027
7237
  pythonPath,
7028
7238
  ["-m", "prisma", "generate", `--schema=${userSchema}`],
7029
7239
  {
@@ -7033,11 +7243,11 @@ echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIM
7033
7243
  }
7034
7244
  );
7035
7245
  if (userResult.stdout)
7036
- (0, import_build_utils14.debug)(`prisma generate stdout: ${userResult.stdout}`);
7246
+ (0, import_build_utils15.debug)(`prisma generate stdout: ${userResult.stdout}`);
7037
7247
  if (userResult.stderr)
7038
- (0, import_build_utils14.debug)(`prisma generate stderr: ${userResult.stderr}`);
7248
+ (0, import_build_utils15.debug)(`prisma generate stderr: ${userResult.stderr}`);
7039
7249
  } catch (err) {
7040
- throw new import_build_utils14.NowBuildError({
7250
+ throw new import_build_utils15.NowBuildError({
7041
7251
  code: "PRISMA_GENERATE_FAILED",
7042
7252
  message: `\`prisma generate\` failed for schema "${userSchema}".
7043
7253
  ` + execErrorMessage(err)
@@ -7048,12 +7258,12 @@ echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIM
7048
7258
  }
7049
7259
  try {
7050
7260
  const allFiles = await collectFiles(
7051
- (0, import_path11.join)(sitePackages, "prisma"),
7261
+ (0, import_path12.join)(sitePackages, "prisma"),
7052
7262
  sitePackages
7053
7263
  );
7054
7264
  const count = await (0, import_python_analysis7.extendDistRecord)(sitePackages, "prisma", allFiles);
7055
7265
  if (count > 0) {
7056
- (0, import_build_utils14.debug)(`Appended ${count} entries to prisma RECORD`);
7266
+ (0, import_build_utils15.debug)(`Appended ${count} entries to prisma RECORD`);
7057
7267
  }
7058
7268
  } catch (err) {
7059
7269
  console.warn(
@@ -7147,13 +7357,13 @@ async function runQuirks(ctx) {
7147
7357
  (0, import_python_analysis8.normalizePackageName)(quirk.dependency)
7148
7358
  );
7149
7359
  if (!installed) {
7150
- (0, import_build_utils15.debug)(`Quirk "${quirk.dependency}": not installed, skipping`);
7360
+ (0, import_build_utils16.debug)(`Quirk "${quirk.dependency}": not installed, skipping`);
7151
7361
  }
7152
7362
  return installed;
7153
7363
  });
7154
7364
  const sorted = toposortQuirks(activated);
7155
7365
  for (const quirk of sorted) {
7156
- (0, import_build_utils15.debug)(`Quirk "${quirk.dependency}": detected, running fix-up`);
7366
+ (0, import_build_utils16.debug)(`Quirk "${quirk.dependency}": detected, running fix-up`);
7157
7367
  const result = await quirk.run(ctx);
7158
7368
  if (result.env) {
7159
7369
  Object.assign(mergedEnv, result.env);
@@ -7174,14 +7384,14 @@ async function runQuirks(ctx) {
7174
7384
  }
7175
7385
 
7176
7386
  // src/django.ts
7177
- var import_fs12 = __toESM(require("fs"));
7178
- var import_path12 = require("path");
7179
- var import_execa6 = __toESM(require_execa());
7180
- var import_build_utils16 = require("@vercel/build-utils");
7181
- var scriptPath2 = (0, import_path12.join)(__dirname, "..", "templates", "vc_django_settings.py");
7182
- var script2 = import_fs12.default.readFileSync(scriptPath2, "utf-8");
7387
+ var import_fs13 = __toESM(require("fs"));
7388
+ var import_path13 = require("path");
7389
+ var import_execa7 = __toESM(require_execa());
7390
+ var import_build_utils17 = require("@vercel/build-utils");
7391
+ var scriptPath2 = (0, import_path13.join)(__dirname, "..", "templates", "vc_django_settings.py");
7392
+ var script2 = import_fs13.default.readFileSync(scriptPath2, "utf-8");
7183
7393
  async function getDjangoSettings(projectDir, env) {
7184
- const { stdout } = await (0, import_execa6.default)("python", ["-c", script2], {
7394
+ const { stdout } = await (0, import_execa7.default)("python", ["-c", script2], {
7185
7395
  env,
7186
7396
  cwd: projectDir
7187
7397
  });
@@ -7207,21 +7417,21 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7207
7417
  const installedApps = djangoSettings["INSTALLED_APPS"] ?? [];
7208
7418
  const staticfilesDirs = djangoSettings["STATICFILES_DIRS"] ?? [];
7209
7419
  const staticSourceDirs = [
7210
- ...installedApps.map((app) => (0, import_path12.join)(workPath, ...app.split("."), "static")),
7420
+ ...installedApps.map((app) => (0, import_path13.join)(workPath, ...app.split("."), "static")),
7211
7421
  // TODO: Deal with optional prefixes in STATICFILES_DIRS.
7212
7422
  ...staticfilesDirs.map((d) => Array.isArray(d) ? d[1] : d)
7213
- ].filter((d) => import_fs12.default.existsSync(d));
7423
+ ].filter((d) => import_fs13.default.existsSync(d));
7214
7424
  if (storageBackend.startsWith("storages.backends.")) {
7215
7425
  console.log(
7216
7426
  "django-storages detected \u2014 running collectstatic with original settings"
7217
7427
  );
7218
- await (0, import_execa6.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7428
+ await (0, import_execa7.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7219
7429
  env: { ...env, DJANGO_SETTINGS_MODULE: settingsModule },
7220
7430
  cwd: workPath
7221
7431
  });
7222
7432
  return {
7223
7433
  staticSourceDirs,
7224
- staticRoot: staticRoot ? (0, import_path12.resolve)(workPath, staticRoot) : null,
7434
+ staticRoot: staticRoot ? (0, import_path13.resolve)(workPath, staticRoot) : null,
7225
7435
  cdnOutputDir: null,
7226
7436
  manifestRelPath: null
7227
7437
  };
@@ -7233,9 +7443,9 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7233
7443
  return null;
7234
7444
  }
7235
7445
  const staticUrlPath = staticUrl.replace(/^\/|\/$/g, "") || "static";
7236
- const staticOutputDir = (0, import_path12.join)(outputStaticDir, staticUrlPath);
7237
- await import_fs12.default.promises.mkdir(staticOutputDir, { recursive: true });
7238
- const shimPath = (0, import_path12.join)(workPath, "_vercel_collectstatic_settings.py");
7446
+ const staticOutputDir = (0, import_path13.join)(outputStaticDir, staticUrlPath);
7447
+ await import_fs13.default.promises.mkdir(staticOutputDir, { recursive: true });
7448
+ const shimPath = (0, import_path13.join)(workPath, "_vercel_collectstatic_settings.py");
7239
7449
  const shimLines = [
7240
7450
  `from ${settingsModule} import *`,
7241
7451
  `STATIC_ROOT = ${JSON.stringify(staticOutputDir)}`
@@ -7243,10 +7453,10 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7243
7453
  if (whitenoiseUseFinders) {
7244
7454
  shimLines.push(`WHITENOISE_USE_FINDERS = False`);
7245
7455
  }
7246
- await import_fs12.default.promises.writeFile(shimPath, shimLines.join("\n") + "\n");
7456
+ await import_fs13.default.promises.writeFile(shimPath, shimLines.join("\n") + "\n");
7247
7457
  try {
7248
7458
  console.log("Running collectstatic...");
7249
- await (0, import_execa6.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7459
+ await (0, import_execa7.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7250
7460
  env: {
7251
7461
  ...env,
7252
7462
  DJANGO_SETTINGS_MODULE: "_vercel_collectstatic_settings"
@@ -7254,7 +7464,7 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7254
7464
  cwd: workPath
7255
7465
  });
7256
7466
  } finally {
7257
- await import_fs12.default.promises.unlink(shimPath).catch(() => {
7467
+ await import_fs13.default.promises.unlink(shimPath).catch(() => {
7258
7468
  });
7259
7469
  }
7260
7470
  const MANIFEST_STORAGE_BACKENDS = [
@@ -7263,17 +7473,17 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7263
7473
  ];
7264
7474
  let manifestRelPath = null;
7265
7475
  if (MANIFEST_STORAGE_BACKENDS.includes(storageBackend) && staticRoot) {
7266
- const manifestSrc = (0, import_path12.join)(staticOutputDir, "staticfiles.json");
7267
- const resolvedStaticRoot = (0, import_path12.resolve)(workPath, staticRoot);
7268
- const manifestDest = (0, import_path12.join)(resolvedStaticRoot, "staticfiles.json");
7269
- await import_fs12.default.promises.mkdir(resolvedStaticRoot, { recursive: true });
7270
- await import_fs12.default.promises.copyFile(manifestSrc, manifestDest);
7271
- manifestRelPath = (0, import_path12.relative)(workPath, manifestDest);
7272
- (0, import_build_utils16.debug)(`Copied staticfiles.json to ${manifestDest} for Lambda bundle`);
7476
+ const manifestSrc = (0, import_path13.join)(staticOutputDir, "staticfiles.json");
7477
+ const resolvedStaticRoot = (0, import_path13.resolve)(workPath, staticRoot);
7478
+ const manifestDest = (0, import_path13.join)(resolvedStaticRoot, "staticfiles.json");
7479
+ await import_fs13.default.promises.mkdir(resolvedStaticRoot, { recursive: true });
7480
+ await import_fs13.default.promises.copyFile(manifestSrc, manifestDest);
7481
+ manifestRelPath = (0, import_path13.relative)(workPath, manifestDest);
7482
+ (0, import_build_utils17.debug)(`Copied staticfiles.json to ${manifestDest} for Lambda bundle`);
7273
7483
  }
7274
7484
  return {
7275
7485
  staticSourceDirs,
7276
- staticRoot: staticRoot ? (0, import_path12.resolve)(workPath, staticRoot) : null,
7486
+ staticRoot: staticRoot ? (0, import_path13.resolve)(workPath, staticRoot) : null,
7277
7487
  cdnOutputDir: outputStaticDir,
7278
7488
  manifestRelPath
7279
7489
  };
@@ -7281,9 +7491,57 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7281
7491
 
7282
7492
  // src/index.ts
7283
7493
  var import_python_analysis9 = require("@vercel/python-analysis");
7284
- var writeFile = import_fs13.default.promises.writeFile;
7494
+ var writeFile = import_fs14.default.promises.writeFile;
7285
7495
  var PYTHON_ENTRYPOINT_DOCS_URL2 = "https://vercel.com/docs/functions/runtimes/python#python-entrypoints";
7286
7496
  var version = -1;
7497
+ function addFiles(target, source) {
7498
+ for (const [p, f] of Object.entries(source)) {
7499
+ target[p] = f;
7500
+ }
7501
+ }
7502
+ function addBytecodeWithinCapacity(files, bytecodeInfo, capacity) {
7503
+ if (!bytecodeInfo || bytecodeInfo.totalSize <= 0 || capacity <= 0) {
7504
+ return capacity;
7505
+ }
7506
+ if (bytecodeInfo.totalSize <= capacity) {
7507
+ addFiles(files, bytecodeInfo.files);
7508
+ return capacity - bytecodeInfo.totalSize;
7509
+ }
7510
+ const selected = lambdaKnapsack(bytecodeInfo.perItemSizes, capacity);
7511
+ let remainingCapacity = capacity;
7512
+ for (const p of selected) {
7513
+ const file = bytecodeInfo.files[p];
7514
+ if (!file)
7515
+ continue;
7516
+ files[p] = file;
7517
+ remainingCapacity -= bytecodeInfo.perItemSizes.get(p) ?? 0;
7518
+ }
7519
+ return remainingCapacity;
7520
+ }
7521
+ async function addVendorBytecodeWithinCapacity({
7522
+ files,
7523
+ depExternalizer,
7524
+ vendorDir,
7525
+ bytecodeInfo,
7526
+ capacity
7527
+ }) {
7528
+ if (!bytecodeInfo || bytecodeInfo.totalSize <= 0 || capacity <= 0) {
7529
+ return capacity;
7530
+ }
7531
+ if (bytecodeInfo.totalSize <= capacity) {
7532
+ addFiles(files, bytecodeInfo.files);
7533
+ return capacity - bytecodeInfo.totalSize;
7534
+ }
7535
+ const selectedPkgs = lambdaKnapsack(bytecodeInfo.perItemSizes, capacity);
7536
+ if (selectedPkgs.length === 0)
7537
+ return capacity;
7538
+ const selectedBytecode = await depExternalizer.collectBytecodeFiles({
7539
+ vendorDirName: vendorDir,
7540
+ includePackages: selectedPkgs
7541
+ });
7542
+ addFiles(files, selectedBytecode.files);
7543
+ return capacity - selectedBytecode.totalSize;
7544
+ }
7287
7545
  async function runFrameworkHook(framework, ctx) {
7288
7546
  const hook = framework ? frameworkHooks[framework] : void 0;
7289
7547
  return hook?.(ctx);
@@ -7297,7 +7555,7 @@ var frameworkHooks = {
7297
7555
  detected
7298
7556
  }) => {
7299
7557
  if (detected?.baseDir === void 0) {
7300
- (0, import_build_utils17.debug)("Django hook: no manage.py detected, skipping");
7558
+ (0, import_build_utils18.debug)("Django hook: no manage.py detected, skipping");
7301
7559
  return;
7302
7560
  }
7303
7561
  let settingsResult;
@@ -7311,13 +7569,13 @@ Hint: activate a venv or run with \`uv run vercel dev\``;
7311
7569
  } else {
7312
7570
  detail = err?.stderr || err?.message || String(err);
7313
7571
  }
7314
- throw new import_build_utils17.NowBuildError({
7572
+ throw new import_build_utils18.NowBuildError({
7315
7573
  code: "DJANGO_SETTINGS_FAILED",
7316
7574
  message: `Failed to read Django application settings from ${projectDir}/manage.py:
7317
7575
  ${detail}`
7318
7576
  });
7319
7577
  }
7320
- (0, import_build_utils17.debug)(`Django settings: ${JSON.stringify(settingsResult)}`);
7578
+ (0, import_build_utils18.debug)(`Django settings: ${JSON.stringify(settingsResult)}`);
7321
7579
  const { djangoSettings, settingsModule, djangoVersion } = settingsResult;
7322
7580
  if (djangoVersion) {
7323
7581
  console.log(`Django ${djangoVersion.join(".")} detected`);
@@ -7330,7 +7588,7 @@ ${detail}`
7330
7588
  const variableName = parts.at(-1);
7331
7589
  const rel = `${parts.slice(0, -1).join("/")}.py`;
7332
7590
  const ep = baseDir ? `${baseDir}/${rel}` : rel;
7333
- (0, import_build_utils17.debug)(`Django hook: ASGI entrypoint: ${ep} (variable: ${variableName})`);
7591
+ (0, import_build_utils18.debug)(`Django hook: ASGI entrypoint: ${ep} (variable: ${variableName})`);
7334
7592
  resolvedEntrypoint = { entrypoint: ep, variableName };
7335
7593
  } else {
7336
7594
  const wsgiApp = djangoSettings["WSGI_APPLICATION"];
@@ -7339,7 +7597,7 @@ ${detail}`
7339
7597
  const variableName = parts.at(-1);
7340
7598
  const rel = `${parts.slice(0, -1).join("/")}.py`;
7341
7599
  const ep = baseDir ? `${baseDir}/${rel}` : rel;
7342
- (0, import_build_utils17.debug)(
7600
+ (0, import_build_utils18.debug)(
7343
7601
  `Django hook: WSGI entrypoint: ${ep} (variable: ${variableName})`
7344
7602
  );
7345
7603
  resolvedEntrypoint = { entrypoint: ep, variableName };
@@ -7347,7 +7605,7 @@ ${detail}`
7347
7605
  }
7348
7606
  let djangoStatic = null;
7349
7607
  if (workPath && venvPath) {
7350
- const outputStaticDir = (0, import_path13.join)(workPath, ".vercel", "output", "static");
7608
+ const outputStaticDir = (0, import_path14.join)(workPath, ".vercel", "output", "static");
7351
7609
  djangoStatic = await runDjangoCollectStatic(
7352
7610
  venvPath,
7353
7611
  workPath,
@@ -7367,23 +7625,23 @@ async function downloadFilesInWorkPath({
7367
7625
  files,
7368
7626
  meta = {}
7369
7627
  }) {
7370
- (0, import_build_utils17.debug)("Downloading user files...");
7371
- let downloadedFiles = await (0, import_build_utils17.download)(files, workPath, meta);
7628
+ (0, import_build_utils18.debug)("Downloading user files...");
7629
+ let downloadedFiles = await (0, import_build_utils18.download)(files, workPath, meta);
7372
7630
  if (meta.isDev && entrypoint) {
7373
7631
  const normalizedEntrypoint = entrypoint.endsWith(".py") ? entrypoint : `${entrypoint}.py`;
7374
7632
  if (!hasProp(downloadedFiles, entrypoint) && !hasProp(downloadedFiles, normalizedEntrypoint)) {
7375
- throw new import_build_utils17.NowBuildError({
7633
+ throw new import_build_utils18.NowBuildError({
7376
7634
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
7377
7635
  message: `Configured Python entrypoint "${normalizedEntrypoint}" was not found.`,
7378
7636
  link: PYTHON_ENTRYPOINT_DOCS_URL2,
7379
7637
  action: "Learn More"
7380
7638
  });
7381
7639
  }
7382
- const { devCacheDir = (0, import_path13.join)(workPath, ".now", "cache") } = meta;
7383
- const cacheKey = (0, import_path13.basename)(entrypoint).replace(/\./g, "_");
7384
- const destCache = (0, import_path13.join)(devCacheDir, cacheKey);
7385
- await (0, import_build_utils17.download)(downloadedFiles, destCache);
7386
- downloadedFiles = await (0, import_build_utils17.glob)("**", destCache);
7640
+ const { devCacheDir = (0, import_path14.join)(workPath, ".now", "cache") } = meta;
7641
+ const cacheKey = (0, import_path14.basename)(entrypoint).replace(/\./g, "_");
7642
+ const destCache = (0, import_path14.join)(devCacheDir, cacheKey);
7643
+ await (0, import_build_utils18.download)(downloadedFiles, destCache);
7644
+ downloadedFiles = await (0, import_build_utils18.glob)("**", destCache);
7387
7645
  workPath = destCache;
7388
7646
  }
7389
7647
  return workPath;
@@ -7407,6 +7665,25 @@ function getTargetPlatform(isDev) {
7407
7665
  }
7408
7666
  return { uvPlatform: UV_LINUX_TARGET, architecture: "x86_64" };
7409
7667
  }
7668
+ async function installInjectedPackage({
7669
+ name,
7670
+ pinned,
7671
+ envOverride,
7672
+ uv,
7673
+ venvPath,
7674
+ projectDir,
7675
+ pipPlatformArgs
7676
+ }) {
7677
+ const localDir = (0, import_path14.join)(__dirname, "..", "..", "..", "python", name);
7678
+ const isLocalDev = import_fs14.default.existsSync((0, import_path14.join)(localDir, "pyproject.toml"));
7679
+ const dep = envOverride || (isLocalDev ? localDir : pinned);
7680
+ (0, import_build_utils18.debug)(`Installing ${dep}`);
7681
+ await uv.pip({
7682
+ venvPath,
7683
+ projectDir,
7684
+ args: ["install", "--link-mode", "copy", ...pipPlatformArgs, dep]
7685
+ });
7686
+ }
7410
7687
  var build = async ({
7411
7688
  workPath,
7412
7689
  repoRootPath,
@@ -7419,14 +7696,14 @@ var build = async ({
7419
7696
  registerPreDeploy
7420
7697
  }) => {
7421
7698
  let entrypoint = rawEntrypoint === "<detect>" ? void 0 : rawEntrypoint;
7422
- const builderSpan = parentSpan ?? new import_build_utils17.Span({ name: "vc.builder" });
7699
+ const builderSpan = parentSpan ?? new import_build_utils18.Span({ name: "vc.builder" });
7423
7700
  const framework = config?.framework;
7424
7701
  const shouldInstallVercelWorkers = config?.hasWorkerServices === true;
7425
7702
  let spawnEnv;
7426
7703
  let projectInstallCommand;
7427
7704
  let hasCustomCommand = false;
7428
7705
  const target = getTargetPlatform(meta.isDev ?? false);
7429
- (0, import_build_utils17.debug)(`workPath: ${workPath}`);
7706
+ (0, import_build_utils18.debug)(`workPath: ${workPath}`);
7430
7707
  workPath = await downloadFilesInWorkPath({
7431
7708
  workPath,
7432
7709
  files: originalFiles,
@@ -7435,7 +7712,7 @@ var build = async ({
7435
7712
  });
7436
7713
  try {
7437
7714
  if (meta.isDev) {
7438
- const setupCfg = (0, import_path13.join)(workPath, "setup.cfg");
7715
+ const setupCfg = (0, import_path14.join)(workPath, "setup.cfg");
7439
7716
  await writeFile(setupCfg, "[install]\nprefix=\n");
7440
7717
  }
7441
7718
  } catch (err) {
@@ -7451,15 +7728,15 @@ var build = async ({
7451
7728
  filePath: entrypoint,
7452
7729
  // For schedule-triggered jobs, the WSGI variable is always 'app' (created dynamically).
7453
7730
  // For other services, handlerFunction is used as the entrypoint variable name.
7454
- varName: service && (0, import_build_utils17.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
7731
+ varName: service && (0, import_build_utils18.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
7455
7732
  } : void 0,
7456
7733
  service
7457
7734
  ) ?? void 0;
7458
7735
  if (detected?.error && detected?.baseDir === void 0) {
7459
7736
  throw detected?.error;
7460
7737
  }
7461
- const entryDirectory = detected?.baseDir ?? (entrypoint ? (0, import_path13.dirname)(entrypoint) : ".");
7462
- const entrypointAbsDir = (0, import_path13.join)(workPath, entryDirectory);
7738
+ const entryDirectory = detected?.baseDir ?? (entrypoint ? (0, import_path14.dirname)(entrypoint) : ".");
7739
+ const entrypointAbsDir = (0, import_path14.join)(workPath, entryDirectory);
7463
7740
  const rootDir = repoRootPath ?? workPath;
7464
7741
  const pythonPackage = await builderSpan.child("vc.builder.python.discover").trace(
7465
7742
  () => discoverPackage({
@@ -7502,12 +7779,12 @@ var build = async ({
7502
7779
  `uv is required for this project but failed to install: ${err instanceof Error ? err.message : String(err)}`
7503
7780
  );
7504
7781
  }
7505
- const venvPath = service?.name ? (0, import_path13.join)(workPath, ".vercel", "python", "services", service.name, ".venv") : (0, import_path13.join)(workPath, ".vercel", "python", ".venv");
7506
- const hasCachedVenv = import_fs13.default.existsSync((0, import_path13.join)(venvPath, "pyvenv.cfg"));
7507
- const hasCachedUv = import_fs13.default.existsSync(uvCacheDir);
7782
+ const venvPath = service?.name ? (0, import_path14.join)(workPath, ".vercel", "python", "services", service.name, ".venv") : (0, import_path14.join)(workPath, ".vercel", "python", ".venv");
7783
+ const hasCachedVenv = import_fs14.default.existsSync((0, import_path14.join)(venvPath, "pyvenv.cfg"));
7784
+ const hasCachedUv = import_fs14.default.existsSync(uvCacheDir);
7508
7785
  const restoredCache = hasCachedVenv && hasCachedUv ? "both" : hasCachedVenv ? "venv" : hasCachedUv ? "uv" : "none";
7509
7786
  if (hasCachedVenv || hasCachedUv) {
7510
- (0, import_build_utils17.debug)(
7787
+ (0, import_build_utils18.debug)(
7511
7788
  `Build cache detected: venv=${hasCachedVenv}, uv-cache=${hasCachedUv}`
7512
7789
  );
7513
7790
  }
@@ -7519,14 +7796,14 @@ var build = async ({
7519
7796
  uvCacheDir
7520
7797
  });
7521
7798
  });
7522
- if ((0, import_build_utils17.isPythonFramework)(framework)) {
7799
+ if ((0, import_build_utils18.isPythonFramework)(framework)) {
7523
7800
  const {
7524
7801
  cliType,
7525
7802
  lockfileVersion,
7526
7803
  packageJsonPackageManager,
7527
7804
  turboSupportsCorepackHome
7528
- } = await (0, import_build_utils17.scanParentDirs)(workPath, true);
7529
- spawnEnv = (0, import_build_utils17.getEnvForPackageManager)({
7805
+ } = await (0, import_build_utils18.scanParentDirs)(workPath, true);
7806
+ spawnEnv = (0, import_build_utils18.getEnvForPackageManager)({
7530
7807
  cliType,
7531
7808
  lockfileVersion,
7532
7809
  packageJsonPackageManager,
@@ -7551,13 +7828,13 @@ var build = async ({
7551
7828
  let uvLockPath = null;
7552
7829
  let uvProjectDir = null;
7553
7830
  let projectName;
7554
- await builderSpan.child(import_build_utils17.BUILDER_INSTALLER_STEP, {
7831
+ await builderSpan.child(import_build_utils18.BUILDER_INSTALLER_STEP, {
7555
7832
  installCommand: projectInstallCommand || void 0,
7556
7833
  runtime: "python",
7557
7834
  "python.cache.restored": restoredCache
7558
7835
  }).trace(async () => {
7559
7836
  if (projectInstallCommand) {
7560
- await import_fs13.default.promises.rm(venvPath, { recursive: true, force: true });
7837
+ await import_fs14.default.promises.rm(venvPath, { recursive: true, force: true });
7561
7838
  await ensureVenv({
7562
7839
  pythonVersion,
7563
7840
  venvPath,
@@ -7568,7 +7845,7 @@ var build = async ({
7568
7845
  console.log(
7569
7846
  `Running "install" command: \`${projectInstallCommand}\`...`
7570
7847
  );
7571
- await (0, import_build_utils17.execCommand)(projectInstallCommand, {
7848
+ await (0, import_build_utils18.execCommand)(projectInstallCommand, {
7572
7849
  env: pythonEnv,
7573
7850
  cwd: workPath
7574
7851
  });
@@ -7589,7 +7866,7 @@ var build = async ({
7589
7866
  }
7590
7867
  if (!assumeDepsInstalled) {
7591
7868
  const lockCacheKey = service?.name ? `uv.lock.${service.name}` : "uv.lock";
7592
- const cachedLockPath = (0, import_path13.join)(uvCacheDir, lockCacheKey);
7869
+ const cachedLockPath = (0, import_path14.join)(uvCacheDir, lockCacheKey);
7593
7870
  const { projectDir, lockPath, lockFileProvidedByUser } = await ensureUvProject({
7594
7871
  workPath,
7595
7872
  rootDir,
@@ -7610,21 +7887,21 @@ var build = async ({
7610
7887
  locked: !lockFileProvidedByUser,
7611
7888
  pythonPlatform: target.uvPlatform
7612
7889
  });
7613
- if (lockPath && import_fs13.default.existsSync(lockPath)) {
7614
- await import_fs13.default.promises.mkdir(uvCacheDir, { recursive: true });
7615
- await import_fs13.default.promises.copyFile(lockPath, cachedLockPath);
7890
+ if (lockPath && import_fs14.default.existsSync(lockPath)) {
7891
+ await import_fs14.default.promises.mkdir(uvCacheDir, { recursive: true });
7892
+ await import_fs14.default.promises.copyFile(lockPath, cachedLockPath);
7616
7893
  }
7617
7894
  }
7618
7895
  });
7619
- if ((0, import_build_utils17.isPythonFramework)(framework)) {
7896
+ if ((0, import_build_utils18.isPythonFramework)(framework)) {
7620
7897
  const projectBuildCommand = config?.projectSettings?.buildCommand ?? // fallback if provided directly on config (some callers set this)
7621
7898
  config?.buildCommand;
7622
- await builderSpan.child(import_build_utils17.BUILDER_COMPILE_STEP, {
7899
+ await builderSpan.child(import_build_utils18.BUILDER_COMPILE_STEP, {
7623
7900
  buildCommand: projectBuildCommand || void 0
7624
7901
  }).trace(async () => {
7625
7902
  if (projectBuildCommand) {
7626
7903
  console.log(`Running "${projectBuildCommand}"`);
7627
- await (0, import_build_utils17.execCommand)(projectBuildCommand, {
7904
+ await (0, import_build_utils18.execCommand)(projectBuildCommand, {
7628
7905
  env: pythonEnv,
7629
7906
  cwd: workPath
7630
7907
  });
@@ -7639,7 +7916,7 @@ var build = async ({
7639
7916
  }
7640
7917
  const hookResult = await runFrameworkHook(framework, {
7641
7918
  pythonEnv,
7642
- projectDir: (0, import_path13.join)(workPath, entryDirectory),
7919
+ projectDir: (0, import_path14.join)(workPath, entryDirectory),
7643
7920
  workPath,
7644
7921
  venvPath,
7645
7922
  entrypoint,
@@ -7651,27 +7928,31 @@ var build = async ({
7651
7928
  }
7652
7929
  entrypoint = resolved?.entrypoint;
7653
7930
  if (!entrypoint) {
7654
- throw new import_build_utils17.NowBuildError({
7931
+ throw new import_build_utils18.NowBuildError({
7655
7932
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
7656
7933
  message: "No Python entrypoint could be detected. Please specify an entrypoint file."
7657
7934
  });
7658
7935
  }
7659
7936
  const djangoStatic = hookResult?.djangoStatic ?? null;
7660
- const runtimeDep = baseEnv.VERCEL_RUNTIME_PYTHON || `vercel-runtime==${VERCEL_RUNTIME_VERSION}`;
7661
- (0, import_build_utils17.debug)(`Installing ${runtimeDep}`);
7662
7937
  const pipPlatformArgs = target.uvPlatform ? ["--python-platform", target.uvPlatform] : [];
7663
- await uv.pip({
7938
+ await installInjectedPackage({
7939
+ name: "vercel-runtime",
7940
+ pinned: `vercel-runtime==${VERCEL_RUNTIME_VERSION}`,
7941
+ envOverride: baseEnv.VERCEL_RUNTIME_PYTHON,
7942
+ uv,
7664
7943
  venvPath,
7665
- projectDir: (0, import_path13.join)(workPath, entryDirectory),
7666
- args: ["install", "--link-mode", "copy", ...pipPlatformArgs, runtimeDep]
7944
+ projectDir: (0, import_path14.join)(workPath, entryDirectory),
7945
+ pipPlatformArgs
7667
7946
  });
7668
7947
  if (shouldInstallVercelWorkers) {
7669
- const workersDep = baseEnv.VERCEL_WORKERS_PYTHON || `vercel-workers==${VERCEL_WORKERS_VERSION}`;
7670
- (0, import_build_utils17.debug)(`Installing ${workersDep}`);
7671
- await uv.pip({
7948
+ await installInjectedPackage({
7949
+ name: "vercel-workers",
7950
+ pinned: `vercel-workers==${VERCEL_WORKERS_VERSION}`,
7951
+ envOverride: baseEnv.VERCEL_WORKERS_PYTHON,
7952
+ uv,
7672
7953
  venvPath,
7673
- projectDir: (0, import_path13.join)(workPath, entryDirectory),
7674
- args: ["install", "--link-mode", "copy", ...pipPlatformArgs, workersDep]
7954
+ projectDir: (0, import_path14.join)(workPath, entryDirectory),
7955
+ pipPlatformArgs
7675
7956
  });
7676
7957
  }
7677
7958
  const quirksResult = await runQuirks({ venvPath, pythonEnv, workPath });
@@ -7683,25 +7964,25 @@ var build = async ({
7683
7964
  const capturedEnv = { ...pythonEnv };
7684
7965
  const capturedCwd = workPath;
7685
7966
  registerPreDeploy(async () => {
7686
- await builderSpan.child(import_build_utils17.BUILDER_PRE_DEPLOY_STEP, {
7967
+ await builderSpan.child(import_build_utils18.BUILDER_PRE_DEPLOY_STEP, {
7687
7968
  preDeployCommand
7688
7969
  }).trace(async () => {
7689
7970
  console.log(`Running pre-deploy command: \`${preDeployCommand}\``);
7690
- await (0, import_build_utils17.execCommand)(preDeployCommand, {
7971
+ await (0, import_build_utils18.execCommand)(preDeployCommand, {
7691
7972
  env: capturedEnv,
7692
7973
  cwd: capturedCwd
7693
7974
  });
7694
7975
  });
7695
7976
  });
7696
7977
  }
7697
- (0, import_build_utils17.debug)("Entrypoint is", entrypoint);
7978
+ (0, import_build_utils18.debug)("Entrypoint is", entrypoint);
7698
7979
  const moduleName = entrypointToModule(entrypoint);
7699
7980
  if (handlerFunction) {
7700
- const entrypointPath = (0, import_path13.join)(workPath, entrypoint);
7701
- const source = await import_fs13.default.promises.readFile(entrypointPath, "utf-8");
7981
+ const entrypointPath = (0, import_path14.join)(workPath, entrypoint);
7982
+ const source = await import_fs14.default.promises.readFile(entrypointPath, "utf-8");
7702
7983
  const found = await (0, import_python_analysis9.containsTopLevelCallable)(source, handlerFunction);
7703
7984
  if (!found) {
7704
- throw new import_build_utils17.NowBuildError({
7985
+ throw new import_build_utils18.NowBuildError({
7705
7986
  code: "PYTHON_HANDLER_NOT_FOUND",
7706
7987
  message: `Handler function "${handlerFunction}" not found in ${entrypoint}. Ensure it is defined at the module's top level.`
7707
7988
  });
@@ -7710,7 +7991,7 @@ var build = async ({
7710
7991
  const vendorDir = resolveVendorDir();
7711
7992
  const suffix = meta.isDev && !entrypoint.endsWith(".py") ? ".py" : "";
7712
7993
  const entrypointWithSuffix = `${entrypoint}${suffix}`;
7713
- (0, import_build_utils17.debug)("Entrypoint with suffix is", entrypointWithSuffix);
7994
+ (0, import_build_utils18.debug)("Entrypoint with suffix is", entrypointWithSuffix);
7714
7995
  const crons = await getServiceCrons({
7715
7996
  service,
7716
7997
  entrypoint,
@@ -7767,6 +8048,10 @@ if os.path.isdir(_vendor):
7767
8048
 
7768
8049
  from vercel_runtime.vc_init import vc_handler
7769
8050
  `;
8051
+ const automaticCompileAllEnabled = shouldUseCompileAll({
8052
+ isDev: meta.isDev,
8053
+ hasCustomCommand
8054
+ });
7770
8055
  const predefinedExcludes = [
7771
8056
  ".git/**",
7772
8057
  ".gitignore",
@@ -7796,12 +8081,18 @@ from vercel_runtime.vc_init import vc_handler
7796
8081
  cwd: workPath,
7797
8082
  ignore: config && typeof config.excludeFiles === "string" ? [...predefinedExcludes, config.excludeFiles] : predefinedExcludes
7798
8083
  };
7799
- const files = await (0, import_build_utils17.glob)("**", globOptions);
8084
+ const files = await (0, import_build_utils18.glob)("**", globOptions);
7800
8085
  if (djangoStatic?.manifestRelPath) {
7801
- files[djangoStatic.manifestRelPath] = new import_build_utils17.FileFsRef({
7802
- fsPath: (0, import_path13.join)(workPath, djangoStatic.manifestRelPath)
8086
+ files[djangoStatic.manifestRelPath] = new import_build_utils18.FileFsRef({
8087
+ fsPath: (0, import_path14.join)(workPath, djangoStatic.manifestRelPath)
7803
8088
  });
7804
8089
  }
8090
+ const handlerPyFilename = "vc__handler__python";
8091
+ files[`${handlerPyFilename}.py`] = new import_build_utils18.FileBlob({ data: runtimeTrampoline });
8092
+ if (config.framework === "fasthtml") {
8093
+ const { SESSKEY = "" } = process.env;
8094
+ files[".sesskey"] = new import_build_utils18.FileBlob({ data: `"${SESSKEY}"` });
8095
+ }
7805
8096
  const depExternalizer = new PythonDependencyExternalizer({
7806
8097
  venvPath,
7807
8098
  vendorDir,
@@ -7829,18 +8120,64 @@ from vercel_runtime.vc_init import vc_handler
7829
8120
  if (depAnalysis.runtimeInstallEnabled) {
7830
8121
  await depExternalizer.generateBundle(files);
7831
8122
  } else {
7832
- for (const [p, f] of Object.entries(depAnalysis.allVendorFiles)) {
7833
- files[p] = f;
8123
+ addFiles(files, depAnalysis.allVendorFiles);
8124
+ if (automaticCompileAllEnabled) {
8125
+ await builderSpan.child("vc.builder.python.compileall").trace(async (compileSpan) => {
8126
+ const sitePackageDirs = (await getVenvSitePackagesDirs(venvPath)).filter((d) => import_fs14.default.existsSync(d));
8127
+ const pythonBin = getVenvPythonBin(venvPath);
8128
+ console.log("Compiling Python application bytecode...");
8129
+ await runCompileAll({
8130
+ pythonBin,
8131
+ filesOrDirectories: [workPath],
8132
+ env: pythonEnv,
8133
+ excludeRegex: getCompileAllAppExcludeRegex(workPath)
8134
+ });
8135
+ console.log("Compiling Python dependency bytecode...");
8136
+ await runCompileAll({
8137
+ pythonBin,
8138
+ filesOrDirectories: sitePackageDirs,
8139
+ env: pythonEnv
8140
+ });
8141
+ compileSpan.setAttributes({
8142
+ "python.compileall.enabled": "true",
8143
+ "python.compileall.sitePackageDirectoryCount": String(
8144
+ sitePackageDirs.length
8145
+ )
8146
+ });
8147
+ });
8148
+ const pythonOnHiveEnabled = process.env.VERCEL_PYTHON_ON_HIVE === "1" || process.env.VERCEL_PYTHON_ON_HIVE === "true";
8149
+ const activeThreshold = pythonOnHiveEnabled ? HIVE_LAMBDA_SIZE_BYTES : LAMBDA_SIZE_THRESHOLD_BYTES;
8150
+ const currentSize = await calculateBundleSize(files);
8151
+ let remainingCapacity = activeThreshold - currentSize;
8152
+ if (pythonVersion.major != null && pythonVersion.minor != null) {
8153
+ const appBytecodeInfo = await collectAppBytecodeFiles({
8154
+ workPath,
8155
+ files,
8156
+ pythonMajor: pythonVersion.major,
8157
+ pythonMinor: pythonVersion.minor
8158
+ });
8159
+ remainingCapacity = addBytecodeWithinCapacity(
8160
+ files,
8161
+ appBytecodeInfo,
8162
+ remainingCapacity
8163
+ );
8164
+ }
8165
+ const vendorBytecodeInfo = await depExternalizer.collectBytecodeFiles(
8166
+ {
8167
+ vendorDirName: vendorDir
8168
+ }
8169
+ );
8170
+ await addVendorBytecodeWithinCapacity({
8171
+ files,
8172
+ depExternalizer,
8173
+ vendorDir,
8174
+ bytecodeInfo: vendorBytecodeInfo,
8175
+ capacity: remainingCapacity
8176
+ });
7834
8177
  }
7835
8178
  }
7836
8179
  });
7837
- const handlerPyFilename = "vc__handler__python";
7838
- files[`${handlerPyFilename}.py`] = new import_build_utils17.FileBlob({ data: runtimeTrampoline });
7839
- if (config.framework === "fasthtml") {
7840
- const { SESSKEY = "" } = process.env;
7841
- files[".sesskey"] = new import_build_utils17.FileBlob({ data: `"${SESSKEY}"` });
7842
- }
7843
- const output = new import_build_utils17.Lambda({
8180
+ const output = new import_build_utils18.Lambda({
7844
8181
  files,
7845
8182
  handler: `${handlerPyFilename}.vc_handler`,
7846
8183
  runtime: pythonVersion.runtime,
@@ -7856,19 +8193,19 @@ from vercel_runtime.vc_init import vc_handler
7856
8193
  pythonVersion,
7857
8194
  uvLockPath,
7858
8195
  framework,
7859
- serviceType: service ? (0, import_build_utils17.getReportedServiceType)(service) : void 0
8196
+ serviceType: service ? (0, import_build_utils18.getReportedServiceType)(service) : void 0
7860
8197
  });
7861
8198
  } catch (err) {
7862
- (0, import_build_utils17.debug)(
8199
+ (0, import_build_utils18.debug)(
7863
8200
  `Failed to write project manifest: ${err instanceof Error ? err.message : String(err)}`
7864
8201
  );
7865
8202
  }
7866
8203
  }
7867
- if (!(0, import_build_utils17.isPythonFramework)(framework) && !service?.name) {
8204
+ if (!(0, import_build_utils18.isPythonFramework)(framework) && !service?.name) {
7868
8205
  return { resultVersion: 3, result: { output } };
7869
8206
  }
7870
8207
  const lambdaPath = service?.name ? `_svc/${service.name}/index` : "index";
7871
- const staticFiles = djangoStatic?.cdnOutputDir ? await (0, import_build_utils17.glob)("**", { cwd: djangoStatic.cdnOutputDir }) : {};
8208
+ const staticFiles = djangoStatic?.cdnOutputDir ? await (0, import_build_utils18.glob)("**", { cwd: djangoStatic.cdnOutputDir }) : {};
7872
8209
  const routes = service?.name ? void 0 : [{ handle: "filesystem" }, { src: "/(.*)", dest: `/${lambdaPath}` }];
7873
8210
  return {
7874
8211
  resultVersion: 2,
@@ -7897,14 +8234,14 @@ var prepareCache = async ({
7897
8234
  }
7898
8235
  } catch {
7899
8236
  }
7900
- return (0, import_build_utils17.glob)("**/.vercel/python/{.venv,services/*/.venv,cache/uv}/**", {
8237
+ return (0, import_build_utils18.glob)("**/.vercel/python/{.venv,services/*/.venv,cache/uv}/**", {
7901
8238
  cwd: root,
7902
8239
  ignore
7903
8240
  });
7904
8241
  };
7905
8242
  var shouldServe = (opts) => {
7906
8243
  const framework = opts.config.framework;
7907
- if ((0, import_build_utils17.isPythonFramework)(framework)) {
8244
+ if ((0, import_build_utils18.isPythonFramework)(framework)) {
7908
8245
  const requestPath = opts.requestPath.replace(/\/$/, "");
7909
8246
  if (requestPath.startsWith("api") && opts.hasMatched) {
7910
8247
  return false;
@@ -7923,7 +8260,7 @@ var defaultShouldServe = ({
7923
8260
  if (entrypoint === requestPath && hasProp(files, entrypoint)) {
7924
8261
  return true;
7925
8262
  }
7926
- const { dir, name } = (0, import_path13.parse)(entrypoint);
8263
+ const { dir, name } = (0, import_path14.parse)(entrypoint);
7927
8264
  if (name === "index" && dir === requestPath && hasProp(files, entrypoint)) {
7928
8265
  return true;
7929
8266
  }