Skip to content

Commit

Permalink
remove references to gzip'd CLDR data
Browse files Browse the repository at this point in the history
This involves a bunch of somewhat unrelated changes that for various
reasons cannot be made separately.

Firstly, don't prune alternate CLDR formats during install. The gains
are negligible considering the cost of bandwidth and disk writing has
already been paid.

Additionally, the postinstall prevents a vanilla 'npm install && npm
test && npm publish' workflow from publishing a valid package because it
prunes the CLDR data based on the version of node used to publish the
module.

This fixes #51

Secondly, we need to fix the problem of node 0.10 seeing the gz version
of the file because if it tries to load it, it will bail because it
does't have a synchronous gunzip API. To fix that, we have to prevent
strong-globalize from even looking at the gz version of the file.

Thirdly, we need to update the various bits of tests that were in place
to support this gz/non-gz behaviour split.

Now we have a bunch of dead code and an unuzed gz file, so remove them.

And that is how we end up with this larger-than-it-should-be commit
instead of a bunch of discrete changes.
  • Loading branch information
rmg committed Jul 26, 2016
1 parent 58f0090 commit 56421b9
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 143 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,6 @@ You can safely ignore these warnings because `strong-globalize` statically bundl
npm WARN EPEERINVALID globalize@1.1.1 requires a peer of cldr-data@>=25 but none was installed.
npm WARN EPEERINVALID cldrjs@0.4.4 requires a peer of cldr-data@>=25 but none was installed.
```
You can safely ignore this warning on Node.js >= 0.12.
```js
npm WARN engine node-zlib-backport@0.11.15: wanted: {"node":">=0.10 <0.11"} ...
```

### usage: `slt-globalize [options]`

Expand Down
Binary file removed cldr/cldr_29.0.1.gz
Binary file not shown.
4 changes: 1 addition & 3 deletions lib/globalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var pathUtil = require('path');
var translate = require('./translate');
var util = require('util');
var YAML = require('yamljs');
var zlib = require('zlib');

exports.setDefaultLanguage = setDefaultLanguage;
exports.setRootDir = helper.setRootDir;
Expand Down Expand Up @@ -393,12 +392,11 @@ function loadCldr(lang) {
assert(global.STRONGLOOP_GLB && (!global.STRONGLOOP_GLB.bundles ||
!global.STRONGLOOP_GLB.bundles[lang]), 'CLDR already loaded for ' + lang);
var cldrDir = pathUtil.join(__dirname, '..', 'cldr');
helper.enumerateFilesSync(cldrDir, null, ['gz', 'json'], false, false,
helper.enumerateFilesSync(cldrDir, null, ['json'], false, false,
function(content, filePath) {
var fileType = helper.getTrailerAfterDot(filePath);
var cldr = null;
try {
if (fileType == 'gz') content = zlib.gunzipSync(content);
cldr = JSON.parse(content);
} catch (e) {
throw new Error('*** CLDR read error on ' + process.platform);
Expand Down
23 changes: 2 additions & 21 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var fsSync = require('fs-sync');
var md5 = require('md5');
var mkdirp = require('mkdirp');
var path = require('path');
var zlib = require('zlib');

exports.cloneEnglishTxtSyncDeep = cloneEnglishTxtSyncDeep;
exports.directoryDepth = directoryDepth;
Expand Down Expand Up @@ -42,7 +41,6 @@ exports.normalizeKeyArrays = normalizeKeyArrays;
exports.percent = percent;
exports.readToJson = readToJson;
exports.registerResTag = registerResTag;
exports.removeRedundantCldrFiles = removeRedundantCldrFiles;
exports.repackArgs = repackArgs;
exports.replaceJson = replaceJson;
exports.resTagExists = resTagExists;
Expand Down Expand Up @@ -314,8 +312,7 @@ function enumerateFilesSyncPriv(
} else {
var fileType = getTrailerAfterDot(item);
if (targetFileType.indexOf(fileType) < 0) return;
var encoding = (fileType === 'gz') ? null : 'utf8';
var content = fs.readFileSync(child, encoding);
var content = fs.readFileSync(child, 'utf8');
if (verbose) console.log('~~~ examining file:', child);
if (checkNodeModules) {
enumeratedFilesCount++;
Expand Down Expand Up @@ -343,21 +340,6 @@ function enumerateFilesSyncPriv(
}
}

function removeRedundantCldrFiles(cldrPath, fileTypeToRemove) {
var files = null;
try {
files = fs.readdirSync(cldrPath);
} catch (e) {
return;
}
files.forEach(function(file) {
if (file.indexOf('.') === 0) return;
var fileType = getTrailerAfterDot(file);
var filePath = path.join(cldrPath, file);
if (fileType === fileTypeToRemove) fs.unlinkSync(filePath);
});
}

/**
* @param {Function}
* If callback returns stop === true, stop enumeration.
Expand Down Expand Up @@ -661,12 +643,11 @@ function isSupportedLanguage(lang) {
function getSupportedLanguages() {
var cldrDir = path.join(__dirname, '..', 'cldr');
var langs = [];
enumerateFilesSync(cldrDir, null, ['gz', 'json'], false, false,
enumerateFilesSync(cldrDir, null, ['json'], false, false,
function(content, filePath) {
var fileType = getTrailerAfterDot(filePath);
var cldr = null;
try {
if (fileType == 'gz') content = zlib.gunzipSync(content);
cldr = JSON.parse(content);
} catch (e) {
throw new Error('*** CLDR read error on ' + process.platform);
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"scripts": {
"pretest": "eslint --ignore-path .gitignore . && jscs ./",
"test": "tap --bail --coverage --coverage-report=cobertura --timeout=200 test/test-*.*",
"posttest": "nyc report --reporter=lcov && nyc report",
"postinstall": "node postinstall.js"
"posttest": "nyc report --reporter=lcov && nyc report"
},
"bugs": {
"url": "https://github.com/strongloop/strong-globalize/issues"
Expand Down
17 changes: 0 additions & 17 deletions postinstall.js

This file was deleted.

20 changes: 3 additions & 17 deletions test/test-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

var test = require('tap').test;
var pkg;
var nodeVersion = process.version.replace(
/(^v[0-9]+\.[0-9]+)\.[0-9]+$/, '$1');

test('package.json', function(t) {
t.doesNotThrow(function() {
Expand All @@ -19,21 +17,9 @@ test('deps', function(t) {
var deps = Object.keys(pkg.dependencies);
t.assert(deps.length > 0, 'has dependencies');
deps.forEach(function(dep) {
if (dep === 'node-zlib-backport') {
if (nodeVersion === 'v0.10') {
t.doesNotThrow(function() {
require.resolve(dep);
}, dep + ' is installed');
} else {
t.throws(function() {
require.resolve(dep);
}, dep + ' cannot be installed');
}
} else {
t.doesNotThrow(function() {
require.resolve(dep);
}, dep + ' is installed');
}
t.doesNotThrow(function() {
require.resolve(dep);
}, dep + ' is installed');
});
t.end();
});
60 changes: 0 additions & 60 deletions test/test-setup-cldr.js

This file was deleted.

16 changes: 0 additions & 16 deletions util/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ var debug = require('debug')('strong-globalize');
var fs = require('fs');
var path = require('path');
var util = require('util');
var zlib = require('zlib');
try {
var nodeVersion = process.version.replace(
/(^v[0-9]+\.[0-9]+)\.[0-9]+$/, '$1');
if (nodeVersion === 'v0.10') {
zlib = require('node-zlib-backport');
debug('Zlib backported on %s', process.version);
}
} catch (e) {
debug('Zlib backport failed on %s', process.version);
}

var LANGS = [
'en', // English
Expand Down Expand Up @@ -109,12 +98,7 @@ LANGS.forEach(function(lang) {
});

var CLDR_FILE = path.join(__dirname, 'cldr_' + cldrVersion);
var CLDR_FILE_GZ = CLDR_FILE + '.gz';

fs.writeFileSync(CLDR_FILE, JSON.stringify(CLDR, null, 2));
var zipped = zlib.gzipSync(
JSON.stringify(CLDR), {data_type: zlib.Z_TEXT});
fs.writeFileSync(CLDR_FILE_GZ, zipped);

function loadCldr(lang) {
var mainPath = path.join(__dirname, 'node_modules',
Expand Down
3 changes: 0 additions & 3 deletions util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@
"dependencies": {
"cldr-data": "^29.0.1",
"lodash": "^4.3.0"
},
"optionalDependencies": {
"node-zlib-backport": "^0.11.15"
}
}

0 comments on commit 56421b9

Please sign in to comment.