Skip to content

Commit 0714c41

Browse files
hanslcwramsey
authored andcommitted
fix: regenerate the program on file change, and only once per rerun
1 parent ebe438d commit 0714c41

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

lib/broccoli/broccoli-typescript.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class BroccoliTypeScriptCompiler extends Plugin {
5252
var entries = this.listEntries();
5353
const inputPath = this.inputPaths[0];
5454

55+
const pathsToEmit = [];
56+
5557
entries.forEach(entry => {
5658
const tsFilePath = path.join(inputPath, entry.relativePath);
5759
if (!tsFilePath.match(/\.ts$/) || !fs.existsSync(tsFilePath)) {
@@ -66,13 +68,11 @@ class BroccoliTypeScriptCompiler extends Plugin {
6668
// not get compiled. It needs to be referenced at some point, and unless we
6769
// add the spec files first (which we don't know the order), it won't.
6870
// So make every new files an entry point instead.
69-
// TODO(hansl): We should rather build a list and recreate the program only once.
70-
// We need to investigate if we should emit files that are not
71+
// TODO(hansl): We need to investigate if we should emit files that are not
7172
// referenced. This doesn't take that into account.
7273
this._tsServiceHost.fileNames.push(tsFilePath);
7374

74-
// Force the TS Service to recreate the program (ie. call synchronizeHostData).
75-
this._tsServiceHost.projectVersion++;
75+
pathsToEmit.push(tsFilePath);
7676
} else if (this._fileRegistry[tsFilePath].version >= entry.mtime) {
7777
// Nothing to do for this file. Just link the cached outputs.
7878
this._fileRegistry[tsFilePath].outputs.forEach(absoluteFilePath => {
@@ -83,21 +83,29 @@ class BroccoliTypeScriptCompiler extends Plugin {
8383
return;
8484
} else {
8585
this._fileRegistry[tsFilePath].version = entry.mtime;
86+
pathsToEmit.push(tsFilePath);
8687
}
88+
});
8789

88-
var output = this._tsService.getEmitOutput(tsFilePath);
89-
if (output.emitSkipped) {
90-
var errorFound = this.collectErrors(tsFilePath);
91-
if (errorFound) {
92-
pathsWithErrors.push(tsFilePath);
93-
errorMessages.push(errorFound);
90+
if (pathsToEmit.length > 0) {
91+
// Force the TS Service to recreate the program (ie. call synchronizeHostData).
92+
this._tsServiceHost.projectVersion++;
93+
94+
pathsToEmit.forEach(tsFilePath => {
95+
var output = this._tsService.getEmitOutput(tsFilePath);
96+
if (output.emitSkipped) {
97+
var errorFound = this.collectErrors(tsFilePath);
98+
if (errorFound) {
99+
pathsWithErrors.push(tsFilePath);
100+
errorMessages.push(errorFound);
101+
}
102+
} else {
103+
output.outputFiles.forEach(o => {
104+
this._outputFile(o.name, o.text, this._fileRegistry[tsFilePath]);
105+
});
94106
}
95-
} else {
96-
output.outputFiles.forEach(o => {
97-
this._outputFile(o.name, o.text, this._fileRegistry[tsFilePath]);
98-
});
99-
}
100-
});
107+
});
108+
}
101109

102110
if (pathsWithErrors.length) {
103111
this.previousRunFailed = true;
@@ -254,6 +262,7 @@ class CustomLanguageServiceHost {
254262
}
255263

256264
getScriptVersion(fileName) {
265+
fileName = path.resolve(this.treeInputPath, fileName);
257266
return this.fileRegistry[fileName] && this.fileRegistry[fileName].version.toString();
258267
}
259268

0 commit comments

Comments
 (0)