Skip to content

Commit 6ee5490

Browse files
authored
Identify when file name is matched by default include spec (microsoft#49040)
Fixes microsoft#43679
1 parent fcd80db commit 6ee5490

File tree

95 files changed

+283
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+283
-266
lines changed

src/compiler/commandLineParser.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ namespace ts {
23262326
function filterSameAsDefaultInclude(specs: readonly string[] | undefined) {
23272327
if (!length(specs)) return undefined;
23282328
if (length(specs) !== 1) return specs;
2329-
if (specs![0] === "**/*") return undefined;
2329+
if (specs![0] === defaultIncludeSpec) return undefined;
23302330
return specs;
23312331
}
23322332

@@ -2627,6 +2627,9 @@ namespace ts {
26272627
return getDirectoryPath(getNormalizedAbsolutePath(fileName, basePath));
26282628
}
26292629

2630+
/*@internal*/
2631+
export const defaultIncludeSpec = "**/*";
2632+
26302633
/**
26312634
* Parse the contents of a config file from json or json source file (tsconfig.json).
26322635
* @param json The contents of the config file to parse
@@ -2705,6 +2708,7 @@ namespace ts {
27052708
let includeSpecs = toPropValue(getSpecsFromRaw("include"));
27062709

27072710
const excludeOfRaw = getSpecsFromRaw("exclude");
2711+
let isDefaultIncludeSpec = false;
27082712
let excludeSpecs = toPropValue(excludeOfRaw);
27092713
if (excludeOfRaw === "no-prop" && raw.compilerOptions) {
27102714
const outDir = raw.compilerOptions.outDir;
@@ -2716,7 +2720,8 @@ namespace ts {
27162720
}
27172721

27182722
if (filesSpecs === undefined && includeSpecs === undefined) {
2719-
includeSpecs = ["**/*"];
2723+
includeSpecs = [defaultIncludeSpec];
2724+
isDefaultIncludeSpec = true;
27202725
}
27212726
let validatedIncludeSpecs: readonly string[] | undefined, validatedExcludeSpecs: readonly string[] | undefined;
27222727

@@ -2740,6 +2745,7 @@ namespace ts {
27402745
validatedIncludeSpecs,
27412746
validatedExcludeSpecs,
27422747
pathPatterns: undefined, // Initialized on first use
2748+
isDefaultIncludeSpec,
27432749
};
27442750
}
27452751

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,10 @@
14441444
"category": "Error",
14451445
"code": 1456
14461446
},
1447+
"Matched by default include pattern '**/*'": {
1448+
"category": "Message",
1449+
"code": 1457
1450+
},
14471451

14481452
"The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.": {
14491453
"category": "Error",

src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3764,7 +3764,7 @@ namespace ts {
37643764
}
37653765
const matchedByInclude = getMatchedIncludeSpec(program, fileName);
37663766
// Could be additional files specified as roots
3767-
if (!matchedByInclude) return undefined;
3767+
if (!matchedByInclude || !isString(matchedByInclude)) return undefined;
37683768
configFileNode = getTsConfigPropArrayElementValue(options.configFile, "include", matchedByInclude);
37693769
message = Diagnostics.File_is_matched_by_include_pattern_specified_here;
37703770
break;

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6385,6 +6385,7 @@ namespace ts {
63856385
validatedIncludeSpecs: readonly string[] | undefined;
63866386
validatedExcludeSpecs: readonly string[] | undefined;
63876387
pathPatterns: readonly (string | Pattern)[] | undefined;
6388+
isDefaultIncludeSpec: boolean;
63886389
}
63896390

63906391
/* @internal */

src/compiler/watch.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ namespace ts {
261261
const configFile = program.getCompilerOptions().configFile;
262262
if (!configFile?.configFileSpecs?.validatedIncludeSpecs) return undefined;
263263

264+
// Return true if its default include spec
265+
if (configFile.configFileSpecs.isDefaultIncludeSpec) return true;
266+
264267
const isJsonFile = fileExtensionIs(fileName, Extension.Json);
265268
const basePath = getDirectoryPath(getNormalizedAbsolutePath(configFile.fileName, program.getCurrentDirectory()));
266269
const useCaseSensitiveFileNames = program.useCaseSensitiveFileNames();
@@ -327,15 +330,18 @@ namespace ts {
327330
const matchedByFiles = getMatchedFileSpec(program, fileName);
328331
if (matchedByFiles) return chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Part_of_files_list_in_tsconfig_json);
329332
const matchedByInclude = getMatchedIncludeSpec(program, fileName);
330-
return matchedByInclude ?
333+
return isString(matchedByInclude) ?
331334
chainDiagnosticMessages(
332335
/*details*/ undefined,
333336
Diagnostics.Matched_by_include_pattern_0_in_1,
334337
matchedByInclude,
335338
toFileName(options.configFile, fileNameConvertor)
336339
) :
337-
// Could be additional files specified as roots
338-
chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Root_file_specified_for_compilation);
340+
// Could be additional files specified as roots or matched by default include
341+
chainDiagnosticMessages(/*details*/ undefined, matchedByInclude ?
342+
Diagnostics.Matched_by_default_include_pattern_Asterisk_Asterisk_Slash_Asterisk :
343+
Diagnostics.Root_file_specified_for_compilation
344+
);
339345
case FileIncludeKind.SourceFromProjectReference:
340346
case FileIncludeKind.OutputFromProjectReference:
341347
const isOutput = reason.kind === FileIncludeKind.OutputFromProjectReference;

tests/baselines/reference/moduleResolutionWithExtensions_withPaths.errors.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error TS6504: File '/node_modules/foo/lib/test.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
22
The file is in the program because:
3-
Root file specified for compilation
3+
Matched by default include pattern '**/*'
44
error TS6504: File '/relative.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
55
The file is in the program because:
6-
Matched by include pattern '**/*' in '/tsconfig.json'
6+
Matched by default include pattern '**/*'
77

88

99
!!! error TS6504: File '/node_modules/foo/lib/test.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
1010
!!! error TS6504: The file is in the program because:
11-
!!! error TS6504: Root file specified for compilation
11+
!!! error TS6504: Matched by default include pattern '**/*'
1212
!!! error TS6504: File '/relative.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
1313
!!! error TS6504: The file is in the program because:
14-
!!! error TS6504: Matched by include pattern '**/*' in '/tsconfig.json'
14+
!!! error TS6504: Matched by default include pattern '**/*'
1515
==== /tsconfig.json (0 errors) ====
1616
{
1717
"compilerOptions": {

tests/baselines/reference/tsbuild/outfile-concat/explainFiles.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ src/first/first_part3.ts
155155
lib/lib.d.ts
156156
Default library for target 'es5'
157157
src/second/second_part1.ts
158-
Matched by include pattern '**/*' in 'src/second/tsconfig.json'
158+
Matched by default include pattern '**/*'
159159
src/second/second_part2.ts
160-
Matched by include pattern '**/*' in 'src/second/tsconfig.json'
160+
Matched by default include pattern '**/*'
161161
[12:00:27 AM] Project 'src/third/tsconfig.json' is out of date because output file 'src/third/thirdjs/output/third-output.js' does not exist
162162

163163
[12:00:28 AM] Building project '/src/third/tsconfig.json'...

tests/baselines/reference/tsbuild/outputPaths/when-rootDir-is-specified-but-not-all-files-belong-to-rootDir-and-is-composite.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Output::
3636

3737
error TS6059: File '/src/types/type.ts' is not under 'rootDir' '/src/src'. 'rootDir' is expected to contain all source files.
3838
The file is in the program because:
39-
Matched by include pattern '**/*' in '/src/tsconfig.json'
39+
Matched by default include pattern '**/*'
4040

4141

4242
Found 1 error.
@@ -61,7 +61,7 @@ Output::
6161

6262
error TS6059: File '/src/types/type.ts' is not under 'rootDir' '/src/src'. 'rootDir' is expected to contain all source files.
6363
The file is in the program because:
64-
Matched by include pattern '**/*' in '/src/tsconfig.json'
64+
Matched by default include pattern '**/*'
6565

6666

6767
Found 1 error.
@@ -79,7 +79,7 @@ Output::
7979
/lib/tsc -p /src/tsconfig.json
8080
error TS6059: File '/src/types/type.ts' is not under 'rootDir' '/src/src'. 'rootDir' is expected to contain all source files.
8181
The file is in the program because:
82-
Matched by include pattern '**/*' in '/src/tsconfig.json'
82+
Matched by default include pattern '**/*'
8383

8484

8585
Found 1 error.

tests/baselines/reference/tsbuild/outputPaths/when-rootDir-is-specified-but-not-all-files-belong-to-rootDir.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Output::
3636

3737
error TS6059: File '/src/types/type.ts' is not under 'rootDir' '/src/src'. 'rootDir' is expected to contain all source files.
3838
The file is in the program because:
39-
Matched by include pattern '**/*' in '/src/tsconfig.json'
39+
Matched by default include pattern '**/*'
4040

4141

4242
Found 1 error.
@@ -61,7 +61,7 @@ Output::
6161

6262
error TS6059: File '/src/types/type.ts' is not under 'rootDir' '/src/src'. 'rootDir' is expected to contain all source files.
6363
The file is in the program because:
64-
Matched by include pattern '**/*' in '/src/tsconfig.json'
64+
Matched by default include pattern '**/*'
6565

6666

6767
Found 1 error.
@@ -79,7 +79,7 @@ Output::
7979
/lib/tsc -p /src/tsconfig.json
8080
error TS6059: File '/src/types/type.ts' is not under 'rootDir' '/src/src'. 'rootDir' is expected to contain all source files.
8181
The file is in the program because:
82-
Matched by include pattern '**/*' in '/src/tsconfig.json'
82+
Matched by default include pattern '**/*'
8383

8484

8585
Found 1 error.

tests/baselines/reference/tsbuild/sample1/explainFiles.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ Output::
123123
lib/lib.d.ts
124124
Default library for target 'es3'
125125
src/core/anotherModule.ts
126-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
126+
Matched by default include pattern '**/*'
127127
src/core/index.ts
128-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
128+
Matched by default include pattern '**/*'
129129
src/core/some_decl.d.ts
130-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
130+
Matched by default include pattern '**/*'
131131
[12:00:17 AM] Project 'src/logic/tsconfig.json' is out of date because output file 'src/logic/index.js' does not exist
132132
133133
[12:00:18 AM] Building project '/src/logic/tsconfig.json'...
@@ -141,7 +141,7 @@ src/core/anotherModule.d.ts
141141
Imported via '../core/anotherModule' from file 'src/logic/index.ts'
142142
File is output of project reference source 'src/core/anotherModule.ts'
143143
src/logic/index.ts
144-
Matched by include pattern '**/*' in 'src/logic/tsconfig.json'
144+
Matched by default include pattern '**/*'
145145
[12:00:24 AM] Project 'src/tests/tsconfig.json' is out of date because output file 'src/tests/index.js' does not exist
146146

147147
[12:00:25 AM] Building project '/src/tests/tsconfig.json'...
@@ -465,11 +465,11 @@ Output::
465465
lib/lib.d.ts
466466
Default library for target 'es3'
467467
src/core/anotherModule.ts
468-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
468+
Matched by default include pattern '**/*'
469469
src/core/index.ts
470-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
470+
Matched by default include pattern '**/*'
471471
src/core/some_decl.d.ts
472-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
472+
Matched by default include pattern '**/*'
473473
[12:00:44 AM] Project 'src/logic/tsconfig.json' is out of date because oldest output 'src/logic/index.js.map' is older than newest input 'src/core'
474474
475475
[12:00:45 AM] Building project '/src/logic/tsconfig.json'...
@@ -483,7 +483,7 @@ src/core/anotherModule.d.ts
483483
Imported via '../core/anotherModule' from file 'src/logic/index.ts'
484484
File is output of project reference source 'src/core/anotherModule.ts'
485485
src/logic/index.ts
486-
Matched by include pattern '**/*' in 'src/logic/tsconfig.json'
486+
Matched by default include pattern '**/*'
487487
[12:00:51 AM] Project 'src/tests/tsconfig.json' is out of date because oldest output 'src/tests/index.js' is older than newest input 'src/core'
488488

489489
[12:00:52 AM] Building project '/src/tests/tsconfig.json'...
@@ -769,11 +769,11 @@ Output::
769769
lib/lib.d.ts
770770
Default library for target 'es3'
771771
src/core/anotherModule.ts
772-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
772+
Matched by default include pattern '**/*'
773773
src/core/index.ts
774-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
774+
Matched by default include pattern '**/*'
775775
src/core/some_decl.d.ts
776-
Matched by include pattern '**/*' in 'src/core/tsconfig.json'
776+
Matched by default include pattern '**/*'
777777
[12:01:11 AM] Project 'src/logic/tsconfig.json' is up to date with .d.ts files from its dependencies
778778
779779
[12:01:13 AM] Updating output timestamps of project '/src/logic/tsconfig.json'...

tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink-moduleCaseChange.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pkg2/dist/index.d.ts
7474
Imported via "@raymondfeng/pkg2" from file 'pkg3/src/keys.ts' with packageId '@raymondfeng/pkg2/dist/[email protected]'
7575
pkg3/src/keys.ts
7676
Imported via './keys' from file 'pkg3/src/index.ts'
77-
Matched by include pattern '**/*' in 'pkg3/tsconfig.json'
77+
Matched by default include pattern '**/*'
7878
pkg3/src/index.ts
79-
Matched by include pattern '**/*' in 'pkg3/tsconfig.json'
79+
Matched by default include pattern '**/*'
8080

8181
Found 1 error in pkg3/src/keys.ts:2
8282

tests/baselines/reference/tsc/declarationEmit/when-pkg-references-sibling-package-through-indirect-symlink.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pkg2/dist/index.d.ts
7474
Imported via "@raymondfeng/pkg2" from file 'pkg3/src/keys.ts' with packageId '@raymondfeng/pkg2/dist/[email protected]'
7575
pkg3/src/keys.ts
7676
Imported via './keys' from file 'pkg3/src/index.ts'
77-
Matched by include pattern '**/*' in 'pkg3/tsconfig.json'
77+
Matched by default include pattern '**/*'
7878
pkg3/src/index.ts
79-
Matched by include pattern '**/*' in 'pkg3/tsconfig.json'
79+
Matched by default include pattern '**/*'
8080

8181
Found 1 error in pkg3/src/keys.ts:2
8282

tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-moduleCaseChange.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ Resolving real path for '/user/username/projects/myProject/plugin-two/node_modul
136136
plugin-one/node_modules/typescript-fsa/index.d.ts
137137
Imported via "typescript-fsa" from file 'plugin-one/action.ts' with packageId 'typescript-fsa/index.d.ts@3.0.0-beta-2'
138138
plugin-one/action.ts
139-
Matched by include pattern '**/*' in 'plugin-one/tsconfig.json'
139+
Matched by default include pattern '**/*'
140140
plugin-two/node_modules/typescript-fsa/index.d.ts
141141
Imported via "typescript-fsa" from file 'plugin-two/index.d.ts' with packageId 'typescript-fsa/[email protected]'
142142
File redirects to file 'plugin-one/node_modules/typescript-fsa/index.d.ts'
143143
plugin-two/index.d.ts
144144
Imported via "plugin-two" from file 'plugin-one/index.ts'
145145
plugin-one/index.ts
146-
Matched by include pattern '**/*' in 'plugin-one/tsconfig.json'
146+
Matched by default include pattern '**/*'
147147

148148

149149
Program root files: ["/user/username/projects/myproject/plugin-one/action.ts","/user/username/projects/myproject/plugin-one/index.ts"]

tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link-moduleCaseChange.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ plugin-one/node_modules/typescript-fsa/index.d.ts
155155
Imported via "typescript-fsa" from file 'plugin-one/index.ts' with packageId 'typescript-fsa/index.d.ts@3.0.0-beta-2'
156156
File redirects to file 'plugin-two/node_modules/typescript-fsa/index.d.ts'
157157
plugin-one/index.ts
158-
Matched by include pattern '**/*' in 'plugin-one/tsconfig.json'
158+
Matched by default include pattern '**/*'
159159

160160

161161
Program root files: ["/user/username/projects/myproject/plugin-one/index.ts"]

tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package-with-indirect-link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ plugin-one/node_modules/typescript-fsa/index.d.ts
155155
Imported via "typescript-fsa" from file 'plugin-one/index.ts' with packageId 'typescript-fsa/index.d.ts@3.0.0-beta-2'
156156
File redirects to file 'plugin-two/node_modules/typescript-fsa/index.d.ts'
157157
plugin-one/index.ts
158-
Matched by include pattern '**/*' in 'plugin-one/tsconfig.json'
158+
Matched by default include pattern '**/*'
159159

160160

161161
Program root files: ["/user/username/projects/myproject/plugin-one/index.ts"]

tests/baselines/reference/tsc/declarationEmit/when-same-version-is-referenced-through-source-and-another-symlinked-package.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ Resolving real path for '/user/username/projects/myproject/plugin-two/node_modul
136136
plugin-one/node_modules/typescript-fsa/index.d.ts
137137
Imported via "typescript-fsa" from file 'plugin-one/action.ts' with packageId 'typescript-fsa/index.d.ts@3.0.0-beta-2'
138138
plugin-one/action.ts
139-
Matched by include pattern '**/*' in 'plugin-one/tsconfig.json'
139+
Matched by default include pattern '**/*'
140140
plugin-two/node_modules/typescript-fsa/index.d.ts
141141
Imported via "typescript-fsa" from file 'plugin-two/index.d.ts' with packageId 'typescript-fsa/[email protected]'
142142
File redirects to file 'plugin-one/node_modules/typescript-fsa/index.d.ts'
143143
plugin-two/index.d.ts
144144
Imported via "plugin-two" from file 'plugin-one/index.ts'
145145
plugin-one/index.ts
146-
Matched by include pattern '**/*' in 'plugin-one/tsconfig.json'
146+
Matched by default include pattern '**/*'
147147

148148

149149
Program root files: ["/user/username/projects/myproject/plugin-one/action.ts","/user/username/projects/myproject/plugin-one/index.ts"]

tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/when-Windows-style-drive-root-is-lowercase.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ Output::
3838
a/lib/lib.d.ts
3939
Default library for target 'es3'
4040
project/a.ts
41-
Matched by include pattern '**/*' in 'project/tsconfig.json'
41+
Matched by default include pattern '**/*'
4242
Imported via "C://project/a" from file 'project/b.ts'
4343
Imported via "c://project/a" from file 'project/b.ts'
4444
project/b.ts
45-
Matched by include pattern '**/*' in 'project/tsconfig.json'
45+
Matched by default include pattern '**/*'
4646
[12:00:22 AM] Found 0 errors. Watching for file changes.
4747

4848

@@ -121,11 +121,11 @@ Output::
121121
a/lib/lib.d.ts
122122
Default library for target 'es3'
123123
project/a.ts
124-
Matched by include pattern '**/*' in 'project/tsconfig.json'
124+
Matched by default include pattern '**/*'
125125
Imported via "C://project/a" from file 'project/b.ts'
126126
Imported via "c://project/a" from file 'project/b.ts'
127127
project/b.ts
128-
Matched by include pattern '**/*' in 'project/tsconfig.json'
128+
Matched by default include pattern '**/*'
129129
[12:00:32 AM] Found 0 errors. Watching for file changes.
130130

131131

tests/baselines/reference/tscWatch/forceConsistentCasingInFileNames/when-Windows-style-drive-root-is-uppercase.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ Output::
3838
a/lib/lib.d.ts
3939
Default library for target 'es3'
4040
project/a.ts
41-
Matched by include pattern '**/*' in 'project/tsconfig.json'
41+
Matched by default include pattern '**/*'
4242
Imported via "C://project/a" from file 'project/b.ts'
4343
Imported via "c://project/a" from file 'project/b.ts'
4444
project/b.ts
45-
Matched by include pattern '**/*' in 'project/tsconfig.json'
45+
Matched by default include pattern '**/*'
4646
[12:00:22 AM] Found 0 errors. Watching for file changes.
4747

4848

@@ -121,11 +121,11 @@ Output::
121121
a/lib/lib.d.ts
122122
Default library for target 'es3'
123123
project/a.ts
124-
Matched by include pattern '**/*' in 'project/tsconfig.json'
124+
Matched by default include pattern '**/*'
125125
Imported via "C://project/a" from file 'project/b.ts'
126126
Imported via "c://project/a" from file 'project/b.ts'
127127
project/b.ts
128-
Matched by include pattern '**/*' in 'project/tsconfig.json'
128+
Matched by default include pattern '**/*'
129129
[12:00:32 AM] Found 0 errors. Watching for file changes.
130130

131131

0 commit comments

Comments
 (0)