diff options
Diffstat (limited to 'lib/internal/util.js')
-rw-r--r-- | lib/internal/util.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js index 8019260e0c..a31f22e6e9 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -1,6 +1,20 @@ 'use strict'; +const prefix = '(node) '; + +// All the internal deprecations have to use this function only, as this will +// prepend the prefix to the actual message. +exports.deprecate = function(fn, msg) { + return exports._deprecate(fn, `${prefix}${msg}`); +}; + +// All the internal deprecations have to use this function only, as this will +// prepend the prefix to the actual message. exports.printDeprecationMessage = function(msg, warned) { + return exports._printDeprecationMessage(`${prefix}${msg}`, warned); +}; + +exports._printDeprecationMessage = function(msg, warned) { if (process.noDeprecation) return true; @@ -10,7 +24,7 @@ exports.printDeprecationMessage = function(msg, warned) { if (process.throwDeprecation) throw new Error(msg); else if (process.traceDeprecation) - console.trace(msg); + console.trace(msg.startsWith(prefix) ? msg.replace(prefix, '') : msg); else console.error(msg); @@ -20,11 +34,11 @@ exports.printDeprecationMessage = function(msg, warned) { // Mark that a method should not be used. // Returns a modified function which warns once by default. // If --no-deprecation is set, then it is a no-op. -exports.deprecate = function(fn, msg) { +exports._deprecate = function(fn, msg) { // Allow for deprecating things in the process of starting up. if (global.process === undefined) { return function() { - return exports.deprecate(fn, msg).apply(this, arguments); + return exports._deprecate(fn, msg).apply(this, arguments); }; } @@ -34,7 +48,7 @@ exports.deprecate = function(fn, msg) { var warned = false; function deprecated() { - warned = exports.printDeprecationMessage(msg, warned); + warned = exports._printDeprecationMessage(msg, warned); return fn.apply(this, arguments); } |