From 0aac7f27708d30921e57b60d96c25c7841aea5f2 Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Tue, 13 Nov 2018 10:45:56 +0800 Subject: [PATCH 1/8] .editorconfig with indent_style = tab --- .editorconfig | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c330fbd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.js] +indent_style = tab From cc2fe85fba52f73e4907019f0254736aadd3ea49 Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Mon, 12 Nov 2018 16:55:18 +0800 Subject: [PATCH 2/8] Add test to support null value in sourcesContent --- .../null-sourcesContent-source-map.js | 2 ++ .../null-sourcesContent-source-map.map | 1 + .../null-sourcesContent-source-map.txt | 1 + test/index.test.js | 32 +++++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 test/fixtures/null-sourcesContent-source-map.js create mode 100644 test/fixtures/null-sourcesContent-source-map.map create mode 100644 test/fixtures/null-sourcesContent-source-map.txt diff --git a/test/fixtures/null-sourcesContent-source-map.js b/test/fixtures/null-sourcesContent-source-map.js new file mode 100644 index 0000000..3c5c45d --- /dev/null +++ b/test/fixtures/null-sourcesContent-source-map.js @@ -0,0 +1,2 @@ +with SourceMap +//#sourceMappingURL=null-sourcesContent-source-map.map \ No newline at end of file diff --git a/test/fixtures/null-sourcesContent-source-map.map b/test/fixtures/null-sourcesContent-source-map.map new file mode 100644 index 0000000..4a37daf --- /dev/null +++ b/test/fixtures/null-sourcesContent-source-map.map @@ -0,0 +1 @@ +{"version":3,"file":"null-sourcesContent-source-map.js","sources":["null-sourcesContent-source-map.txt"],"sourcesContent":[null],"mappings":"AAAA"} \ No newline at end of file diff --git a/test/fixtures/null-sourcesContent-source-map.txt b/test/fixtures/null-sourcesContent-source-map.txt new file mode 100644 index 0000000..3f2f36d --- /dev/null +++ b/test/fixtures/null-sourcesContent-source-map.txt @@ -0,0 +1 @@ +with SourceMap \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 1191e24..150c8de 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -304,4 +304,36 @@ describe("source-map-loader", function() { } ); }); + + it("should support null value in sourcesContent", (done) => { + const javaScriptFilename = "null-sourcesContent-source-map.js"; + const sourceFilename = "null-sourcesContent-source-map.txt"; + const rootRelativeSourcePath = path.join(fixturesPath, sourceFilename); + const sourceMapPath = path.join(fixturesPath, "null-sourcesContent-source-map.map"); + + execLoader( + path.join(fixturesPath, javaScriptFilename), + (err, res, map, deps, warns) => { + should.equal(err, null); + warns.should.be.eql([]); + should.equal(res, "with SourceMap\n"); + map.should.be.eql({ + "version": 3, + "file": javaScriptFilename, + "sources": [ + rootRelativeSourcePath + ], + "sourcesContent": [ + "with SourceMap" + ], + "mappings": "AAAA" + }); + deps.should.be.eql([ + sourceMapPath, + rootRelativeSourcePath + ]); + done(); + } + ); + }); }); \ No newline at end of file From 5d65ab14dfcf05c7559aa128f482c436427d7d17 Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Mon, 12 Nov 2018 17:04:15 +0800 Subject: [PATCH 3/8] Add test to resolve relative paths when sourcesContent is present --- ...ve-sourceRoot-sourcesContent-source-map.js | 2 ++ ...e-sourceRoot-sourcesContent-source-map.map | 1 + test/index.test.js | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 test/fixtures/relative-sourceRoot-sourcesContent-source-map.js create mode 100644 test/fixtures/relative-sourceRoot-sourcesContent-source-map.map diff --git a/test/fixtures/relative-sourceRoot-sourcesContent-source-map.js b/test/fixtures/relative-sourceRoot-sourcesContent-source-map.js new file mode 100644 index 0000000..cbd9fc1 --- /dev/null +++ b/test/fixtures/relative-sourceRoot-sourcesContent-source-map.js @@ -0,0 +1,2 @@ +with SourceMap +//#sourceMappingURL=relative-sourceRoot-sourcesContent-source-map.map \ No newline at end of file diff --git a/test/fixtures/relative-sourceRoot-sourcesContent-source-map.map b/test/fixtures/relative-sourceRoot-sourcesContent-source-map.map new file mode 100644 index 0000000..b103a97 --- /dev/null +++ b/test/fixtures/relative-sourceRoot-sourcesContent-source-map.map @@ -0,0 +1 @@ +{"version":3,"file":"relative-sourceRoot-sourcesContent-source-map.js","sourceRoot":"../fixtures/data/","sources":["relative-sourceRoot-sourcesContent-source-map.txt"],"sourcesContent":["with SourceMap"],"mappings":"AAAA"} \ No newline at end of file diff --git a/test/index.test.js b/test/index.test.js index 150c8de..7991b6b 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -336,4 +336,36 @@ describe("source-map-loader", function() { } ); }); + + it("should resolve relative sources path even with sourcesContent", (done) => { + const javaScriptFilename = "relative-sourceRoot-sourcesContent-source-map.js"; + const sourceFilename = "relative-sourceRoot-sourcesContent-source-map.txt"; + const rootRelativeSourcePath = path.join(dataPath, sourceFilename); + const sourceMapPath = path.join(fixturesPath, "relative-sourceRoot-sourcesContent-source-map"); + + execLoader( + path.join(fixturesPath, javaScriptFilename), + (err, res, map, deps, warns) => { + should.equal(err, null); + warns.should.be.eql([]); + should.equal(res, "with SourceMap\n"); + map.should.be.eql({ + "version": 3, + "file": javaScriptFilename, + "sources": [ + rootRelativeSourcePath + ], + "sourcesContent": [ + "with SourceMap" + ], + "mappings": "AAAA" + }); + deps.should.be.eql([ + sourceMapPath, + rootRelativeSourcePath + ]); + done(); + } + ); + }); }); \ No newline at end of file From b892c8cb920afe284b9848e2e9f5f6e365b22c20 Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Tue, 13 Nov 2018 13:58:00 +0800 Subject: [PATCH 4/8] Don't use webpack to resolve sourcemap and sources path --- index.js | 48 +++++++++++++++++++++++++++++++--------------- package-lock.json | 25 ------------------------ package.json | 3 +-- test/index.test.js | 16 ++++++++-------- 4 files changed, 42 insertions(+), 50 deletions(-) diff --git a/index.js b/index.js index 6137235..139cbd6 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ var fs = require("fs"); var path = require("path"); var async = require("async"); -var loaderUtils = require("loader-utils"); +var urlUtils = require("url"); // Matches only the last occurrence of sourceMappingURL var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)(?![\\S\\s]*sourceMappingURL)", @@ -14,11 +14,14 @@ var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)(?![\\S\\s]*sourc // Matches // .... comments regex2 = new RegExp("//"+baseRegex+"($|\n|\r\n?)"), // Matches DataUrls - regexDataUrl = /data:[^;\n]+(?:;charset=[^;\n]+)?;base64,([a-zA-Z0-9+/]+={0,2})/; + regexDataUrl = /data:[^;\n]+(?:;charset=[^;\n]+)?;base64,([a-zA-Z0-9+/]+={0,2})/, + // Matches url with scheme, doesn't match Windows disk + regexUrl = /[a-zA-Z]{2,}:/; + +const FILE_SCHEME = "file:"; module.exports = function(input, inputMap) { this.cacheable && this.cacheable(); - var resolve = this.resolve; var addDependency = this.addDependency; var emitWarning = this.emitWarning || function() {}; var match = input.match(regex1) || input.match(regex2); @@ -38,17 +41,17 @@ module.exports = function(input, inputMap) { } processMap(map, this.context, callback); } else { - resolve(this.context, loaderUtils.urlToRequest(url, true), function(err, result) { + resolveAbsolutePath(this.context, url, function(err, absoluteFilepath) { if(err) { emitWarning("Cannot find SourceMap '" + url + "': " + err); return untouched(); } - addDependency(result); - fs.readFile(result, "utf-8", function(err, content) { + fs.readFile(absoluteFilepath, "utf-8", function(err, content) { if(err) { - emitWarning("Cannot open SourceMap '" + result + "': " + err); + emitWarning("Cannot open SourceMap '" + absoluteFilepath + "': " + err); return untouched(); } + addDependency(absoluteFilepath); var map; try { map = JSON.parse(content); @@ -56,10 +59,9 @@ module.exports = function(input, inputMap) { emitWarning("Cannot parse SourceMap '" + url + "': " + e); return untouched(); } - processMap(map, path.dirname(result), callback); + processMap(map, path.dirname(absoluteFilepath), callback); }); }.bind(this)); - return; } } else { var callback = this.callback; @@ -68,6 +70,22 @@ module.exports = function(input, inputMap) { function untouched() { callback(null, input, inputMap); } + function resolveAbsolutePath(context, url, resolveAbsolutePathCallback) { + let filepath = url; + if(regexUrl.test(filepath) && !filepath.startsWith(FILE_SCHEME)) { + resolveAbsolutePathCallback("URL scheme not supported"); + return; + } + if(filepath.startsWith(FILE_SCHEME)) { + if(urlUtils.fileURLToPath) { + filepath = urlUtils.fileURLToPath(filepath); + } else { + resolveAbsolutePathCallback("file URL scheme support requires node 10.x"); + return; + } + } + resolveAbsolutePathCallback(null, path.resolve(context, filepath)); + } function processMap(map, context, callback) { if(!map.sourcesContent || map.sourcesContent.length < map.sources.length) { var sourcePrefix = map.sourceRoot ? map.sourceRoot + "/" : ""; @@ -75,19 +93,19 @@ module.exports = function(input, inputMap) { delete map.sourceRoot; var missingSources = map.sourcesContent ? map.sources.slice(map.sourcesContent.length) : map.sources; async.map(missingSources, function(source, callback) { - resolve(context, loaderUtils.urlToRequest(source, true), function(err, result) { + resolveAbsolutePath(context, source, function(err, absoluteFilepath) { if(err) { emitWarning("Cannot find source file '" + source + "': " + err); return callback(null, null); } - addDependency(result); - fs.readFile(result, "utf-8", function(err, content) { + fs.readFile(absoluteFilepath, "utf-8", function(err, content) { if(err) { - emitWarning("Cannot open source file '" + result + "': " + err); + emitWarning("Cannot open source file '" + absoluteFilepath + "': " + err); return callback(null, null); } + addDependency(absoluteFilepath); callback(null, { - source: result, + source: absoluteFilepath, content: content }); }); @@ -106,6 +124,6 @@ module.exports = function(input, inputMap) { }); return; } - callback(null, input.replace(match[0], ''), map); + callback(null, input.replace(match[0], ""), map); } } diff --git a/package-lock.json b/package-lock.json index 98b8845..def0d75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,11 +75,6 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, - "big.js": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/big.js/-/big.js-3.2.0.tgz", - "integrity": "sha512-+hN/Zh2D08Mx65pZ/4g5bsmNiZUuChDiQfTUQ7qJr4/kuopCr88xZsAXv6mBoZEsUI4OuGHlX59qE94K2mMW8Q==" - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -587,11 +582,6 @@ "minimatch": "^3.0.4" } }, - "emojis-list": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz", - "integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k=" - }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1028,11 +1018,6 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, - "json5": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-0.5.1.tgz", - "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" - }, "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", @@ -1076,16 +1061,6 @@ "strip-bom": "^3.0.0" } }, - "loader-utils": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.1.0.tgz", - "integrity": "sha1-yYrvSIvM7aL/teLeZG1qdUQp9c0=", - "requires": { - "big.js": "^3.1.3", - "emojis-list": "^2.0.0", - "json5": "^0.5.0" - } - }, "locate-path": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", diff --git a/package.json b/package.json index 83e35e7..cca6990 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,7 @@ "release": "standard-version" }, "dependencies": { - "async": "^2.5.0", - "loader-utils": "^1.1.0" + "async": "^2.5.0" }, "devDependencies": { "mocha": "^5.0.5", diff --git a/test/index.test.js b/test/index.test.js index 7991b6b..90f2bb2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -176,10 +176,10 @@ describe("source-map-loader", function() { it("should warn on missing SourceMap", function(done) { execLoader(path.join(fixturesPath, "missing-source-map.js"), function(err, res, map, deps, warns) { should.equal(err, null); - warns.should.be.eql([ - "Cannot find SourceMap 'missing-source-map.map': Error: File not found" - ]); - should.equal(res, "with SourceMap\n//#sourceMappingURL=missing-source-map.map\n// comment"), + warns.should.matchEach( + new RegExp(`Cannot open SourceMap '${path.join(fixturesPath, 'missing-source-map.map')}':`) + ); + should.equal(res, "with SourceMap\n//#sourceMappingURL=missing-source-map.map\n// comment"); should.equal(map, null); deps.should.be.eql([]); done(); @@ -189,10 +189,10 @@ describe("source-map-loader", function() { it("should warn on missing source file", function(done) { execLoader(path.join(fixturesPath, "missing-source-map2.js"), function(err, res, map, deps, warns) { should.equal(err, null); - warns.should.be.eql([ - "Cannot find source file 'missing-source-map2.txt': Error: File not found" - ]); - should.equal(res, "with SourceMap\n// comment"), + warns.should.matchEach( + new RegExp(`Cannot open source file '${path.join(fixturesPath, 'missing-source-map2.txt')}':`) + ); + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version":3, "file":"missing-source-map2.js", From 93b54c077ae2da082c7480570ed9c3c34ee87f5a Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Tue, 13 Nov 2018 14:29:16 +0800 Subject: [PATCH 5/8] Force absolute source path in returned source, handle null value in sourcesContent --- index.js | 82 ++++++++++++++++++++++++++-------------------- package-lock.json | 36 +++++++++++++++----- package.json | 2 +- test/index.test.js | 31 +++++++++--------- 4 files changed, 90 insertions(+), 61 deletions(-) diff --git a/index.js b/index.js index 139cbd6..2119429 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ */ var fs = require("fs"); var path = require("path"); -var async = require("async"); +var loaderUtils = require("loader-utils"); var urlUtils = require("url"); // Matches only the last occurrence of sourceMappingURL @@ -20,15 +20,22 @@ var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)(?![\\S\\s]*sourc const FILE_SCHEME = "file:"; +const DEFAULT_OPTIONS = { + // Prevent the loader to rewrite all sources as absolute paths + keepRelativeSources: false +}; + module.exports = function(input, inputMap) { + const options = Object.assign({}, DEFAULT_OPTIONS, loaderUtils.getOptions(this)); this.cacheable && this.cacheable(); var addDependency = this.addDependency; var emitWarning = this.emitWarning || function() {}; var match = input.match(regex1) || input.match(regex2); + var callback; if(match) { var url = match[1]; var dataUrlMatch = regexDataUrl.exec(url); - var callback = this.async(); + callback = this.async(); if(dataUrlMatch) { var mapBase64 = dataUrlMatch[1]; var mapStr = (new Buffer(mapBase64, "base64")).toString(); @@ -64,7 +71,7 @@ module.exports = function(input, inputMap) { }.bind(this)); } } else { - var callback = this.callback; + callback = this.callback; return untouched(); } function untouched() { @@ -87,43 +94,48 @@ module.exports = function(input, inputMap) { resolveAbsolutePathCallback(null, path.resolve(context, filepath)); } function processMap(map, context, callback) { - if(!map.sourcesContent || map.sourcesContent.length < map.sources.length) { - var sourcePrefix = map.sourceRoot ? map.sourceRoot + "/" : ""; - map.sources = map.sources.map(function(s) { return sourcePrefix + s; }); - delete map.sourceRoot; - var missingSources = map.sourcesContent ? map.sources.slice(map.sourcesContent.length) : map.sources; - async.map(missingSources, function(source, callback) { - resolveAbsolutePath(context, source, function(err, absoluteFilepath) { + const sourcePrefix = map.sourceRoot ? map.sourceRoot + "/" : ""; + const sources = map.sources.map(function(s) { return sourcePrefix + s; }); + delete map.sourceRoot; + const sourcesContent = map.sourcesContent || []; + const sourcesPromises = sources.map((source, sourceIndex) => new Promise((resolveSource) => { + resolveAbsolutePath(context, source, function(err, absoluteFilepath) { + if(err) { + emitWarning("Cannot find source file '" + source + "': " + err); + return resolveSource({ + source: source, + content: sourcesContent[sourceIndex] != null ? sourcesContent[sourceIndex] : null + }); + } + if(sourcesContent[sourceIndex] != null) { + return resolveSource({ + source: absoluteFilepath, + content: sourcesContent[sourceIndex] + }); + } + fs.readFile(absoluteFilepath, "utf-8", function(err, content) { if(err) { - emitWarning("Cannot find source file '" + source + "': " + err); - return callback(null, null); - } - fs.readFile(absoluteFilepath, "utf-8", function(err, content) { - if(err) { - emitWarning("Cannot open source file '" + absoluteFilepath + "': " + err); - return callback(null, null); - } - addDependency(absoluteFilepath); - callback(null, { + emitWarning("Cannot open source file '" + absoluteFilepath + "': " + err); + return resolveSource({ source: absoluteFilepath, - content: content + content: null }); - }); - }); - }, function(err, info) { - map.sourcesContent = map.sourcesContent || []; - info.forEach(function(res) { - if(res) { - map.sources[map.sourcesContent.length] = res.source; - map.sourcesContent.push(res.content); - } else { - map.sourcesContent.push(null); } + addDependency(absoluteFilepath); + resolveSource({ + source: absoluteFilepath, + content: content + }); }); - processMap(map, context, callback); }); - return; - } - callback(null, input.replace(match[0], ""), map); + })); + Promise.all(sourcesPromises) + .then((results) => { + if (!options.keepRelativeSources) { + map.sources = results.map(res => res.source); + } + map.sourcesContent = results.map(res => res.content); + callback(null, input.replace(match[0], ""), map); + }); } } diff --git a/package-lock.json b/package-lock.json index def0d75..66f216c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,20 +61,17 @@ "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, - "async": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/async/-/async-2.5.0.tgz", - "integrity": "sha512-e+lJAJeNWuPCNyxZKOBdaJGyLGHugXVQtrAwtuAe2vhxTYxFTKE73p8JuTmdH0qdQZtDvI4dhJwjZc5zsfIsYw==", - "requires": { - "lodash": "^4.14.0" - } - }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, + "big.js": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-3.2.0.tgz", + "integrity": "sha512-+hN/Zh2D08Mx65pZ/4g5bsmNiZUuChDiQfTUQ7qJr4/kuopCr88xZsAXv6mBoZEsUI4OuGHlX59qE94K2mMW8Q==" + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -582,6 +579,11 @@ "minimatch": "^3.0.4" } }, + "emojis-list": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-2.1.0.tgz", + "integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k=" + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1018,6 +1020,11 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "json5": { + "version": "0.5.1", + "resolved": "http://registry.npmjs.org/json5/-/json5-0.5.1.tgz", + "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=" + }, "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", @@ -1061,6 +1068,16 @@ "strip-bom": "^3.0.0" } }, + "loader-utils": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.1.0.tgz", + "integrity": "sha1-yYrvSIvM7aL/teLeZG1qdUQp9c0=", + "requires": { + "big.js": "^3.1.3", + "emojis-list": "^2.0.0", + "json5": "^0.5.0" + } + }, "locate-path": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", @@ -1074,7 +1091,8 @@ "lodash": { "version": "4.17.10", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", - "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==", + "dev": true }, "lodash._reinterpolate": { "version": "3.0.0", diff --git a/package.json b/package.json index cca6990..d55c20e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "release": "standard-version" }, "dependencies": { - "async": "^2.5.0" + "loader-utils": "^1.1.0" }, "devDependencies": { "mocha": "^5.0.5", diff --git a/test/index.test.js b/test/index.test.js index 90f2bb2..255732e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -47,7 +47,7 @@ describe("source-map-loader", function() { execLoader(path.join(fixturesPath, "normal-file.js"), function(err, res, map, deps, warns) { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "without SourceMap"), + should.equal(res, "without SourceMap"); should.equal(map, null); deps.should.be.eql([]); done(); @@ -58,12 +58,12 @@ describe("source-map-loader", function() { execLoader(path.join(fixturesPath, "inline-source-map.js"), function(err, res, map, deps, warns) { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"), + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version":3, "file":"inline-source-map.js", "sources":[ - "inline-source-map.txt" + path.join(fixturesPath,"inline-source-map.txt") ], "sourcesContent":["with SourceMap"], "mappings":"AAAA" @@ -77,12 +77,12 @@ describe("source-map-loader", function() { execLoader(path.join(fixturesPath, "external-source-map.js"), function(err, res, map, deps, warns) { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"), + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version":3, "file":"external-source-map.js", "sources":[ - "external-source-map.txt" + path.join(fixturesPath,"external-source-map.txt") ], "sourcesContent":["with SourceMap"], "mappings":"AAAA" @@ -98,7 +98,7 @@ describe("source-map-loader", function() { execLoader(path.join(fixturesPath, "external-source-map2.js"), function(err, res, map, deps, warns) { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"), + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version":3, "file":"external-source-map2.js", @@ -120,12 +120,12 @@ describe("source-map-loader", function() { execLoader(path.join(fixturesPath, "multi-source-map.js"), function (err, res, map, deps, warns) { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\nanInvalidDirective = \"\\n/*# sourceMappingURL=data:application/json;base64,\"+btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))+\" */\";\n// comment"), + should.equal(res, "with SourceMap\nanInvalidDirective = \"\\n/*# sourceMappingURL=data:application/json;base64,\"+btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))+\" */\";\n// comment"); map.should.be.eql({ "version": 3, "file": "inline-source-map.js", "sources": [ - "inline-source-map.txt" + path.join(fixturesPath,"inline-source-map.txt") ], "sourcesContent": ["with SourceMap"], "mappings": "AAAA" @@ -197,7 +197,7 @@ describe("source-map-loader", function() { "version":3, "file":"missing-source-map2.js", "sources":[ - "missing-source-map2.txt" + path.join(fixturesPath,"missing-source-map2.txt") ], "sourcesContent":[null], "mappings":"AAAA" @@ -213,12 +213,12 @@ describe("source-map-loader", function() { execLoader(path.join(fixturesPath, "charset-inline-source-map.js"), function(err, res, map, deps, warns) { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"), + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version":3, "file":"charset-inline-source-map.js", "sources":[ - "charset-inline-source-map.txt" + path.join(fixturesPath,"charset-inline-source-map.txt") ], "sourcesContent":["with SourceMap"], "mappings":"AAAA" @@ -252,7 +252,7 @@ describe("source-map-loader", function() { (err, res, map, deps, warns) => { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"), + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version": 3, "file": javaScriptFilename, @@ -284,7 +284,7 @@ describe("source-map-loader", function() { (err, res, map, deps, warns) => { should.equal(err, null); warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"), + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ "version": 3, "file": javaScriptFilename, @@ -341,7 +341,7 @@ describe("source-map-loader", function() { const javaScriptFilename = "relative-sourceRoot-sourcesContent-source-map.js"; const sourceFilename = "relative-sourceRoot-sourcesContent-source-map.txt"; const rootRelativeSourcePath = path.join(dataPath, sourceFilename); - const sourceMapPath = path.join(fixturesPath, "relative-sourceRoot-sourcesContent-source-map"); + const sourceMapPath = path.join(fixturesPath, "relative-sourceRoot-sourcesContent-source-map.map"); execLoader( path.join(fixturesPath, javaScriptFilename), @@ -361,8 +361,7 @@ describe("source-map-loader", function() { "mappings": "AAAA" }); deps.should.be.eql([ - sourceMapPath, - rootRelativeSourcePath + sourceMapPath ]); done(); } From c3e75320be2eb10be1c8d7ae7ff00b7deb8e3d0d Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Tue, 13 Nov 2018 14:30:28 +0800 Subject: [PATCH 6/8] Replace deprecated new Buffer with Buffer.from --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2119429..fe12fce 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,7 @@ module.exports = function(input, inputMap) { callback = this.async(); if(dataUrlMatch) { var mapBase64 = dataUrlMatch[1]; - var mapStr = (new Buffer(mapBase64, "base64")).toString(); + var mapStr = Buffer.from(mapBase64, "base64").toString(); var map; try { map = JSON.parse(mapStr) From c1dc68f2abd5d0ee2ed7cb025023650d518d1291 Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Tue, 13 Nov 2018 18:26:46 +0800 Subject: [PATCH 7/8] Refactor test to use Promise, prevent timeout on failed expectation --- test/index.test.js | 362 +++++++++++++++++++++------------------------ 1 file changed, 167 insertions(+), 195 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index 255732e..308bcf9 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -3,21 +3,12 @@ var fs = require("fs"); var should = require("should"); var loader = require("../"); -function execLoader(filename, callback) { +const execLoader = (filename) => new Promise((resolvePromise, rejectPromise) => { var async = false; var deps = []; var warns = []; var context = { context: path.dirname(filename), - resolve: function(context, request, callback) { - process.nextTick(function() { - var p = path.isAbsolute(request) ? request : path.resolve(context, request); - if(fs.existsSync(p)) - callback(null, p); - else - callback(new Error("File not found")); - }); - }, addDependency: function(dep) { deps.push(dep); }, @@ -26,7 +17,11 @@ function execLoader(filename, callback) { }, callback: function(err, res, map) { async = true; - callback(err, res, map, deps, warns); + if(err) { + rejectPromise(err); + } else { + resolvePromise({res, map, deps, warns}); + } }, async: function() { async = true; @@ -36,199 +31,188 @@ function execLoader(filename, callback) { // Remove CRs to make test line ending invariant var fixtureContent = fs.readFileSync(filename, "utf-8").replace(/\r/g, ''); var res = loader.call(context, fixtureContent); - if(!async) return callback(null, res, null, deps, warns); -} + if(!async) return resolvePromise({res, map: null, deps, warns}); +}); describe("source-map-loader", function() { const fixturesPath = path.join(__dirname, "fixtures"); const dataPath = path.join(fixturesPath, "data"); - it("should leave normal files untouched", function(done) { - execLoader(path.join(fixturesPath, "normal-file.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "without SourceMap"); - should.equal(map, null); - deps.should.be.eql([]); - done(); - }); - }); - - it("should process inlined SourceMaps", function(done) { - execLoader(path.join(fixturesPath, "inline-source-map.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"); - map.should.be.eql({ - "version":3, - "file":"inline-source-map.js", - "sources":[ - path.join(fixturesPath,"inline-source-map.txt") - ], - "sourcesContent":["with SourceMap"], - "mappings":"AAAA" + it("should leave normal files untouched", function() { + return execLoader(path.join(fixturesPath, "normal-file.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "without SourceMap"); + should.equal(map, null); + deps.should.be.eql([]); }); - deps.should.be.eql([]); - done(); - }); }); - it("should process external SourceMaps", function(done) { - execLoader(path.join(fixturesPath, "external-source-map.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"); - map.should.be.eql({ - "version":3, - "file":"external-source-map.js", - "sources":[ - path.join(fixturesPath,"external-source-map.txt") - ], - "sourcesContent":["with SourceMap"], - "mappings":"AAAA" + it("should process inlined SourceMaps", function() { + return execLoader(path.join(fixturesPath, "inline-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "with SourceMap\n// comment"); + map.should.be.eql({ + "version":3, + "file":"inline-source-map.js", + "sources":[ + path.join(fixturesPath,"inline-source-map.txt") + ], + "sourcesContent":["with SourceMap"], + "mappings":"AAAA" + }); + deps.should.be.eql([]); }); - deps.should.be.eql([ - path.join(fixturesPath, "external-source-map.map") - ]); - done(); - }); }); - it("should process external SourceMaps (external sources)", function(done) { - execLoader(path.join(fixturesPath, "external-source-map2.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"); - map.should.be.eql({ - "version":3, - "file":"external-source-map2.js", - "sources":[ - path.join(fixturesPath, "external-source-map2.txt") - ], - "sourcesContent":["with SourceMap"], - "mappings":"AAAA" + it("should process external SourceMaps", function() { + return execLoader(path.join(fixturesPath, "external-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "with SourceMap\n// comment"); + map.should.be.eql({ + "version":3, + "file":"external-source-map.js", + "sources":[ + path.join(fixturesPath,"external-source-map.txt") + ], + "sourcesContent":["with SourceMap"], + "mappings":"AAAA" + }); + deps.should.be.eql([ + path.join(fixturesPath, "external-source-map.map") + ]); }); - deps.should.be.eql([ - path.join(dataPath, "external-source-map2.map"), - path.join(fixturesPath, "external-source-map2.txt") - ]); - done(); - }); }); - it("should use last SourceMap directive", function (done) { - execLoader(path.join(fixturesPath, "multi-source-map.js"), function (err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "with SourceMap\nanInvalidDirective = \"\\n/*# sourceMappingURL=data:application/json;base64,\"+btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))+\" */\";\n// comment"); + it("should process external SourceMaps (external sources)", function() { + return execLoader(path.join(fixturesPath, "external-source-map2.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ - "version": 3, - "file": "inline-source-map.js", - "sources": [ - path.join(fixturesPath,"inline-source-map.txt") + "version":3, + "file":"external-source-map2.js", + "sources":[ + path.join(fixturesPath, "external-source-map2.txt") ], - "sourcesContent": ["with SourceMap"], - "mappings": "AAAA" + "sourcesContent":["with SourceMap"], + "mappings":"AAAA" }); - deps.should.be.eql([]); - done(); - }); + deps.should.be.eql([ + path.join(dataPath, "external-source-map2.map"), + path.join(fixturesPath, "external-source-map2.txt") + ]); + }); }); - it("should skip invalid base64 SourceMap", function (done) { - execLoader(path.join(fixturesPath, "invalid-inline-source-map.js"), function (err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "without SourceMap\n// @sourceMappingURL=data:application/source-map;base64,\"something invalid\"\n// comment"); - should.equal(map, null); - deps.should.be.eql([]); - done(); - }); + it("should use last SourceMap directive", function () { + return execLoader(path.join(fixturesPath, "multi-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "with SourceMap\nanInvalidDirective = \"\\n/*# sourceMappingURL=data:application/json;base64,\"+btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))+\" */\";\n// comment"); + map.should.be.eql({ + "version": 3, + "file": "inline-source-map.js", + "sources": [ + path.join(fixturesPath,"inline-source-map.txt") + ], + "sourcesContent": ["with SourceMap"], + "mappings": "AAAA" + }); + deps.should.be.eql([]); + }); }); - it("should warn on invalid base64 SourceMap", function (done) { - execLoader(path.join(fixturesPath, "invalid-inline-source-map2.js"), function (err, res, map, deps, warns) { - should.equal(err, null); - warns.should.matchEach( - new RegExp("Cannot parse inline SourceMap 'invalid\/base64=': SyntaxError: Unexpected token") - ); - should.equal(res, "without SourceMap\n// @sourceMappingURL=data:application/source-map;base64,invalid/base64=\n// comment"); - should.equal(map, null); - deps.should.be.eql([]); - done(); - }); + + it("should skip invalid base64 SourceMap", function () { + return execLoader(path.join(fixturesPath, "invalid-inline-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "without SourceMap\n// @sourceMappingURL=data:application/source-map;base64,\"something invalid\"\n// comment"); + should.equal(map, null); + deps.should.be.eql([]); + }); + }); + it("should warn on invalid base64 SourceMap", function () { + return execLoader(path.join(fixturesPath, "invalid-inline-source-map2.js")) + .then(function({res, map, deps, warns}) { + warns.should.matchEach( + new RegExp("Cannot parse inline SourceMap 'invalid\/base64=': SyntaxError: Unexpected token") + ); + should.equal(res, "without SourceMap\n// @sourceMappingURL=data:application/source-map;base64,invalid/base64=\n// comment"); + should.equal(map, null); + deps.should.be.eql([]); + }); }); - it("should warn on invalid SourceMap", function (done) { - execLoader(path.join(fixturesPath, "invalid-source-map.js"), function (err, res, map, deps, warns) { - should.equal(err, null); - warns.should.matchEach( - new RegExp("Cannot parse SourceMap 'invalid-source-map.map': SyntaxError: Unexpected string in JSON at position 102") - ); - should.equal(res, "with SourceMap\n//#sourceMappingURL=invalid-source-map.map\n// comment"); - should.equal(map, null); - deps.should.be.eql([ - path.join(fixturesPath, "invalid-source-map.map") - ]); - done(); - }); + it("should warn on invalid SourceMap", function () { + return execLoader(path.join(fixturesPath, "invalid-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.matchEach( + new RegExp("Cannot parse SourceMap 'invalid-source-map.map': SyntaxError: Unexpected string in JSON at position 102") + ); + should.equal(res, "with SourceMap\n//#sourceMappingURL=invalid-source-map.map\n// comment"); + should.equal(map, null); + deps.should.be.eql([ + path.join(fixturesPath, "invalid-source-map.map") + ]); + }); }); - it("should warn on missing SourceMap", function(done) { - execLoader(path.join(fixturesPath, "missing-source-map.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.matchEach( - new RegExp(`Cannot open SourceMap '${path.join(fixturesPath, 'missing-source-map.map')}':`) - ); - should.equal(res, "with SourceMap\n//#sourceMappingURL=missing-source-map.map\n// comment"); - should.equal(map, null); - deps.should.be.eql([]); - done(); - }); + it("should warn on missing SourceMap", function() { + return execLoader(path.join(fixturesPath, "missing-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.matchEach( + new RegExp(`Cannot open SourceMap '${path.join(fixturesPath, 'missing-source-map.map')}':`) + ); + should.equal(res, "with SourceMap\n//#sourceMappingURL=missing-source-map.map\n// comment"); + should.equal(map, null); + deps.should.be.eql([]); + }); }); - it("should warn on missing source file", function(done) { - execLoader(path.join(fixturesPath, "missing-source-map2.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.matchEach( - new RegExp(`Cannot open source file '${path.join(fixturesPath, 'missing-source-map2.txt')}':`) - ); - should.equal(res, "with SourceMap\n// comment"); - map.should.be.eql({ - "version":3, - "file":"missing-source-map2.js", - "sources":[ - path.join(fixturesPath,"missing-source-map2.txt") - ], - "sourcesContent":[null], - "mappings":"AAAA" + it("should warn on missing source file", function() { + return execLoader(path.join(fixturesPath, "missing-source-map2.js")) + .then(function({res, map, deps, warns}) { + warns.should.matchEach( + new RegExp(`Cannot open source file '${path.join(fixturesPath, 'missing-source-map2.txt')}':`) + ); + should.equal(res, "with SourceMap\n// comment"); + map.should.be.eql({ + "version":3, + "file":"missing-source-map2.js", + "sources":[ + path.join(fixturesPath,"missing-source-map2.txt") + ], + "sourcesContent":[null], + "mappings":"AAAA" + }); + deps.should.be.eql([ + path.join(fixturesPath, "missing-source-map2.map") + ]); }); - deps.should.be.eql([ - path.join(fixturesPath, "missing-source-map2.map") - ]); - done(); - }); }); - it("should process inlined SourceMaps with charset", function(done) { - execLoader(path.join(fixturesPath, "charset-inline-source-map.js"), function(err, res, map, deps, warns) { - should.equal(err, null); - warns.should.be.eql([]); - should.equal(res, "with SourceMap\n// comment"); - map.should.be.eql({ - "version":3, - "file":"charset-inline-source-map.js", - "sources":[ - path.join(fixturesPath,"charset-inline-source-map.txt") - ], - "sourcesContent":["with SourceMap"], - "mappings":"AAAA" + it("should process inlined SourceMaps with charset", function() { + return execLoader(path.join(fixturesPath, "charset-inline-source-map.js")) + .then(function({res, map, deps, warns}) { + warns.should.be.eql([]); + should.equal(res, "with SourceMap\n// comment"); + map.should.be.eql({ + "version":3, + "file":"charset-inline-source-map.js", + "sources":[ + path.join(fixturesPath,"charset-inline-source-map.txt") + ], + "sourcesContent":["with SourceMap"], + "mappings":"AAAA" + }); + deps.should.be.eql([]); }); - deps.should.be.eql([]); - done(); - }); }); - it("should support absolute sourceRoot paths in sourcemaps", (done) => { + it("should support absolute sourceRoot paths in sourcemaps", () => { const sourceRoot = path.join(fixturesPath); const javaScriptFilename = "absolute-sourceRoot-source-map.js"; const sourceFilename = "absolute-sourceRoot-source-map.txt"; @@ -247,10 +231,8 @@ describe("source-map-loader", function() { }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); - execLoader( - path.join(fixturesPath, javaScriptFilename), - (err, res, map, deps, warns) => { - should.equal(err, null); + return execLoader(path.join(fixturesPath, javaScriptFilename)) + .then(function({res, map, deps, warns}) { warns.should.be.eql([]); should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ @@ -268,21 +250,18 @@ describe("source-map-loader", function() { sourceMapPath, rootRelativeSourcePath ]); - done(); } ); }); - it("should support relative sourceRoot paths in sourcemaps", (done) => { + it("should support relative sourceRoot paths in sourcemaps", () => { const javaScriptFilename = "relative-sourceRoot-source-map.js"; const sourceFilename = "relative-sourceRoot-source-map.txt"; const rootRelativeSourcePath = path.join(dataPath, sourceFilename); const sourceMapPath = path.join(fixturesPath, "relative-sourceRoot-source-map.map"); - execLoader( - path.join(fixturesPath, javaScriptFilename), - (err, res, map, deps, warns) => { - should.equal(err, null); + return execLoader(path.join(fixturesPath, javaScriptFilename)) + .then(function({res, map, deps, warns}) { warns.should.be.eql([]); should.equal(res, "with SourceMap\n// comment"); map.should.be.eql({ @@ -300,21 +279,18 @@ describe("source-map-loader", function() { sourceMapPath, rootRelativeSourcePath ]); - done(); } ); }); - it("should support null value in sourcesContent", (done) => { + it("should support null value in sourcesContent", () => { const javaScriptFilename = "null-sourcesContent-source-map.js"; const sourceFilename = "null-sourcesContent-source-map.txt"; const rootRelativeSourcePath = path.join(fixturesPath, sourceFilename); const sourceMapPath = path.join(fixturesPath, "null-sourcesContent-source-map.map"); - execLoader( - path.join(fixturesPath, javaScriptFilename), - (err, res, map, deps, warns) => { - should.equal(err, null); + return execLoader(path.join(fixturesPath, javaScriptFilename)) + .then(function({res, map, deps, warns}) { warns.should.be.eql([]); should.equal(res, "with SourceMap\n"); map.should.be.eql({ @@ -332,21 +308,18 @@ describe("source-map-loader", function() { sourceMapPath, rootRelativeSourcePath ]); - done(); } ); }); - it("should resolve relative sources path even with sourcesContent", (done) => { + it("should resolve relative sources path even with sourcesContent", () => { const javaScriptFilename = "relative-sourceRoot-sourcesContent-source-map.js"; const sourceFilename = "relative-sourceRoot-sourcesContent-source-map.txt"; const rootRelativeSourcePath = path.join(dataPath, sourceFilename); const sourceMapPath = path.join(fixturesPath, "relative-sourceRoot-sourcesContent-source-map.map"); - execLoader( - path.join(fixturesPath, javaScriptFilename), - (err, res, map, deps, warns) => { - should.equal(err, null); + return execLoader(path.join(fixturesPath, javaScriptFilename)) + .then(function({res, map, deps, warns}) { warns.should.be.eql([]); should.equal(res, "with SourceMap\n"); map.should.be.eql({ @@ -363,7 +336,6 @@ describe("source-map-loader", function() { deps.should.be.eql([ sourceMapPath ]); - done(); } ); }); From 241ea1a27c64e01ea50a1bef4b00c16b9e80bc74 Mon Sep 17 00:00:00 2001 From: Jeremy Judeaux Date: Thu, 22 Nov 2018 09:42:01 +0800 Subject: [PATCH 8/8] emitWarning is expecting an Error object --- index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index fe12fce..df899fb 100644 --- a/index.js +++ b/index.js @@ -43,19 +43,20 @@ module.exports = function(input, inputMap) { try { map = JSON.parse(mapStr) } catch (e) { - emitWarning("Cannot parse inline SourceMap '" + mapBase64.substr(0, 50) + "': " + e); + emitWarning(new Error("Cannot parse inline SourceMap '" + + mapBase64.substr(0, 50) + "': " + e)); return untouched(); } processMap(map, this.context, callback); } else { resolveAbsolutePath(this.context, url, function(err, absoluteFilepath) { if(err) { - emitWarning("Cannot find SourceMap '" + url + "': " + err); + emitWarning(new Error("Cannot find SourceMap '" + url + "': " + err)); return untouched(); } fs.readFile(absoluteFilepath, "utf-8", function(err, content) { if(err) { - emitWarning("Cannot open SourceMap '" + absoluteFilepath + "': " + err); + emitWarning(new Error("Cannot open SourceMap '" + absoluteFilepath + "': " + err)); return untouched(); } addDependency(absoluteFilepath); @@ -63,7 +64,7 @@ module.exports = function(input, inputMap) { try { map = JSON.parse(content); } catch (e) { - emitWarning("Cannot parse SourceMap '" + url + "': " + e); + emitWarning(new Error("Cannot parse SourceMap '" + url + "': " + e)); return untouched(); } processMap(map, path.dirname(absoluteFilepath), callback); @@ -101,7 +102,7 @@ module.exports = function(input, inputMap) { const sourcesPromises = sources.map((source, sourceIndex) => new Promise((resolveSource) => { resolveAbsolutePath(context, source, function(err, absoluteFilepath) { if(err) { - emitWarning("Cannot find source file '" + source + "': " + err); + emitWarning(new Error("Cannot find source file '" + source + "': " + err)); return resolveSource({ source: source, content: sourcesContent[sourceIndex] != null ? sourcesContent[sourceIndex] : null @@ -115,7 +116,7 @@ module.exports = function(input, inputMap) { } fs.readFile(absoluteFilepath, "utf-8", function(err, content) { if(err) { - emitWarning("Cannot open source file '" + absoluteFilepath + "': " + err); + emitWarning(new Error("Cannot open source file '" + absoluteFilepath + "': " + err)); return resolveSource({ source: absoluteFilepath, content: null