Comments (16)
I'm keen to have a go at this!
from envalid.
TBH I like the changes for the most part. I'm not sure how much people use those missing features but the only things I would miss personally are:
- colorized CLI output (chalk is overkill for this anyways, but colors are nice for readability in the terminal)
- errors from the Proxy (could maybe create extension points that make this possible in "userland"?)
I'll take a closer look this weekend but I'm intrigued by the idea of this being a v7. Curious if any of those features are a "dealbreaker" for anyone.
from envalid.
But I might approach it a bit differently as I use envalid in the browser a lot. I'd like it to be:
- Strict by default
- Have no dependencies
- No useage of proxy
from envalid.
That's a separate discussion from migrating to TS - ideally a TS migration should have no logic changes
from envalid.
Yeah, you're right, I snowballed a few different discussions in there.
from envalid.
That said, would love a PR migrating to TS and an issue discussing potential changes 🙂
from envalid.
What's your opinion on using tsdx
to reduce boilerplate?
from envalid.
Up to @af, but if it helps us get up and running we can always rip it out later
from envalid.
This sounds great! I agree with SimenB that we should limit the breaking changes as part of the conversion. Ideally the conversion could happen without requiring a major version bump. Personally I agree the lib should be strict by default, but we should move that to a separate discussion.
On the dependencies side, this lib was never initially intended for browser usage, so it's not optimized for that case dependency-wise. According to bundlephobia something like 50% of the bundle size comes from the chalk
dependency, which could easily be replaced by creating a couple small helper functions to add the ANSI color codes.
from envalid.
Hey again! So, it was easier for me to start from scratch and add things gradually than to get it working here so it resulted in a new repo as you can see here: https://github.com/KATT/envsafe
Which then also led me to change some things to how I'd like it 😬 ... overall it's very similar but kinda slimmed down the API-surface, it's all in TypeScript and no third party deps added (yet).
What I'm "missing" right now is:
host
-support- the
testOnly
-thing - non-strict mode & the proxy-stuff that throws error
- chalk
How do you think we should proceed? I have a feeling like the changes are too major for you to want it in as it is, so maybe we keep it as two sister projects?
from envalid.
I'm very happy to pass this back into envalid and burn that project if you like it, but I don't know if you like the changes, want to do a major version, etc.
from envalid.
Great to hear! I'd prefer to have one-package-to-rule-them-all rather than adding more fragmentation.
- I've added the proxy, but I already want to refactor it to just expose
freezeObject
so the logic is not always included in the bundle when using it in the browser - If there's a way (that doesn't take a day of configuration) of conditionally including
chalk
depending if node/browser it'd be nice. Colors are nice indeed!
Other notable changes:
- The first arg is now the options and
env
is optional in the options obj withprocess.env
as default. - Added
input
to help with environments where you can't iterate on theprocess.env
- but I'm working on a webpack plugin which could replace it and also make the build fail at compile time rather than at runtime. - I removed
process.exit(1)
and simply throw the error as it gives better error messages in CI - exit propagatesexit(1)
anyway
Removed:
host
- No built-in
dotenv
-stuff. Can justrequire('dotenv')
before callingenvsafe()
transformer
- I don't see the point. If you wanna transform the object after creating the env, just do it, I don't see why an API is needed for it.- No second arg on
makeValidator
- didn't see the point.
from envalid.
Update: I finally had some time to check this out over this last weekend. Thanks @KATT, looks great and while I think overall it's a big step forward, to reduce churn for existing users I think we should roll the changes into the existing API. My WIP isn't in a reviewable state yet, but hopefully will be in a couple of days. Wanted to get feedback on the following plan though:
Major changes I think we should incorporate:
- Rewrite in TypeScript (obviously)
- Use tsdx to simplify tooling, including migrating tests to jest (I still like
painless
but it's abandoned 😢 ) - Remove all runtime dependencies. The value they bring right now is not (IMO) worth the cost for client-side users (who are more numerous than I ever anticipated). As you mentioned,
dotenv
can just be used before passing the env object intoenvalid
. The other deps are really just providing minor conveniences, and being dependency-free would be great - Introduce the concept of "middlewares", which basically do the same thing as
transformer
does now. The proxy andisDev/isProd/etc
properties can probably be re-implemented as middlewares to make things more modular - Turn on
strict
behavior by default and remove the option. If you want to preserve existing non-strict behavior, you can turn off the proxy middleware and do something likeconst output = { ...process.env, ...cleanedEnvFromEnvalid }
However I don't want to do a full rewrite of the API; the churn would probably be too annoying for existing users. That means:
- Keep all existing validators, including
host
.host
andip
rely on an existing package currently, but a simplified version can be rolled into envalid. If a user wants more exhaustive checking, they can use a custom validator to recreate the v6 behavior - Keep as much of the existing test suite as possible
- Minimize overall api changes unless they're unavoidably tied to the benefits above
from envalid.
Sounds like good plan! I'm happy to take a look at your WIP whenever.
from envalid.
@KATT Just pushed up a WIP PR, would love your feedback 👍
from envalid.
Finally done as of v7.0.0-beta.1
from envalid.
Related Issues (20)
- Help with Next.js HOT 5
- ts-expect-error problem with 7.2.1 HOT 4
- Make an optional case-insensitive flag HOT 2
- NPM package is not valid HOT 3
- Support `structuredClone` HOT 3
- How to access desc HOT 2
- Add parse options to str() HOT 1
- array validator HOT 1
- 7.3.0 breaking change? HOT 11
- Add option to load validator specs from .example.env file HOT 1
- Access value of env object by name HOT 1
- envalid in react-native for preview crashes without giving description of missing env HOT 2
- testOnly setting variable to Symbol instead of failing HOT 5
- Pick from validators HOT 2
- str({ devDefault: undefined }) generates an incorrect type HOT 2
- Require environment variables only if `NODE_ENV` is not set to `test` HOT 2
- Skipping env var validation in tests HOT 1
- Prevent process exit during tests HOT 1
- makeExactValidator is not exported HOT 1
- Combine envalid with Docker secrets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from envalid.