Conversation
- Introduced automatic conversion of "true"/"false" strings to boolean values in the arkenv package. - Updated documentation to reflect new boolean type behavior and provided examples. - Added support for boolean defaults in environment variable definitions. - Updated related tests to ensure correct functionality of the new boolean handling. These changes improve the usability of environment variables in the arkenv package, making it easier to manage boolean configurations.
🦋 Changeset detectedLatest commit: 755500a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a new boolean type to arkenv that coerces Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant App
participant ArkEnv as ArkEnv Config
participant Types as Types.boolean
participant Env as ProcessEnv
App->>ArkEnv: define schema { DEBUG: "boolean = true", ... }
App->>Env: read DEBUG (string or absent)
alt DEBUG provided as string ("true"/"false")
ArkEnv->>Types: morph("true"/"false")
Types-->>ArkEnv: boolean true/false
else DEBUG not provided
ArkEnv-->>App: use default true
end
ArkEnv-->>App: env.DEBUG (boolean)
App->>App: use env.DEBUG (logging/runtime)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (1)
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 |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
apps/playgrounds/node/.env.example (1)
4-4: Consider alphabetical ordering for consistency.The
DEBUGkey could be placed beforeHOSTto maintain alphabetical ordering, which can improve readability and maintainability of environment variable files.Apply this diff to reorder alphabetically:
HOST=localhost PORT=3000 NODE_ENV=development -DEBUG=true +DEBUG=trueActually, to maintain alphabetical order:
+DEBUG=true HOST=localhost +NODE_ENV=development PORT=3000 -NODE_ENV=development -DEBUG=truepackages/arkenv/src/types.ts (1)
21-29: LGTM! Clean boolean conversion implementation.The type definition correctly handles both string ("true"/"false") and boolean literal inputs, converting them to actual booleans. The morph function logic is sound:
str === "true" || str === truecorrectly returnstruefor "true" ortrue, andfalsefor "false" orfalse.Optional refinement: The JSDoc could be more concise:
/** - * A boolean that accepts string values and converts them to boolean - * Accepts "true" or "false" strings and converts them to actual boolean values + * Accepts "true"/"false" strings or boolean literals and converts them to boolean */packages/arkenv/src/type.test.ts (1)
202-217: Excellent test for boolean defaults and overrides.This test comprehensively verifies:
- Default boolean values are applied when no environment variables are provided
- String values ("true"/"false") correctly override the defaults
The test follows the coding guidelines by using the describe/it structure and testing success cases.
Minor enhancement: Consider adding a test case for invalid overrides to ensure proper error handling:
// Test with invalid override (should throw) expect(() => envType.assert({ DEBUG: "invalid" })).toThrow();Based on coding guidelines (test both success and failure cases).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (11)
.changeset/silly-animals-fly.md(1 hunks)apps/playgrounds/node/.env.example(1 hunks)apps/playgrounds/node/index.ts(2 hunks)apps/www/content/docs/how-to/load-environment-variables.mdx(1 hunks)apps/www/content/docs/meta.json(1 hunks)apps/www/content/docs/morphs.mdx(1 hunks)apps/www/content/docs/quickstart.mdx(2 hunks)apps/www/package.json(1 hunks)packages/arkenv/src/scope.ts(2 hunks)packages/arkenv/src/type.test.ts(5 hunks)packages/arkenv/src/types.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.test.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.test.ts: Place tests alongside source files and use the .test.ts suffix (e.g., create-env.test.ts, types.test.ts, errors.test.ts, utils.test.ts)
Use Vitest's describe/it structure in tests
Test both success and failure cases for environment validation and utilities
Mock process.env to cover different environment scenarios in tests
In tests, save and restore process.env in setup/teardown (beforeEach/afterEach) to avoid leakage between cases
Verify both runtime behavior and TypeScript types in tests
Files:
packages/arkenv/src/type.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-12T06:23:45.463Z
Learnt from: CR
PR: yamcodes/arkenv#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-12T06:23:45.463Z
Learning: Applies to **/*.test.ts : Test both success and failure cases for environment validation and utilities
Applied to files:
packages/arkenv/src/type.test.ts
🧬 Code graph analysis (4)
apps/www/content/docs/quickstart.mdx (1)
packages/arkenv/src/index.test.ts (1)
vi(37-47)
apps/playgrounds/node/index.ts (2)
packages/arkenv/src/index.test.ts (4)
vi(25-35)vi(65-81)vi(37-47)arkenv(50-53)packages/arkenv/src/create-env.test.ts (1)
env(88-99)
packages/arkenv/src/types.ts (2)
packages/arkenv/src/type.ts (1)
type(3-3)packages/arkenv/src/scope.test.ts (1)
stringType(46-50)
packages/arkenv/src/type.test.ts (1)
packages/arkenv/src/type.ts (1)
type(3-3)
🪛 dotenv-linter (3.3.0)
apps/playgrounds/node/.env.example
[warning] 4-4: [UnorderedKey] The DEBUG key should go before the HOST key
(UnorderedKey)
🔇 Additional comments (14)
apps/www/content/docs/quickstart.mdx (1)
47-49: LGTM! Clear documentation of the boolean type.The addition of the DEBUG boolean environment variable with its explanatory comment is clear and demonstrates the new boolean string conversion feature effectively.
Also applies to: 77-77
apps/www/package.json (1)
26-26: LGTM! Appropriate dependency addition.Adding
arktypeas a direct dependency is appropriate for the documentation site, as it likely needs to import and demonstrate arktype features in examples.apps/www/content/docs/how-to/load-environment-variables.mdx (1)
187-189: LGTM! Comprehensive documentation update.The addition of the DEBUG boolean example with a clear explanatory comment effectively demonstrates the new boolean string conversion feature in a practical context.
apps/www/content/docs/meta.json (1)
7-8: LGTM! Appropriate navigation structure.Adding the API section header and morphs page entry properly integrates the new documentation into the site navigation.
apps/www/content/docs/morphs.mdx (1)
1-63: LGTM! Excellent documentation of the morphs feature.The documentation clearly explains:
- What morphs are and why they exist
- The boolean morph behavior with string-to-boolean conversion
- How to set boolean defaults
- How to customize behavior with custom morph functions
The examples are practical and include expected outputs, making it easy for users to understand and implement.
.changeset/silly-animals-fly.md (1)
1-29: LGTM! Clear and informative changelog entry.The changeset appropriately documents the new boolean string conversion feature as a patch release with a clear example demonstrating the functionality.
packages/arkenv/src/scope.ts (1)
18-18:booleantype correctly defined withouttype.module()
Verified thatbooleanis exported viatype()inpackages/arkenv/src/types.tsand has no nestedboolean.*usages, so no module wrapper is needed.packages/arkenv/src/type.test.ts (5)
17-21: LGTM! Correctly tests string-to-boolean conversion.The test now validates that the string "true" is converted to the boolean
true, which aligns with the new boolean type behavior.
23-27: Good coverage of string-to-boolean conversion.This test complements the existing "true" test by verifying that the string "false" converts to the boolean
false.However, consider adding explicit tests for boolean literal inputs to ensure the type also accepts
trueandfalseas direct boolean values (not just strings). This would provide complete coverage of the type signature"'true' | 'false' | true | false".Example test to add:
it("should accept boolean literals", () => { const envType = type({ DEBUG: "boolean" }); const result1 = envType.assert({ DEBUG: true }); expect(result1.DEBUG).toBe(true); const result2 = envType.assert({ DEBUG: false }); expect(result2.DEBUG).toBe(false); });Based on coding guidelines (test both success and failure cases).
86-108: LGTM! Consistent with string-to-boolean behavior.The update to use string "true" instead of boolean
trueis consistent with the new boolean type behavior and ensures the test validates the string-to-boolean conversion in a complex type scenario.
121-130: LGTM! Properly tests invalid boolean input.Changing from
true(which is now valid) to"invalid"correctly tests the failure case, ensuring that only the allowed values ("true", "false",true,false) are accepted by the boolean type.
171-190: LGTM! Consistent test update.The change aligns with the new boolean type behavior, testing string-to-boolean conversion alongside other type validations.
apps/playgrounds/node/index.ts (2)
8-8: LGTM! Proper usage of the new boolean type.The DEBUG environment variable correctly uses the new boolean type with a default value. The inline default syntax
"boolean = true"is appropriate and will accept "true"/"false" strings from environment variables while defaulting totruewhen not provided.Note: This uses inline default syntax while ALLOWED_ORIGINS uses the functional default syntax
.default(() => []). Both are valid, though the codebase now has two different default patterns. This is a minor stylistic observation and doesn't require changes.
17-24: LGTM! Consistent pattern and proper integration.The debug variable extraction and console.log update follow the same pattern as the other environment variables. The TypeScript types are properly inferred, ensuring type safety throughout.
- Ensure build before typecheck
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.7.3 ### Patch Changes - #### Automatic boolean string conversion _[`#218`](#218) [`e554e2b`](e554e2b) [@yamcodes](https://github.com/yamcodes)_ The `boolean` type now accepts `"true"`/`"false"` strings from environment variables and converts them to actual boolean values. This also works with boolean defaults. Example: ```ts import arkenv from "arkenv"; const env = arkenv({ DEBUG: "boolean", ENABLE_FEATURE: "boolean = true", }); console.log(env.DEBUG); console.log(env.ENABLE_FEATURE); ``` Result: ```sh ❯ DEBUG=true npx tsx index.ts true true ``` ## @arkenv/vite-plugin@0.0.13 ### Patch Changes - #### Support Vite 2.x _[`#212`](#212) [`bfe08f6`](bfe08f6) [@yamcodes](https://github.com/yamcodes)_ Extended the supported Vite versions to include **2.9.18** through **7.x** (inclusive). Also, we've added the `vite-plugin` keyword to the `package.json`, and a section in the `README.md` explaining why this plugin is a Vite only plugin (and not a Rollup plugin). <details><summary>Updated 1 dependency</summary> <small> [`e554e2b`](e554e2b) </small> - `arkenv@0.7.3` </details> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR contains the following updates: | Package | Change | Age | Confidence | |---|---|---|---| | [arkenv](https://arkenv.js.org) ([source](https://redirect.github.com/yamcodes/arkenv)) | [`0.7.0` -> `0.7.3`](https://renovatebot.com/diffs/npm/arkenv/0.7.0/0.7.3) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>yamcodes/arkenv (arkenv)</summary> ### [`v0.7.3`](https://redirect.github.com/yamcodes/arkenv/releases/tag/arkenv%400.7.3) [Compare Source](https://redirect.github.com/yamcodes/arkenv/compare/arkenv@0.7.2...arkenv@0.7.3) ##### Patch Changes - #### Automatic boolean string conversion *[`#218`](https://redirect.github.com/yamcodes/arkenv/pull/218) [`e554e2b`](https://redirect.github.com/yamcodes/arkenv/commit/e554e2b41aab1b8e29d873982ea587c069f4732d) [@​yamcodes](https://redirect.github.com/yamcodes)* The `boolean` type now accepts `"true"`/`"false"` strings from environment variables and converts them to actual boolean values. This also works with boolean defaults. Example: ```ts import arkenv from "arkenv"; const env = arkenv({ DEBUG: "boolean", ENABLE_FEATURE: "boolean = true", }); console.log(env.DEBUG); console.log(env.ENABLE_FEATURE); ``` Result: ```sh ❯ DEBUG=true npx tsx index.ts true true ``` ### [`v0.7.2`](https://redirect.github.com/yamcodes/arkenv/releases/tag/arkenv%400.7.2) [Compare Source](https://redirect.github.com/yamcodes/arkenv/compare/arkenv@0.7.1...arkenv@0.7.2) ##### Patch Changes - #### Support array defaults using type().default() syntax *[`#199`](https://redirect.github.com/yamcodes/arkenv/pull/199) [`e50dba1`](https://redirect.github.com/yamcodes/arkenv/commit/e50dba1f19418f8fc007dc786df1172067e3d07c) [@​copilot-swe-agent](https://redirect.github.com/apps/copilot-swe-agent)* Fix to an issue where `type("array[]").default(() => [...])` syntax was not accepted by `createEnv` due to overly restrictive type constraints. The function now accepts any string-keyed record while still maintaining type safety through ArkType's validation system. ##### New Features - Array defaults to empty using `type("string[]").default(() => [])` syntax - Support for complex array types with defaults - Mixed schemas combining string-based and type-based defaults ##### Example ```typescript const env = arkenv({ ALLOWED_ORIGINS: type("string[]").default(() => ["localhost"]), FEATURE_FLAGS: type("string[]").default(() => []), PORT: "number.port", }); ``` ### [`v0.7.1`](https://redirect.github.com/yamcodes/arkenv/releases/tag/arkenv%400.7.1) [Compare Source](https://redirect.github.com/yamcodes/arkenv/compare/arkenv@0.7.0...arkenv@0.7.1) ##### Patch Changes - Export `ArkEnvError` *[`#161`](https://redirect.github.com/yamcodes/arkenv/pull/161) [`221f9ef`](https://redirect.github.com/yamcodes/arkenv/commit/221f9efdef65691b0c5155b12ec460404dddbe82) [@​yamcodes](https://redirect.github.com/yamcodes)* You can now import `ArkEnvError` from `arkenv`: ```ts import { ArkEnvError } from "arkenv"; ``` - Improve JSDoc *[`#161`](https://redirect.github.com/yamcodes/arkenv/pull/161) [`221f9ef`](https://redirect.github.com/yamcodes/arkenv/commit/221f9efdef65691b0c5155b12ec460404dddbe82) [@​yamcodes](https://redirect.github.com/yamcodes)* The JSDoc for `arkenv` and `createEnv` is now more descriptive. </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on friday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/yamcodes/arkenv). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4xNTkuNCIsInVwZGF0ZWRJblZlciI6IjQxLjE1OS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
These changes improve the usability of environment variables in the arkenv package, making it easier to manage boolean configurations.
Closes #87
Summary by CodeRabbit
New Features
Documentation
Tests
Chores