karma-sourcemap-loader
Advanced tools
Comparing version 0.1.1 to 0.2.0
41
index.js
var fs = require('fs'); | ||
var createSourceMapLocatorPreprocessor = function(args, logger, helper) { | ||
@@ -6,14 +7,34 @@ var log = logger.create('preprocessor.sourcemap'); | ||
return function(content, file, done) { | ||
var mapPath = file.path+".map"; | ||
fs.exists(mapPath, function(exists) { | ||
if (!exists) { | ||
done(content); | ||
return; | ||
var match = content.match(/#\s*sourceMappingURL=(data:application\/json.+)$/m); | ||
if (match !== null && match.length == 2) { | ||
// inline source map | ||
var data; | ||
var b64Match = match[1].match(/^data:.+\/(.+);base64,(.*)$/); | ||
if (b64Match !== null && b64Match.length == 3) { | ||
// base64-encoded JSON string | ||
log.debug('base64-encoded source map for', file.originalPath); | ||
var buffer = new Buffer(b64Match[2], 'base64'); | ||
data = buffer.toString(); | ||
} else { | ||
// straight-up URL-encoded JSON string | ||
log.debug('raw inline source map for', file.originalPath); | ||
data = decodeURIComponent(match[1].slice('data:application/json'.length)); | ||
} | ||
fs.readFile(mapPath, function(err, data) { | ||
if (err) throw err; | ||
file.sourceMap = JSON.parse(data); | ||
done(content); | ||
file.sourceMap = JSON.parse(data); | ||
done(content); | ||
} else { | ||
var mapPath = file.path+".map"; | ||
fs.exists(mapPath, function(exists) { | ||
if (!exists) { | ||
done(content); | ||
return; | ||
} | ||
fs.readFile(mapPath, function(err, data) { | ||
if (err) throw err; | ||
log.debug('external source map exists for', file.originalPath); | ||
file.sourceMap = JSON.parse(data); | ||
done(content); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
@@ -20,0 +41,0 @@ }; |
{ | ||
"name": "karma-sourcemap-loader", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Karma plugin that locates and loads existing javascript source map files.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# karma-sourcemap-loader | ||
> Preprocessor that locates and loads existing source map files. | ||
> Preprocessor that locates and loads existing source maps. | ||
@@ -14,10 +14,11 @@ ## Why | ||
Right now source maps are located via this rule: the preprocessors appends | ||
".map" to the file name, and if that file exists it loads and includes it. | ||
This plug-in supports both inline and external source maps. | ||
Inline source maps are located by searching "sourceMappingURL=" inside the javascript | ||
file, both plain text and base64-encoded maps are supported. | ||
External source maps are located by appending ".map" to the javascript file name. | ||
So if for example you have Hello.js, the preprocessor will try to load source map from | ||
Hello.js.map. | ||
This is very simple but should work in the majority of cases for standard usage (e.g. with typescript). | ||
## Installation | ||
@@ -29,3 +30,3 @@ | ||
"devDependencies": { | ||
"karma-sourcemap-loader": "~0.1" | ||
"karma-sourcemap-loader": "~0.2" | ||
} | ||
@@ -53,1 +54,5 @@ } | ||
``` | ||
## Credits | ||
Thanks to @goldibex for adding inline source mpas support. |
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
17938
13
43
55