Support callbacks in config JS/TS/ files to avoid the need for require() in config files#863
Support callbacks in config JS/TS/ files to avoid the need for require() in config files#863jdmarshall wants to merge 7 commits intonode-config:masterfrom
Conversation
…fig() This should answer node-config#740 and also opens the door for migrating to ESM modules. This does not at present address the issue of async.
And move some integration tests to unit tests. Prep work for adding async support to defer()
This is prep work for fixing node-config#740
📝 WalkthroughWalkthroughReplaces in-file defer implementation with a new Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant Loader as Config Loader
participant ConfigFn as Config Function
participant Util as Util
participant Defer as lib/defer
App->>Loader: require/load config file
Loader->>ConfigFn: invoke with ({defer: Defer.deferConfig, util: Util})
ConfigFn->>Defer: create deferred values (deferConfig)
ConfigFn-->>Loader: return config object (may contain DeferredConfig or Promises)
Loader->>Util: Util.resolveAsyncConfigs(config)
Util->>Util: traverse config, collect Promises/Deferreds
Util->>Defer: prepare/resolve deferreds (resolve may return Promises)
Util->>Util: Promise.all on collected promises
Util-->>App: finalized, resolved config object
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)lib/defer.js (1)
🔇 Additional comments (3)
✏️ Tip: You can disable this entire section by setting Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4fd312d to
e6478c4
Compare
This will probably be better overall for anyone doing an incremental migration since the new code will run last.
|
This feature is critical to breaking the chicken and egg problems with the config singleton and moving this module to ESM. I have a PR almost ready to go for ESM migration that requires this PR to land. I’d appreciate a timely review while I still have momentum. Because it deprecates several features, I'd like this to be in 4.3 so that people have plenty of time to adapt before I remove those deprecations in 5.0, which will absolutely be necessary in order to get import to work. You cannot import from modules that are currently being imported, and that is exactly what async.js and defer.js are doing. Using the callback mechanism means we are exposing the parts of node-config that are stateless or have private state, and thus have already finished importing by the time deferment is resolved. |
This fixes #740 and provides a solution for a number of issues preventing ESM migration.
Summary by CodeRabbit
New Features
Documentation
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.