Skip to content

feat: add script mode values - #82

Merged
lukeed merged 9 commits into
mainfrom
feat/client-mode
Oct 23, 2026
Merged

lukeed merged 9 commits into
mainfrom
feat/client-mode

Conversation

@lukeed

@lukeed lukeed commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

A client script could not tell bongo dev from bongo build. A user had the layout write a data-dev attribute for dev-only scripts to read.

Changes

  • Scripts get process.env.NODE_ENV ("development" or "production"), import.meta.env.DEV, and import.meta.env.PROD. import.meta.env itself becomes an object, so import.meta.env.OTHER is undefined, not a TypeError.
  • A library that reads process.env.NODE_ENV gets the mode. Before, it threw in the browser.
  • Packages resolve with the development condition in dev. Before, dev always used production.
  • $build.define adds user values, and replaces the built-in ones of the same name. The define maps of plugins and the config merge, and the config's values win.
  • bongo/env types import.meta.env.DEV and PROD. A project opts in with "types": ["bongo/env"] in its tsconfig.json, or with /// <reference types="bongo/env" />, since bun-types also declares ImportMeta.env and the two conflict.
  • The create-bongo template sets "types": ["bongo/env", "node"]. TypeScript loads only the listed types, so a later @types/bun does not conflict on its own. Release @bongo/bongo with this change before create-bongo, since the template installs the latest bongo.
  • Docs: a "Script values" section in config.md.

Test plan

  • bun test (857 pass), bunx tsc -p ., bunx tsc -p build, bun run build
  • New tests fail without the change: mode values in dev and build, the package condition by mode, define over the built-ins, $build.define through build(), and the merge of define maps
  • By hand, after fix: ship bongo/client types #86: a site from create-bongo, installed from packed tarballs, passes tsc as shipped, and with import.meta.env.DEV/PROD in main.ts and process.env.NODE_ENV in the config. bongo build --minify drops the dev branch, and bongo dev keeps it.
  • By hand: a site from create-bongo, installed from packed local tarballs, has no import.meta.env errors in tsc with the template's types, and has them without it
  • By hand: in a project shaped like the create-bongo template, tsc fails on import.meta.env.DEV without the reference and passes with it
  • By hand with the CLI: bongo build gives "production", false, and the production export. bongo dev gives "development", true, and the development export. --minify removes if (import.meta.env.DEV) branches.

@lukeed lukeed mentioned this pull request Oct 23, 2026
3 tasks done
@lukeed
lukeed merged commit 8f8c776 into main Oct 23, 2026
4 checks passed
@lukeed
lukeed deleted the feat/client-mode branch October 23, 2026 00:38
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