Rework raw.js to function like the new defer mechanism.#879
Rework raw.js to function like the new defer mechanism.#879jdmarshall wants to merge 2 commits intonode-config:masterfrom
Conversation
📝 WalkthroughWalkthroughAdds a public RawConfig class in Changes
Sequence Diagram(s)sequenceDiagram
participant Loader as Load
participant Util as Util
participant Raw as RawConfig
participant ConfigFn as Config File (function)
Loader->>ConfigFn: invoke({ defer, util: Util, raw: Raw.raw })
ConfigFn->>Raw: (optional) call Raw.raw(...)
ConfigFn-->>Loader: return config object
Loader->>Util: merge/clone config (RawConfig treated as pass-through)
Loader-->>Caller: final config
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@lib/util.js`:
- Around line 1020-1023: Fix the JSDoc typo: change the annotation `@type
defebootstrapCallback` to the correct `@type {bootstrapCallback}` so the
documented type matches the actual callback definition; update the comment
immediately above where `let fn = configObject;` is declared (referencing
symbols `configObject`, `fn`) and ensure the typedef name `bootstrapCallback`
matches the callback used earlier in the file (lines that reference `Util` and
`RawConfig.raw`).
In `@raw.js`:
- Around line 1-6: lib/config.js currently imports RawConfig indirectly via
raw.js (which calls Util.errorOnce and delegates to RawConfig.raw), creating a
dependency on a deprecated module; change the require in lib/config.js to import
RawConfig directly from lib/util (the module that defines and exports RawConfig)
and update any references to RawConfig there to use the directly imported symbol
so behavior is unchanged but the deprecated internal dependency is removed.
🧹 Nitpick comments (2)
lib/util.js (2)
453-454: Consider an earlyreturnforRawConfigincloneDeep, similar to theBufferbranch.Currently
child = parentfalls through to the circular-reference tracking and thefor…inproperty loop. SinceRawConfighas no enumerable own properties, the loop is a no-op, but an early return would make the intent clearer and avoid unnecessary work.Proposed fix
} else if (parent instanceof RawConfig) { - child = parent; + return parent; } else {
23-24:rawproperty is missing its type in the@paramJSDoc.The
contextobject documents types forutilanddeferbut omits the type forraw. For consistency and IDE support, consider adding it.Proposed fix
- * `@param` context { util: Util, defer: deferConfig, raw } - utility functions for startup + * `@param` context {{ util: Util, defer: deferConfig, raw: RawConfig.raw }} - utility functions for startup
Deprecatng the old mechanism, as it blocks ESM migration. addresses node-config#878
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/util.js (1)
640-659:⚠️ Potential issue | 🔴 CriticalBreaking the
if/elsechain causes double-processing ofDate(and other) values.The
ifon line 644 is no longer chained as anelse ifto theDatecheck on line 640. This means whenmergeFrom[prop]is aDate:
- Line 641 assigns it correctly.
- Execution falls through to line 644's
if, which doesn't match.- The
else ifon line 647 sees both sides as objects (typeof Date === 'object') and callsextendDeepon the Date, corrupting it.Re-attach the chain with
else if:🐛 Proposed fix
if (mergeFrom[prop] instanceof Date) { mergeInto[prop] = mergeFrom[prop]; - } - - if ((mergeFrom[prop] instanceof RegExp) || + } else if ((mergeFrom[prop] instanceof RegExp) || (mergeFrom[prop] instanceof RawConfig)) {
🧹 Nitpick comments (1)
lib/util.js (1)
16-26: Minor JSDoc formatting for@callbackparameter.The
@paramon line 24 uses informal syntax. Consider proper JSDoc:- * `@param` context { util: Util, defer: deferConfig, raw } - utility functions for startup + * `@param` {Object} context - utility functions for startup + * `@param` {typeof Util} context.util - Util class + * `@param` {typeof deferConfig} context.defer - deferred config factory + * `@param` {typeof RawConfig.raw} context.raw - raw config factory
This should be the last part of the config API that blocks ESM usage.
addresses #878
Summary by CodeRabbit
New Features
Deprecations