Skip to content

Commit 0adf12c

Browse files
sigvctalkington
authored andcommitted
Add a process.emitWarning for deprecated (#202)
* 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. * 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. * 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. * Do not repeat the same string twice Code maintainability and clean'ness and such features are included in this commit.
1 parent 38ff225 commit 0adf12c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var Archiver = function(format, options) {
5858
};
5959

6060
this._streams = [];
61+
62+
this._loggedBulkDeprecation = false;
6163
};
6264

6365
inherits(Archiver, Transform);
@@ -555,6 +557,16 @@ Archiver.prototype.append = function(source, data) {
555557
* @return {this}
556558
*/
557559
Archiver.prototype.bulk = function(mappings) {
560+
if (!this._loggedBulkDeprecation) {
561+
this._loggedBulkDeprecation = true;
562+
var warning = 'Archiver.bulk() deprecated since 0.21.0';
563+
if (typeof process !== 'undefined' && typeof process.emitWarning !== 'undefined') {
564+
process.emitWarning(warning, 'DeprecationWarning');
565+
} else {
566+
console.warn(warning);
567+
}
568+
}
569+
558570
if (this._state.finalize || this._state.aborted) {
559571
this.emit('error', new Error('bulk: queue closed'));
560572
return this;

0 commit comments

Comments
 (0)