Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
util: add internal function _deprecationWarning()
  • Loading branch information
bnoordhuis committed Dec 14, 2011
1 parent d29be0d commit 9790077
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 2 additions & 6 deletions lib/os.js
Expand Up @@ -37,12 +37,8 @@ exports.platform = function() {
return process.platform;
};

var warnNetworkInterfaces = true;
exports.getNetworkInterfaces = function() {
if (warnNetworkInterfaces) {
console.error("os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()");
console.trace();
warnNetworkInterfaces = false;
}
require('util')._deprecationWarning('os',
'os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()');
return exports.networkInterfaces();
};
11 changes: 2 additions & 9 deletions lib/sys.js
Expand Up @@ -21,15 +21,8 @@

var util = require('util');

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

exports.print = util.print;
exports.puts = util.puts;
Expand Down
16 changes: 16 additions & 0 deletions lib/util.js
Expand Up @@ -518,3 +518,19 @@ exports.inherits = function(ctor, superCtor) {
}
});
};

var deprecationWarnings;

exports._deprecationWarning = function(moduleId, message) {
if (!deprecationWarnings)
deprecationWarnings = {};
else if (message in deprecationWarnings)
return;

deprecationWarnings[message] = true;

if ((new RegExp('\\b' + moduleId + '\\b')).test(process.env.NODE_DEBUG))
console.trace(message);
else
console.error(message);
};

0 comments on commit 9790077

Please sign in to comment.