Skip to content

feat(cli): vercel output directory override and relaxed output validator - #695

Merged
blove merged 3 commits into
mainfrom
blove/sharp-morse-002d21
Sep 17, 2026
Merged

blove merged 3 commits into
mainfrom
blove/sharp-morse-002d21

Conversation

@blove

@blove blove commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Closes #680. Sibling of #679 (composition of static assets, extra functions and routes), which this does not attempt; it only makes room for it.

What changed

Output directory override. b4 build --out-dir <dir> and build.vercel.outDir in b4.config.ts choose where the vercel target publishes its Build Output tree. Both resolve relative to the app root; the flag wins over config for one run. Default is unchanged (.vercel/output), and the vercel-native lane's expectations are untouched.

  • A directory that contains the app root (., .., the root itself, or an ancestor) is rejected before typegen or any target emits, because publication replaces the directory wholesale.
  • --out-dir without "vercel" in build.targets is an error rather than a silent no-op.
  • The generated runtime still stages under <appRoot>/.vercel/.b4-vercel-<id>/ so its imports resolve from the app's node_modules; only the output tree stages beside its destination, so publication stays a same-device rename. For the default location both share one invocation directory, as before. Cleanup removes both and reports whichever failed.
  • publishVercelOutput now takes the explicit outputDir and parks the prior output beside it.

Relaxed validator. validateVercelOutput asserts that config.json is version 3 and that routes is an array of objects containing a route whose dest is /index, instead of requiring the exact single catch-all. Extra routes ({ handle: "filesystem" }, static fallbacks, other functions) and extra top-level keys (overrides, images, …) are accepted. The function directory checks (.vc-config.json exact match, self-contained bundle, no escaping symlinks or dependencies) are unchanged.

Tests

packages/cli/test/vercel-target.test.ts:

  • new Vercel output directory override block: config override, flag-over-config with prior output replaced, absolute directory outside the app root with no staging left behind, --out-dir without the target, and the three app-root-containing rejections
  • validator: a composed config.json (static route, filesystem handle, api function route, check, overrides, images) validates; missing runtime route, routes without any function destination, non-array routes, and a non-object route entry each fail at the precise location; the two "extra property" rejections are gone by design

Docs: b4 build reference gains the flag and a vercel target bullet; configuration.mdx documents build.vercel.outDir and the docs schema inventory in scripts/check-docs.mjs registers the new paths. Changeset: patch for @b4run/cli and @b4run/core.

Verified locally: pnpm build, CLI typecheck (covers tests), lint for cli and core, node scripts/check-docs.mjs, vercel-target + vercel-native-lane + build-targets test files (525 tests), and the full CLI suite.

🤖 Generated with Claude Code

@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 5:30pm 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 3 commits September 17, 2026 10:27
The vercel target always published to <appRoot>/.vercel/output, and
validateVercelOutput rejected any config.json that was not the exact
catch-all the build writes, so composing the runtime function with static
assets or further functions meant mutating the published tree after the
build without the validator's help.

- `b4 build --out-dir <dir>` and `build.vercel.outDir` choose where the
  Build Output tree is published, resolved relative to the app root, flag
  over config. A directory that contains the app root is rejected before
  anything is written, and `--out-dir` without a configured vercel target
  is an error.
- The generated runtime still stages inside the app root so its imports
  resolve, while the output tree stages beside its destination so
  publication stays a same-device rename.
- validateVercelOutput now asserts config.json is version 3 and contains a
  route whose dest is /index, accepting extra routes and top-level keys.

Closes #680

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…olver

`build.vercel` gained a second option on main (reconcileVercelJson) with a
resolver that rejects unknown keys, so an `outDir` read straight off the
config would have been refused as an authoring error. Route it through the
same resolver instead: it validates the value and `b4 build` honors what the
resolver returned, so the validated shape and the honored value cannot
diverge — the property that resolver exists to hold.

Rejects a non-string outDir, a blank one that would resolve to the app root,
and the key misplaced directly on `build`. `b4 check` applies the same gate.

Co-Authored-By: Claude Opus 5 <[email protected]>
@blove
blove force-pushed the blove/sharp-morse-002d21 branch from e2bab84 to 0328779 Compare September 17, 2026 17:29
@blove
blove merged commit acfc786 into main Sep 17, 2026
29 of 30 checks passed
@blove
blove deleted the blove/sharp-morse-002d21 branch September 17, 2026 18:38
blove added a commit that referenced this pull request Sep 17, 2026
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]>
blove added a commit that referenced this pull request Sep 17, 2026
#695 landed two things this guide needed:

- `build.vercel.outDir` / `b4 build --out-dir <dir>`, with the flag
  winning over the config value, app-root-relative resolution, the
  rejection of a directory containing the app root, and the error when
  vercel is not a configured target;
- a relaxed output validator. `config.json` now needs version 3 and a
  route reaching `/index` rather than the exact catch-all, and extra
  routes and top-level keys are accepted.

Together those turn the frontend-composition section from a list of
workarounds into a supported flow: stage the runtime tree elsewhere,
assemble into `.vercel/output`, and a composed config still validates.
The section now says so, and says plainly that the validator runs on
what the target stages rather than on what an assembler produces, and
that renaming the function off `dest: "/index"` makes the final config
the author's responsibility.

Also records that the generated stores import
`@b4run/postgres-storage/node`, which reaches `pg` through that
package's own dependency so an app never declares `pg` itself — the one
real gap raised by the session that owns #698.

cli.mdx conflicted and takes main's bullet, which covers outDir and the
relaxed validator, with a link to this page appended.

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

This branch was successfully deployed

1 active and 1 inactive deployments
vercel-preview — 0328779a Deployed Sep 17, 2026 by blove via vercel-native #1973
Preview — 0328779a Deployed Sep 17, 2026 by vercel[bot]
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: allow an output directory override and relax validateVercelOutput

1 participant