pnpm 6.22.2 → 6.23.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/node_modules/ansi-regex/index.js +8 -2
  2. package/dist/node_modules/ansi-regex/license +4 -16
  3. package/dist/node_modules/ansi-regex/package.json +53 -62
  4. package/dist/node_modules/aproba/index.js +33 -33
  5. package/dist/node_modules/aproba/package.json +5 -4
  6. package/dist/node_modules/are-we-there-yet/{index.js → lib/index.js} +0 -0
  7. package/dist/node_modules/are-we-there-yet/{tracker-base.js → lib/tracker-base.js} +0 -0
  8. package/dist/node_modules/are-we-there-yet/{tracker-group.js → lib/tracker-group.js} +14 -5
  9. package/dist/node_modules/are-we-there-yet/{tracker-stream.js → lib/tracker-stream.js} +0 -0
  10. package/dist/node_modules/are-we-there-yet/{tracker.js → lib/tracker.js} +3 -1
  11. package/dist/node_modules/are-we-there-yet/package.json +35 -17
  12. package/dist/node_modules/{npmlog → color-support}/LICENSE +0 -0
  13. package/dist/node_modules/color-support/bin.js +3 -0
  14. package/dist/node_modules/color-support/browser.js +14 -0
  15. package/dist/node_modules/color-support/index.js +134 -0
  16. package/dist/node_modules/color-support/package.json +36 -0
  17. package/dist/node_modules/debug/LICENSE +10 -9
  18. package/dist/node_modules/debug/package.json +6 -6
  19. package/dist/node_modules/debug/src/common.js +1 -1
  20. package/dist/node_modules/gauge/{base-theme.js → lib/base-theme.js} +7 -3
  21. package/dist/node_modules/gauge/lib/demo.js +45 -0
  22. package/dist/node_modules/gauge/{error.js → lib/error.js} +0 -0
  23. package/dist/node_modules/gauge/lib/has-color.js +4 -0
  24. package/dist/node_modules/gauge/{index.js → lib/index.js} +90 -33
  25. package/dist/node_modules/gauge/{plumbing.js → lib/plumbing.js} +3 -1
  26. package/dist/node_modules/gauge/{process.js → lib/process.js} +0 -0
  27. package/dist/node_modules/gauge/{progress-bar.js → lib/progress-bar.js} +12 -6
  28. package/dist/node_modules/gauge/{render-template.js → lib/render-template.js} +69 -28
  29. package/dist/node_modules/gauge/{set-immediate.js → lib/set-immediate.js} +0 -0
  30. package/dist/node_modules/gauge/{set-interval.js → lib/set-interval.js} +0 -0
  31. package/dist/node_modules/gauge/{spin.js → lib/spin.js} +0 -0
  32. package/dist/node_modules/gauge/{template-item.js → lib/template-item.js} +21 -7
  33. package/dist/node_modules/gauge/{theme-set.js → lib/theme-set.js} +31 -24
  34. package/dist/node_modules/gauge/lib/themes.js +56 -0
  35. package/dist/node_modules/gauge/{wide-truncate.js → lib/wide-truncate.js} +9 -3
  36. package/dist/node_modules/gauge/package.json +39 -40
  37. package/dist/node_modules/is-fullwidth-code-point/index.js +40 -36
  38. package/dist/node_modules/is-fullwidth-code-point/license +4 -16
  39. package/dist/node_modules/is-fullwidth-code-point/package.json +40 -43
  40. package/dist/node_modules/node-gyp/package.json +2 -2
  41. package/dist/node_modules/npmlog/{log.js → lib/log.js} +148 -54
  42. package/dist/node_modules/npmlog/package.json +30 -12
  43. package/dist/node_modules/readable-stream/errors-browser.js +127 -0
  44. package/dist/node_modules/readable-stream/errors.js +116 -0
  45. package/dist/node_modules/readable-stream/experimentalWarning.js +17 -0
  46. package/dist/node_modules/readable-stream/lib/_stream_duplex.js +52 -44
  47. package/dist/node_modules/readable-stream/lib/_stream_passthrough.js +1 -9
  48. package/dist/node_modules/readable-stream/lib/_stream_readable.js +446 -341
  49. package/dist/node_modules/readable-stream/lib/_stream_transform.js +29 -42
  50. package/dist/node_modules/readable-stream/lib/_stream_writable.js +200 -190
  51. package/dist/node_modules/readable-stream/lib/internal/streams/async_iterator.js +207 -0
  52. package/dist/node_modules/readable-stream/lib/internal/streams/buffer_list.js +210 -0
  53. package/dist/node_modules/readable-stream/lib/internal/streams/destroy.js +48 -17
  54. package/dist/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +104 -0
  55. package/dist/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  56. package/dist/node_modules/readable-stream/lib/internal/streams/from.js +64 -0
  57. package/dist/node_modules/readable-stream/lib/internal/streams/pipeline.js +97 -0
  58. package/dist/node_modules/readable-stream/lib/internal/streams/state.js +27 -0
  59. package/dist/node_modules/readable-stream/package.json +35 -19
  60. package/dist/node_modules/readable-stream/readable-browser.js +2 -0
  61. package/dist/node_modules/readable-stream/readable.js +5 -8
  62. package/dist/node_modules/safe-buffer/index.js +3 -0
  63. package/dist/node_modules/safe-buffer/package.json +18 -4
  64. package/dist/node_modules/signal-exit/index.js +30 -8
  65. package/dist/node_modules/signal-exit/package.json +7 -5
  66. package/dist/node_modules/socks-proxy-agent/package.json +2 -2
  67. package/dist/node_modules/string-width/index.js +29 -19
  68. package/dist/node_modules/string-width/license +4 -16
  69. package/dist/node_modules/string-width/package.json +54 -54
  70. package/dist/node_modules/string_decoder/package.json +5 -2
  71. package/dist/node_modules/strip-ansi/index.js +2 -4
  72. package/dist/node_modules/strip-ansi/license +4 -16
  73. package/dist/node_modules/strip-ansi/package.json +52 -55
  74. package/dist/pnpm.cjs +52779 -4337
  75. package/package.json +18 -18
  76. package/dist/node_modules/are-we-there-yet/LICENSE +0 -5
  77. package/dist/node_modules/code-point-at/index.js +0 -32
  78. package/dist/node_modules/code-point-at/license +0 -21
  79. package/dist/node_modules/code-point-at/package.json +0 -38
  80. package/dist/node_modules/core-util-is/LICENSE +0 -19
  81. package/dist/node_modules/core-util-is/lib/util.js +0 -107
  82. package/dist/node_modules/core-util-is/package.json +0 -38
  83. package/dist/node_modules/gauge/LICENSE +0 -13
  84. package/dist/node_modules/gauge/has-color.js +0 -12
  85. package/dist/node_modules/gauge/themes.js +0 -54
  86. package/dist/node_modules/isarray/component.json +0 -19
  87. package/dist/node_modules/isarray/index.js +0 -5
  88. package/dist/node_modules/isarray/package.json +0 -45
  89. package/dist/node_modules/isarray/test.js +0 -20
  90. package/dist/node_modules/number-is-nan/index.js +0 -4
  91. package/dist/node_modules/number-is-nan/license +0 -21
  92. package/dist/node_modules/number-is-nan/package.json +0 -35
  93. package/dist/node_modules/object-assign/index.js +0 -90
  94. package/dist/node_modules/object-assign/license +0 -21
  95. package/dist/node_modules/object-assign/package.json +0 -42
  96. package/dist/node_modules/process-nextick-args/index.js +0 -45
  97. package/dist/node_modules/process-nextick-args/package.json +0 -25
  98. package/dist/node_modules/readable-stream/duplex-browser.js +0 -1
  99. package/dist/node_modules/readable-stream/duplex.js +0 -1
  100. package/dist/node_modules/readable-stream/lib/internal/streams/BufferList.js +0 -79
  101. package/dist/node_modules/readable-stream/passthrough.js +0 -1
  102. package/dist/node_modules/readable-stream/transform.js +0 -1
  103. package/dist/node_modules/readable-stream/writable-browser.js +0 -1
  104. package/dist/node_modules/readable-stream/writable.js +0 -8
  105. package/dist/node_modules/wide-align/node_modules/ansi-regex/index.js +0 -10
  106. package/dist/node_modules/wide-align/node_modules/ansi-regex/license +0 -9
  107. package/dist/node_modules/wide-align/node_modules/ansi-regex/package.json +0 -55
  108. package/dist/node_modules/wide-align/node_modules/is-fullwidth-code-point/index.js +0 -50
  109. package/dist/node_modules/wide-align/node_modules/is-fullwidth-code-point/license +0 -9
  110. package/dist/node_modules/wide-align/node_modules/is-fullwidth-code-point/package.json +0 -42
  111. package/dist/node_modules/wide-align/node_modules/string-width/index.js +0 -47
  112. package/dist/node_modules/wide-align/node_modules/string-width/license +0 -9
  113. package/dist/node_modules/wide-align/node_modules/string-width/package.json +0 -56
  114. package/dist/node_modules/wide-align/node_modules/strip-ansi/index.js +0 -4
  115. package/dist/node_modules/wide-align/node_modules/strip-ansi/license +0 -9
  116. package/dist/node_modules/wide-align/node_modules/strip-ansi/package.json +0 -54
@@ -18,35 +18,29 @@
18
18
  // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
19
  // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
  // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
21
  // A bit simpler than readable streams.
23
22
  // Implement an async ._write(chunk, encoding, cb), and it'll handle all
24
23
  // the drain event emission and buffering.
25
-
26
24
  'use strict';
27
25
 
28
- /*<replacement>*/
29
-
30
- var pna = require('process-nextick-args');
31
- /*</replacement>*/
32
-
33
26
  module.exports = Writable;
34
-
35
27
  /* <replacement> */
28
+
36
29
  function WriteReq(chunk, encoding, cb) {
37
30
  this.chunk = chunk;
38
31
  this.encoding = encoding;
39
32
  this.callback = cb;
40
33
  this.next = null;
41
- }
42
-
43
- // It seems a linked list but it is not
34
+ } // It seems a linked list but it is not
44
35
  // there will be only 2 of these for each stream
36
+
37
+
45
38
  function CorkedRequest(state) {
46
39
  var _this = this;
47
40
 
48
41
  this.next = null;
49
42
  this.entry = null;
43
+
50
44
  this.finish = function () {
51
45
  onCorkedFinish(_this, state);
52
46
  };
@@ -54,266 +48,247 @@ function CorkedRequest(state) {
54
48
  /* </replacement> */
55
49
 
56
50
  /*<replacement>*/
57
- var asyncWrite = !process.browser && ['v0.10', 'v0.9.'].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna.nextTick;
58
- /*</replacement>*/
59
51
 
60
- /*<replacement>*/
52
+
61
53
  var Duplex;
62
54
  /*</replacement>*/
63
55
 
64
56
  Writable.WritableState = WritableState;
65
-
66
57
  /*<replacement>*/
67
- var util = Object.create(require('core-util-is'));
68
- util.inherits = require('inherits');
69
- /*</replacement>*/
70
58
 
71
- /*<replacement>*/
72
59
  var internalUtil = {
73
60
  deprecate: require('util-deprecate')
74
61
  };
75
62
  /*</replacement>*/
76
63
 
77
64
  /*<replacement>*/
65
+
78
66
  var Stream = require('./internal/streams/stream');
79
67
  /*</replacement>*/
80
68
 
81
- /*<replacement>*/
82
69
 
83
- var Buffer = require('safe-buffer').Buffer;
70
+ var Buffer = require('buffer').Buffer;
71
+
84
72
  var OurUint8Array = global.Uint8Array || function () {};
73
+
85
74
  function _uint8ArrayToBuffer(chunk) {
86
75
  return Buffer.from(chunk);
87
76
  }
77
+
88
78
  function _isUint8Array(obj) {
89
79
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
90
80
  }
91
81
 
92
- /*</replacement>*/
93
-
94
82
  var destroyImpl = require('./internal/streams/destroy');
95
83
 
96
- util.inherits(Writable, Stream);
84
+ var _require = require('./internal/streams/state'),
85
+ getHighWaterMark = _require.getHighWaterMark;
97
86
 
98
- function nop() {}
87
+ var _require$codes = require('../errors').codes,
88
+ ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
89
+ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
90
+ ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
91
+ ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
92
+ ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
93
+ ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
94
+ ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
95
+ ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
99
96
 
100
- function WritableState(options, stream) {
101
- Duplex = Duplex || require('./_stream_duplex');
97
+ var errorOrDestroy = destroyImpl.errorOrDestroy;
102
98
 
103
- options = options || {};
99
+ require('inherits')(Writable, Stream);
104
100
 
105
- // Duplex streams are both readable and writable, but share
101
+ function nop() {}
102
+
103
+ function WritableState(options, stream, isDuplex) {
104
+ Duplex = Duplex || require('./_stream_duplex');
105
+ options = options || {}; // Duplex streams are both readable and writable, but share
106
106
  // the same options object.
107
107
  // However, some cases require setting options to different
108
- // values for the readable and the writable sides of the duplex stream.
109
- // These options can be provided separately as readableXXX and writableXXX.
110
- var isDuplex = stream instanceof Duplex;
108
+ // values for the readable and the writable sides of the duplex stream,
109
+ // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
111
110
 
112
- // object stream flag to indicate whether or not this stream
111
+ if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
113
112
  // contains buffers or objects.
114
- this.objectMode = !!options.objectMode;
115
-
116
- if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
117
113
 
118
- // the point at which write() starts returning false
114
+ this.objectMode = !!options.objectMode;
115
+ if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
119
116
  // Note: 0 is a valid value, means that we always return false if
120
117
  // the entire buffer is not flushed immediately on write()
121
- var hwm = options.highWaterMark;
122
- var writableHwm = options.writableHighWaterMark;
123
- var defaultHwm = this.objectMode ? 16 : 16 * 1024;
124
118
 
125
- if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm;
119
+ this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
120
+
121
+ this.finalCalled = false; // drain event flag.
126
122
 
127
- // cast to ints.
128
- this.highWaterMark = Math.floor(this.highWaterMark);
123
+ this.needDrain = false; // at the start of calling end()
129
124
 
130
- // if _final has been called
131
- this.finalCalled = false;
125
+ this.ending = false; // when end() has been called, and returned
132
126
 
133
- // drain event flag.
134
- this.needDrain = false;
135
- // at the start of calling end()
136
- this.ending = false;
137
- // when end() has been called, and returned
138
- this.ended = false;
139
- // when 'finish' is emitted
140
- this.finished = false;
127
+ this.ended = false; // when 'finish' is emitted
141
128
 
142
- // has it been destroyed
143
- this.destroyed = false;
129
+ this.finished = false; // has it been destroyed
144
130
 
145
- // should we decode strings into buffers before passing to _write?
131
+ this.destroyed = false; // should we decode strings into buffers before passing to _write?
146
132
  // this is here so that some node-core streams can optimize string
147
133
  // handling at a lower level.
148
- var noDecode = options.decodeStrings === false;
149
- this.decodeStrings = !noDecode;
150
134
 
151
- // Crypto is kind of old and crusty. Historically, its default string
135
+ var noDecode = options.decodeStrings === false;
136
+ this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
152
137
  // encoding is 'binary' so we have to make this configurable.
153
138
  // Everything else in the universe uses 'utf8', though.
154
- this.defaultEncoding = options.defaultEncoding || 'utf8';
155
139
 
156
- // not an actual buffer we keep track of, but a measurement
140
+ this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
157
141
  // of how much we're waiting to get pushed to some underlying
158
142
  // socket or file.
159
- this.length = 0;
160
143
 
161
- // a flag to see when we're in the middle of a write.
162
- this.writing = false;
144
+ this.length = 0; // a flag to see when we're in the middle of a write.
163
145
 
164
- // when true all writes will be buffered until .uncork() call
165
- this.corked = 0;
146
+ this.writing = false; // when true all writes will be buffered until .uncork() call
166
147
 
167
- // a flag to be able to tell if the onwrite cb is called immediately,
148
+ this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
168
149
  // or on a later tick. We set this to true at first, because any
169
150
  // actions that shouldn't happen until "later" should generally also
170
151
  // not happen before the first write call.
171
- this.sync = true;
172
152
 
173
- // a flag to know if we're processing previously buffered items, which
153
+ this.sync = true; // a flag to know if we're processing previously buffered items, which
174
154
  // may call the _write() callback in the same tick, so that we don't
175
155
  // end up in an overlapped onwrite situation.
176
- this.bufferProcessing = false;
177
156
 
178
- // the callback that's passed to _write(chunk,cb)
157
+ this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
158
+
179
159
  this.onwrite = function (er) {
180
160
  onwrite(stream, er);
181
- };
161
+ }; // the callback that the user supplies to write(chunk,encoding,cb)
182
162
 
183
- // the callback that the user supplies to write(chunk,encoding,cb)
184
- this.writecb = null;
185
163
 
186
- // the amount that is being written when _write is called.
187
- this.writelen = 0;
164
+ this.writecb = null; // the amount that is being written when _write is called.
188
165
 
166
+ this.writelen = 0;
189
167
  this.bufferedRequest = null;
190
- this.lastBufferedRequest = null;
191
-
192
- // number of pending user-supplied write callbacks
168
+ this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
193
169
  // this must be 0 before 'finish' can be emitted
194
- this.pendingcb = 0;
195
170
 
196
- // emit prefinish if the only thing we're waiting for is _write cbs
171
+ this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
197
172
  // This is relevant for synchronous Transform streams
198
- this.prefinished = false;
199
173
 
200
- // True if the error was already emitted and should not be thrown again
201
- this.errorEmitted = false;
174
+ this.prefinished = false; // True if the error was already emitted and should not be thrown again
202
175
 
203
- // count buffered requests
204
- this.bufferedRequestCount = 0;
176
+ this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
205
177
 
206
- // allocate the first CorkedRequest, there is always
178
+ this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
179
+
180
+ this.autoDestroy = !!options.autoDestroy; // count buffered requests
181
+
182
+ this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
207
183
  // one allocated and free to use, and we maintain at most two
184
+
208
185
  this.corkedRequestsFree = new CorkedRequest(this);
209
186
  }
210
187
 
211
188
  WritableState.prototype.getBuffer = function getBuffer() {
212
189
  var current = this.bufferedRequest;
213
190
  var out = [];
191
+
214
192
  while (current) {
215
193
  out.push(current);
216
194
  current = current.next;
217
195
  }
196
+
218
197
  return out;
219
198
  };
220
199
 
221
200
  (function () {
222
201
  try {
223
202
  Object.defineProperty(WritableState.prototype, 'buffer', {
224
- get: internalUtil.deprecate(function () {
203
+ get: internalUtil.deprecate(function writableStateBufferGetter() {
225
204
  return this.getBuffer();
226
205
  }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
227
206
  });
228
207
  } catch (_) {}
229
- })();
230
-
231
- // Test _writableState for inheritance to account for Duplex streams,
208
+ })(); // Test _writableState for inheritance to account for Duplex streams,
232
209
  // whose prototype chain only points to Readable.
210
+
211
+
233
212
  var realHasInstance;
213
+
234
214
  if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
235
215
  realHasInstance = Function.prototype[Symbol.hasInstance];
236
216
  Object.defineProperty(Writable, Symbol.hasInstance, {
237
- value: function (object) {
217
+ value: function value(object) {
238
218
  if (realHasInstance.call(this, object)) return true;
239
219
  if (this !== Writable) return false;
240
-
241
220
  return object && object._writableState instanceof WritableState;
242
221
  }
243
222
  });
244
223
  } else {
245
- realHasInstance = function (object) {
224
+ realHasInstance = function realHasInstance(object) {
246
225
  return object instanceof this;
247
226
  };
248
227
  }
249
228
 
250
229
  function Writable(options) {
251
- Duplex = Duplex || require('./_stream_duplex');
252
-
253
- // Writable ctor is applied to Duplexes, too.
230
+ Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
254
231
  // `realHasInstance` is necessary because using plain `instanceof`
255
232
  // would return false, as no `_writableState` property is attached.
256
-
257
233
  // Trying to use the custom `instanceof` for Writable here will also break the
258
234
  // Node.js LazyTransform implementation, which has a non-trivial getter for
259
235
  // `_writableState` that would lead to infinite recursion.
260
- if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
261
- return new Writable(options);
262
- }
236
+ // Checking for a Stream.Duplex instance is faster here instead of inside
237
+ // the WritableState constructor, at least with V8 6.5
263
238
 
264
- this._writableState = new WritableState(options, this);
239
+ var isDuplex = this instanceof Duplex;
240
+ if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
241
+ this._writableState = new WritableState(options, this, isDuplex); // legacy.
265
242
 
266
- // legacy.
267
243
  this.writable = true;
268
244
 
269
245
  if (options) {
270
246
  if (typeof options.write === 'function') this._write = options.write;
271
-
272
247
  if (typeof options.writev === 'function') this._writev = options.writev;
273
-
274
248
  if (typeof options.destroy === 'function') this._destroy = options.destroy;
275
-
276
249
  if (typeof options.final === 'function') this._final = options.final;
277
250
  }
278
251
 
279
252
  Stream.call(this);
280
- }
253
+ } // Otherwise people can pipe Writable streams, which is just wrong.
254
+
281
255
 
282
- // Otherwise people can pipe Writable streams, which is just wrong.
283
256
  Writable.prototype.pipe = function () {
284
- this.emit('error', new Error('Cannot pipe, not readable'));
257
+ errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
285
258
  };
286
259
 
287
260
  function writeAfterEnd(stream, cb) {
288
- var er = new Error('write after end');
289
- // TODO: defer error events consistently everywhere, not just the cb
290
- stream.emit('error', er);
291
- pna.nextTick(cb, er);
292
- }
261
+ var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
293
262
 
294
- // Checks that a user-supplied chunk is valid, especially for the particular
263
+ errorOrDestroy(stream, er);
264
+ process.nextTick(cb, er);
265
+ } // Checks that a user-supplied chunk is valid, especially for the particular
295
266
  // mode the stream is in. Currently this means that `null` is never accepted
296
267
  // and undefined/non-string values are only allowed in object mode.
268
+
269
+
297
270
  function validChunk(stream, state, chunk, cb) {
298
- var valid = true;
299
- var er = false;
271
+ var er;
300
272
 
301
273
  if (chunk === null) {
302
- er = new TypeError('May not write null values to stream');
303
- } else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
304
- er = new TypeError('Invalid non-string/buffer chunk');
274
+ er = new ERR_STREAM_NULL_VALUES();
275
+ } else if (typeof chunk !== 'string' && !state.objectMode) {
276
+ er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
305
277
  }
278
+
306
279
  if (er) {
307
- stream.emit('error', er);
308
- pna.nextTick(cb, er);
309
- valid = false;
280
+ errorOrDestroy(stream, er);
281
+ process.nextTick(cb, er);
282
+ return false;
310
283
  }
311
- return valid;
284
+
285
+ return true;
312
286
  }
313
287
 
314
288
  Writable.prototype.write = function (chunk, encoding, cb) {
315
289
  var state = this._writableState;
316
290
  var ret = false;
291
+
317
292
  var isBuf = !state.objectMode && _isUint8Array(chunk);
318
293
 
319
294
  if (isBuf && !Buffer.isBuffer(chunk)) {
@@ -326,21 +301,16 @@ Writable.prototype.write = function (chunk, encoding, cb) {
326
301
  }
327
302
 
328
303
  if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
329
-
330
304
  if (typeof cb !== 'function') cb = nop;
331
-
332
- if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
305
+ if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
333
306
  state.pendingcb++;
334
307
  ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
335
308
  }
336
-
337
309
  return ret;
338
310
  };
339
311
 
340
312
  Writable.prototype.cork = function () {
341
- var state = this._writableState;
342
-
343
- state.corked++;
313
+ this._writableState.corked++;
344
314
  };
345
315
 
346
316
  Writable.prototype.uncork = function () {
@@ -348,23 +318,33 @@ Writable.prototype.uncork = function () {
348
318
 
349
319
  if (state.corked) {
350
320
  state.corked--;
351
-
352
- if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
321
+ if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
353
322
  }
354
323
  };
355
324
 
356
325
  Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
357
326
  // node::ParseEncoding() requires lower case.
358
327
  if (typeof encoding === 'string') encoding = encoding.toLowerCase();
359
- if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new TypeError('Unknown encoding: ' + encoding);
328
+ if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
360
329
  this._writableState.defaultEncoding = encoding;
361
330
  return this;
362
331
  };
363
332
 
333
+ Object.defineProperty(Writable.prototype, 'writableBuffer', {
334
+ // making it explicit this property is not enumerable
335
+ // because otherwise some prototype manipulation in
336
+ // userland will fail
337
+ enumerable: false,
338
+ get: function get() {
339
+ return this._writableState && this._writableState.getBuffer();
340
+ }
341
+ });
342
+
364
343
  function decodeChunk(state, chunk, encoding) {
365
344
  if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
366
345
  chunk = Buffer.from(chunk, encoding);
367
346
  }
347
+
368
348
  return chunk;
369
349
  }
370
350
 
@@ -373,29 +353,28 @@ Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
373
353
  // because otherwise some prototype manipulation in
374
354
  // userland will fail
375
355
  enumerable: false,
376
- get: function () {
356
+ get: function get() {
377
357
  return this._writableState.highWaterMark;
378
358
  }
379
- });
380
-
381
- // if we're already writing something, then just put this
359
+ }); // if we're already writing something, then just put this
382
360
  // in the queue, and wait our turn. Otherwise, call _write
383
361
  // If we return false, then we need a drain event, so set that flag.
362
+
384
363
  function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
385
364
  if (!isBuf) {
386
365
  var newChunk = decodeChunk(state, chunk, encoding);
366
+
387
367
  if (chunk !== newChunk) {
388
368
  isBuf = true;
389
369
  encoding = 'buffer';
390
370
  chunk = newChunk;
391
371
  }
392
372
  }
393
- var len = state.objectMode ? 1 : chunk.length;
394
373
 
374
+ var len = state.objectMode ? 1 : chunk.length;
395
375
  state.length += len;
376
+ var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
396
377
 
397
- var ret = state.length < state.highWaterMark;
398
- // we must ensure that previous needDrain will not be reset to false.
399
378
  if (!ret) state.needDrain = true;
400
379
 
401
380
  if (state.writing || state.corked) {
@@ -407,11 +386,13 @@ function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
407
386
  callback: cb,
408
387
  next: null
409
388
  };
389
+
410
390
  if (last) {
411
391
  last.next = state.lastBufferedRequest;
412
392
  } else {
413
393
  state.bufferedRequest = state.lastBufferedRequest;
414
394
  }
395
+
415
396
  state.bufferedRequestCount += 1;
416
397
  } else {
417
398
  doWrite(stream, state, false, len, chunk, encoding, cb);
@@ -425,7 +406,7 @@ function doWrite(stream, state, writev, len, chunk, encoding, cb) {
425
406
  state.writecb = cb;
426
407
  state.writing = true;
427
408
  state.sync = true;
428
- if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
409
+ if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
429
410
  state.sync = false;
430
411
  }
431
412
 
@@ -435,20 +416,20 @@ function onwriteError(stream, state, sync, er, cb) {
435
416
  if (sync) {
436
417
  // defer the callback if we are being called synchronously
437
418
  // to avoid piling up things on the stack
438
- pna.nextTick(cb, er);
439
- // this can emit finish, and it will always happen
419
+ process.nextTick(cb, er); // this can emit finish, and it will always happen
440
420
  // after error
441
- pna.nextTick(finishMaybe, stream, state);
421
+
422
+ process.nextTick(finishMaybe, stream, state);
442
423
  stream._writableState.errorEmitted = true;
443
- stream.emit('error', er);
424
+ errorOrDestroy(stream, er);
444
425
  } else {
445
426
  // the caller expect this to happen before if
446
427
  // it is async
447
428
  cb(er);
448
429
  stream._writableState.errorEmitted = true;
449
- stream.emit('error', er);
450
- // this can emit finish, but finish must
430
+ errorOrDestroy(stream, er); // this can emit finish, but finish must
451
431
  // always follow error
432
+
452
433
  finishMaybe(stream, state);
453
434
  }
454
435
  }
@@ -464,21 +445,18 @@ function onwrite(stream, er) {
464
445
  var state = stream._writableState;
465
446
  var sync = state.sync;
466
447
  var cb = state.writecb;
467
-
448
+ if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
468
449
  onwriteStateUpdate(state);
469
-
470
450
  if (er) onwriteError(stream, state, sync, er, cb);else {
471
451
  // Check if we're actually ready to finish, but don't emit yet
472
- var finished = needFinish(state);
452
+ var finished = needFinish(state) || stream.destroyed;
473
453
 
474
454
  if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
475
455
  clearBuffer(stream, state);
476
456
  }
477
457
 
478
458
  if (sync) {
479
- /*<replacement>*/
480
- asyncWrite(afterWrite, stream, state, finished, cb);
481
- /*</replacement>*/
459
+ process.nextTick(afterWrite, stream, state, finished, cb);
482
460
  } else {
483
461
  afterWrite(stream, state, finished, cb);
484
462
  }
@@ -490,19 +468,19 @@ function afterWrite(stream, state, finished, cb) {
490
468
  state.pendingcb--;
491
469
  cb();
492
470
  finishMaybe(stream, state);
493
- }
494
-
495
- // Must force callback to be called on nextTick, so that we don't
471
+ } // Must force callback to be called on nextTick, so that we don't
496
472
  // emit 'drain' before the write() consumer gets the 'false' return
497
473
  // value, and has a chance to attach a 'drain' listener.
474
+
475
+
498
476
  function onwriteDrain(stream, state) {
499
477
  if (state.length === 0 && state.needDrain) {
500
478
  state.needDrain = false;
501
479
  stream.emit('drain');
502
480
  }
503
- }
481
+ } // if there's something in the buffer waiting, then process it
482
+
504
483
 
505
- // if there's something in the buffer waiting, then process it
506
484
  function clearBuffer(stream, state) {
507
485
  state.bufferProcessing = true;
508
486
  var entry = state.bufferedRequest;
@@ -513,29 +491,30 @@ function clearBuffer(stream, state) {
513
491
  var buffer = new Array(l);
514
492
  var holder = state.corkedRequestsFree;
515
493
  holder.entry = entry;
516
-
517
494
  var count = 0;
518
495
  var allBuffers = true;
496
+
519
497
  while (entry) {
520
498
  buffer[count] = entry;
521
499
  if (!entry.isBuf) allBuffers = false;
522
500
  entry = entry.next;
523
501
  count += 1;
524
502
  }
525
- buffer.allBuffers = allBuffers;
526
503
 
527
- doWrite(stream, state, true, state.length, buffer, '', holder.finish);
528
-
529
- // doWrite is almost always async, defer these to save a bit of time
504
+ buffer.allBuffers = allBuffers;
505
+ doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
530
506
  // as the hot path ends with doWrite
507
+
531
508
  state.pendingcb++;
532
509
  state.lastBufferedRequest = null;
510
+
533
511
  if (holder.next) {
534
512
  state.corkedRequestsFree = holder.next;
535
513
  holder.next = null;
536
514
  } else {
537
515
  state.corkedRequestsFree = new CorkedRequest(state);
538
516
  }
517
+
539
518
  state.bufferedRequestCount = 0;
540
519
  } else {
541
520
  // Slow case, write chunks one-by-one
@@ -544,14 +523,13 @@ function clearBuffer(stream, state) {
544
523
  var encoding = entry.encoding;
545
524
  var cb = entry.callback;
546
525
  var len = state.objectMode ? 1 : chunk.length;
547
-
548
526
  doWrite(stream, state, false, len, chunk, encoding, cb);
549
527
  entry = entry.next;
550
- state.bufferedRequestCount--;
551
- // if we didn't call the onwrite immediately, then
528
+ state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
552
529
  // it means that we need to wait until it does.
553
530
  // also, that means that the chunk and cb are currently
554
531
  // being processed, so move the buffer counter past them.
532
+
555
533
  if (state.writing) {
556
534
  break;
557
535
  }
@@ -565,7 +543,7 @@ function clearBuffer(stream, state) {
565
543
  }
566
544
 
567
545
  Writable.prototype._write = function (chunk, encoding, cb) {
568
- cb(new Error('_write() is not implemented'));
546
+ cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
569
547
  };
570
548
 
571
549
  Writable.prototype._writev = null;
@@ -582,38 +560,52 @@ Writable.prototype.end = function (chunk, encoding, cb) {
582
560
  encoding = null;
583
561
  }
584
562
 
585
- if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
563
+ if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
586
564
 
587
- // .end() fully uncorks
588
565
  if (state.corked) {
589
566
  state.corked = 1;
590
567
  this.uncork();
591
- }
568
+ } // ignore unnecessary end() calls.
569
+
592
570
 
593
- // ignore unnecessary end() calls.
594
- if (!state.ending && !state.finished) endWritable(this, state, cb);
571
+ if (!state.ending) endWritable(this, state, cb);
572
+ return this;
595
573
  };
596
574
 
575
+ Object.defineProperty(Writable.prototype, 'writableLength', {
576
+ // making it explicit this property is not enumerable
577
+ // because otherwise some prototype manipulation in
578
+ // userland will fail
579
+ enumerable: false,
580
+ get: function get() {
581
+ return this._writableState.length;
582
+ }
583
+ });
584
+
597
585
  function needFinish(state) {
598
586
  return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
599
587
  }
588
+
600
589
  function callFinal(stream, state) {
601
590
  stream._final(function (err) {
602
591
  state.pendingcb--;
592
+
603
593
  if (err) {
604
- stream.emit('error', err);
594
+ errorOrDestroy(stream, err);
605
595
  }
596
+
606
597
  state.prefinished = true;
607
598
  stream.emit('prefinish');
608
599
  finishMaybe(stream, state);
609
600
  });
610
601
  }
602
+
611
603
  function prefinish(stream, state) {
612
604
  if (!state.prefinished && !state.finalCalled) {
613
- if (typeof stream._final === 'function') {
605
+ if (typeof stream._final === 'function' && !state.destroyed) {
614
606
  state.pendingcb++;
615
607
  state.finalCalled = true;
616
- pna.nextTick(callFinal, stream, state);
608
+ process.nextTick(callFinal, stream, state);
617
609
  } else {
618
610
  state.prefinished = true;
619
611
  stream.emit('prefinish');
@@ -623,22 +615,37 @@ function prefinish(stream, state) {
623
615
 
624
616
  function finishMaybe(stream, state) {
625
617
  var need = needFinish(state);
618
+
626
619
  if (need) {
627
620
  prefinish(stream, state);
621
+
628
622
  if (state.pendingcb === 0) {
629
623
  state.finished = true;
630
624
  stream.emit('finish');
625
+
626
+ if (state.autoDestroy) {
627
+ // In case of duplex streams we need a way to detect
628
+ // if the readable side is ready for autoDestroy as well
629
+ var rState = stream._readableState;
630
+
631
+ if (!rState || rState.autoDestroy && rState.endEmitted) {
632
+ stream.destroy();
633
+ }
634
+ }
631
635
  }
632
636
  }
637
+
633
638
  return need;
634
639
  }
635
640
 
636
641
  function endWritable(stream, state, cb) {
637
642
  state.ending = true;
638
643
  finishMaybe(stream, state);
644
+
639
645
  if (cb) {
640
- if (state.finished) pna.nextTick(cb);else stream.once('finish', cb);
646
+ if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
641
647
  }
648
+
642
649
  state.ended = true;
643
650
  stream.writable = false;
644
651
  }
@@ -646,42 +653,45 @@ function endWritable(stream, state, cb) {
646
653
  function onCorkedFinish(corkReq, state, err) {
647
654
  var entry = corkReq.entry;
648
655
  corkReq.entry = null;
656
+
649
657
  while (entry) {
650
658
  var cb = entry.callback;
651
659
  state.pendingcb--;
652
660
  cb(err);
653
661
  entry = entry.next;
654
- }
655
- if (state.corkedRequestsFree) {
656
- state.corkedRequestsFree.next = corkReq;
657
- } else {
658
- state.corkedRequestsFree = corkReq;
659
- }
662
+ } // reuse the free corkReq.
663
+
664
+
665
+ state.corkedRequestsFree.next = corkReq;
660
666
  }
661
667
 
662
668
  Object.defineProperty(Writable.prototype, 'destroyed', {
663
- get: function () {
669
+ // making it explicit this property is not enumerable
670
+ // because otherwise some prototype manipulation in
671
+ // userland will fail
672
+ enumerable: false,
673
+ get: function get() {
664
674
  if (this._writableState === undefined) {
665
675
  return false;
666
676
  }
677
+
667
678
  return this._writableState.destroyed;
668
679
  },
669
- set: function (value) {
680
+ set: function set(value) {
670
681
  // we ignore the value if the stream
671
682
  // has not been initialized yet
672
683
  if (!this._writableState) {
673
684
  return;
674
- }
675
-
676
- // backward compatibility, the user is explicitly
685
+ } // backward compatibility, the user is explicitly
677
686
  // managing destroyed
687
+
688
+
678
689
  this._writableState.destroyed = value;
679
690
  }
680
691
  });
681
-
682
692
  Writable.prototype.destroy = destroyImpl.destroy;
683
693
  Writable.prototype._undestroy = destroyImpl.undestroy;
694
+
684
695
  Writable.prototype._destroy = function (err, cb) {
685
- this.end();
686
696
  cb(err);
687
697
  };