diff --git a/GlobalizeCompilerHelper.js b/GlobalizeCompilerHelper.js index 05b1d6e..7d23620 100644 --- a/GlobalizeCompilerHelper.js +++ b/GlobalizeCompilerHelper.js @@ -1,3 +1,4 @@ +var crypto = require("crypto"); var fs = require("fs"); var globalizeCompiler = require("globalize-compiler"); var path = require("path"); @@ -39,8 +40,30 @@ GlobalizeCompilerHelper.prototype.createCompiledDataModule = function(request) { return filepath; }; +var _tmpFilesMap = {}; +function assertUniqueTmpfile(filepath, tmpfile) { + if (_tmpFilesMap[tmpfile] != null) { + if (_tmpFilesMap[tmpfile] != filepath) { + throw new Error( + "Multiple files map to temporary file \"" + tmpfile + "\":\n" + + [_tmpFilesMap[tmpfile], filepath].join('\n') + ); + } + } else { + _tmpFilesMap[tmpfile] = filepath; + } +} + GlobalizeCompilerHelper.prototype.getModuleFilepath = function(request) { - return path.join(this.tmpdir, request.replace(/.*!/, "").replace(/[\/\\?" :]/g, "-")); + var filepath = request.replace(/.*!/, ""); + var tmpfile = crypto + .createHash("sha1") + .update(filepath, "utf8") + .digest("hex") + ".js"; + + assertUniqueTmpfile(filepath, tmpfile); + + return path.join(this.tmpdir, tmpfile); }; GlobalizeCompilerHelper.prototype.compile = function(locale, request) {