diff --git a/package.json b/package.json index be3b7f3f4..38d01b5ac 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.12.0", - "tailwind-merge": "^2.1.0" + "tailwind-merge": "^2.1.0", + "zod": "^3.22.4" }, "devDependencies": { "@commitlint/cli": "^16.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2630069d4..1018744cb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ dependencies: tailwind-merge: specifier: ^2.1.0 version: 2.2.1 + zod: + specifier: ^3.22.4 + version: 3.22.4 devDependencies: '@commitlint/cli': @@ -7890,3 +7893,7 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} dev: true + + /zod@3.22.4: + resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} + dev: false diff --git a/src/app/page.tsx b/src/app/page.tsx index 46c05602d..cf0ed16e8 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,6 +2,7 @@ import Head from 'next/head'; import * as React from 'react'; +import '@/lib/env'; import ArrowLink from '@/components/links/ArrowLink'; import ButtonLink from '@/components/links/ButtonLink'; diff --git a/src/lib/env.ts b/src/lib/env.ts new file mode 100644 index 000000000..9f1a3e3f4 --- /dev/null +++ b/src/lib/env.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/no-namespace */ +/** + * Configuration for type-safe environment variables. + * Imported through src/app/page.tsx + * @see https://x.com/mattpocockuk/status/1760991147793449396 + */ +import { z } from 'zod'; + +const envVariables = z.object({ + NEXT_PUBLIC_SHOW_LOGGER: z.enum(['true', 'false']).optional(), +}); + +envVariables.parse(process.env); + +declare global { + namespace NodeJS { + // eslint-disable-next-line @typescript-eslint/no-empty-interface + interface ProcessEnv extends z.infer {} + } +}