@vercel/python 5.0.2 → 5.0.3

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 +43 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2967,6 +2967,23 @@ function isInstalled2({ pipPath, pythonPath }) {
2967
2967
  // src/index.ts
2968
2968
  var readFile = (0, import_util.promisify)(import_fs.default.readFile);
2969
2969
  var writeFile = (0, import_util.promisify)(import_fs.default.writeFile);
2970
+ var fastapiEntrypointFilenames = ["app", "index", "server", "main"];
2971
+ var fastapiEntrypointDirs = ["", "src", "app"];
2972
+ var fastapiContentRegex = /(from\s+fastapi\s+import\s+FastAPI|import\s+fastapi|FastAPI\s*\()/;
2973
+ var fastapiCandidateEntrypoints = fastapiEntrypointFilenames.flatMap(
2974
+ (filename) => fastapiEntrypointDirs.map((dir) => import_path2.posix.join(dir, `${filename}.py`))
2975
+ );
2976
+ function isFastapiEntrypoint(file) {
2977
+ try {
2978
+ const fsPath = file.fsPath;
2979
+ if (!fsPath)
2980
+ return false;
2981
+ const contents = import_fs.default.readFileSync(fsPath, "utf8");
2982
+ return fastapiContentRegex.test(contents);
2983
+ } catch {
2984
+ return false;
2985
+ }
2986
+ }
2970
2987
  async function pipenvConvert(cmd, srcDir, env) {
2971
2988
  (0, import_build_utils3.debug)("Running pipfile2req...");
2972
2989
  try {
@@ -3023,6 +3040,32 @@ var build = async ({
3023
3040
  throw err;
3024
3041
  }
3025
3042
  let fsFiles = await (0, import_build_utils3.glob)("**", workPath);
3043
+ if (!fsFiles[entrypoint]) {
3044
+ let discovered;
3045
+ if (config?.framework === "fastapi") {
3046
+ const entrypointCandidates = fastapiCandidateEntrypoints.filter(
3047
+ (c) => !!fsFiles[c]
3048
+ );
3049
+ if (entrypointCandidates.length) {
3050
+ const fastapiEntrypoint = entrypointCandidates.find(
3051
+ (c) => isFastapiEntrypoint(fsFiles[c])
3052
+ );
3053
+ discovered = fastapiEntrypoint || entrypointCandidates[0];
3054
+ }
3055
+ }
3056
+ if (discovered) {
3057
+ (0, import_build_utils3.debug)(
3058
+ `Resolved Python entrypoint to "${discovered}" (configured "${entrypoint}" not found).`
3059
+ );
3060
+ entrypoint = discovered;
3061
+ } else if (config?.framework === "fastapi") {
3062
+ const searchedList = fastapiCandidateEntrypoints.join(", ");
3063
+ throw new import_build_utils3.NowBuildError({
3064
+ code: "FASTAPI_ENTRYPOINT_NOT_FOUND",
3065
+ message: `No FastAPI entrypoint found. Searched for: ${searchedList}`
3066
+ });
3067
+ }
3068
+ }
3026
3069
  const entryDirectory = (0, import_path2.dirname)(entrypoint);
3027
3070
  const hasReqLocal = !!fsFiles[(0, import_path2.join)(entryDirectory, "requirements.txt")];
3028
3071
  const hasReqGlobal = !!fsFiles["requirements.txt"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/python",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "main": "./dist/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/python",