@vercel/python 6.43.3 → 6.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +713 -400
  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
  }
@@ -1895,9 +1895,9 @@ var require_pump = __commonJS({
1895
1895
  "../../node_modules/.pnpm/pump@3.0.2/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() {
@@ -1909,9 +1909,9 @@ var require_pump = __commonJS({
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
3234
  var VERCEL_RUNTIME_VERSION = "0.14.1";
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,142 @@ 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
+ "--invalidation-mode",
4511
+ "unchecked-hash",
4512
+ ...excludeRegex ? ["-x", excludeRegex] : [],
4513
+ ...filesOrDirectories
4514
+ ];
4515
+ try {
4516
+ await (0, import_execa4.default)(pythonBin, args, { env: env || process.env });
4517
+ } catch (err) {
4518
+ (0, import_build_utils6.debug)(`compileall error details: ${JSON.stringify(err)}`);
4519
+ }
4520
+ }
4521
+ function derivePycPath(pyRelPath, pythonMajor, pythonMinor) {
4522
+ if (!pyRelPath.endsWith(".py"))
4523
+ return null;
4524
+ const lastSlash = pyRelPath.lastIndexOf("/");
4525
+ const dir = lastSlash === -1 ? "" : pyRelPath.slice(0, lastSlash + 1);
4526
+ const baseName = pyRelPath.slice(lastSlash + 1, -3);
4527
+ return `${dir}__pycache__/${baseName}.cpython-${pythonMajor}${pythonMinor}.pyc`;
4528
+ }
4529
+ var COMPILEALL_APP_EXCLUDED_DIRS = [
4530
+ ".git",
4531
+ ".vercel",
4532
+ ".pnpm-store",
4533
+ "node_modules",
4534
+ ".next",
4535
+ ".nuxt",
4536
+ ".venv",
4537
+ "venv",
4538
+ "__pycache__",
4539
+ ".mypy_cache",
4540
+ ".ruff_cache",
4541
+ "public"
4542
+ ];
4543
+ function escapePythonRegex(value) {
4544
+ return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
4545
+ }
4546
+ function getCompileAllAppExcludeRegex(workPath) {
4547
+ const excludedDirs = COMPILEALL_APP_EXCLUDED_DIRS.map(escapePythonRegex).join("|");
4548
+ return `${escapePythonRegex(workPath)}[/\\\\](?:${excludedDirs})(?:[/\\\\]|$)`;
4549
+ }
4550
+ async function collectAppBytecodeFiles({
4551
+ workPath,
4552
+ files: appFiles,
4553
+ pythonMajor,
4554
+ pythonMinor
4555
+ }) {
4556
+ const pending = [];
4557
+ for (const bundlePath of Object.keys(appFiles)) {
4558
+ const pycRel = derivePycPath(bundlePath, pythonMajor, pythonMinor);
4559
+ if (!pycRel)
4560
+ continue;
4561
+ pending.push({
4562
+ bundlePath: pycRel,
4563
+ srcFsPath: (0, import_path6.join)(workPath, pycRel.replaceAll("/", import_path6.sep))
4564
+ });
4565
+ }
4566
+ const results = await Promise.all(
4567
+ pending.map(async ({ bundlePath, srcFsPath }) => {
4568
+ try {
4569
+ const stats = await import_fs5.default.promises.stat(srcFsPath);
4570
+ return { bundlePath, srcFsPath, size: stats.size };
4571
+ } catch {
4572
+ return null;
4573
+ }
4574
+ })
4575
+ );
4576
+ const files = {};
4577
+ const perItemSizes = /* @__PURE__ */ new Map();
4578
+ let totalSize = 0;
4579
+ for (const result of results) {
4580
+ if (!result)
4581
+ continue;
4582
+ files[result.bundlePath] = new import_build_utils6.FileFsRef({
4583
+ fsPath: result.srcFsPath,
4584
+ size: result.size
4585
+ });
4586
+ perItemSizes.set(result.bundlePath, result.size);
4587
+ totalSize += result.size;
4588
+ }
4589
+ return { files, totalSize, perItemSizes };
4590
+ }
4591
+
4592
+ // src/dependency-externalizer.ts
4593
+ var readFile = (0, import_util.promisify)(import_fs6.default.readFile);
4464
4594
  var STRIP_BASENAMES = /* @__PURE__ */ new Set([
4465
4595
  "py.typed",
4466
4596
  "WHEEL",
@@ -4468,7 +4598,7 @@ var STRIP_BASENAMES = /* @__PURE__ */ new Set([
4468
4598
  "direct_url.json"
4469
4599
  ]);
4470
4600
  function shouldStripVendorFile(filePath) {
4471
- const segments = filePath.split(import_path6.sep);
4601
+ const segments = filePath.split(import_path7.sep);
4472
4602
  if (segments.includes("__pycache__"))
4473
4603
  return true;
4474
4604
  const name = segments[segments.length - 1] ?? "";
@@ -4533,7 +4663,7 @@ var PythonDependencyExternalizer = class {
4533
4663
  this.distributions = /* @__PURE__ */ new Map();
4534
4664
  for (const dir of this.sitePackageDirs) {
4535
4665
  try {
4536
- await import_fs5.default.promises.access(dir);
4666
+ await import_fs6.default.promises.access(dir);
4537
4667
  } catch {
4538
4668
  continue;
4539
4669
  }
@@ -4549,12 +4679,12 @@ var PythonDependencyExternalizer = class {
4549
4679
  this.totalBundleSize = await calculateBundleSize(tempFilesForSizing);
4550
4680
  this.analyzed = true;
4551
4681
  const totalBundleSizeMB = (this.totalBundleSize / (1024 * 1024)).toFixed(2);
4552
- (0, import_build_utils6.debug)(`Total bundle size: ${totalBundleSizeMB} MB`);
4682
+ (0, import_build_utils7.debug)(`Total bundle size: ${totalBundleSizeMB} MB`);
4553
4683
  const runtimeInstallEnabled = this.shouldEnableRuntimeInstall();
4554
4684
  const pythonOnHiveEnabled = process.env.VERCEL_PYTHON_ON_HIVE === "1" || process.env.VERCEL_PYTHON_ON_HIVE === "true";
4555
4685
  if (this.totalBundleSize > LAMBDA_SIZE_THRESHOLD_BYTES && this.hasCustomCommand && !pythonOnHiveEnabled) {
4556
4686
  const limitMB = (LAMBDA_SIZE_THRESHOLD_BYTES / (1024 * 1024)).toFixed(0);
4557
- throw new import_build_utils6.NowBuildError({
4687
+ throw new import_build_utils7.NowBuildError({
4558
4688
  code: "LAMBDA_SIZE_EXCEEDED",
4559
4689
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${totalBundleSizeMB} MB) exceeds the size limit (${limitMB} MB).
4560
4690
 
@@ -4572,7 +4702,7 @@ dependencies, you can:
4572
4702
  }
4573
4703
  if (pythonOnHiveEnabled && this.totalBundleSize > HIVE_LAMBDA_SIZE_BYTES) {
4574
4704
  const limitMB = (HIVE_LAMBDA_SIZE_BYTES / (1024 * 1024)).toFixed(0);
4575
- throw new import_build_utils6.NowBuildError({
4705
+ throw new import_build_utils7.NowBuildError({
4576
4706
  code: "LAMBDA_SIZE_EXCEEDED",
4577
4707
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${totalBundleSizeMB} MB) exceeds the extended function size limit (${limitMB} MB).
4578
4708
 
@@ -4603,7 +4733,7 @@ application into smaller functions.`,
4603
4733
  );
4604
4734
  }
4605
4735
  if (!this.uvLockPath || !this.uvProjectDir) {
4606
- throw new import_build_utils6.NowBuildError({
4736
+ throw new import_build_utils7.NowBuildError({
4607
4737
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4608
4738
  message: "Runtime dependency installation requires a uv.lock file and project directory."
4609
4739
  });
@@ -4614,7 +4744,7 @@ application into smaller functions.`,
4614
4744
  );
4615
4745
  if (this.totalBundleSize > LAMBDA_EPHEMERAL_STORAGE_BYTES) {
4616
4746
  const ephemeralLimitMB = (LAMBDA_EPHEMERAL_STORAGE_BYTES / (1024 * 1024)).toFixed(0);
4617
- throw new import_build_utils6.NowBuildError({
4747
+ throw new import_build_utils7.NowBuildError({
4618
4748
  code: "LAMBDA_SIZE_EXCEEDED",
4619
4749
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${totalBundleSizeMB} MB) exceeds the ephemeral storage limit (${ephemeralLimitMB} MB).
4620
4750
 
@@ -4641,7 +4771,7 @@ your application into smaller functions.`,
4641
4771
  `Failed to read uv.lock file at "${this.uvLockPath}": ${String(error)}`
4642
4772
  );
4643
4773
  }
4644
- throw new import_build_utils6.NowBuildError({
4774
+ throw new import_build_utils7.NowBuildError({
4645
4775
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4646
4776
  message: `Failed to read uv.lock file at "${this.uvLockPath}"`
4647
4777
  });
@@ -4657,7 +4787,7 @@ your application into smaller functions.`,
4657
4787
  ${error.fileContent}`
4658
4788
  );
4659
4789
  }
4660
- throw new import_build_utils6.NowBuildError({
4790
+ throw new import_build_utils7.NowBuildError({
4661
4791
  code: error.code,
4662
4792
  message: error.message
4663
4793
  });
@@ -4667,7 +4797,7 @@ ${error.fileContent}`
4667
4797
  const excludePackages = [];
4668
4798
  if (this.projectName) {
4669
4799
  excludePackages.push(this.projectName);
4670
- (0, import_build_utils6.debug)(
4800
+ (0, import_build_utils7.debug)(
4671
4801
  `Excluding project package "${this.projectName}" from runtime installation`
4672
4802
  );
4673
4803
  }
@@ -4675,7 +4805,7 @@ ${error.fileContent}`
4675
4805
  lockFile,
4676
4806
  excludePackages
4677
4807
  });
4678
- (0, import_build_utils6.debug)(
4808
+ (0, import_build_utils7.debug)(
4679
4809
  `Package classification: ${classification.privatePackages.length} private, ${classification.publicPackages.length} public`
4680
4810
  );
4681
4811
  const forceBundledDueToWheels = await this.findPackagesWithoutCompatibleWheels(
@@ -4694,7 +4824,7 @@ ${error.fileContent}`
4694
4824
  (name) => !forceBundledSet.has((0, import_python_analysis3.normalizePackageName)(name))
4695
4825
  );
4696
4826
  if (externalizablePublic.length === 0) {
4697
- throw new import_build_utils6.NowBuildError({
4827
+ throw new import_build_utils7.NowBuildError({
4698
4828
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4699
4829
  message: `Bundle size exceeds the Lambda limit and requires runtime
4700
4830
  dependency installation, but no public packages have compatible
@@ -4729,26 +4859,26 @@ To fix this, either:
4729
4859
  let runtimeToolingOverhead = 0;
4730
4860
  try {
4731
4861
  const uvBinaryPath = await this.resolveUvBinaryForBundling();
4732
- const uvStats = await import_fs5.default.promises.stat(uvBinaryPath);
4862
+ const uvStats = await import_fs6.default.promises.stat(uvBinaryPath);
4733
4863
  runtimeToolingOverhead = uvStats.size;
4734
4864
  } catch {
4735
4865
  runtimeToolingOverhead = 50 * 1024 * 1024;
4736
4866
  }
4737
4867
  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);
4868
+ const projectDirRel = (0, import_path7.relative)(this.workPath, this.uvProjectDir);
4869
+ const uvLockRel = (0, import_path7.relative)(this.workPath, this.uvLockPath);
4740
4870
  const isOutsideWorkPath = projectDirRel.startsWith("..") || uvLockRel.startsWith("..");
4741
4871
  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);
4872
+ const pyprojectPath = (0, import_path7.join)(this.uvProjectDir, "pyproject.toml");
4873
+ const pyprojectStats = await import_fs6.default.promises.stat(pyprojectPath).catch(() => null);
4874
+ const uvLockStats = await import_fs6.default.promises.stat(this.uvLockPath).catch(() => null);
4745
4875
  if (pyprojectStats)
4746
4876
  runtimeToolingOverhead += pyprojectStats.size;
4747
4877
  if (uvLockStats)
4748
4878
  runtimeToolingOverhead += uvLockStats.size;
4749
4879
  }
4750
4880
  const remainingCapacity = LAMBDA_SIZE_THRESHOLD_BYTES - fixedOverhead - runtimeToolingOverhead;
4751
- (0, import_build_utils6.debug)(
4881
+ (0, import_build_utils7.debug)(
4752
4882
  `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
4883
  );
4754
4884
  const externalizableSet = new Set(
@@ -4775,11 +4905,11 @@ To fix this, either:
4775
4905
  ...forceBundledDueToWheels
4776
4906
  ];
4777
4907
  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({
4908
+ const srcPyproject = (0, import_path7.join)(this.uvProjectDir, "pyproject.toml");
4909
+ files[`${UV_BUNDLE_DIR}/pyproject.toml`] = new import_build_utils7.FileFsRef({
4780
4910
  fsPath: srcPyproject
4781
4911
  });
4782
- files[`${UV_BUNDLE_DIR}/uv.lock`] = new import_build_utils6.FileFsRef({
4912
+ files[`${UV_BUNDLE_DIR}/uv.lock`] = new import_build_utils7.FileFsRef({
4783
4913
  fsPath: this.uvLockPath
4784
4914
  });
4785
4915
  }
@@ -4787,24 +4917,24 @@ To fix this, either:
4787
4917
  projectDir: isOutsideWorkPath ? UV_BUNDLE_DIR : projectDirRel,
4788
4918
  bundledPackages: bundledPackagesForConfig
4789
4919
  });
4790
- files[`${UV_BUNDLE_DIR}/_runtime_config.json`] = new import_build_utils6.FileBlob({
4920
+ files[`${UV_BUNDLE_DIR}/_runtime_config.json`] = new import_build_utils7.FileBlob({
4791
4921
  data: runtimeConfigData
4792
4922
  });
4793
4923
  try {
4794
4924
  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);
4925
+ const uvBundleDir = (0, import_path7.join)(this.workPath, UV_BUNDLE_DIR);
4926
+ const uvLocalPath = (0, import_path7.join)(uvBundleDir, "uv");
4927
+ await import_fs6.default.promises.mkdir(uvBundleDir, { recursive: true });
4928
+ await import_fs6.default.promises.copyFile(uvBinaryPath, uvLocalPath);
4929
+ await import_fs6.default.promises.chmod(uvLocalPath, 493);
4800
4930
  const uvBundlePath = `${UV_BUNDLE_DIR}/uv`;
4801
- files[uvBundlePath] = new import_build_utils6.FileFsRef({
4931
+ files[uvBundlePath] = new import_build_utils7.FileFsRef({
4802
4932
  fsPath: uvLocalPath,
4803
4933
  mode: 33261
4804
4934
  });
4805
- (0, import_build_utils6.debug)(`Bundled uv binary from ${uvBinaryPath} to ${uvLocalPath}`);
4935
+ (0, import_build_utils7.debug)(`Bundled uv binary from ${uvBinaryPath} to ${uvLocalPath}`);
4806
4936
  } catch (err) {
4807
- throw new import_build_utils6.NowBuildError({
4937
+ throw new import_build_utils7.NowBuildError({
4808
4938
  code: "RUNTIME_DEPENDENCY_INSTALLATION_FAILED",
4809
4939
  message: `Failed to bundle uv binary for runtime installation: ${err instanceof Error ? err.message : String(err)}`
4810
4940
  });
@@ -4813,7 +4943,7 @@ To fix this, either:
4813
4943
  if (finalBundleSize > LAMBDA_SIZE_THRESHOLD_BYTES + 100 * 1024) {
4814
4944
  const finalSizeMB = (finalBundleSize / (1024 * 1024)).toFixed(2);
4815
4945
  const limitMB = (LAMBDA_SIZE_THRESHOLD_BYTES / (1024 * 1024)).toFixed(0);
4816
- throw new import_build_utils6.NowBuildError({
4946
+ throw new import_build_utils7.NowBuildError({
4817
4947
  code: "LAMBDA_SIZE_EXCEEDED",
4818
4948
  message: shouldShowFunctionsBetaHint() ? `Total bundle size (${finalSizeMB} MB) exceeds the size limit (${limitMB} MB).
4819
4949
 
@@ -4841,7 +4971,7 @@ splitting your application.`,
4841
4971
  async findPackagesWithoutCompatibleWheels(lockFile, publicPackageNames) {
4842
4972
  const platform = detectTargetPlatform();
4843
4973
  if (this.pythonMajor === void 0 || this.pythonMinor === void 0) {
4844
- (0, import_build_utils6.debug)("Skipping wheel compatibility check: dev mode");
4974
+ (0, import_build_utils7.debug)("Skipping wheel compatibility check: dev mode");
4845
4975
  return [];
4846
4976
  }
4847
4977
  const reachable = await getPackagesReachableOnPlatform(
@@ -4856,7 +4986,7 @@ splitting your application.`,
4856
4986
  (name) => reachable.has((0, import_python_analysis3.normalizePackageName)(name))
4857
4987
  ) : publicPackageNames;
4858
4988
  if (relevantPackages.length < publicPackageNames.length) {
4859
- (0, import_build_utils6.debug)(
4989
+ (0, import_build_utils7.debug)(
4860
4990
  `Skipping wheel check for ${publicPackageNames.length - relevantPackages.length} package(s) not reachable on the target platform`
4861
4991
  );
4862
4992
  }
@@ -4896,7 +5026,7 @@ splitting your application.`,
4896
5026
  break;
4897
5027
  }
4898
5028
  } catch (err) {
4899
- (0, import_build_utils6.debug)(
5029
+ (0, import_build_utils7.debug)(
4900
5030
  `Failed to check wheel compatibility for ${filename}: ${err instanceof Error ? err.message : String(err)}`
4901
5031
  );
4902
5032
  }
@@ -4913,7 +5043,7 @@ splitting your application.`,
4913
5043
  return getUvBinaryForBundling(this.pythonPath);
4914
5044
  }
4915
5045
  return downloadUvBinaryForTarget(
4916
- (0, import_path6.join)(this.workPath, ".vercel", "python", "cache")
5046
+ (0, import_path7.join)(this.workPath, ".vercel", "python", "cache")
4917
5047
  );
4918
5048
  }
4919
5049
  /**
@@ -4940,21 +5070,21 @@ splitting your application.`,
4940
5070
  const dirDistributions = this.distributions.get(dir);
4941
5071
  if (!dirDistributions)
4942
5072
  continue;
4943
- const resolvedDir = (0, import_path6.resolve)(dir);
4944
- const dirPrefix = resolvedDir + import_path6.sep;
5073
+ const resolvedDir = (0, import_path7.resolve)(dir);
5074
+ const dirPrefix = resolvedDir + import_path7.sep;
4945
5075
  for (const [name, dist] of dirDistributions) {
4946
5076
  if (includeSet && !includeSet.has(name))
4947
5077
  continue;
4948
5078
  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)) {
5079
+ const filePath = rawPath.replaceAll("/", import_path7.sep);
5080
+ if (!(0, import_path7.resolve)(resolvedDir, filePath).startsWith(dirPrefix)) {
4951
5081
  continue;
4952
5082
  }
4953
5083
  if (shouldStripVendorFile(filePath)) {
4954
5084
  continue;
4955
5085
  }
4956
- const srcFsPath = (0, import_path6.join)(dir, filePath);
4957
- const bundlePath = (0, import_path6.join)(vendorDirName, filePath).replace(/\\/g, "/");
5086
+ const srcFsPath = (0, import_path7.join)(dir, filePath);
5087
+ const bundlePath = (0, import_path7.join)(vendorDirName, filePath).replace(/\\/g, "/");
4958
5088
  pending.push({
4959
5089
  bundlePath,
4960
5090
  srcFsPath,
@@ -4968,14 +5098,14 @@ splitting your application.`,
4968
5098
  pending.map(async ({ bundlePath, srcFsPath, recordSize }) => {
4969
5099
  if (recordSize !== void 0) {
4970
5100
  try {
4971
- await import_fs5.default.promises.access(srcFsPath);
5101
+ await import_fs6.default.promises.access(srcFsPath);
4972
5102
  return { bundlePath, srcFsPath, size: recordSize };
4973
5103
  } catch {
4974
5104
  return null;
4975
5105
  }
4976
5106
  } else {
4977
5107
  try {
4978
- const stats = await import_fs5.default.promises.stat(srcFsPath);
5108
+ const stats = await import_fs6.default.promises.stat(srcFsPath);
4979
5109
  return { bundlePath, srcFsPath, size: stats.size };
4980
5110
  } catch {
4981
5111
  return null;
@@ -4985,13 +5115,13 @@ splitting your application.`,
4985
5115
  );
4986
5116
  for (const result of results) {
4987
5117
  if (result) {
4988
- vendorFiles[result.bundlePath] = new import_build_utils6.FileFsRef({
5118
+ vendorFiles[result.bundlePath] = new import_build_utils7.FileFsRef({
4989
5119
  fsPath: result.srcFsPath,
4990
5120
  size: result.size
4991
5121
  });
4992
5122
  }
4993
5123
  }
4994
- (0, import_build_utils6.debug)(
5124
+ (0, import_build_utils7.debug)(
4995
5125
  `Mirrored ${Object.keys(vendorFiles).length} files` + (includePackages ? ` from ${includePackages.length} packages` : "")
4996
5126
  );
4997
5127
  return vendorFiles;
@@ -5009,14 +5139,14 @@ splitting your application.`,
5009
5139
  const dirDistributions = this.distributions.get(dir);
5010
5140
  if (!dirDistributions)
5011
5141
  continue;
5012
- const resolvedDir = (0, import_path6.resolve)(dir);
5013
- const dirPrefix = resolvedDir + import_path6.sep;
5142
+ const resolvedDir = (0, import_path7.resolve)(dir);
5143
+ const dirPrefix = resolvedDir + import_path7.sep;
5014
5144
  for (const [name, dist] of dirDistributions) {
5015
5145
  let knownSize = 0;
5016
5146
  const statPromises = [];
5017
5147
  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)) {
5148
+ const filePath = rawPath.replaceAll("/", import_path7.sep);
5149
+ if (!(0, import_path7.resolve)(resolvedDir, filePath).startsWith(dirPrefix)) {
5020
5150
  continue;
5021
5151
  }
5022
5152
  if (shouldStripVendorFile(filePath)) {
@@ -5026,7 +5156,7 @@ splitting your application.`,
5026
5156
  knownSize += Number(recordSize);
5027
5157
  } else {
5028
5158
  statPromises.push(
5029
- import_fs5.default.promises.stat((0, import_path6.join)(dir, filePath)).then((stats) => stats.size).catch(() => 0)
5159
+ import_fs6.default.promises.stat((0, import_path7.join)(dir, filePath)).then((stats) => stats.size).catch(() => 0)
5030
5160
  );
5031
5161
  }
5032
5162
  }
@@ -5040,6 +5170,85 @@ splitting your application.`,
5040
5170
  }
5041
5171
  return sizes;
5042
5172
  }
5173
+ /**
5174
+ * Collect pre-compiled `.pyc` bytecode files for vendor packages.
5175
+ *
5176
+ * For each `.py` file listed in a package's RECORD, derives the expected
5177
+ * `__pycache__/*.cpython-XY.pyc` path and checks whether it exists on
5178
+ * disk (i.e. whether `compileall` produced it). Files that do not exist
5179
+ * are silently skipped.
5180
+ *
5181
+ * Must be called after `analyze()` which populates `sitePackageDirs` and
5182
+ * `distributions`.
5183
+ */
5184
+ async collectBytecodeFiles({
5185
+ vendorDirName,
5186
+ includePackages
5187
+ }) {
5188
+ if (!this.sitePackageDirs || !this.distributions) {
5189
+ throw new Error("collectBytecodeFiles() must be called after analyze()");
5190
+ }
5191
+ if (this.pythonMajor == null || this.pythonMinor == null) {
5192
+ return { files: {}, totalSize: 0, perItemSizes: /* @__PURE__ */ new Map() };
5193
+ }
5194
+ const includeSet = includePackages ? new Set(includePackages.map(import_python_analysis3.normalizePackageName)) : null;
5195
+ const pending = [];
5196
+ for (const dir of this.sitePackageDirs) {
5197
+ const dirDistributions = this.distributions.get(dir);
5198
+ if (!dirDistributions)
5199
+ continue;
5200
+ for (const [name, dist] of dirDistributions) {
5201
+ if (includeSet && !includeSet.has(name))
5202
+ continue;
5203
+ for (const { path: rawPath } of dist.files) {
5204
+ const pycRel = derivePycPath(
5205
+ rawPath,
5206
+ this.pythonMajor,
5207
+ this.pythonMinor
5208
+ );
5209
+ if (!pycRel)
5210
+ continue;
5211
+ const pycFilePath = pycRel.replaceAll("/", import_path7.sep);
5212
+ const srcFsPath = (0, import_path7.join)(dir, pycFilePath);
5213
+ const bundlePath = (0, import_path7.join)(vendorDirName, pycFilePath).replace(
5214
+ /\\/g,
5215
+ "/"
5216
+ );
5217
+ pending.push({ bundlePath, srcFsPath, packageName: name });
5218
+ }
5219
+ }
5220
+ }
5221
+ const results = await Promise.all(
5222
+ pending.map(async ({ bundlePath, srcFsPath, packageName }) => {
5223
+ try {
5224
+ const stats = await import_fs6.default.promises.stat(srcFsPath);
5225
+ return { bundlePath, srcFsPath, size: stats.size, packageName };
5226
+ } catch {
5227
+ return null;
5228
+ }
5229
+ })
5230
+ );
5231
+ const files = {};
5232
+ let totalSize = 0;
5233
+ const perItemSizes = /* @__PURE__ */ new Map();
5234
+ for (const result of results) {
5235
+ if (!result)
5236
+ continue;
5237
+ files[result.bundlePath] = new import_build_utils7.FileFsRef({
5238
+ fsPath: result.srcFsPath,
5239
+ size: result.size
5240
+ });
5241
+ totalSize += result.size;
5242
+ perItemSizes.set(
5243
+ result.packageName,
5244
+ (perItemSizes.get(result.packageName) ?? 0) + result.size
5245
+ );
5246
+ }
5247
+ (0, import_build_utils7.debug)(
5248
+ `Collected ${Object.keys(files).length} bytecode files (${(totalSize / (1024 * 1024)).toFixed(2)} MB)` + (includePackages ? ` from ${includePackages.length} packages` : "")
5249
+ );
5250
+ return { files, totalSize, perItemSizes };
5251
+ }
5043
5252
  };
5044
5253
  async function getPackagesReachableOnPlatform(lockFile, projectName, pythonMajor, pythonMinor, sysPlatform, platformMachine) {
5045
5254
  if (!projectName)
@@ -5072,13 +5281,13 @@ async function getPackagesReachableOnPlatform(lockFile, projectName, pythonMajor
5072
5281
  platformMachine
5073
5282
  );
5074
5283
  if (!compatible) {
5075
- (0, import_build_utils6.debug)(
5284
+ (0, import_build_utils7.debug)(
5076
5285
  `Skipping dependency ${dep.name}: marker "${dep.marker}" not satisfied on ${sysPlatform}`
5077
5286
  );
5078
5287
  continue;
5079
5288
  }
5080
5289
  } catch (err) {
5081
- (0, import_build_utils6.debug)(
5290
+ (0, import_build_utils7.debug)(
5082
5291
  `Failed to evaluate marker "${dep.marker}" for ${dep.name}, including conservatively: ${err instanceof Error ? err.message : String(err)}`
5083
5292
  );
5084
5293
  }
@@ -5110,7 +5319,7 @@ async function calculateBundleSize(files) {
5110
5319
  knownSize += fsRef.size;
5111
5320
  } else {
5112
5321
  statPromises.push(
5113
- import_fs5.default.promises.stat(fsRef.fsPath).then((stats) => stats.size).catch((err) => {
5322
+ import_fs6.default.promises.stat(fsRef.fsPath).then((stats) => stats.size).catch((err) => {
5114
5323
  console.warn(
5115
5324
  `Warning: Failed to stat file ${fsRef.fsPath}, size will not be included in bundle calculation: ${err}`
5116
5325
  );
@@ -5147,8 +5356,8 @@ function lambdaKnapsack(packages, capacity) {
5147
5356
  }
5148
5357
 
5149
5358
  // src/diagnostics.ts
5150
- var import_fs6 = __toESM(require("fs"));
5151
- var import_build_utils7 = require("@vercel/build-utils");
5359
+ var import_fs7 = __toESM(require("fs"));
5360
+ var import_build_utils8 = require("@vercel/build-utils");
5152
5361
  var import_python_analysis4 = require("@vercel/python-analysis");
5153
5362
  function isDependencyGroupInclude(entry) {
5154
5363
  return typeof entry === "object" && "include-group" in entry;
@@ -5262,7 +5471,7 @@ async function generateProjectManifest({
5262
5471
  const directEntries = [];
5263
5472
  const transitiveEntries = [];
5264
5473
  {
5265
- const content = await import_fs6.default.promises.readFile(uvLockPath, "utf-8");
5474
+ const content = await import_fs7.default.promises.readFile(uvLockPath, "utf-8");
5266
5475
  const uvLock = (0, import_python_analysis4.parseUvLock)(content, uvLockPath);
5267
5476
  const projectName = project?.name;
5268
5477
  const excludeSet = new Set(
@@ -5353,7 +5562,7 @@ async function generateProjectManifest({
5353
5562
  }
5354
5563
  }
5355
5564
  const manifest = {
5356
- version: import_build_utils7.MANIFEST_VERSION,
5565
+ version: import_build_utils8.MANIFEST_VERSION,
5357
5566
  runtime: "python",
5358
5567
  ...framework ? { framework } : {},
5359
5568
  ...serviceType ? { serviceType } : {},
@@ -5367,22 +5576,22 @@ async function generateProjectManifest({
5367
5576
  ...transitiveEntries.sort((a, b) => a.name.localeCompare(b.name))
5368
5577
  ]
5369
5578
  };
5370
- await (0, import_build_utils7.writeProjectManifest)(manifest, workPath, "python");
5579
+ await (0, import_build_utils8.writeProjectManifest)(manifest, workPath, "python");
5371
5580
  }
5372
- var diagnostics = (0, import_build_utils7.createDiagnostics)("python");
5581
+ var diagnostics = (0, import_build_utils8.createDiagnostics)("python");
5373
5582
 
5374
5583
  // 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");
5584
+ var import_fs9 = __toESM(require("fs"));
5585
+ var import_path9 = require("path");
5586
+ var import_execa5 = __toESM(require_execa());
5587
+ var import_build_utils12 = require("@vercel/build-utils");
5379
5588
 
5380
5589
  // 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");
5590
+ var import_fs8 = __toESM(require("fs"));
5591
+ var import_path8 = require("path");
5384
5592
  var import_build_utils9 = require("@vercel/build-utils");
5385
5593
  var import_build_utils10 = require("@vercel/build-utils");
5594
+ var import_build_utils11 = require("@vercel/build-utils");
5386
5595
  var import_python_analysis5 = require("@vercel/python-analysis");
5387
5596
  var PYTHON_ENTRYPOINT_FILENAMES = [
5388
5597
  "app",
@@ -5401,13 +5610,13 @@ var SKIP_DIRS = /* @__PURE__ */ new Set(["__pycache__", "node_modules"]);
5401
5610
  function getCandidateEntrypointsInDirs(dirs) {
5402
5611
  return dirs.flatMap(
5403
5612
  (dir) => PYTHON_ENTRYPOINT_FILENAMES.map(
5404
- (filename) => import_path7.posix.join(dir, `${filename}.py`)
5613
+ (filename) => import_path8.posix.join(dir, `${filename}.py`)
5405
5614
  )
5406
5615
  );
5407
5616
  }
5408
5617
  async function fileExists(filePath) {
5409
5618
  try {
5410
- const stat = await import_fs7.default.promises.stat(filePath);
5619
+ const stat = await import_fs8.default.promises.stat(filePath);
5411
5620
  return stat.isFile();
5412
5621
  } catch {
5413
5622
  return false;
@@ -5462,28 +5671,28 @@ function entrypointToModule(entrypoint) {
5462
5671
  return entrypoint.replace(/\\/g, "/").replace(/\.py$/i, "").replace(/\//g, ".");
5463
5672
  }
5464
5673
  async function checkEntrypoint(workPath, relPath) {
5465
- const absPath = (0, import_path7.join)(workPath, relPath);
5674
+ const absPath = (0, import_path8.join)(workPath, relPath);
5466
5675
  if (!await fileExists(absPath))
5467
5676
  return null;
5468
- const content = await import_fs7.default.promises.readFile(absPath, "utf-8");
5677
+ const content = await import_fs8.default.promises.readFile(absPath, "utf-8");
5469
5678
  return (0, import_python_analysis5.findAppOrHandler)(content);
5470
5679
  }
5471
5680
  async function findPythonFilesRecursive(dir, rootDir) {
5472
5681
  const results = [];
5473
5682
  let entries;
5474
5683
  try {
5475
- entries = await import_fs7.default.promises.readdir(dir, { withFileTypes: true });
5684
+ entries = await import_fs8.default.promises.readdir(dir, { withFileTypes: true });
5476
5685
  } catch {
5477
5686
  return results;
5478
5687
  }
5479
5688
  for (const entry of entries) {
5480
5689
  if (entry.name.startsWith(".") || SKIP_DIRS.has(entry.name))
5481
5690
  continue;
5482
- const fullPath = (0, import_path7.join)(dir, entry.name);
5691
+ const fullPath = (0, import_path8.join)(dir, entry.name);
5483
5692
  if (entry.isDirectory()) {
5484
5693
  results.push(...await findPythonFilesRecursive(fullPath, rootDir));
5485
5694
  } else if (entry.isFile() && entry.name.endsWith(".py")) {
5486
- results.push((0, import_path7.relative)(rootDir, fullPath).replace(/\\/g, "/"));
5695
+ results.push((0, import_path8.relative)(rootDir, fullPath).replace(/\\/g, "/"));
5487
5696
  }
5488
5697
  }
5489
5698
  return results;
@@ -5493,8 +5702,8 @@ async function findEntrypointCandidates(workPath) {
5493
5702
  const candidates = [];
5494
5703
  for (const relPath of pyFiles) {
5495
5704
  try {
5496
- const content = await import_fs7.default.promises.readFile(
5497
- (0, import_path7.join)(workPath, relPath),
5705
+ const content = await import_fs8.default.promises.readFile(
5706
+ (0, import_path8.join)(workPath, relPath),
5498
5707
  "utf-8"
5499
5708
  );
5500
5709
  const varName = await (0, import_python_analysis5.findAppOrHandler)(content);
@@ -5529,14 +5738,14 @@ async function resolveModuleAttrEntrypoint(workPath, value) {
5529
5738
  const relPath = modulePath.replace(/\./g, "/");
5530
5739
  const candidates = [`${relPath}.py`, `${relPath}/__init__.py`];
5531
5740
  for (const candidate of candidates) {
5532
- if (await fileExists((0, import_path7.join)(workPath, candidate))) {
5741
+ if (await fileExists((0, import_path8.join)(workPath, candidate))) {
5533
5742
  return { entrypoint: candidate, variableName };
5534
5743
  }
5535
5744
  }
5536
5745
  return null;
5537
5746
  }
5538
5747
  async function getVercelToolsEntrypoint(workPath) {
5539
- const pyprojectData = await (0, import_build_utils10.readConfigFile)((0, import_path7.join)(workPath, "pyproject.toml"));
5748
+ const pyprojectData = await (0, import_build_utils11.readConfigFile)((0, import_path8.join)(workPath, "pyproject.toml"));
5540
5749
  if (!pyprojectData)
5541
5750
  return null;
5542
5751
  const vercelEntrypoint = pyprojectData.tool?.vercel?.entrypoint;
@@ -5545,7 +5754,7 @@ async function getVercelToolsEntrypoint(workPath) {
5545
5754
  return resolveModuleAttrEntrypoint(workPath, vercelEntrypoint);
5546
5755
  }
5547
5756
  async function getPyprojectEntrypointWithDiagnostics(workPath) {
5548
- const pyprojectData = await (0, import_build_utils10.readConfigFile)((0, import_path7.join)(workPath, "pyproject.toml"));
5757
+ const pyprojectData = await (0, import_build_utils11.readConfigFile)((0, import_path8.join)(workPath, "pyproject.toml"));
5549
5758
  if (!pyprojectData)
5550
5759
  return { entrypoint: null };
5551
5760
  const scripts = pyprojectData.project?.scripts;
@@ -5560,7 +5769,7 @@ async function getPyprojectEntrypointWithDiagnostics(workPath) {
5560
5769
  const relPath = modulePath.replace(/\./g, "/");
5561
5770
  const candidates = [`${relPath}.py`, `${relPath}/__init__.py`];
5562
5771
  for (const candidate of candidates) {
5563
- if (await fileExists((0, import_path7.join)(workPath, candidate))) {
5772
+ if (await fileExists((0, import_path8.join)(workPath, candidate))) {
5564
5773
  return { entrypoint: { entrypoint: candidate, variableName } };
5565
5774
  }
5566
5775
  }
@@ -5569,13 +5778,13 @@ async function getPyprojectEntrypointWithDiagnostics(workPath) {
5569
5778
  async function findValidEntrypoint(workPath, candidates) {
5570
5779
  const existingWithoutEntrypoint = [];
5571
5780
  for (const candidate of candidates) {
5572
- const absPath = (0, import_path7.join)(workPath, candidate);
5781
+ const absPath = (0, import_path8.join)(workPath, candidate);
5573
5782
  if (!await fileExists(absPath))
5574
5783
  continue;
5575
- const content = await import_fs7.default.promises.readFile(absPath, "utf-8");
5784
+ const content = await import_fs8.default.promises.readFile(absPath, "utf-8");
5576
5785
  const varName = await (0, import_python_analysis5.findAppOrHandler)(content);
5577
5786
  if (varName) {
5578
- (0, import_build_utils9.debug)(`Detected Python entrypoint: ${candidate} (variable: ${varName})`);
5787
+ (0, import_build_utils10.debug)(`Detected Python entrypoint: ${candidate} (variable: ${varName})`);
5579
5788
  return {
5580
5789
  entrypoint: { entrypoint: candidate, variableName: varName },
5581
5790
  existingWithoutEntrypoint
@@ -5586,12 +5795,12 @@ async function findValidEntrypoint(workPath, candidates) {
5586
5795
  return { entrypoint: null, existingWithoutEntrypoint };
5587
5796
  }
5588
5797
  async function checkDjangoManage(workPath) {
5589
- const managePath = (0, import_path7.join)(workPath, "manage.py");
5798
+ const managePath = (0, import_path8.join)(workPath, "manage.py");
5590
5799
  try {
5591
- const content = await import_fs7.default.promises.readFile(managePath, "utf-8");
5800
+ const content = await import_fs8.default.promises.readFile(managePath, "utf-8");
5592
5801
  if (!content.includes("DJANGO_SETTINGS_MODULE"))
5593
5802
  return false;
5594
- (0, import_build_utils9.debug)(`Found Django manage.py with DJANGO_SETTINGS_MODULE at ${workPath}`);
5803
+ (0, import_build_utils10.debug)(`Found Django manage.py with DJANGO_SETTINGS_MODULE at ${workPath}`);
5595
5804
  return true;
5596
5805
  } catch {
5597
5806
  return false;
@@ -5599,7 +5808,7 @@ async function checkDjangoManage(workPath) {
5599
5808
  }
5600
5809
  async function getSubdirectories(workPath) {
5601
5810
  try {
5602
- const entries = await import_fs7.default.promises.readdir(workPath, {
5811
+ const entries = await import_fs8.default.promises.readdir(workPath, {
5603
5812
  withFileTypes: true
5604
5813
  });
5605
5814
  return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name).sort();
@@ -5644,7 +5853,7 @@ ${suggestion}`;
5644
5853
  const searchedList = PYTHON_CANDIDATE_ENTRYPOINTS.join(", ");
5645
5854
  message = `No ${displayName} entrypoint found. Set "tool.vercel.entrypoint" in pyproject.toml or define an entrypoint in one of: ${searchedList}.`;
5646
5855
  }
5647
- return new import_build_utils8.NowBuildError({ code, message, link, action });
5856
+ return new import_build_utils9.NowBuildError({ code, message, link, action });
5648
5857
  }
5649
5858
  async function detectGenericPythonEntrypoint(workPath) {
5650
5859
  try {
@@ -5657,7 +5866,7 @@ async function detectGenericPythonEntrypoint(workPath) {
5657
5866
  findDiagnostics: result
5658
5867
  };
5659
5868
  } catch {
5660
- (0, import_build_utils9.debug)("Failed to discover Python entrypoint");
5869
+ (0, import_build_utils10.debug)("Failed to discover Python entrypoint");
5661
5870
  return {
5662
5871
  detected: null,
5663
5872
  findDiagnostics: { entrypoint: null, existingWithoutEntrypoint: [] }
@@ -5676,7 +5885,7 @@ async function detectDjangoPythonEntrypoint(workPath) {
5676
5885
  const subdirs = await getSubdirectories(workPath);
5677
5886
  const rootDirs = ["", ...subdirs];
5678
5887
  for (const rootDir of rootDirs) {
5679
- const currPath = (0, import_path7.join)(workPath, rootDir);
5888
+ const currPath = (0, import_path8.join)(workPath, rootDir);
5680
5889
  const isDjango = await checkDjangoManage(currPath);
5681
5890
  if (isDjango) {
5682
5891
  return {
@@ -5692,7 +5901,7 @@ async function detectDjangoPythonEntrypoint(workPath) {
5692
5901
  findDiagnostics: result
5693
5902
  };
5694
5903
  } catch {
5695
- (0, import_build_utils9.debug)("Failed to discover Django Python entrypoint");
5904
+ (0, import_build_utils10.debug)("Failed to discover Django Python entrypoint");
5696
5905
  return emptyResult;
5697
5906
  }
5698
5907
  }
@@ -5700,10 +5909,10 @@ async function detectPythonEntrypoint(framework, workPath, configuredEntrypoint,
5700
5909
  if (configuredEntrypoint) {
5701
5910
  const { filePath: configEntryFile, varName: configEntryVar } = configuredEntrypoint;
5702
5911
  const entrypoint = configEntryFile.endsWith(".py") ? configEntryFile : `${configEntryFile}.py`;
5703
- const entrypointExists = await fileExists((0, import_path7.join)(workPath, entrypoint));
5912
+ const entrypointExists = await fileExists((0, import_path8.join)(workPath, entrypoint));
5704
5913
  if (!entrypointExists) {
5705
5914
  return {
5706
- error: new import_build_utils8.NowBuildError({
5915
+ error: new import_build_utils9.NowBuildError({
5707
5916
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
5708
5917
  message: `Configured Python entrypoint "${entrypoint}" was not found.`,
5709
5918
  link: PYTHON_ENTRYPOINT_DOCS_URL,
@@ -5713,17 +5922,17 @@ async function detectPythonEntrypoint(framework, workPath, configuredEntrypoint,
5713
5922
  }
5714
5923
  let varName = configEntryVar ?? await checkEntrypoint(workPath, entrypoint);
5715
5924
  if (!varName) {
5716
- const needsDynamicApp = !!service && ((0, import_build_utils8.isScheduleTriggeredService)(service) || (0, import_build_utils8.isQueueTriggeredService)(service) || (0, import_build_utils8.isWorkflowTriggeredService)(service));
5925
+ const needsDynamicApp = !!service && ((0, import_build_utils9.isScheduleTriggeredService)(service) || (0, import_build_utils9.isQueueTriggeredService)(service) || (0, import_build_utils9.isWorkflowTriggeredService)(service));
5717
5926
  if (needsDynamicApp) {
5718
5927
  varName = "app";
5719
5928
  }
5720
5929
  }
5721
5930
  if (varName) {
5722
- (0, import_build_utils9.debug)(`Using configured Python entrypoint: ${entrypoint}`);
5931
+ (0, import_build_utils10.debug)(`Using configured Python entrypoint: ${entrypoint}`);
5723
5932
  return { entrypoint: { entrypoint, variableName: varName } };
5724
5933
  } else {
5725
5934
  return {
5726
- error: new import_build_utils8.NowBuildError({
5935
+ error: new import_build_utils9.NowBuildError({
5727
5936
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
5728
5937
  message: `Could not find a top-level "app", "application", or "handler" in "${entrypoint}".`,
5729
5938
  link: PYTHON_ENTRYPOINT_DOCS_URL,
@@ -5773,7 +5982,7 @@ var detectEntrypoint = async ({
5773
5982
  workPath,
5774
5983
  framework
5775
5984
  }) => {
5776
- if (!(0, import_build_utils8.isPythonFramework)(framework))
5985
+ if (!(0, import_build_utils9.isPythonFramework)(framework))
5777
5986
  return null;
5778
5987
  const detected = await detectPythonEntrypoint(
5779
5988
  framework,
@@ -5790,8 +5999,8 @@ var detectEntrypoint = async ({
5790
5999
 
5791
6000
  // src/crons.ts
5792
6001
  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");
6002
+ var scriptPath = (0, import_path9.join)(__dirname, "..", "templates", "vc_cron_detect.py");
6003
+ var script = import_fs9.default.readFileSync(scriptPath, "utf-8");
5795
6004
  function buildCronRouteTable(crons) {
5796
6005
  const table = {};
5797
6006
  for (const cron of crons) {
@@ -5801,13 +6010,13 @@ function buildCronRouteTable(crons) {
5801
6010
  }
5802
6011
  async function getServiceCrons(opts) {
5803
6012
  const { service, entrypoint, rawEntrypoint, handlerFunction } = opts;
5804
- const isScheduledService = !!service && (0, import_build_utils11.isScheduleTriggeredService)(service);
6013
+ const isScheduledService = !!service && (0, import_build_utils12.isScheduleTriggeredService)(service);
5805
6014
  if (!isScheduledService || !service.name || typeof service.schedule !== "string" && !Array.isArray(service.schedule)) {
5806
6015
  return void 0;
5807
6016
  }
5808
6017
  const cronEntrypoint = entrypoint || rawEntrypoint;
5809
6018
  if (!cronEntrypoint) {
5810
- throw new import_build_utils11.NowBuildError({
6019
+ throw new import_build_utils12.NowBuildError({
5811
6020
  code: "PYTHON_CRON_NO_ENTRYPOINT",
5812
6021
  message: "Cron service is missing an entrypoint."
5813
6022
  });
@@ -5822,7 +6031,7 @@ async function getServiceCrons(opts) {
5822
6031
  workPath: opts.workPath
5823
6032
  });
5824
6033
  }
5825
- const cronPath = (0, import_build_utils11.getInternalServiceCronPath)(
6034
+ const cronPath = (0, import_build_utils12.getInternalServiceCronPath)(
5826
6035
  service.name,
5827
6036
  cronEntrypoint,
5828
6037
  handlerFunction || "cron"
@@ -5846,7 +6055,7 @@ async function getServiceCronsDynamic(opts) {
5846
6055
  workPath
5847
6056
  } = opts;
5848
6057
  if (!handlerFunction) {
5849
- throw new import_build_utils11.NowBuildError({
6058
+ throw new import_build_utils12.NowBuildError({
5850
6059
  code: "PYTHON_DYNAMIC_CRON_NO_HANDLER",
5851
6060
  message: 'Dynamic cron detection requires a "module:object" entrypoint where the object has a get_crons() method.'
5852
6061
  });
@@ -5863,7 +6072,7 @@ async function getServiceCronsDynamic(opts) {
5863
6072
  `Detected ${entries.length} cron entry(s): ${entries.map((e) => `${e.module_function} (${e.schedule})`).join(", ")}`
5864
6073
  );
5865
6074
  if (entries.length === 0) {
5866
- throw new import_build_utils11.NowBuildError({
6075
+ throw new import_build_utils12.NowBuildError({
5867
6076
  code: "PYTHON_DYNAMIC_CRON_EMPTY",
5868
6077
  message: `Dynamic cron detection returned no entries. "${moduleName}.${handlerFunction}.get_crons()" returned an empty iterable.`
5869
6078
  });
@@ -5884,7 +6093,7 @@ async function detectDynamicCrons(opts) {
5884
6093
  const { pythonBin, env, workPath, moduleName, attrName } = opts;
5885
6094
  let stdout;
5886
6095
  try {
5887
- const result = await (0, import_execa4.default)(
6096
+ const result = await (0, import_execa5.default)(
5888
6097
  pythonBin,
5889
6098
  ["-c", script, moduleName, attrName],
5890
6099
  { env, cwd: workPath }
@@ -5898,7 +6107,7 @@ async function detectDynamicCrons(opts) {
5898
6107
  detail = parsed2.error;
5899
6108
  } catch {
5900
6109
  }
5901
- throw new import_build_utils11.NowBuildError({
6110
+ throw new import_build_utils12.NowBuildError({
5902
6111
  code: "PYTHON_DYNAMIC_CRON_DETECTION_FAILED",
5903
6112
  message: `Failed to detect dynamic cron entries: ${detail}`
5904
6113
  });
@@ -5907,7 +6116,7 @@ async function detectDynamicCrons(opts) {
5907
6116
  try {
5908
6117
  parsed = JSON.parse(stdout);
5909
6118
  } catch {
5910
- throw new import_build_utils11.NowBuildError({
6119
+ throw new import_build_utils12.NowBuildError({
5911
6120
  code: "PYTHON_DYNAMIC_CRON_DETECTION_FAILED",
5912
6121
  message: `Dynamic cron detection returned invalid JSON: ${stdout}`
5913
6122
  });
@@ -5917,7 +6126,7 @@ async function detectDynamicCrons(opts) {
5917
6126
  function moduleColonFuncToCronPath(serviceName, moduleFunction) {
5918
6127
  const colonIdx = moduleFunction.indexOf(":");
5919
6128
  if (colonIdx === -1) {
5920
- throw new import_build_utils11.NowBuildError({
6129
+ throw new import_build_utils12.NowBuildError({
5921
6130
  code: "PYTHON_DYNAMIC_CRON_INVALID_FORMAT",
5922
6131
  message: `Dynamic cron entry must use "module:function" format, got: "${moduleFunction}"`
5923
6132
  });
@@ -5925,14 +6134,14 @@ function moduleColonFuncToCronPath(serviceName, moduleFunction) {
5925
6134
  const modulePart = moduleFunction.slice(0, colonIdx);
5926
6135
  const funcPart = moduleFunction.slice(colonIdx + 1);
5927
6136
  const entrypointPath = modulePart.replace(/\./g, "/");
5928
- return (0, import_build_utils11.getInternalServiceCronPath)(serviceName, entrypointPath, funcPart);
6137
+ return (0, import_build_utils12.getInternalServiceCronPath)(serviceName, entrypointPath, funcPart);
5929
6138
  }
5930
6139
 
5931
6140
  // src/start-dev-server.ts
5932
6141
  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");
6142
+ var import_fs10 = require("fs");
6143
+ var import_path10 = require("path");
6144
+ var import_build_utils13 = require("@vercel/build-utils");
5936
6145
  var import_get_port = __toESM(require_get_port());
5937
6146
  var import_is_port_reachable = __toESM(require_is_port_reachable());
5938
6147
  var import_python_analysis6 = require("@vercel/python-analysis");
@@ -6021,17 +6230,17 @@ async function syncDependencies({
6021
6230
  let { manifestPath } = installInfo;
6022
6231
  const manifest = pythonPackage.manifest;
6023
6232
  if (!manifestType || !manifestPath) {
6024
- (0, import_build_utils12.debug)("No Python project manifest found, skipping dependency sync");
6233
+ (0, import_build_utils13.debug)("No Python project manifest found, skipping dependency sync");
6025
6234
  return;
6026
6235
  }
6027
6236
  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");
6237
+ const syncDir = (0, import_path10.join)(workPath, ".vercel", "python", "sync");
6238
+ (0, import_fs10.mkdirSync)(syncDir, { recursive: true });
6239
+ const tempPyproject = (0, import_path10.join)(syncDir, "pyproject.toml");
6031
6240
  const content = (0, import_python_analysis6.stringifyManifest)(manifest.data);
6032
- (0, import_fs9.writeFileSync)(tempPyproject, content, "utf8");
6241
+ (0, import_fs10.writeFileSync)(tempPyproject, content, "utf8");
6033
6242
  manifestPath = tempPyproject;
6034
- (0, import_build_utils12.debug)(
6243
+ (0, import_build_utils13.debug)(
6035
6244
  `Wrote converted ${manifest.origin.kind} manifest to ${tempPyproject}`
6036
6245
  );
6037
6246
  }
@@ -6064,7 +6273,7 @@ async function syncDependencies({
6064
6273
  for (const [channel, chunk] of captured) {
6065
6274
  (channel === "stdout" ? writeOut : writeErr)(chunk.toString());
6066
6275
  }
6067
- throw new import_build_utils12.NowBuildError({
6276
+ throw new import_build_utils13.NowBuildError({
6068
6277
  code: "PYTHON_DEPENDENCY_SYNC_FAILED",
6069
6278
  message: `Failed to install Python dependencies from ${manifestType}: ${err instanceof Error ? err.message : String(err)}`
6070
6279
  });
@@ -6079,14 +6288,14 @@ async function runSync({
6079
6288
  onStdout,
6080
6289
  onStderr
6081
6290
  }) {
6082
- const projectDir = (0, import_path9.dirname)(manifestPath);
6291
+ const projectDir = (0, import_path10.dirname)(manifestPath);
6083
6292
  const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
6084
6293
  let spawnCmd;
6085
6294
  let spawnArgs;
6086
6295
  switch (manifestType) {
6087
6296
  case "uv.lock": {
6088
6297
  if (!uvPath) {
6089
- throw new import_build_utils12.NowBuildError({
6298
+ throw new import_build_utils13.NowBuildError({
6090
6299
  code: "PYTHON_DEPENDENCY_SYNC_FAILED",
6091
6300
  message: "uv is required to install dependencies from uv.lock.",
6092
6301
  link: "https://docs.astral.sh/uv/getting-started/installation/",
@@ -6108,11 +6317,11 @@ async function runSync({
6108
6317
  break;
6109
6318
  }
6110
6319
  default:
6111
- (0, import_build_utils12.debug)(`Unknown manifest type: ${manifestType}`);
6320
+ (0, import_build_utils13.debug)(`Unknown manifest type: ${manifestType}`);
6112
6321
  return;
6113
6322
  }
6114
6323
  await new Promise((resolve3, reject) => {
6115
- (0, import_build_utils12.debug)(`Running "${spawnCmd} ${spawnArgs.join(" ")}" in ${projectDir}...`);
6324
+ (0, import_build_utils13.debug)(`Running "${spawnCmd} ${spawnArgs.join(" ")}" in ${projectDir}...`);
6116
6325
  const child = (0, import_child_process2.spawn)(spawnCmd, spawnArgs, {
6117
6326
  cwd: projectDir,
6118
6327
  env: getProtectedUvEnv(env),
@@ -6156,7 +6365,7 @@ async function installVercelRuntime({
6156
6365
  onStdout,
6157
6366
  onStderr
6158
6367
  }) {
6159
- const targetDir = (0, import_path9.join)(workPath, ".vercel", "python");
6368
+ const targetDir = (0, import_path10.join)(workPath, ".vercel", "python");
6160
6369
  let pending = PENDING_RUNTIME_INSTALLS.get(targetDir);
6161
6370
  if (!pending) {
6162
6371
  pending = doInstallVercelRuntime({
@@ -6182,8 +6391,8 @@ async function doInstallVercelRuntime({
6182
6391
  onStdout,
6183
6392
  onStderr
6184
6393
  }) {
6185
- (0, import_fs9.mkdirSync)(targetDir, { recursive: true });
6186
- const localRuntimeDir = (0, import_path9.join)(
6394
+ (0, import_fs10.mkdirSync)(targetDir, { recursive: true });
6395
+ const localRuntimeDir = (0, import_path10.join)(
6187
6396
  __dirname,
6188
6397
  "..",
6189
6398
  "..",
@@ -6191,21 +6400,21 @@ async function doInstallVercelRuntime({
6191
6400
  "python",
6192
6401
  "vercel-runtime"
6193
6402
  );
6194
- const isLocalDev = (0, import_fs9.existsSync)((0, import_path9.join)(localRuntimeDir, "pyproject.toml"));
6403
+ const isLocalDev = (0, import_fs10.existsSync)((0, import_path10.join)(localRuntimeDir, "pyproject.toml"));
6195
6404
  const runtimeDep = env.VERCEL_RUNTIME_PYTHON || (isLocalDev ? localRuntimeDir : `vercel-runtime==${VERCEL_RUNTIME_VERSION}`);
6196
6405
  if (!isLocalDev && !env.VERCEL_RUNTIME_PYTHON) {
6197
- const distInfo = (0, import_path9.join)(
6406
+ const distInfo = (0, import_path10.join)(
6198
6407
  targetDir,
6199
6408
  `vercel_runtime-${VERCEL_RUNTIME_VERSION}.dist-info`
6200
6409
  );
6201
- if ((0, import_fs9.existsSync)(distInfo)) {
6202
- (0, import_build_utils12.debug)(
6410
+ if ((0, import_fs10.existsSync)(distInfo)) {
6411
+ (0, import_build_utils13.debug)(
6203
6412
  `vercel-runtime ${VERCEL_RUNTIME_VERSION} already installed, skipping`
6204
6413
  );
6205
6414
  return;
6206
6415
  }
6207
6416
  }
6208
- (0, import_build_utils12.debug)(
6417
+ (0, import_build_utils13.debug)(
6209
6418
  `Installing vercel-runtime into ${targetDir} (type: ${isLocalDev ? "local" : "pypi"}, source: ${runtimeDep})`
6210
6419
  );
6211
6420
  const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
@@ -6220,14 +6429,14 @@ async function doInstallVercelRuntime({
6220
6429
  if (onStdout) {
6221
6430
  onStdout(data);
6222
6431
  } else {
6223
- (0, import_build_utils12.debug)(data.toString());
6432
+ (0, import_build_utils13.debug)(data.toString());
6224
6433
  }
6225
6434
  });
6226
6435
  child.stderr?.on("data", (data) => {
6227
6436
  if (onStderr) {
6228
6437
  onStderr(data);
6229
6438
  } else {
6230
- (0, import_build_utils12.debug)(data.toString());
6439
+ (0, import_build_utils13.debug)(data.toString());
6231
6440
  }
6232
6441
  });
6233
6442
  child.on("error", reject);
@@ -6252,7 +6461,7 @@ async function installVercelWorkers({
6252
6461
  onStdout,
6253
6462
  onStderr
6254
6463
  }) {
6255
- const targetDir = (0, import_path9.join)(workPath, ".vercel", "python");
6464
+ const targetDir = (0, import_path10.join)(workPath, ".vercel", "python");
6256
6465
  let pending = PENDING_WORKERS_INSTALLS.get(targetDir);
6257
6466
  if (!pending) {
6258
6467
  pending = doInstallVercelWorkers({
@@ -6278,8 +6487,8 @@ async function doInstallVercelWorkers({
6278
6487
  onStdout,
6279
6488
  onStderr
6280
6489
  }) {
6281
- (0, import_fs9.mkdirSync)(targetDir, { recursive: true });
6282
- const localWorkersDir = (0, import_path9.join)(
6490
+ (0, import_fs10.mkdirSync)(targetDir, { recursive: true });
6491
+ const localWorkersDir = (0, import_path10.join)(
6283
6492
  __dirname,
6284
6493
  "..",
6285
6494
  "..",
@@ -6287,21 +6496,21 @@ async function doInstallVercelWorkers({
6287
6496
  "python",
6288
6497
  "vercel-workers"
6289
6498
  );
6290
- const isLocalDev = (0, import_fs9.existsSync)((0, import_path9.join)(localWorkersDir, "pyproject.toml"));
6499
+ const isLocalDev = (0, import_fs10.existsSync)((0, import_path10.join)(localWorkersDir, "pyproject.toml"));
6291
6500
  const workersDep = env.VERCEL_WORKERS_PYTHON || (isLocalDev ? localWorkersDir : `vercel-workers==${VERCEL_WORKERS_VERSION}`);
6292
6501
  if (!isLocalDev && !env.VERCEL_WORKERS_PYTHON) {
6293
- const distInfo = (0, import_path9.join)(
6502
+ const distInfo = (0, import_path10.join)(
6294
6503
  targetDir,
6295
6504
  `vercel_workers-${VERCEL_WORKERS_VERSION}.dist-info`
6296
6505
  );
6297
- if ((0, import_fs9.existsSync)(distInfo)) {
6298
- (0, import_build_utils12.debug)(
6506
+ if ((0, import_fs10.existsSync)(distInfo)) {
6507
+ (0, import_build_utils13.debug)(
6299
6508
  `vercel-workers ${VERCEL_WORKERS_VERSION} already installed, skipping`
6300
6509
  );
6301
6510
  return;
6302
6511
  }
6303
6512
  }
6304
- (0, import_build_utils12.debug)(
6513
+ (0, import_build_utils13.debug)(
6305
6514
  `Installing vercel-workers into ${targetDir} (type: ${isLocalDev ? "local" : "pypi"}, source: ${workersDep})`
6306
6515
  );
6307
6516
  const pip = uvPath ? { cmd: uvPath, prefix: ["pip", "install"] } : { cmd: pythonBin, prefix: ["-m", "pip", "install"] };
@@ -6316,14 +6525,14 @@ async function doInstallVercelWorkers({
6316
6525
  if (onStdout) {
6317
6526
  onStdout(data);
6318
6527
  } else {
6319
- (0, import_build_utils12.debug)(data.toString());
6528
+ (0, import_build_utils13.debug)(data.toString());
6320
6529
  }
6321
6530
  });
6322
6531
  child.stderr?.on("data", (data) => {
6323
6532
  if (onStderr) {
6324
6533
  onStderr(data);
6325
6534
  } else {
6326
- (0, import_build_utils12.debug)(data.toString());
6535
+ (0, import_build_utils13.debug)(data.toString());
6327
6536
  }
6328
6537
  });
6329
6538
  child.on("error", reject);
@@ -6353,12 +6562,12 @@ function installGlobalCleanupHandlers() {
6353
6562
  try {
6354
6563
  process.kill(info.pid, "SIGTERM");
6355
6564
  } catch (err) {
6356
- (0, import_build_utils12.debug)(`Error sending SIGTERM to ${info.pid}: ${err}`);
6565
+ (0, import_build_utils13.debug)(`Error sending SIGTERM to ${info.pid}: ${err}`);
6357
6566
  }
6358
6567
  try {
6359
6568
  process.kill(info.pid, "SIGKILL");
6360
6569
  } catch (err) {
6361
- (0, import_build_utils12.debug)(`Error sending SIGKILL to ${info.pid}: ${err}`);
6570
+ (0, import_build_utils13.debug)(`Error sending SIGKILL to ${info.pid}: ${err}`);
6362
6571
  }
6363
6572
  PERSISTENT_SERVERS.delete(key);
6364
6573
  }
@@ -6366,7 +6575,7 @@ function installGlobalCleanupHandlers() {
6366
6575
  try {
6367
6576
  restoreWarnings();
6368
6577
  } catch (err) {
6369
- (0, import_build_utils12.debug)(`Error restoring warnings: ${err}`);
6578
+ (0, import_build_utils13.debug)(`Error restoring warnings: ${err}`);
6370
6579
  }
6371
6580
  restoreWarnings = null;
6372
6581
  }
@@ -6383,55 +6592,55 @@ function installGlobalCleanupHandlers() {
6383
6592
  }
6384
6593
  function createDevShim(workPath, entry, modulePath, serviceName, framework, variableName) {
6385
6594
  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 });
6595
+ const vercelPythonDir = serviceName ? (0, import_path10.join)(workPath, ".vercel", "python", "services", serviceName) : (0, import_path10.join)(workPath, ".vercel", "python");
6596
+ (0, import_fs10.mkdirSync)(vercelPythonDir, { recursive: true });
6388
6597
  let qualifiedModule = modulePath;
6389
6598
  let extraPythonPath;
6390
- if ((0, import_fs9.existsSync)((0, import_path9.join)(workPath, "__init__.py"))) {
6391
- const pkgName = (0, import_path9.basename)(workPath);
6599
+ if ((0, import_fs10.existsSync)((0, import_path10.join)(workPath, "__init__.py"))) {
6600
+ const pkgName = (0, import_path10.basename)(workPath);
6392
6601
  qualifiedModule = `${pkgName}.${modulePath}`;
6393
- extraPythonPath = (0, import_path9.dirname)(workPath);
6602
+ extraPythonPath = (0, import_path10.dirname)(workPath);
6394
6603
  }
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)(
6604
+ const entryAbs = (0, import_path10.join)(workPath, entry);
6605
+ const shimPath = (0, import_path10.join)(vercelPythonDir, `${DEV_SHIM_MODULE}.py`);
6606
+ const templatePath = (0, import_path10.join)(
6398
6607
  __dirname,
6399
6608
  "..",
6400
6609
  "templates",
6401
6610
  `${DEV_SHIM_MODULE}.py`
6402
6611
  );
6403
- const template = (0, import_fs9.readFileSync)(templatePath, "utf8");
6612
+ const template = (0, import_fs10.readFileSync)(templatePath, "utf8");
6404
6613
  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}`);
6614
+ (0, import_fs10.writeFileSync)(shimPath, shimSource, "utf8");
6615
+ (0, import_build_utils13.debug)(`Prepared Python dev shim at ${shimPath}`);
6407
6616
  return {
6408
6617
  module: DEV_SHIM_MODULE,
6409
6618
  extraPythonPath,
6410
6619
  shimDir: vercelPythonDir
6411
6620
  };
6412
6621
  } catch (err) {
6413
- (0, import_build_utils12.debug)(`Failed to prepare dev shim: ${err?.message || err}`);
6622
+ (0, import_build_utils13.debug)(`Failed to prepare dev shim: ${err?.message || err}`);
6414
6623
  return null;
6415
6624
  }
6416
6625
  }
6417
6626
  async function getMultiServicePythonRunner(workPath, env, systemPython, uvPath) {
6418
6627
  const { pythonCmd, venvRoot } = useVirtualEnv(workPath, env, systemPython);
6419
6628
  if (venvRoot) {
6420
- (0, import_build_utils12.debug)(`Using existing virtualenv at ${venvRoot} for multi-service dev`);
6629
+ (0, import_build_utils13.debug)(`Using existing virtualenv at ${venvRoot} for multi-service dev`);
6421
6630
  return { command: pythonCmd, args: [] };
6422
6631
  }
6423
- const venvPath = (0, import_path9.join)(workPath, ".venv");
6632
+ const venvPath = (0, import_path10.join)(workPath, ".venv");
6424
6633
  await ensureVenv({
6425
6634
  pythonVersion: { pythonPath: systemPython },
6426
6635
  venvPath,
6427
6636
  uvPath,
6428
6637
  quiet: true
6429
6638
  });
6430
- (0, import_build_utils12.debug)(`Created virtualenv at ${venvPath} for multi-service dev`);
6639
+ (0, import_build_utils13.debug)(`Created virtualenv at ${venvPath} for multi-service dev`);
6431
6640
  const pythonBin = getVenvPythonBin(venvPath);
6432
6641
  const binDir = getVenvBinDir(venvPath);
6433
6642
  env.VIRTUAL_ENV = venvPath;
6434
- env.PATH = `${binDir}${import_path9.delimiter}${env.PATH || ""}`;
6643
+ env.PATH = `${binDir}${import_path10.delimiter}${env.PATH || ""}`;
6435
6644
  return { command: pythonBin, args: [] };
6436
6645
  }
6437
6646
  var startDevServer = async (opts) => {
@@ -6485,7 +6694,7 @@ var startDevServer = async (opts) => {
6485
6694
  filePath: entrypoint,
6486
6695
  // Schedule-triggered services create their own "app" wrapper dynamically.
6487
6696
  // Other services use handlerFunction as the entrypoint variable name.
6488
- varName: service && (0, import_build_utils12.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
6697
+ varName: service && (0, import_build_utils13.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
6489
6698
  } : void 0,
6490
6699
  service
6491
6700
  );
@@ -6494,7 +6703,7 @@ var startDevServer = async (opts) => {
6494
6703
  } else {
6495
6704
  const hookResult = await runFrameworkHook(framework, {
6496
6705
  pythonEnv: env,
6497
- projectDir: (0, import_path9.join)(workPath, detected?.baseDir ?? ""),
6706
+ projectDir: (0, import_path10.join)(workPath, detected?.baseDir ?? ""),
6498
6707
  workPath,
6499
6708
  entrypoint,
6500
6709
  detected: detected ?? void 0
@@ -6505,7 +6714,7 @@ var startDevServer = async (opts) => {
6505
6714
  if (detected?.error) {
6506
6715
  throw detected.error;
6507
6716
  }
6508
- throw new import_build_utils12.NowBuildError({
6717
+ throw new import_build_utils13.NowBuildError({
6509
6718
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
6510
6719
  message: "No Python entrypoint could be detected. Please specify an entrypoint file."
6511
6720
  });
@@ -6534,7 +6743,7 @@ var startDevServer = async (opts) => {
6534
6743
  const yellow = "\x1B[33m";
6535
6744
  const white = "\x1B[1m";
6536
6745
  const reset = "\x1B[0m";
6537
- throw new import_build_utils12.NowBuildError({
6746
+ throw new import_build_utils13.NowBuildError({
6538
6747
  code: "PYTHON_EXTERNAL_VENV_DETECTED",
6539
6748
  message: `Detected activated venv at ${yellow}${venv}${reset}, ${white}vercel dev${reset} manages virtual environments automatically.
6540
6749
  Run ${white}deactivate${reset} and try again.`
@@ -6551,11 +6760,11 @@ Run ${white}deactivate${reset} and try again.`
6551
6760
  );
6552
6761
  spawnCommand = runner.command;
6553
6762
  spawnArgsPrefix = runner.args;
6554
- (0, import_build_utils12.debug)(
6763
+ (0, import_build_utils13.debug)(
6555
6764
  `Multi-service Python runner: ${spawnCommand} ${spawnArgsPrefix.join(" ")}`
6556
6765
  );
6557
6766
  } else if (venv) {
6558
- (0, import_build_utils12.debug)(`Running in virtualenv at ${venv}`);
6767
+ (0, import_build_utils13.debug)(`Running in virtualenv at ${venv}`);
6559
6768
  } else {
6560
6769
  const { pythonCmd: venvPythonCmd, venvRoot } = useVirtualEnv(
6561
6770
  workPath,
@@ -6564,9 +6773,9 @@ Run ${white}deactivate${reset} and try again.`
6564
6773
  );
6565
6774
  spawnCommand = venvPythonCmd;
6566
6775
  if (venvRoot) {
6567
- (0, import_build_utils12.debug)(`Using virtualenv at ${venvRoot}`);
6776
+ (0, import_build_utils13.debug)(`Using virtualenv at ${venvRoot}`);
6568
6777
  } else {
6569
- (0, import_build_utils12.debug)("No virtualenv found");
6778
+ (0, import_build_utils13.debug)("No virtualenv found");
6570
6779
  try {
6571
6780
  const yellow = "\x1B[33m";
6572
6781
  const reset = "\x1B[0m";
@@ -6630,7 +6839,7 @@ If you are using a virtual environment, activate it before running "vercel dev",
6630
6839
  const port = typeof meta.port === "number" ? meta.port : await (0, import_get_port.default)();
6631
6840
  env.PORT = `${port}`;
6632
6841
  if (entry) {
6633
- env.__VC_HANDLER_ENTRYPOINT_ABS = (0, import_path9.join)(workPath, entry);
6842
+ env.__VC_HANDLER_ENTRYPOINT_ABS = (0, import_path10.join)(workPath, entry);
6634
6843
  }
6635
6844
  const devShim = createDevShim(
6636
6845
  workPath,
@@ -6641,8 +6850,8 @@ If you are using a virtual environment, activate it before running "vercel dev",
6641
6850
  variableName ?? ""
6642
6851
  );
6643
6852
  if (devShim) {
6644
- const shimDir = devShim.shimDir || (0, import_path9.join)(workPath, ".vercel", "python");
6645
- const runtimeDir = (0, import_path9.join)(workPath, ".vercel", "python");
6853
+ const shimDir = devShim.shimDir || (0, import_path10.join)(workPath, ".vercel", "python");
6854
+ const runtimeDir = (0, import_path10.join)(workPath, ".vercel", "python");
6646
6855
  const pathParts = shimDir !== runtimeDir ? [shimDir, runtimeDir] : [shimDir];
6647
6856
  if (devShim.extraPythonPath) {
6648
6857
  pathParts.push(devShim.extraPythonPath);
@@ -6651,12 +6860,12 @@ If you are using a virtual environment, activate it before running "vercel dev",
6651
6860
  if (existingPythonPath) {
6652
6861
  pathParts.push(existingPythonPath);
6653
6862
  }
6654
- env.PYTHONPATH = pathParts.join(import_path9.delimiter);
6863
+ env.PYTHONPATH = pathParts.join(import_path10.delimiter);
6655
6864
  }
6656
6865
  const moduleToRun = devShim?.module || modulePath;
6657
6866
  const pythonArgs = ["-u", "-m", moduleToRun];
6658
6867
  const argv = [...spawnArgsPrefix, ...pythonArgs];
6659
- (0, import_build_utils12.debug)(
6868
+ (0, import_build_utils13.debug)(
6660
6869
  `Starting Python dev server (${framework}): ${spawnCommand} ${argv.join(" ")} [PORT=${port}]`
6661
6870
  );
6662
6871
  if (process.stdout.columns) {
@@ -6710,7 +6919,7 @@ If you are using a virtual environment, activate it before running "vercel dev",
6710
6919
  };
6711
6920
 
6712
6921
  // src/quirks/index.ts
6713
- var import_build_utils15 = require("@vercel/build-utils");
6922
+ var import_build_utils16 = require("@vercel/build-utils");
6714
6923
  var import_python_analysis8 = require("@vercel/python-analysis");
6715
6924
 
6716
6925
  // src/quirks/matplotlib.ts
@@ -6724,9 +6933,9 @@ var matplotlibQuirk = {
6724
6933
  };
6725
6934
 
6726
6935
  // 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");
6936
+ var import_fs11 = __toESM(require("fs"));
6937
+ var import_path11 = require("path");
6938
+ var import_build_utils14 = require("@vercel/build-utils");
6730
6939
  var LAMBDA_ROOT = "/var/task";
6731
6940
  var CONFIG_CANDIDATES = [
6732
6941
  "litellm_config.yaml",
@@ -6736,9 +6945,9 @@ var CONFIG_CANDIDATES = [
6736
6945
  ];
6737
6946
  async function findConfigFile(workPath) {
6738
6947
  for (const name of CONFIG_CANDIDATES) {
6739
- const candidate = (0, import_path10.join)(workPath, name);
6948
+ const candidate = (0, import_path11.join)(workPath, name);
6740
6949
  try {
6741
- await import_fs10.default.promises.access(candidate);
6950
+ await import_fs11.default.promises.access(candidate);
6742
6951
  return name;
6743
6952
  } catch {
6744
6953
  }
@@ -6753,32 +6962,32 @@ var litellmQuirk = {
6753
6962
  const env = {};
6754
6963
  const sitePackagesDirs = await getVenvSitePackagesDirs(ctx.venvPath);
6755
6964
  for (const sitePackages of sitePackagesDirs) {
6756
- const schemaPath = (0, import_path10.join)(
6965
+ const schemaPath = (0, import_path11.join)(
6757
6966
  sitePackages,
6758
6967
  "litellm",
6759
6968
  "proxy",
6760
6969
  "schema.prisma"
6761
6970
  );
6762
6971
  try {
6763
- await import_fs10.default.promises.access(schemaPath);
6764
- (0, import_build_utils13.debug)(`LiteLLM quirk: found schema at ${schemaPath}`);
6972
+ await import_fs11.default.promises.access(schemaPath);
6973
+ (0, import_build_utils14.debug)(`LiteLLM quirk: found schema at ${schemaPath}`);
6765
6974
  buildEnv.PRISMA_SCHEMA_PATH = schemaPath;
6766
6975
  break;
6767
6976
  } catch {
6768
6977
  }
6769
6978
  }
6770
6979
  if (!buildEnv.PRISMA_SCHEMA_PATH) {
6771
- (0, import_build_utils13.debug)("LiteLLM quirk: schema.prisma not found in any site-packages");
6980
+ (0, import_build_utils14.debug)("LiteLLM quirk: schema.prisma not found in any site-packages");
6772
6981
  }
6773
6982
  if (!process.env.CONFIG_FILE_PATH) {
6774
6983
  const configName = await findConfigFile(ctx.workPath);
6775
6984
  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);
6985
+ (0, import_build_utils14.debug)(`LiteLLM quirk: found config at ${configName}`);
6986
+ buildEnv.CONFIG_FILE_PATH = (0, import_path11.join)(ctx.workPath, configName);
6987
+ env.CONFIG_FILE_PATH = (0, import_path11.join)(LAMBDA_ROOT, configName);
6779
6988
  }
6780
6989
  } else {
6781
- (0, import_build_utils13.debug)(
6990
+ (0, import_build_utils14.debug)(
6782
6991
  `LiteLLM quirk: CONFIG_FILE_PATH already set to ${process.env.CONFIG_FILE_PATH}`
6783
6992
  );
6784
6993
  }
@@ -6787,10 +6996,10 @@ var litellmQuirk = {
6787
6996
  };
6788
6997
 
6789
6998
  // 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");
6999
+ var import_fs12 = __toESM(require("fs"));
7000
+ var import_path12 = require("path");
7001
+ var import_execa6 = __toESM(require_execa());
7002
+ var import_build_utils15 = require("@vercel/build-utils");
6794
7003
  var import_python_analysis7 = require("@vercel/python-analysis");
6795
7004
  function execErrorMessage(err) {
6796
7005
  if (err != null && typeof err === "object" && "stderr" in err) {
@@ -6828,22 +7037,22 @@ model DummyModel {
6828
7037
  async function findUserSchema(workPath) {
6829
7038
  const envPath = process.env.PRISMA_SCHEMA_PATH;
6830
7039
  if (envPath) {
6831
- const resolved = (0, import_path11.isAbsolute)(envPath) ? envPath : (0, import_path11.join)(workPath, envPath);
7040
+ const resolved = (0, import_path12.isAbsolute)(envPath) ? envPath : (0, import_path12.join)(workPath, envPath);
6832
7041
  try {
6833
- await import_fs11.default.promises.access(resolved);
7042
+ await import_fs12.default.promises.access(resolved);
6834
7043
  return resolved;
6835
7044
  } catch {
6836
- (0, import_build_utils14.debug)(`PRISMA_SCHEMA_PATH=${envPath} not found at ${resolved}`);
7045
+ (0, import_build_utils15.debug)(`PRISMA_SCHEMA_PATH=${envPath} not found at ${resolved}`);
6837
7046
  return null;
6838
7047
  }
6839
7048
  }
6840
7049
  const candidates = [
6841
- (0, import_path11.join)(workPath, "schema.prisma"),
6842
- (0, import_path11.join)(workPath, "prisma", "schema.prisma")
7050
+ (0, import_path12.join)(workPath, "schema.prisma"),
7051
+ (0, import_path12.join)(workPath, "prisma", "schema.prisma")
6843
7052
  ];
6844
7053
  for (const candidate of candidates) {
6845
7054
  try {
6846
- await import_fs11.default.promises.access(candidate);
7055
+ await import_fs12.default.promises.access(candidate);
6847
7056
  return candidate;
6848
7057
  } catch {
6849
7058
  }
@@ -6854,32 +7063,32 @@ async function collectFiles(dir, base) {
6854
7063
  const result = [];
6855
7064
  let entries;
6856
7065
  try {
6857
- entries = await import_fs11.default.promises.readdir(dir, { withFileTypes: true });
7066
+ entries = await import_fs12.default.promises.readdir(dir, { withFileTypes: true });
6858
7067
  } catch {
6859
7068
  return result;
6860
7069
  }
6861
7070
  for (const entry of entries) {
6862
7071
  if (entry.name === "__pycache__")
6863
7072
  continue;
6864
- const full = (0, import_path11.join)(dir, entry.name);
7073
+ const full = (0, import_path12.join)(dir, entry.name);
6865
7074
  if (entry.isDirectory()) {
6866
7075
  result.push(...await collectFiles(full, base));
6867
7076
  } else {
6868
- result.push((0, import_path11.relative)(base, full));
7077
+ result.push((0, import_path12.relative)(base, full));
6869
7078
  }
6870
7079
  }
6871
7080
  return result;
6872
7081
  }
6873
7082
  async function cleanCacheArtifacts(cacheDir, extras = []) {
6874
7083
  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"),
7084
+ (0, import_path12.join)(cacheDir, "node_modules"),
7085
+ (0, import_path12.join)(cacheDir, "package.json"),
7086
+ (0, import_path12.join)(cacheDir, "package-lock.json"),
6878
7087
  ...extras
6879
7088
  ];
6880
7089
  for (const p of paths) {
6881
7090
  try {
6882
- await import_fs11.default.promises.rm(p, { recursive: true, force: true });
7091
+ await import_fs12.default.promises.rm(p, { recursive: true, force: true });
6883
7092
  } catch (err) {
6884
7093
  console.warn(
6885
7094
  `could not clean up ${p}: ${err instanceof Error ? err.message : String(err)}`
@@ -6889,7 +7098,7 @@ async function cleanCacheArtifacts(cacheDir, extras = []) {
6889
7098
  }
6890
7099
  async function isClientGenerated(pythonPath, env) {
6891
7100
  try {
6892
- await (0, import_execa5.default)(pythonPath, ["-c", "import prisma.client"], {
7101
+ await (0, import_execa6.default)(pythonPath, ["-c", "import prisma.client"], {
6893
7102
  env,
6894
7103
  stdio: "pipe"
6895
7104
  });
@@ -6903,7 +7112,7 @@ var prismaQuirk = {
6903
7112
  async run(ctx) {
6904
7113
  const { venvPath, pythonEnv, workPath } = ctx;
6905
7114
  const pythonPath = getVenvPythonBin(venvPath);
6906
- const runtimeCacheDir = (0, import_path11.join)(
7115
+ const runtimeCacheDir = (0, import_path12.join)(
6907
7116
  LAMBDA_ROOT2,
6908
7117
  resolveVendorDir(),
6909
7118
  "prisma",
@@ -6913,7 +7122,7 @@ var prismaQuirk = {
6913
7122
  let sitePackages;
6914
7123
  for (const dir of sitePackagesDirs) {
6915
7124
  try {
6916
- await import_fs11.default.promises.access((0, import_path11.join)(dir, "prisma"));
7125
+ await import_fs12.default.promises.access((0, import_path12.join)(dir, "prisma"));
6917
7126
  sitePackages = dir;
6918
7127
  break;
6919
7128
  } catch {
@@ -6925,21 +7134,21 @@ var prismaQuirk = {
6925
7134
  );
6926
7135
  return {};
6927
7136
  }
6928
- const cacheDir = (0, import_path11.join)(sitePackages, "prisma", "__bincache__");
6929
- await import_fs11.default.promises.mkdir(cacheDir, { recursive: true });
7137
+ const cacheDir = (0, import_path12.join)(sitePackages, "prisma", "__bincache__");
7138
+ await import_fs12.default.promises.mkdir(cacheDir, { recursive: true });
6930
7139
  const generateEnv = {
6931
7140
  ...pythonEnv,
6932
7141
  PRISMA_BINARY_CACHE_DIR: cacheDir
6933
7142
  };
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(
7143
+ const generatedDir = (0, import_path12.join)(workPath, "_prisma_generated");
7144
+ const dummySchemaPath = (0, import_path12.join)(workPath, DUMMY_SCHEMA_NAME);
7145
+ await import_fs12.default.promises.writeFile(
6937
7146
  dummySchemaPath,
6938
7147
  buildDummySchema(generatedDir)
6939
7148
  );
6940
- (0, import_build_utils14.debug)(`Running prisma generate (dummy) with cache dir: ${cacheDir}`);
7149
+ (0, import_build_utils15.debug)(`Running prisma generate (dummy) with cache dir: ${cacheDir}`);
6941
7150
  try {
6942
- const dummyResult = await (0, import_execa5.default)(
7151
+ const dummyResult = await (0, import_execa6.default)(
6943
7152
  pythonPath,
6944
7153
  ["-m", "prisma", "generate", `--schema=${dummySchemaPath}`],
6945
7154
  {
@@ -6949,11 +7158,11 @@ var prismaQuirk = {
6949
7158
  }
6950
7159
  );
6951
7160
  if (dummyResult.stdout)
6952
- (0, import_build_utils14.debug)(`prisma generate (dummy) stdout: ${dummyResult.stdout}`);
7161
+ (0, import_build_utils15.debug)(`prisma generate (dummy) stdout: ${dummyResult.stdout}`);
6953
7162
  if (dummyResult.stderr)
6954
- (0, import_build_utils14.debug)(`prisma generate (dummy) stderr: ${dummyResult.stderr}`);
7163
+ (0, import_build_utils15.debug)(`prisma generate (dummy) stderr: ${dummyResult.stderr}`);
6955
7164
  } catch (err) {
6956
- throw new import_build_utils14.NowBuildError({
7165
+ throw new import_build_utils15.NowBuildError({
6957
7166
  code: "PRISMA_GENERATE_FAILED",
6958
7167
  message: `Prisma engine download failed during \`prisma generate\`. Check that your prisma version is compatible with this Python version.
6959
7168
  ` + execErrorMessage(err)
@@ -6961,47 +7170,47 @@ var prismaQuirk = {
6961
7170
  }
6962
7171
  const srcBinaryPrefix = `query-engine-${getLambdaBinaryTarget()}`;
6963
7172
  const runtimeName = `prisma-query-engine-rhel-openssl-${RUNTIME_OPENSSL_VERSION}.x`;
6964
- const nodeModulesDir = (0, import_path11.join)(cacheDir, "node_modules", "prisma");
7173
+ const nodeModulesDir = (0, import_path12.join)(cacheDir, "node_modules", "prisma");
6965
7174
  let engineCopied = false;
6966
7175
  try {
6967
- const entries = await import_fs11.default.promises.readdir(nodeModulesDir);
7176
+ const entries = await import_fs12.default.promises.readdir(nodeModulesDir);
6968
7177
  for (const entry of entries) {
6969
7178
  if (!entry.startsWith(srcBinaryPrefix))
6970
7179
  continue;
6971
- const srcPath = (0, import_path11.join)(nodeModulesDir, entry);
6972
- const destPath = (0, import_path11.join)(cacheDir, runtimeName);
7180
+ const srcPath = (0, import_path12.join)(nodeModulesDir, entry);
7181
+ const destPath = (0, import_path12.join)(cacheDir, runtimeName);
6973
7182
  try {
6974
- await import_fs11.default.promises.access(destPath);
6975
- (0, import_build_utils14.debug)(`Engine binary: ${runtimeName} already exists, skipping`);
7183
+ await import_fs12.default.promises.access(destPath);
7184
+ (0, import_build_utils15.debug)(`Engine binary: ${runtimeName} already exists, skipping`);
6976
7185
  } catch {
6977
- (0, import_build_utils14.debug)(`Engine binary: copying ${entry} -> ${runtimeName}`);
6978
- await import_fs11.default.promises.copyFile(srcPath, destPath);
7186
+ (0, import_build_utils15.debug)(`Engine binary: copying ${entry} -> ${runtimeName}`);
7187
+ await import_fs12.default.promises.copyFile(srcPath, destPath);
6979
7188
  }
6980
7189
  engineCopied = true;
6981
7190
  }
6982
7191
  } catch (err) {
6983
- throw new import_build_utils14.NowBuildError({
7192
+ throw new import_build_utils15.NowBuildError({
6984
7193
  code: "PRISMA_ENGINE_NOT_FOUND",
6985
7194
  message: `could not read Prisma engine directory "${nodeModulesDir}". This may indicate an incompatible prisma version.
6986
7195
  ` + (err instanceof Error ? err.message : String(err))
6987
7196
  });
6988
7197
  }
6989
7198
  if (!engineCopied) {
6990
- throw new import_build_utils14.NowBuildError({
7199
+ throw new import_build_utils15.NowBuildError({
6991
7200
  code: "PRISMA_ENGINE_NOT_FOUND",
6992
7201
  message: `could not find engine binary matching "${srcBinaryPrefix}*" in "${nodeModulesDir}". This may indicate an incompatible prisma version or an unsupported platform (${process.arch}).`
6993
7202
  });
6994
7203
  }
6995
- const shimPath = (0, import_path11.join)(cacheDir, "openssl");
6996
- await import_fs11.default.promises.writeFile(
7204
+ const shimPath = (0, import_path12.join)(cacheDir, "openssl");
7205
+ await import_fs12.default.promises.writeFile(
6997
7206
  shimPath,
6998
7207
  `#!/bin/sh
6999
7208
  echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIME_OPENSSL_VERSION}.0)"
7000
7209
  `
7001
7210
  );
7002
- await import_fs11.default.promises.chmod(shimPath, 493);
7211
+ await import_fs12.default.promises.chmod(shimPath, 493);
7003
7212
  for (const p of [generatedDir, dummySchemaPath]) {
7004
- await import_fs11.default.promises.rm(p, { recursive: true, force: true });
7213
+ await import_fs12.default.promises.rm(p, { recursive: true, force: true });
7005
7214
  }
7006
7215
  await cleanCacheArtifacts(cacheDir);
7007
7216
  const generateMode = (process.env.VERCEL_PRISMA_GENERATE_CLIENT ?? "auto").toLowerCase();
@@ -7014,16 +7223,16 @@ echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIM
7014
7223
  pythonEnv
7015
7224
  );
7016
7225
  if (clientAlreadyGenerated) {
7017
- (0, import_build_utils14.debug)(
7226
+ (0, import_build_utils15.debug)(
7018
7227
  "Prisma quirk: client already generated, skipping user schema generate"
7019
7228
  );
7020
7229
  shouldGenerate = false;
7021
7230
  }
7022
7231
  }
7023
7232
  if (shouldGenerate) {
7024
- (0, import_build_utils14.debug)(`Running prisma generate with user schema: ${userSchema}`);
7233
+ (0, import_build_utils15.debug)(`Running prisma generate with user schema: ${userSchema}`);
7025
7234
  try {
7026
- const userResult = await (0, import_execa5.default)(
7235
+ const userResult = await (0, import_execa6.default)(
7027
7236
  pythonPath,
7028
7237
  ["-m", "prisma", "generate", `--schema=${userSchema}`],
7029
7238
  {
@@ -7033,11 +7242,11 @@ echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIM
7033
7242
  }
7034
7243
  );
7035
7244
  if (userResult.stdout)
7036
- (0, import_build_utils14.debug)(`prisma generate stdout: ${userResult.stdout}`);
7245
+ (0, import_build_utils15.debug)(`prisma generate stdout: ${userResult.stdout}`);
7037
7246
  if (userResult.stderr)
7038
- (0, import_build_utils14.debug)(`prisma generate stderr: ${userResult.stderr}`);
7247
+ (0, import_build_utils15.debug)(`prisma generate stderr: ${userResult.stderr}`);
7039
7248
  } catch (err) {
7040
- throw new import_build_utils14.NowBuildError({
7249
+ throw new import_build_utils15.NowBuildError({
7041
7250
  code: "PRISMA_GENERATE_FAILED",
7042
7251
  message: `\`prisma generate\` failed for schema "${userSchema}".
7043
7252
  ` + execErrorMessage(err)
@@ -7048,12 +7257,12 @@ echo "OpenSSL ${RUNTIME_OPENSSL_VERSION}.0 1 Jan 2024 (Library: OpenSSL ${RUNTIM
7048
7257
  }
7049
7258
  try {
7050
7259
  const allFiles = await collectFiles(
7051
- (0, import_path11.join)(sitePackages, "prisma"),
7260
+ (0, import_path12.join)(sitePackages, "prisma"),
7052
7261
  sitePackages
7053
7262
  );
7054
7263
  const count = await (0, import_python_analysis7.extendDistRecord)(sitePackages, "prisma", allFiles);
7055
7264
  if (count > 0) {
7056
- (0, import_build_utils14.debug)(`Appended ${count} entries to prisma RECORD`);
7265
+ (0, import_build_utils15.debug)(`Appended ${count} entries to prisma RECORD`);
7057
7266
  }
7058
7267
  } catch (err) {
7059
7268
  console.warn(
@@ -7147,13 +7356,13 @@ async function runQuirks(ctx) {
7147
7356
  (0, import_python_analysis8.normalizePackageName)(quirk.dependency)
7148
7357
  );
7149
7358
  if (!installed) {
7150
- (0, import_build_utils15.debug)(`Quirk "${quirk.dependency}": not installed, skipping`);
7359
+ (0, import_build_utils16.debug)(`Quirk "${quirk.dependency}": not installed, skipping`);
7151
7360
  }
7152
7361
  return installed;
7153
7362
  });
7154
7363
  const sorted = toposortQuirks(activated);
7155
7364
  for (const quirk of sorted) {
7156
- (0, import_build_utils15.debug)(`Quirk "${quirk.dependency}": detected, running fix-up`);
7365
+ (0, import_build_utils16.debug)(`Quirk "${quirk.dependency}": detected, running fix-up`);
7157
7366
  const result = await quirk.run(ctx);
7158
7367
  if (result.env) {
7159
7368
  Object.assign(mergedEnv, result.env);
@@ -7174,14 +7383,14 @@ async function runQuirks(ctx) {
7174
7383
  }
7175
7384
 
7176
7385
  // 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");
7386
+ var import_fs13 = __toESM(require("fs"));
7387
+ var import_path13 = require("path");
7388
+ var import_execa7 = __toESM(require_execa());
7389
+ var import_build_utils17 = require("@vercel/build-utils");
7390
+ var scriptPath2 = (0, import_path13.join)(__dirname, "..", "templates", "vc_django_settings.py");
7391
+ var script2 = import_fs13.default.readFileSync(scriptPath2, "utf-8");
7183
7392
  async function getDjangoSettings(projectDir, env) {
7184
- const { stdout } = await (0, import_execa6.default)("python", ["-c", script2], {
7393
+ const { stdout } = await (0, import_execa7.default)("python", ["-c", script2], {
7185
7394
  env,
7186
7395
  cwd: projectDir
7187
7396
  });
@@ -7207,21 +7416,21 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7207
7416
  const installedApps = djangoSettings["INSTALLED_APPS"] ?? [];
7208
7417
  const staticfilesDirs = djangoSettings["STATICFILES_DIRS"] ?? [];
7209
7418
  const staticSourceDirs = [
7210
- ...installedApps.map((app) => (0, import_path12.join)(workPath, ...app.split("."), "static")),
7419
+ ...installedApps.map((app) => (0, import_path13.join)(workPath, ...app.split("."), "static")),
7211
7420
  // TODO: Deal with optional prefixes in STATICFILES_DIRS.
7212
7421
  ...staticfilesDirs.map((d) => Array.isArray(d) ? d[1] : d)
7213
- ].filter((d) => import_fs12.default.existsSync(d));
7422
+ ].filter((d) => import_fs13.default.existsSync(d));
7214
7423
  if (storageBackend.startsWith("storages.backends.")) {
7215
7424
  console.log(
7216
7425
  "django-storages detected \u2014 running collectstatic with original settings"
7217
7426
  );
7218
- await (0, import_execa6.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7427
+ await (0, import_execa7.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7219
7428
  env: { ...env, DJANGO_SETTINGS_MODULE: settingsModule },
7220
7429
  cwd: workPath
7221
7430
  });
7222
7431
  return {
7223
7432
  staticSourceDirs,
7224
- staticRoot: staticRoot ? (0, import_path12.resolve)(workPath, staticRoot) : null,
7433
+ staticRoot: staticRoot ? (0, import_path13.resolve)(workPath, staticRoot) : null,
7225
7434
  cdnOutputDir: null,
7226
7435
  manifestRelPath: null
7227
7436
  };
@@ -7233,9 +7442,9 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7233
7442
  return null;
7234
7443
  }
7235
7444
  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");
7445
+ const staticOutputDir = (0, import_path13.join)(outputStaticDir, staticUrlPath);
7446
+ await import_fs13.default.promises.mkdir(staticOutputDir, { recursive: true });
7447
+ const shimPath = (0, import_path13.join)(workPath, "_vercel_collectstatic_settings.py");
7239
7448
  const shimLines = [
7240
7449
  `from ${settingsModule} import *`,
7241
7450
  `STATIC_ROOT = ${JSON.stringify(staticOutputDir)}`
@@ -7243,10 +7452,10 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7243
7452
  if (whitenoiseUseFinders) {
7244
7453
  shimLines.push(`WHITENOISE_USE_FINDERS = False`);
7245
7454
  }
7246
- await import_fs12.default.promises.writeFile(shimPath, shimLines.join("\n") + "\n");
7455
+ await import_fs13.default.promises.writeFile(shimPath, shimLines.join("\n") + "\n");
7247
7456
  try {
7248
7457
  console.log("Running collectstatic...");
7249
- await (0, import_execa6.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7458
+ await (0, import_execa7.default)(pythonPath, ["manage.py", "collectstatic", "--noinput"], {
7250
7459
  env: {
7251
7460
  ...env,
7252
7461
  DJANGO_SETTINGS_MODULE: "_vercel_collectstatic_settings"
@@ -7254,7 +7463,7 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7254
7463
  cwd: workPath
7255
7464
  });
7256
7465
  } finally {
7257
- await import_fs12.default.promises.unlink(shimPath).catch(() => {
7466
+ await import_fs13.default.promises.unlink(shimPath).catch(() => {
7258
7467
  });
7259
7468
  }
7260
7469
  const MANIFEST_STORAGE_BACKENDS = [
@@ -7263,17 +7472,17 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7263
7472
  ];
7264
7473
  let manifestRelPath = null;
7265
7474
  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`);
7475
+ const manifestSrc = (0, import_path13.join)(staticOutputDir, "staticfiles.json");
7476
+ const resolvedStaticRoot = (0, import_path13.resolve)(workPath, staticRoot);
7477
+ const manifestDest = (0, import_path13.join)(resolvedStaticRoot, "staticfiles.json");
7478
+ await import_fs13.default.promises.mkdir(resolvedStaticRoot, { recursive: true });
7479
+ await import_fs13.default.promises.copyFile(manifestSrc, manifestDest);
7480
+ manifestRelPath = (0, import_path13.relative)(workPath, manifestDest);
7481
+ (0, import_build_utils17.debug)(`Copied staticfiles.json to ${manifestDest} for Lambda bundle`);
7273
7482
  }
7274
7483
  return {
7275
7484
  staticSourceDirs,
7276
- staticRoot: staticRoot ? (0, import_path12.resolve)(workPath, staticRoot) : null,
7485
+ staticRoot: staticRoot ? (0, import_path13.resolve)(workPath, staticRoot) : null,
7277
7486
  cdnOutputDir: outputStaticDir,
7278
7487
  manifestRelPath
7279
7488
  };
@@ -7281,9 +7490,57 @@ async function runDjangoCollectStatic(venvPath, workPath, env, outputStaticDir,
7281
7490
 
7282
7491
  // src/index.ts
7283
7492
  var import_python_analysis9 = require("@vercel/python-analysis");
7284
- var writeFile = import_fs13.default.promises.writeFile;
7493
+ var writeFile = import_fs14.default.promises.writeFile;
7285
7494
  var PYTHON_ENTRYPOINT_DOCS_URL2 = "https://vercel.com/docs/functions/runtimes/python#python-entrypoints";
7286
7495
  var version = -1;
7496
+ function addFiles(target, source) {
7497
+ for (const [p, f] of Object.entries(source)) {
7498
+ target[p] = f;
7499
+ }
7500
+ }
7501
+ function addBytecodeWithinCapacity(files, bytecodeInfo, capacity) {
7502
+ if (!bytecodeInfo || bytecodeInfo.totalSize <= 0 || capacity <= 0) {
7503
+ return capacity;
7504
+ }
7505
+ if (bytecodeInfo.totalSize <= capacity) {
7506
+ addFiles(files, bytecodeInfo.files);
7507
+ return capacity - bytecodeInfo.totalSize;
7508
+ }
7509
+ const selected = lambdaKnapsack(bytecodeInfo.perItemSizes, capacity);
7510
+ let remainingCapacity = capacity;
7511
+ for (const p of selected) {
7512
+ const file = bytecodeInfo.files[p];
7513
+ if (!file)
7514
+ continue;
7515
+ files[p] = file;
7516
+ remainingCapacity -= bytecodeInfo.perItemSizes.get(p) ?? 0;
7517
+ }
7518
+ return remainingCapacity;
7519
+ }
7520
+ async function addVendorBytecodeWithinCapacity({
7521
+ files,
7522
+ depExternalizer,
7523
+ vendorDir,
7524
+ bytecodeInfo,
7525
+ capacity
7526
+ }) {
7527
+ if (!bytecodeInfo || bytecodeInfo.totalSize <= 0 || capacity <= 0) {
7528
+ return capacity;
7529
+ }
7530
+ if (bytecodeInfo.totalSize <= capacity) {
7531
+ addFiles(files, bytecodeInfo.files);
7532
+ return capacity - bytecodeInfo.totalSize;
7533
+ }
7534
+ const selectedPkgs = lambdaKnapsack(bytecodeInfo.perItemSizes, capacity);
7535
+ if (selectedPkgs.length === 0)
7536
+ return capacity;
7537
+ const selectedBytecode = await depExternalizer.collectBytecodeFiles({
7538
+ vendorDirName: vendorDir,
7539
+ includePackages: selectedPkgs
7540
+ });
7541
+ addFiles(files, selectedBytecode.files);
7542
+ return capacity - selectedBytecode.totalSize;
7543
+ }
7287
7544
  async function runFrameworkHook(framework, ctx) {
7288
7545
  const hook = framework ? frameworkHooks[framework] : void 0;
7289
7546
  return hook?.(ctx);
@@ -7297,7 +7554,7 @@ var frameworkHooks = {
7297
7554
  detected
7298
7555
  }) => {
7299
7556
  if (detected?.baseDir === void 0) {
7300
- (0, import_build_utils17.debug)("Django hook: no manage.py detected, skipping");
7557
+ (0, import_build_utils18.debug)("Django hook: no manage.py detected, skipping");
7301
7558
  return;
7302
7559
  }
7303
7560
  let settingsResult;
@@ -7311,13 +7568,13 @@ Hint: activate a venv or run with \`uv run vercel dev\``;
7311
7568
  } else {
7312
7569
  detail = err?.stderr || err?.message || String(err);
7313
7570
  }
7314
- throw new import_build_utils17.NowBuildError({
7571
+ throw new import_build_utils18.NowBuildError({
7315
7572
  code: "DJANGO_SETTINGS_FAILED",
7316
7573
  message: `Failed to read Django application settings from ${projectDir}/manage.py:
7317
7574
  ${detail}`
7318
7575
  });
7319
7576
  }
7320
- (0, import_build_utils17.debug)(`Django settings: ${JSON.stringify(settingsResult)}`);
7577
+ (0, import_build_utils18.debug)(`Django settings: ${JSON.stringify(settingsResult)}`);
7321
7578
  const { djangoSettings, settingsModule, djangoVersion } = settingsResult;
7322
7579
  if (djangoVersion) {
7323
7580
  console.log(`Django ${djangoVersion.join(".")} detected`);
@@ -7330,7 +7587,7 @@ ${detail}`
7330
7587
  const variableName = parts.at(-1);
7331
7588
  const rel = `${parts.slice(0, -1).join("/")}.py`;
7332
7589
  const ep = baseDir ? `${baseDir}/${rel}` : rel;
7333
- (0, import_build_utils17.debug)(`Django hook: ASGI entrypoint: ${ep} (variable: ${variableName})`);
7590
+ (0, import_build_utils18.debug)(`Django hook: ASGI entrypoint: ${ep} (variable: ${variableName})`);
7334
7591
  resolvedEntrypoint = { entrypoint: ep, variableName };
7335
7592
  } else {
7336
7593
  const wsgiApp = djangoSettings["WSGI_APPLICATION"];
@@ -7339,7 +7596,7 @@ ${detail}`
7339
7596
  const variableName = parts.at(-1);
7340
7597
  const rel = `${parts.slice(0, -1).join("/")}.py`;
7341
7598
  const ep = baseDir ? `${baseDir}/${rel}` : rel;
7342
- (0, import_build_utils17.debug)(
7599
+ (0, import_build_utils18.debug)(
7343
7600
  `Django hook: WSGI entrypoint: ${ep} (variable: ${variableName})`
7344
7601
  );
7345
7602
  resolvedEntrypoint = { entrypoint: ep, variableName };
@@ -7347,7 +7604,7 @@ ${detail}`
7347
7604
  }
7348
7605
  let djangoStatic = null;
7349
7606
  if (workPath && venvPath) {
7350
- const outputStaticDir = (0, import_path13.join)(workPath, ".vercel", "output", "static");
7607
+ const outputStaticDir = (0, import_path14.join)(workPath, ".vercel", "output", "static");
7351
7608
  djangoStatic = await runDjangoCollectStatic(
7352
7609
  venvPath,
7353
7610
  workPath,
@@ -7367,23 +7624,23 @@ async function downloadFilesInWorkPath({
7367
7624
  files,
7368
7625
  meta = {}
7369
7626
  }) {
7370
- (0, import_build_utils17.debug)("Downloading user files...");
7371
- let downloadedFiles = await (0, import_build_utils17.download)(files, workPath, meta);
7627
+ (0, import_build_utils18.debug)("Downloading user files...");
7628
+ let downloadedFiles = await (0, import_build_utils18.download)(files, workPath, meta);
7372
7629
  if (meta.isDev && entrypoint) {
7373
7630
  const normalizedEntrypoint = entrypoint.endsWith(".py") ? entrypoint : `${entrypoint}.py`;
7374
7631
  if (!hasProp(downloadedFiles, entrypoint) && !hasProp(downloadedFiles, normalizedEntrypoint)) {
7375
- throw new import_build_utils17.NowBuildError({
7632
+ throw new import_build_utils18.NowBuildError({
7376
7633
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
7377
7634
  message: `Configured Python entrypoint "${normalizedEntrypoint}" was not found.`,
7378
7635
  link: PYTHON_ENTRYPOINT_DOCS_URL2,
7379
7636
  action: "Learn More"
7380
7637
  });
7381
7638
  }
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);
7639
+ const { devCacheDir = (0, import_path14.join)(workPath, ".now", "cache") } = meta;
7640
+ const cacheKey = (0, import_path14.basename)(entrypoint).replace(/\./g, "_");
7641
+ const destCache = (0, import_path14.join)(devCacheDir, cacheKey);
7642
+ await (0, import_build_utils18.download)(downloadedFiles, destCache);
7643
+ downloadedFiles = await (0, import_build_utils18.glob)("**", destCache);
7387
7644
  workPath = destCache;
7388
7645
  }
7389
7646
  return workPath;
@@ -7419,14 +7676,14 @@ var build = async ({
7419
7676
  registerPreDeploy
7420
7677
  }) => {
7421
7678
  let entrypoint = rawEntrypoint === "<detect>" ? void 0 : rawEntrypoint;
7422
- const builderSpan = parentSpan ?? new import_build_utils17.Span({ name: "vc.builder" });
7679
+ const builderSpan = parentSpan ?? new import_build_utils18.Span({ name: "vc.builder" });
7423
7680
  const framework = config?.framework;
7424
7681
  const shouldInstallVercelWorkers = config?.hasWorkerServices === true;
7425
7682
  let spawnEnv;
7426
7683
  let projectInstallCommand;
7427
7684
  let hasCustomCommand = false;
7428
7685
  const target = getTargetPlatform(meta.isDev ?? false);
7429
- (0, import_build_utils17.debug)(`workPath: ${workPath}`);
7686
+ (0, import_build_utils18.debug)(`workPath: ${workPath}`);
7430
7687
  workPath = await downloadFilesInWorkPath({
7431
7688
  workPath,
7432
7689
  files: originalFiles,
@@ -7435,7 +7692,7 @@ var build = async ({
7435
7692
  });
7436
7693
  try {
7437
7694
  if (meta.isDev) {
7438
- const setupCfg = (0, import_path13.join)(workPath, "setup.cfg");
7695
+ const setupCfg = (0, import_path14.join)(workPath, "setup.cfg");
7439
7696
  await writeFile(setupCfg, "[install]\nprefix=\n");
7440
7697
  }
7441
7698
  } catch (err) {
@@ -7451,15 +7708,15 @@ var build = async ({
7451
7708
  filePath: entrypoint,
7452
7709
  // For schedule-triggered jobs, the WSGI variable is always 'app' (created dynamically).
7453
7710
  // For other services, handlerFunction is used as the entrypoint variable name.
7454
- varName: service && (0, import_build_utils17.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
7711
+ varName: service && (0, import_build_utils18.isScheduleTriggeredService)(service) ? void 0 : handlerFunction
7455
7712
  } : void 0,
7456
7713
  service
7457
7714
  ) ?? void 0;
7458
7715
  if (detected?.error && detected?.baseDir === void 0) {
7459
7716
  throw detected?.error;
7460
7717
  }
7461
- const entryDirectory = detected?.baseDir ?? (entrypoint ? (0, import_path13.dirname)(entrypoint) : ".");
7462
- const entrypointAbsDir = (0, import_path13.join)(workPath, entryDirectory);
7718
+ const entryDirectory = detected?.baseDir ?? (entrypoint ? (0, import_path14.dirname)(entrypoint) : ".");
7719
+ const entrypointAbsDir = (0, import_path14.join)(workPath, entryDirectory);
7463
7720
  const rootDir = repoRootPath ?? workPath;
7464
7721
  const pythonPackage = await builderSpan.child("vc.builder.python.discover").trace(
7465
7722
  () => discoverPackage({
@@ -7502,12 +7759,12 @@ var build = async ({
7502
7759
  `uv is required for this project but failed to install: ${err instanceof Error ? err.message : String(err)}`
7503
7760
  );
7504
7761
  }
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);
7762
+ const venvPath = service?.name ? (0, import_path14.join)(workPath, ".vercel", "python", "services", service.name, ".venv") : (0, import_path14.join)(workPath, ".vercel", "python", ".venv");
7763
+ const hasCachedVenv = import_fs14.default.existsSync((0, import_path14.join)(venvPath, "pyvenv.cfg"));
7764
+ const hasCachedUv = import_fs14.default.existsSync(uvCacheDir);
7508
7765
  const restoredCache = hasCachedVenv && hasCachedUv ? "both" : hasCachedVenv ? "venv" : hasCachedUv ? "uv" : "none";
7509
7766
  if (hasCachedVenv || hasCachedUv) {
7510
- (0, import_build_utils17.debug)(
7767
+ (0, import_build_utils18.debug)(
7511
7768
  `Build cache detected: venv=${hasCachedVenv}, uv-cache=${hasCachedUv}`
7512
7769
  );
7513
7770
  }
@@ -7519,14 +7776,14 @@ var build = async ({
7519
7776
  uvCacheDir
7520
7777
  });
7521
7778
  });
7522
- if ((0, import_build_utils17.isPythonFramework)(framework)) {
7779
+ if ((0, import_build_utils18.isPythonFramework)(framework)) {
7523
7780
  const {
7524
7781
  cliType,
7525
7782
  lockfileVersion,
7526
7783
  packageJsonPackageManager,
7527
7784
  turboSupportsCorepackHome
7528
- } = await (0, import_build_utils17.scanParentDirs)(workPath, true);
7529
- spawnEnv = (0, import_build_utils17.getEnvForPackageManager)({
7785
+ } = await (0, import_build_utils18.scanParentDirs)(workPath, true);
7786
+ spawnEnv = (0, import_build_utils18.getEnvForPackageManager)({
7530
7787
  cliType,
7531
7788
  lockfileVersion,
7532
7789
  packageJsonPackageManager,
@@ -7551,13 +7808,13 @@ var build = async ({
7551
7808
  let uvLockPath = null;
7552
7809
  let uvProjectDir = null;
7553
7810
  let projectName;
7554
- await builderSpan.child(import_build_utils17.BUILDER_INSTALLER_STEP, {
7811
+ await builderSpan.child(import_build_utils18.BUILDER_INSTALLER_STEP, {
7555
7812
  installCommand: projectInstallCommand || void 0,
7556
7813
  runtime: "python",
7557
7814
  "python.cache.restored": restoredCache
7558
7815
  }).trace(async () => {
7559
7816
  if (projectInstallCommand) {
7560
- await import_fs13.default.promises.rm(venvPath, { recursive: true, force: true });
7817
+ await import_fs14.default.promises.rm(venvPath, { recursive: true, force: true });
7561
7818
  await ensureVenv({
7562
7819
  pythonVersion,
7563
7820
  venvPath,
@@ -7568,7 +7825,7 @@ var build = async ({
7568
7825
  console.log(
7569
7826
  `Running "install" command: \`${projectInstallCommand}\`...`
7570
7827
  );
7571
- await (0, import_build_utils17.execCommand)(projectInstallCommand, {
7828
+ await (0, import_build_utils18.execCommand)(projectInstallCommand, {
7572
7829
  env: pythonEnv,
7573
7830
  cwd: workPath
7574
7831
  });
@@ -7589,7 +7846,7 @@ var build = async ({
7589
7846
  }
7590
7847
  if (!assumeDepsInstalled) {
7591
7848
  const lockCacheKey = service?.name ? `uv.lock.${service.name}` : "uv.lock";
7592
- const cachedLockPath = (0, import_path13.join)(uvCacheDir, lockCacheKey);
7849
+ const cachedLockPath = (0, import_path14.join)(uvCacheDir, lockCacheKey);
7593
7850
  const { projectDir, lockPath, lockFileProvidedByUser } = await ensureUvProject({
7594
7851
  workPath,
7595
7852
  rootDir,
@@ -7610,21 +7867,21 @@ var build = async ({
7610
7867
  locked: !lockFileProvidedByUser,
7611
7868
  pythonPlatform: target.uvPlatform
7612
7869
  });
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);
7870
+ if (lockPath && import_fs14.default.existsSync(lockPath)) {
7871
+ await import_fs14.default.promises.mkdir(uvCacheDir, { recursive: true });
7872
+ await import_fs14.default.promises.copyFile(lockPath, cachedLockPath);
7616
7873
  }
7617
7874
  }
7618
7875
  });
7619
- if ((0, import_build_utils17.isPythonFramework)(framework)) {
7876
+ if ((0, import_build_utils18.isPythonFramework)(framework)) {
7620
7877
  const projectBuildCommand = config?.projectSettings?.buildCommand ?? // fallback if provided directly on config (some callers set this)
7621
7878
  config?.buildCommand;
7622
- await builderSpan.child(import_build_utils17.BUILDER_COMPILE_STEP, {
7879
+ await builderSpan.child(import_build_utils18.BUILDER_COMPILE_STEP, {
7623
7880
  buildCommand: projectBuildCommand || void 0
7624
7881
  }).trace(async () => {
7625
7882
  if (projectBuildCommand) {
7626
7883
  console.log(`Running "${projectBuildCommand}"`);
7627
- await (0, import_build_utils17.execCommand)(projectBuildCommand, {
7884
+ await (0, import_build_utils18.execCommand)(projectBuildCommand, {
7628
7885
  env: pythonEnv,
7629
7886
  cwd: workPath
7630
7887
  });
@@ -7639,7 +7896,7 @@ var build = async ({
7639
7896
  }
7640
7897
  const hookResult = await runFrameworkHook(framework, {
7641
7898
  pythonEnv,
7642
- projectDir: (0, import_path13.join)(workPath, entryDirectory),
7899
+ projectDir: (0, import_path14.join)(workPath, entryDirectory),
7643
7900
  workPath,
7644
7901
  venvPath,
7645
7902
  entrypoint,
@@ -7651,26 +7908,26 @@ var build = async ({
7651
7908
  }
7652
7909
  entrypoint = resolved?.entrypoint;
7653
7910
  if (!entrypoint) {
7654
- throw new import_build_utils17.NowBuildError({
7911
+ throw new import_build_utils18.NowBuildError({
7655
7912
  code: "PYTHON_ENTRYPOINT_NOT_FOUND",
7656
7913
  message: "No Python entrypoint could be detected. Please specify an entrypoint file."
7657
7914
  });
7658
7915
  }
7659
7916
  const djangoStatic = hookResult?.djangoStatic ?? null;
7660
7917
  const runtimeDep = baseEnv.VERCEL_RUNTIME_PYTHON || `vercel-runtime==${VERCEL_RUNTIME_VERSION}`;
7661
- (0, import_build_utils17.debug)(`Installing ${runtimeDep}`);
7918
+ (0, import_build_utils18.debug)(`Installing ${runtimeDep}`);
7662
7919
  const pipPlatformArgs = target.uvPlatform ? ["--python-platform", target.uvPlatform] : [];
7663
7920
  await uv.pip({
7664
7921
  venvPath,
7665
- projectDir: (0, import_path13.join)(workPath, entryDirectory),
7922
+ projectDir: (0, import_path14.join)(workPath, entryDirectory),
7666
7923
  args: ["install", "--link-mode", "copy", ...pipPlatformArgs, runtimeDep]
7667
7924
  });
7668
7925
  if (shouldInstallVercelWorkers) {
7669
7926
  const workersDep = baseEnv.VERCEL_WORKERS_PYTHON || `vercel-workers==${VERCEL_WORKERS_VERSION}`;
7670
- (0, import_build_utils17.debug)(`Installing ${workersDep}`);
7927
+ (0, import_build_utils18.debug)(`Installing ${workersDep}`);
7671
7928
  await uv.pip({
7672
7929
  venvPath,
7673
- projectDir: (0, import_path13.join)(workPath, entryDirectory),
7930
+ projectDir: (0, import_path14.join)(workPath, entryDirectory),
7674
7931
  args: ["install", "--link-mode", "copy", ...pipPlatformArgs, workersDep]
7675
7932
  });
7676
7933
  }
@@ -7683,25 +7940,25 @@ var build = async ({
7683
7940
  const capturedEnv = { ...pythonEnv };
7684
7941
  const capturedCwd = workPath;
7685
7942
  registerPreDeploy(async () => {
7686
- await builderSpan.child(import_build_utils17.BUILDER_PRE_DEPLOY_STEP, {
7943
+ await builderSpan.child(import_build_utils18.BUILDER_PRE_DEPLOY_STEP, {
7687
7944
  preDeployCommand
7688
7945
  }).trace(async () => {
7689
7946
  console.log(`Running pre-deploy command: \`${preDeployCommand}\``);
7690
- await (0, import_build_utils17.execCommand)(preDeployCommand, {
7947
+ await (0, import_build_utils18.execCommand)(preDeployCommand, {
7691
7948
  env: capturedEnv,
7692
7949
  cwd: capturedCwd
7693
7950
  });
7694
7951
  });
7695
7952
  });
7696
7953
  }
7697
- (0, import_build_utils17.debug)("Entrypoint is", entrypoint);
7954
+ (0, import_build_utils18.debug)("Entrypoint is", entrypoint);
7698
7955
  const moduleName = entrypointToModule(entrypoint);
7699
7956
  if (handlerFunction) {
7700
- const entrypointPath = (0, import_path13.join)(workPath, entrypoint);
7701
- const source = await import_fs13.default.promises.readFile(entrypointPath, "utf-8");
7957
+ const entrypointPath = (0, import_path14.join)(workPath, entrypoint);
7958
+ const source = await import_fs14.default.promises.readFile(entrypointPath, "utf-8");
7702
7959
  const found = await (0, import_python_analysis9.containsTopLevelCallable)(source, handlerFunction);
7703
7960
  if (!found) {
7704
- throw new import_build_utils17.NowBuildError({
7961
+ throw new import_build_utils18.NowBuildError({
7705
7962
  code: "PYTHON_HANDLER_NOT_FOUND",
7706
7963
  message: `Handler function "${handlerFunction}" not found in ${entrypoint}. Ensure it is defined at the module's top level.`
7707
7964
  });
@@ -7710,7 +7967,7 @@ var build = async ({
7710
7967
  const vendorDir = resolveVendorDir();
7711
7968
  const suffix = meta.isDev && !entrypoint.endsWith(".py") ? ".py" : "";
7712
7969
  const entrypointWithSuffix = `${entrypoint}${suffix}`;
7713
- (0, import_build_utils17.debug)("Entrypoint with suffix is", entrypointWithSuffix);
7970
+ (0, import_build_utils18.debug)("Entrypoint with suffix is", entrypointWithSuffix);
7714
7971
  const crons = await getServiceCrons({
7715
7972
  service,
7716
7973
  entrypoint,
@@ -7767,6 +8024,10 @@ if os.path.isdir(_vendor):
7767
8024
 
7768
8025
  from vercel_runtime.vc_init import vc_handler
7769
8026
  `;
8027
+ const automaticCompileAllEnabled = shouldUseCompileAll({
8028
+ isDev: meta.isDev,
8029
+ hasCustomCommand
8030
+ });
7770
8031
  const predefinedExcludes = [
7771
8032
  ".git/**",
7772
8033
  ".gitignore",
@@ -7796,12 +8057,18 @@ from vercel_runtime.vc_init import vc_handler
7796
8057
  cwd: workPath,
7797
8058
  ignore: config && typeof config.excludeFiles === "string" ? [...predefinedExcludes, config.excludeFiles] : predefinedExcludes
7798
8059
  };
7799
- const files = await (0, import_build_utils17.glob)("**", globOptions);
8060
+ const files = await (0, import_build_utils18.glob)("**", globOptions);
7800
8061
  if (djangoStatic?.manifestRelPath) {
7801
- files[djangoStatic.manifestRelPath] = new import_build_utils17.FileFsRef({
7802
- fsPath: (0, import_path13.join)(workPath, djangoStatic.manifestRelPath)
8062
+ files[djangoStatic.manifestRelPath] = new import_build_utils18.FileFsRef({
8063
+ fsPath: (0, import_path14.join)(workPath, djangoStatic.manifestRelPath)
7803
8064
  });
7804
8065
  }
8066
+ const handlerPyFilename = "vc__handler__python";
8067
+ files[`${handlerPyFilename}.py`] = new import_build_utils18.FileBlob({ data: runtimeTrampoline });
8068
+ if (config.framework === "fasthtml") {
8069
+ const { SESSKEY = "" } = process.env;
8070
+ files[".sesskey"] = new import_build_utils18.FileBlob({ data: `"${SESSKEY}"` });
8071
+ }
7805
8072
  const depExternalizer = new PythonDependencyExternalizer({
7806
8073
  venvPath,
7807
8074
  vendorDir,
@@ -7829,18 +8096,64 @@ from vercel_runtime.vc_init import vc_handler
7829
8096
  if (depAnalysis.runtimeInstallEnabled) {
7830
8097
  await depExternalizer.generateBundle(files);
7831
8098
  } else {
7832
- for (const [p, f] of Object.entries(depAnalysis.allVendorFiles)) {
7833
- files[p] = f;
8099
+ addFiles(files, depAnalysis.allVendorFiles);
8100
+ if (automaticCompileAllEnabled) {
8101
+ await builderSpan.child("vc.builder.python.compileall").trace(async (compileSpan) => {
8102
+ const sitePackageDirs = (await getVenvSitePackagesDirs(venvPath)).filter((d) => import_fs14.default.existsSync(d));
8103
+ const pythonBin = getVenvPythonBin(venvPath);
8104
+ console.log("Compiling Python application bytecode...");
8105
+ await runCompileAll({
8106
+ pythonBin,
8107
+ filesOrDirectories: [workPath],
8108
+ env: pythonEnv,
8109
+ excludeRegex: getCompileAllAppExcludeRegex(workPath)
8110
+ });
8111
+ console.log("Compiling Python dependency bytecode...");
8112
+ await runCompileAll({
8113
+ pythonBin,
8114
+ filesOrDirectories: sitePackageDirs,
8115
+ env: pythonEnv
8116
+ });
8117
+ compileSpan.setAttributes({
8118
+ "python.compileall.enabled": "true",
8119
+ "python.compileall.sitePackageDirectoryCount": String(
8120
+ sitePackageDirs.length
8121
+ )
8122
+ });
8123
+ });
8124
+ const pythonOnHiveEnabled = process.env.VERCEL_PYTHON_ON_HIVE === "1" || process.env.VERCEL_PYTHON_ON_HIVE === "true";
8125
+ const activeThreshold = pythonOnHiveEnabled ? HIVE_LAMBDA_SIZE_BYTES : LAMBDA_SIZE_THRESHOLD_BYTES;
8126
+ const currentSize = await calculateBundleSize(files);
8127
+ let remainingCapacity = activeThreshold - currentSize;
8128
+ if (pythonVersion.major != null && pythonVersion.minor != null) {
8129
+ const appBytecodeInfo = await collectAppBytecodeFiles({
8130
+ workPath,
8131
+ files,
8132
+ pythonMajor: pythonVersion.major,
8133
+ pythonMinor: pythonVersion.minor
8134
+ });
8135
+ remainingCapacity = addBytecodeWithinCapacity(
8136
+ files,
8137
+ appBytecodeInfo,
8138
+ remainingCapacity
8139
+ );
8140
+ }
8141
+ const vendorBytecodeInfo = await depExternalizer.collectBytecodeFiles(
8142
+ {
8143
+ vendorDirName: vendorDir
8144
+ }
8145
+ );
8146
+ await addVendorBytecodeWithinCapacity({
8147
+ files,
8148
+ depExternalizer,
8149
+ vendorDir,
8150
+ bytecodeInfo: vendorBytecodeInfo,
8151
+ capacity: remainingCapacity
8152
+ });
7834
8153
  }
7835
8154
  }
7836
8155
  });
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({
8156
+ const output = new import_build_utils18.Lambda({
7844
8157
  files,
7845
8158
  handler: `${handlerPyFilename}.vc_handler`,
7846
8159
  runtime: pythonVersion.runtime,
@@ -7856,19 +8169,19 @@ from vercel_runtime.vc_init import vc_handler
7856
8169
  pythonVersion,
7857
8170
  uvLockPath,
7858
8171
  framework,
7859
- serviceType: service ? (0, import_build_utils17.getReportedServiceType)(service) : void 0
8172
+ serviceType: service ? (0, import_build_utils18.getReportedServiceType)(service) : void 0
7860
8173
  });
7861
8174
  } catch (err) {
7862
- (0, import_build_utils17.debug)(
8175
+ (0, import_build_utils18.debug)(
7863
8176
  `Failed to write project manifest: ${err instanceof Error ? err.message : String(err)}`
7864
8177
  );
7865
8178
  }
7866
8179
  }
7867
- if (!(0, import_build_utils17.isPythonFramework)(framework) && !service?.name) {
8180
+ if (!(0, import_build_utils18.isPythonFramework)(framework) && !service?.name) {
7868
8181
  return { resultVersion: 3, result: { output } };
7869
8182
  }
7870
8183
  const lambdaPath = service?.name ? `_svc/${service.name}/index` : "index";
7871
- const staticFiles = djangoStatic?.cdnOutputDir ? await (0, import_build_utils17.glob)("**", { cwd: djangoStatic.cdnOutputDir }) : {};
8184
+ const staticFiles = djangoStatic?.cdnOutputDir ? await (0, import_build_utils18.glob)("**", { cwd: djangoStatic.cdnOutputDir }) : {};
7872
8185
  const routes = service?.name ? void 0 : [{ handle: "filesystem" }, { src: "/(.*)", dest: `/${lambdaPath}` }];
7873
8186
  return {
7874
8187
  resultVersion: 2,
@@ -7897,14 +8210,14 @@ var prepareCache = async ({
7897
8210
  }
7898
8211
  } catch {
7899
8212
  }
7900
- return (0, import_build_utils17.glob)("**/.vercel/python/{.venv,services/*/.venv,cache/uv}/**", {
8213
+ return (0, import_build_utils18.glob)("**/.vercel/python/{.venv,services/*/.venv,cache/uv}/**", {
7901
8214
  cwd: root,
7902
8215
  ignore
7903
8216
  });
7904
8217
  };
7905
8218
  var shouldServe = (opts) => {
7906
8219
  const framework = opts.config.framework;
7907
- if ((0, import_build_utils17.isPythonFramework)(framework)) {
8220
+ if ((0, import_build_utils18.isPythonFramework)(framework)) {
7908
8221
  const requestPath = opts.requestPath.replace(/\/$/, "");
7909
8222
  if (requestPath.startsWith("api") && opts.hasMatched) {
7910
8223
  return false;
@@ -7923,7 +8236,7 @@ var defaultShouldServe = ({
7923
8236
  if (entrypoint === requestPath && hasProp(files, entrypoint)) {
7924
8237
  return true;
7925
8238
  }
7926
- const { dir, name } = (0, import_path13.parse)(entrypoint);
8239
+ const { dir, name } = (0, import_path14.parse)(entrypoint);
7927
8240
  if (name === "index" && dir === requestPath && hasProp(files, entrypoint)) {
7928
8241
  return true;
7929
8242
  }