From ce25c0ba0b76a57a98f0647b402d2c0a928f26e2 Mon Sep 17 00:00:00 2001 From: Valters Jansons Date: Mon, 3 Oct 2016 16:39:33 +0300 Subject: [PATCH 1/4] Add a console.log call for @deprecated The Archiver.bulk() call has been deprecated for a while and various answers on SO and other sites still suggest it, so if there are no planned maintenance fixes and updates to that function, everyone (even those who do not read the docs) should be informed that they are using something that is deprecated. --- lib/core.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/core.js b/lib/core.js index 66e395d40..03fc76fb1 100644 --- a/lib/core.js +++ b/lib/core.js @@ -555,6 +555,8 @@ Archiver.prototype.append = function(source, data) { * @return {this} */ Archiver.prototype.bulk = function(mappings) { + console.log('Archiver.bulk() deprecated since 0.21.0'); + if (this._state.finalize || this._state.aborted) { this.emit('error', new Error('bulk: queue closed')); return this; From 98fa9731296737eb7084491f9e43f81c1f631fce Mon Sep 17 00:00:00 2001 From: Valters Jansons Date: Mon, 3 Oct 2016 23:28:09 +0300 Subject: [PATCH 2/4] Prefer process.emitWarning for @deprecated The process.emitWarning call is much fancier than the plain logging call as the user can --throw-deprecation or --no-deprecation if he or she prefers to. As a fallback, we just console.warn to stderr. --- lib/core.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/core.js b/lib/core.js index 03fc76fb1..798b3e4fe 100644 --- a/lib/core.js +++ b/lib/core.js @@ -555,7 +555,11 @@ Archiver.prototype.append = function(source, data) { * @return {this} */ Archiver.prototype.bulk = function(mappings) { - console.log('Archiver.bulk() deprecated since 0.21.0'); + if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') { + process.emitWarning('Archiver.bulk() deprecated since 0.21.0', 'DeprecationWarning'); + } else if (typeof console !== 'undefined' && typeof console.warn !== 'undefined') { + console.warn('Archiver.bulk() deprecated since 0.21.0'); + } if (this._state.finalize || this._state.aborted) { this.emit('error', new Error('bulk: queue closed')); From f83795a0117e6120a9e02869fe4f24f46968902d Mon Sep 17 00:00:00 2001 From: Valters Jansons Date: Tue, 4 Oct 2016 00:04:07 +0300 Subject: [PATCH 3/4] Inform about @deprecated only once The deprecation logging action should only take place once so that the client does not get spammed with the warnings. Additionally, the console is now always expected to be around. --- lib/core.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/core.js b/lib/core.js index 798b3e4fe..33394e91c 100644 --- a/lib/core.js +++ b/lib/core.js @@ -58,6 +58,8 @@ var Archiver = function(format, options) { }; this._streams = []; + + this._loggedBulkDeprecation = false; }; inherits(Archiver, Transform); @@ -555,10 +557,13 @@ Archiver.prototype.append = function(source, data) { * @return {this} */ Archiver.prototype.bulk = function(mappings) { - if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') { - process.emitWarning('Archiver.bulk() deprecated since 0.21.0', 'DeprecationWarning'); - } else if (typeof console !== 'undefined' && typeof console.warn !== 'undefined') { - console.warn('Archiver.bulk() deprecated since 0.21.0'); + if (!this._loggedBulkDeprecation) { + this._loggedBulkDeprecation = true; + if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') { + process.emitWarning('Archiver.bulk() deprecated since 0.21.0', 'DeprecationWarning'); + } else { + console.warn('Archiver.bulk() deprecated since 0.21.0'); + } } if (this._state.finalize || this._state.aborted) { From 86b1123c1c76e5c1c2b1c96c9b5ebc767b3acdf1 Mon Sep 17 00:00:00 2001 From: Valters Jansons Date: Tue, 4 Oct 2016 02:18:44 +0300 Subject: [PATCH 4/4] Do not repeat the same string twice Code maintainability and clean'ness and such features are included in this commit. --- lib/core.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/core.js b/lib/core.js index 33394e91c..5590e8b58 100644 --- a/lib/core.js +++ b/lib/core.js @@ -559,10 +559,11 @@ Archiver.prototype.append = function(source, data) { Archiver.prototype.bulk = function(mappings) { if (!this._loggedBulkDeprecation) { this._loggedBulkDeprecation = true; + var warning = 'Archiver.bulk() deprecated since 0.21.0'; if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') { - process.emitWarning('Archiver.bulk() deprecated since 0.21.0', 'DeprecationWarning'); + process.emitWarning(warning, 'DeprecationWarning'); } else { - console.warn('Archiver.bulk() deprecated since 0.21.0'); + console.warn(warning); } }