Skip to content

Commit

Permalink
lib: do not access process.noDeprecation at build time
Browse files Browse the repository at this point in the history
Delay access at run time otherwise the value is captured at build
time and always false.

PR-URL: #51447
Reviewed-By: Jithil P Ponnan <jithil@outlook.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
joyeecheung authored and pull[bot] committed Mar 7, 2024
1 parent 7218685 commit 5197b1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) ' +
Expand Down
9 changes: 4 additions & 5 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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);
}
Expand Down

0 comments on commit 5197b1a

Please sign in to comment.