Skip to content

fix(cli): export B4Config so config() typechecks under pnpm - #810

Merged
blove merged 1 commit into
mainfrom
blove/config-type-nameable
Sep 23, 2026
Merged

blove merged 1 commit into
mainfrom
blove/config-type-nameable

Conversation

@blove

@blove blove commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Problem

b4.config.ts written as import { config } from "@b4run/cli" + export default config({}) failed tsc --noEmit in a pnpm-installed app:

b4.config.ts(3,1): error TS2883: The inferred type of 'default' cannot be named without a reference to 'B4Config' from '.pnpm/@b4run+core@.../node_modules/@b4run/core'. This is likely not portable. A type annotation is necessary.

@b4run/cli re-exported config from @b4run/core but not the B4Config type. Under pnpm's isolated layout the app can resolve only @b4run/cli, so declaration emit had no way to name the inferred type. npm's hoisted layout hid the problem. I reproduced it with create-b4-app --mode internal under pnpm in two places:

  • the research template's server/, which already uses config(), so pnpm users of that template got a failing typecheck
  • the basic template with config({}) swapped in

Fix

  • packages/cli/src/index.ts: export { type B4Config, config } from "@b4run/core". TypeScript then names the inferred type through @b4run/cli. Checked under real pnpm installs of both scaffolds.
  • The basic template's b4.config.ts now uses import { config } from "@b4run/cli" + export default config({}), which was the original plan and matches the docs.
  • apps/web/content/docs/api/cli.mdx: documents the new B4Config export (required by check-docs).
  • Patch changeset for @b4run/cli and @b4run/devkit.

The code-fixer blueprint guide is unchanged. It is pinned to 0.10.0 and says nothing about what the scaffold's b4.config.ts contains. No generated .b4 files, harness overlays or basic.expected.json changed. The overlays write their own config, and renderedBytes stayed the same.

Regression test

packages/cli/test/config-type-portability.test.ts builds a pnpm-style .pnpm store in a temp dir outside the repo:

  • the built @b4run/cli and @b4run/core declarations are copied in
  • the app links only @b4run/cli
  • core is a sibling link that only the cli can see

It then typechecks export default config({}) and a B4Config-annotated file with declaration: true. Without the re-export it fails with the exact TS2883 above and TS2724. With the re-export it passes. A plain symlink to packages/cli does not reproduce the bug: TS resolves core to a real path outside node_modules, where TS2883 never fires. That is why the test copies the declarations.

Test plan

  • Scratch pnpm apps (create-b4-app --mode internal): basic with config({}) and research server/ both fail pnpm typecheck before the fix and pass after. The new basic scaffold also passes pnpm test and b4 check.
  • New cli test fails before the fix and passes after
  • vitest: cli (172 files, 2104 tests), core, create-b4-app, devkit
  • pnpm lint, pnpm typecheck, node scripts/check-docs.mjs
  • apps/web api-reference-inventory + docs-anchors tests
  • pnpm verify:harness:framework passed

🤖 Generated with Claude Code

`export default config({})` in b4.config.ts infers `B4Config` from
`@b4run/core`. Under pnpm's isolated node_modules an app depends only on
`@b4run/cli`, so declaration emit could not name the type and tsc failed
with TS2883. This broke typecheck for pnpm users of the research template.

`@b4run/cli` now re-exports the `B4Config` type, which TypeScript uses to
name the inferred type. The basic template's b4.config.ts switches to
`config({})` to match the docs. A cli test builds a pnpm-style `.pnpm`
store layout and typechecks `config({})` against it; it reproduces the
exact TS2883 without the re-export.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blove
blove enabled auto-merge (squash) September 23, 2026 15:26
@vercel

vercel Bot commented Sep 23, 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 23, 2026 3:26pm 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 837bcfb into main Sep 23, 2026
30 of 31 checks passed
@blove
blove deleted the blove/config-type-nameable branch September 23, 2026 16:00
blove added a commit that referenced this pull request Sep 23, 2026
#815)

#810 re-exports B4Config next to config from @b4run/cli, so the built
index.ts line now reads `export { type B4Config, config } from "@b4run/core"`
and the drafter end-to-end test's exact-line assertion fails in
sandbox-docker.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@blove blove mentioned this pull request Sep 23, 2026

This branch was successfully deployed

1 active and 1 inactive deployments
vercel-preview — e7234306 Deployed Sep 23, 2026 by blove via vercel-native #2278
Preview — e7234306 Deployed Sep 23, 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.

1 participant