8000 Updated to node v7.8.0. · rvagg/archived-string_decoder@1ea0385 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 5, 2018. It is now read-only.

Commit 1ea0385

Browse files
committed
Updated to node v7.8.0.
1 parent 0cd36da commit 1ea0385

13 files changed

+1219
-641
lines changed

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
**string_decoder.js** (`require('string_decoder')`) from Node.js core
2-
3-
Copyright Joyent, Inc. and other Node contributors. See LICENCE file for details.
4-
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.**
6-
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.

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: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
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+
// add Buffer.isEncoding where missing
18+
, [
19+
/const isEncoding = Buffer\[internalUtil.kIsEncodingSymbol\];/
20+
, '\nvar isEncoding = Buffer.isEncoding'
1821
+ '\n || function(encoding) {'
1922
+ '\n switch (encoding && encoding.toLowerCase()) {'
2023
+ '\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;'
@@ -23,14 +26,46 @@ module.exports['string_decoder.js'] = [
2326
+ '\n }'
2427
+ '\n'
2528

29+
+ '\nfunction _normalizeEncoding(enc) {'
30+
+ '\n if (!enc) return \'utf8\';'
31+
+ '\n var retried;'
32+
+ '\n while (true) {'
33+
+ '\n switch (enc) {'
34+
+ '\n case \'utf8\':'
35+
+ '\n case \'utf-8\':'
36+
+ '\n return \'utf8\';'
37+
+ '\n case \'ucs2\':'
38+
+ '\n case \'ucs-2\':'
39+
+ '\n case \'utf16le\':'
40+
+ '\n case \'utf-16le\':'
41+
+ '\n return \'utf16le\';'
42+
+ '\n case \'latin1\':'
43+
+ '\n case \'binary\':'
44+
+ '\n return \'latin1\';'
45+
+ '\n case \'base64\':'
46+
+ '\n case \'ascii\':'
47+
+ '\n case \'hex\':'
48+
+ '\n return enc;'
49+
+ '\n default:'
50+
+ '\n if (retried) return; // undefined'
51+
+ '\n enc = (\'\' + enc).toLowerCase();'
52+
+ '\n retried = true;'
53+
+ '\n }'
54+
+ '\n }'
55+
+ '\n };'
2656
]
2757

58+
2859
// use custom Buffer.isEncoding reference
2960
, [
3061
/Buffer\.isEncoding\(/g
31-
, 'isBufferEncoding\('
62+
, 'isEncoding\('
3263
]
3364

34-
]
65+
// use _normalizeEncoding everywhere
66+
, [
67+
/internalUtil\.normalizeEncoding/g
68+
, '_normalizeEncoding'
69+
]
3570

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

build/package.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44
"description": "",
55
"main": "build.js",
66
"dependencies": {
7-
"bl": "~0.6.0",
8-
"hyperzip": "0.0.0",
9-
"hyperdirect": "0.0.0",
10-
"cheerio": "~0.13.1"
7+
"babel-core": "^6.5.2",
8+
"babel-plugin-transform-es2015-arrow-functions": "^6.5.2",
9+
"babel-plugin-transform-es2015-block-scoping": "^6.5.0",
10+
"babel-plugin-transform-es2015-destructuring": "^6.18.0",
11+
"babel-plugin-transform-es2015-for-of": "^6.8.0",
12+
"babel-plugin-transform-es2015-parameters": "^6.11.4",
13+
"babel-plugin-transform-es2015-shorthand-properties": "^6.8.0",
14+
"babel-plugin-transform-es2015-template-literals": "^6.8.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"
1122
}
1223
}

build/test-replacements.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,24 @@ module.exports['common.js'] = [
2121
/^ global];$/m
2222
, ' global].filter(Boolean);'
2323
]
24+
25+
, [
26+
/^/
27+
, 'require(\'babel-polyfill\');'
28+
]
29+
30+
, [
31+
/^( for \(var x in global\) \{|function leakedGlobals\(\) \{)$/m
32+
, ' /*<replacement>*/\n'
33+
+ ' if (typeof constructor == \'function\')\n'
34+
+ ' knownGlobals.push(constructor);\n'
35+
+ ' if (typeof DTRACE_NET_SOCKET_READ == \'function\')\n'
36+
+ ' knownGlobals.push(DTRACE_NET_SOCKET_READ);\n'
37+
+ ' if (typeof DTRACE_NET_SOCKET_WRITE == \'function\')\n'
38+
+ ' knownGlobals.push(DTRACE_NET_SOCKET_WRITE);\n'
39+
+ ' if (global.__coverage__)\n'
40+
+ ' knownGlobals.push(__coverage__);\n'
41+
+ '\'core,__core-js_shared__,Promise,Map,Set,WeakMap,WeakSet,Reflect,System,asap,Observable,regeneratorRuntime,_babelPolyfill\'.split(\',\').filter(function (item) { return typeof global[item] !== undefined}).forEach(function (item) {knownGlobals.push(global[item])})'
42+
+ ' /*</replacement>*/\n\n$1'
43+
]
2444
]

0 commit comments

Comments
 (0)
0