Prevent extension when calling makeImmutable(), and add pinning tests#866
Prevent extension when calling makeImmutable(), and add pinning tests#866jdmarshall wants to merge 1 commit intonode-config:masterfrom
Conversation
📝 WalkthroughWalkthroughReplaces the first-get mutability flag with a runtime Changes
Sequence Diagram(s)(Skipped — changes are internal control-flow and immutability behavior, not multi-component interaction flows.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
2d35760 to
e14f228
Compare
e14f228 to
d3719cf
Compare
|
This change may have some performance implications. Running some benchmarks to check. Follow-up: Only inside Webstorm. Not reproducible from the command line. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@lib/config.js`:
- Around line 352-356: Update the JSDoc to reflect that when makeImmutable is
called with no property list (i.e., partial is falsy) the target object is made
non‑extensible via Object.preventExtensions(object), so new properties cannot be
added; locate the documentation near the makeImmutable/partial logic and change
the comment that currently says new properties can be added to state the
opposite: in full mode the object is non‑extensible and new properties are
prohibited (mention Object.preventExtensions and the partial flag).
d3719cf to
bd1103e
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/config.js (1)
207-223: setModuleDefaults with new modules after get() will fail with immutability enabled.Calling
setModuleDefaultswith a new module name after the firstget()call (whenALLOW_CONFIG_MUTATIONSis false by default) will throw an error. TheUtil.setPathcall at line 216 attempts to create intermediate objects by assigning to a proxy-wrapped immutable config, triggering the proxy's set trap which rejects adding new properties. This is a breaking change from prior behavior where mutability could be reset.
♻️ Duplicate comments (1)
lib/config.js (1)
231-232: JSDoc partially updated but still incomplete.The doc update here is accurate. However, as previously noted, the JSDoc further down (around lines 233-235 per the past review) still states that new properties can be added, which contradicts the new
Object.preventExtensionsbehavior in full mode. Please address the outstanding comment to complete the documentation alignment.
🧹 Nitpick comments (1)
lib/config.js (1)
269-276: Logic for partial mode is correct.The
partialflag cleanly differentiates between freezing specific properties (array provided) versus full immutability (no array). This preserves backward compatibility while enabling the new non-extensible behavior for the default case.Minor style nit: Line 270 has the comment attached without a space after
null;.🔧 Optional formatting fix
- let properties = null;// Get the list of properties to work with + let properties = null; // Get the list of properties to work with
…rack state. Fix for both bugs in node-config#865
bd1103e to
6e6fff9
Compare
That's documented as unsupported. Where do you see the opposite mentioned in the docs?
Now you're hallucinating. 233-235 has always been an empty paragraph. Unless there's some whitespace morse code I'm not seeing... |
|
I'm going to split this in two. |
Ask JavaScript if the object is mutable instead of trying to track state
Fix for both bugs in #865, and makes #864 more agreeable to honoring the immutability contract.
Note while this PR is marked as a breaking change, absolutely none of our existing tests failed with this change,
meaning we have documented behavior that we do not test for.
Looking into the commit history, the contrary comment in the JSDoc dates to a time when this function was about
eight lines long and had none of the other many, many additions to enforce immutability. I propose that this is not actually a useful feature anymore. But I will mark this as 4.4 which will have several other breaking changes, to leave 4.3 more or less in peace.
Summary by CodeRabbit
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.