-
Notifications
You must be signed in to change notification settings - Fork 7
/
karma_sourcemaps.js
46 lines (36 loc) · 1.15 KB
/
karma_sourcemaps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var SOURCE_MAP = /\.map$/;
function findFile(files, path) {
for (var i = 0, ii = files.length; i < ii; i++) {
if (files[i].path === path) {
return files[i];
}
}
return null;
}
function createSourceMapsPlugin(emitter, basePath, logger) {
var log = logger.create('sourcemaps');
emitter.on('file_list_modified', function(filesPromise) {
filesPromise.then(function(files) {
files.served.forEach(function(file) {
if (SOURCE_MAP.test(file.path)) {
var sourceMap = JSON.parse(file.content);
if (!sourceMap) {
log.warn('Invalid source map file', file.originalPath);
return;
}
var sourceFile = findFile(files.served, basePath + '/' + sourceMap.file);
if (!sourceFile) {
log.warn('Can not find source file for map', file.originalPath);
return
}
sourceMap.sourceRoot = basePath;
sourceFile.sourceMap = sourceMap;
}
});
});
});
}
createSourceMapsPlugin.$inject = ['emitter', 'config.basePath', 'logger'];
module.exports = {
'framework:sourcemaps': ['factory', createSourceMapsPlugin]
};