@ -103,7 +103,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
output.outputFiles.forEach(o => {
|
||||
let destDirPath = path.dirname(o.name);
|
||||
fse.mkdirsSync(destDirPath);
|
||||
fs.writeFileSync(o.name, o.text, FS_OPTS);
|
||||
fs.writeFileSync(o.name, this.fixSourceMapSources(o.text), FS_OPTS);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -145,9 +145,9 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
|
||||
private doFullBuild() {
|
||||
let program = this.tsService.getProgram();
|
||||
let emitResult = program.emit(undefined, function(absoluteFilePath, fileContent) {
|
||||
let emitResult = program.emit(undefined, (absoluteFilePath, fileContent) => {
|
||||
fse.mkdirsSync(path.dirname(absoluteFilePath));
|
||||
fs.writeFileSync(absoluteFilePath, fileContent, FS_OPTS);
|
||||
fs.writeFileSync(absoluteFilePath, this.fixSourceMapSources(fileContent), FS_OPTS);
|
||||
});
|
||||
|
||||
if (emitResult.emitSkipped) {
|
||||
@ -176,6 +176,33 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* There is a bug in TypeScript 1.6, where the sourceRoot and inlineSourceMap properties
|
||||
* are exclusive. This means that the sources property always contains relative paths
|
||||
* (e.g, ../../../../angular2/src/di/injector.ts).
|
||||
*
|
||||
* Here, we normalize the sources property and remove the ../../../
|
||||
*
|
||||
* This issue is fixed in https://github.com/Microsoft/TypeScript/pull/5620.
|
||||
* Once we switch to TypeScript 1.8, we can remove this method.
|
||||
*/
|
||||
private fixSourceMapSources(content: string): string {
|
||||
try {
|
||||
const marker = "//# sourceMappingURL=data:application/json;base64,";
|
||||
const index = content.indexOf(marker);
|
||||
if (index == -1) return content;
|
||||
|
||||
const base = content.substring(0, index + marker.length);
|
||||
const sourceMapBit =
|
||||
new Buffer(content.substring(index + marker.length), 'base64').toString("utf8");
|
||||
const sourceMaps = JSON.parse(sourceMapBit);
|
||||
const source = sourceMaps.sources[0];
|
||||
sourceMaps.sources = [source.substring(source.lastIndexOf("../") + 3)];
|
||||
return `${base}${new Buffer(JSON.stringify(sourceMaps)).toString('base64')}`;
|
||||
} catch (e) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private removeOutputFor(tsFilePath: string) {
|
||||
let absoluteJsFilePath = path.join(this.cachePath, tsFilePath.replace(/\.ts$/, '.js'));
|
||||
|
Reference in New Issue
Block a user