Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion GlobalizeCompilerHelper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var crypto = require("crypto");
var fs = require("fs");
var globalizeCompiler = require("globalize-compiler");
var path = require("path");
Expand Down Expand Up @@ -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) {
Expand Down