diff --git a/src/compiler/program.ts b/src/compiler/program.ts index af404ba57ad..4dfb9039ccf 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2667,6 +2667,11 @@ namespace ts { return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts); } + // If declarationDir is specified, return if its a file in that directory + if (options.declarationDir && containsPath(options.declarationDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames())) { + return true; + } + // If --outDir, check if file is in that directory if (options.outDir) { return containsPath(options.outDir, filePath, currentDirectory, !host.useCaseSensitiveFileNames()); @@ -2675,8 +2680,8 @@ namespace ts { if (fileExtensionIsOneOf(filePath, supportedJavascriptExtensions) || fileExtensionIs(filePath, Extension.Dts)) { // Otherwise just check if sourceFile with the name exists const filePathWithoutExtension = removeFileExtension(filePath); - return !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Ts) as Path) || - !!getSourceFileByPath(combinePaths(filePathWithoutExtension, Extension.Tsx) as Path); + return !!getSourceFileByPath((filePathWithoutExtension + Extension.Ts) as Path) || + !!getSourceFileByPath((filePathWithoutExtension + Extension.Tsx) as Path); } return false; } diff --git a/src/harness/unittests/tscWatchMode.ts b/src/harness/unittests/tscWatchMode.ts index f2ef80ce515..44b6c8ea887 100644 --- a/src/harness/unittests/tscWatchMode.ts +++ b/src/harness/unittests/tscWatchMode.ts @@ -1116,34 +1116,53 @@ namespace ts.tscWatch { assert.equal(nowErrors[1].start, intialErrors[1].start! - configFileContentComment.length); }); - it("should not trigger recompilation because of program emit", () => { - const proj = "/user/username/projects/myproject"; - const file1: File = { - path: `${proj}/file1.ts`, - content: "export const c = 30;" - }; - const file2: File = { - path: `${proj}/src/file2.ts`, - content: `import {c} from "file1"; export const d = 30;` - }; - const tsconfig: File = { - path: `${proj}/tsconfig.json`, - content: JSON.stringify({ - compilerOptions: { - module: "amd", - outDir: "build" - } - }) - }; - const host = createWatchedSystem([file1, file2, libFile, tsconfig], { currentDirectory: proj }); - const watch = createWatchOfConfigFile(tsconfig.path, host, /*maxNumberOfFilesToIterateForInvalidation*/1); - checkProgramActualFiles(watch(), [file1.path, file2.path, libFile.path]); + describe("should not trigger should not trigger recompilation because of program emit", () => { + function verifyWithOptions(options: CompilerOptions, outputFiles: ReadonlyArray) { + const proj = "/user/username/projects/myproject"; + const file1: File = { + path: `${proj}/file1.ts`, + content: "export const c = 30;" + }; + const file2: File = { + path: `${proj}/src/file2.ts`, + content: `import {c} from "file1"; export const d = 30;` + }; + const tsconfig: File = { + path: `${proj}/tsconfig.json`, + content: generateTSConfig(options, emptyArray, "\n") + }; + const host = createWatchedSystem([file1, file2, libFile, tsconfig], { currentDirectory: proj }); + const watch = createWatchOfConfigFile(tsconfig.path, host, /*maxNumberOfFilesToIterateForInvalidation*/1); + checkProgramActualFiles(watch(), [file1.path, file2.path, libFile.path]); - assert.isTrue(host.fileExists("build/file1.js")); - assert.isTrue(host.fileExists("build/src/file2.js")); + outputFiles.forEach(f => host.fileExists(f)); - // This should be 0 - host.checkTimeoutQueueLengthAndRun(0); + // This should be 0 + host.checkTimeoutQueueLengthAndRun(0); + } + + it("without outDir or outFile is specified", () => { + debugger; + verifyWithOptions({ module: ModuleKind.AMD }, ["file1.js", "src/file2.js"]); + }); + + it("with outFile", () => { + verifyWithOptions({ module: ModuleKind.AMD, outFile: "build/outFile.js" }, ["build/outFile.js"]); + }); + + it("when outDir is specified", () => { + verifyWithOptions({ module: ModuleKind.AMD, outDir: "build" }, ["build/file1.js", "build/src/file2.js"]); + }); + + it("when outDir and declarationDir is specified", () => { + verifyWithOptions({ module: ModuleKind.AMD, outDir: "build", declaration: true, declarationDir: "decls" }, + ["build/file1.js", "build/src/file2.js", "decls/file1.d.ts", "decls/src/file2.d.ts"]); + }); + + it("declarationDir is specified", () => { + verifyWithOptions({ module: ModuleKind.AMD, declaration: true, declarationDir: "decls" }, + ["file1.js", "src/file2.js", "decls/file1.d.ts", "decls/src/file2.d.ts"]); + }); }); it("shouldnt report error about unused function incorrectly when file changes from global to module", () => { diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 28a8bdb114a..f6efe8b99dd 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -8314,7 +8314,7 @@ new C();` }); }); - describe("watchDirectories implementation", () => { + describe("tsserverProjectSystem watchDirectories implementation", () => { function verifyCompletionListWithNewFileInSubFolder(tscWatchDirectory: TestFSWithWatch.Tsc_WatchDirectory) { const projectFolder = "/a/username/project"; const projectSrcFolder = `${projectFolder}/src`; @@ -8422,7 +8422,7 @@ new C();` }); }); - describe("document registry in project service", () => { + describe("tsserverProjectSystem document registry in project service", () => { const projectRootPath = "/user/username/projects/project"; const importModuleContent = `import {a} from "./module1"`; const file: File = {