Skip to content

Comments

Add AllowedKeys typing to Bun plugin#814

Merged
yamcodes merged 6 commits intomainfrom
node-env-type-fixes
Feb 23, 2026
Merged

Add AllowedKeys typing to Bun plugin#814
yamcodes merged 6 commits intomainfrom
node-env-type-fixes

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Feb 23, 2026

Natural continuation of #804 - that was the runtime change, this PR is the typing change.

Summary by CodeRabbit

  • New Features

    • NODE_ENV can be declared in env schemas: validated at startup and exposed with full type safety when included.
  • Documentation

    • Docs and examples updated to show NODE_ENV usage, process.env typing, and UI access examples.
  • Chores

    • Bumped dependency versions and added development env files in example/playground projects.

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2026

⚠️ No Changeset found

Latest commit: 4371087

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
@arkenv/bun-plugin Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added docs Improvements or additions to documentation example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) www Improvements or additions to arkenv.js.org labels Feb 23, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 23, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3061eae and 4371087.

📒 Files selected for processing (1)
  • packages/bun-plugin/src/types.ts

Walkthrough

Adds NODE_ENV to the bun-plugin environment schema and type filtering so NODE_ENV is validated at startup and appears with full type safety when included in the schema; updates examples, docs, and dependency versions accordingly.

Changes

Cohort / File(s) Summary
Changeset & Package Versions
\.changeset/few-lights-ask.md, examples/basic-js/package.json, examples/basic/package.json, examples/with-bun/package.json, examples/with-bun-react/package.json, examples/with-solid-start/package.json, examples/with-standard-schema/package.json, examples/with-vite-react/package.json
Changeset entry adjusted from minor to patch; multiple example packages bumped (arkenv and related plugins) to new versions.
Environment Files
apps/playgrounds/bun-react/.env.development, examples/with-bun-react/.env.development
Added .env.development files containing BUN_PUBLIC_API_URL, BUN_PUBLIC_DEBUG, and NODE_ENV=development.
Env Schema Files
apps/playgrounds/bun-react/src/env.ts, examples/with-bun-react/src/env.ts
Added NODE_ENV to exported env schema as union `'development'
Documentation
apps/www/content/docs/bun-plugin/index.mdx, apps/www/content/docs/bun-plugin/typing-process-env.mdx
Expanded docs and examples to document NODE_ENV exposure and typing when present in the schema; updated explanation of filtering and usage examples.
Type System
packages/bun-plugin/src/types.ts, packages/internal/types/src/filter-by-prefix.ts
Updated FilterByPrefix to accept AllowedKeys generic and changed ProcessEnvAugmented to include AllowedKeys = "NODE_ENV", ensuring NODE_ENV is included alongside prefix-filtered keys.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

@arkenv/bun-plugin

Poem

🐰 NODE_ENV hopped into the light,
Typed and tidy, snug and right,
Development, production, test—so neat,
Filtered keys in tidy suite,
A little hop, a typesafe beat.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main change: adding AllowedKeys typing to the Bun plugin. This directly corresponds to the core modification in packages/internal/types/src/filter-by-prefix.ts and its usage in packages/bun-plugin/src/types.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch node-env-type-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/arkenv@814
npm i https://pkg.pr.new/@arkenv/bun-plugin@814
npm i https://pkg.pr.new/@arkenv/fumadocs-ui@814
npm i https://pkg.pr.new/@arkenv/vite-plugin@814

commit: 4371087

@arkenv-bot
Copy link
Contributor

arkenv-bot bot commented Feb 23, 2026

📦 Bundle Size Report

Package Size Limit Diff Status
@arkenv/bun-plugin 2.4 kB 2.44 kB 0.0%

All size limits passed!

@arkenv-bot
Copy link
Contributor

arkenv-bot bot commented Feb 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (Asia/Almaty)
arkenv Ready Ready Preview, Comment Feb 23 2026, 11:09 PM (Asia/Almaty)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bun-plugin/src/types.ts (1)

4-50: ⚠️ Potential issue | 🟡 Minor

Update the JSDoc to document NODE_ENV inclusion.

The type was changed to include "NODE_ENV" via AllowedKeys, but the JSDoc block still only documents prefix-based filtering. Specifically:

  • Line 9: "filters it to only include variables matching the Bun prefix (defaults to 'BUN_PUBLIC_')" — omits the NODE_ENV exception.
  • Neither @example block demonstrates NODE_ENV in a schema or in process.env.
📝 Suggested JSDoc patch
  * This type extracts the inferred type from the schema (result of `type()` from arkenv),
- * filters it to only include variables matching the Bun prefix (defaults to "BUN_PUBLIC_"),
- * and makes them available on `process.env`.
+ * filters it to only include variables matching the Bun prefix (defaults to "BUN_PUBLIC_")
+ * and `NODE_ENV` (when present in the schema), and makes them available on `process.env`.

And in the first @example, add NODE_ENV to show it is passed through:

  * export const Env = type({
  *   BUN_PUBLIC_API_URL: 'string',
  *   BUN_PUBLIC_DEBUG: 'boolean',
+ *   NODE_ENV: "'development' | 'production' | 'test'", // Also typed in ProcessEnvAugmented
  *   PORT: 'number.port', // Server-only, won't be in ProcessEnvAugmented
  * });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bun-plugin/src/types.ts` around lines 4 - 50, Update the JSDoc for
ProcessEnvAugmented to mention that in addition to filtering by the Prefix
(default "BUN_PUBLIC_"), the NODE_ENV key is always included (via
AllowedKeys/FilterByPrefix). Modify the narrative sentence that currently says
it "filters it to only include variables matching the Bun prefix" to explicitly
state "filters by the Bun prefix and always includes NODE_ENV". Also add
NODE_ENV to the first `@example` schema and/or to the second example's
ProcessEnvAugmented usage so the docs demonstrate that NODE_ENV is passed
through (references: ProcessEnvAugmented and FilterByPrefix).
🧹 Nitpick comments (1)
packages/bun-plugin/src/types.ts (1)

47-50: Consider exposing AllowedKeys as a type parameter for user customizability.

"NODE_ENV" is hardcoded, so users who use a custom prefix and want different extra keys included have no escape hatch. Since FilterByPrefix already accepts a generic AllowedKeys, ProcessEnvAugmented could forward a third parameter with a sensible default:

♻️ Optional refactor
 export type ProcessEnvAugmented<
 	TSchema extends type.Any,
 	Prefix extends string = "BUN_PUBLIC_",
-	> = FilterByPrefix<InferType<TSchema>, Prefix, "NODE_ENV">;
+	ExtraKeys extends string = "NODE_ENV",
+> = FilterByPrefix<InferType<TSchema>, Prefix, ExtraKeys>;

This is fully backward-compatible (the default is "NODE_ENV") and lets advanced users add or replace the allowed extra keys.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bun-plugin/src/types.ts` around lines 47 - 50, ProcessEnvAugmented
currently hardcodes "NODE_ENV" as the extra allowed key; make it customizable by
adding a third generic type parameter like AllowedKeys extends string =
"NODE_ENV" to the ProcessEnvAugmented declaration and forward that to
FilterByPrefix (i.e., change ProcessEnvAugmented< TSchema extends type.Any,
Prefix extends string = "BUN_PUBLIC_", AllowedKeys extends string = "NODE_ENV" >
= FilterByPrefix<InferType<TSchema>, Prefix, AllowedKeys>), keeping the default
so existing behavior is preserved while allowing users to supply custom extra
keys.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.changeset/few-lights-ask.md:
- Line 2: The changeset incorrectly marks the release as "patch" even though
ProcessEnvAugmented now adds NODE_ENV to the public TypeScript API; update the
changeset entry for "@arkenv/bun-plugin" from "patch" to "minor" so the
semantic-release reflects the additive API change and consumers see a minor
version bump.

---

Outside diff comments:
In `@packages/bun-plugin/src/types.ts`:
- Around line 4-50: Update the JSDoc for ProcessEnvAugmented to mention that in
addition to filtering by the Prefix (default "BUN_PUBLIC_"), the NODE_ENV key is
always included (via AllowedKeys/FilterByPrefix). Modify the narrative sentence
that currently says it "filters it to only include variables matching the Bun
prefix" to explicitly state "filters by the Bun prefix and always includes
NODE_ENV". Also add NODE_ENV to the first `@example` schema and/or to the second
example's ProcessEnvAugmented usage so the docs demonstrate that NODE_ENV is
passed through (references: ProcessEnvAugmented and FilterByPrefix).

---

Nitpick comments:
In `@packages/bun-plugin/src/types.ts`:
- Around line 47-50: ProcessEnvAugmented currently hardcodes "NODE_ENV" as the
extra allowed key; make it customizable by adding a third generic type parameter
like AllowedKeys extends string = "NODE_ENV" to the ProcessEnvAugmented
declaration and forward that to FilterByPrefix (i.e., change
ProcessEnvAugmented< TSchema extends type.Any, Prefix extends string =
"BUN_PUBLIC_", AllowedKeys extends string = "NODE_ENV" > =
FilterByPrefix<InferType<TSchema>, Prefix, AllowedKeys>), keeping the default so
existing behavior is preserved while allowing users to supply custom extra keys.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5962ed and 3061eae.

⛔ Files ignored due to path filters (7)
  • examples/basic-js/package-lock.json is excluded by !**/package-lock.json
  • examples/basic/package-lock.json is excluded by !**/package-lock.json
  • examples/with-bun-react/bun.lock is excluded by !**/*.lock
  • examples/with-bun/bun.lock is excluded by !**/*.lock
  • examples/with-solid-start/package-lock.json is excluded by !**/package-lock.json
  • examples/with-standard-schema/package-lock.json is excluded by !**/package-lock.json
  • examples/with-vite-react/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (16)
  • .changeset/few-lights-ask.md
  • apps/playgrounds/bun-react/.env.development
  • apps/playgrounds/bun-react/src/env.ts
  • apps/www/content/docs/bun-plugin/index.mdx
  • apps/www/content/docs/bun-plugin/typing-process-env.mdx
  • examples/basic-js/package.json
  • examples/basic/package.json
  • examples/with-bun-react/.env.development
  • examples/with-bun-react/package.json
  • examples/with-bun-react/src/env.ts
  • examples/with-bun/package.json
  • examples/with-solid-start/package.json
  • examples/with-standard-schema/package.json
  • examples/with-vite-react/package.json
  • packages/bun-plugin/src/types.ts
  • packages/internal/types/src/filter-by-prefix.ts

@yamcodes yamcodes merged commit fb9954d into main Feb 23, 2026
19 of 20 checks passed
@yamcodes yamcodes deleted the node-env-type-fixes branch February 23, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant