Skip to content

Commit d782d0d

Browse files
committed
Fix incremental compilation with no changed files, fix #342
1 parent 623959b commit d782d0d

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/compiler.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ export class ProjectCompiler implements ICompiler {
4242
return;
4343
}
4444

45+
let root = this.project.input.commonBasePath;
46+
let rootFilenames: string[] = this.project.input.getFileNames(true);
47+
if (!this.project.singleOutput) {
48+
// Add an empty file under the root.
49+
// This will make sure the commonSourceDirectory, calculated by TypeScript, won't point to a subdirectory of the root.
50+
// We cannot use the `rootDir` option here, since that gives errors if the commonSourceDirectory points to a
51+
// directory containing the rootDir instead of the rootDir, which will break the build when using `noEmitOnError`.
52+
// The empty file is filtered out later on.
53+
let emptyFileName = path.join(this.project.options['rootDir'] ? path.resolve(this.project.projectDirectory, this.project.options['rootDir']) : root, '________________empty.ts');
54+
rootFilenames.push(emptyFileName);
55+
this.project.input.addContent(emptyFileName, '');
56+
}
57+
4558
if (!this.project.input.isChanged(true)) {
4659
// Re-use old output
4760
const old = this.project.previousOutput;
@@ -64,7 +77,6 @@ export class ProjectCompiler implements ICompiler {
6477
return;
6578
}
6679

67-
let root = this.project.input.commonBasePath;
6880
this.project.options.sourceRoot = root;
6981

7082
this.host = new Host(
@@ -75,24 +87,11 @@ export class ProjectCompiler implements ICompiler {
7587
this.project.options.target >= ts.ScriptTarget.ES6 ? 'lib.es6.d.ts' : 'lib.d.ts'
7688
);
7789

78-
let rootFilenames: string[] = this.project.input.getFileNames(true);
79-
8090
if (this.project.filterSettings !== undefined) {
8191
let filter = new Filter(this.project, this.project.filterSettings);
8292
rootFilenames = rootFilenames.filter((fileName) => filter.match(fileName));
8393
}
8494

85-
if (!this.project.singleOutput) {
86-
// Add an empty file under the root.
87-
// This will make sure the commonSourceDirectory, calculated by TypeScript, won't point to a subdirectory of the root.
88-
// We cannot use the `rootDir` option here, since that gives errors if the commonSourceDirectory points to a
89-
// directory containing the rootDir instead of the rootDir, which will break the build when using `noEmitOnError`.
90-
// The empty file is filtered out later on.
91-
let emptyFileName = path.join(this.project.options['rootDir'] ? path.resolve(this.project.projectDirectory, this.project.options['rootDir']) : root, '________________empty.ts');
92-
rootFilenames.push(emptyFileName);
93-
this.project.input.addContent(emptyFileName, '');
94-
}
95-
9695
// Creating a program to compile the sources
9796
// We cast to `tsApi.CreateProgram` so we can pass the old program as an extra argument.
9897
// TS 1.6+ will try to reuse program structure (if possible)

0 commit comments

Comments
 (0)