-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Pull from GitHub instead of npm
Fixes: #36 - fetch from ICU’s GitHub release instead of npm (ICU v50+) - set env FULL_ICU_PREFER_NPM=1 to prefer npm instead - add .eslint (as well as standard) - for ICU 67 and following, fetch from icu4c-___-data-_.zip - otherwise fetch from icu4c-src.zip for little endian - otherwise, use npm as before - work around ICU issue with data file name https://unicode-org.atlassian.net/browse/ICU-21764
- Loading branch information
Showing
15 changed files
with
355 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
env: { | ||
commonjs: true, | ||
es6: true, | ||
node: true | ||
}, | ||
extends: 'standard', | ||
globals: { | ||
Atomics: 'readonly', | ||
SharedArrayBuffer: 'readonly' | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018 | ||
}, | ||
rules: { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ node_modules | |
*.dat | ||
npm-debug.log | ||
/yarn.lock | ||
package-lock.json | ||
/.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
node_modules | ||
.svn | ||
.git | ||
npm-debug.log | ||
npm-debug.log | ||
/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: node_js | ||
node_js: | ||
- '8' | ||
- '10' | ||
- '11' | ||
- '12' | ||
script: | ||
- npm install | ||
- npm t | ||
cache: | ||
directories: | ||
- node_modules | ||
- ".nvm" | ||
# this is a comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved. | ||
|
||
// Install by fetching ICU source tarball | ||
// This will only work for little endian systems, but will work for ancient ICU (back to v50) | ||
|
||
const fs = require('fs') | ||
const { URL } = require('url') | ||
const process = require('process') | ||
const myFetch = require('./myFetch') | ||
const yauzl = require('yauzl') | ||
|
||
// var isglobal = process.env.npm_config_global === 'true'; | ||
|
||
module.exports = async function installFromGithub (fullIcu, advice) { | ||
// const icupkg = fullIcu.icupkg | ||
const { icudat, icuend } = fullIcu | ||
if (fs.existsSync(icudat)) { | ||
console.log(` √ ${icudat} (exists)`) | ||
return | ||
} | ||
|
||
// var cmdPath = nodePath = process.env.npm_node_execpath; | ||
|
||
// var npmPath = process.env.npm_execpath; | ||
|
||
// var args; | ||
// https://github.com/unicode-org/icu/releases/download/release-51-3/icu4c-51_3-src.zip | ||
const _baseUrl = process.env.FULL_ICU_BASEURL || 'https://github.com/unicode-org/icu/releases/' | ||
const baseUrl = new URL(_baseUrl) | ||
const versionsAsHyphen = fullIcu.icuver.replace(/\./g, '-') | ||
// ICU v67/v68 use "68.1" and "67.1" in the filename instead of 68_1 and 69_1 | ||
// https://unicode-org.atlassian.net/browse/ICU-21764 | ||
// Can remove this conditional if the files are updated later. | ||
const versionsAsUnderscore = (fullIcu.icumaj >= 69) ? fullIcu.icuver.replace(/\./g, '_') : fullIcu.icuver | ||
const tag = `release-${versionsAsHyphen}` | ||
const file = `icu4c-${versionsAsUnderscore}-data-bin-${icuend}.zip` | ||
const fullUrl = new URL(`./download/${tag}/${file}`, baseUrl) | ||
console.log(fullUrl.toString()) | ||
const [srcZip, tmpd] = await myFetch(fullUrl) | ||
|
||
console.log(srcZip, tmpd) | ||
// now, unpack it | ||
|
||
console.log(`Looking for ${icudat}`) | ||
return new Promise((resolve, reject) => | ||
yauzl.open(srcZip, { lazyEntries: true }, (err, zipfile) => { | ||
if (err) return reject(err) | ||
zipfile.readEntry() | ||
zipfile.on('end', () => reject(Error(`Not found in zipfile: ${icudat}`))) | ||
zipfile.on('entry', (entry) => { | ||
if (entry.fileName.endsWith('/')) { | ||
zipfile.readEntry() | ||
} else if (entry.fileName.endsWith(icudat) || entry.fileName.endsWith('/' + icudat)) { | ||
console.log('found ' + entry.fileName) | ||
zipfile.openReadStream(entry, (err, readStream) => { | ||
if (err) return reject(err) | ||
// if entry.file | ||
readStream.on('end', () => zipfile.readEntry()) | ||
const pipeOut = fs.createWriteStream(icudat) | ||
readStream.pipe(pipeOut) | ||
console.log(` √ ${icudat} (from ICU binary data tarball)`) | ||
return resolve() | ||
}) | ||
} else { | ||
zipfile.readEntry() // get next | ||
} | ||
}) | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved. | ||
|
||
// Install by fetching ICU source tarball | ||
// This will only work for little endian systems, but will work for ancient ICU (back to v50) | ||
|
||
const fs = require('fs') | ||
const { URL } = require('url') | ||
const process = require('process') | ||
const myFetch = require('./myFetch') | ||
const yauzl = require('yauzl') | ||
|
||
// var isglobal = process.env.npm_config_global === 'true'; | ||
|
||
module.exports = async function installFromGithub (fullIcu, advice) { | ||
const { icudat, icuend } = fullIcu | ||
|
||
if (fs.existsSync(icudat)) { | ||
console.log(` √ ${icudat} (exists)`) | ||
return | ||
} | ||
|
||
if (icuend !== 'l') { | ||
// Should not hit this, as versions 67 and prior are already in NPM | ||
console.error('Warning: this method probably will fail, because the ICU source tarball only contains little endian data.') | ||
} | ||
|
||
// var cmdPath = nodePath = process.env.npm_node_execpath; | ||
|
||
// var npmPath = process.env.npm_execpath; | ||
|
||
// var args; | ||
// https://github.com/unicode-org/icu/releases/download/release-51-3/icu4c-51_3-src.zip | ||
const _baseUrl = process.env.FULL_ICU_BASEURL || 'https://github.com/unicode-org/icu/releases/' | ||
const baseUrl = new URL(_baseUrl) | ||
const versionsAsHyphen = fullIcu.icuver.replace(/\./g, '-') | ||
const versionsAsUnderscore = fullIcu.icuver.replace(/\./g, '_') | ||
const tag = `release-${versionsAsHyphen}` | ||
const file = `icu4c-${versionsAsUnderscore}-src.zip` | ||
const fullUrl = new URL(`./download/${tag}/${file}`, baseUrl) | ||
console.log(fullUrl.toString()) | ||
const [srcZip, tmpd] = await myFetch(fullUrl) | ||
|
||
console.log(srcZip, tmpd) | ||
// now, unpack it | ||
|
||
console.log(`Looking for ${icudat}`) | ||
return new Promise((resolve, reject) => | ||
yauzl.open(srcZip, { lazyEntries: true }, (err, zipfile) => { | ||
if (err) return reject(err) | ||
zipfile.readEntry() | ||
zipfile.on('end', () => reject(Error(`Not found in zipfile: ${icudat}`))) | ||
zipfile.on('entry', (entry) => { | ||
if (entry.fileName.endsWith('/')) { | ||
zipfile.readEntry() | ||
} else if (entry.fileName.endsWith('/' + icudat)) { | ||
console.log('found ' + entry.fileName) | ||
zipfile.openReadStream(entry, (err, readStream) => { | ||
if (err) return reject(err) | ||
// if entry.file | ||
readStream.on('end', () => zipfile.readEntry()) | ||
const pipeOut = fs.createWriteStream(icudat) | ||
readStream.pipe(pipeOut) | ||
console.log(` √ ${icudat} (from ICU source tarball)`) | ||
return resolve() | ||
}) | ||
} else { | ||
zipfile.readEntry() // get next | ||
} | ||
}) | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved. | ||
|
||
const os = require('os') | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
function getFetcher (u) { | ||
if (u.protocol === 'https:') return require('https') | ||
if (u.protocol === 'http:') return require('http') | ||
return null | ||
} | ||
|
||
/** | ||
* @param {URL} fullUrl url to fetch | ||
* @returns {Promse<String[]>} filename, tmpdir | ||
*/ | ||
function myFetch (fullUrl) { | ||
return new Promise((resolve, reject) => { | ||
const fetcher = getFetcher(fullUrl) | ||
console.log('Fetch:', fullUrl.toString()) | ||
if (!fetcher) { | ||
return reject(Error(`Unknown URL protocol ${fullUrl.protocol} in ${fullUrl.toString()}`)) | ||
} | ||
|
||
fetcher.get(fullUrl, res => { | ||
const length = res.headers['content-length'] | ||
if (res.statusCode === 302 && res.headers.location) { | ||
return resolve(myFetch(new URL(res.headers.location))) | ||
} else if (res.statusCode !== 200) { | ||
return reject(Error(`Bad status code ${res.statusCode}`)) | ||
} | ||
const tmpd = fs.mkdtempSync(os.tmpdir()) | ||
const tmpf = path.join(tmpd, 'icu-download.zip') | ||
let gotSoFar = 0 | ||
console.dir(tmpd) | ||
|
||
res.on('data', data => { | ||
gotSoFar += data.length | ||
fs.appendFileSync(tmpf, data) | ||
// console.dir(res.headers); | ||
process.stdout.write(`${gotSoFar}/${length}\r`) | ||
// console.log(`chunk: ${data.length}`); | ||
}) | ||
res.on('end', () => { | ||
resolve([tmpf, tmpd]) | ||
console.log(`${gotSoFar}/${length}\n`) | ||
}) | ||
res.on('error', error => { | ||
fs.unlinkSync(tmpf) | ||
fs.rmdirSync(tmpd) | ||
console.error(error) | ||
return reject(error) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = myFetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const tap = require('tap') | ||
const fs = require('fs') | ||
const unzipOne = require('../unzipOne') | ||
|
||
tap.test('unzipOne', async t => { | ||
t.test('setup', t => { | ||
try { | ||
fs.unlinkSync('test/tmp/needle.txt') | ||
} catch (e) { /* ignore */ } | ||
t.end() | ||
}) | ||
t.test('no easteregg in haystack.zip', async t => { | ||
const ee = await unzipOne('./test/data/haystack.zip', 'easteregg.txt', './test/tmp/') | ||
t.notOk(ee, 'Did not expect to find easteregg in haystack: ' + ee) | ||
t.end() | ||
}) | ||
t.test('get needle.txt in haystack.zip', async t => { | ||
const ee = await unzipOne('./test/data/haystack.zip', 'needle.txt', './test/tmp/') | ||
t.ok(ee, 'Did expect to find needle.txt in haystack: ' + ee) | ||
const truism = fs.readFileSync('./test/tmp/needle.txt', 'utf-8') | ||
t.ok(truism) | ||
t.equal(truism.trim(), 'true') | ||
t.end() | ||
}) | ||
t.test('cleanup', t => { | ||
try { | ||
fs.unlinkSync('test/tmp/needle.txt') | ||
} catch (e) { /* ignore */ } | ||
t.end() | ||
}) | ||
t.end() | ||
}) |
Empty file.
Oops, something went wrong.