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

synchronous loadConfig #146

Closed
DetachHead opened this issue Apr 26, 2021 · 7 comments
Closed

synchronous loadConfig #146

DetachHead opened this issue Apr 26, 2021 · 7 comments

Comments

@DetachHead
Copy link

DetachHead commented Apr 26, 2021

it would be great if you could load the config without requiring an IIFE and a call to the loadConfig function at runtime.

something like node -r app-config/register for example.

@joelgallant
Copy link
Contributor

Thanks for the feedback!

I believe that this would be something solved by https://v8.dev/features/top-level-await This is available in Node 14+, when using a "type": "module" package.

Unfortunately, this isn't possible to do with a --require because loadConfig is async, at least as far as I know. (it would lead to race conditions otherwise)

@joelgallant
Copy link
Contributor

Further - our v1 actually had loadConfigSync. We had to move away from supporting this use case in order to support things like built-in encryption, and arbitrary parsing extensions.

@joelgallant
Copy link
Contributor

@DetachHead does this solve your use case?

@DetachHead
Copy link
Author

i tried updating our project to esmodules, but wasn't able to get it working with jest. seems their support for esmodules is experimental and it wouldn't work no matter what i tried.

@joelgallant
Copy link
Contributor

Hm, yeah the Node ecosystem will still take a while to get there 100%.

Is https://app-config.dev/guide/testing/jest.html enough? It might require duplication unfortunately, but it's the best way I know of at the moment.

@DetachHead
Copy link
Author

Yeah mocking it worked for our use case, though as mentioned in #100 that's not really ideal

@joelgallant
Copy link
Contributor

Okay, thanks for the feedback! I agree with the conclusion there, wanted to make sure there wasn't an issue I could help with more quickly.

Moved this feature request to #152

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