Skip to content

Commit 200b770

Browse files
josephperrottAndrewKushnir
authored andcommitted
build: revert back to downloading cldr-data directly rather than via npm (angular#39341)
Revert back to downloading cldr-data directly as the npm package seems to no longer be maintained and additionally, it carries a ~350mb cost in our node modules that is unnecessarily downloaded by most developers and on CI. PR Close angular#39341
1 parent 25e1432 commit 200b770

File tree

8 files changed

+237
-99
lines changed

8 files changed

+237
-99
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ baseline.json
4848

4949
# Ignore .history for the xyz.local-history VSCode extension
5050
.history
51+
52+
# CLDR data
53+
tools/gulp-tasks/cldr/cldr-data/

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ gulp.task('changelog', loadTask('changelog'));
3232
gulp.task('changelog:zonejs', loadTask('changelog-zonejs'));
3333
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});
3434
gulp.task('cldr:extract', loadTask('cldr', 'extract'));
35+
gulp.task('cldr:download', loadTask('cldr', 'download'));
3536
gulp.task('cldr:gen-closure-locale', loadTask('cldr', 'closure'));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
"check-side-effects": "0.0.21",
170170
"clang-format": "^1.4.0",
171171
"cldr": "4.10.0",
172-
"cldr-data": "36.0.0",
172+
"cldr-data-downloader": "0.3.2",
173173
"cldrjs": "0.5.0",
174174
"cli-progress": "^3.7.0",
175175
"conventional-changelog": "^2.0.3",

tools/gulp-tasks/cldr.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,29 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
const path = require('path');
910
const fs = require('fs');
1011

1112
module.exports = {
1213
extract: gulp => done => {
14+
if (!fs.existsSync(path.join(__dirname, 'cldr/cldr-data'))) {
15+
throw new Error(`You must run "gulp cldr:download" before you can extract the data`);
16+
}
1317
const extract = require('./cldr/extract');
1418
return extract(gulp, done);
1519
},
1620

21+
download: gulp => done => {
22+
const cldrDownloader = require('cldr-data-downloader');
23+
const cldrDataFolder = path.join(__dirname, 'cldr/cldr-data');
24+
if (fs.existsSync(cldrDataFolder)) {
25+
fs.rmdirSync(cldrDataFolder, {recursive: true});
26+
} else {
27+
fs.mkdirSync(cldrDataFolder);
28+
}
29+
cldrDownloader(path.join(__dirname, 'cldr/cldr-urls.json'), cldrDataFolder, {}, done);
30+
},
31+
1732
closure: gulp => done => {
1833
const {RELATIVE_I18N_DATA_FOLDER} = require('./cldr/extract');
1934
// tslint:disable-next-line:no-console

tools/gulp-tasks/cldr/cldr-data.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// tslint:disable:file-header
2+
3+
/**
4+
* Npm module for Unicode CLDR JSON data
5+
*
6+
* @license
7+
* Copyright 2013 Rafael Xavier de Souza
8+
* Released under the MIT license
9+
* https://github.com/rxaviers/cldr-data-npm/blob/master/LICENSE-MIT
10+
*/
11+
12+
'use strict';
13+
14+
const JSON_EXTENSION = /^(.*)\.json$/;
15+
16+
const assert = require('assert');
17+
const _fs = require('fs');
18+
const _path = require('path');
19+
20+
function argsToArray(arg) {
21+
return [].slice.call(arg, 0);
22+
}
23+
24+
function jsonFiles(dirName) {
25+
const fileList = _fs.readdirSync(_path.join(__dirname, 'cldr-data', dirName));
26+
27+
return fileList.reduce(function(sum, file) {
28+
if (JSON_EXTENSION.test(file)) {
29+
return sum.concat(file.match(JSON_EXTENSION)[1]);
30+
}
31+
}, []);
32+
}
33+
34+
function cldrData(path /*, ...*/) {
35+
assert(
36+
typeof path === 'string',
37+
'must include path (e.g., "main/en/numbers" or "supplemental/likelySubtags")');
38+
39+
if (arguments.length > 1) {
40+
return argsToArray(arguments).reduce(function(sum, path) {
41+
sum.push(cldrData(path));
42+
return sum;
43+
}, []);
44+
}
45+
return require('./cldr-data/' + path);
46+
}
47+
48+
function mainPathsFor(locales) {
49+
return locales.reduce(function(sum, locale) {
50+
const mainFiles = jsonFiles(_path.join('main', locale));
51+
mainFiles.forEach(function(mainFile) {
52+
sum.push(_path.join('main', locale, mainFile));
53+
});
54+
return sum;
55+
}, []);
56+
}
57+
58+
function supplementalPaths() {
59+
const supplementalFiles = jsonFiles('supplemental');
60+
61+
return supplementalFiles.map(function(supplementalFile) {
62+
return _path.join('supplemental', supplementalFile);
63+
});
64+
}
65+
66+
Object.defineProperty(cldrData, 'availableLocales', {
67+
get: function() {
68+
return cldrData('availableLocales').availableLocales;
69+
}
70+
});
71+
72+
cldrData.all = function() {
73+
const paths = supplementalPaths().concat(mainPathsFor(this.availableLocales));
74+
return cldrData.apply({}, paths);
75+
};
76+
77+
cldrData.entireMainFor = function(locale /*, ...*/) {
78+
assert(typeof locale === 'string', 'must include locale (e.g., "en")');
79+
return cldrData.apply({}, mainPathsFor(argsToArray(arguments)));
80+
};
81+
82+
cldrData.entireSupplemental = function() {
83+
return cldrData.apply({}, supplementalPaths());
84+
};
85+
86+
module.exports = cldrData;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"core": [
3+
"https://github.com/unicode-cldr/cldr-core/archive/36.0.0.zip",
4+
"https://github.com/unicode-cldr/cldr-segments-modern/archive/36.0.0.zip",
5+
"https://github.com/unicode-cldr/cldr-dates-full/archive/36.0.0.zip",
6+
"https://github.com/unicode-cldr/cldr-cal-buddhist-full/archive/36.0.0.zip",
7+
"https://github.com/unicode-cldr/cldr-cal-chinese-full/archive/36.0.0.zip",
8+
"https://github.com/unicode-cldr/cldr-cal-coptic-full/archive/36.0.0.zip",
9+
"https://github.com/unicode-cldr/cldr-cal-dangi-full/archive/36.0.0.zip",
10+
"https://github.com/unicode-cldr/cldr-cal-ethiopic-full/archive/36.0.0.zip",
11+
"https://github.com/unicode-cldr/cldr-cal-hebrew-full/archive/36.0.0.zip",
12+
"https://github.com/unicode-cldr/cldr-cal-indian-full/archive/36.0.0.zip",
13+
"https://github.com/unicode-cldr/cldr-cal-islamic-full/archive/36.0.0.zip",
14+
"https://github.com/unicode-cldr/cldr-cal-japanese-full/archive/36.0.0.zip",
15+
"https://github.com/unicode-cldr/cldr-cal-persian-full/archive/36.0.0.zip",
16+
"https://github.com/unicode-cldr/cldr-cal-roc-full/archive/36.0.0.zip",
17+
"https://github.com/unicode-cldr/cldr-localenames-full/archive/36.0.0.zip",
18+
"https://github.com/unicode-cldr/cldr-misc-full/archive/36.0.0.zip",
19+
"https://github.com/unicode-cldr/cldr-numbers-full/archive/36.0.0.zip",
20+
"https://github.com/unicode-cldr/cldr-units-full/archive/36.0.0.zip"
21+
]
22+
}

tools/gulp-tasks/cldr/extract.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const HEADER = `/**
4646

4747
// tslint:disable:no-console
4848
module.exports = (gulp, done) => {
49-
const cldrData = require('cldr-data');
49+
const cldrData = require('./cldr-data');
5050
const LOCALES = cldrData.availableLocales;
5151

5252
console.log(`Loading CLDR data...`);

0 commit comments

Comments
 (0)