Skip to content

Commit

Permalink
lib: use emitWarning instead of printDeprecationMessage
Browse files Browse the repository at this point in the history
The process.emitWarning() API should be used for printing
deprecation warning messages rather than directly using the
internal/util#printDeprecationMessage

PR-URL: #8166
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
  • Loading branch information
jasnell committed Sep 2, 2016
1 parent bf91035 commit 15eaba9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/_linklist.js
Original file line number Diff line number Diff line change
@@ -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');
5 changes: 4 additions & 1 deletion lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions lib/sys.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 15eaba9

Please sign in to comment.