lib: deep-copy process.config during configure #2368
Merged
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 test
passesDescription of change
In
lib/configure.js
, when creating the localconfig
object 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.config
or 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-gyp
v8.0.0 during theconfig
orrebuild
commands.With the
--trace-deprecation
flag:In Node v16, the
process.config
object 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.cflags
array, we are also modifyingprocess.config.target_defaults.cflags
.See the discussion at the bottom of #2322 for more details.