From 0570e40ef7a53817ac1d2539d1115f0805014c17 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Thu, 4 Jun 2015 21:37:59 +0000 Subject: [PATCH] lib: Deprecating with internal/util's deprecate Since internal/util's deprecate prepends `(node)` to the messages, all the deprecations in the code base has to use it only. --- lib/_http_outgoing.js | 5 +++-- lib/_stream_writable.js | 3 ++- lib/buffer.js | 14 +++++++------- lib/child_process.js | 5 +++-- lib/crypto.js | 18 ++++++++++++------ lib/http.js | 5 +++-- lib/module.js | 3 ++- lib/net.js | 14 ++++++++------ lib/os.js | 6 ++++-- lib/readline.js | 6 ++++-- lib/smalloc.js | 2 +- lib/sys.js | 2 +- lib/tty.js | 6 ++++-- 13 files changed, 54 insertions(+), 35 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 952b2ed082644a..f712fb16b1e2b2 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -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; @@ -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.'); diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index 06bde5561683a3..f51984c27aebd3 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -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); @@ -119,7 +120,7 @@ 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.') diff --git a/lib/buffer.js b/lib/buffer.js index ccd899da5f32ae..38c69656d29374 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -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) { @@ -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; diff --git a/lib/child_process.js b/lib/child_process.js index d8d2ec6aacff56..3161869abf6601 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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'); @@ -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) { diff --git a/lib/crypto.js b/lib/crypto.js index 7ce89482d54b14..e041227bae84c9 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -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; @@ -679,10 +680,15 @@ function filterDuplicates(names) { } // Legacy API -exports.__defineGetter__('createCredentials', util.deprecate(function() { - return require('tls').createSecureContext; -}, 'createCredentials() is deprecated, use tls.createSecureContext instead')); - -exports.__defineGetter__('Credentials', util.deprecate(function() { +exports.__defineGetter__( + 'createCredentials', + internalUtil.deprecate(function() { + return require('tls').createSecureContext; + }, 'crypto.createCredentials() is deprecated, ' + + 'use tls.createSecureContext instead') +); + +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')); diff --git a/lib/http.js b/lib/http.js index a9cfeddeea5cfa..0685c9203c44dd 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1,6 +1,7 @@ 'use strict'; const util = require('util'); +const internalUtil = require('internal/util'); const EventEmitter = require('events').EventEmitter; @@ -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.'); diff --git a/lib/module.js b/lib/module.js index 844b683940c2a4..b38bd0fda3fa7d 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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'); @@ -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.'); diff --git a/lib/net.js b/lib/net.js index 53095210fdd808..7baf40d8545958 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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'); @@ -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 }); @@ -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: }).'); +}, 'Server.listenFD is deprecated. Use Server.listen({fd: }).'); Server.prototype._setupSlave = function(socketList) { this._usingSlaves = true; diff --git a/lib/os.js b/lib/os.js index 4426612285e299..dddbf7ff785d13 100644 --- a/lib/os.js +++ b/lib/os.js @@ -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; @@ -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'; diff --git a/lib/readline.js b/lib/readline.js index 5782eb86e3eb12..d6a8a48f536420 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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; @@ -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'); /** diff --git a/lib/smalloc.js b/lib/smalloc.js index 9a74ca94bf8520..24048d34a21663 100644 --- a/lib/smalloc.js +++ b/lib/smalloc.js @@ -3,4 +3,4 @@ const util = require('internal/util'); module.exports = require('internal/smalloc'); -util.printDeprecationMessage('smalloc is deprecated.'); +util.deprecate('smalloc is deprecated. Use typed arrays.'); diff --git a/lib/sys.js b/lib/sys.js index a34ea0b899f824..512f1054030939 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -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.deprecate('sys is deprecated. Use util instead.'); diff --git a/lib/tty.js b/lib/tty.js index 1241d52535cfeb..ce1e61379f205b 100644 --- a/lib/tty.js +++ b/lib/tty.js @@ -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; @@ -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) {