Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,45 @@ func (p *Program) verifyCompilerOptions() {
}
}

if !options.NoEmit.IsTrue() &&
!options.Composite.IsTrue() &&
options.RootDir == "" &&
options.ConfigFilePath != "" &&
(options.OutDir != "" ||
(options.GetEmitDeclarations() && options.DeclarationDir != "") ||
options.OutFile != "") {
// Check if rootDir inferred changed and issue diagnostic
dir := p.CommonSourceDirectory()
var emittedFiles []string
for _, file := range p.files {
if !file.IsDeclarationFile && sourceFileMayBeEmitted(file, p, false) {
emittedFiles = append(emittedFiles, file.FileName())
}
}
dir59 := outputpaths.GetComputedCommonSourceDirectory(emittedFiles, p.GetCurrentDirectory(), p.UseCaseSensitiveFileNames())
if dir59 != "" && tspath.GetCanonicalFileName(dir, p.UseCaseSensitiveFileNames()) != tspath.GetCanonicalFileName(dir59, p.UseCaseSensitiveFileNames()) {
option1 := "outDir"
if options.OutFile != "" {
option1 = "outFile"
} else if options.OutDir == "" {
option1 = "declarationDir"
}
option2 := ""
if options.OutFile == "" && options.OutDir != "" {
option2 = "declarationDir"
}
diag := createDiagnosticForOption(
true, /*onKey*/
option1,
option2,
diagnostics.The_common_source_directory_of_0_is_1_The_rootDir_setting_must_be_explicitly_set_to_this_or_another_path_to_adjust_your_output_s_file_layout,
tspath.GetBaseFileName(options.ConfigFilePath),
tspath.GetRelativePathFromFile(options.ConfigFilePath, dir59, tspath.ComparePathsOptions{UseCaseSensitiveFileNames: p.UseCaseSensitiveFileNames()}),
)
diag.AddMessageChain(ast.NewCompilerDiagnostic(diagnostics.Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information))
}
}

if options.CheckJs.IsTrue() && !options.GetAllowJS() {
createDiagnosticForOptionName(diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs")
}
Expand Down
46 changes: 46 additions & 0 deletions internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,52 @@ func TestTscExtends(t *testing.T) {
}
}

func TestTscOutDirWithParentDirInclude(t *testing.T) {
t.Parallel()
testCases := []*tscInput{
{
subScenario: "outDir when include references parent directories",
files: FileMap{
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
{
"compilerOptions": {
"target": "ES2024",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "${configDir}/dist/",
"strict": true,
"skipLibCheck": true
},
"include": ["common/src/**/*"]
}`),
"/home/src/workspaces/project/common/src/greeter.ts": stringtestutil.Dedent(`
export function greet(name: string): string {
return "Hello, " + name + "!";
}
`),
"/home/src/workspaces/project/sub/tsconfig.json": stringtestutil.Dedent(`
{
"extends": "../tsconfig.json",
"include": [
"src/**/*",
"../common/src/**/*"
]
}`),
"/home/src/workspaces/project/sub/src/index.ts": stringtestutil.Dedent(`
import { greet } from "../../common/src/greeter.js";
console.log(greet("world"));
`),
},
cwd: "/home/src/workspaces/project",
commandLineArgs: []string{"-p", "sub/tsconfig.json", "--explainFiles"},
},
}

for _, test := range testCases {
test.run(t, "outDir")
}
}

func TestForceConsistentCasingInFileNames(t *testing.T) {
t.Parallel()
testCases := []*tscInput{
Expand Down
8 changes: 8 additions & 0 deletions internal/outputpaths/commonsourcedirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func computeCommonSourceDirectoryOfFilenames(fileNames []string, currentDirector
return tspath.GetPathFromPathComponents(commonPathComponents)
}

func GetComputedCommonSourceDirectory(fileNames []string, currentDirectory string, useCaseSensitiveFileNames bool) string {
commonSourceDirectory := computeCommonSourceDirectoryOfFilenames(fileNames, currentDirectory, useCaseSensitiveFileNames)
if len(commonSourceDirectory) > 0 {
commonSourceDirectory = tspath.EnsureTrailingDirectorySeparator(commonSourceDirectory)
}
return commonSourceDirectory
}

func GetCommonSourceDirectory(options *core.CompilerOptions, files func() []string, currentDirectory string, useCaseSensitiveFileNames bool) string {
var commonSourceDirectory string
if options.RootDir != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,35 @@ x + y;
//// [/app/bin/index.d.ts]
/// <reference path="../../types/bar.d.ts" preserve="true" />
export {};


//// [DtsFileErrors]


error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.


!!! error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
==== /app/tsconfig.json (0 errors) ====
{
"compilerOptions": {
"outDir": "bin",
"typeRoots": ["../types"],
"sourceMap": true,
"mapRoot": "myMapRoot",
"sourceRoot": "mySourceRoot",
"declaration": true
}
}

==== /app/bin/index.d.ts (0 errors) ====
/// <reference path="../../types/bar.d.ts" preserve="true" />
export {};

==== /types/bar.d.ts (0 errors) ====
declare module "bar" {
export const y = 0;
}

Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
--- old.commonSourceDirectory.js
+++ new.commonSourceDirectory.js
@@= skipped -24, +24 lines =@@
//// [/app/bin/index.d.ts]
/// <reference path="../../types/bar.d.ts" preserve="true" />
export {};
-
-
-//// [DtsFileErrors]
-
-
@@= skipped -29, +29 lines =@@
//// [DtsFileErrors]


-/app/tsconfig.json(3,9): error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
- Visit https://aka.ms/ts6 for migration information.
-
-
+error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.


-==== /app/tsconfig.json (1 errors) ====
- {
- "compilerOptions": {
- "outDir": "bin",
+!!! error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
+!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
+==== /app/tsconfig.json (0 errors) ====
{
"compilerOptions": {
"outDir": "bin",
- ~~~~~~~~
-!!! error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
-!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
- "typeRoots": ["../types"],
- "sourceMap": true,
- "mapRoot": "myMapRoot",
- "sourceRoot": "mySourceRoot",
- "declaration": true
- }
- }
-
-==== /app/bin/index.d.ts (0 errors) ====
- /// <reference path="../../types/bar.d.ts" preserve="true" />
- export {};
-
-==== /types/bar.d.ts (0 errors) ====
- declare module "bar" {
- export const y = 0;
- }
-
"typeRoots": ["../types"],
"sourceMap": true,
"mapRoot": "myMapRoot",
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/app/tsconfig.json(3,9): error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.


==== /app/tsconfig.json (1 errors) ====
{
"compilerOptions": {
"outDir": "bin",
~~~~~~~~
!!! error TS5011: The common source directory of 'tsconfig.json' is './src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
"sourceMap": true,
"mapRoot": "myMapRoot",
"sourceRoot": "mySourceRoot",
"declaration": true
}
}

==== /app/lib/bar.d.ts (0 errors) ====
declare const y: number;

==== /app/src/index.ts (0 errors) ====
/// <reference path="../lib/bar.d.ts" preserve="true" />
export const x = y;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ interface Foo {
x: number;
}
export default Foo;


//// [DtsFileErrors]


error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.


!!! error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
==== /foo/tsconfig.json (0 errors) ====
{
"compilerOptions": { "declaration": true, "declarationDir": "out", "module": "commonjs", "target": "es2015" }
}

Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
--- old.declarationEmitToDeclarationDirWithDeclarationOption.js
+++ new.declarationEmitToDeclarationDirWithDeclarationOption.js
@@= skipped -16, +16 lines =@@
x: number;
}
export default Foo;
-
-
-//// [DtsFileErrors]
-
-
@@= skipped -21, +21 lines =@@
//// [DtsFileErrors]


-/foo/tsconfig.json(2,47): error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
- Visit https://aka.ms/ts6 for migration information.
-
-
+error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
Visit https://aka.ms/ts6 for migration information.


-==== /foo/tsconfig.json (1 errors) ====
- {
- "compilerOptions": { "declaration": true, "declarationDir": "out", "module": "commonjs", "target": "es2015" }
- ~~~~~~~~~~~~~~~~
-!!! error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
-!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
- }
-
!!! error TS5011: The common source directory of 'tsconfig.json' is '../.src'. The 'rootDir' setting must be explicitly set to this or another path to adjust your output's file layout.
!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
+==== /foo/tsconfig.json (0 errors) ====
+ {
+ "compilerOptions": { "declaration": true, "declarationDir": "out", "module": "commonjs", "target": "es2015" }
}

Loading