alexmarqs / zod-config

Load configuration variables from multiple sources with flexible adapters, ensuring type safety with Zod.
https://www.npmjs.com/package/zod-config
MIT License
34 stars 7 forks source link

Script Adapter: Support importing TypeScript using a TypeScript loader (optionally) #10

Open Lordfirespeed opened 1 month ago

Lordfirespeed commented 1 month ago

Hello, me again! Hope you're well.

Thinking of doing something like postcss-load-config whereby tsx and jiti are optional peer dependencies used to import TypeScript files from a JavaScript context.

In transpiled projects, this would have the benefit that changes to script config files would not require the project to be 'built (transpiled) for changes to the config to be reflected.

let me know what you think! I'll start working on the code for it either way, since I can just define the adapter in my project if you'd rather not bloat the library :)

alexmarqs commented 1 month ago

Hey @Lordfirespeed thanks for this! Any news regarding the usage of your own adapter? Just to understand if your PR is still valid 👍 or new findings or needs from your side. Cheers!

Lordfirespeed commented 1 month ago

It works great! I ran into one issue with it when trying to load config in a next.js application - namely, ran into some error r.e. webpack trying to bundle esbuild, etc. but that's a separate issue.

As long as I specify the config directory to my dev server 'watch' option, my server auto reloads as I would usually expect.

And I don't have to recompile the project for configuration changes to be reflected in the built project.

Overall - success :)

alexmarqs commented 1 month ago

thanks @Lordfirespeed ! I will then clone + double check your PR ;), cheers!

Lordfirespeed commented 1 month ago

I will then clone + double check your PR ;), cheers!

No worries! Keep #12 in mind - I am worried something I did may have broken the TypeScript types' compatibility with some versions of zod ...