Skip to content

Commit 9b9ec63

Browse files
authored
Merge pull request #24390 from Microsoft/isEmittedDeclarationFile
Do not trigger invalidation if emitted file is in declarationDir
2 parents 4be4e56 + 51058b5 commit 9b9ec63

File tree

3 files changed

+54
-30
lines changed

3 files changed

+54
-30
lines changed

src/compiler/program.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,11 @@ namespace ts {
26672667
return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts);
26682668
}
26692669

2670+
// If declarationDir is specified, return if its a file in that directory
2671+
if (options.declarationDir && containsPath(options.declarationDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames())) {
2672+
return true;
2673+
}
2674+
26702675
// If --outDir, check if file is in that directory
26712676
if (options.outDir) {
26722677
return containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames());
@@ -2675,8 +2680,8 @@ namespace ts {
26752680
if (fileExtensionIsOneOf(filePath, supportedJavascriptExtensions) || fileExtensionIs(filePath, Extension.Dts)) {
26762681
// Otherwise just check if sourceFile with the name exists
26772682
const filePathWithoutExtension = removeFileExtension(filePath);
2678-
return !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Ts) as Path) ||
2679-
!!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Tsx) as Path);
2683+
return !!getSourceFileByPath((filePathWithoutExtension + Extension.Ts) as Path) ||
2684+
!!getSourceFileByPath((filePathWithoutExtension + Extension.Tsx) as Path);
26802685
}
26812686
return false;
26822687
}

src/harness/unittests/tscWatchMode.ts

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,34 +1116,53 @@ namespace ts.tscWatch {
11161116
assert.equal(nowErrors[1].start, intialErrors[1].start! - configFileContentComment.length);
11171117
});
11181118

1119-
it("should not trigger recompilation because of program emit", () => {
1120-
const proj = "/user/username/projects/myproject";
1121-
const file1: File = {
1122-
path: `${proj}/file1.ts`,
1123-
content: "export const c = 30;"
1124-
};
1125-
const file2: File = {
1126-
path: `${proj}/src/file2.ts`,
1127-
content: `import {c} from "file1"; export const d = 30;`
1128-
};
1129-
const tsconfig: File = {
1130-
path: `${proj}/tsconfig.json`,
1131-
content: JSON.stringify({
1132-
compilerOptions: {
1133-
module: "amd",
1134-
outDir: "build"
1135-
}
1136-
})
1137-
};
1138-
const host = createWatchedSystem([file1, file2, libFile, tsconfig], { currentDirectory: proj });
1139-
const watch = createWatchOfConfigFile(tsconfig.path, host, /*maxNumberOfFilesToIterateForInvalidation*/1);
1140-
checkProgramActualFiles(watch(), [file1.path, file2.path, libFile.path]);
1119+
describe("should not trigger should not trigger recompilation because of program emit", () => {
1120+
function verifyWithOptions(options: CompilerOptions, outputFiles: ReadonlyArray<string>) {
1121+
const proj = "/user/username/projects/myproject";
1122+
const file1: File = {
1123+
path: `${proj}/file1.ts`,
1124+
content: "export const c = 30;"
1125+
};
1126+
const file2: File = {
1127+
path: `${proj}/src/file2.ts`,
1128+
content: `import {c} from "file1"; export const d = 30;`
1129+
};
1130+
const tsconfig: File = {
1131+
path: `${proj}/tsconfig.json`,
1132+
content: generateTSConfig(options, emptyArray, "\n")
1133+
};
1134+
const host = createWatchedSystem([file1, file2, libFile, tsconfig], { currentDirectory: proj });
1135+
const watch = createWatchOfConfigFile(tsconfig.path, host, /*maxNumberOfFilesToIterateForInvalidation*/1);
1136+
checkProgramActualFiles(watch(), [file1.path, file2.path, libFile.path]);
11411137

1142-
assert.isTrue(host.fileExists("build/file1.js"));
1143-
assert.isTrue(host.fileExists("build/src/file2.js"));
1138+
outputFiles.forEach(f => host.fileExists(f));
1139+
1140+
// This should be 0
1141+
host.checkTimeoutQueueLengthAndRun(0);
1142+
}
11441143

1145-
// This should be 0
1146-
host.checkTimeoutQueueLengthAndRun(0);
1144+
it("without outDir or outFile is specified", () => {
1145+
debugger;
1146+
verifyWithOptions({ module: ModuleKind.AMD }, ["file1.js", "src/file2.js"]);
1147+
});
1148+
1149+
it("with outFile", () => {
1150+
verifyWithOptions({ module: ModuleKind.AMD, outFile: "build/outFile.js" }, ["build/outFile.js"]);
1151+
});
1152+
1153+
it("when outDir is specified", () => {
1154+
verifyWithOptions({ module: ModuleKind.AMD, outDir: "build" }, ["build/file1.js", "build/src/file2.js"]);
1155+
});
1156+
1157+
it("when outDir and declarationDir is specified", () => {
1158+
verifyWithOptions({ module: ModuleKind.AMD, outDir: "build", declaration: true, declarationDir: "decls" },
1159+
["build/file1.js", "build/src/file2.js", "decls/file1.d.ts", "decls/src/file2.d.ts"]);
1160+
});
1161+
1162+
it("declarationDir is specified", () => {
1163+
verifyWithOptions({ module: ModuleKind.AMD, declaration: true, declarationDir: "decls" },
1164+
["file1.js", "src/file2.js", "decls/file1.d.ts", "decls/src/file2.d.ts"]);
1165+
});
11471166
});
11481167

11491168
it("shouldnt report error about unused function incorrectly when file changes from global to module", () => {

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8314,7 +8314,7 @@ new C();`
83148314
});
83158315
});
83168316

8317-
describe("watchDirectories implementation", () => {
8317+
describe("tsserverProjectSystem watchDirectories implementation", () => {
83188318
function verifyCompletionListWithNewFileInSubFolder(tscWatchDirectory: TestFSWithWatch.Tsc_WatchDirectory) {
83198319
const projectFolder = "/a/username/project";
83208320
const projectSrcFolder = `${projectFolder}/src`;
@@ -8422,7 +8422,7 @@ new C();`
84228422
});
84238423
});
84248424

8425-
describe("document registry in project service", () => {
8425+
describe("tsserverProjectSystem document registry in project service", () => {
84268426
const projectRootPath = "/user/username/projects/project";
84278427
const importModuleContent = `import {a} from "./module1"`;
84288428
const file: File = {

0 commit comments

Comments
 (0)