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.
  • Loading branch information
joyeecheung committed Jan 13, 2024
1 parent c25878d commit 108f05b
Show file tree
Hide file tree
Showing 2 changed files with 10 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 @@ -902,8 +902,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
10 changes: 5 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 Expand Up @@ -881,6 +880,7 @@ module.exports = {
filterOwnProperties,
getConstructorOf,
getCWDURL,
getDeprecationWarningEmitter,
getInternalGlobal,
getSystemErrorMap,
getSystemErrorName,
Expand Down

0 comments on commit 108f05b

Please sign in to comment.