Skip to content
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

Load envalid declarations from directories/files #52

Closed
SimenB opened this issue Aug 23, 2017 · 3 comments
Closed

Load envalid declarations from directories/files #52

SimenB opened this issue Aug 23, 2017 · 3 comments

Comments

@SimenB
Copy link
Collaborator

SimenB commented Aug 23, 2017

The way we have our envalid declarations set up at work is to put them by category in different files in a directory, then load the whole directory, merging all declarations, then passing the result through cleanEnv and making it immutable.

After #44 we can drop our immutable proxy wrapper, but we still need our own code to load all en variables. What do you think about adding that capability directly to envalid?

Example:

../frontpage/server/config
├── assets.js
├── cdn.js
├── messages.js
├── nunjucks.js
├── security.js
├── services.js
├── tracking.js
└── trackjs.js

0 directories, 8 files

Each file is e.g security.js

'use strict';

const { bool } = require('envalid');

module.exports = {
    SECURE_COOKIES: bool({
        desc: 'Enable to set `Secure` flag on all cookies',
        default: true,
        devDefault: false,
    }),
};

You can provide multiple directories, or single files of these, and they are merged.
handling of dupes are undefined (in practice last one wins, but you should avoid overlap). That can be defined, though, if you want that.

@af
Copy link
Owner

af commented Aug 23, 2017

That looks like a nice way of organizing your env config. At work we still have things in a single file and it's getting a bit unwieldy. I'm in favor of adding this as long as it's not adding a ton of complexity, and that the fs calls can be worked around for those using envalid from RN.

@SimenB
Copy link
Collaborator Author

SimenB commented Aug 28, 2017

We can probably use the same workaround as jest does in order to fool the compiler.

jestjs/jest#4376

Ref #31 & #38

@af
Copy link
Owner

af commented Dec 2, 2017

I'm going to close this as it's not a near-term priority. Definitely happy to review a PR for this if one comes along though!

@af af closed this as completed Dec 2, 2017
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

No branches or pull requests

2 participants