Skip to content

Commit b0c67fd

Browse files
authored
Merge pull request microsoft#24056 from a-tarasyuk/bug/23891-declarationDir-needs-to-be-handled-in-excludeSpecs
Add declarationDir to excludeSpec
2 parents cc36cfc + 60d39d7 commit b0c67fd

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/compiler/commandLineParser.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,10 +1607,12 @@ namespace ts {
16071607
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array");
16081608
}
16091609
}
1610-
else {
1611-
const outDir = raw.compilerOptions && raw.compilerOptions.outDir;
1612-
if (outDir) {
1613-
excludeSpecs = [outDir];
1610+
else if (raw.compilerOptions) {
1611+
const outDir = raw.compilerOptions.outDir;
1612+
const declarationDir = raw.compilerOptions.declarationDir;
1613+
1614+
if (outDir || declarationDir) {
1615+
excludeSpecs = [outDir, declarationDir].filter(d => !!d);
16141616
}
16151617
}
16161618

src/harness/unittests/tsconfigParsing.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,29 @@ namespace ts {
217217
assertParseFileList(tsconfigWithExclude, "tsconfig.json", rootDir, allFiles, allFiles);
218218
});
219219

220+
it("exclude declarationDir unless overridden", () => {
221+
const tsconfigWithoutExclude =
222+
`{
223+
"compilerOptions": {
224+
"declarationDir": "declarations"
225+
}
226+
}`;
227+
const tsconfigWithExclude =
228+
`{
229+
"compilerOptions": {
230+
"declarationDir": "declarations"
231+
},
232+
"exclude": [ "types" ]
233+
}`;
234+
235+
const rootDir = "/";
236+
const allFiles = ["/declarations/a.d.ts", "/a.ts"];
237+
const expectedFiles = ["/a.ts"];
238+
239+
assertParseFileList(tsconfigWithoutExclude, "tsconfig.json", rootDir, allFiles, expectedFiles);
240+
assertParseFileList(tsconfigWithExclude, "tsconfig.json", rootDir, allFiles, allFiles);
241+
});
242+
220243
it("implicitly exclude common package folders", () => {
221244
assertParseFileList(
222245
`{}`,

0 commit comments

Comments
 (0)