From 672a3af4dd179124aff5d71613c2152753dd6aa1 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 12 Jan 2021 15:38:00 -0800 Subject: [PATCH 1/3] process: runtime deprecate changing process.config The fact that `process.config` is mutable has long made it unreliable when it really should just work. Start the process of deprecating the ability to change it. Fixes: https://github.com/nodejs/node/issues/7803 Signed-off-by: James M Snell --- doc/api/deprecations.md | 11 +++++++++++ lib/internal/bootstrap/node.js | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 6aaf1c9fd394d0..be5e57f2260d6f 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2712,6 +2712,17 @@ Type: Documentation-only. Prefer [`message.socket`][] over [`message.connection`][]. + +### DEP0XXX: Changing the value of `process.config` + + +The `process.config` property is intended to provide access to configuration +settings set when the Node.js binary was compiled. However, the property has +been mutable by user code making it impossible to rely on. The ability to +change the value has been deprecated and will be disabled in the future. + [Legacy URL API]: url.md#url_legacy_url_api [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 8077c462983154..a4d1c66b55130a 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -59,7 +59,23 @@ process._exiting = false; // process.config is serialized config.gypi const nativeModule = internalBinding('native_module'); -process.config = JSONParse(nativeModule.config); + +// TODO(@jasnell): Once this has gone through one full major +// release cycle, remove the setter and update the getter to +// either return a read-only object or always return a freshly +// parsed version of nativeModule.config. +let processConfig = JSONParse(nativeModule.config); +ObjectDefineProperty(process, 'config', { + enumerable: true, + configurable: true, + get() { return processConfig; }, + set: deprecate( + (value) => { processConfig = value; }, + 'Setting process.config is deprecated. ' + + 'In the future the property will be read-only.', + 'DEP0XXX') +}); + require('internal/worker/js_transferable').setup(); // Bootstrappers for all threads, including worker threads and main thread From 80bf075a38660c89bf500dd32be22e95d5412379 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 13 Jan 2021 15:23:44 -0800 Subject: [PATCH 2/3] fixup! process: runtime deprecate changing process.config --- doc/api/process.md | 8 ++++ lib/internal/bootstrap/node.js | 72 +++++++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 5b6e4c5e99fead..dfa6a8eab0f4f2 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -759,6 +759,10 @@ This feature is not available in [`Worker`][] threads. ## `process.config` * {Object} @@ -803,6 +807,10 @@ The `process.config` property is **not** read-only and there are existing modules in the ecosystem that are known to extend, modify, or entirely replace the value of `process.config`. +Modifying the `process.config` property, or any child-property of the +`process.config` object has been deprecated. The `process.config` will be made +read-only in a future release. + ## `process.connected` +Type: Runtime + The `process.config` property is intended to provide access to configuration settings set when the Node.js binary was compiled. However, the property has been mutable by user code making it impossible to rely on. The ability to