Skip to content

fix(core): type build.targets as the known target union - #693

Merged
blove merged 1 commit into
mainfrom
fix/686-typed-build-targets
Sep 17, 2026
Merged

blove merged 1 commit into
mainfrom
fix/686-typed-build-targets

Conversation

@blove

@blove blove commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Closes #686.

Problem

build.targets in config() was typed readonly string[], so targets: ["vercell"] type-checked and only failed at b4 build time.

Change

  • @b4run/core: new build-targets.ts exports BUILD_TARGET_NAMES (["node", "langsmith", "hono", "vercel"] as const), the derived BuildTargetName union, and an isBuildTargetName guard. B4Config.build.targets is now readonly BuildTargetName[].
  • @b4run/cli: the target registry is typed Readonly<Record<BuildTargetName, BuildTarget>> with literal keys, BuildTarget.name is BuildTargetName, and knownTargetNames() returns the core tuple. Adding a target to the registry without adding its name in core, or the reverse, is now a compile error, so the config type and the registry cannot drift.
  • b4 build and b4 check keep their runtime validation and the exact Unknown build target "…". Known targets: … message, since a b4.config.js or JSON config arrives untyped. build.ts narrows through the guard instead of an as cast.
  • Docs: configuration.mdx describes the union; the three new exports are listed on the core API page; the SEO lastmod manifest is regenerated for those two pages.
  • Changeset: patch for @b4run/core and @b4run/cli.

No plugin escape hatch

The issue floated an optional (string & {}) hatch. The registry is a closed object literal with no plugin registration path, so a hatch would only reopen the typo gap the issue is about. If plugin targets land later, the hatch is a one-line change at the type.

Tests

  • packages/core/test/build-targets.test.ts: expectTypeOf pins the union exactly, // @ts-expect-error proves ["vercell"] and a plain string[] are rejected by config(), plus runtime guard cases. Verified by tsc -p tsconfig.test.json in core's typecheck (an unneeded @ts-expect-error would itself fail).
  • packages/cli/test/build-target-registry.test.ts: registry keys equal BUILD_TARGET_NAMES at runtime, every target reports the name it is keyed by, and the registry/default/known-names types are pinned to the union.

Verification

  • pnpm typecheck 53/53, pnpm lint 28/28, node scripts/check-docs.mjs pass.
  • @b4run/core tests 539/539. @b4run/cli full suite alone: 4 files timed out under load (no assertion failures); those 4 files re-run in isolation 422/422, including the existing build-targets.test.ts unknown-target cases.
  • apps/web generate-lastmod test passes after regeneration.

🤖 Generated with Claude Code

`build.targets` in `config()` was `readonly string[]`, so a typo such as
`targets: ["vercell"]` type-checked and only failed at `b4 build` time.

Add `BUILD_TARGET_NAMES` to `@b4run/core` as the single source of truth,
derive `BuildTargetName` from it, and type `B4Config.build.targets` as
`readonly BuildTargetName[]`. The CLI's target registry is now a
`Record<BuildTargetName, BuildTarget>`, so adding a target on one side
without the other is a compile error. No `(string & {})` escape hatch: the
registry is a closed object literal with no plugin registration, so a hatch
would only reopen the typo gap.

Runtime validation in `b4 build` and `b4 check` is kept with the same
message, because JS and JSON configs arrive untyped, and it now narrows
through `isBuildTargetName`.

Closes #686

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 5:32am 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
blove merged commit 12726b4 into main Sep 17, 2026
30 of 31 checks passed
@blove
blove deleted the fix/686-typed-build-targets branch September 17, 2026 15:08
blove added a commit that referenced this pull request Sep 17, 2026
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 added a commit that referenced this pull request Sep 17, 2026
#698 landed while this branch was open and closed #690: the vercel
target's generated stores now select a driver per request, so the built
bundle reaches a plain local Postgres over pooled `pg` with no WebSocket
proxy at all. The guide documented the proxy as a hard requirement, so
that section was rewritten:

- the local recipe is now DATABASE_URL plus a bare `node --input-type=module`
  import, no Docker network and no wsproxy containers;
- `B4_PG_WS_PROXY` is described with the forms it actually accepts
  (host:port, ws://, wss://), as a way to rehearse the Neon path rather
  than as a precondition, alongside `B4_PG_DRIVER` and the
  proxy-with-pg configuration error;
- the driver detail links to the edge page's new "Database drivers"
  section instead of restating it;
- the fit check no longer claims WebSocket Postgres is required, and the
  Neon section notes non-Neon hosts get a pooled `pg` connection.

Conflicts resolved toward main: configuration.mdx takes main's
`BuildTargetName` union wording from #693, which already names both
edge targets, and lastmod.generated.json is regenerated.

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

This branch was successfully deployed

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

config: type build.targets as a union of known target names

1 participant