@@ -195,6 +195,7 @@ class BroccoliTypeScriptCompiler extends Plugin {
195
195
196
196
_outputFile ( absoluteFilePath , fileContent , registry ) {
197
197
absoluteFilePath = path . resolve ( this . cachePath , absoluteFilePath ) ;
198
+ let inputFilePath = absoluteFilePath ;
198
199
// Replace the input path by the output.
199
200
absoluteFilePath = absoluteFilePath . replace ( this . inputPaths [ 0 ] , this . cachePath ) ;
200
201
const outputFilePath = absoluteFilePath . replace ( this . cachePath , this . outputPath ) ;
@@ -204,7 +205,7 @@ class BroccoliTypeScriptCompiler extends Plugin {
204
205
}
205
206
206
207
fse . mkdirsSync ( path . dirname ( absoluteFilePath ) ) ;
207
- const content = this . fixSourceMapSources ( fileContent ) ;
208
+ const content = this . fixSourceMapSources ( fileContent , inputFilePath ) ;
208
209
fs . writeFileSync ( absoluteFilePath , content , FS_OPTS ) ;
209
210
210
211
fse . mkdirsSync ( path . dirname ( outputFilePath ) ) ;
@@ -242,12 +243,31 @@ class BroccoliTypeScriptCompiler extends Plugin {
242
243
* This issue is fixed in https://github.com/Microsoft/TypeScript/pull/5620.
243
244
* Once we switch to TypeScript 1.8, we can remove this method.
244
245
*/
245
- fixSourceMapSources ( content ) {
246
+ fixSourceMapSources ( content , inputFilePath ) {
246
247
try {
247
- var marker = '//# sourceMappingURL=data:application/json;base64,' ;
248
- var index = content . indexOf ( marker ) ;
249
- if ( index == - 1 )
250
- return content ;
248
+ const marker = '//# sourceMappingURL=data:application/json;base64,' ;
249
+
250
+ let index = content . indexOf ( marker ) ;
251
+ if ( index == - 1 ) {
252
+ const pathMarker = '//# sourceMappingURL=' ;
253
+ index = content . indexOf ( pathMarker ) ;
254
+ if ( index == - 1 ) {
255
+ return content ;
256
+ }
257
+
258
+ // We have a regular path, make it relative to the input path.
259
+ let base = content . substring ( 0 , index + pathMarker . length ) ;
260
+ let mapPath = content . substring ( index + pathMarker . length ) ;
261
+ if ( mapPath . startsWith ( this . outputPath ) ) {
262
+ mapPath = mapPath . replace ( this . outputPath , this . inputPaths [ 0 ] ) ;
263
+ } else if ( ! mapPath . startsWith ( this . inputPaths [ 0 ] ) ) {
264
+ mapPath = path . join ( this . inputPaths [ 0 ] , path . dirname ( this . _tsConfigPath ) , mapPath ) ;
265
+ }
266
+
267
+ mapPath = path . relative ( path . dirname ( inputFilePath ) , mapPath ) ;
268
+ return '' + base + mapPath ;
269
+ }
270
+
251
271
var base = content . substring ( 0 , index + marker . length ) ;
252
272
var sourceMapBit = new Buffer ( content . substring ( index + marker . length ) , 'base64' ) . toString ( 'utf8' ) ;
253
273
var sourceMaps = JSON . parse ( sourceMapBit ) ;
0 commit comments