From 15eaba98a1dac646225ba74a2abab63de4913188 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 18 Aug 2016 11:51:10 -0700 Subject: [PATCH] lib: use emitWarning instead of printDeprecationMessage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The process.emitWarning() API should be used for printing deprecation warning messages rather than directly using the internal/util#printDeprecationMessage PR-URL: https://github.com/nodejs/node/pull/8166 Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Myles Borins --- lib/_linklist.js | 6 +++--- lib/internal/util.js | 5 ++++- lib/module.js | 12 ++++++++---- lib/sys.js | 5 ++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/_linklist.js b/lib/_linklist.js index 08ecbea828b666..1b709d6fbd282e 100644 --- a/lib/_linklist.js +++ b/lib/_linklist.js @@ -1,6 +1,6 @@ 'use strict'; -const msg = require('internal/util').printDeprecationMessage; - module.exports = require('internal/linkedlist'); -msg('_linklist module is deprecated. Please use a userland alternative.'); +process.emitWarning( + '_linklist module is deprecated. Please use a userland alternative.', + 'DeprecationWarning'); diff --git a/lib/internal/util.js b/lib/internal/util.js index 7f93e1a2e021cb..dae45b0ebbd9a4 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -63,7 +63,10 @@ exports._deprecate = function(fn, msg) { var warned = false; function deprecated() { - warned = exports.printDeprecationMessage(msg, warned, deprecated); + if (!warned) { + warned = true; + process.emitWarning(msg, 'DeprecationWarning', deprecated); + } if (new.target) { return Reflect.construct(fn, arguments, new.target); } diff --git a/lib/module.js b/lib/module.js index fe9700f7a673ae..96f1cfc42e47c6 100644 --- a/lib/module.js +++ b/lib/module.js @@ -196,10 +196,14 @@ Module._findPath = function(request, paths, isMain) { if (filename) { // Warn once if '.' resolved outside the module dir if (request === '.' && i > 0) { - warned = internalUtil.printDeprecationMessage( - 'warning: require(\'.\') resolved outside the package ' + - 'directory. This functionality is deprecated and will be removed ' + - 'soon.', warned); + if (!warned) { + warned = true; + process.emitWarning( + 'warning: require(\'.\') resolved outside the package ' + + 'directory. This functionality is deprecated and will be removed ' + + 'soon.', + 'DeprecationWarning'); + } } Module._pathCache[cacheKey] = filename; diff --git a/lib/sys.js b/lib/sys.js index a34ea0b899f824..c94b032c649662 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -1,10 +1,9 @@ 'use strict'; -const util = require('internal/util'); - // the sys module was renamed to 'util'. // this shim remains to keep old programs working. // sys is deprecated and shouldn't be used module.exports = require('util'); -util.printDeprecationMessage('sys is deprecated. Use util instead.'); +process.emitWarning('sys is deprecated. Use util instead.', + 'DeprecationWarning');