Skip to content

Commit 9790077

Browse files
committed
util: add internal function _deprecationWarning()
1 parent d29be0d commit 9790077

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

lib/os.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ exports.platform = function() {
3737
return process.platform;
3838
};
3939

40-
var warnNetworkInterfaces = true;
4140
exports.getNetworkInterfaces = function() {
42-
if (warnNetworkInterfaces) {
43-
console.error("os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()");
44-
console.trace();
45-
warnNetworkInterfaces = false;
46-
}
41+
require('util')._deprecationWarning('os',
42+
'os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()');
4743
return exports.networkInterfaces();
4844
};

lib/sys.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,8 @@
2121

2222
var util = require('util');
2323

24-
var sysWarning;
25-
if (!sysWarning) {
26-
sysWarning = 'The "sys" module is now called "util". ' +
27-
'It should have a similar interface.';
28-
if (process.env.NODE_DEBUG && process.env.NODE_DEBUG.indexOf('sys') != -1)
29-
console.trace(sysWarning);
30-
else
31-
console.error(sysWarning);
32-
}
24+
util._deprecationWarning('sys',
25+
'The "sys" module is now called "util". It should have a similar interface.');
3326

3427
exports.print = util.print;
3528
exports.puts = util.puts;

lib/util.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,19 @@ exports.inherits = function(ctor, superCtor) {
518518
}
519519
});
520520
};
521+
522+
var deprecationWarnings;
523+
524+
exports._deprecationWarning = function(moduleId, message) {
525+
if (!deprecationWarnings)
526+
deprecationWarnings = {};
527+
else if (message in deprecationWarnings)
528+
return;
529+
530+
deprecationWarnings[message] = true;
531+
532+
if ((new RegExp('\\b' + moduleId + '\\b')).test(process.env.NODE_DEBUG))
533+
console.trace(message);
534+
else
535+
console.error(message);
536+
};

0 commit comments

Comments
 (0)