diff options
author | Chad Austin <caustin@gmail.com> | 2012-08-14 13:27:52 -0700 |
---|---|---|
committer | Chad Austin <chad@chadaustin.me> | 2012-09-25 16:30:42 -0700 |
commit | 0bd9bff496b894af1e211a830df5cce4c80dcfd5 (patch) | |
tree | 9b28da0fff215cd19ca50cf4964fafa429b5b74f /tools/js-optimizer.js | |
parent | ac36f1a7237e1e804d7f07bed4226a3f5a3320d8 (diff) |
Support loading emscripten argument filenames with relative paths
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index e1cfbe65..521656e2 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -26,15 +26,20 @@ if (ENVIRONMENT_IS_NODE) { var nodeFS = require('fs'); var nodePath = require('path'); - read = function(filename) { - filename = nodePath['normalize'](filename); - var ret = nodeFS['readFileSync'](filename).toString(); - // The path is absolute if the normalized version is the same as the resolved. - if (!ret && filename != nodePath['resolve'](filename)) { - filename = path.join(__dirname, '..', 'src', filename); - ret = nodeFS['readFileSync'](filename).toString(); + function find(filename) { + var prefixes = [nodePath.join(__dirname, '..', 'src'), process.cwd()]; + for (var i = 0; i < prefixes.length; ++i) { + var combined = nodePath.join(prefixes[i], filename); + if (nodeFS.existsSync(combined)) { + return combined; + } } - return ret; + return filename; + } + + read = function(filename) { + var absolute = find(filename); + return nodeFS['readFileSync'](absolute).toString(); }; load = function(f) { @@ -98,14 +103,6 @@ if (typeof print === 'undefined') { } // *** Environment setup code *** -// Fix read for our location -read = function(filename) { - // The path is absolute if the normalized version is the same as the resolved. - filename = path.normalize(filename); - if (filename != path.resolve(filename)) filename = path.join(__dirname, '..', 'src', filename); - return fs.readFileSync(filename).toString(); -} - var uglify = require('../tools/eliminator/node_modules/uglify-js'); var fs = require('fs'); var path = require('path'); |