Skip to content

Commit de367a8

Browse files
authored
Merge pull request #53 from nodejs/pull-l-from-gh
Pull data files from ICU GitHub instead of npm
2 parents 0a1b7a4 + 255faa8 commit de367a8

File tree

18 files changed

+377
-15
lines changed

18 files changed

+377
-15
lines changed

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
env: {
3+
commonjs: true,
4+
es6: true,
5+
node: true
6+
},
7+
extends: 'standard',
8+
globals: {
9+
Atomics: 'readonly',
10+
SharedArrayBuffer: 'readonly'
11+
},
12+
parserOptions: {
13+
ecmaVersion: 2018
14+
},
15+
rules: {
16+
}
17+
}

.github/workflows/lint.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Lint
33
on: [push, pull_request]
44

55
jobs:
6-
build:
6+
lint:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
@@ -12,3 +12,12 @@ jobs:
1212
node-version: 16
1313
- run: npm i
1414
- run: npm run lint
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-node@v1
20+
with:
21+
node-version: 16
22+
- run: npm i
23+
- run: npm t

.github/workflows/test.yml renamed to .github/workflows/test-gh.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Integration Test
1+
name: Integration Test GitHub
22

33
on: [push, pull_request]
44

@@ -28,4 +28,4 @@ jobs:
2828
- name: Install full-icu
2929
run: docker run --rm -v $(pwd):/usr/src/app -w /usr/src/app ${{ matrix.container }} npm i --no-package-lock --unsafe-perm
3030
- name: Test full-icu
31-
run: docker run --rm -v $(pwd):/usr/src/app -w /usr/src/app ${{ matrix.container }} --icu-data-dir=. ./full-icu-test/test.js
31+
run: docker run --rm -e NODE_ICU_DATA=. -v $(pwd):/usr/src/app -w /usr/src/app ${{ matrix.container }} node ./full-icu-test/test.js

.github/workflows/test-npm.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Integration Test npm
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
container:
11+
- node:12
12+
- node:12-slim
13+
# Will fail on versions that aren't in icu4c-data
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v2
18+
with:
19+
repository: nodejs/full-icu-test
20+
path: full-icu-test
21+
- name: Install full-icu
22+
run: docker run --rm -v $(pwd):/usr/src/app -w /usr/src/app ${{ matrix.container }} env FULL_ICU_PREFER_NPM=1 npm i --no-package-lock --unsafe-perm
23+
- name: Test full-icu
24+
run: docker run --rm -e NODE_ICU_DATA=. -v $(pwd):/usr/src/app -w /usr/src/app ${{ matrix.container }} node ./full-icu-test/test.js

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
*.dat
33
npm-debug.log
44
/yarn.lock
5+
package-lock.json
6+
/.nyc_output

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
node_modules
33
.svn
44
.git
5-
npm-debug.log
5+
npm-debug.log
6+
/test

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
- '10'
5+
- '11'
6+
- '12'
7+
script:
8+
- npm install
9+
- npm t
10+
cache:
11+
directories:
12+
- node_modules
13+
- ".nvm"
14+
# this is a comment

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# full-icu-npm
22

3-
Install full ICU data
3+
Install full ICU data from GitHub or npm
44

55
### To use
66

77
`npm install full-icu`
88

9+
Note: Set env var `FULL_ICU_PREFER_NPM=true` to prefer using the `icu4c-data` npm module,
10+
otherwise the default is now to load from ICU4C’s GitHub release.
11+
912
### To install globally
1013

1114
`npm install -g full-icu`

install-gh-data.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved.
2+
3+
// Install by fetching ICU source tarball
4+
// This will only work for little endian systems, but will work for ancient ICU (back to v50)
5+
6+
const fs = require('fs')
7+
const { URL } = require('url')
8+
const process = require('process')
9+
const myFetch = require('./myFetch')
10+
const yauzl = require('yauzl')
11+
12+
module.exports = async function installFromGithub (fullIcu, advice) {
13+
const { icudat, icuend } = fullIcu
14+
if (fs.existsSync(icudat)) {
15+
console.log(` √ ${icudat} (exists)`)
16+
return
17+
}
18+
19+
// Example URL:
20+
// https://github.com/unicode-org/icu/releases/download/release-51-3/icu4c-51_3-src.zip
21+
const _baseUrl = process.env.FULL_ICU_BASEURL || 'https://github.com/unicode-org/icu/releases/'
22+
const baseUrl = new URL(_baseUrl)
23+
const versionsAsHyphen = fullIcu.icuver.replace(/\./g, '-')
24+
// ICU v67/v68 use "68.1" and "67.1" in the filename instead of 68_1 and 69_1
25+
// https://unicode-org.atlassian.net/browse/ICU-21764
26+
// Can remove this conditional if the files are updated later.
27+
const versionsAsUnderscore = (fullIcu.icumaj >= 69) ? fullIcu.icuver.replace(/\./g, '_') : fullIcu.icuver
28+
const tag = `release-${versionsAsHyphen}`
29+
const file = `icu4c-${versionsAsUnderscore}-data-bin-${icuend}.zip`
30+
const fullUrl = new URL(`./download/${tag}/${file}`, baseUrl)
31+
console.log(fullUrl.toString())
32+
const [srcZip, tmpd] = await myFetch(fullUrl)
33+
34+
console.log(srcZip, tmpd)
35+
36+
// now, unpack it
37+
console.log(`Looking for ${icudat}`)
38+
return new Promise((resolve, reject) =>
39+
yauzl.open(srcZip, { lazyEntries: true }, (err, zipfile) => {
40+
if (err) return reject(err)
41+
zipfile.readEntry()
42+
zipfile.on('end', () => reject(Error(`Not found in zipfile: ${icudat}`)))
43+
zipfile.on('entry', (entry) => {
44+
if (entry.fileName.endsWith('/')) {
45+
zipfile.readEntry()
46+
} else if (entry.fileName.endsWith(icudat) || entry.fileName.endsWith('/' + icudat)) {
47+
console.log('found ' + entry.fileName)
48+
zipfile.openReadStream(entry, (err, readStream) => {
49+
if (err) return reject(err)
50+
readStream.on('end', () => zipfile.readEntry())
51+
const pipeOut = fs.createWriteStream(icudat)
52+
readStream.pipe(pipeOut)
53+
console.log(` √ ${icudat} (from ICU binary data tarball)`)
54+
return resolve()
55+
})
56+
} else {
57+
zipfile.readEntry()
58+
}
59+
})
60+
}))
61+
}

install-gh.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (C) 2015-2016 IBM Corporation and Others. All Rights Reserved.
2+
3+
// Install by fetching ICU source tarball
4+
// This will only work for little endian systems, but will work for ancient ICU (back to v50)
5+
6+
const fs = require('fs')
7+
const { URL } = require('url')
8+
const process = require('process')
9+
const myFetch = require('./myFetch')
10+
const yauzl = require('yauzl')
11+
12+
module.exports = async function installFromGithub (fullIcu, advice) {
13+
const { icudat, icuend } = fullIcu
14+
15+
if (fs.existsSync(icudat)) {
16+
console.log(` √ ${icudat} (exists)`)
17+
return
18+
}
19+
20+
if (icuend !== 'l') {
21+
// Should not hit this, as versions 67 and prior are already in NPM
22+
console.error('Warning: this method probably will fail, because the ICU source tarball only contains little endian data.')
23+
}
24+
25+
// var args;
26+
// https://github.com/unicode-org/icu/releases/download/release-51-3/icu4c-51_3-src.zip
27+
const _baseUrl = process.env.FULL_ICU_BASEURL || 'https://github.com/unicode-org/icu/releases/'
28+
const baseUrl = new URL(_baseUrl)
29+
const versionsAsHyphen = fullIcu.icuver.replace(/\./g, '-')
30+
const versionsAsUnderscore = fullIcu.icuver.replace(/\./g, '_')
31+
const tag = `release-${versionsAsHyphen}`
32+
const file = `icu4c-${versionsAsUnderscore}-src.zip`
33+
const fullUrl = new URL(`./download/${tag}/${file}`, baseUrl)
34+
console.log(fullUrl.toString())
35+
const [srcZip, tmpd] = await myFetch(fullUrl)
36+
37+
console.log(srcZip, tmpd)
38+
39+
// now, unpack it
40+
console.log(`Looking for ${icudat}`)
41+
return new Promise((resolve, reject) =>
42+
yauzl.open(srcZip, { lazyEntries: true }, (err, zipfile) => {
43+
if (err) return reject(err)
44+
zipfile.readEntry()
45+
zipfile.on('end', () => reject(Error(`Not found in zipfile: ${icudat}`)))
46+
zipfile.on('entry', (entry) => {
47+
if (entry.fileName.endsWith('/')) {
48+
zipfile.readEntry()
49+
} else if (entry.fileName.endsWith('/' + icudat)) {
50+
console.log('found ' + entry.fileName)
51+
zipfile.openReadStream(entry, (err, readStream) => {
52+
if (err) return reject(err)
53+
readStream.on('end', () => zipfile.readEntry())
54+
const pipeOut = fs.createWriteStream(icudat)
55+
readStream.pipe(pipeOut)
56+
console.log(` √ ${icudat} (from ICU source tarball)`)
57+
return resolve()
58+
})
59+
} else {
60+
zipfile.readEntry()
61+
}
62+
})
63+
}))
64+
}

0 commit comments

Comments
 (0)