diff --git a/doc/api/_toc.md b/doc/api/_toc.md index 2527ad84e2e360..eb248f3b72c90d 100644 --- a/doc/api/_toc.md +++ b/doc/api/_toc.md @@ -14,6 +14,7 @@ * [Console](console.html) * [Crypto](crypto.html) * [Debugger](debugger.html) +* [Deprecated APIs](deprecations.html) * [DNS](dns.html) * [Domain](domain.html) * [Errors](errors.html) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md new file mode 100644 index 00000000000000..73a2c6c4e5ea29 --- /dev/null +++ b/doc/api/deprecations.md @@ -0,0 +1,577 @@ +# Deprecated APIs + +Node.js may deprecate APIs when either: (a) use of the API is considered to be +unsafe, (b) an improved alternative API has been made available, or (c) +breaking changes to the API are expected in a future major release. + +Node.js utilizes three kinds of Deprecations: + +* Documentation-only +* Runtime +* End-of-Life + +A Documentation-only deprecation is one that is expressed only within the +Node.js API docs. These generate no side-effects while running Node.js. + +A Runtime deprecation will, by default, generate a process warning that will +be printed to `stderr` the first time the deprecated API is used. When the +`--throw-deprecation` command-line flag is used, a Runtime deprecation will +cause an error to be thrown. + +An End-of-Life deprecation is used to identify code that either has been +removed or will soon be removed from Node.js. + +## Un-deprecation + +From time-to-time the deprecation of an API may be reversed. Such action may +happen in either a semver-minor or semver-major release. In such situations, +this document will be updated with information relevant to the decision. +*However, the deprecation identifier will not be modified*. + +## List of Deprecated APIs + + +### DEP0001: http.OutgoingMessage.prototype.flush + +Type: Runtime + +The `OutgoingMessage.prototype.flush()` method is deprecated. Use +`OutgoingMessage.prototype.flushHeaders()` instead. + + +### DEP0002: require('\_linklist') + +Type: Runtime + +The `_linklist` module is deprecated. Please use a userland alternative. + + +### DEP0003: \_writableState.buffer + +Type: Runtime + +The `_writableState.buffer` property is deprecated. Use the +`_writableState.getBuffer()` method instead. + + +### DEP0004: CryptoStream.prototype.readyState + +Type: Documentation-only + +The `CryptoStream.prototype.readyState` property is deprecated and should not +be used. + + +### DEP0005: Buffer() constructor + +Type: Documentation-only + +The `Buffer()` function and `new Buffer()` constructor are deprecated due to +API usability issues that can potentially lead to accidental security issues. + +As an alternative, use of the following methods of constructing `Buffer` objects +is strongly recommended: + +* [`Buffer.alloc(size[, fill[, encoding]])`][alloc] - Create a `Buffer` with + *initialized* memory. +* [`Buffer.allocUnsafe(size)`][alloc_unsafe_size] - Create a `Buffer` with *uninitialized* + memory. +* [`Buffer.allocUnsafeSlow(size)`][] - Create a `Buffer` with *uninitialized* + memory. +* [`Buffer.from(array)`][] - Create a `Buffer` with a copy of `array` +* [`Buffer.from(arrayBuffer[, byteOffset[, length]])`][from_arraybuffer] - Create a `Buffer` + that wraps the given `arrayBuffer`. +* [`Buffer.from(buffer)`][] - Create a `Buffer` that copies `buffer`. +* [`Buffer.from(string[, encoding])`][from_string_encoding] - Create a `Buffer` that copies + `string`. + + +### DEP0006: child\_process options.customFds + +Type: Runtime + +Within the [`child_process`][] module's `spawn()`, `fork()`, and `exec()` +methods, the `options.customFds` option is deprecated. The `options.stdio` +option should be used instead. + + +### DEP0007: cluster worker.suicide + +Type: Runtime + +Within the `cluster` module, the [`worker.suicide`][] property has been +deprecated. Please use [`worker.exitedAfterDisconnect`][] instead. + + +### DEP0008: require('constants') + +Type: Documentation-only + +The `constants` module has been deprecated. When requiring access to constants +relevant to specific Node.js builtin modules, developers should instead refer +to the `constants` property exposed by the relevant module. For instance, +`require('fs').constants` and `require('os').constants`. + + +### DEP0009: crypto.pbkdf2 without digest + +Type: Runtime + +Use of the [`crypto.pbkdf2()`][] API without specifying a digest is deprecated. +Please specify a digest. + + +### DEP0010: crypto.createCredentials + +Type: Runtime + +The [`crypto.createCredentials()`][] API is deprecated. Please use +[`tls.createSecureContext()`][] instead. + + +### DEP0011: crypto.Credentials + +Type: Runtime + +The `crypto.Credentials` class is deprecated. Please use [`tls.SecureContext`][] +instead. + + +### DEP0012: Domain.dispose + +Type: Runtime + +[`Domain.dispose()`][] is deprecated. Recover from failed I/O actions +explicitly via error event handlers set on the domain instead. + + +### DEP0013: fs async function without callback + +Type: Runtime + +Calling an asynchronous function without a callback is deprecated. + + +### DEP0014: fs.read legacy String interface + +Type: End-of-Life + +The [`fs.read()`][] legacy String interface is deprecated. Use the Buffer API as +mentioned in the documentation instead. + + +### DEP0015: fs.readSync legacy String interface + +Type: End-of-Life + +The [`fs.readSync()`][] legacy String interface is deprecated. Use the Buffer +API as mentioned in the documentation instead. + + +### DEP0016: GLOBAL/root + +Type: Runtime + +The `GLOBAL` and `root` aliases for the `global` property have been deprecated +and should no longer be used. + + +### DEP0017: Intl.v8BreakIterator + +Type: Runtime + +The `Intl.v8BreakIterator` is deprecated and will be removed or replaced soon. + + +### DEP0018: Unhandled promise rejections + +Type: Runtime + +Unhandled promise rejections are deprecated. In the future, promise rejections +that are not handled will terminate the Node.js process with a non-zero exit +code. + + +### DEP0019: require('.') resolved outside directory + +Type: Runtime + +In certain cases, `require('.')` may resolve outside the package directory. +This behavior is deprecated and will be removed in a future major Node.js +release. + + +### DEP0020: Server.connections + +Type: Runtime + +The [`Server.connections`][] property is deprecated. Please use the +[`Server.getConnections()`][] method instead. + + +### DEP0021: Server.listenFD + +Type: Runtime + +The `Server.listenFD()` method is deprecated. Please use +[`Server.listen({fd: })`][] instead. + + +### DEP0022: os.tmpDir() + +Type: Runtime + +The `os.tmpDir()` API is deprecated. Please use [`os.tmpdir()`][] instead. + + +### DEP0023: os.getNetworkInterfaces() + +Type: Runtime + +The `os.getNetworkInterfaces()` method is deprecated. Please use the +[`os.networkInterfaces`][] property instead. + + +### DEP0024: REPLServer.prototype.convertToContext() + +Type: Runtime + +The `REPLServer.prototype.convertToContext()` API is deprecated and should +not be used. + + +### DEP0025: require('sys') + +Type: Runtime + +The `sys` module is deprecated. Please use the [`util`][] module instead. + + +### DEP0026: util.print() + +Type: Runtime + +The [`util.print()`][] API is deprecated. Please use [`console.log()`][] +instead. + + +### DEP0027: util.puts() + +Type: Runtime + +The [`util.puts()`][] API is deprecated. Please use [`console.log()`][] instead. + + +### DEP0028: util.debug() + +Type: Runtime + +The [`util.debug()`][] API is deprecated. Please use [`console.error()`][] +instead. + + +### DEP0029: util.error() + +Type: Runtime + +The [`util.error()`][] API is deprecated. Please use [`console.error()`][] +instead. + + +### DEP0030: SlowBuffer + +Type: Documentation-only + +The [`SlowBuffer`][] class has been deprecated. Please use +[`Buffer.allocUnsafeSlow(size)`][] instead. + + +### DEP0031: ecdh.setPublicKey() + +Type: Documentation-only + +The [`ecdh.setPublicKey()`][] method is now deprecated as its inclusion in the +API is not useful. + + +### DEP0032: domain module + +Type: Documentation-only + +The [`domain`][] module is deprecated and should not be used. + + +### DEP0033: EventEmitter.listenerCount() + +Type: Documentation-only + +The [`EventEmitter.listenerCount(emitter, eventName)`][] API has been +deprecated. Please use [`emitter.listenerCount(eventName)`][] instead. + + +### DEP0034: fs.exists(path, callback) + +Type: Documentation-only + +The [`fs.exists(path, callback)`][] API has been deprecated. Please use +[`fs.stat()`][] or [`fs.access()`][] instead. + + +### DEP0035: fs.lchmod(path, mode, callback) + +Type: Documentation-only + +The [`fs.lchmod(path, mode, callback)`][] API has been deprecated. + + +### DEP0036: fs.lchmodSync(path, mode) + +Type: Documentation-only + +The [`fs.lchmodSync(path, mode)`][] API has been deprecated. + + +### DEP0037: fs.lchown(path, uid, gid, callback) + +Type: Documentation-only + +The [`fs.lchown(path, uid, gid, callback)`][] API has been deprecated. + + +### DEP0038: fs.lchownSync(path, uid, gid) + +Type: Documentation-only + +The [`fs.lchownSync(path, uid, gid)`][] API has been deprecated. + + +### DEP0039: require.extensions + +Type: Documentation-only + +The [`require.extensions`][] property has been deprecated. + + +### DEP0040: punycode module + +Type: Documentation-only + +The [`punycode`][] module has been deprecated. Please use a userland alternative +instead. + + +### DEP0041: NODE\_REPL\_HISTORY\_FILE environment variable + +Type: Documentation-only + +The `NODE_REPL_HISTORY_FILE` environment variable has been deprecated. + + +### DEP0042: tls.CryptoStream + +Type: Documentation-only + +The [`tls.CryptoStream`][] class has been deprecated. Please use +[`tls.TLSSocket`][] instead. + + +### DEP0043: tls.SecurePair + +Type: Documentation-only + +The [`tls.SecurePair`][] class has been deprecated. Please use +[`tls.TLSSocket`][] instead. + + +### DEP0044: util.isArray() + +Type: Documentation-only + +The [`util.isArray()`][] API has been deprecated. Please use `Array.isArray()` +instead. + + +### DEP0045: util.isBoolean() + +Type: Documentation-only + +The [`util.isBoolean()`][] API has been deprecated. + + +### DEP0046: util.isBuffer() + +Type: Documentation-only + +The [`util.isBuffer()`][] API has been deprecated. Please use +[`Buffer.isBuffer()`][] instead. + + +### DEP0047: util.isDate() + +Type: Documentation-only + +The [`util.isDate()`][] API has been deprecated. + + +### DEP0048: util.isError() + +Type: Documentation-only + +The [`util.isError()`][] API has been deprecated. + + +### DEP0049: util.isFunction() + +Type: Documentation-only + +The [`util.isFunction()`][] API has been deprecated. + + +### DEP0050: util.isNull() + +Type: Documentation-only + +The [`util.isNull()`][] API has been deprecated. + + +### DEP0051: util.isNullOrUndefined() + +Type: Documentation-only + +The [`util.isNullOrUndefined()`][] API has been deprecated. + + +### DEP0052: util.isNumber() + +Type: Documentation-only + +The [`util.isNumber()`][] API has been deprecated. + + +### DEP0053 util.isObject() + +Type: Documentation-only + +The [`util.isObject()`][] API has been deprecated. + + +### DEP0054: util.isPrimitive() + +Type: Documentation-only + +The [`util.isPrimitive()`][] API has been deprecated. + + +### DEP0055: util.isRegExp() + +Type: Documentation-only + +The [`util.isRegExp()`][] API has been deprecated. + + +### DEP0056: util.isString() + +Type: Documentation-only + +The [`util.isString()`][] API has been deprecated. + + +### DEP0057: util.isSymbol() + +Type: Documentation-only + +The [`util.isSymbol()`][] API has been deprecated. + + +### DEP0058: util.isUndefined() + +Type: Documentation-only + +The [`util.isUndefined()`][] API has been deprecated. + + +### DEP0059: util.log() + +Type: Documentation-only + +The [`util.log()`][] API has been deprecated. + + +### DEP0060: util.\_extend() + +Type: Documentation-only + +The [`util._extend()`][] API has been deprecated. + + +### DEP0061: fs.SyncWriteStream + +Type: Documentation-only + +The `fs.SyncWriteStream` class was never intended to be a publicly accessible +API. + +[alloc]: buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding +[alloc_unsafe_size]: buffer.html#buffer_class_method_buffer_allocunsafe_size +[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size +[`Buffer.isBuffer()`]: buffer.html#buffer_class_method_buffer_isbuffer_obj +[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array +[from_arraybuffer]: buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length +[`Buffer.from(buffer)`]: buffer.html#buffer_class_method_buffer_from_buffer +[from_string_encoding]: buffer.html#buffer_class_method_buffer_from_string_encoding +[`SlowBuffer`]: buffer.html#buffer_class_slowbuffer +[`child_process`]: child_process.html +[`console.error()`]: console.html#console_console_error_data_args +[`console.log()`]: console.html#console_console_log_data_args +[`crypto.createCredentials()`]: crypto.html#crypto_crypto_createcredentials_details +[`crypto.pbkdf2()`]: crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback +[`domain`]: domain.html +[`Domain.dispose()`]: domain.html#domain_domain_dispose +[`ecdh.setPublicKey()`]: crypto.html#crypto_ecdh_setpublickey_public_key_encoding +[`emitter.listenerCount(eventName)`]: events.html#events_emitter_listenercount_eventname +[`EventEmitter.listenerCount(emitter, eventName)`]: events.html#events_eventemitter_listenercount_emitter_eventname +[`fs.exists(path, callback)`]: fs.html#fs_fs_exists_path_callback +[`fs.stat()`]: fs.html#fs_fs_stat_path_callback +[`fs.access()`]: fs.html#fs_fs_access_path_mode_callback +[`fs.lchmod(path, mode, callback)`]: fs.html#fs_fs_lchmod_path_mode_callback +[`fs.lchmodSync(path, mode)`]: fs.html#fs_fs_lchmodsync_path_mode +[`fs.lchown(path, uid, gid, callback)`]: fs.html#fs_fs_lchown_path_uid_gid_callback +[`fs.lchownSync(path, uid, gid)`]: fs.html#fs_fs_lchownsync_path_uid_gid +[`fs.read()`]: fs.html#fs_fs_read_fd_buffer_offset_length_position_callback +[`fs.readSync()`]: fs.html#fs_fs_readsync_fd_buffer_offset_length_position +[`Server.connections`]: net.html#net_server_connections +[`Server.getConnections()`]: net.html#net_server_getconnections_callback +[`Server.listen({fd: })`]: net.html#net_server_listen_handle_backlog_callback +[`os.networkInterfaces`]: os.html#os_os_networkinterfaces +[`os.tmpdir()`]: os.html#os_os_tmpdir +[`punycode`]: punycode.html +[`require.extensions`]: globals.html#globals_require_extensions +[`tls.TLSSocket`]: tls.html#tls_class_tls_tlssocket +[`tls.CryptoStream`]: tls.html#tls_class_cryptostream +[`tls.SecurePair`]: tls.html#tls_class_securepair +[`tls.SecureContext`]: tls.html#tls_tls_createsecurecontext_options +[`tls.createSecureContext()`]: tls.html#tls_tls_createsecurecontext_options +[`util`]: util.html +[`util.debug()`]: util.html#util_util_debug_string +[`util.error()`]: util.html#util_util_error_strings +[`util.puts()`]: util.html#util_util_puts_strings +[`util.print()`]: util.html#util_util_print_strings +[`util.isArray()`]: util.html#util_util_isarray_object +[`util.isBoolean()`]: util.html#util_util_isboolean_object +[`util.isBuffer()`]: util.html#util_util_isbuffer_object +[`util.isDate()`]: util.html#util_util_isdate_object +[`util.isError()`]: util.html#util_util_iserror_object +[`util.isFunction()`]: util.html#util_util_isfunction_object +[`util.isNull()`]: util.html#util_util_isnull_object +[`util.isNullOrUndefined()`]: util.html#util_util_isnullorundefined_object +[`util.isNumber()`]: util.html#util_util_isnumber_object +[`util.isObject()`]: util.html#util_util_isobject_object +[`util.isPrimitive()`]: util.html#util_util_isprimitive_object +[`util.isRegExp()`]: util.html#util_util_isregexp_object +[`util.isString()`]: util.html#util_util_isstring_object +[`util.isSymbol()`]: util.html#util_util_issymbol_object +[`util.isUndefined()`]: util.html#util_util_isundefined_object +[`util.log()`]: util.html#util_util_log_string +[`util._extend()`]: util.html#util_util_extend_target_source +[`worker.suicide`]: cluster.html#cluster_worker_suicide +[`worker.exitedAfterDisconnect`]: cluster.html#cluster_worker_exitedafterdisconnect diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 30011e091525a3..f9df7817512519 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -738,4 +738,4 @@ OutgoingMessage.prototype.flushHeaders = function flushHeaders() { OutgoingMessage.prototype.flush = internalUtil.deprecate(function() { this.flushHeaders(); -}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.'); +}, 'OutgoingMessage.flush is deprecated. Use flushHeaders instead.', 'DEP0001'); diff --git a/lib/_linklist.js b/lib/_linklist.js index 1b709d6fbd282e..1d2e9fa4d4411a 100644 --- a/lib/_linklist.js +++ b/lib/_linklist.js @@ -3,4 +3,4 @@ module.exports = require('internal/linkedlist'); process.emitWarning( '_linklist module is deprecated. Please use a userland alternative.', - 'DeprecationWarning'); + 'DeprecationWarning', 'DEP0002'); diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index af97fc2d8180c6..eedeb56e125db0 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -125,7 +125,7 @@ Object.defineProperty(WritableState.prototype, 'buffer', { get: internalUtil.deprecate(function() { return this.getBuffer(); }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + - 'instead.') + 'instead.', 'DEP0003') }); // Test _writableState for inheritance to account for Duplex streams, diff --git a/lib/_tls_legacy.js b/lib/_tls_legacy.js index e765b2507e7502..83ee3e0f8f5cda 100644 --- a/lib/_tls_legacy.js +++ b/lib/_tls_legacy.js @@ -479,6 +479,7 @@ CryptoStream.prototype._done = function() { // readyState is deprecated. Don't use it. +// Deprecation Code: DEP0004 Object.defineProperty(CryptoStream.prototype, 'readyState', { get: function() { if (this.connecting) { diff --git a/lib/buffer.js b/lib/buffer.js index 456580a5c0ca8d..0a8724bda48e48 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -65,14 +65,14 @@ function alignPool() { } /** - * The Buffer() construtor is "soft deprecated" ... that is, it is deprecated - * in the documentation and should not be used moving forward. Rather, - * developers should use one of the three new factory APIs: Buffer.from(), - * Buffer.allocUnsafe() or Buffer.alloc() based on their specific needs. There - * is no hard deprecation because of the extent to which the Buffer constructor - * is used in the ecosystem currently -- a hard deprecation would introduce too - * much breakage at this time. It's not likely that the Buffer constructors - * would ever actually be removed. + * The Buffer() construtor is deprecated in documentation and should not be + * used moving forward. Rather, developers should use one of the three new + * factory APIs: Buffer.from(), Buffer.allocUnsafe() or Buffer.alloc() based on + * their specific needs. There is no runtime deprecation because of the extent + * to which the Buffer constructor is used in the ecosystem currently -- a + * runtime deprecation would introduce too much breakage at this time. It's not + * likely that the Buffer constructors would ever actually be removed. + * Deprecation Code: DEP0005 **/ function Buffer(arg, encodingOrOffset, length) { // Common case. diff --git a/lib/child_process.js b/lib/child_process.js index b00e3829b455a9..409dfff170cf4a 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -324,8 +324,7 @@ const _deprecatedCustomFds = internalUtil.deprecate( return fd === -1 ? 'pipe' : fd; }); }, 'child_process: options.customFds option is deprecated. ' + - 'Use options.stdio instead.' -); + 'Use options.stdio instead.', 'DEP0006'); function _convertCustomFds(options) { if (options.customFds && !options.stdio) { diff --git a/lib/constants.js b/lib/constants.js index fec7e13d94145a..c1cbf2db3cce37 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,8 +1,9 @@ 'use strict'; -// This module is soft-deprecated. Users should be directed towards using -// the specific constants exposed by the individual modules on which they -// are most relevant. +// This module is deprecated in documentation only. Users should be directed +// towards using the specific constants exposed by the individual modules on +// which they are most relevant. +// Deprecation Code: DEP0008 const constants = process.binding('constants'); Object.assign(exports, constants.os.errno, diff --git a/lib/crypto.js b/lib/crypto.js index 9180ce70dce12e..2d4695dc97e6fb 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -539,7 +539,7 @@ ECDH.prototype.getPublicKey = function getPublicKey(encoding, format) { const pbkdf2DeprecationWarning = internalUtil.deprecate(() => {}, 'crypto.pbkdf2 without specifying' + - ' a digest is deprecated. Please specify a digest'); + ' a digest is deprecated. Please specify a digest', 'DEP0009'); exports.pbkdf2 = function(password, @@ -663,7 +663,7 @@ Object.defineProperty(exports, 'createCredentials', { get: internalUtil.deprecate(function() { return require('tls').createSecureContext; }, 'crypto.createCredentials is deprecated. ' + - 'Use tls.createSecureContext instead.') + 'Use tls.createSecureContext instead.', 'DEP0010') }); Object.defineProperty(exports, 'Credentials', { @@ -672,5 +672,5 @@ Object.defineProperty(exports, 'Credentials', { get: internalUtil.deprecate(function() { return require('tls').SecureContext; }, 'crypto.Credentials is deprecated. ' + - 'Use tls.SecureContext instead.') + 'Use tls.SecureContext instead.', 'DEP0011') }); diff --git a/lib/domain.js b/lib/domain.js index c86af75c86760b..f45a623e8acafd 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -315,4 +315,4 @@ Domain.prototype.dispose = util.deprecate(function() { // so that it can't be entered or activated. this._disposed = true; }, 'Domain.dispose is deprecated. Recover from failed I/O actions explicitly ' + - 'via error event handlers set on the domain instead.'); + 'via error event handlers set on the domain instead.', 'DEP0012'); diff --git a/lib/fs.js b/lib/fs.js index 573ffec05992aa..27e1a2e79cd135 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -68,8 +68,7 @@ function rethrow() { // TODO(thefourtheye) Throw error instead of warning in major version > 7 process.emitWarning( 'Calling an asynchronous function without callback is deprecated.', - 'DeprecationWarning', - rethrow + 'DeprecationWarning', 'DEP0013', rethrow ); // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and @@ -1943,6 +1942,7 @@ WriteStream.prototype.destroySoon = WriteStream.prototype.end; // todo(jasnell): "Docs-only" deprecation for now. This was never documented // so there's no documentation to modify. In the future, add a runtime // deprecation. +// Deprecation ID: DEP0061 Object.defineProperty(fs, 'SyncWriteStream', { configurable: true, writable: true, diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 71a6c529041b47..efdbc5d9e3ac48 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -204,7 +204,7 @@ // getter const get = util.deprecate(function() { return this; - }, `'${name}' is deprecated, use 'global'`); + }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); // setter const set = util.deprecate(function(value) { Object.defineProperty(this, name, { @@ -213,7 +213,7 @@ enumerable: true, value: value }); - }, `'${name}' is deprecated, use 'global'`); + }, `'${name}' is deprecated, use 'global'`, 'DEP0016'); // define property Object.defineProperty(global, name, { get, set, configurable: true }); }); diff --git a/lib/internal/cluster/worker.js b/lib/internal/cluster/worker.js index fd46ed571076d5..687e4c12fecea4 100644 --- a/lib/internal/cluster/worker.js +++ b/lib/internal/cluster/worker.js @@ -23,10 +23,10 @@ function Worker(options) { defineProperty(this, 'suicide', { get: internalUtil.deprecate( () => this.exitedAfterDisconnect, - suicideDeprecationMessage), + suicideDeprecationMessage, 'DEP0007'), set: internalUtil.deprecate( (val) => { this.exitedAfterDisconnect = val; }, - suicideDeprecationMessage), + suicideDeprecationMessage, 'DEP0007'), enumerable: true }); diff --git a/lib/internal/process.js b/lib/internal/process.js index 44f1370459eb98..3f050b42cafe42 100644 --- a/lib/internal/process.js +++ b/lib/internal/process.js @@ -130,7 +130,8 @@ function setupConfig(_source) { 'See https://github.com/nodejs/node/wiki/Intl'); } return Reflect.construct(oldV8BreakIterator, arguments); - }, 'Intl.v8BreakIterator is deprecated and will be removed soon.'); + }, 'Intl.v8BreakIterator is deprecated and will be removed soon.', + 'DEP0017'); Object.defineProperty(Intl, 'v8BreakIterator', des); } // Don’t let icu_data_dir leak through. diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index 83dee491a55c90..0e382d11d5523b 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -70,7 +70,7 @@ function setupPromises(scheduleMicrotasks) { 'Unhandled promise rejections are deprecated. In the future, ' + 'promise rejections that are not handled will terminate the ' + 'Node.js process with a non-zero exit code.', - 'DeprecationWarning'); + 'DeprecationWarning', 'DEP0018'); } } var deprecationWarned = false; diff --git a/lib/internal/util.js b/lib/internal/util.js index 42a0922d304970..10844b645455dd 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -15,8 +15,8 @@ exports.customInspectSymbol = Symbol('util.inspect.custom'); // All the internal deprecations have to use this function only, as this will // prepend the prefix to the actual message. -exports.deprecate = function(fn, msg) { - return exports._deprecate(fn, msg); +exports.deprecate = function(fn, msg, code) { + return exports._deprecate(fn, msg, code); }; exports.error = function(msg) { @@ -39,7 +39,7 @@ exports.trace = function(msg) { // Mark that a method should not be used. // Returns a modified function which warns once by default. // If --no-deprecation is set, then it is a no-op. -exports._deprecate = function(fn, msg) { +exports._deprecate = function(fn, msg, code) { // Allow for deprecating things in the process of starting up. if (global.process === undefined) { return function() { @@ -51,11 +51,18 @@ exports._deprecate = function(fn, msg) { return fn; } + if (code !== undefined && typeof code !== 'string') + throw new TypeError('`code` argument must be a string'); + var warned = false; function deprecated() { if (!warned) { warned = true; - process.emitWarning(msg, 'DeprecationWarning', deprecated); + if (code !== undefined) { + process.emitWarning(msg, 'DeprecationWarning', code, deprecated); + } else { + process.emitWarning(msg, 'DeprecationWarning', deprecated); + } } if (new.target) { return Reflect.construct(fn, arguments, new.target); diff --git a/lib/module.js b/lib/module.js index 09c4b85b9e5599..9a6b641a753588 100644 --- a/lib/module.js +++ b/lib/module.js @@ -213,7 +213,7 @@ Module._findPath = function(request, paths, isMain) { 'warning: require(\'.\') resolved outside the package ' + 'directory. This functionality is deprecated and will be removed ' + 'soon.', - 'DeprecationWarning'); + 'DeprecationWarning', 'DEP0019'); } } diff --git a/lib/net.js b/lib/net.js index e4f97ab80debd5..121309895343b7 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1131,9 +1131,10 @@ function Server(options, connectionListener) { } return this._connections; }, 'Server.connections property is deprecated. ' + - 'Use Server.getConnections method instead.'), + 'Use Server.getConnections method instead.', 'DEP0020'), set: internalUtil.deprecate((val) => (this._connections = val), - 'Server.connections property is deprecated.'), + 'Server.connections property is deprecated.', + 'DEP0020'), configurable: true, enumerable: false }); @@ -1546,7 +1547,8 @@ function emitCloseNT(self) { Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) { return this.listen({ fd: fd }); -}, 'Server.listenFD is deprecated. Use Server.listen({fd: }) instead.'); +}, 'Server.listenFD is deprecated. Use Server.listen({fd: }) instead.', + 'DEP0021'); Server.prototype._setupSlave = function(socketList) { this._usingSlaves = true; diff --git a/lib/os.js b/lib/os.js index a59cc49bae8c51..7ab0ec5fa423be 100644 --- a/lib/os.js +++ b/lib/os.js @@ -53,12 +53,14 @@ exports.tmpdir = function() { const tmpDirDeprecationMsg = 'os.tmpDir() is deprecated. Use os.tmpdir() instead.'; -exports.tmpDir = internalUtil.deprecate(exports.tmpdir, tmpDirDeprecationMsg); +exports.tmpDir = internalUtil.deprecate(exports.tmpdir, + tmpDirDeprecationMsg, + 'DEP0022'); exports.getNetworkInterfaces = internalUtil.deprecate(function() { return exports.networkInterfaces(); }, 'os.getNetworkInterfaces is deprecated. ' + - 'Use os.networkInterfaces instead.'); + 'Use os.networkInterfaces instead.', 'DEP0023'); exports.EOL = isWindows ? '\r\n' : '\n'; diff --git a/lib/repl.js b/lib/repl.js index 29f25a5c37b8c1..fed89146dc9af7 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1356,7 +1356,7 @@ REPLServer.prototype.convertToContext = util.deprecate(function(cmd) { } return cmd; -}, 'replServer.convertToContext() is deprecated'); +}, 'replServer.convertToContext() is deprecated', 'DEP0024'); function bailOnIllegalToken(parser) { return parser._literal === null && diff --git a/lib/sys.js b/lib/sys.js index c94b032c649662..4d7d305daa056b 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -6,4 +6,4 @@ module.exports = require('util'); process.emitWarning('sys is deprecated. Use util instead.', - 'DeprecationWarning'); + 'DeprecationWarning', 'DEP0025'); diff --git a/lib/util.js b/lib/util.js index 9d5909cdc7ce30..46cde4d85bf28b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -993,26 +993,26 @@ exports.print = internalUtil.deprecate(function() { for (var i = 0, len = arguments.length; i < len; ++i) { process.stdout.write(String(arguments[i])); } -}, 'util.print is deprecated. Use console.log instead.'); +}, 'util.print is deprecated. Use console.log instead.', 'DEP0026'); exports.puts = internalUtil.deprecate(function() { for (var i = 0, len = arguments.length; i < len; ++i) { process.stdout.write(arguments[i] + '\n'); } -}, 'util.puts is deprecated. Use console.log instead.'); +}, 'util.puts is deprecated. Use console.log instead.', 'DEP0027'); exports.debug = internalUtil.deprecate(function(x) { process.stderr.write(`DEBUG: ${x}\n`); -}, 'util.debug is deprecated. Use console.error instead.'); +}, 'util.debug is deprecated. Use console.error instead.', 'DEP0028'); exports.error = internalUtil.deprecate(function(x) { for (var i = 0, len = arguments.length; i < len; ++i) { process.stderr.write(arguments[i] + '\n'); } -}, 'util.error is deprecated. Use console.error instead.'); +}, 'util.error is deprecated. Use console.error instead.', 'DEP0029'); exports._errnoException = function(err, syscall, original) { diff --git a/test/message/unhandled_promise_trace_warnings.out b/test/message/unhandled_promise_trace_warnings.out index 80cf948cf118a3..e5432bdf99f66b 100644 --- a/test/message/unhandled_promise_trace_warnings.out +++ b/test/message/unhandled_promise_trace_warnings.out @@ -9,7 +9,7 @@ at * at * at * -(node:*) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. +(node:*) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. at * at * at *