From 32e6c3997e5c2a5e67eeae79c0751966b1a7f1d8 Mon Sep 17 00:00:00 2001 From: Max Park Date: Thu, 4 Jan 2018 20:39:15 -0500 Subject: [PATCH 1/2] remove sourceMappingURL if it doesn't have the same name with the js file. use the last map file if there is no map file with the same name with the js file. this is possibly wrong and it might rather be correct to raise an error in such case. --- index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.js b/index.js index e2e23be..91cba49 100644 --- a/index.js +++ b/index.js @@ -100,6 +100,17 @@ UglifyWriter.prototype.processFile = function(inFile, outFile, relativePath, out if (srcURL.existsIn(src)) { let url = srcURL.getFrom(src); + let lastUrl = srcURL.getFrom(src); + // Make sure vendor.map is being used because vendor.js can have multiple sourceMappingURL if modules also have it. + while (url && url.match(/.+?(?=\.map$)/)[0] !== relativePath.match(/(.*\/)?(.+)\.js/)[2]) { + src = srcURL.removeFrom(src) + url = srcURL.getFrom(src); + } + // If there is no map url which has an identical name with the js file, use the last one. + // It's possible we should rather raise an error instead. + if (!url) { + url = lastUrl; + } let sourceMapPath = path.join(path.dirname(inFile), url); if (fs.existsSync(sourceMapPath)) { sourceMap.content = JSON.parse(fs.readFileSync(sourceMapPath)); From 5be963135b6ca3029a709185198113e51079c907 Mon Sep 17 00:00:00 2001 From: Max Park Date: Thu, 11 Jan 2018 17:27:39 -0500 Subject: [PATCH 2/2] make lastUrl updated in the loop --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 91cba49..5cc1f6d 100644 --- a/index.js +++ b/index.js @@ -100,10 +100,11 @@ UglifyWriter.prototype.processFile = function(inFile, outFile, relativePath, out if (srcURL.existsIn(src)) { let url = srcURL.getFrom(src); - let lastUrl = srcURL.getFrom(src); + let lastUrl = null; // Make sure vendor.map is being used because vendor.js can have multiple sourceMappingURL if modules also have it. while (url && url.match(/.+?(?=\.map$)/)[0] !== relativePath.match(/(.*\/)?(.+)\.js/)[2]) { - src = srcURL.removeFrom(src) + lastUrl = url; + src = srcURL.removeFrom(src); url = srcURL.getFrom(src); } // If there is no map url which has an identical name with the js file, use the last one.