Skip to content

Commit

Permalink
Merge pull request #52 from strongloop/unprune
Browse files Browse the repository at this point in the history
remove use of gzip compressed CLDR data
  • Loading branch information
rmg committed Jul 26, 2016
2 parents 58f0090 + 95f48e5 commit 9731d05
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 176 deletions.
4 changes: 0 additions & 4 deletions README.md
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
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
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
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.

2 changes: 1 addition & 1 deletion test/load-msg-helper.js
Expand Up @@ -101,7 +101,7 @@ function secondaryMgr(rootDir, lang, t, aml, positive, callback) {
msgFound.push(msg.message);
if (msgFound.length === (msgWanted[lang].length + 1)) {
for (var i = 0; i < msgFound.length - 1; i++) {
console.log('checking', msgWanted[lang][i]);
t.comment('checking', msgWanted[lang][i]);
if (positive) {
t.match(msgFound[i + 1], msgWanted[lang][i],
lang + ' message ' + i.toString() + ' is correct.');
Expand Down
10 changes: 5 additions & 5 deletions test/slt-test-helper.js
Expand Up @@ -67,7 +67,7 @@ function testHarness(t, targets, noFixtures, testCallback, testAllDone) {
function checkErrMsg(outMsg, errMsg, key, targets, t) {
outMsg = stripRootDirInfo(outMsg, key);
errMsg = stripRootDirInfo(errMsg, key);
if (DEBUG) console.log(
if (DEBUG) t.comment(
'\n<<< BEGIN', key,
'\nout ________________\n',
outMsg,
Expand Down Expand Up @@ -119,19 +119,19 @@ function testHarness(t, targets, noFixtures, testCallback, testAllDone) {
keys.forEach(function(key) {
if (noFixtures) {
var dir = path.join(destDir, key);
console.log('--- making dir: %s', dir);
t.comment('--- making dir: %s', dir);
shell.mkdir('-p', dir);
console.log('----- made dir: %s', dir);
t.comment('----- made dir: %s', dir);
} else {
var dir = path.join(__dirname, 'fixtures', key);
copyDirs.push(dir);
}
});
if (!noFixtures) {
console.log('--- copying %d: %s to %s',
t.comment('--- copying %d: %s to %s',
copyDirs.length, JSON.stringify(copyDirs, null, 2), destDir);
shell.cp('-r', copyDirs, destDir);
console.log('---- copied %d: %s to %s',
t.comment('---- copied %d: %s to %s',
copyDirs.length, JSON.stringify(copyDirs, null, 2), destDir);
}
var asyncTasks = [];
Expand Down
50 changes: 23 additions & 27 deletions test/test-load-msg-forking.js
Expand Up @@ -7,33 +7,32 @@ var async = require('async');
var f = require('util').format;
var helper = require('../lib/helper');
var loadMsgHelper = require('./load-msg-helper');
var test = require('tap').test;

var wellKnownLangs = loadMsgHelper.wellKnownLangs;
var secondaryMgr = loadMsgHelper.secondaryMgr;

var cluster = require('cluster');

test('secondary test on forking', function(t) {
if (cluster.isMaster && !process.argv[2]) {
var msg = f('Master is %s', process.pid);
if (cluster.isMaster && !process.argv[2]) {
var msg = f('Master is %s', process.pid);
console.log(msg);
cluster.setupMaster({
exec: __filename,
args: ['second_invoke'],
silent: false,
});
cluster.fork();
cluster.on('online', function(worker) {
msg = f('Worker %s has started', worker.process.pid);
console.log(msg);
cluster.setupMaster({
exec: __filename,
args: ['second_invoke'],
silent: false,
});
cluster.fork();
cluster.on('online', function(worker) {
msg = f('Worker %s has started', worker.process.pid);
console.log(msg);
});
cluster.on('exit', function(worker) {
msg = f('Worker %s has completed', worker.process.pid);
console.log(msg);
t.end();
});
} else if (cluster.isWorker) {
});
cluster.on('exit', function(worker) {
msg = f('Worker %s has completed', worker.process.pid);
console.log(msg);
});
} else if (cluster.isWorker) {
var test = require('tap').test;
test('secondary test on forking', function(t) {
t.equal(process.argv[2], 'second_invoke', 'worker in the second invoke');
async.forEachOfSeries(wellKnownLangs, function(lang, ix, callback) {
secondaryMgr(__dirname, lang, t, helper.AML_ALL, true,
Expand All @@ -45,11 +44,8 @@ test('secondary test on forking', function(t) {
if (err) t.fail('language iteration failed.');
else t.pass('language iteration succeeds.');
t.end();
process.exit(0);
// process should now exit cleanly
process.disconnect();
});
} else {
t.pass('default case');
t.end();
}
});

});
}
20 changes: 3 additions & 17 deletions test/test-package.js
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
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
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 9731d05

Please sign in to comment.