Julien-R44 / vite-plugin-validate-env

✅ Vite plugin for validating your environment variables
MIT License
164 stars 6 forks source link

Fixed issue with optional schemas #9

Closed meinlebenswerk closed 1 year ago

meinlebenswerk commented 1 year ago

When a Schema, either built-in or via zod has an optional variable, which results in the validation result being undefined, the corresponding env-variable is set to 'undefined', because of the implicit string conversion via process.env. This however does not match the types generated for the import.meta.env and is, at least imo, not what I'd expect to happen.

This PR fixes that issue, by unsetting any env-variable, which is undefined after validation and adds tests for this case. I adapted the test-files slightly to fix any eslint/prettier warnings as well, but we can roll this back again :)

Julien-R44 commented 1 year ago

Thanks dude !