Support standard validator mode in Bun plugin#763
Conversation
- Design document for validator mode - Proposal for validator mode support - Specification of new requirements - Tasks for implementation plan
🦋 Changeset detectedLatest commit: 273239f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThis PR adds optional validator configuration support to the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
- Update `arkenv` signature to accept config - Pass `ArkEnvConfig` to underlying `createEnv` call - Add
commit: |
📦 Bundle Size Report
✅ All size limits passed! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@openspec/changes/bun-plugin-validator-mode/proposal.md`:
- Around line 1-20: Update the proposal to follow openspec format by adding a
"Why" section that concisely states the motivation (support validator mode
without requiring ArkType), a "What Changes" section listing concrete
modifications (e.g., change arkenv() factory to accept optional ArkEnvConfig,
update processEnvSchema to accept/pass-through config, mention files
packages/bun-plugin and packages/bun-plugin/src/utils.ts) and mark any breaking
changes with explicit "BREAKING" labels, and an "Impact" section describing
who/what is affected (users removing arktype, downstream type inference via
InferType and dependency on vite-plugin-validator-mode); ensure each section is
clearly titled and scannable.
In `@openspec/changes/bun-plugin-validator-mode/tasks.md`:
- Around line 1-11: Convert the grouped, already-checked checklist into a
numbered, initially-unchecked checklist: replace the three section headings
("Core Implementation", "Documentation", "Verification") and their checked items
with a single numbered list where each task is an individual numbered "1. - [
]", "2. - [ ]" etc., preserving the exact task text (e.g., "Update
`@arkenv/bun-plugin` signature to `arkenv(schema, config?)`", "Update
`processEnvSchema` to accept and pass `config` to `createEnv`", "Add JSDoc
examples showing `validator: \"standard\"` usage", "Update plugin documentation
with Standard Schema examples", "Add test case for `validator: \"standard\"` in
Bun plugin tests", "Verify using a Zod schema in an example project with
`arktype` uninstalled"); ensure all boxes start unchecked (`[ ]`) so they can be
marked `[x]` as work completes.
In `@packages/bun-plugin/src/utils.ts`:
- Around line 9-18: processEnvSchema currently forces process.env by merging {
...config, env: process.env }, which ignores any ArkEnvConfig.env provided;
change the merge so createEnv receives the config's env when present and falls
back to process.env only if config.env is undefined (i.e., pass the same
{...config, env: config.env ?? process.env} behavior), keeping the existing
createEnv(options as any, ...) call and type assertion.
| # Proposal: Support Validator Mode in Bun Plugin | ||
|
|
||
| ## Problem | ||
| Currently, the `@arkenv/bun-plugin` does not allow users to specify a validator engine. It defaults to ArkType, which causes a crash if the user removes `arktype` from their project and tries to use Standard Schema validators (e.g., Zod, Valibot). This prevents the "validator" mode from being truly usable in Bun projects. | ||
|
|
||
| ## Solution | ||
| 1. Update the `@arkenv/bun-plugin` factory function to accept an optional `ArkEnvConfig` object as a second argument. | ||
| 2. In the plugin's `processEnvSchema` utility, pass this configuration to the `createEnv` call. | ||
| 3. Leverage the existing `InferType` improvements (from `vite-plugin-validator-mode`) to ensure proper type inference for Standard Schema validators. | ||
|
|
||
| ## Scope | ||
| - `packages/bun-plugin`: Update `arkenv()` plugin factory signature and implementation. | ||
| - `packages/bun-plugin/src/utils.ts`: Update `processEnvSchema` to accept and pass through config. | ||
|
|
||
| ## Alternatives Considered | ||
| - **Refactoring the Entire Plugin**: Not necessary; a surgical addition of the second argument is sufficient, mirroring the Vite plugin approach. | ||
| - **Requiring ArkType always**: This contradicts the goal of supporting Standard Schema as an alternative. | ||
|
|
||
| ## Dependencies | ||
| - Requires `vite-plugin-validator-mode` to be complete (for `InferType` and `ArkEnvConfig` export). |
There was a problem hiding this comment.
Add required Why, What Changes (with BREAKING markers), and Impact sections.
The proposal format does not follow the required openspec structure. Please restructure accordingly so it’s compliant and scannable.
As per coding guidelines, proposal.md must include Why, What Changes (with BREAKING markers), and Impact sections.
🤖 Prompt for AI Agents
In `@openspec/changes/bun-plugin-validator-mode/proposal.md` around lines 1 - 20,
Update the proposal to follow openspec format by adding a "Why" section that
concisely states the motivation (support validator mode without requiring
ArkType), a "What Changes" section listing concrete modifications (e.g., change
arkenv() factory to accept optional ArkEnvConfig, update processEnvSchema to
accept/pass-through config, mention files packages/bun-plugin and
packages/bun-plugin/src/utils.ts) and mark any breaking changes with explicit
"BREAKING" labels, and an "Impact" section describing who/what is affected
(users removing arktype, downstream type inference via InferType and dependency
on vite-plugin-validator-mode); ensure each section is clearly titled and
scannable.
| # Tasks: Bun Plugin Validator Mode Support | ||
|
|
||
| - [x] **Core Implementation** | ||
| - [x] Update `@arkenv/bun-plugin` signature to `arkenv(schema, config?)`. | ||
| - [x] Update `processEnvSchema` to accept and pass `config` to `createEnv`. | ||
| - [x] **Documentation** | ||
| - [x] Add JSDoc examples showing `validator: "standard"` usage. | ||
| - [x] Update plugin documentation with Standard Schema examples. | ||
| - [x] **Verification** | ||
| - [x] Add test case for `validator: "standard"` in Bun plugin tests. | ||
| - [x] Verify using a Zod schema in an example project with `arktype` uninstalled. |
There was a problem hiding this comment.
Align tasks checklist with required numbered, initially-unchecked format.
The tasks list is grouped and already checked. Please convert to numbered checklist items and keep them unchecked initially, updating to [x] as work completes.
As per coding guidelines and based on learnings, tasks.md should use numbered - [ ] items and start unchecked.
🤖 Prompt for AI Agents
In `@openspec/changes/bun-plugin-validator-mode/tasks.md` around lines 1 - 11,
Convert the grouped, already-checked checklist into a numbered,
initially-unchecked checklist: replace the three section headings ("Core
Implementation", "Documentation", "Verification") and their checked items with a
single numbered list where each task is an individual numbered "1. - [ ]", "2. -
[ ]" etc., preserving the exact task text (e.g., "Update `@arkenv/bun-plugin`
signature to `arkenv(schema, config?)`", "Update `processEnvSchema` to accept
and pass `config` to `createEnv`", "Add JSDoc examples showing `validator:
\"standard\"` usage", "Update plugin documentation with Standard Schema
examples", "Add test case for `validator: \"standard\"` in Bun plugin tests",
"Verify using a Zod schema in an example project with `arktype` uninstalled");
ensure all boxes start unchecked (`[ ]`) so they can be marked `[x]` as work
completes.
- Allow `config.env` to override `process.env` - Update proposal document for validator mode - Simplify task list for implementation
- Handles cases where arkenvConfig.env is undefined - Falls back to loadEnv when env is missing
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## arkenv@0.9.1 ### Patch Changes - #### Fix Standard Schema type inference _[`#758`](#758) [`3b747b0`](3b747b0) [@yamcodes](https://github.com/yamcodes)_ Fixed type inference when using `validator: "standard"` mode. The `env` object now correctly infers types from Standard Schema validators like Zod or Valibot. ## @arkenv/bun-plugin@0.1.1 ### Patch Changes - #### Support configuration _[`#763`](#763) [`06de0ef`](06de0ef) [@yamcodes](https://github.com/yamcodes)_ Add support for an optional configuration object as the second argument. This allows you to set the `validator` mode to `"standard"`, enabling support for libraries like Zod or Valibot without an ArkType dependency. ```ts import { z } from "zod"; import arkenv from "@arkenv/bun-plugin"; arkenv( { BUN_PUBLIC_API_URL: z.string().url(), }, { validator: "standard", } ); ``` <details><summary>Updated 1 dependency</summary> <small> [`3b747b0`](3b747b0) </small> - `arkenv@0.9.1` </details> ## @arkenv/vite-plugin@0.0.28 ### Patch Changes - #### Support configuration _[`bb832b1`](bb832b1) [@yamcodes](https://github.com/yamcodes)_ Add support for an optional configuration object as the second argument. This allows you to set the `validator` mode to `"standard"`, enabling support for libraries like Zod or Valibot without an ArkType dependency. ```ts import { z } from "zod"; import arkenvVitePlugin from "@arkenv/vite-plugin"; arkenvVitePlugin( { VITE_API_URL: z.string().url(), }, { validator: "standard", } ); ``` <details><summary>Updated 1 dependency</summary> <small> [`3b747b0`](3b747b0) </small> - `arkenv@0.9.1` </details> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary by CodeRabbit
Release Notes
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.