-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add edge runtime compatibility and allow custom formatters #15
base: master
Are you sure you want to change the base?
Conversation
Nice one! Will definitely try |
Just one question-why was this not merged yet? |
Because I work on this project unpaid as volunteer :) I don't currently use any edge runtimes and didn't have the time to investigate how well this solution works, so I was relying on feedback from those who raised issues and requested a solution. I didn't receive any, so the pull request has been sitting here. If you're willing to try the |
Thanks, this works for me. |
Resolves #2, supersedes #9 and #11.
This PR adds support for non-Node runtimes via a new entrypoint,
znv/compat
. To accomplish this, I've added the ability to pass a custom reporter toparseEnv
, or more granular token formatters.The default entrypoint,
znv
, now exports a version ofparseEnv
that defaults to colorized tokens, which matches the current behaviour. This relies on Node'stty
module.The new
znv/compat
entrypoint exports a version ofparseEnv
that doesn't colorize any tokens; nothing in this codepath importstty
or any other Node module, so it should be compatible with serverless environments (and even browsers, if you somehow need environment parsing there).Additionally, I've removed the dependency on the
colorette
module and have instead added a simplified version of it for our own use.One small thing I'm unsure about is that I had to change the signature of the "internal"
parseEnv
:but the exported
parseEnv
that wraps the aboveparseEnvImpl
retainsRestrictSchemas<T>
, so everything should work the same:All this feels a little clunky, but I couldn't think of any other way to do this that doesn't add a bunch of other complexity. Alternate suggestions welcome!
Please take a look if you're one of the people who requested serverless support for
znv
! I've published it to npm under thenext
tag, so you can usenpm i znv@next
to try it out.