Skip to content

Commit 5dd33eb

Browse files
authored
Merge pull request nodejs#2 from rvagg/update-to-latest-core
Updated to node v7.8.0
2 parents 0cd36da + 53f692c commit 5dd33eb

File tree

14 files changed

+1333
-659
lines changed

14 files changed

+1333
-659
lines changed

LICENSE

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
1-
Copyright Joyent, Inc. and other Node contributors.
2-
3-
Permission is hereby granted, free of charge, to any person obtaining a
4-
copy of this software and associated documentation files (the
5-
"Software"), to deal in the Software without restriction, including
6-
without limitation the rights to use, copy, modify, merge, publish,
7-
distribute, sublicense, and/or sell copies of the Software, and to permit
8-
persons to whom the Software is furnished to do so, subject to the
9-
following conditions:
10-
11-
The above copyright notice and this permission notice shall be included
12-
in all copies or substantial portions of the Software.
13-
14-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
USE OR OTHER DEALINGS IN THE SOFTWARE.
1+
Node.js is licensed for use as follows:
2+
3+
"""
4+
Copyright Node.js contributors. All rights reserved.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to
8+
deal in the Software without restriction, including without limitation the
9+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
sell copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
IN THE SOFTWARE.
23+
"""
24+
25+
This license applies to parts of Node.js originating from the
26+
https://github.com/joyent/node repository:
27+
28+
"""
29+
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
30+
Permission is hereby granted, free of charge, to any person obtaining a copy
31+
of this software and associated documentation files (the "Software"), to
32+
deal in the Software without restriction, including without limitation the
33+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
34+
sell copies of the Software, and to permit persons to whom the Software is
35+
furnished to do so, subject to the following conditions:
36+
37+
The above copyright notice and this permission notice shall be included in
38+
all copies or substantial portions of the Software.
39+
40+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
46+
IN THE SOFTWARE.
47+
"""
48+

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1-
**string_decoder.js** (`require('string_decoder')`) from Node.js core
1+
# string_decoder
22

3-
Copyright Joyent, Inc. and other Node contributors. See LICENCE file for details.
3+
***Node-core v7.0.0 string_decoder for userland***
44

5-
Version numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10. **Prefer the stable version over the unstable.**
65

7-
The *build/* directory contains a build script that will scrape the source from the [joyent/node](https://github.com/joyent/node) repo given a specific Node version.
6+
[![NPM](https://nodei.co/npm/string_decoder.png?downloads=true&downloadRank=true)](https://nodei.co/npm/string_decoder/)
7+
[![NPM](https://nodei.co/npm-dl/string_decoder.png?&months=6&height=3)](https://nodei.co/npm/string_decoder/)
8+
9+
10+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/string_decoder.svg)](https://saucelabs.com/u/string_decoder)
11+
12+
```bash
13+
npm install --save string_decoder
14+
```
15+
16+
***Node-core string_decoderstring_decoder for userland***
17+
18+
This package is a mirror of the string_decoder implementation in Node-core.
19+
20+
Full documentation may be found on the [Node.js website](https://nodejs.org/dist/v7.8.0/docs/api/).
21+
22+
As of version 1.0.0 **string_decoder** uses semantic versioning.
23+
24+
## Previous versions
25+
26+
Previous version numbers match the versions found in Node core, e.g. 0.10.24 matches Node 0.10.24, likewise 0.11.10 matches Node 0.11.10.
27+
28+
## Update
29+
30+
The *build/* directory contains a build script that will scrape the source from the [nodejs/node](https://github.com/nodejs/node) repo given a specific Node version.

build/build.js

Lines changed: 119 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,89 @@
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')
8-
7+
, tar = require('tar-fs')
8+
, gunzip = require('gunzip-maybe')
9+
, babel = require('babel-core')
10+
, glob = require('glob')
11+
, pump = require('pump')
12+
, rimraf = require('rimraf')
13+
, encoding = 'utf8'
14+
, urlRegex = /^https?:\/\//
15+
, nodeVersion = process.argv[2]
16+
, nodeVersionRegexString = '\\d+\\.\\d+\\.\\d+'
17+
, usageVersionRegex = RegExp('^' + nodeVersionRegexString + '$')
18+
, readmeVersionRegex =
19+
RegExp('((?:Node-core )|(?:https\:\/\/nodejs\.org\/dist\/)v)' + nodeVersionRegexString, 'g')
20+
21+
, readmePath = path.join(__dirname, '..', 'README.md')
922
, files = require('./files')
1023
, testReplace = require('./test-replacements')
1124

12-
, srcurlpfx = 'https://raw.github.com/joyent/node/v' + process.argv[2] + '-release/'
13-
, libsrcurl = srcurlpfx + 'lib/'
14-
, testsrcurl = srcurlpfx + 'test/simple/'
15-
, testlisturl = 'https://github.com/joyent/node/tree/v' + process.argv[2] + '-release/test/simple'
16-
, libourroot = path.join(__dirname, '../')
17-
, testourroot = path.join(__dirname, '../test/simple/')
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/')
29+
, libourroot = path.join(__dirname, '../lib/')
30+
, testourroot = path.join(__dirname, '../test/parallel/')
1831

1932

20-
function processFile (url, out, replacements) {
21-
hyperquest(url).pipe(bl(function (err, data) {
22-
if (err)
23-
throw err
33+
if (!usageVersionRegex.test(nodeVersion)) {
34+
console.error('Usage: build.js xx.yy.zz')
35+
return process.exit(1);
36+
}
37+
38+
// `inputLoc`: URL or local path.
39+
function processFile (inputLoc, out, replacements) {
40+
var file = fs.createReadStream(inputLoc, encoding)
2441

42+
file.pipe(bl(function (err, data) {
43+
if (err) throw err
44+
45+
console.log('Processing', inputLoc)
2546
data = data.toString()
2647
replacements.forEach(function (replacement) {
27-
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)
2853
})
29-
30-
fs.writeFile(out, data, 'utf8', function (err) {
31-
if (err)
32-
throw err
54+
if (inputLoc.slice(-3) === '.js') {
55+
const transformed = babel.transform(data, {
56+
plugins: [
57+
'transform-es2015-parameters',
58+
'transform-es2015-arrow-functions',
59+
'transform-es2015-block-scoping',
60+
'transform-es2015-template-literals',
61+
'transform-es2015-shorthand-properties',
62+
'transform-es2015-for-of',
63+
'transform-es2015-destructuring'
64+
]
65+
})
66+
data = transformed.code
67+
}
68+
fs.writeFile(out, data, encoding, function (err) {
69+
if (err) throw err
3370

3471
console.log('Wrote', out)
3572
})
3673
}))
3774
}
38-
75+
function deleteOldTests(){
76+
const files = fs.readdirSync(path.join(__dirname, '..', 'test', 'parallel'));
77+
for (let file of files) {
78+
let name = path.join(__dirname, '..', 'test', 'parallel', file);
79+
console.log('Removing', name);
80+
fs.unlinkSync(name);
81+
}
82+
}
3983
function processLibFile (file) {
4084
var replacements = files[file]
4185
, url = libsrcurl + file
42-
, out = path.join(libourroot, replacements.out || file)
86+
, out = path.join(libourroot, file)
4387

4488
processFile(url, out, replacements)
4589
}
@@ -56,39 +100,68 @@ function processTestFile (file) {
56100
processFile(url, out, replacements)
57101
}
58102

103+
//--------------------------------------------------------------------
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+
}
59114

60-
if (!/0\.1\d\.\d+/.test(process.argv[2])) {
61-
console.log('Usage: build.js <node version>')
62-
return process.exit(-1)
63-
}
64115

116+
//--------------------------------------------------------------------
117+
// Grab & process files in ../lib/
65118

66-
//--------------------------------------------------------------------
67-
// Grab & process files in ../lib/
119+
Object.keys(files).forEach(processLibFile)
68120

69-
Object.keys(files).forEach(processLibFile)
70121

71-
//--------------------------------------------------------------------
72-
// Discover, grab and process all test-string-decoder* files on joyent/node
122+
//--------------------------------------------------------------------
123+
// Discover, grab and process all test-stream* files on the given release
124+
125+
glob(path.join(testsrcurl, 'test-string-decoder*.js'), function (err, list) {
126+
if (err) {
127+
throw err
128+
}
73129

74-
hyperquest(testlisturl).pipe(bl(function (err, data) {
75-
if (err)
76-
throw err
130+
list.forEach(function (file) {
131+
file = path.basename(file)
132+
processTestFile(file)
133+
})
134+
})
77135

78-
var $ = cheerio.load(data.toString())
79136

80-
$('table.files .js-directory-link').each(function () {
81-
var file = $(this).text()
82-
if (/^test-string-decoder/.test(file) || file == 'common.js')
83-
processTestFile(file)
84-
})
85-
}))
137+
//--------------------------------------------------------------------
138+
// Grab the nodejs/node test/common.js
86139

87-
//--------------------------------------------------------------------
88-
// Grab the joyent/node test/common.js
140+
processFile(
141+
testsrcurl.replace(/parallel\/$/, 'common.js')
142+
, path.join(testourroot, '../common.js')
143+
, testReplace['common.js']
144+
)
89145

90-
processFile(
91-
testsrcurl + '../common.js'
92-
, path.join(testourroot, '../common.js')
93-
, testReplace['common.js']
94-
)
146+
//--------------------------------------------------------------------
147+
// Update Node version in README
148+
149+
processFile(readmePath, readmePath, [
150+
[readmeVersionRegex, "$1" + nodeVersion]
151+
])
152+
}
153+
)
154+
155+
// delete the current contents of test/parallel so if node removes any tests
156+
// they are removed here
157+
deleteOldTests();
158+
159+
process.once('beforeExit', function () {
160+
rimraf(src, function (err) {
161+
if (err) {
162+
throw err
163+
}
164+
165+
console.log('Removed', src)
166+
})
167+
})

build/files.js

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,78 @@
88

99
module.exports['string_decoder.js'] = [
1010

11-
// pull in Bufer as a require
12-
// add Buffer.isEncoding where missing
11+
// we do not need internal/util anymore
1312
[
14-
/^(\/\/ USE OR OTHER DEALINGS IN THE SOFTWARE\.)/m
15-
, '$1\n\nvar Buffer = require(\'buffer\').Buffer;'
16-
+ '\n'
17-
+ '\nvar isBufferEncoding = Buffer.isEncoding'
13+
/const internalUtil = require\('internal\/util'\);/
14+
, ''
15+
]
16+
17+
, [
18+
/const Buffer = require\('buffer'\).Buffer;/
19+
, 'var Buffer = require(\'buffer\').Buffer;\n' +
20+
'var bufferShim = require(\'buffer-shims\');'
21+
]
22+
23+
// allocUnsafe
24+
25+
, [
26+
/Buffer\.((?:alloc)|(?:allocUnsafe)|(?:from))/g,
27+
'bufferShim.$1'
28+
]
29+
30+
// add Buffer.isEncoding where missing
31+
, [
32+
/const isEncoding = Buffer\[internalUtil.kIsEncodingSymbol\];/
33+
, '\nvar isEncoding = Buffer.isEncoding'
1834
+ '\n || function(encoding) {'
35+
+ '\n encoding = \'\' + encoding'
1936
+ '\n switch (encoding && encoding.toLowerCase()) {'
2037
+ '\n case \'hex\': case \'utf8\': case \'utf-8\': case \'ascii\': case \'binary\': case \'base64\': case \'ucs2\': case \'ucs-2\': case \'utf16le\': case \'utf-16le\': case \'raw\': return true;'
2138
+ '\n default: return false;'
2239
+ '\n }'
2340
+ '\n }'
2441
+ '\n'
2542

43+
+ '\nfunction _normalizeEncoding(enc) {'
44+
+ '\n if (!enc) return \'utf8\';'
45+
+ '\n var retried;'
46+
+ '\n while (true) {'
47+
+ '\n switch (enc) {'
48+
+ '\n case \'utf8\':'
49+
+ '\n case \'utf-8\':'
50+
+ '\n return \'utf8\';'
51+
+ '\n case \'ucs2\':'
52+
+ '\n case \'ucs-2\':'
53+
+ '\n case \'utf16le\':'
54+
+ '\n case \'utf-16le\':'
55+
+ '\n return \'utf16le\';'
56+
+ '\n case \'latin1\':'
57+
+ '\n case \'binary\':'
58+
+ '\n return \'latin1\';'
59+
+ '\n case \'base64\':'
60+
+ '\n case \'ascii\':'
61+
+ '\n case \'hex\':'
62+
+ '\n return enc;'
63+
+ '\n default:'
64+
+ '\n if (retried) return; // undefined'
65+
+ '\n enc = (\'\' + enc).toLowerCase();'
66+
+ '\n retried = true;'
67+
+ '\n }'
68+
+ '\n }'
69+
+ '\n };'
2670
]
2771

72+
2873
// use custom Buffer.isEncoding reference
2974
, [
3075
/Buffer\.isEncoding\(/g
31-
, 'isBufferEncoding\('
76+
, 'isEncoding\('
3277
]
3378

34-
]
79+
// use _normalizeEncoding everywhere
80+
, [
81+
/internalUtil\.normalizeEncoding/g
82+
, '_normalizeEncoding'
83+
]
3584

36-
module.exports['string_decoder.js'].out = 'index.js'
85+
]

0 commit comments

Comments
 (0)