From 9fabb3199d532e47e95f8ef868727ab6961b8fff Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 26 Feb 2024 03:55:07 +0100 Subject: [PATCH] lib: do not access process.noDeprecation at build time Delay access at run time otherwise the value is captured at build time and always false. PR-URL: https://github.com/nodejs/node/pull/51447 Reviewed-By: Jithil P Ponnan Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Chengzhong Wu --- lib/internal/fs/utils.js | 6 +++++- lib/internal/util.js | 9 ++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index a012ad0a75338e..087d27f2db7bb9 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -907,8 +907,12 @@ const validateRmOptionsSync = hideStackFrames((path, options, expectDir) => { return options; }); -let recursiveRmdirWarned = process.noDeprecation; +let recursiveRmdirWarned; function emitRecursiveRmdirWarning() { + if (recursiveRmdirWarned === undefined) { + // TODO(joyeecheung): use getOptionValue('--no-deprecation') instead. + recursiveRmdirWarned = process.noDeprecation; + } if (!recursiveRmdirWarned) { process.emitWarning( 'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' + diff --git a/lib/internal/util.js b/lib/internal/util.js index b32c0e8472b320..603f8164a14405 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -142,10 +142,6 @@ function pendingDeprecate(fn, msg, code) { // Returns a modified function which warns once by default. // If --no-deprecation is set, then it is a no-op. function deprecate(fn, msg, code, useEmitSync) { - if (process.noDeprecation === true) { - return fn; - } - // Lazy-load to avoid a circular dependency. if (validateString === undefined) ({ validateString } = require('internal/validators')); @@ -158,7 +154,10 @@ function deprecate(fn, msg, code, useEmitSync) { ); function deprecated(...args) { - emitDeprecationWarning(); + // TODO(joyeecheung): use getOptionValue('--no-deprecation') instead. + if (!process.noDeprecation) { + emitDeprecationWarning(); + } if (new.target) { return ReflectConstruct(fn, args, new.target); }