Skip to content

Commit

Permalink
Update to Node v10.18.1 (#420)
Browse files Browse the repository at this point in the history
* Update to Node v10.17.0

* Browsers might not have Symbol, from edition

* Use Node 12 for airtap

* test passing on browser

* Update to Node 10.18.1

* fixed file patterns for build

* possibly browser fix

* test passing down to Node 6
  • Loading branch information
mcollina committed Jan 17, 2020
1 parent ed213f0 commit 040b813
Show file tree
Hide file tree
Showing 43 changed files with 1,396 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -14,7 +14,7 @@ matrix:
env: CMD=test
- node_js: 12
env: CMD=test
- node_js: stable
- node_js: 12
env: CMD=test-browsers
addons:
sauce_connect: true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -15,7 +15,7 @@ npm install --save readable-stream

This package is a mirror of the streams implementations in Node.js.

Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.15.3/docs/api/stream.html).
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v10.18.1/docs/api/stream.html).

If you want to guarantee a stable streams base, regardless of what version of
Node you, or the users of your libraries are using, use **readable-stream** *only* and avoid the *"stream"* module in Node-core, for background see [this blogpost](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html).
Expand Down
3 changes: 1 addition & 2 deletions build/build.js
Expand Up @@ -131,7 +131,7 @@ pump(
//--------------------------------------------------------------------
// Discover, grab and process all test-stream* files on the given release

glob(path.join(testsrcurl, 'test-stream*.js'), function (err, list) {
glob(path.join(testsrcurl, 'test-@(stream|readable)*.js'), function (err, list) {
if (err) {
throw err
}
Expand All @@ -153,7 +153,6 @@ pump(
})
})


//--------------------------------------------------------------------
// Grab the nodejs/node test/common.js

Expand Down
21 changes: 21 additions & 0 deletions build/files.js
Expand Up @@ -208,6 +208,14 @@ function CorkedRequest(state) {
/return createReadableStreamAsyncIterator\(this\);\n};/m
, 'return createReadableStreamAsyncIterator(this);\n};\n}'
]
, noAsyncIteratorsFrom1 = [
/Readable\.from = function *\(iterable, opts\) \{/g
, 'if (typeof Symbol === \'function\' ) {\nReadable.from = function (iterable, opts) {'
]
, noAsyncIteratorsFrom2 = [
/return from\(Readable, iterable, opts\);\n};/m
, 'return from(Readable, iterable, opts);\n};\n}'
]
, once = [
/const \{ once \} = require\('internal\/util'\);/
, 'function once(callback) { let called = false; return function(...args) { if (called) return; called = true; callback(...args); }; }'
Expand Down Expand Up @@ -257,6 +265,8 @@ module.exports['_stream_readable.js'] = [
, numberIE11
, noAsyncIterators1
, noAsyncIterators2
, noAsyncIteratorsFrom1
, noAsyncIteratorsFrom2
]

module.exports['_stream_transform.js'] = [
Expand Down Expand Up @@ -358,3 +368,14 @@ module.exports['internal/streams/pipeline.js'] = [
'require(\'.\/end-of-stream\')'
]
]

module.exports['internal/streams/from.js'] = [
errorsTwoLevel
, [
/if \(iterable && iterable\[Symbol.asyncIterator\]\)/
, `if (iterable && typeof iterable.next === 'function') {
iterator = iterable
}
else if (iterable && iterable[Symbol.asyncIterator])`
]
]
21 changes: 20 additions & 1 deletion build/test-replacements.js
Expand Up @@ -55,10 +55,14 @@ module.exports.all = [
]
, bufferShimFix
, bufferStaticMethods
, [
, [
/require\(['"]assert['"]\)/g
, 'require(\'assert/\')'
]
, [
/\/\/ Flags: .*/
, ''
]
]

module.exports['test-stream2-basic.js'] = [
Expand Down Expand Up @@ -105,6 +109,14 @@ module.exports['common.js'] = [
, deepStrictEqual
, catchES7
, catchES7OpenClose
, [
/require\('module'\)\.builtinModules\.includes\('worker_threads'\)/,
'false'
]
, [
/process.argv.length === 2/,
'false'
]
, [
/^( for \(var x in global\) \{|function leakedGlobals\(\) \{)$/m
, ' /*<replacement>*/\n'
Expand Down Expand Up @@ -452,3 +464,10 @@ module.exports['test-stream-readable-async-iterators.js'] = [
'const AsyncIteratorPrototype = Object\.getPrototypeOf(function () {})'
]
]

module.exports['test-readable-from.js'] = [
[
/const \{ once \} = require\('events'\);/
, 'const once = require(\'events.once\');'
]
]
71 changes: 54 additions & 17 deletions lib/_stream_readable.js
Expand Up @@ -80,17 +80,16 @@ var _require$codes = require('../errors').codes,
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;

var _require2 = require('../experimentalWarning'),
emitExperimentalWarning = _require2.emitExperimentalWarning; // Lazy loaded to improve the startup performance.
ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.


var StringDecoder;
var createReadableStreamAsyncIterator;
var from;

require('inherits')(Readable, Stream);

var errorOrDestroy = destroyImpl.errorOrDestroy;
var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];

function prependListener(emitter, event, fn) {
Expand Down Expand Up @@ -144,7 +143,9 @@ function ReadableState(options, stream, isDuplex) {
this.resumeScheduled = false;
this.paused = true; // Should close be emitted on destroy. Defaults to true.

this.emitClose = options.emitClose !== false; // has it been destroyed
this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')

this.autoDestroy = !!options.autoDestroy; // has it been destroyed

this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
Expand Down Expand Up @@ -257,16 +258,16 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
if (!skipChunkCheck) er = chunkInvalid(state, chunk);

if (er) {
stream.emit('error', er);
errorOrDestroy(stream, er);
} else if (state.objectMode || chunk && chunk.length > 0) {
if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
chunk = _uint8ArrayToBuffer(chunk);
}

if (addToFront) {
if (state.endEmitted) stream.emit('error', new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
} else if (state.ended) {
stream.emit('error', new ERR_STREAM_PUSH_AFTER_EOF());
errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
} else if (state.destroyed) {
return false;
} else {
Expand Down Expand Up @@ -322,17 +323,32 @@ Readable.prototype.isPaused = function () {

Readable.prototype.setEncoding = function (enc) {
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder;
this._readableState.decoder = new StringDecoder(enc); // if setEncoding(null), decoder.encoding equals utf8
var decoder = new StringDecoder(enc);
this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8

this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:

var p = this._readableState.buffer.head;
var content = '';

while (p !== null) {
content += decoder.write(p.data);
p = p.next;
}

this._readableState.buffer.clear();

this._readableState.encoding = this._readableState.decoder.encoding;
if (content !== '') this._readableState.buffer.push(content);
this._readableState.length = content.length;
return this;
}; // Don't raise the hwm > 8MB
}; // Don't raise the hwm > 1GB


var MAX_HWM = 0x800000;
var MAX_HWM = 0x40000000;

function computeNewHighWaterMark(n) {
if (n >= MAX_HWM) {
// TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
n = MAX_HWM;
} else {
// Get the next highest power of 2 to prevent increasing hwm excessively in
Expand Down Expand Up @@ -449,7 +465,7 @@ Readable.prototype.read = function (n) {
if (n > 0) ret = fromList(n, state);else ret = null;

if (ret === null) {
state.needReadable = true;
state.needReadable = state.length <= state.highWaterMark;
n = 0;
} else {
state.length -= n;
Expand All @@ -469,6 +485,7 @@ Readable.prototype.read = function (n) {
};

function onEofChunk(stream, state) {
debug('onEofChunk');
if (state.ended) return;

if (state.decoder) {
Expand Down Expand Up @@ -503,6 +520,7 @@ function onEofChunk(stream, state) {

function emitReadable(stream) {
var state = stream._readableState;
debug('emitReadable', state.needReadable, state.emittedReadable);
state.needReadable = false;

if (!state.emittedReadable) {
Expand All @@ -518,6 +536,7 @@ function emitReadable_(stream) {

if (!state.destroyed && (state.length || state.ended)) {
stream.emit('readable');
state.emittedReadable = false;
} // The stream needs another readable event if
// 1. It is not flowing, as the flow mechanism will take
// care of it.
Expand Down Expand Up @@ -583,7 +602,7 @@ function maybeReadMore_(stream, state) {


Readable.prototype._read = function (n) {
this.emit('error', new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
};

Readable.prototype.pipe = function (dest, pipeOpts) {
Expand Down Expand Up @@ -682,7 +701,7 @@ Readable.prototype.pipe = function (dest, pipeOpts) {
debug('onerror', er);
unpipe();
dest.removeListener('error', onerror);
if (EElistenerCount(dest, 'error') === 0) dest.emit('error', er);
if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
} // Make sure our error handler is attached before userland ones.


Expand Down Expand Up @@ -986,8 +1005,6 @@ Readable.prototype.wrap = function (stream) {

if (typeof Symbol === 'function') {
Readable.prototype[Symbol.asyncIterator] = function () {
emitExperimentalWarning('Readable[Symbol.asyncIterator]');

if (createReadableStreamAsyncIterator === undefined) {
createReadableStreamAsyncIterator = require('./internal/streams/async_iterator');
}
Expand Down Expand Up @@ -1075,9 +1092,29 @@ function endReadableNT(state, stream) {
state.endEmitted = true;
stream.readable = false;
stream.emit('end');

if (state.autoDestroy) {
// In case of duplex streams we need a way to detect
// if the writable side is ready for autoDestroy as well
var wState = stream._writableState;

if (!wState || wState.autoDestroy && wState.finished) {
stream.destroy();
}
}
}
}

if (typeof Symbol === 'function') {
Readable.from = function (iterable, opts) {
if (from === undefined) {
from = require('./internal/streams/from');
}

return from(Readable, iterable, opts);
};
}

function indexOf(xs, x) {
for (var i = 0, l = xs.length; i < l; i++) {
if (xs[i] === x) return i;
Expand Down
28 changes: 21 additions & 7 deletions lib/_stream_writable.js
Expand Up @@ -94,6 +94,8 @@ var _require$codes = require('../errors').codes,
ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;

var errorOrDestroy = destroyImpl.errorOrDestroy;

require('inherits')(Writable, Stream);

function nop() {}
Expand Down Expand Up @@ -173,7 +175,9 @@ function WritableState(options, stream, isDuplex) {

this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.

this.emitClose = options.emitClose !== false; // count buffered requests
this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')

this.autoDestroy = !!options.autoDestroy; // count buffered requests

this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
// one allocated and free to use, and we maintain at most two
Expand Down Expand Up @@ -250,13 +254,13 @@ function Writable(options) {


Writable.prototype.pipe = function () {
this.emit('error', new ERR_STREAM_CANNOT_PIPE());
errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
};

function writeAfterEnd(stream, cb) {
var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb

stream.emit('error', er);
errorOrDestroy(stream, er);
process.nextTick(cb, er);
} // Checks that a user-supplied chunk is valid, especially for the particular
// mode the stream is in. Currently this means that `null` is never accepted
Expand All @@ -273,7 +277,7 @@ function validChunk(stream, state, chunk, cb) {
}

if (er) {
stream.emit('error', er);
errorOrDestroy(stream, er);
process.nextTick(cb, er);
return false;
}
Expand Down Expand Up @@ -417,13 +421,13 @@ function onwriteError(stream, state, sync, er, cb) {

process.nextTick(finishMaybe, stream, state);
stream._writableState.errorEmitted = true;
stream.emit('error', er);
errorOrDestroy(stream, er);
} else {
// the caller expect this to happen before if
// it is async
cb(er);
stream._writableState.errorEmitted = true;
stream.emit('error', er); // this can emit finish, but finish must
errorOrDestroy(stream, er); // this can emit finish, but finish must
// always follow error

finishMaybe(stream, state);
Expand Down Expand Up @@ -587,7 +591,7 @@ function callFinal(stream, state) {
state.pendingcb--;

if (err) {
stream.emit('error', err);
errorOrDestroy(stream, err);
}

state.prefinished = true;
Expand Down Expand Up @@ -618,6 +622,16 @@ function finishMaybe(stream, state) {
if (state.pendingcb === 0) {
state.finished = true;
stream.emit('finish');

if (state.autoDestroy) {
// In case of duplex streams we need a way to detect
// if the readable side is ready for autoDestroy as well
var rState = stream._readableState;

if (!rState || rState.autoDestroy && rState.endEmitted) {
stream.destroy();
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/internal/streams/buffer_list.js
@@ -1,6 +1,8 @@
'use strict';

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

Expand Down

0 comments on commit 040b813

Please sign in to comment.