Skip to content

Conversation

@yamcodes
Copy link
Owner

@yamcodes yamcodes commented Jan 6, 2026

Closes #705

Summary by CodeRabbit

  • New Features

    • Support for Standard Schema validators (e.g., Zod) alongside ArkType; mixed validator mappings allowed and ArkType can be optional.
  • Improvements

    • Better runtime handling: on-demand validator support, improved coercion, and clearer, user-facing validation errors.
  • Types

    • Broadened type support to accept mixed schema styles for better interoperability.
  • Tests

    • Added Standard Schema integration tests and fixtures for Vite and Bun plugins.

✏️ Tip: You can customize this high-level summary in your review settings.

- Normalize ArkEnvError constructor input
- Add public issues property to ArkEnvError
- Deprecate and refactor formatErrors function
@changeset-bot
Copy link

changeset-bot bot commented Jan 6, 2026

⚠️ No Changeset found

Latest commit: 918ece4

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 no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 6, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

ArkType is now optional and loaded at runtime; createEnv detects Standard Schema vs ArkType validators, dispatches validation accordingly, normalizes errors to EnvIssue[], preserves ArkType-only coercion, adjusts types (InferType/EnvSchemaWithType), and updates plugin callsites and tests for mixed-validator support.

Changes

Cohort / File(s) Summary
Package manifests
packages/arkenv/package.json, packages/internal/types/package.json, packages/vite-plugin/package.json, packages/internal/scope/package.json
Add @standard-schema/spec, add devDeps (zod, @types/node), mark arktype optional via peerDependenciesMeta, update size-limit ignore.
Core validation runtime
packages/arkenv/src/create-env.ts
Runtime validator detection (Standard Schema vs ArkType), runtime require of arktype, dispatch to appropriate validator path, map errors to EnvIssue[], change ArkEnvConfig.env to `Record<string,string
Error normalization
packages/arkenv/src/errors.ts
Add EnvIssue type; formatErrors and ArkEnvError accept `ArkErrors
Coercion & utils
packages/arkenv/src/utils/coerce.ts
Move to runtime require("arktype"), tighten schema introspection checks, change coerce signature to T extends Type, add early-return when no coercion targets.
Type wrapper & scope
packages/arkenv/src/type.ts, packages/internal/scope/src/index.ts, packages/internal/scope/src/scope-def.ts, packages/internal/scope/tsconfig.json
Replace direct type export with Proxy resolving arktype at runtime; add lazy $ scope proxy and scope-def compile-time type; add Node types to scope tsconfig.
Internal types
packages/internal/types/src/infer-type.ts, packages/internal/types/src/schema.ts, packages/internal/types/src/filter-by-prefix.ts
Extend InferType<T> to include StandardSchemaV1, widen EnvSchemaWithType to allow StandardSchemaV1, relax FilterByPrefix generic (any-guard) for looser inference.
Plugin integrations & usage
packages/vite-plugin/src/index.ts, packages/bun-plugin/src/index.ts
Cast createEnv options to any at call sites to avoid deep type instantiation; runtime behaviour unchanged.
Tests & fixtures
packages/arkenv/src/create-env.test.ts, packages/arkenv/src/standard-schema.test.ts, packages/vite-plugin/src/__fixtures__/standard-schema/*, packages/vite-plugin/src/index.test.ts, packages/bun-plugin/src/index.test.ts
Add tests covering Standard Schema (Zod-like), mixed-validator scenarios, top-level Standard Schema rejection, and fixture files for plugin integration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant createEnv
    participant detectValidatorType
    participant validateStandard
    participant validateArkType
    participant formatErrors

    User->>createEnv: createEnv(def, config)
    createEnv->>detectValidatorType: detectValidatorType(def)
    alt Standard Schema
        detectValidatorType-->>validateStandard: def (StandardSchemaV1)
        validateStandard->>validateStandard: run validator -> value or issues
        validateStandard->>formatErrors: map issues -> EnvIssue[]
    else ArkType
        detectValidatorType-->>validateArkType: def (ArkType)
        validateArkType->>validateArkType: load arktype, apply coercion, validate
        validateArkType->>formatErrors: map ArkErrors -> EnvIssue[]
    end
    alt No errors
        formatErrors-->>createEnv: success
        createEnv-->>User: return inferred value
    else Errors
        formatErrors-->>createEnv: formatted issues
        createEnv-->>User: throw ArkEnvError with issues
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

Possibly related PRs

Poem

🐰
I nibble schemas, soft and bright,
Zod and ArkType share the night,
Optional hops, runtime delight,
Errors tidy, fences tight,
A carrot for mixed-validator flight! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Make ArkType optional and support Standard Schema directly' accurately summarizes the main objective of the PR, which is to make ArkType optional and add Standard Schema support.
Linked Issues check ✅ Passed All coding requirements from issue #705 are substantially addressed: ArkType is made optional with runtime loading, Standard Schema validators are supported directly in mappings, both can be mixed, coercion remains ArkType-specific, and error handling is normalized.
Out of Scope Changes check ✅ Passed Changes are well-aligned with PR objectives. The modifications to package.json, type utilities, and test fixtures are all necessary for implementing Standard Schema support and making ArkType optional.

✏️ 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.

❤️ Share

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

@github-actions github-actions bot added arkenv Changes to the `arkenv` npm package. tests This issue or PR is about adding, removing or changing tests. labels Jan 6, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/arkenv@704
npm i https://pkg.pr.new/@arkenv/bun-plugin@704
npm i https://pkg.pr.new/@arkenv/vite-plugin@704

commit: 918ece4

@arkenv-bot
Copy link
Contributor

arkenv-bot bot commented Jan 6, 2026

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

Project Deployment Review Updated (Asia/Almaty)
arkenv Ready Ready Preview, Comment Jan 10 2026, 11:15 PM (Asia/Almaty)

@github-actions github-actions bot added the @arkenv/vite-plugin Issues or Pull Requests involving the Vite plugin for ArkEnv label Jan 6, 2026
@yamcodes
Copy link
Owner Author

yamcodes commented Jan 6, 2026

  • 1. Remove or reject arkenv(z.object(...))
  • * Only allow Standard Schema inside object mappings
  • * This preserves ArkEnv’s identity and migration story
  • 2. Keep one public API
  • * arkenv(...)
  • * Everything else internal or deprecated-for-real
  • 3. Reframe Standard Schema as support, not replacement
  • * Migration tool, not an alternative product direction

@yamcodes yamcodes changed the title Make ArkEnv optional Make ArkType optional and support Standard Schema directly Jan 6, 2026
- `arkenv()` now strictly expects a schema mapping object
- No longer accepts top-level compiled ArkType or Zod
@github-actions github-actions bot added docs Improvements or additions to documentation www Improvements or additions to arkenv.js.org labels Jan 8, 2026
- Allow compiled ArkType schemas as top-level arg
- Support standard Zod schemas as top-level arg
- Remove invalid schema argument error
- Update Bun and Vite plugins to support new schema types
- Remove deprecated formatErrors function.
- Update tests to use formatIssues directly.
- Simplify error formatting logic.
- Simplify ArkType brand check
- Remove unnecessary infer function check
- Maintain existing duck typing fallback
@yamcodes
Copy link
Owner Author

yamcodes commented Jan 9, 2026

@coderabbitai all clear? Can you approve?

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: 0

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

77-79: Document or eliminate unsafe type assertions.

The as any cast at line 79 bypasses type safety. If this is necessary because $.type() accepts dynamic input, add a comment explaining why. Consider whether runtime validation could replace the cast.

📝 Add explanatory comment
 let schema = isCompiledType
 	? (def as Type)
-	: ($.type(def as any) as unknown as Type);
+	: // @ts-expect-error - $.type accepts dynamic schema definitions that can't be statically typed
+	  ($.type(def) as unknown as Type);

113-122: Improve error message specificity.

The phrase "this schema type" is vague. Be more explicit about what triggered the ArkType requirement.

💬 Suggested improvement
 		throw new Error(
-			"ArkType is required for this schema type. Please install 'arktype' or use a Standard Schema validator like Zod.",
+			"ArkType is required for the provided schema definition. Please install 'arktype' as a dependency, or use Standard Schema validators (Zod, Valibot) inside your env mapping.",
 		);
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 989160f and 5c6e05d.

📒 Files selected for processing (1)
  • packages/arkenv/src/create-env.ts
🧰 Additional context used
📓 Path-based instructions (2)
packages/arkenv/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/arktype.mdc)

packages/arkenv/**/*.ts: Use ArkType's type() function to define schemas in environment variable definitions
Leverage ArkType's type inference for TypeScript types instead of manual type definitions
Use the scoped $ type system for custom types defined in scope.ts
Keep environment variable schemas readable and TypeScript-like using ArkType syntax
Use union types for enums in ArkType schemas (e.g., "'dev' | 'prod'") instead of separate enum definitions
Leverage ArkType's built-in types (e.g., string.host, number.port) where possible in environment schemas
Convert ArkType validation errors to ArkEnvError for user-friendly error messages that include variable name and expected type

Files:

  • packages/arkenv/src/create-env.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/coding-guidelines.mdc)

**/*.{ts,tsx}: Prefer type over interface for type definitions in TypeScript
Use TypeScript 5.1+ features when appropriate
Leverage const type parameters for better inference in TypeScript
Use JSDoc comments for public APIs
Use tabs for indentation (configured in Biome)
Use double quotes for strings (configured in Biome)
Organize imports automatically (Biome handles this)
Avoid explicit types when TypeScript can infer them (noInferrableTypes error)
Use as const where appropriate for immutable values (useAsConstAssertion error)
Don't reassign function parameters (noParameterAssign error)
Place default parameters last in function signatures (useDefaultParameterLast error)
Always initialize enum values (useEnumInitializers error)
Declare one variable per statement (useSingleVarDeclarator error)
Avoid unnecessary template literals (noUnusedTemplateLiteral error)
Prefer Number.parseInt over global parseInt (useNumberNamespace error)
Use kebab-case for TypeScript filenames (e.g., create-env.ts)
Use camelCase for function names (e.g., createEnv)
Use PascalCase for type names (e.g., ArkEnvError)
Use UPPER_SNAKE_CASE for environment variables and constants
Include examples in JSDoc comments when helpful for public APIs
Document complex type logic with JSDoc comments
Use ArkEnvError for environment variable validation errors
Provide clear, actionable error messages that include the variable name and expected type

**/*.{ts,tsx}: Use createEnv(schema) function (or default import as arkenv) to create validated environment objects in TypeScript
Use built-in validators (host, port, url, email) from ArkEnv when available instead of custom ArkType schemas
Provide default values for optional environment variables using ArkType syntax (e.g., 'boolean = false')
Use ArkEnvError for environment variable errors instead of generic Error types
For environment schema definition, use ArkType string literal syntax for enumerated values (e.g., "'deve...

Files:

  • packages/arkenv/src/create-env.ts
🧠 Learnings (18)
📓 Common learnings
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Keep environment variable schemas readable and TypeScript-like using ArkType syntax
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Leverage ArkType's built-in types (e.g., `string.host`, `number.port`) where possible in environment schemas
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use built-in validators (host, port, url, email) from ArkEnv when available instead of custom ArkType schemas
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Convert ArkType validation errors to `ArkEnvError` for user-friendly error messages that include variable name and expected type
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use union types for enums in ArkType schemas (e.g., `"'dev' | 'prod'"`) instead of separate enum definitions
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use ArkType's `type()` function to define schemas in environment variable definitions
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use `createEnv(schema)` function (or default import as `arkenv`) to create validated environment objects in TypeScript
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : For environment schema definition, use ArkType string literal syntax for enumerated values (e.g., "'development' | 'production' | 'test'")
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Provide default values for optional environment variables using ArkType syntax (e.g., 'boolean = false')
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Leverage ArkType's type inference for TypeScript types instead of manual type definitions
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: ArkType validates environment variables at runtime and TypeScript types are inferred from the schema definition
Learnt from: yamcodes
Repo: yamcodes/arkenv PR: 498
File: apps/playgrounds/node/index.ts:2-2
Timestamp: 2025-12-05T20:33:10.676Z
Learning: ArkType 2.1.28+ supports Standard Schema specification, allowing interoperability with other Standard Schema-compliant validation libraries (e.g., Zod, Valibot) within the same schema definition
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/coding-guidelines.mdc:0-0
Timestamp: 2025-11-24T16:04:00.957Z
Learning: Applies to **/*.{ts,tsx} : Use `ArkEnvError` for environment variable validation errors
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use ArkEnvError for environment variable errors instead of generic Error types
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Keep environment variable schemas readable and TypeScript-like using ArkType syntax

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Convert ArkType validation errors to `ArkEnvError` for user-friendly error messages that include variable name and expected type

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: ArkType validates environment variables at runtime and TypeScript types are inferred from the schema definition

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-12-23T07:09:57.130Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use `createEnv(schema)` function (or default import as `arkenv`) to create validated environment objects in TypeScript

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use ArkType's `type()` function to define schemas in environment variable definitions

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use union types for enums in ArkType schemas (e.g., `"'dev' | 'prod'"`) instead of separate enum definitions

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Leverage ArkType's type inference for TypeScript types instead of manual type definitions

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Leverage ArkType's built-in types (e.g., `string.host`, `number.port`) where possible in environment schemas

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-12-23T07:09:57.130Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use built-in validators (host, port, url, email) from ArkEnv when available instead of custom ArkType schemas

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-12-23T07:09:57.130Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : For environment schema definition, use ArkType string literal syntax for enumerated values (e.g., "'development' | 'production' | 'test'")

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-12-22T19:44:11.474Z
Learnt from: yamcodes
Repo: yamcodes/arkenv PR: 596
File: examples/basic/index.ts:4-5
Timestamp: 2025-12-22T19:44:11.474Z
Learning: In examples/basic/index.ts: Use explicit ArkType syntax (e.g., "string.ip | 'localhost'", "0 <= number.integer <= 65535") instead of built-in validators (string.host, number.port) to showcase ArkType's type system capabilities for educational purposes.

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:04:00.957Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/coding-guidelines.mdc:0-0
Timestamp: 2025-11-24T16:04:00.957Z
Learning: Applies to **/*.{ts,tsx} : Use `ArkEnvError` for environment variable validation errors

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-12-23T07:09:57.130Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use ArkEnvError for environment variable errors instead of generic Error types

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/scope.ts : Define custom types in `scope.ts` using ArkType's scoped type system for reusability across schemas

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:04:00.957Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/coding-guidelines.mdc:0-0
Timestamp: 2025-11-24T16:04:00.957Z
Learning: Applies to **/*.{ts,tsx} : Provide clear, actionable error messages that include the variable name and expected type

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-11-24T16:03:45.295Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use the scoped `$` type system for custom types defined in `scope.ts`

Applied to files:

  • packages/arkenv/src/create-env.ts
📚 Learning: 2025-12-23T07:09:57.130Z
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Provide default values for optional environment variables using ArkType syntax (e.g., 'boolean = false')

Applied to files:

  • packages/arkenv/src/create-env.ts
🔇 Additional comments (6)
packages/arkenv/src/create-env.ts (6)

1-9: LGTM! Clean setup for optional ArkType loading.

The dynamic require approach with type-only imports enables optional ArkType usage without forcing it into the bundle when Standard Schema validators are used.


16-40: LGTM! Type refinements improve clarity.

The explicit Record<string, string | undefined> type for env and the enhanced documentation for onUndeclaredKey and arrayFormat options make the API more self-documenting.


152-159: LGTM! Guardrail correctly enforces mapping-based API.

The error message clearly explains that Standard Schema validators must be inside object mappings, not passed as top-level schemas. This aligns with the PR objective to preserve ArkEnv's identity.


42-65: The duck typing detection at lines 57–62 is a reasonable and effective fallback. The implementation is working correctly:

  • String schemas bypass duck typing (non-object-like) and are compiled via $.type() at line 79
  • The primary infer brand check reliably identifies pre-compiled ArkType validators
  • Test coverage confirms both string and compiled validators work, including mixed ArkType + Standard Schema scenarios
  • No edge cases or false positives/negatives have been encountered in practice

No changes needed.


161-167: Error message is misleading about Standard Schema as alternative to ArkType.

The code always requires ArkType at line 73 via require("arktype"). While Standard Schema validators (Zod, Valibot) can be used within mappings like { PORT: z.number() }, they require ArkType to be installed—ArkType processes them through its Standard Schema support, not as a replacement.

The error at line 120 suggests "use a Standard Schema validator" as if it's an alternative to installing ArkType, which is incorrect. Users providing Standard Schema validators without ArkType installed will still fail at the require("arktype") call with a misleading error message.

Recommended fix: Update the error message to clarify that Standard Schema validators require ArkType:

"ArkType is required. You can use Standard Schema validators (Zod, Valibot, etc.) within your environment mapping, but ArkType must be installed to process them."

Alternatively, add a separate validation check in createEnv to detect Standard Schema validators in the mapping and provide a clearer error before reaching require("arktype").


93-105: Verify error path handling for nested objects and arrays in ArkType validation results.

The current implementation at lines 93-105 uses path.split(".") to convert error paths from ArkType's byPath keys into string arrays. While this handles root-level errors correctly (with the path ? ... : [] check), the actual structure of byPath keys for nested objects and array validation is not tested in the codebase.

The concerns are valid but unconfirmed:

  • No tests validate error structures for nested object properties (e.g., whether ArkType produces keys like "CONFIG.DB.PORT")
  • No tests verify array element error paths (e.g., how indices are formatted)
  • No tests cover special characters or quoted keys in paths

The implementation assumes ArkType produces dot-separated paths, which works if that's the case, but the codebase provides no evidence of how ArkType structures errors for complex nested schemas.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2026

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the implementation in create-env.ts enforces top-level Standard Schema rejection
cat packages/arkenv/src/create-env.ts | grep -A 20 "detectValidatorType"

Length of output: 1983


🏁 Script executed:

#!/bin/bash
# Check the error message when top-level Standard Schema is passed
cat packages/arkenv/src/create-env.ts | grep -B 5 -A 10 "Standard Schema.*top-level\|directly.*Standard Schema"

Length of output: 581


🏁 Script executed:

#!/bin/bash
# Verify the public API exports from arkenv package
cat packages/arkenv/src/index.ts

Length of output: 413


🏁 Script executed:

#!/bin/bash
# Check test that verifies top-level Standard Schema is rejected
cat packages/arkenv/src/create-env.test.ts | grep -A 15 "should throw error when passing a Standard Schema"

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Find the test that validates top-level Standard Schema rejection
cat packages/arkenv/src/create-env.test.ts | grep -B 2 -A 15 "top-level.*Standard\|Standard.*directly"

Length of output: 579


🏁 Script executed:

#!/bin/bash
# Look at the standard-schema.test.ts file for rejection tests
cat packages/arkenv/src/standard-schema.test.ts | head -30

Length of output: 752


🏁 Script executed:

#!/bin/bash
# Check if there are any other exports besides arkenv/createEnv that might be public APIs
rg -n "export (const|function|default|type|class|interface)" packages/arkenv/src/ --type=ts -g '!*.test.ts' -C 1

Length of output: 2775


🏁 Script executed:

#!/bin/bash
# Check for any deprecated exports or APIs
rg -n "@deprecated|DEPRECATED" packages/arkenv/src/ --type=ts

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Verify the error message framing positions Standard Schema as support
cat packages/arkenv/src/create-env.ts | grep -A 3 "Standard Schema validators are supported"

Length of output: 131


🏁 Script executed:

#!/bin/bash
# Check if tests demonstrate the "support" framing (mixed usage)
cat packages/arkenv/src/create-env.test.ts | grep -A 10 "mixed ArkType DSL and Standard Schema"

Length of output: 241


@yamcodes All clear! I've verified the implementation against your three requirements:

Top-level Standard Schema rejection: The code explicitly blocks arkenv(z.object(...)) with a clear error message and only allows Standard Schema validators inside object mappings like { PORT: z.string() }.

Single public API: The package exports arkenv (default) and createEnv as the main API, with supporting utilities (type, ArkEnvError). No deprecated or alternative APIs found.

Standard Schema as support: The error message frames it perfectly: "Standard Schema validators are supported inside the mapping" and tests demonstrate mixed usage (ArkType DSL + Zod validators together), positioning Standard Schema as a migration tool rather than a replacement.

The PR successfully preserves ArkEnv's identity while enabling interoperability. Approving now! 🎉


🧠 Learnings used
Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Keep environment variable schemas readable and TypeScript-like using ArkType syntax

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Leverage ArkType's built-in types (e.g., `string.host`, `number.port`) where possible in environment schemas

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use built-in validators (host, port, url, email) from ArkEnv when available instead of custom ArkType schemas

Learnt from: yamcodes
Repo: yamcodes/arkenv PR: 498
File: apps/playgrounds/node/index.ts:2-2
Timestamp: 2025-12-05T20:33:10.676Z
Learning: ArkType 2.1.28+ supports Standard Schema specification, allowing interoperability with other Standard Schema-compliant validation libraries (e.g., Zod, Valibot) within the same schema definition

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Convert ArkType validation errors to `ArkEnvError` for user-friendly error messages that include variable name and expected type

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use ArkType's `type()` function to define schemas in environment variable definitions

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: Applies to packages/arkenv/**/*.ts : Use union types for enums in ArkType schemas (e.g., `"'dev' | 'prod'"`) instead of separate enum definitions

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : Use `createEnv(schema)` function (or default import as `arkenv`) to create validated environment objects in TypeScript

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-23T07:09:57.130Z
Learning: Applies to **/*.{ts,tsx} : For environment schema definition, use ArkType string literal syntax for enumerated values (e.g., "'development' | 'production' | 'test'")

Learnt from: CR
Repo: yamcodes/arkenv PR: 0
File: .cursor/rules/arktype.mdc:0-0
Timestamp: 2025-11-24T16:03:45.295Z
Learning: ArkType validates environment variables at runtime and TypeScript types are inferred from the schema definition

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Actions performed

Comments resolved and changes approved.

@yamcodes
Copy link
Owner Author

yamcodes commented Jan 9, 2026

Before merge, also

  1. Manual review
  2. Address size limits or raise them
  3. Add changeset
  4. Clarify top-level Standard Schema support model (doc note)
  5. Document ArkType optionality boundaries and expectations (doc note)

@yamcodes yamcodes marked this pull request as draft January 9, 2026 21:02
@arkenv-bot
Copy link
Contributor

arkenv-bot bot commented Jan 10, 2026

📦 Bundle Size Report

Package Size Limit Diff Status
@arkenv/vite-plugin 2.51 kB 1.95 kB +40.2%
arkenv 2.38 kB 1.95 kB +43.4%
@arkenv/bun-plugin 3 kB 2.44 kB +31.0%

Size limits exceeded! Please review the changes above.

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. tests This issue or PR is about adding, removing or changing tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make ArkType optional and support Standard Schema directly

2 participants