Skip to content

fix(cli): name the vercel function b4.func instead of index.func - #691

Closed
blove wants to merge 9 commits into
mainfrom
fix/vercel-function-name
Closed

blove wants to merge 9 commits into
mainfrom
fix/vercel-function-name

Conversation

@blove

@blove blove commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #687.

Problem

The vercel target emitted .vercel/output/functions/index.func with config.json routing /(.*) to /index. In the Build Output API a function named index is also served at /, so it shadowed a static index.html for any app that ships a frontend beside the runtime. hashbrown had to copy the function as agent.func in an external assembler (liveloveapp/hashbrown@cf3f94f).

Change

  • Default function name is now b4: b4 build emits functions/b4.func and config.json routes /(.*) to /b4. validateVercelOutput validates the name/route pair it is given (default b4), so an output built for another name is rejected rather than silently accepted.
  • New build.vercel.functionName option (@b4run/core B4Config): one path segment of letters, digits, _ or -. Both b4 build (before any filesystem work) and b4 check reject anything else with B4_E1003. Setting it to "index" restores the old layout exactly.
  • BuildEmitContext now carries the loaded config so targets can read their own build.<target> block.
  • Docs: the b4 build reference gains the missing vercel bullet; the Upgrading page gets a compatibility section.
  • Changeset (patch) with a compatibility note: existing deployments' output paths change, and anything reading .vercel/output by path must use the new name or pin functionName: "index".

Tests

  • vercel-target.test.ts: custom name emits agent.func and routes to /agent; six invalid names ("", ../escape, index/../escape, a b, .hidden, a number) are rejected before .vercel is created; the Build Output contract test proves the default validator rejects an output written for another name.
  • check-error-codes.test.ts: invalid build.vercel.functionName → [B4_E1003] with the docs link.
  • Existing index.func expectations across build-targets, vercel-target, vercel-native-lane and the native fixture helper moved to b4.func.

Ran locally: vercel-target, build-targets, check-error-codes, vercel-native-lane (424 passed, 1 gated skip), plus lint and typecheck for @b4run/cli and @b4run/core.

Not released.

🤖 Generated with Claude Code

In the Build Output API a function named `index` is also served at `/`,
so `.vercel/output/functions/index.func` shadowed a static `index.html`
for any app shipping a frontend beside the runtime. The target now
emits `functions/b4.func` with `config.json` routing `/(.*)` to `/b4`,
and `validateVercelOutput` checks that pair.

`build.vercel.functionName` picks a different name (one path segment of
letters, digits, `_` or `-`); `b4 check` and `b4 build` reject anything
else before writing. The loaded config now travels on BuildEmitContext
so targets can read their own `build.<target>` block.

Fixes #687

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Sep 17, 2026 8:21pm UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

The docs checker's B4Config path inventory and the Key reference on the
configuration page both enumerate every config key, so the new option
has to appear in both.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Resolves four conflicts against #693 (typed build.targets) and #698
(vercel Postgres driver):

- core types.ts and the configuration reference keep main's
  BuildTargetName union alongside the new build.vercel block.
- The targets registry keeps main's Record<BuildTargetName, BuildTarget>
  alongside the config field on BuildEmitContext.
- The SEO lastmod manifest is regenerated rather than hand-merged.

Also renames the function path in #698's new "Run the Vercel bundle
locally" snippet, which still imported index.func.

Co-Authored-By: Claude Opus 5 <[email protected]>
blove and others added 2 commits September 17, 2026 10:19
Adopts #697's build.vercel resolver instead of the parallel one this
branch added:

- functionName moves into resolveVercelBuildConfig beside
  reconcileVercelJson, so one resolver validates the whole build.vercel
  shape and b4 check/b4 build reject a bad name through the path that
  already rejects a bad flag. The separate check.ts hook is gone.
- The emitter reads ctx.buildConfig (#697) rather than the ctx.config
  field this branch had added, and resolves both options in one call.
- types.ts, the config reference, and the CLI page carry both options.
- #697's new prebuilt test asserted the old index.func path; updated,
  plus a test that both options are honored together.

Co-Authored-By: Claude Opus 5 <[email protected]>
The build target context carries buildConfig from #697, so the config
field this branch had added is gone. Spreads skip excess-property
checks, so the leftover spread compiled silently.

Co-Authored-By: Claude Opus 5 <[email protected]>
@blove

blove commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Drive-by from #697, since this PR is already editing NATIVE_REMOTE_BUILD_SIGNATURE in packages/cli/test/helpers/vercel-native-fixture.ts.

That list is consumed as an exact-ordered, all-present signature: exactOrderedSignature requires every entry to appear exactly once and in increasing index order. As of #697 the last entry, "wrote vercel.json", is conditional rather than guaranteed. The vercel target drops vercel.json from its emitted artifacts when build.vercel.reconcileVercelJson is false, which is the prebuilt-CI configuration.

Nothing is broken today: the flag defaults to true and this lane's fixtures do not set it, so the marker is always emitted and the lane stays green. It is a latent trap for whoever next configures the lane's fixture for a prebuilt-only project. That change would flip exactOrderedSignature to false, and the failure surfaces as native Vercel source build provenance is incomplete without naming which marker went missing, which is a slow thing to debug.

Two options, whichever fits your rename:

  • derive the expected tail from the fixture's own config, so the vercel.json marker is expected only when reconciliation is on; or
  • leave the list as-is and make the mismatch name the offending marker, so the next person gets missing marker: wrote vercel.json instead of the generic message.

Entirely your call whether to fold it in here or leave it. Flagging rather than opening a competing PR, since your diff already owns these lines.

Only the generated SEO lastmod manifest conflicted; regenerated rather
than hand-merged. No code overlap with #694, #701, or the
software-factory work order.

Co-Authored-By: Claude Opus 5 <[email protected]>
Integrates #695 (vercel outDir + relaxed output validator), which
landed on the same files:

- functionName joins outDir and reconcileVercelJson in the shared
  build.vercel resolver.
- The relaxed validator asserted a route reaching a hardcoded /index;
  it now takes the resolved function name, so a composed config.json
  is still checked against the function the build actually wrote.
- The emitter derives both the staged and published function
  directories from the name, on top of #695's outDir staging.
- Docs and the config path inventory carry all three options.

Co-Authored-By: Claude Opus 5 <[email protected]>
Only the generated SEO lastmod manifest conflicted with #705;
regenerated rather than hand-merged.

Co-Authored-By: Claude Opus 5 <[email protected]>
@blove

blove commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #696, which covers the same ground as part of the composed Build Output work.

Both PRs added build.vercel.functionName and a config field on BuildEmitContext, and both were approved with auto-merge enabled, so whichever landed second would have conflicted on exactly those two additions.

#696 addresses the shadowing this PR fixes: it exposes build.vercel.functionName, defaults the runtime function to b4 as soon as build.vercel.static is configured, and fails the build with a pointed error if functionName: "index" is combined with static assets. That covers the case where a function named index would shadow static/index.html, which is the actual bug in #687.

The one behavioural difference worth noting: this PR renamed the function unconditionally, while #696 keeps index for a bare runtime build with no static assets. #687 stays open to track whether the unconditional rename is still wanted on top of #696.

No work is lost; nothing here is needed once #696 lands.

@blove blove closed this Sep 17, 2026
auto-merge was automatically disabled September 17, 2026 20:21

Pull request was closed

blove added a commit that referenced this pull request Sep 17, 2026
Neither change affects this page. #705 batches route-discovery errors,
and #708 is the edge page's own local-run recipe switching from /healthz
to /readyz for the same reason this guide already did.

#691 was closed unmerged, so the emitted function directory is still
index.func and this page's shadowing argument stands unchanged.

Only the lastmod manifest conflicted; regenerated.

Co-Authored-By: Claude Opus 5 <[email protected]>

This branch was successfully deployed

1 active and 1 inactive deployments
Preview — e51d64e2 Deployed Sep 17, 2026 by vercel[bot]
vercel-preview — e51d64e2 Deployed Sep 17, 2026 by blove via vercel-native #2001
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.

vercel target: function named index shadows a static index.html at /

1 participant