-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Allow async config file exports #9
Conversation
This allows config files to be CommonJS files that pull in connection details from ESM files using dynamic imports
Codecov Report
@@ Coverage Diff @@
## master #9 +/- ##
==========================================
- Coverage 48.07% 45.94% -2.14%
==========================================
Files 2 2
Lines 104 111 +7
==========================================
+ Hits 50 51 +1
- Misses 54 60 +6
Continue to review full report at Codecov.
|
I think I'm good with this. Just to make sure we're on the same page, can you share a demo config file that'd use this? |
Accident? 🤔 |
oh shit, yeah, apparently I accidentally wiped this out while going push-crazy on the command-line |
Here's a config file I'm imagining: module.exports = import('./environment.mjs').then(({ db_user, db_password }) => ({
host: 'localhost',
database: 'my_sweet_app',
user: db_user,
pass: db_password
})) I tested this change locally by just using module.exports = Promise.resolve({
host: 'localhost',
database: 'my_sweet_app',
user: 'testuser',
pass: 'somepass'
}) |
I don't really know why but those examples give me the heebie jeebies haha. It feels a bit off to do |
hah, yeah, I can understand that. Taste could easily drive you to module.exports = async () => {
const { db_user, db_password } = await import('./environment.mjs')
return {
host: 'localhost',
database: 'my_sweet_app',
user: db_user,
pass: db_password
}
} I put the |
This would allow config files to be CommonJS files that pull in connection details from ESM files using dynamic imports.
Alternately,
util.local
could be changed to be async, and use dynamic imports if the file extension is.mjs
or something, but forcing config files to be CJS while allowing asynchrony seemed less problematic.