check that files specified in tsconfig.json "include" is located in "rootdir"#3783
Open
iisaduan wants to merge 1 commit intomicrosoft:mainfrom
Open
check that files specified in tsconfig.json "include" is located in "rootdir"#3783iisaduan wants to merge 1 commit intomicrosoft:mainfrom
iisaduan wants to merge 1 commit intomicrosoft:mainfrom
Conversation
iisaduan
commented
May 8, 2026
| if checkSourceFilesBelongToPath != nil { | ||
| checkSourceFilesBelongToPath(files, options.RootDir) | ||
| } | ||
| } else if options.ConfigFilePath != "" { |
Member
Author
There was a problem hiding this comment.
In strada, this is else if (options.composite && options.configFilePath), but making that change here broke quite a few things. I'm not sure the reasoning for the change, so I left it
Member
There was a problem hiding this comment.
What did it break? I think I remember sheetal doing that on purpose
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a behavior gap vs upstream TypeScript by reporting TS6059 when a file is included in the program but lies outside the effective rootDir/common source directory, ensuring tsgo aligns with tsc for include/default-include scenarios.
Changes:
- Add a source-file containment check during common source directory computation to emit TS6059 diagnostics for out-of-root files.
- Plumb the containment check through
outputpaths.GetCommonSourceDirectoryand invoke it from both parsed config handling andProgram. - Add/refresh compiler + build baselines to reflect the newly reported diagnostics and build-info “errors” state.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/tests/cases/compiler/tsconfigRootdirInclude.ts | New regression test intended to cover include selecting a file outside rootDir. |
| testdata/baselines/reference/compiler/tsconfigRootdirInclude.errors.txt | Expected diagnostics output for the new regression test. |
| testdata/baselines/reference/compiler/tsconfigRootdirInclude.js | Expected JS emit baseline for the new regression test. |
| testdata/baselines/reference/compiler/tsconfigRootdirInclude.symbols | Expected symbols baseline for the new regression test. |
| testdata/baselines/reference/compiler/tsconfigRootdirInclude.types | Expected types baseline for the new regression test. |
| testdata/baselines/reference/tsc/projectReferences/errors-when-a-file-is-outside-the-rootdir.js | Updates reference output to include TS6059 in addition to existing errors. |
| testdata/baselines/reference/tsbuild/outputPaths/when-rootDir-is-specified-but-not-all-files-belong-to-rootDir.js | Updates build baselines to reflect TS6059 and buildinfo “errors” propagation. |
| testdata/baselines/reference/tsbuild/outputPaths/when-rootDir-is-specified-but-not-all-files-belong-to-rootDir-and-is-composite.js | Same as above, for composite builds. |
| internal/tsoptions/parsedcommandline.go | Computes file list and adds a root/common-dir containment check during common source dir computation. |
| internal/outputpaths/commonsourcedirectory.go | Extends GetCommonSourceDirectory to accept files and an optional containment-check callback. |
| internal/compiler/program.go | Adds program-level containment check that reports via include-processing diagnostics for richer “why included” chains. |
| internal/compiler/emitter.go | Updates call site for the new GetCommonSourceDirectory signature. |
Comment on lines
+3
to
+10
| "compilerOptions": { | ||
| "target": "es2020", | ||
| "strictNullChecks": true, | ||
| "stableTypeOrdering": true, | ||
| "rootDir": "./src2", | ||
| "include": ["src1/*"] | ||
| } | ||
| } |
Comment on lines
+139
to
+146
| func (p *ParsedCommandLine) checkSourceFilesBelongToPath(sourceFiles []string, rootDirectory string) bool { | ||
| allFilesBelongToPath := true | ||
| absoluteRootDirectoryPath := tspath.GetCanonicalFileName(tspath.GetNormalizedAbsolutePath(rootDirectory, p.GetCurrentDirectory()), p.UseCaseSensitiveFileNames()) | ||
| for _, file := range sourceFiles { | ||
| absoluteSourceFilePath := tspath.GetCanonicalFileName(tspath.GetNormalizedAbsolutePath(file, p.GetCurrentDirectory()), p.UseCaseSensitiveFileNames()) | ||
| if !strings.HasPrefix(absoluteSourceFilePath, absoluteRootDirectoryPath) { | ||
| p.Errors = append(p.Errors, ast.NewCompilerDiagnostic(diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, file, rootDirectory)) | ||
| allFilesBelongToPath = false |
Comment on lines
+1551
to
+1557
| func (p *Program) checkSourceFilesBelongToPath(sourceFiles []string, rootDirectory string) bool { | ||
| allFilesBelongToPath := true | ||
| absoluteRootDirectoryPath := tspath.GetCanonicalFileName(tspath.GetNormalizedAbsolutePath(rootDirectory, p.GetCurrentDirectory()), p.UseCaseSensitiveFileNames()) | ||
| for _, file := range sourceFiles { | ||
| absoluteSourceFilePath := tspath.GetCanonicalFileName(tspath.GetNormalizedAbsolutePath(file, p.GetCurrentDirectory()), p.UseCaseSensitiveFileNames()) | ||
| if !strings.HasPrefix(absoluteSourceFilePath, absoluteRootDirectoryPath) { | ||
| p.includeProcessor.addProcessingDiagnostic(&processingDiagnostic{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #3662