From f64b3b0de1c63a369bbf4aac3d32e179194ae010 Mon Sep 17 00:00:00 2001 From: "Corneliu C. Prodescu" Date: Sat, 18 Mar 2017 15:37:15 -0700 Subject: [PATCH 1/2] Hash temporary file names. Current encoding transforms the file path from where the Globalize calls were extracted into a file name. In deeply nested projects, this can double the length of the path, causing E_NAMETOOLONG issues. Before this: /long/path/to/project/.tmp-globalize-webpack/-long-path-to-project-src-component-foo-index.js After this: /long/path/to/project/.tmp-globalize-webpack/5b4c40dd44a2cfde54a3e04cd183aa70edd64c1a.js This has the downside that it makes the content of the files more opaque, being harder to debug which content maps to which file. One would have to ``` echo -n `readlink -f src/component/foo/index.js` | shasum ``` This fixes #42 and #16. --- GlobalizeCompilerHelper.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/GlobalizeCompilerHelper.js b/GlobalizeCompilerHelper.js index 05b1d6e..58ad7e0 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"); @@ -40,7 +41,12 @@ GlobalizeCompilerHelper.prototype.createCompiledDataModule = function(request) { }; 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'; + return path.join(this.tmpdir, tmpfile); }; GlobalizeCompilerHelper.prototype.compile = function(locale, request) { From 4aa1d2fda21be1a45238dd07885c92d05e26ee5e Mon Sep 17 00:00:00 2001 From: "Corneliu C. Prodescu" Date: Sun, 26 Mar 2017 00:21:09 -0700 Subject: [PATCH 2/2] Ensure temporary file names hashes do not have collisions. --- GlobalizeCompilerHelper.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/GlobalizeCompilerHelper.js b/GlobalizeCompilerHelper.js index 58ad7e0..7d23620 100644 --- a/GlobalizeCompilerHelper.js +++ b/GlobalizeCompilerHelper.js @@ -1,4 +1,4 @@ -var crypto = require('crypto'); +var crypto = require("crypto"); var fs = require("fs"); var globalizeCompiler = require("globalize-compiler"); var path = require("path"); @@ -40,12 +40,29 @@ 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) { var filepath = request.replace(/.*!/, ""); var tmpfile = crypto - .createHash('sha1') - .update(filepath, 'utf8') - .digest('hex') + '.js'; + .createHash("sha1") + .update(filepath, "utf8") + .digest("hex") + ".js"; + + assertUniqueTmpfile(filepath, tmpfile); + return path.join(this.tmpdir, tmpfile); };