Skip to content

feat(cli): compose static assets, functions, and routes into the Vercel build output - #696

Merged
blove merged 23 commits into
mainfrom
blove/vercel-composed-output
Sep 17, 2026
Merged

blove merged 23 commits into
mainfrom
blove/vercel-composed-output

Conversation

@blove

@blove blove commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #679. Also resolves the validator half of #680 and the function-name half of #687.

b4 build with the vercel target used to emit only the runtime function and a catch-all config.json, so a real app had to post-process the published tree (hashbrown's tools/vercel/assemble.mjs). The target can now compose the whole Build Output API v3 tree from b4.config.ts:

build: {
  targets: ["vercel"],
  vercel: {
    static: { dir: "../web/dist", spaFallback: "index.html" },
    functions: { api: { entry: "src/api.ts", maxDuration: 30, supportsResponseStreaming: true } },
    routes: [{ src: "/api/(.*)", dest: "/api" }],
  },
}
  • build.vercel schema (@b4run/core): functionName, static { dir, spaFallback }, functions { entry, runtime, maxDuration, supportsResponseStreaming }, routes. Exported as VercelBuildConfig / VercelBuildRoute.
  • Composition (@b4run/cli): every configured path is checked before .vercel/ is touched; the static dir is copied into static/ (symlinks dereferenced); each extra function is esbuild-bundled into functions/<name>.func/ with its .vc-config.json; routes are ordered user routes → { handle: "filesystem" } → runtime → SPA fallback. Everything lands in the existing per-invocation staging dir and goes through the existing validate → atomic rename → backup/rollback publish.
  • Function name (vercel target: function named index shadows a static index.html at / #687): unchanged index.func for a bare runtime build (the gated vercel-native lane pins that listing). Once static is configured the default becomes b4.func, since a function named index is served at / and shadows static/index.html; functionName overrides either default, and "index" beside static fails the build with a pointed error.
  • Runtime route under a SPA fallback: scoped to /(healthz|agui|threads|memory)(/.*)? so every other path falls through to the SPA document. Without a fallback the runtime stays the catch-all.
  • validateVercelOutput(outputDir, { functionName }) (vercel target: allow an output directory override and relax validateVercelOutput #680): accepts a composed config.json (must route to the runtime function; { handle: "filesystem" } at most once; route keys allow-listed), keeps the runtime function's .vc-config.json exact, and applies the same symlink/dependency containment checks to every extra functions/*.func. The one-argument call used by the native lane keeps working.
  • BuildEmitContext gains optional config so targets can read the loaded config.

Not in this PR: per-option config for the runtime function (maxDuration / supportsResponseStreaming, which hashbrown merges into it). build.vercel.outDir / --out-dir arrived separately in #695 and is integrated here (see below).

Design note: docs/superpowers/specs/2026-09-16-vercel-composed-output-design.md.

Validation

  • pnpm lint
  • pnpm build
  • pnpm --filter @b4run/core --filter @b4run/cli typecheck
  • vitest test/vercel-target.test.ts test/vercel-compose.test.ts test/build-targets.test.ts — 165 passed (29 new pure-unit tests, 26 new validator/integration tests; the composed-tree integration test builds a fixture with a SPA, an extra function, and a user route through runBuildCommand and asserts the published tree, config.json, both .vc-config.json files, and the reported artifact list)
  • node scripts/check-docs.mjs (config-path inventory extended with build.vercel.*)
  • node scripts/check-changesets.mjs
  • pnpm test:release-integrity
  • pnpm --filter @b4run/web seo:lastmod:check (manifest regenerated)
  • Full pnpm --filter @b4run/cli test — 165 files, 1918 passed, 4 skipped on the post-merge tree (raised per-test timeout; the machine was saturated by a concurrent vitest, no assertion failures).
  • pnpm pack:check — not run locally (no packaging changes; CI pack-smoke covers it).
  • Real vercel-native lane — gated; the default build listing it pins is unchanged.

Merged with main (2026-09-17)

Rebased onto main after #693 (build.targets typed as BuildTargetName), #698 (vercel target reaching plain Postgres), and #692. Conflicts resolved in four files:

  • packages/core/src/types.ts — kept main's readonly BuildTargetName[] typing for targets, added vercel?: VercelBuildConfig beside it.
  • packages/cli/src/lib/build/targets/index.ts — kept main's Record<BuildTargetName, BuildTarget> registry, kept the added config?: B4Config context field.
  • apps/web/content/docs/configuration.mdx — merged main's BuildTargetName prose with the build.vercel schema block and paragraph.
  • apps/web/app/seo/lastmod.generated.json — took main's copy, regenerated.

Re-verified on the merged tree: pnpm build, pnpm typecheck (53 tasks), pnpm lint, node scripts/check-docs.mjs, seo:lastmod:check, @b4run/core tests (539 passed), @b4run/cli tests (165 files, 1918 passed, 4 skipped).

Second merge with main — unified build.vercel (2026-09-17)

Main then took #697, which introduced build.vercel.reconcileVercelJson under the same config key as this PR, with its own resolveVercelBuildConfig that rejects unknown keys, plus a ctx.buildConfig field overlapping the ctx.config added here. Left side by side, each resolver would reject the other's options — build.vercel: { static: … } would have failed with "Unknown build.vercel option(s): static".

Unified into the single resolver #697's own commit message asks for:

  • vercel-config.ts's resolveVercelBuildConfig(build, appRoot) now owns the shape of all of build.vercel and returns { reconcileVercelJson, composition }. It keeps feat(cli): opt the vercel target out of vercel.json reconciliation #697's misplaced-flag, non-object and non-boolean rejections, and delegates the tree keys to resolveVercelComposition (this PR's resolver, renamed from its colliding name).
  • VERCEL_BUILD_OPTION_KEYS is the union of both key sets, so an unknown option names every known one.
  • BuildEmitContext keeps only feat(cli): opt the vercel target out of vercel.json reconciliation #697's buildConfig; the redundant config field added here is gone.
  • b4 check now validates the composition keys too, which two separate resolvers would not have done.
  • VercelBuildConfig in @b4run/core absorbs reconcileVercelJson, so one interface describes the key.

Eight new tests cover the unified resolver (both axes together, each alone, an absent section, the unknown-key message, the misplaced and non-boolean flag, and a composition error surfacing through the same entry point). Four pass shapes the type forbids, via an explicit untyped cast, since a b4.config.js or JSON config arrives with no compiler.

Re-verified after this merge: pnpm build, pnpm typecheck (53 tasks), pnpm lint, node scripts/check-docs.mjs, node scripts/check-changesets.mjs, seo:lastmod:check, @b4run/core (539 passed), @b4run/cli (167 files, 1982 passed, 4 skipped) — including main's own tests for #697's rejection paths.

A real bug caught by merging #694 (2026-09-17)

#694 added a /readyz readiness probe beside /healthz. The scoped runtime route this PR installs under a SPA fallback listed only /healthz, /agui, /threads, /memory — so on a composed Vercel deployment /readyz fell through to { src: "/(.*)", dest: "/<spaFallback>" } and served the SPA document with a 200. A readiness probe that returns HTML and success is the worst shape of wrong: it reports healthy while reporting nothing.

Fixed test-first. Beyond adding readyz, the composed route is now covered by one case per rooted runtime surface (/healthz, /readyz, /threads, /threads/:id/runs/stream, /agui/:id, /memory/candidates, …) plus negative cases (/, /index.html, /assets/app.js, /about), so a surface added to the runtime later cannot be left out of this route silently. The integration test now asserts the route from the exported constant rather than a duplicated literal.

Integrating #695 — outDir and a second validator relaxation (2026-09-17)

Main then took #695, which implemented the half of #680 this PR had deferred — and relaxed the same validateVercelOutput in its own way.

  • outDir joins the unified build.vercel: the one resolver now validates functionName, static, functions, routes, outDir and reconcileVercelJson together and returns the output directory, the flag and the composition.
  • Two relaxations became one. feat(cli): vercel output directory override and relaxed output validator #695's asserted a route to a hardcoded /index; this PR's parameterizes on the runtime function name and also checks route shapes, the filesystem phase and every extra function. Kept the parameterized one, adopted feat(cli): vercel output directory override and relaxed output validator #695's clearer error wording (its tests assert that phrasing), and aligned this PR's own assertions to match.
  • feat(cli): vercel output directory override and relaxed output validator #695's staging model won, being strictly better: the runtime stages inside the app root so its imports resolve, while the output tree stages beside its destination so publication stays a same-device rename. The composed tree is written into that staged output, and cleanup covers both directories.
  • The non-array and empty-array route checks are now separate, so each reports precisely what is wrong instead of one message that satisfied neither test.

Re-verified: pnpm build, pnpm typecheck (54 tasks), pnpm lint, node scripts/check-docs.mjs, seo:lastmod:check, @b4run/cli (167 files, 1996 passed, 4 skipped).

One unrelated flake appeared in an intermediate run: dev-command.test.ts > serializes a watched edit that arrives during initial child startup timed out waiting for a child pid file. It passes in isolation, passed in the runs either side, and is in a file this PR does not touch — the known process-runner descendant-startup flake.

Release Notes

  • Changeset added (@b4run/cli, @b4run/core, patch).

Screenshots Or Artifacts

Composed output for the test fixture:

.vercel/output/
  config.json
  functions/api.func/{.vc-config.json,index.mjs}
  functions/b4.func/{.vc-config.json,index.mjs}
  static/assets/app.js
  static/index.html
{ "routes": [
    { "dest": "/api", "src": "/api/(.*)" },
    { "handle": "filesystem" },
    { "dest": "/b4", "src": "/(healthz|agui|threads|memory)(/.*)?" },
    { "dest": "/index.html", "src": "/(.*)" } ],
  "version": 3 }

Checklist

  • I read CONTRIBUTING.md.
  • I followed CODE_OF_CONDUCT.md.
  • I did not include secrets, credentials, or private data.
  • I am not disclosing a security vulnerability publicly.

🤖 Generated with Claude Code

blove and others added 4 commits September 16, 2026 22:01
…lidator

Pure resolver for build.vercel (functionName, static, functions, routes),
route composition in Build Output order, and a validator that accepts a
composed tree while keeping the runtime function config exact.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e Vercel build output

build.vercel describes the Build Output tree beyond the runtime function.
The target checks every configured path before touching .vercel/, copies
the static dir, bundles each extra function, orders routes as user routes
-> filesystem -> runtime -> SPA fallback, and validates the composed tree
before the existing atomic publish. The runtime function is b4.func when
static assets are configured so it does not shadow static/index.html.

Refs #679, #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 10:29pm 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.

blove and others added 2 commits September 17, 2026 09:09
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
#	apps/web/content/docs/configuration.mdx
#	packages/cli/src/lib/build/targets/index.ts
#	packages/core/src/types.ts
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
#	apps/web/content/docs/cli.mdx
#	apps/web/content/docs/configuration.mdx
#	packages/cli/src/lib/build/targets/index.ts
#	packages/cli/src/lib/build/targets/vercel.ts
#	packages/core/src/types.ts
#	scripts/check-docs.mjs
blove and others added 2 commits September 17, 2026 09:45
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
blove and others added 3 commits September 17, 2026 10:40
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
#694 added /readyz beside /healthz. The scoped runtime route a SPA fallback
installs did not list it, so on a composed Vercel deployment /readyz matched
the fallback and served the SPA document with a 200 rather than reaching the
runtime — a readiness probe that looks healthy while reporting nothing.

Add readyz, and cover the composed route with one case per rooted runtime
surface so a future surface cannot be added without updating it.

Co-Authored-By: Claude Opus 5 <[email protected]>
The integration test duplicated the route string, so adding /readyz to the
implementation left a stale literal asserting the old value. Reference the
constant instead.

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

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
#	apps/web/content/docs/cli.mdx
#	apps/web/content/docs/configuration.mdx
#	packages/cli/src/lib/build/targets/vercel-config.ts
#	packages/cli/src/lib/build/targets/vercel-output.ts
#	packages/cli/src/lib/build/targets/vercel.ts
#	packages/cli/test/vercel-target.test.ts
#	packages/core/src/types.ts
#	scripts/check-docs.mjs
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
The runtime function's .vc-config.json carried only handler, launcherType
and runtime, so Vercel's Node launcher buffered its responses. The runtime
answers /agui/:routeId and /threads/:id/runs/stream with text/event-stream,
which meant a deployed frontend received nothing until a run finished
instead of tokens as they were produced. Extra functions configured through
build.vercel.functions could already opt into streaming; the one function
that always streams could not.

supportsResponseStreaming is fixed rather than configurable: it follows from
what the runtime serves, not from how the app is deployed. validateVercelOutput
keeps asserting the runtime config exactly, deriving both the written bytes and
the expectation from the same constant.

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

resolveVercelComposition threw bare CliErrors, so a malformed
build.vercel.static.dir printed an uncoded line while an unknown
build.vercel key printed the coded, linked form check-error-codes.test.ts
asserts. Move the shared invalidBuildConfig helper into vercel-compose.ts,
which vercel-config.ts already depends on, and route every throw through it.

Also qualify the local-run snippet in the edge docs: the runtime function is
index.func only until build.vercel.static renames it.

Co-Authored-By: Claude Opus 5 <[email protected]>
blove and others added 2 commits September 17, 2026 13:35
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
#	apps/web/content/docs/deployment/edge.mdx
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
blove and others added 2 commits September 17, 2026 15:26
…-output

# Conflicts:
#	apps/web/app/seo/lastmod.generated.json
#	apps/web/content/docs/cli.mdx
#	apps/web/content/docs/deployment.mdx
#700 added the guide against the pre-change behaviour: its compose section
said the target emits no static dir, no extra functions and no routes, and
cited #679/#687 as open proposals. Rewrite it around build.vercel, keep the
assemble-it-yourself path as a scoped subsection since outDir still serves
that case, and qualify the artifacts table as the bare-build shape.

Co-Authored-By: Claude Opus 5 <[email protected]>
@blove
blove merged commit 0aa4d42 into main Sep 17, 2026
29 of 30 checks passed
@blove
blove deleted the blove/vercel-composed-output branch September 17, 2026 22:47
blove added a commit that referenced this pull request Sep 17, 2026
…716)

The runtime function's supportsResponseStreaming: true is what stops Vercel's Node launcher buffering the whole body; the page now names that mechanism and its symptom, and notes that a function declared under build.vercel.functions must ask for the flag itself.

The local-run snippet's functions/index.func/index.mjs is the bare build's path; a build configuring build.vercel.static emits b4.func, so the snippet now says so.

Follow-up to #700, audited against #696's source and tests.

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

This branch was successfully deployed

1 active and 1 inactive deployments
Preview — 07ddb718 Deployed Sep 17, 2026 by vercel[bot]
vercel-preview — 07ddb718 Deployed Sep 17, 2026 by blove via vercel-native #2028
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: let the build describe static assets, extra functions and routes

1 participant