Skip to content

Commit

Permalink
lib: Deprecating with internal/util's deprecate
Browse files Browse the repository at this point in the history
Since internal/util's deprecate prepends `(node)` to the messages, all
the deprecations in the code base has to use it only.
  • Loading branch information
thefourtheye committed Jun 5, 2015
1 parent 660fc96 commit 6d4a717
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 36 deletions.
5 changes: 3 additions & 2 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const assert = require('assert').ok;
const Stream = require('stream');
const timers = require('timers');
const util = require('util');
const internalUtil = require('internal/util');
const common = require('_http_common');

const CRLF = common.CRLF;
Expand Down Expand Up @@ -643,6 +644,6 @@ OutgoingMessage.prototype.flushHeaders = function() {
this._send('');
};

OutgoingMessage.prototype.flush = util.deprecate(function() {
OutgoingMessage.prototype.flush = internalUtil.deprecate(function() {
this.flushHeaders();
}, 'flush is deprecated. Use flushHeaders instead.');
}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.');
7 changes: 4 additions & 3 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = Writable;
Writable.WritableState = WritableState;

const util = require('util');
const internalUtil = require('internal/util');
const Stream = require('stream');

util.inherits(Writable, Stream);
Expand Down Expand Up @@ -119,10 +120,10 @@ WritableState.prototype.getBuffer = function writableStateGetBuffer() {
};

Object.defineProperty(WritableState.prototype, 'buffer', {
get: util.deprecate(function() {
get: internalUtil.deprecate(function() {
return this.getBuffer();
}, '_writableState.buffer is deprecated. Use ' +
'_writableState.getBuffer() instead.')
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer() ' +
'instead.')
});

function Writable(options) {
Expand Down
14 changes: 7 additions & 7 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,28 +456,28 @@ Buffer.prototype.fill = function fill(val, start, end) {


// XXX remove in v0.13
Buffer.prototype.get = util.deprecate(function get(offset) {
Buffer.prototype.get = internalUtil.deprecate(function get(offset) {
offset = ~~offset;
if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range');
return this[offset];
}, '.get() is deprecated. Access using array indexes instead.');
}, 'Buffer.get() is deprecated. Access using array indexes instead.');


// XXX remove in v0.13
Buffer.prototype.set = util.deprecate(function set(offset, v) {
Buffer.prototype.set = internalUtil.deprecate(function set(offset, v) {
offset = ~~offset;
if (offset < 0 || offset >= this.length)
throw new RangeError('index out of range');
return this[offset] = v;
}, '.set() is deprecated. Set using array indexes instead.');
}, 'Buffer.set() is deprecated. Set using array indexes instead.');


// TODO(trevnorris): fix these checks to follow new standard
// write(string, offset = 0, length = buffer.length, encoding = 'utf8')
var writeWarned = false;
const writeMsg = '.write(string, encoding, offset, length) is deprecated.' +
' Use write(string[, offset[, length]][, encoding]) instead.';
const writeMsg = 'Buffer.write(string, encoding, offset, length) is deprecated.'
+ ' Use write(string[, offset[, length]][, encoding]) instead.';
Buffer.prototype.write = function(string, offset, length, encoding) {
// Buffer#write(string);
if (offset === undefined) {
Expand Down Expand Up @@ -505,7 +505,7 @@ Buffer.prototype.write = function(string, offset, length, encoding) {

// XXX legacy write(string, encoding, offset, length) - remove in v0.13
} else {
writeWarned = internalUtil.printDeprecationMessage(writeMsg, writeWarned);
writeWarned = internalUtil.deprecate(writeMsg, writeWarned);
var swap = encoding;
encoding = offset;
offset = length >>> 0;
Expand Down
5 changes: 3 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('util');
const internalUtil = require('internal/util');
const debug = util.debuglog('child_process');
const constants = require('constants');

Expand Down Expand Up @@ -268,11 +269,11 @@ exports.execFile = function(file /* args, options, callback */) {
return child;
};

var _deprecatedCustomFds = util.deprecate(function(options) {
var _deprecatedCustomFds = internalUtil.deprecate(function(options) {
options.stdio = options.customFds.map(function(fd) {
return fd === -1 ? 'pipe' : fd;
});
}, 'child_process: customFds option is deprecated, use stdio instead.');
}, 'child_process.customFds option is deprecated, use stdio instead.');

function _convertCustomFds(options) {
if (options && options.customFds && !options.stdio) {
Expand Down
14 changes: 9 additions & 5 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ try {
const constants = require('constants');
const stream = require('stream');
const util = require('util');
const internalUtil = require('internal/util');

const DH_GENERATOR = 2;

Expand Down Expand Up @@ -679,10 +680,13 @@ function filterDuplicates(names) {
}

// Legacy API
exports.__defineGetter__('createCredentials', util.deprecate(function() {
return require('tls').createSecureContext;
}, 'createCredentials() is deprecated, use tls.createSecureContext instead'));
exports.__defineGetter__('createCredentials',
internalUtil.deprecate(function() {
return require('tls').createSecureContext;
}, 'crypto.createCredentials() is deprecated, ' +
'use tls.createSecureContext instead'));

exports.__defineGetter__('Credentials', util.deprecate(function() {
exports.__defineGetter__('Credentials', internalUtil.deprecate(function() {
return require('tls').SecureContext;
}, 'Credentials is deprecated, use tls.createSecureContext instead'));
}, 'crypto.Credentials is deprecated, ' +
'use tls.createSecureContext instead'));
5 changes: 3 additions & 2 deletions lib/http.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('util');
const internalUtil = require('internal/util');
const EventEmitter = require('events').EventEmitter;


Expand Down Expand Up @@ -91,9 +92,9 @@ Client.prototype.request = function(method, path, headers) {
return c;
};

exports.Client = util.deprecate(Client,
exports.Client = internalUtil.deprecate(Client,
'http.Client will be removed soon. Do not use it.');

exports.createClient = util.deprecate(function(port, host) {
exports.createClient = internalUtil.deprecate(function(port, host) {
return new Client(port, host);
}, 'http.createClient is deprecated. Use `http.request` instead.');
3 changes: 2 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const NativeModule = require('native_module');
const util = require('util');
const internalUtil = require('internal/util');
const runInThisContext = require('vm').runInThisContext;
const assert = require('assert').ok;
const fs = require('fs');
Expand Down Expand Up @@ -121,7 +122,7 @@ function tryExtensions(p, exts) {
}


const noopDeprecateRequireDot = util.deprecate(function() {},
const noopDeprecateRequireDot = internalUtil.deprecate(function() {},
'warning: require(\'.\') resolved outside the package directory. ' +
'This functionality is deprecated and will be removed soon.');

Expand Down
14 changes: 8 additions & 6 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const events = require('events');
const stream = require('stream');
const timers = require('timers');
const util = require('util');
const internalUtil = require('internal/util');
const assert = require('assert');
const cares = process.binding('cares_wrap');
const uv = process.binding('uv');
Expand Down Expand Up @@ -1075,16 +1076,17 @@ function Server(options, connectionListener) {
this._connections = 0;

Object.defineProperty(this, 'connections', {
get: util.deprecate(function() {
get: internalUtil.deprecate(function() {

if (self._usingSlaves) {
return null;
}
return self._connections;
}, 'connections property is deprecated. Use getConnections() method'),
set: util.deprecate(function(val) {
}, 'Server.connections property is deprecated. ' +
'Use Server.getConnections() method'),
set: internalUtil.deprecate(function(val) {
return (self._connections = val);
}, 'connections property is deprecated. Use getConnections() method'),
}, 'Server.connections property is deprecated.'),
configurable: true, enumerable: false
});

Expand Down Expand Up @@ -1496,9 +1498,9 @@ function emitCloseNT(self) {
}


Server.prototype.listenFD = util.deprecate(function(fd, type) {
Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) {
return this.listen({ fd: fd });
}, 'listenFD is deprecated. Use listen({fd: <number>}).');
}, 'Server.listenFD is deprecated. Use Server.listen({fd: <number>}).');

Server.prototype._setupSlave = function(socketList) {
this._usingSlaves = true;
Expand Down
6 changes: 4 additions & 2 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const binding = process.binding('os');
const util = require('util');
const internalUtil = require('internal/util');
const isWindows = process.platform === 'win32';

exports.hostname = binding.getHostname;
Expand Down Expand Up @@ -44,9 +45,10 @@ exports.tmpdir = function() {

exports.tmpDir = exports.tmpdir;

exports.getNetworkInterfaces = util.deprecate(function() {
exports.getNetworkInterfaces = internalUtil.deprecate(function() {
return exports.networkInterfaces();
}, 'getNetworkInterfaces is now called `os.networkInterfaces`.');
}, 'os.getNetworkInterfaces is deprecated. ' +
'Use `os.networkInterfaces` instead.');

exports.EOL = isWindows ? '\r\n' : '\n';

Expand Down
6 changes: 4 additions & 2 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
const kHistorySize = 30;

const util = require('util');
const internalUtil = require('internal/util');
const inherits = util.inherits;
const EventEmitter = require('events').EventEmitter;

Expand Down Expand Up @@ -1417,8 +1418,9 @@ function codePointAt(str, index) {
}
return code;
}
exports.codePointAt = util.deprecate(codePointAt,
'codePointAt() is deprecated. Use String.prototype.codePointAt');
exports.codePointAt = internalUtil.deprecate(codePointAt,
'readline.codePointAt is deprecated. ' +
'Use String.prototype.codePointAt instead');


/**
Expand Down
2 changes: 1 addition & 1 deletion lib/smalloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
const util = require('internal/util');

module.exports = require('internal/smalloc');
util.printDeprecationMessage('smalloc is deprecated.');
util.printDeprecationMessage('(node) smalloc is deprecated. Use typed arrays.');
2 changes: 1 addition & 1 deletion lib/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const util = require('internal/util');
// sys is deprecated and shouldn't be used

module.exports = require('util');
util.printDeprecationMessage('sys is deprecated. Use util instead.');
util.printDeprecationMessage('(node) sys is deprecated. Use util instead.');
6 changes: 4 additions & 2 deletions lib/tty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const util = require('util');
const internalUtil = require('internal/util');
const net = require('net');
const TTY = process.binding('tty_wrap').TTY;
const isTTY = process.binding('tty_wrap').isTTY;
Expand All @@ -14,12 +15,13 @@ exports.isatty = function(fd) {


// backwards-compat
exports.setRawMode = util.deprecate(function(flag) {
exports.setRawMode = internalUtil.deprecate(function(flag) {
if (!process.stdin.isTTY) {
throw new Error('can\'t set raw mode on non-tty');
}
process.stdin.setRawMode(flag);
}, 'tty.setRawMode: Use `process.stdin.setRawMode()` instead.');
}, 'tty.setRawMode is deprecated. ' +
'Use `process.stdin.setRawMode()` instead.');


function ReadStream(fd, options) {
Expand Down

0 comments on commit 6d4a717

Please sign in to comment.