Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/playgrounds/node/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ HOST=localhost
PORT=3000
NODE_ENV=development
DEBUG=true
ZED_ENV=development
8 changes: 5 additions & 3 deletions apps/playgrounds/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
import arkenv, { type } from "arkenv";
import * as z from "zod";
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const Env = type({
const env = arkenv({
HOST: "string.host",
PORT: "number.port",
NODE_ENV: "'development' | 'production' | 'test' = 'development'",
ALLOWED_ORIGINS: type("string[]").default(() => []),
DEBUG: "boolean = true",
ZED_ENV: z.string(),
});

const env = arkenv(Env, process.env);

// Automatically validate and parse process.env
// TypeScript knows the ✨exact✨ types!
const host = env.HOST;
const port = env.PORT;
const nodeEnv = env.NODE_ENV;
const allowedOrigins = env.ALLOWED_ORIGINS;
const debug = env.DEBUG;
const zedEnv = env.ZED_ENV;
console.log({
host,
port,
nodeEnv,
allowedOrigins,
debug,
zedEnv,
});

export default env;
3 changes: 2 additions & 1 deletion apps/playgrounds/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"dependencies": {
"arkenv": "workspace:*",
"arktype": "catalog:"
"arktype": "catalog:",
"zod": "^4.1.13"
},
"devDependencies": {
"@types/node": "catalog:",
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default function arkenv<const T extends Record<string, unknown>>(

// createEnv accepts both EnvSchema and type.Any at runtime
// We use overloads above to provide external type precision
const env = createEnv(options, loadEnv(mode, process.cwd(), ""));
// TODO: Improve the `EnvSchema<T>` type rather than using `as never`. See #501.
const env = createEnv(options as never, loadEnv(mode, process.cwd(), ""));

// Filter to only include environment variables matching the prefix
// This prevents server-only variables from being exposed to client code
Expand Down
53 changes: 19 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ catalog:
"@types/react-dom": 19.2.3
"@vitejs/plugin-react": 5.1.1
"@vitest/ui": 4.0.15
arktype: 2.1.27
arktype: 2.1.28
bun: 1.3.3
concurrently: 9.2.1
globals: 16.5.0
Expand Down
Loading