Skip to content

createEnv facelift#129

Merged
yamcodes merged 7 commits intomainfrom
new-create-env
Sep 8, 2025
Merged

createEnv facelift#129
yamcodes merged 7 commits intomainfrom
new-create-env

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Sep 8, 2025

Improved type inference and scope-based validation

The createEnv function got a facelift with better TypeScript inference and introduced a new scope-based validation system.

Key improvements:

  • Better ecosytem integration: Use string.host and number.port in your schemas, as if they were native ArkType keywords
  • Cleaner API: No need to awkwardly import host and port types anymore

Before:

host and port had to be manually imported from the arkenv package, and used as arguments to the createEnv function.

import { createEnv, host, port } from "arkenv";

const env = createEnv({
  HOST: host,    // Validates IP addresses or "localhost"
  PORT: port,    // Validates port numbers (0-65535)
  NODE_ENV: "string",     // Standard string validation
});

After:

Now you can use string.host and number.port in your schemas, in a way that is much more natural and idiomatic within the ArkType ecosystem.

import { createEnv } from "arkenv";

const env = createEnv({
  HOST: "string.host",    // Validates IP addresses or "localhost"
  PORT: "number.port",    // Validates port numbers (0-65535)
  NODE_ENV: "string",     // Standard string validation
});

BREAKING CHANGE:

  • We are no longer exporting host and port types. Use string.host and number.port instead.

Summary by CodeRabbit

  • New Features

    • Improved TypeScript inference and scope-based validation in environment creation.
    • New tokens for validation: string.host and number.port.
    • Added Playground app to try ArkEnv interactively.
  • Breaking Changes

    • host and port types removed; use string.host and number.port in schemas.
  • Documentation

    • New README for the Playground.
  • Examples

    • Example scripts now load variables from .env by default.
  • Tests

    • Added validation tests for host and port behavior.
  • Chores

    • Updated peer dependency to ArkType ^2.1.22 and tooling/config updates.

This commit introduces a new playground application within the 'apps' directory, allowing users to experiment with ArkEnv. The playground includes TypeScript configuration, a README, and example usage of environment variable validation. Additionally, dependencies have been updated to support the new app.
This commit updates the `index.ts` file by removing the export of types, streamlining the default export to only include environment-related functionalities. This change simplifies the module's interface and focuses on core features.
@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2025

🦋 Changeset detected

Latest commit: ae9d0e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
arkenv Minor
@arkenv/vite-plugin Patch

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

@vercel
Copy link

vercel bot commented Sep 8, 2025

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

Project Deployment Preview Comments Updated (UTC)
arkenv Ready Ready Preview Comment Sep 8, 2025 6:40pm

@github-actions github-actions bot added docs Improvements or additions to documentation arkenv Changes to the `arkenv` npm package. example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) tests This issue or PR is about adding, removing or changing tests labels Sep 8, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

Warning

Rate limit exceeded

@yamcodes has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between e7c7592 and ae9d0e1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (22)
  • .changeset/dull-socks-return.md (1 hunks)
  • .changeset/social-teeth-peel.md (1 hunks)
  • .github/copilot-instructions.md (2 hunks)
  • README.md (1 hunks)
  • apps/playground/README.md (1 hunks)
  • apps/playground/index.ts (1 hunks)
  • apps/playground/package.json (1 hunks)
  • apps/playground/tsconfig.json (1 hunks)
  • apps/www/content/docs/guides/environment-configuration.mdx (2 hunks)
  • apps/www/content/docs/index.mdx (1 hunks)
  • apps/www/content/docs/quickstart.mdx (1 hunks)
  • arkenv.code-workspace (1 hunks)
  • biome.jsonc (1 hunks)
  • examples/basic/package.json (1 hunks)
  • packages/arkenv/package.json (2 hunks)
  • packages/arkenv/src/create-env.ts (1 hunks)
  • packages/arkenv/src/index.ts (1 hunks)
  • packages/arkenv/src/scope.test.ts (1 hunks)
  • packages/arkenv/src/scope.ts (1 hunks)
  • packages/arkenv/tsconfig.json (0 hunks)
  • packages/vite-plugin/package.json (1 hunks)
  • packages/vite-plugin/src/index.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch new-create-env

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.

This commit updates the `biome.jsonc` file to include the `playground` directory in the linter's includes, enhancing the linting coverage for example files within the playground.
This commit updates the ArkType peer dependency in the pnpm-lock.yaml and package.json files to version ^2.1.22 for compatibility with the latest version of ArkEnv. Additionally, the index.ts file has been refactored to streamline type imports.
@github-actions github-actions bot added the @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv label Sep 8, 2025
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: 5

🧹 Nitpick comments (6)
examples/basic/package.json (1)

6-7: Scripts update looks good; consider adding a .env.example

Using tsx --env-file .env is correct. To improve DX, include a minimal .env.example in examples/basic so users know expected keys.

apps/playground/README.md (1)

1-6: Add quick-start commands

Consider adding run commands for clarity:

  • pnpm -w --filter playground dev
  • pnpm -w --filter playground start
packages/arkenv/src/scope.test.ts (2)

17-20: Use an unambiguously invalid host for the failure test.

"invalid-host" could be a valid single-label hostname. Prefer an obviously invalid value.

-  expect(() => hostType.assert({ HOST: "invalid-host" })).toThrow();
+  expect(() => hostType.assert({ HOST: "256.256.256.256" })).toThrow();

28-31: Add boundary tests for ports.

Cover 0 and 65535 (valid) and a negative (invalid).

   it("should throw for invalid port", () => {
     const portType = $.type({ PORT: "number.port" });
     expect(() => portType.assert({ PORT: "99999" })).toThrow();
   });
+
+  it("should accept boundary ports", () => {
+    const t = $.type({ PORT: "number.port" });
+    expect(t.assert({ PORT: "0" }).PORT).toBe(0);
+    expect(t.assert({ PORT: "65535" }).PORT).toBe(65535);
+  });
+
+  it("should reject negative ports", () => {
+    const t = $.type({ PORT: "number.port" });
+    expect(() => t.assert({ PORT: "-1" })).toThrow();
+  });
packages/arkenv/src/scope.ts (1)

4-4: Prefer durable docs over ephemeral links.

Consider summarizing the $ naming rationale inline or linking to repo docs instead of a Discord message.

packages/arkenv/src/create-env.ts (1)

10-15: Tighten JSDoc wording.

Return is the validated environment object, not “schema.”

- * @returns The validated environment variable schema
+ * @returns The validated environment object
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7c7592 and 796effe.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • .changeset/dull-socks-return.md (1 hunks)
  • apps/playground/README.md (1 hunks)
  • apps/playground/index.ts (1 hunks)
  • apps/playground/package.json (1 hunks)
  • apps/playground/tsconfig.json (1 hunks)
  • arkenv.code-workspace (1 hunks)
  • biome.jsonc (1 hunks)
  • examples/basic/package.json (1 hunks)
  • packages/arkenv/package.json (2 hunks)
  • packages/arkenv/src/create-env.ts (1 hunks)
  • packages/arkenv/src/index.ts (1 hunks)
  • packages/arkenv/src/scope.test.ts (1 hunks)
  • packages/arkenv/src/scope.ts (1 hunks)
  • packages/arkenv/tsconfig.json (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/arkenv/tsconfig.json
🧰 Additional context used
📓 Path-based instructions (1)
**/*.test.ts

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.test.ts: Name test files with the .test.ts suffix and colocate them alongside the source files they cover
Use Vitest's describe/it structure in tests
Mock process.env in tests that depend on environment variables and restore the original environment in setup/teardown
Test both success and failure cases for environment validation and validators
Verify both runtime behavior and TypeScript types in tests (e.g., with type assertions)

Files:

  • packages/arkenv/src/scope.test.ts
🪛 markdownlint-cli2 (0.17.2)
.changeset/dull-socks-return.md

5-5: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


11-11: Unordered list indentation
Expected: 0; Actual: 2

(MD007, ul-indent)


12-12: Unordered list indentation
Expected: 0; Actual: 2

(MD007, ul-indent)


45-45: Unordered list indentation
Expected: 0; Actual: 2

(MD007, ul-indent)

🔇 Additional comments (11)
packages/arkenv/package.json (2)

49-49: Peer dep bump to ArkType ^2.1.22 makes sense

Matches the new scope/token usage.


20-22: Workspace “fix” script correctly delegates to the root and won’t recurse
The root package.json defines "fix": "biome check --write ."; pnpm -w run fix invokes that root script, not this package’s own, so there’s no recursion.

biome.jsonc (1)

65-65: Include playground in override — LGTM

Extending the override to **/playground/**/* is appropriate for relaxed console rules there.

arkenv.code-workspace (1)

23-26: Workspace folder addition — LGTM

Playground entry aligns with repo structure.

packages/arkenv/src/scope.test.ts (2)

5-15: LGTM: happy-path host validation looks solid.


22-26: LGTM: port coercion and assertion behave as expected.

apps/playground/index.ts (2)

3-7: LGTM: schema uses the new string.host/number.port tokens.


6-6: Defaultable union default syntax is supported.
ArkType allows = 'value' defaults on string union properties in object schemas, so the existing NODE_ENV line is valid.

packages/arkenv/src/scope.ts (1)

9-18: LGTM: clean composition of root scope with string.host and number.port.

packages/arkenv/src/create-env.ts (2)

16-24: Overload design reads well and preserves inference.


24-34: Error guard: confirm instanceof works across bundlers.

Some setups can break instanceof checks on cross-bundle classes. If issues arise, consider a predicate from arktype (if available) or shape-checking.

This commit modifies the examples in the README and various documentation files to replace the usage of `host` and `port` with string literals for `HOST` and `PORT`. This change enhances clarity by providing explicit example values, improving the overall understanding of environment variable configuration in ArkEnv.
@github-actions github-actions bot added the www Improvements or additions to arkenv.js.org label Sep 8, 2025
This commit introduces the `tsx` dependency at version ^4.20.5 in the `playground` app's package.json and updates the pnpm-lock.yaml file accordingly. This addition enhances the TypeScript experience in the project.
This commit updates the TypeScript target version to ES2020 and changes the module system to ESNext in the playground's tsconfig.json. Additionally, a new script for fixing issues has been added to package.json, enhancing the development workflow.
@yamcodes yamcodes merged commit dd15b60 into main Sep 8, 2025
8 checks passed
@yamcodes yamcodes deleted the new-create-env branch September 8, 2025 18:41
@github-actions github-actions bot mentioned this pull request Sep 8, 2025
yamcodes pushed a commit that referenced this pull request Sep 8, 2025
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.4.0

### Minor Changes

- ## Improved type inference and scope-based validation
_[`#129`](#129)
[`dd15b60`](dd15b60)
[@yamcodes](https://github.com/yamcodes)_

The `createEnv` function got a facelift with better TypeScript inference
and introduced a new scope-based validation system.

    **Key improvements:**

- **Better ecosystem integration**: Use `string.host` and `number.port`
in your schemas, as if they were native ArkType keywords
- **Cleaner API**: No need to awkwardly import `host` and `port` types
anymore

    ### Before:

`host` and `port` had to be manually imported from the `arkenv` package,
and used as arguments to the `createEnv` function.

    ```ts
    import { createEnv, host, port } from "arkenv";

    const env = createEnv({
      HOST: host, // Validates IP addresses or "localhost"
      PORT: port, // Validates port numbers (0-65535)
      NODE_ENV: "string", // Standard string validation
    });
    ```

    ### After:

Now you can use `string.host` and `number.port` in your schemas, in a
way that is much more natural and idiomatic within the ArkType
ecosystem.

    ```ts
    import { createEnv } from "arkenv";

    const env = createEnv({
      HOST: "string.host", // Validates IP addresses or "localhost"
      PORT: "number.port", // Validates port numbers (0-65535)
      NODE_ENV: "string", // Standard string validation
    });
    ```

    ### BREAKING CHANGE:

- We are no longer exporting `host` and `port` types. Use `string.host`
and `number.port` instead.

## @arkenv/vite-plugin@0.0.7

### Patch Changes

- Upgraded ArkType peer dependency from `^2.0.0` to `^2.1.22` for
compatibility with the latest version of ArkEnv
_[`#129`](#129)
[`dd15b60`](dd15b60)
[@yamcodes](https://github.com/yamcodes)_

<details><summary>Updated 1 dependency</summary>

<small>


[`dd15b60`](dd15b60)

</small>

-   `arkenv@0.4.0`

</details>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@yamcodes yamcodes mentioned this pull request Jan 1, 2026
@yamcodes yamcodes added this to the v1 milestone Jan 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv arkenv Changes to the `arkenv` npm package. docs Improvements or additions to documentation example Issues or Pull Requests concerning at least one ArkEnv example. (Found in the `examples/` directory) tests This issue or PR is about adding, removing or changing tests www Improvements or additions to arkenv.js.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant