lib: deep-copy process.config during configure#2368
Merged
gengjiawen merged 2 commits intonodejs:masterfrom May 29, 2021
Merged
lib: deep-copy process.config during configure#2368gengjiawen merged 2 commits intonodejs:masterfrom
gengjiawen merged 2 commits intonodejs:masterfrom
Conversation
Makes it entirely sure that we won't modify the original process.config. (Modifying process.config or its children is deprecated as of Node 16.)
richardlau
approved these changes
Apr 11, 2021
Avoids errors in JSON.parse if process.config has been deleted
imatlopez
approved these changes
Apr 11, 2021
gengjiawen
approved these changes
May 29, 2021
Contributor
Author
|
Hi again, thanks for merging. I just wanted to mention: Apparently I don't think people should be putting either of those things in their So, for dealing with this unlikely/bizarre case, we could consider handling the error somehow or using a purpose-built library for deep-copying objects. I don't really think that's worth it, but I thought I would raise the issue. (I forgot to mention it earlier.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
npm install && npm testpassesDescription of change
In
lib/configure.js, when creating the localconfigobject as a copy ofprocess.config, useJSON.parse(JSON.stringify(process.config)rather thanObject.assign({}, process.config).Makes it so we won't modify properties of child objects of the original
process.config. (Modifyingprocess.configor its children is deprecated as of Node 16.)Background
Testing with the latest Node v16 nightly build revealed that the deprecation warning from nodejs/node#36902 was still showing with the latest
node-gypv8.0.0 during theconfigorrebuildcommands.With the
--trace-deprecationflag:In Node v16, the
process.configobject has a proxy function which warns once if it, or any of its properties, or any of its child objects' properties, are modified. And it turns out thatObject.assign()does not deep copy any nested objects of the object you assign from. Nested objects are copied by reference rather than by value. So by modifying (for example) our localconfig.defaults.cflagsarray, we are also modifyingprocess.config.target_defaults.cflags.See the discussion at the bottom of #2322 for more details.