Skip to content

Commit 7af74b0

Browse files
mcollinacalvinmetcalf
authored andcommitted
node v7.7.2 build (#262)
* replace bind() * re-add WriteReq and CorkedRequest constructors * Updated to v7.7.2, refactored the build to not crawl The new build system uses the tarball from nodejs.org. * try updating zuul * just remove android
1 parent 4dbe6e2 commit 7af74b0

File tree

49 files changed

+716
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+716
-470
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ matrix:
2828
env: TASK=test
2929
- node_js: 6
3030
env: TASK=test
31-
- node_js: 5
32-
env: TASK=browser BROWSER_NAME=android BROWSER_VERSION="4.0..latest"
3331
- node_js: 5
3432
env: TASK=browser BROWSER_NAME=ie BROWSER_VERSION="9..latest"
3533
- node_js: 5

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ npm install --save readable-stream
1818
This package is a mirror of the Streams2 and Streams3 implementations in
1919
Node-core.
2020

21-
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.3.0/docs/api/).
21+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.7.2/docs/api/).
2222

2323
If you want to guarantee a stable streams base, regardless of what version of
2424
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).

build/build.js

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#!/usr/bin/env node
22

3-
const hyperquest = require('hyperzip')(require('hyperdirect'))
3+
const hyperquest = require('hyperquest')
44
, bl = require('bl')
55
, fs = require('fs')
66
, path = require('path')
7-
, cheerio = require('cheerio')
7+
, tar = require('tar-fs')
8+
, gunzip = require('gunzip-maybe')
89
, babel = require('babel-core')
10+
, glob = require('glob')
11+
, pump = require('pump')
12+
, rimraf = require('rimraf')
913
, encoding = 'utf8'
10-
, urlRegex = /^https?:\/\//
14+
, urlRegex = /^https?:\/\//
1115
, nodeVersion = process.argv[2]
1216
, nodeVersionRegexString = '\\d+\\.\\d+\\.\\d+'
1317
, usageVersionRegex = RegExp('^' + nodeVersionRegexString + '$')
@@ -18,10 +22,10 @@ const hyperquest = require('hyperzip')(require('hyperdirect'))
1822
, files = require('./files')
1923
, testReplace = require('./test-replacements')
2024

21-
, srcurlpfx = `https://raw.githubusercontent.com/nodejs/node/v${nodeVersion}/`
22-
, libsrcurl = srcurlpfx + 'lib/'
23-
, testsrcurl = srcurlpfx + 'test/parallel/'
24-
, testlisturl = `https://github.com/nodejs/node/tree/v${nodeVersion}/test/parallel`
25+
, downloadurl = `https://nodejs.org/dist/v${nodeVersion}/node-v${nodeVersion}.tar.gz`
26+
, src = path.join(__dirname, `node-v${nodeVersion}`)
27+
, libsrcurl = path.join(src, 'lib/')
28+
, testsrcurl = path.join(src, 'test/parallel/')
2529
, libourroot = path.join(__dirname, '../lib/')
2630
, testourroot = path.join(__dirname, '../test/parallel/')
2731

@@ -33,16 +37,19 @@ if (!usageVersionRegex.test(nodeVersion)) {
3337

3438
// `inputLoc`: URL or local path.
3539
function processFile (inputLoc, out, replacements) {
36-
var file = urlRegex.test(inputLoc) ?
37-
hyperquest(inputLoc) :
38-
fs.createReadStream(inputLoc, encoding)
40+
var file = fs.createReadStream(inputLoc, encoding)
3941

4042
file.pipe(bl(function (err, data) {
4143
if (err) throw err
4244

45+
console.log('Processing', inputLoc)
4346
data = data.toString()
4447
replacements.forEach(function (replacement) {
45-
data = data.replace.apply(data, replacement)
48+
const regexp = replacement[0]
49+
var arg2 = replacement[1]
50+
if (typeof arg2 === 'function')
51+
arg2 = arg2.bind(data)
52+
data = data.replace(regexp, arg2)
4653
})
4754
if (inputLoc.slice(-3) === '.js') {
4855
const transformed = babel.transform(data, {
@@ -69,7 +76,7 @@ function deleteOldTests(){
6976
const files = fs.readdirSync(path.join(__dirname, '..', 'test', 'parallel'));
7077
for (let file of files) {
7178
let name = path.join(__dirname, '..', 'test', 'parallel', file);
72-
console.log('removing', name);
79+
console.log('Removing', name);
7380
fs.unlinkSync(name);
7481
}
7582
}
@@ -94,43 +101,73 @@ function processTestFile (file) {
94101
}
95102

96103
//--------------------------------------------------------------------
97-
// Grab & process files in ../lib/
104+
// Download the release from nodejs.org
105+
console.log(`Downloading ${downloadurl}`)
106+
pump(
107+
hyperquest(downloadurl),
108+
gunzip(),
109+
tar.extract(__dirname),
110+
function (err) {
111+
if (err) {
112+
throw err
113+
}
98114

99-
Object.keys(files).forEach(processLibFile)
100115

101-
// delete the current contents of test/parallel so if node removes any tests
102-
// they are removed here
103-
deleteOldTests();
116+
//--------------------------------------------------------------------
117+
// Grab & process files in ../lib/
104118

105-
//--------------------------------------------------------------------
106-
// Discover, grab and process all test-stream* files on nodejs/node
119+
Object.keys(files).forEach(processLibFile)
107120

108-
hyperquest(testlisturl).pipe(bl(function (err, data) {
109-
if (err)
110-
throw err
111121

112-
var $ = cheerio.load(data.toString())
122+
//--------------------------------------------------------------------
123+
// Discover, grab and process all test-stream* files on the given release
113124

114-
$('table.files .js-navigation-open').each(function () {
115-
var file = $(this).text()
116-
if (/^test-stream/.test(file) && !/-wrap(?:-encoding)?\.js$/.test(file) && file !== 'test-stream2-httpclient-response-end.js' && file !== 'test-stream-base-no-abort.js' && file !== 'test-stream-preprocess.js' && file !== 'test-stream-inheritance.js')
117-
processTestFile(file)
118-
})
119-
}))
125+
glob(path.join(testsrcurl, 'test-stream*.js'), function (err, list) {
126+
if (err) {
127+
throw err
128+
}
120129

130+
list.forEach(function (file) {
131+
file = path.basename(file)
132+
if (!/-wrap(?:-encoding)?\.js$/.test(file) &&
133+
file !== 'test-stream2-httpclient-response-end.js' &&
134+
file !== 'test-stream-base-no-abort.js' &&
135+
file !== 'test-stream-preprocess.js' &&
136+
file !== 'test-stream-inheritance.js') {
137+
processTestFile(file)
138+
}
139+
})
140+
})
121141

122-
//--------------------------------------------------------------------
123-
// Grab the nodejs/node test/common.js
124142

125-
processFile(
126-
testsrcurl.replace(/parallel\/$/, 'common.js')
127-
, path.join(testourroot, '../common.js')
128-
, testReplace['common.js']
143+
//--------------------------------------------------------------------
144+
// Grab the nodejs/node test/common.js
145+
146+
processFile(
147+
testsrcurl.replace(/parallel\/$/, 'common.js')
148+
, path.join(testourroot, '../common.js')
149+
, testReplace['common.js']
150+
)
151+
152+
//--------------------------------------------------------------------
153+
// Update Node version in README
154+
155+
processFile(readmePath, readmePath, [
156+
[readmeVersionRegex, "$1" + nodeVersion]
157+
])
158+
}
129159
)
130160

131-
//--------------------------------------------------------------------
132-
// Update Node version in README
161+
// delete the current contents of test/parallel so if node removes any tests
162+
// they are removed here
163+
deleteOldTests();
133164

134-
processFile(readmePath, readmePath, [
135-
[readmeVersionRegex, "$1" + nodeVersion]
136-
])
165+
process.once('beforeExit', function () {
166+
rimraf(src, function (err) {
167+
if (err) {
168+
throw err
169+
}
170+
171+
console.log('Removed', src)
172+
})
173+
})

build/files.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,47 @@ const headRegexp = /(^module.exports = \w+;?)/m
183183
/if \(typeof Symbol === 'function' && Symbol\.hasInstance\) \{/,
184184
`if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {`
185185
]
186+
, removeOnWriteBind = [
187+
/onwrite\.bind\([^)]+?\)/,
188+
`function(er) { onwrite(stream, er); }`
189+
]
190+
, removeCorkedFinishBind = [
191+
/onCorkedFinish\.bind\([^)]+?\)/,
192+
function (match) {
193+
const code = this
194+
var src = /^function onCorkedFinish[^{]*?\{([\s\S]+?\r?\n)\}/m.exec(code)
195+
src = src[1].trim().replace(/corkReq/g, 'this').replace(/(\r?\n)/mg, ' $1')
196+
return `(err) => {\n${src}\n}`
197+
}
198+
]
199+
, removeOnCorkedFinish = [
200+
/^function onCorkedFinish[\s\S]+?\r?\n\}/m,
201+
''
202+
]
203+
, addConstructors = [
204+
headRegexp,
205+
`$1\n\nfunction WriteReq(chunk, encoding, cb) {
206+
this.chunk = chunk;
207+
this.encoding = encoding;
208+
this.callback = cb;
209+
this.next = null;
210+
}
211+
// It seems a linked list but it is not
212+
// there will be only 2 of these for each stream
213+
function CorkedRequest(state) {
214+
this.next = null;
215+
this.entry = null;
216+
this.finish = onCorkedFinish.bind(undefined, this, state);
217+
}\n\n`
218+
]
219+
, useWriteReq = [
220+
/state\.lastBufferedRequest = \{.+?\}/g,
221+
`state.lastBufferedRequest = new WriteReq(chunk, encoding, cb)`
222+
]
223+
, useCorkedRequest = [
224+
/var corkReq = [\s\S]+?(.+?)\.corkedRequestsFree = corkReq/g,
225+
`$1.corkedRequestsFree = new CorkedRequest($1)`
226+
]
186227

187228
module.exports['_stream_duplex.js'] = [
188229
requireReplacement
@@ -261,6 +302,12 @@ module.exports['_stream_writable.js'] = [
261302
, bufferShimFix
262303
, bufferStaticMethods
263304
, fixInstanceCheck
305+
, removeOnWriteBind
306+
, removeCorkedFinishBind
307+
, removeOnCorkedFinish
308+
, addConstructors
309+
, useWriteReq
310+
, useCorkedRequest
264311
]
265312
module.exports['internal/streams/BufferList.js'] = [
266313
bufferShimFix

build/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
"babel-plugin-transform-es2015-parameters": "^6.11.4",
1313
"babel-plugin-transform-es2015-shorthand-properties": "^6.8.0",
1414
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
15-
"bl": "~0.6.0",
16-
"cheerio": "~0.13.1",
17-
"hyperdirect": "0.0.0",
18-
"hyperzip": "0.0.0"
15+
"bl": "^1.2.0",
16+
"glob": "^7.1.1",
17+
"gunzip-maybe": "^1.4.0",
18+
"hyperquest": "^2.1.2",
19+
"pump": "^1.0.2",
20+
"rimraf": "^2.6.1",
21+
"tar-fs": "^1.15.1"
1922
}
2023
}

lib/_stream_readable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function ReadableState(options, stream) {
9292
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
9393

9494
// cast to ints.
95-
this.highWaterMark = ~ ~this.highWaterMark;
95+
this.highWaterMark = ~~this.highWaterMark;
9696

9797
// A linked list is used to store data chunks instead of an array because the
9898
// linked list can remove elements from the beginning faster than

lib/_stream_writable.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
module.exports = Writable;
88

9+
function WriteReq(chunk, encoding, cb) {
10+
this.chunk = chunk;
11+
this.encoding = encoding;
12+
this.callback = cb;
13+
this.next = null;
14+
}
15+
// It seems a linked list but it is not
16+
// there will be only 2 of these for each stream
17+
function CorkedRequest(state) {
18+
this.next = null;
19+
this.entry = null;
20+
this.finish = onCorkedFinish.bind(undefined, this, state);
21+
}
22+
923
/*<replacement>*/
1024
var processNextTick = require('process-nextick-args');
1125
/*</replacement>*/
@@ -77,7 +91,7 @@ function WritableState(options, stream) {
7791
this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm;
7892

7993
// cast to ints.
80-
this.highWaterMark = ~ ~this.highWaterMark;
94+
this.highWaterMark = ~~this.highWaterMark;
8195

8296
// drain event flag.
8397
this.needDrain = false;
@@ -232,20 +246,16 @@ function writeAfterEnd(stream, cb) {
232246
processNextTick(cb, er);
233247
}
234248

235-
// If we get something that is not a buffer, string, null, or undefined,
236-
// and we're not in objectMode, then that's an error.
237-
// Otherwise stream chunks are all considered to be of length=1, and the
238-
// watermarks determine how many objects to keep in the buffer, rather than
239-
// how many bytes or characters.
249+
// Checks that a user-supplied chunk is valid, especially for the particular
250+
// mode the stream is in. Currently this means that `null` is never accepted
251+
// and undefined/non-string values are only allowed in object mode.
240252
function validChunk(stream, state, chunk, cb) {
241253
var valid = true;
242254
var er = false;
243-
// Always throw error if a null is written
244-
// if we are not in object mode then throw
245-
// if it is not a buffer, string, or undefined.
255+
246256
if (chunk === null) {
247257
er = new TypeError('May not write null values to stream');
248-
} else if (!Buffer.isBuffer(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
258+
} else if (typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
249259
er = new TypeError('Invalid non-string/buffer chunk');
250260
}
251261
if (er) {
@@ -259,19 +269,20 @@ function validChunk(stream, state, chunk, cb) {
259269
Writable.prototype.write = function (chunk, encoding, cb) {
260270
var state = this._writableState;
261271
var ret = false;
272+
var isBuf = Buffer.isBuffer(chunk);
262273

263274
if (typeof encoding === 'function') {
264275
cb = encoding;
265276
encoding = null;
266277
}
267278

268-
if (Buffer.isBuffer(chunk)) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
279+
if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
269280

270281
if (typeof cb !== 'function') cb = nop;
271282

272-
if (state.ended) writeAfterEnd(this, cb);else if (validChunk(this, state, chunk, cb)) {
283+
if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
273284
state.pendingcb++;
274-
ret = writeOrBuffer(this, state, chunk, encoding, cb);
285+
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
275286
}
276287

277288
return ret;
@@ -311,10 +322,11 @@ function decodeChunk(state, chunk, encoding) {
311322
// if we're already writing something, then just put this
312323
// in the queue, and wait our turn. Otherwise, call _write
313324
// If we return false, then we need a drain event, so set that flag.
314-
function writeOrBuffer(stream, state, chunk, encoding, cb) {
315-
chunk = decodeChunk(state, chunk, encoding);
316-
317-
if (Buffer.isBuffer(chunk)) encoding = 'buffer';
325+
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
326+
if (!isBuf) {
327+
chunk = decodeChunk(state, chunk, encoding);
328+
if (Buffer.isBuffer(chunk)) encoding = 'buffer';
329+
}
318330
var len = state.objectMode ? 1 : chunk.length;
319331

320332
state.length += len;
@@ -383,8 +395,8 @@ function onwrite(stream, er) {
383395
asyncWrite(afterWrite, stream, state, finished, cb);
384396
/*</replacement>*/
385397
} else {
386-
afterWrite(stream, state, finished, cb);
387-
}
398+
afterWrite(stream, state, finished, cb);
399+
}
388400
}
389401
}
390402

@@ -535,7 +547,6 @@ function CorkedRequest(state) {
535547

536548
this.next = null;
537549
this.entry = null;
538-
539550
this.finish = function (err) {
540551
var entry = _this.entry;
541552
_this.entry = null;

0 commit comments

Comments
 (0)