Skip to content
Merged
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
42 changes: 42 additions & 0 deletions internal/compiler/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,48 @@ 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()) {
// change in layout
var option1 string
if options.OutFile != "" {
option1 = "outFile"
} else if options.OutDir != "" {
option1 = "outDir"
} else {
option1 = "declarationDir"
}
var option2 string
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, p.comparePathsOptions),
)
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
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(emittedFiles []string, currentDirectory string, useCaseSensitiveFileNames bool) string {
commonSourceDirectory := computeCommonSourceDirectoryOfFilenames(emittedFiles, 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" }
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const x = 10;
}

tsgo -b -v
ExitStatus:: Success
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
[HH:MM:SS AM] Projects in this build:
* tsconfig.json
Expand All @@ -20,6 +20,15 @@ Output::

[HH:MM:SS AM] Building project 'tsconfig.json'...

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.

3 "outDir": "dist",
   ~~~~~~~~


Found 1 error in tsconfig.json:3

//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
interface Boolean {}
Expand Down Expand Up @@ -47,10 +56,11 @@ declare const console: { log(msg: any): void; };
export const x = 10;

//// [/home/src/workspaces/project/dist/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":["../src/index.ts"]}
{"version":"FakeTSVersion","errors":true,"root":["../src/index.ts"]}
//// [/home/src/workspaces/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"errors": true,
"root": [
{
"files": [
Expand All @@ -59,33 +69,61 @@ export const x = 10;
"original": "../src/index.ts"
}
],
"size": 54
"size": 68
}

tsconfig.json::
SemanticDiagnostics::
*refresh* /home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
*refresh* /home/src/workspaces/project/src/index.ts
*not cached* /home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
*not cached* /home/src/workspaces/project/src/index.ts
Signatures::


Edit [0]:: no change

tsgo -b -v
ExitStatus:: Success
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
[HH:MM:SS AM] Projects in this build:
* tsconfig.json

[HH:MM:SS AM] Project 'tsconfig.json' is up to date because newest input 'src/index.ts' is older than output 'dist/src/index.js'
[HH:MM:SS AM] Project 'tsconfig.json' is out of date because buildinfo file 'dist/tsconfig.tsbuildinfo' indicates that program needs to report errors.

[HH:MM:SS AM] Building project 'tsconfig.json'...

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.

3 "outDir": "dist",
   ~~~~~~~~


Found 1 error in tsconfig.json:3

//// [/home/src/workspaces/project/dist/src/index.js] *rewrite with same content*
//// [/home/src/workspaces/project/dist/tsconfig.tsbuildinfo] *rewrite with same content*
//// [/home/src/workspaces/project/dist/tsconfig.tsbuildinfo.readable.baseline.txt] *rewrite with same content*

tsconfig.json::
SemanticDiagnostics::
*not cached* /home/src/tslibs/TS/Lib/lib.es2025.full.d.ts
*not cached* /home/src/workspaces/project/src/index.ts
Signatures::


Edit [1]:: Normal build without change, that does not block emit on error to show files that get emitted

tsgo -p /home/src/workspaces/project/tsconfig.json
ExitStatus:: Success
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
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.

3 "outDir": "dist",
   ~~~~~~~~


Found 1 error in tsconfig.json:3

//// [/home/src/workspaces/project/dist/src/index.js] *rewrite with same content*

Loading