Skip to content

Commit f329ce9

Browse files
authored
Merge branch 'v1' into 1199-distribution-implement-standard-mode-packaging-strategy
2 parents c756d75 + 2b50ca9 commit f329ce9

80 files changed

Lines changed: 691 additions & 524 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/docs/CONTEXT.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ The main goal is to provide a developer-friendly way to validate and type-check
6363

6464
**Naming Conventions:**
6565

66-
- **Files**: kebab-case (`create-env.ts`)
67-
- **Functions**: camelCase (`createEnv`)
66+
- **Files**: kebab-case (`arkenv.ts`)
67+
- **Functions**: camelCase (`arkenvInternal`, `myFunction`)
6868
- **Types**: PascalCase (`ArkEnvError`)
6969
- **Constants**: UPPER_SNAKE_CASE for environment variables
7070

@@ -95,7 +95,7 @@ The main goal is to provide a developer-friendly way to validate and type-check
9595
**Package Architecture:**
9696

9797
- **Core Package** (`arkenv`):
98-
- Main export: `createEnv` function (also exported as default `arkenv`)
98+
- Main export: `arkenv` function (also exported as default export)
9999
- Uses ArkType's `scope` system for type validation
100100
- Custom types: `string.host`, `number.port`, `boolean`
101101
- Error handling via `ArkEnvError` class
@@ -200,7 +200,7 @@ pnpm run test:e2e # E2E tests
200200
- **Vite**: Integrated via `@arkenv/vite-plugin`. Validates environment variables at build-time and inlines `import.meta.env` variables for **client-side** (browser) usage.
201201
- **Next.js**: Integrated via `@arkenv/nextjs`. Provides two layout patterns:
202202
- **3-File Layout (Strict)**: Uses separate environment files for client, server, and shared scopes (`env/client.ts`, `env/server.ts`, and `env/internal/shared.ts`) for compile-time locking of secrets from browser bundles using package conditional exports (`react-server` vs. `default`) and `server-only`.
203-
- **Unified 1-File Layout**: Uses a single `env.ts` schema file. In Next.js, client-side environment variables must be statically destructured in a `runtimeEnv` block to allow static inlining by the Next.js compiler. To automate this, `@arkenv/nextjs/config` exposes a `withArkEnv` wrapper for `next.config.js` that performs static analysis on `env.ts` to locate `client` and `shared` keys, then automatically generates a tailored `createEnv` factory in `generated/env.gen.ts` that pre-fills `runtimeEnv`. It enforces strict client-side prefixing (`NEXT_PUBLIC_`) and prevents server secrets from leaking to client components.
203+
- **Unified 1-File Layout**: Uses a single `env.ts` schema file. In Next.js, client-side environment variables must be statically destructured in a `runtimeEnv` block to allow static inlining by the Next.js compiler. To automate this, `@arkenv/nextjs/config` exposes a `withArkEnv` wrapper for `next.config.js` that performs static analysis on `env.ts` to locate `client` and `shared` keys, then automatically generates a tailored `arkenv` factory in `generated/env.gen.ts` that pre-fills `runtimeEnv`. It enforces strict client-side prefixing (`NEXT_PUBLIC_`) and prevents server secrets from leaking to client components.
204204
- **Bun fullstack dev server**:
205205
- **Bun.serve**: An HTTP server runtime that integrates with Bun's built-in bundler to scan HTML files, trigger on-demand bundling, and serve resulting assets. It does not perform bundling itself; rather, it coordinates with Bun's bundler (configured via `@arkenv/bun-plugin` in `bunfig.toml`) to inline environment variables (e.g., using a `PUBLIC_` prefix) via static replacement. Primarily used for **client-side** bundling integration.
206206
- **Bun.build**: Bun's programmatic bundling API. Integrated via `@arkenv/bun-plugin` in the `Bun.build` plugins array. Used for custom build scripts targeting the browser in a fullstack context.
@@ -218,7 +218,7 @@ pnpm run test:e2e # E2E tests
218218

219219
- Uses `const` type parameters for better type inference
220220
- Leverages ArkType's `type.infer` and `type.validate` utilities
221-
- Typesafe environment object returned from `createEnv`
221+
- Typesafe environment object returned from `arkenv`
222222

223223
**Error Handling:**
224224

.agents/platforms/.cursor/rules/arktype.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Define environment variable schemas using ArkType syntax:
2222
```typescript
2323
import { type } from "arktype";
2424

25-
const env = createEnv({
25+
const env = arkenv({
2626
HOST: "string.host", // Custom host type
2727
PORT: "number.port", // Custom port type
2828
NODE_ENV: "'development' | 'production' | 'test'", // Union type
@@ -49,7 +49,7 @@ import { $ } from "./scope";
4949
## Type Inference
5050

5151
- Use `type.infer` to extract TypeScript types from schemas
52-
- The return type of `createEnv` is inferred from the schema
52+
- The return type of `arkenv` is inferred from the schema
5353
- No manual type definitions needed
5454

5555
## Error Handling

.agents/platforms/.cursor/rules/coding-guidelines.mdc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ This project uses [Biome](https://biomejs.dev/) for formatting and linting. The
4848

4949
## Naming Conventions
5050

51-
- **Files**: Use kebab-case for files (`create-env.ts`)
52-
- **Functions**: Use camelCase (`createEnv`)
51+
- **Files**: Use kebab-case for files (`arkenv-internal.ts`)
52+
- **Functions**: Use camelCase (`arkenv`, `myFunction`)
5353
- **Types**: Use PascalCase (`ArkEnvError`)
5454
- **Constants**: Use UPPER_SNAKE_CASE for environment variables and constants
5555

.agents/platforms/.cursor/rules/test-patterns.mdc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ alwaysApply: true
3333
- Fast execution (< 100ms per test)
3434
- Mocked external dependencies (clipboard, network, etc.)
3535
- Focused on single unit behavior
36-
- Co-locate with source: `create-env.ts` → `create-env.test.ts`
36+
- Co-locate with source: `arkenv.ts` → `arkenv.test.ts`
3737

3838
### Integration Tests (`*.integration.test.ts` or `*.integration.test.tsx`)
3939
**What:** Test how multiple units (components, hooks, functions) work together without mocking their interactions.
@@ -45,8 +45,8 @@ alwaysApply: true
4545
- State synchronization across boundaries
4646

4747
**Examples:**
48-
- `custom-types.integration.test.ts` - Tests `createEnv` + `scope` + custom types working together
49-
- `error.integration.test.ts` - Tests error propagation through `createEnv` + `formatErrors` + `ArkEnvError`
48+
- `custom-types.integration.test.ts` - Tests `arkenv` + `scope` + custom types working together
49+
- `error.integration.test.ts` - Tests error propagation through `arkenv` + `formatErrors` + `ArkEnvError`
5050
- `copy-button.integration.test.tsx` - Tests `CopyButton` + `useToast` + `Toaster` as a complete flow
5151
- `heading.integration.test.tsx` - Tests `Heading` + `useIsMobile` responding to viewport changes
5252
- `toaster.integration.test.tsx` - Tests `useToast` hook + `Toaster` component state synchronization
@@ -98,12 +98,12 @@ alwaysApply: true
9898

9999
```typescript
100100
import { describe, expect, it } from "vitest";
101-
import { createEnv } from "./create-env";
101+
import arkenv from "./arkenv";
102102

103-
describe("createEnv", () => {
103+
describe("arkenv", () => {
104104
it("should validate string env variables", () => {
105105
process.env.TEST_STRING = "hello";
106-
const env = createEnv({
106+
const env = arkenv({
107107
TEST_STRING: "string",
108108
});
109109
expect(env.TEST_STRING).toBe("hello");

.agents/platforms/copilot-instructions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ The project uses modern tooling:
5656

5757
The core package provides:
5858

59-
1. **`createEnv(schema)`** - Main function to create validated environment objects. Also available as the default export, typically imported as `arkenv`.
59+
1. **`arkenv(schema)`** - Main function to create validated environment objects. Exposed as default export, and also as named export `arkenv`.
6060
2. **Built-in validators** - Common validators like `host`, `port`, `url`, etc.
6161
3. **ArkType integration** - Uses ArkType for schema definition and validation
6262
4. **Type inference** - Full TypeScript type inference from schemas
6363

6464
### Key files
6565

66-
- `src/create-env.ts` - Core `createEnv` implementation
66+
- `src/arkenv.ts` - Core `arkenv` implementation
6767
- `src/types.ts` - Built-in type validators (host, port, url, etc.)
6868
- `src/errors.ts` - Error handling and formatting
6969
- `src/utils.ts` - Utility functions
@@ -113,7 +113,7 @@ The project uses three types of tests:
113113

114114
Tests are located alongside source files with `.test.ts` suffix:
115115

116-
- `create-env.test.ts` - Tests for main `createEnv` functionality
116+
- `arkenv.test.ts` - Tests for main `arkenv` functionality
117117
- `types.test.ts` - Tests for built-in validators
118118
- `errors.test.ts` - Tests for error handling
119119
- `utils.test.ts` - Tests for utility functions
@@ -131,7 +131,7 @@ Tests are located alongside source files with `.test.ts` suffix:
131131

132132
**Examples:**
133133

134-
- `custom-types.integration.test.ts` - Tests `createEnv` + `scope` + custom types working together
134+
- `custom-types.integration.test.ts` - Tests `arkenv` + `scope` + custom types working together
135135
- `error.integration.test.ts` - Tests error propagation through validation pipeline
136136
- `copy-button.integration.test.tsx` - Tests `CopyButton` + `useToast` + `Toaster` flow
137137
- `heading.integration.test.tsx` - Tests `Heading` + `useIsMobile` responsive behavior

.changeset/pre.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"@arkenv/nextjs": "0.0.7",
1818
"@arkenv/vite-plugin": "0.1.1"
1919
},
20-
"changesets": ["init-v1", "unify-coercion"]
20+
"changesets": ["init-v1", "rename-create-env-to-arkenv", "unify-coercion"]
2121
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
"arkenv": major
3+
"@arkenv/nextjs": major
4+
---
5+
6+
#### Rename `createEnv` function to `arkenv`
7+
8+
**BREAKING CHANGE**: Rename the primary environment variable validation function from `createEnv` to `arkenv` across all packages in the ecosystem, and expose it as both the default export and a named export.
9+
10+
Update all usages:
11+
12+
```ts
13+
// Before
14+
import { createEnv } from "arkenv";
15+
16+
export const env = createEnv({
17+
NODE_ENV: "'development' | 'production' | 'test'",
18+
});
19+
20+
// After
21+
import arkenv from "arkenv";
22+
// or: import { arkenv } from "arkenv";
23+
24+
export const env = arkenv({
25+
NODE_ENV: "'development' | 'production' | 'test'",
26+
});
27+
```
28+
29+
Migration Steps:
30+
- Replace all imports and invocations of `createEnv` with `arkenv`.
31+
- Update config generators and plugins (Next.js config templates, Vite plugin, Bun plugin) to use `arkenv`.

apps/playgrounds/nextjs-strict/env/generated/env.gen.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* @see https://arkenv.js.org
88
*/
99

10-
import { createEnv as coreCreateEnv } from "@arkenv/nextjs/client";
10+
import { arkenv as coreArkenv } from "@arkenv/nextjs/client";
1111

1212
export { type } from "@arkenv/nextjs/client";
1313

14-
export function createEnv<
14+
export function arkenv<
1515
const TSchema extends Record<string, any> = {},
1616
const TExtends extends readonly unknown[] = [],
1717
>(
@@ -22,7 +22,7 @@ export function createEnv<
2222
extends?: [...TExtends];
2323
},
2424
) {
25-
return coreCreateEnv<TSchema, TExtends>(
25+
return coreArkenv<TSchema, TExtends>(
2626
schema as any,
2727
{
2828
...options,
@@ -34,5 +34,4 @@ export function createEnv<
3434
);
3535
}
3636

37-
const arkenv = createEnv;
3837
export default arkenv;

apps/playgrounds/nextjs/generated/env.gen.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99

1010
import type { Infer } from "@arkenv/nextjs";
11-
import { createEnv as coreCreateEnv } from "@arkenv/nextjs";
11+
import { arkenv as coreArkenv } from "@arkenv/nextjs";
1212

1313
export { type } from "@arkenv/nextjs";
1414

15-
export function createEnv<
15+
export function arkenv<
1616
const TServer extends Record<string, any> = {},
1717
const TClient extends Record<string, any> = {},
1818
const TShared extends Record<string, any> = {},
@@ -23,7 +23,7 @@ export function createEnv<
2323
};
2424
shared?: TShared;
2525
}): Readonly<Infer<TServer & TClient & TShared>> {
26-
return coreCreateEnv({
26+
return coreArkenv({
2727
...options,
2828
runtimeEnv: {
2929
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
@@ -32,5 +32,4 @@ export function createEnv<
3232
} as any) as any;
3333
}
3434

35-
const arkenv = createEnv;
3635
export default arkenv;

apps/www/content/docs/arkenv/coercion.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Coercion works recursively: even variables inside a JSON object are coerced to t
100100

101101
## How it works
102102

103-
ArkEnv uses a unified pre-coercion model shared across both `arkenv` and `arkenv/standard`. When you call `createEnv()` (or `arkenv()`):
103+
ArkEnv uses a unified pre-coercion model shared across both `arkenv` and `arkenv/standard`. When you call `arkenv()`:
104104

105105
1. **Introspection**: ArkEnv extracts the JSON Schema of your defined schema. For `arkenv` (ArkType), it introspects the schema (with a fallback to handle unjsonifiable parts of the schema like custom morphs or predicates). For `arkenv/standard` (e.g., Zod, Valibot), it extracts JSON Schema using the validator's standard metadata.
106106
2. **Paths Identification**: It computes the exact paths requiring coercion (using `findCoercionPaths`) to identify target non-string types like numbers, booleans, arrays, or objects.

0 commit comments

Comments
 (0)