Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Jan 25, 2025
2 parents 17ce3c6 + 23f7115 commit 8bd3218
Show file tree
Hide file tree
Showing 39 changed files with 2,445 additions and 1,438 deletions.
15 changes: 15 additions & 0 deletions .changeset/fair-rats-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@t3-oss/env-nextjs": minor
"@t3-oss/env-core": minor
"@t3-oss/env-nuxt": minor
---

feat!: support standard schema

Validators can now be any validator that supports [Standard Schema](https://github.com/standard-schema/standard-schema),
for example Zod & Valibot.

This feature comes with some breaking changes:

- If using Zod, the minimum required version is now 3.24.
- `onValidationError` now gets `StandardSchemaV1.Issue[]` instead of `ZodError`
12 changes: 11 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ jobs:

- run: bun lint

typecheck:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- uses: ./.github/setup

- run: bun typecheck

test:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- uses: ./.github/setup

- run: bun turbo test typecheck --filter "@t3-oss/env*"
- run: bun turbo run build --filter=@t3-oss/env*
- run: bun test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ env.d.ts
next-env.d.ts
**/.vscode
**/.zed
*.tsbuildinfo
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Julius Marminge
Copyright (c) 2025 Julius Marminge

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ pnpm add @t3-oss/env-core zod
pnpm add @t3-oss/env-nextjs zod
```

> Currently only supports Zod (which you'll need to install separately). Bring your own validation library is on the roadmap.
> [!NOTE]
>
> You may use any Standard Schema compliant validator of your choice. This example uses Zod

## Usage

> For full documentation, see https://env.t3.gg
This package supports the full power of Zod, meaning you can use `transforms` and `default` values.
This package supports the full power of Zod/Valibot etc, meaning you can use `transforms` and `default` values.

### Define your schema

Expand Down Expand Up @@ -76,4 +79,4 @@ export const GET = (req: Request) => {

## Roadmap

- [ ] Bring your own validation library - currently only supports Zod.
- [x] Bring your own validation library - now supports any [Standard Schema library](https://github.com/standard-schema/standard-schema?tab=readme-ov-file#what-schema-libraries-implement-the-spec)
2,707 changes: 1,394 additions & 1,313 deletions bun.lock

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@
"start": "next start"
},
"dependencies": {
"@juliusmarminge/next-themes": "^0.3.0",
"@mdx-js/loader": "^2.3.0",
"@next/mdx": "^14.2.1",
"@radix-ui/react-popover": "^1.0.5",
"@radix-ui/react-scroll-area": "^1.0.3",
"@mdx-js/loader": "^3.1.0",
"@next/mdx": "^15.1.6",
"radix-ui": "^1.1.2",
"@vercel/analytics": "^1.2.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"lucide-react": "0.368.0",
"next": "^14.2.1",
"next-view-transitions": "^0.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-wrap-balancer": "^1.1.0",
"next": "^15.1.6",
"next-themes": "^0.4.4",
"next-view-transitions": "^0.3.4",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-wrap-balancer": "^1.1.1",
"rehype-pretty-code": "0.9.5",
"sharp": "^0.33.3",
"shiki": "0.14.1",
"tailwind-merge": "^2.2.0",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/node": "^20.12.0",
"@types/react": "18.2.78",
"@types/react-dom": "18.2.25",
"@types/node": "^22.10.10",
"@types/react": "19.0.0",
"@types/react-dom": "19.0.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5"
"typescript": "^5.7.3"
}
}
6 changes: 6 additions & 0 deletions docs/src/app/docs/core/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ npm install @t3-oss/env-core zod

<Callout>

Although we'll use Zod as examples throughout these docs, you can use any validator that supports [Standard Schema](https://github.com/standard-schema/standard-schema).

</Callout>

<Callout>

`@t3-oss/env-core` requires a minimum of `typescript@5.0.0`.

</Callout>
Expand Down
4 changes: 2 additions & 2 deletions docs/src/app/docs/customization/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import { createEnv } from "@t3-oss/env-core";
export const env = createEnv({
// ...
// Called when the schema validation fails.
onValidationError: (error: ZodError) => {
onValidationError: (issues: StandardSchemaV1.Issue[]) => {
console.error(
"❌ Invalid environment variables:",
error.flatten().fieldErrors
issues
);
throw new Error("Invalid environment variables");
},
Expand Down
6 changes: 6 additions & 0 deletions docs/src/app/docs/nextjs/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pnpm add @t3-oss/env-nextjs zod

<Callout>

Although we'll use Zod as examples throughout these docs, you can use any validator that supports [Standard Schema](https://github.com/standard-schema/standard-schema).

</Callout>

<Callout>

`@t3-oss/env-nextjs` requires a minimum of `typescript@5.0.0`.

</Callout>
Expand Down
6 changes: 6 additions & 0 deletions docs/src/app/docs/nuxt/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ pnpm add @t3-oss/env-nuxt zod

<Callout>

Although we'll use Zod as examples throughout these docs, you can use any validator that supports [Standard Schema](https://github.com/standard-schema/standard-schema).

</Callout>

<Callout>

`@t3-oss/env-core` requires a minimum of `typescript@5`.

</Callout>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { SiteHeader } from "@/components/site-header";
import { TailwindIndicator } from "@/components/tailwind-indicator";
import { cn } from "@/lib/cn";
import "@/styles/globals.css";
import { ThemeProvider } from "@juliusmarminge/next-themes";
import { Analytics } from "@vercel/analytics/react";
import type { Metadata, Viewport } from "next";
import { ThemeProvider } from "next-themes";
import { ViewTransitions } from "next-view-transitions";

import { Inter, JetBrains_Mono } from "next/font/google";
Expand Down
9 changes: 7 additions & 2 deletions docs/src/components/mobile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import { Link } from "next-view-transitions";
import * as React from "react";

import { Button } from "./ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
import {
Popover,
PopoverClose,
PopoverContent,
PopoverTrigger,
} from "./ui/popover";
import { ScrollArea } from "./ui/scroll-area";

import { cn } from "@/lib/cn";
import { PopoverClose } from "@radix-ui/react-popover";

import { usePathname } from "next/navigation";
import { Icons } from "./icons";
import type { NavItem } from "./main-nav";
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/theme-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useTheme } from "@juliusmarminge/next-themes";
import { useTheme } from "next-themes";
import * as React from "react";

import { Icons } from "@/components/icons";
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/ui/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { cn } from "@/lib/cn";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { Popover as PopoverPrimitive } from "radix-ui";
import * as React from "react";

const Popover = PopoverPrimitive.Root;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/ui/scroll-area.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import { ScrollArea as ScrollAreaPrimitive } from "radix-ui";
import * as React from "react";

import { cn } from "@/lib/cn";
Expand Down
2 changes: 2 additions & 0 deletions examples/astro-valibot/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=3000
PUBLIC_API_URL=http://localhost:3000
8 changes: 8 additions & 0 deletions examples/astro-valibot/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "astro/config";

import solidJs from "@astrojs/solid-js";

// https://astro.build/config
export default defineConfig({
integrations: [solidJs()],
});
21 changes: 21 additions & 0 deletions examples/astro-valibot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@examples/astro-valibot",
"type": "module",
"private": true,
"scripts": {
"build": "astro build",
"dev": "astro dev",
"preview": "astro preview",
"start": "astro dev"
},
"dependencies": {
"@astrojs/solid-js": "^5.0.4",
"@t3-oss/env-core": "workspace:*",
"astro": "^5.1.9",
"solid-js": "^1.9.4",
"valibot": "^1.0.0-beta.14"
},
"devDependencies": {
"vite": "^6.0.1"
}
}
6 changes: 6 additions & 0 deletions examples/astro-valibot/src/counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { env } from "./t3-env";

export function ClientComponent() {
// Try changing PUBLIC_API_URL to PORT - the component will throw
return <div>Client API Url:{env.PUBLIC_API_URL}</div>;
}
18 changes: 18 additions & 0 deletions examples/astro-valibot/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import { ClientComponent } from "../counter";
import { env } from "../t3-env";
---

<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Astro</title>
</head>
<body>
<h1>Astro</h1>
<p>PORT: {env.PORT}</p>
<ClientComponent client:only />
</body>
</html>
17 changes: 17 additions & 0 deletions examples/astro-valibot/src/t3-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createEnv } from "@t3-oss/env-core";
import { string } from "valibot";

export const env = createEnv({
server: {
PORT: string(),
},
client: {
PUBLIC_API_URL: string(),
},
// Astro bundles all environment variables so
// we don't need to manually destructure them
runtimeEnv: import.meta.env,
// process is not available in Astro, so we must set this explicitly
skipValidation: import.meta.env.SKIP_ENV_VALIDATION === "development",
clientPrefix: "PUBLIC_",
});
11 changes: 11 additions & 0 deletions examples/astro-valibot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "astro/tsconfigs/strictest",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"types": ["astro/client"]
},
"include": ["src", "astro.config.mjs"]
}
10 changes: 5 additions & 5 deletions examples/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"start": "astro dev"
},
"dependencies": {
"@astrojs/solid-js": "^2.1.0",
"@astrojs/solid-js": "^5.0.4",
"@t3-oss/env-core": "workspace:*",
"astro": "^2.3.0",
"solid-js": "^1.4.3",
"zod": "^3.23.0"
"astro": "^5.1.9",
"solid-js": "^1.9.4",
"zod": "^3.24.1"
},
"devDependencies": {
"vite": "^4.3.1"
"vite": "^6.0.1"
}
}
16 changes: 8 additions & 8 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
},
"dependencies": {
"@t3-oss/env-nextjs": "workspace:*",
"next": "^14.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"zod": "^3.23.0"
"next": "^15.1.6",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"zod": "^3.24.1"
},
"devDependencies": {
"@types/node": "^20.12.0",
"@types/react": "18.2.78",
"@types/react-dom": "18.2.25",
"@types/node": "^22.10.10",
"@types/react": "19.0.0",
"@types/react-dom": "19.0.0",
"jiti": "^1.21.0",
"typescript": "^5.4.5"
"typescript": "^5.7.3"
}
}
6 changes: 3 additions & 3 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"preview": "nuxt preview"
},
"devDependencies": {
"@types/node": "^20.12.0",
"nuxt": "^3.11.2"
"@types/node": "^22.10.10",
"nuxt": "^3.15.3"
},
"dependencies": {
"@t3-oss/env-nuxt": "workspace:*",
"zod": "^3.23.0"
"zod": "^3.24.1"
}
}
Loading

0 comments on commit 8bd3218

Please sign in to comment.