Skip to content

Commit 15eaba9

Browse files
committed
lib: use emitWarning instead of printDeprecationMessage
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]>
1 parent bf91035 commit 15eaba9

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

lib/_linklist.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const msg = require('internal/util').printDeprecationMessage;
4-
53
module.exports = require('internal/linkedlist');
6-
msg('_linklist module is deprecated. Please use a userland alternative.');
4+
process.emitWarning(
5+
'_linklist module is deprecated. Please use a userland alternative.',
6+
'DeprecationWarning');

lib/internal/util.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ exports._deprecate = function(fn, msg) {
6363

6464
var warned = false;
6565
function deprecated() {
66-
warned = exports.printDeprecationMessage(msg, warned, deprecated);
66+
if (!warned) {
67+
warned = true;
68+
process.emitWarning(msg, 'DeprecationWarning', deprecated);
69+
}
6770
if (new.target) {
6871
return Reflect.construct(fn, arguments, new.target);
6972
}

lib/module.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,14 @@ Module._findPath = function(request, paths, isMain) {
196196
if (filename) {
197197
// Warn once if '.' resolved outside the module dir
198198
if (request === '.' && i > 0) {
199-
warned = internalUtil.printDeprecationMessage(
200-
'warning: require(\'.\') resolved outside the package ' +
201-
'directory. This functionality is deprecated and will be removed ' +
202-
'soon.', warned);
199+
if (!warned) {
200+
warned = true;
201+
process.emitWarning(
202+
'warning: require(\'.\') resolved outside the package ' +
203+
'directory. This functionality is deprecated and will be removed ' +
204+
'soon.',
205+
'DeprecationWarning');
206+
}
203207
}
204208

205209
Module._pathCache[cacheKey] = filename;

lib/sys.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
22

3-
const util = require('internal/util');
4-
53
// the sys module was renamed to 'util'.
64
// this shim remains to keep old programs working.
75
// sys is deprecated and shouldn't be used
86

97
module.exports = require('util');
10-
util.printDeprecationMessage('sys is deprecated. Use util instead.');
8+
process.emitWarning('sys is deprecated. Use util instead.',
9+
'DeprecationWarning');

0 commit comments

Comments
 (0)