Skip to content
Source
Sign inSign up
TanStack/cli

feat(create): add ArkEnv add-on for environment variables #516

Openyamcodes(GitHub profile, opens in a new tab)wants to merge 9 commits intomain fromrefs/pull/516/headopened

Showing 14 changed files with 147 additions and 0 deletions (loading 11).

x
0 of 14 viewed, 14 left
10 additions and 0 deletions.changeset/arkenv-addon.mdAdded
View file
@@ -0,0 +1,10 @@
+---
+'@tanstack/create': minor
+---
+​
+Add an ArkEnv add-on for environment variable validation in React Start apps.
+​
+`tanstack add arkenv` (or `--add-ons arkenv` on `tanstack create`)
+writes `src/env.ts`, registers `@arkenv/vite-plugin`, and can add a
+`/demo/arkenv` route. ArkType, Zod, and Valibot are selectable. ArkEnv
+and T3Env are mutually exclusive because both write `src/env.ts`.
82 additions and 0 deletionspackages/create/src/frameworks/react/add-ons/arkenv/assets/src/routes/demo/arkenv.tsx.ejsAdded
View file
@@ -0,0 +1,82 @@
+<% if (!includeExamples || routerOnly || !fileRouter) { ignoreFile(); return; } %>
+import { useState } from 'react'
+import { createFileRoute } from '@tanstack/react-router'
+import { createServerFn } from '@tanstack/react-start'
+import { env } from '../../env'
+​
+const getDatabaseConfig = createServerFn({ method: 'GET' }).handler(() => {
+ // Read the server-only key here. Return a fixed example so the deployed
+ // database endpoint is not sent to the browser.
+ if (!env.DATABASE_URL) {
+ throw new Error('DATABASE_URL is not set')
+ }
+​
+ return { host: 'localhost:5432', protocol: 'postgresql:' }
+})
+​
+export const Route = createFileRoute('/demo/arkenv')({