Skip to content

feat: type-safe env via @t3-oss/env-core + zod#139

Open
azizbecha wants to merge 4 commits intoBearStudio:mainfrom
azizbecha:feat/typesafe-env
Open

feat: type-safe env via @t3-oss/env-core + zod#139
azizbecha wants to merge 4 commits intoBearStudio:mainfrom
azizbecha:feat/typesafe-env

Conversation

@azizbecha
Copy link
Copy Markdown
Contributor

Replaced ad-hoc process.env access with a validated env module so missing or malformed vars fail fast at startup instead of producing undefined runtime values, in addition to having typed env vars instead of ghosted process.env.*.

Replace ad-hoc process.env access with a validated env module so missing
or malformed vars fail fast at startup instead of producing undefined
runtime values.
@azizbecha
Copy link
Copy Markdown
Contributor Author

cc @yoannfleurydev

Copy link
Copy Markdown
Member

@yoannfleurydev yoannfleurydev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contributions. I think we will be good to go after the suggested changes.

Comment thread package.json Outdated
@azizbecha
Copy link
Copy Markdown
Contributor Author

Done, thanks for the review!
Let me know if there are any other changes required, alongside with the other PRs opened.

@yoannfleurydev
Copy link
Copy Markdown
Member

We'll need to skip the validations for the CI I guess

image

@azizbecha
Copy link
Copy Markdown
Contributor Author

Yes! The env schema rename to EXPO_PUBLIC_BASE_URL requires updating the workflow files too, since they still export the old EXPO_PUBLIC_API_URL name. I'll push a fix renaming it across all 6 workflows, and add SKIP_ENV_VALIDATION=true to the lint/typecheck jobs so they don't need the repo variables set at all.

Separately, I think the workflows could be reorganized so each does one thing, happy to open a follow-up issue for that.

The env schema rename in 12d0497 wasn't propagated to the GitHub Actions
workflows, causing every job to fail at `pnpm install` because the
`prepare` hook runs `gen:api`, which loads `src/env.ts` and rejects an
undefined `EXPO_PUBLIC_BASE_URL`.

Also adds a public demo URL fallback in code-quality.yml so lint and
typecheck pass on forks where `vars.API_URL` isn't configured.
Comment thread src/env.ts Outdated
Derive EXPO_PUBLIC_AUTH_URL and EXPO_PUBLIC_OPENAPI_URL from
EXPO_PUBLIC_BASE_URL inside `runtimeEnv` so both vars are always
defined and validated as URLs. Consumers now read `env.EXPO_PUBLIC_*`
directly without per-call-site fallback logic.
@azizbecha
Copy link
Copy Markdown
Contributor Author

Nice catch! Fixed that in a new commit. The new code looks cleaner now.

Comment thread src/env.ts
Comment on lines +13 to +14
EXPO_PUBLIC_AUTH_URL: z.url(),
EXPO_PUBLIC_OPENAPI_URL: z.url(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be marked as optional() here, it's only required when we want to override the one based on baseUrl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants