File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -103,14 +103,26 @@ function buildFile(file, silent) {
103103 } (copy)\n`,
104104 ) ;
105105 } else {
106- const options = Object . assign ( { } , transformOptions ) ;
106+ const options = {
107+ ...transformOptions ,
108+ sourceMaps : true ,
109+ sourceFileName : path . basename ( file ) ,
110+ } ;
107111
108112 let { code, map} = babel . transformFileSync ( file , options ) ;
109113
110- if ( ! file . endsWith ( '.d.ts' ) && map . sources . length > 0 ) {
111- code = `${ code } \n\n//# sourceMappingURL=${ destPath } .map` ;
112- map . sources = [ path . relative ( path . dirname ( destPath ) , file ) ] ;
113- fs . writeFileSync ( `${ destPath } .map` , JSON . stringify ( map ) ) ;
114+ if ( ! file . endsWith ( '.d.ts' ) ) {
115+ const outDir = path . dirname ( destPath ) ;
116+ const outFile = path . basename ( destPath ) ;
117+ const mapFileName = `${ outFile } .map` ;
118+ const mapPath = path . join ( outDir , mapFileName ) ;
119+
120+ // Normalize/override key fields for consistency
121+ map . file = outFile ;
122+ map . sources = [ path . relative ( outDir , file ) . replace ( / \\ / g, '/' ) ] ;
123+
124+ code = `${ code } \n\n//# sourceMappingURL=${ mapFileName } ` ;
125+ fs . writeFileSync ( mapPath , JSON . stringify ( map ) ) ;
114126 }
115127
116128 fs . writeFileSync ( destPath , code ) ;
You can’t perform that action at this time.
0 commit comments