source-map-loader
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.2.2"></a> | ||
## [0.2.2](https://github.com/webpack/source-map-loader/compare/v0.2.1...v0.2.2) (2017-09-30) | ||
### Bug Fixes | ||
* Handle exception on loading invalid base64 source maps ([#53](https://github.com/webpack/source-map-loader/issues/53)) ([38da2eb](https://github.com/webpack/source-map-loader/commit/38da2eb)) | ||
<a name="0.2.1"></a> | ||
@@ -7,0 +17,0 @@ ## [0.2.1](https://github.com/webpack/source-map-loader/compare/v0.2.0...v0.2.1) (2017-03-30) |
13
index.js
@@ -18,3 +18,3 @@ /* | ||
// Matches DataUrls | ||
regexDataUrl = /data:[^;\n]+(?:;charset=[^;\n]+)?;base64,(.*)/; | ||
regexDataUrl = /data:[^;\n]+(?:;charset=[^;\n]+)?;base64,([a-zA-Z0-9+/]+={0,2})/; | ||
@@ -32,3 +32,12 @@ module.exports = function(input, inputMap) { | ||
if(dataUrlMatch) { | ||
processMap(JSON.parse((new Buffer(dataUrlMatch[1], "base64")).toString()), this.context, callback); | ||
var mapBase64 = dataUrlMatch[1]; | ||
var mapStr = (new Buffer(mapBase64, "base64")).toString(); | ||
var map; | ||
try { | ||
map = JSON.parse(mapStr) | ||
} catch (e) { | ||
emitWarning("Cannot parse inline SourceMap '" + mapBase64.substr(0, 50) + "': " + e); | ||
return untouched(); | ||
} | ||
processMap(map, this.context, callback); | ||
} else { | ||
@@ -35,0 +44,0 @@ resolve(this.context, loaderUtils.urlToRequest(url), function(err, result) { |
{ | ||
"name": "source-map-loader", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -5,0 +5,0 @@ "description": "extracts inlined source map and offers it to webpack", |
@@ -12,3 +12,3 @@ [![npm][npm]][npm-url] | ||
<h1>Sourcemap Loader</h1> | ||
<p>Extracts SourceMaps for source files that as added as `sourceMappingURL` comment.<p> | ||
<p>Extracts source maps from existing source files (from their <code>sourceMappingURL</code>).<p> | ||
</div> | ||
@@ -43,4 +43,8 @@ | ||
This extracts SourceMaps from all js files (including node_modules). This is not very performant, so you may want to only apply the loader to relevant files. | ||
`source-map-loader` extracts existing source maps from all JavaScript entries. This includes both inline source maps as well as those linked via URL. All source map data is passed to webpack for processing as per a chosen [source map style](https://webpack.js.org/configuration/devtool/) specified by the `devtool` option in [webpack.config.js](https://webpack.js.org/configuration/). | ||
This loader is especially useful when using 3rd-party libraries having their own source maps. If not extracted and processed into the souce map of the webpack bundle, browsers may misinterpret source map data. `source-map-loader` allows webpack to maintain source map data continuity across libraries so ease of debugging is preserved. | ||
`source-map-loader` will extract from any JavaScript file, including those in the `node_modules` directory. Be mindful in setting [include](https://webpack.js.org/configuration/module/#rule-include) and [exclude](https://webpack.js.org/configuration/module/#rule-exclude) rule conditions to maximize bundling performance. | ||
<h2 align="center">Maintainers</h2> | ||
@@ -47,0 +51,0 @@ |
@@ -130,2 +130,24 @@ var path = require("path"); | ||
}); | ||
it("should skip invalid base64 SourceMap", function (done) { | ||
execLoader(path.join(__dirname, "fixtures", "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 warn on invalid base64 SourceMap", function (done) { | ||
execLoader(path.join(__dirname, "fixtures", "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 warn on missing SourceMap", function(done) { | ||
@@ -132,0 +154,0 @@ execLoader(path.join(__dirname, "fixtures", "missing-source-map.js"), function(err, res, map, deps, warns) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55383
24
324
90