@@ -22,7 +22,6 @@ function getOptions(sourceMapEnabled, filename) {
22
22
options . map = {
23
23
inline : false ,
24
24
inFile : filename ,
25
- sourceRoot : filename
26
25
} ;
27
26
}
28
27
@@ -33,28 +32,22 @@ function getOptions(sourceMapEnabled, filename) {
33
32
return options ;
34
33
}
35
34
36
-
37
- module . exports = function ( source , inputSourceMap ) {
35
+ function mergeSourceMaps ( inputSourceMap , annotateMap ) {
38
36
var outputSourceMap ;
39
37
var sourceMapEnabled = this . sourceMap ;
40
- var filename = utils . getCurrentRequest ( this ) ;
38
+ var filename = this . resourcePath ;
41
39
this . cacheable && this . cacheable ( ) ;
42
40
43
- var annotateResult = ngAnnotate ( source , getOptions . call ( this , sourceMapEnabled , filename ) ) ;
44
-
45
- // Merge source maps. Using BabelJS as an example,
41
+ // Using BabelJS as an example,
46
42
// https://github.com./babel/babel/blob/d3a73b87e9007104cb4fec343f0cfb9e1c67a4ec/packages/babel/src/transformation/file/index.js#L465
47
43
// See also vinyl-sourcemaps-apply (used by gulp-ng-annotate) - https://github.com./floridoo/vinyl-sourcemaps-apply/blob/master/index.js
48
44
if ( sourceMapEnabled && inputSourceMap ) {
49
- if ( annotateResult . map ) {
50
- var annotateMap = JSON . parse ( annotateResult . map ) ;
51
- //Sources array should be filled somehow to work with source-map package
52
- annotateMap . sources [ 0 ] = inputSourceMap . file ;
45
+ if ( annotateMap ) {
53
46
var generator = SourceMapGenerator . fromSourceMap ( new SourceMapConsumer ( annotateMap ) ) ;
54
- generator . applySourceMap ( new SourceMapConsumer ( inputSourceMap ) ) ;
47
+ generator . applySourceMap ( new SourceMapConsumer ( inputSourceMap ) , filename ) ;
55
48
56
49
outputSourceMap = generator . toJSON ( ) ;
57
- outputSourceMap . sources = inputSourceMap . sources ;
50
+
58
51
//Should be set to avoid '../../file is not in SourceMap error https://github.com./huston007/ng-annotate-loader/pull/11'
59
52
outputSourceMap . sourceRoot = '' ;
60
53
//Copy file name from incoming file because it is empty by some unknown reaon
@@ -64,5 +57,16 @@ module.exports = function(source, inputSourceMap) {
64
57
}
65
58
}
66
59
60
+ return outputSourceMap ;
61
+ }
62
+
63
+ module . exports = function ( source , inputSourceMap ) {
64
+ var sourceMapEnabled = this . sourceMap ;
65
+ var filename = this . resourcePath ;
66
+ this . cacheable && this . cacheable ( ) ;
67
+
68
+ var annotateResult = ngAnnotate ( source , getOptions . call ( this , sourceMapEnabled , filename ) ) ;
69
+ var outputSourceMap = mergeSourceMaps . call ( this , inputSourceMap , annotateResult . map ) ;
70
+
67
71
this . callback ( null , annotateResult . src || source , outputSourceMap ) ;
68
72
} ;
0 commit comments