Skip to content

[python] only create api builders for .py files that export an app or handler#14493

Merged
ricardo-agz merged 9 commits into
mainfrom
ricardo/voc-1762-py-files-api-builders
Dec 18, 2025
Merged

[python] only create api builders for .py files that export an app or handler#14493
ricardo-agz merged 9 commits into
mainfrom
ricardo/voc-1762-py-files-api-builders

Conversation

@ricardo-agz

@ricardo-agz ricardo-agz commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

A helper file in /api that does not export an app or http handler should not create a lambda. This PR adds a helper to build-utils to detect if a file contains a top-level app or handler

@changeset-bot

changeset-bot Bot commented Dec 17, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 66e6dc7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@vercel/build-utils Patch
vercel Patch
@vercel/fs-detectors Patch
@vercel/python Patch
@vercel/client Patch
@vercel/elysia Patch
@vercel/express Patch
@vercel/fastify Patch
@vercel/gatsby-plugin-vercel-builder Patch
@vercel/h3 Patch
@vercel/hono Patch
@vercel/nestjs Patch
@vercel/node Patch
@vercel/static-build Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

🧪 Test Strategy

Comparing: b56ac0766e6dc7 (view diff)

Strategy: Code changed outside of a package - running ALL tests

⚠️ All tests will run because global code changes could impact all packages.

Affected packages - 39 (100%)
  1. @vercel-internals/get-package-json
  2. @vercel/backends
  3. @vercel/build-utils
  4. @vercel/cervel
  5. @vercel/cli-auth
  6. @vercel/client
  7. @vercel/config
  8. @vercel/detect-agent
  9. @vercel/edge
  10. @vercel/elysia
  11. @vercel/error-utils
  12. @vercel/express
  13. @vercel/fastify
  14. @vercel/firewall
  15. @vercel/frameworks
  16. @vercel/fs-detectors
  17. @vercel/functions
  18. @vercel/gatsby-plugin-vercel-builder
  19. @vercel/go
  20. @vercel/h3
  21. @vercel/hono
  22. @vercel/hydrogen
  23. @vercel/introspection
  24. @vercel/nestjs
  25. @vercel/next
  26. @vercel/node
  27. @vercel/oidc
  28. @vercel/oidc-aws-credentials-provider
  29. @vercel/python
  30. @vercel/redwood
  31. @vercel/related-projects
  32. @vercel/remix-builder
  33. @vercel/routing-utils
  34. @vercel/ruby
  35. @vercel/rust
  36. @vercel/static-build
  37. @vercel/static-config
  38. examples
  39. vercel

Results

  • Unit tests: All affected packages will run unit tests
  • E2E tests: All e2e tests will run
  • Type checks: All affected packages will run type checks

This comment is automatically generated based on the affected testing strategy

Comment thread packages/fs-detectors/src/detect-builders.ts Outdated
@ricardo-agz ricardo-agz merged commit c55475f into main Dec 18, 2025
365 of 369 checks passed
@ricardo-agz ricardo-agz deleted the ricardo/voc-1762-py-files-api-builders branch December 18, 2025 18:14
onsclom pushed a commit that referenced this pull request Dec 19, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/build-utils@13.2.4

### Patch Changes

- [python] only create api builders for `.py` files that export an app
or handler ([#14493](#14493))

## vercel@50.1.3

### Patch Changes

- Run install command earlier for vercel.ts
([#14504](#14504))

- [python] only create api builders for `.py` files that export an app
or handler ([#14493](#14493))

- Remove vercel.ts feature flag
([#14501](#14501))

- Updated dependencies
\[[`f8e79cd385e3635a5d8227cb357af381b883d053`](f8e79cd),
[`c55475f865ecf22f27b8b17f6fc98b9e1455ab5d`](c55475f)]:
    -   @vercel/ruby@2.2.4
    -   @vercel/build-utils@13.2.4
    -   @vercel/python@6.1.5
    -   @vercel/backends@0.0.17
    -   @vercel/elysia@0.1.15
    -   @vercel/express@0.1.21
    -   @vercel/fastify@0.1.18
    -   @vercel/go@3.2.4
    -   @vercel/h3@0.1.24
    -   @vercel/hono@0.2.18
    -   @vercel/hydrogen@1.3.3
    -   @vercel/nestjs@0.2.19
    -   @vercel/next@4.15.9
    -   @vercel/node@5.5.16
    -   @vercel/redwood@2.4.6
    -   @vercel/remix-builder@5.5.6
    -   @vercel/rust@1.0.4
    -   @vercel/static-build@2.8.15

## @vercel/client@17.2.18

### Patch Changes

- Updated dependencies
\[[`c55475f865ecf22f27b8b17f6fc98b9e1455ab5d`](c55475f)]:
    -   @vercel/build-utils@13.2.4

## @vercel/elysia@0.1.15

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.5.16

## @vercel/express@0.1.21

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.5.16

## @vercel/fastify@0.1.18

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.5.16

## @vercel/fs-detectors@5.7.11

### Patch Changes

- [python] only create api builders for `.py` files that export an app
or handler ([#14493](#14493))

## @vercel/gatsby-plugin-vercel-builder@2.0.114

### Patch Changes

- Updated dependencies
\[[`c55475f865ecf22f27b8b17f6fc98b9e1455ab5d`](c55475f)]:
    -   @vercel/build-utils@13.2.4

## @vercel/h3@0.1.24

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.5.16

## @vercel/hono@0.2.18

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.5.16

## @vercel/nestjs@0.2.19

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/node@5.5.16

## @vercel/node@5.5.16

### Patch Changes

- Updated dependencies
\[[`c55475f865ecf22f27b8b17f6fc98b9e1455ab5d`](c55475f)]:
    -   @vercel/build-utils@13.2.4

## @vercel/python@6.1.5

### Patch Changes

- [python] only create api builders for `.py` files that export an app
or handler ([#14493](#14493))

## @vercel/ruby@2.2.4

### Patch Changes

- Replace bundle install flags with environment variables.
([#14499](#14499))

## @vercel/static-build@2.8.15

### Patch Changes

-   Updated dependencies \[]:
    -   @vercel/gatsby-plugin-vercel-builder@2.0.114

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
smaeda-ks added a commit that referenced this pull request Apr 8, 2026
Add static entrypoint detection for Node.js files in `/api/`,
mirroring #14493 which did the same for Python. Helper/utility files
that don't export a valid handler are no longer treated as API routes,
avoiding unnecessary Vercel Function creation.

Gated behind `VERCEL_NODE_FILTER_ENTRYPOINTS=1` env var for safe
incremental rollout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
smaeda-ks added a commit that referenced this pull request Apr 9, 2026
…15873)

## Summary

- Adds static entrypoint detection for Node.js files in `/api/`,
mirroring #14493 which did the same for Python
- Helper/utility files that don't export a valid handler are no longer
treated as API routes, avoiding unnecessary Vercel Function creation
- Gated behind `VERCEL_NODE_FILTER_ENTRYPOINTS=1` environment variable
for safe incremental rollout

## How it works

A new `isNodeEntrypoint()` function in `@vercel/build-utils` uses
regex-based heuristics to detect valid handler export patterns in `.js`,
`.mjs`, `.ts`, and `.tsx` files:

| Pattern | Example |
|---------|---------|
| ESM default export | `export default function handler(req, res) {}` |
| CJS module.exports | `module.exports = (req, res) => {}` |
| Named HTTP method exports | `export function GET(request) {}` |
| Fetch export | `export function fetch(request) {}` |
| Re-exports | `export { handler as default }` |
| Server handler | `http.createServer(...)` |

Files that don't match any pattern (e.g., utility functions, type-only
files, config exports) are skipped in `maybeGetApiBuilder()` and won't
produce a Vercel Function.

## Test plan

- [ ] 34 unit tests for `isNodeEntrypoint()` covering valid entrypoints,
non-entrypoints, and edge cases
- [ ] 3 integration tests in fs-detectors verifying builder
creation/skipping with actual files on disk
- [ ] Verified all 116+ existing handler files across Node builder and
CLI test fixtures match at least one detection pattern
- [ ] Verified feature is inactive without env var (zero behavior change
by default)


🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants