From 70fc7deef2840a1666b0d35b2ba36aa3b30c1382 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 8aa25ee70d07b5..f38e225ef7c593 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -855,8 +855,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); }