Skip to content

Commit c92bd16

Browse files
authored
Exclude outDir and declarationDir even if they come from extended config (#58335)
1 parent 04963ee commit c92bd16

14 files changed

+170
-35
lines changed

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,12 +2976,12 @@ function parseJsonConfigFileContentWorker(
29762976
const excludeOfRaw = getSpecsFromRaw("exclude");
29772977
let isDefaultIncludeSpec = false;
29782978
let excludeSpecs = toPropValue(excludeOfRaw);
2979-
if (excludeOfRaw === "no-prop" && raw.compilerOptions) {
2980-
const outDir = raw.compilerOptions.outDir;
2981-
const declarationDir = raw.compilerOptions.declarationDir;
2979+
if (excludeOfRaw === "no-prop") {
2980+
const outDir = options.outDir;
2981+
const declarationDir = options.declarationDir;
29822982

29832983
if (outDir || declarationDir) {
2984-
excludeSpecs = [outDir, declarationDir].filter(d => !!d);
2984+
excludeSpecs = filter([outDir, declarationDir], d => !!d) as string[];
29852985
}
29862986
}
29872987

src/testRunner/unittests/config/tsconfigParsing.ts

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
3232
jsonText: string;
3333
configFileName: string;
3434
basePath: string;
35-
allFileList: string[];
35+
allFileList: string[] | vfs.FileSet;
3636
}
3737

3838
function baselinedParsed(subScenario: string, scenario: () => VerifyConfig[], skipJson?: true) {
@@ -42,7 +42,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
4242
input: () =>
4343
scenario().map(({ jsonText, configFileName, basePath, allFileList }) => ({
4444
createHost: () => {
45-
const files = allFileList.reduce((files, value) => (files[value] = "", files), {} as vfs.FileSet);
45+
const files = ts.isArray(allFileList) ? allFileList.reduce((files, value) => (files[value] = "", files), {} as vfs.FileSet) : allFileList;
4646
files[ts.combinePaths(basePath, configFileName)] = jsonText;
4747
return new fakes.ParseConfigHost(
4848
new vfs.FileSystem(
@@ -211,6 +211,38 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
211211
];
212212
});
213213

214+
baselinedParsed("with outDir from base tsconfig", () => {
215+
const tsconfigWithoutConfigDir = jsonToReadableText({
216+
extends: "./tsconfigWithoutConfigDir.json",
217+
});
218+
const tsconfigWithConfigDir = jsonToReadableText({
219+
extends: "./tsconfigWithConfigDir.json",
220+
});
221+
const basePath = "/";
222+
return [
223+
{
224+
jsonText: tsconfigWithoutConfigDir,
225+
configFileName: "tsconfig.json",
226+
basePath,
227+
allFileList: {
228+
"/tsconfigWithoutConfigDir.json": jsonToReadableText({ compilerOptions: { outDir: "bin" } }),
229+
"/bin/a.ts": "",
230+
"/b.ts": "",
231+
},
232+
},
233+
{
234+
jsonText: tsconfigWithConfigDir,
235+
configFileName: "tsconfig.json",
236+
basePath,
237+
allFileList: {
238+
"/tsconfigWithConfigDir.json": jsonToReadableText({ compilerOptions: { outDir: "${configDir}/bin" } }), // eslint-disable-line no-template-curly-in-string
239+
"/bin/a.ts": "",
240+
"/b.ts": "",
241+
},
242+
},
243+
];
244+
});
245+
214246
baselinedParsed("implicitly exclude common package folders", () => [{
215247
jsonText: `{}`,
216248
configFileName: "tsconfig.json",
@@ -241,7 +273,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
241273
"files": []
242274
}`,
243275
configFileName: "/apath/tsconfig.json",
244-
basePath: "tests/cases/unittests",
276+
basePath: "/apath",
245277
allFileList: ["/apath/a.ts"],
246278
}]);
247279

@@ -251,7 +283,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
251283
"references": []
252284
}`,
253285
configFileName: "/apath/tsconfig.json",
254-
basePath: "tests/cases/unittests",
286+
basePath: "/apath",
255287
allFileList: ["/apath/a.ts"],
256288
}]);
257289

@@ -261,15 +293,15 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
261293
"references": [{ "path": "/apath" }]
262294
}`,
263295
configFileName: "/apath/tsconfig.json",
264-
basePath: "tests/cases/unittests",
296+
basePath: "/apath",
265297
allFileList: ["/apath/a.ts"],
266298
}]);
267299

268300
baselinedParsed("generates errors for directory with no .ts files", () => [{
269301
jsonText: `{
270302
}`,
271303
configFileName: "/apath/tsconfig.json",
272-
basePath: "tests/cases/unittests",
304+
basePath: "/apath",
273305
allFileList: ["/apath/a.js"],
274306
}]);
275307

@@ -280,7 +312,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
280312
}
281313
}`,
282314
configFileName: "/apath/tsconfig.json",
283-
basePath: "tests/cases/unittests",
315+
basePath: "/apath",
284316
allFileList: [],
285317
}]);
286318

@@ -301,7 +333,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
301333
"include": ["**/*"]
302334
}`,
303335
configFileName: "/apath/tsconfig.json",
304-
basePath: "tests/cases/unittests",
336+
basePath: "/apath",
305337
allFileList: ["/apath/a.ts"],
306338
}]);
307339

@@ -314,7 +346,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
314346
}
315347
}`,
316348
configFileName: "/apath/tsconfig.json",
317-
basePath: "tests/cases/unittests",
349+
basePath: "/apath",
318350
allFileList: ["/apath/a.ts"],
319351
}], /*skipJson*/ true);
320352

@@ -328,7 +360,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
328360
}],
329361
}),
330362
configFileName: "/apath/tsconfig.json",
331-
basePath: "tests/cases/unittests",
363+
basePath: "/apath",
332364
allFileList: ["/apath/a.ts"],
333365
}]);
334366

@@ -339,7 +371,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
339371
],
340372
}),
341373
configFileName: "/apath/tsconfig.json",
342-
basePath: "tests/cases/unittests",
374+
basePath: "/apath",
343375
allFileList: ["/apath/a.ts"],
344376
}]);
345377

@@ -350,7 +382,7 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
350382
},
351383
}),
352384
configFileName: "/apath/tsconfig.json",
353-
basePath: "tests/cases/unittests",
385+
basePath: "/apath",
354386
allFileList: ["/apath/a.ts"],
355387
}]);
356388

@@ -392,6 +424,6 @@ describe("unittests:: config:: tsconfigParsing:: parseConfigFileTextToJson", ()
392424
jsonText: jsonToReadableText({
393425
include: ["./", "./**/*.json"],
394426
}),
395-
basePath: "/foo",
427+
basePath: "/foo.bar",
396428
}]);
397429
});

tests/baselines/reference/config/showConfig/Show TSConfig with paths and more/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
"./src/**/*"
3333
],
3434
"exclude": [
35-
"./lib"
35+
"/Show TSConfig with paths and more/lib"
3636
]
3737
}

tests/baselines/reference/config/tsconfigParsing/generates errors for empty files list when no references are provided with jsonSourceFile api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ configFileName:: /apath/tsconfig.json
1313
FileNames::
1414

1515
Errors::
16-
[96m/apath/tsconfig.json[0m:[93m2[0m:[93m26[0m - [91merror[0m[90m TS18002: [0mThe 'files' list in config file '/apath/tsconfig.json' is empty.
16+
[96mtsconfig.json[0m:[93m2[0m:[93m26[0m - [91merror[0m[90m TS18002: [0mThe 'files' list in config file '/apath/tsconfig.json' is empty.
1717

1818
2 "files": [],
1919
   ~~

tests/baselines/reference/config/tsconfigParsing/generates errors for empty files list with jsonSourceFile api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ configFileName:: /apath/tsconfig.json
1212
FileNames::
1313

1414
Errors::
15-
[96m/apath/tsconfig.json[0m:[93m2[0m:[93m26[0m - [91merror[0m[90m TS18002: [0mThe 'files' list in config file '/apath/tsconfig.json' is empty.
15+
[96mtsconfig.json[0m:[93m2[0m:[93m26[0m - [91merror[0m[90m TS18002: [0mThe 'files' list in config file '/apath/tsconfig.json' is empty.
1616

1717
2 "files": []
1818
   ~~

tests/baselines/reference/config/tsconfigParsing/generates errors for includes with outDir with json api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ configFileName:: /apath/tsconfig.json
1515
FileNames::
1616

1717
Errors::
18-
[91merror[0m[90m TS18003: [0mNo inputs were found in config file '/apath/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["./"]'.
18+
[91merror[0m[90m TS18003: [0mNo inputs were found in config file '/apath/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["/apath"]'.
1919

tests/baselines/reference/config/tsconfigParsing/generates errors for includes with outDir with jsonSourceFile api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ configFileName:: /apath/tsconfig.json
1515
FileNames::
1616

1717
Errors::
18-
[91merror[0m[90m TS18003: [0mNo inputs were found in config file '/apath/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["./"]'.
18+
[91merror[0m[90m TS18003: [0mNo inputs were found in config file '/apath/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["/apath"]'.
1919

tests/baselines/reference/config/tsconfigParsing/generates errors for when invalid comment type present in tsconfig with jsonSourceFile api.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@ configFileName:: /apath/tsconfig.json
1616
FileNames::
1717
/apath/a.ts
1818
Errors::
19-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m17[0m - [91merror[0m[90m TS1327: [0mString literal with double quotes expected.
19+
[96mtsconfig.json[0m:[93m3[0m:[93m17[0m - [91merror[0m[90m TS1327: [0mString literal with double quotes expected.
2020

2121
3 ## this comment does cause issues
2222
   ~
23-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m18[0m - [91merror[0m[90m TS1328: [0mProperty value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.
23+
[96mtsconfig.json[0m:[93m3[0m:[93m18[0m - [91merror[0m[90m TS1328: [0mProperty value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.
2424

2525
3 ## this comment does cause issues
2626
   ~
27-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m17[0m - [91merror[0m[90m TS5023: [0mUnknown compiler option '#'.
27+
[96mtsconfig.json[0m:[93m3[0m:[93m17[0m - [91merror[0m[90m TS5023: [0mUnknown compiler option '#'.
2828

2929
3 ## this comment does cause issues
3030
   ~
31-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m20[0m - [91merror[0m[90m TS1327: [0mString literal with double quotes expected.
31+
[96mtsconfig.json[0m:[93m3[0m:[93m20[0m - [91merror[0m[90m TS1327: [0mString literal with double quotes expected.
3232

3333
3 ## this comment does cause issues
3434
   ~~~~
35-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m25[0m - [91merror[0m[90m TS1328: [0mProperty value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.
35+
[96mtsconfig.json[0m:[93m3[0m:[93m25[0m - [91merror[0m[90m TS1328: [0mProperty value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.
3636

3737
3 ## this comment does cause issues
3838
   ~~~~~~~
39-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m20[0m - [91merror[0m[90m TS5023: [0mUnknown compiler option 'this'.
39+
[96mtsconfig.json[0m:[93m3[0m:[93m20[0m - [91merror[0m[90m TS5023: [0mUnknown compiler option 'this'.
4040

4141
3 ## this comment does cause issues
4242
   ~~~~
43-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m33[0m - [91merror[0m[90m TS1136: [0mProperty assignment expected.
43+
[96mtsconfig.json[0m:[93m3[0m:[93m33[0m - [91merror[0m[90m TS1136: [0mProperty assignment expected.
4444

4545
3 ## this comment does cause issues
4646
   ~~~~
47-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m38[0m - [91merror[0m[90m TS1136: [0mProperty assignment expected.
47+
[96mtsconfig.json[0m:[93m3[0m:[93m38[0m - [91merror[0m[90m TS1136: [0mProperty assignment expected.
4848

4949
3 ## this comment does cause issues
5050
   ~~~~~
51-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m44[0m - [91merror[0m[90m TS1136: [0mProperty assignment expected.
51+
[96mtsconfig.json[0m:[93m3[0m:[93m44[0m - [91merror[0m[90m TS1136: [0mProperty assignment expected.
5252

5353
3 ## this comment does cause issues
5454
   ~~~~~~

tests/baselines/reference/config/tsconfigParsing/generates errors when commandline option is in tsconfig with jsonSourceFile api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ configFileName:: /apath/tsconfig.json
1414
FileNames::
1515
/apath/a.ts
1616
Errors::
17-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS6266: [0mOption 'help' can only be specified on command line.
17+
[96mtsconfig.json[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS6266: [0mOption 'help' can only be specified on command line.
1818

1919
3 "help": true
2020
   ~~~~~~

tests/baselines/reference/config/tsconfigParsing/generates errors when files is not string with jsonSourceFile api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ configFileName:: /apath/tsconfig.json
1919
FileNames::
2020

2121
Errors::
22-
[96m/apath/tsconfig.json[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS5024: [0mCompiler option 'files' requires a value of type string.
22+
[96mtsconfig.json[0m:[93m3[0m:[93m5[0m - [91merror[0m[90m TS5024: [0mCompiler option 'files' requires a value of type string.
2323

2424
 3 {
2525
   ~

0 commit comments

Comments
 (0)