Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ export function getCommonSourceDirectory(
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory);
checkSourceFilesBelongToPath?.(options.rootDir);
}
else if (options.composite && options.configFilePath) {
else if (options.configFilePath) {
// Project compilations never infer their root from the input source paths
commonSourceDirectory = getDirectoryPath(normalizeSlashes(options.configFilePath));
checkSourceFilesBelongToPath?.(commonSourceDirectory);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ function getLoadModuleFromTargetExportOrImport(extensions: Extensions, state: Mo
const commonSourceDirGuesses: string[] = [];
// A `rootDir` compiler option strongly indicates the root location
// A `composite` project is using project references and has it's common src dir set to `.`, so it shouldn't need to check any other locations
if (state.compilerOptions.rootDir || (state.compilerOptions.composite && state.compilerOptions.configFilePath)) {
if (state.compilerOptions.rootDir || state.compilerOptions.configFilePath) {
const commonDir = toAbsolutePath(getCommonSourceDirectory(state.compilerOptions, () => [], state.host.getCurrentDirectory?.() || "", getCanonicalFileName));
commonSourceDirGuesses.push(commonDir);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6622,7 +6622,7 @@ export function sourceFileMayBeEmitted(sourceFile: SourceFile, host: SourceFileM
// Json file is not emitted if outDir is not specified
if (!options.outDir) return false;
// Otherwise if rootDir or composite config file, we know common sourceDir and can check if file would be emitted in same location
if (options.rootDir || (options.composite && options.configFilePath)) {
if (options.rootDir || options.configFilePath) {
const commonDir = getNormalizedAbsolutePath(getCommonSourceDirectory(options, () => [], host.getCurrentDirectory(), host.getCanonicalFileName), host.getCurrentDirectory());
const outputPath = getSourceFilePathInNewDirWorker(sourceFile.fileName, options.outDir, host.getCurrentDirectory(), commonDir, host.getCanonicalFileName);
if (comparePaths(sourceFile.fileName, outputPath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === Comparison.EqualTo) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function getMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(
compilerOptions: {
outDir: "lib",
declaration: true,
rootDir: "src",
},
include: ["src/**/*.ts"],
}),
Expand All @@ -169,6 +170,7 @@ function getMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(
compilerOptions: {
outDir: "lib",
declaration: true,
rootDir: "src",
},
include: ["src/**/*.ts"],
}),
Expand All @@ -183,6 +185,7 @@ function getMonorepoSymlinkedSiblingPackagesSysWithUnRelatedFolders(
"/home/src/projects/b/2/b-impl/b/tsconfig.json": jsonToReadableText({
compilerOptions: {
outDir: "lib",
rootDir: "src",
},
include: ["src/**/*.ts"],
}),
Expand Down
4 changes: 2 additions & 2 deletions src/testRunner/unittests/tsbuild/outputPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("unittests:: tsbuild:: outputPaths::", () => {
...input,
});

it("verify getOutputFileNames", () => {
it("verify getOutputFileNames " + input.subScenario, () => {
const sys = input.sys();
assert.deepEqual(
ts.getOutputFileNames(
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("unittests:: tsbuild:: outputPaths::", () => {
}),
}),
edits,
}, ["/home/src/workspaces/project/dist/index.js"]);
}, ["/home/src/workspaces/project/dist/src/index.js"]);

verify({
subScenario: "when rootDir is not specified and is composite",
Expand Down
8 changes: 4 additions & 4 deletions tests/baselines/reference/commonSourceDirectory_dts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ declare const y: number;
export const x = y;


//// [/app/bin/index.js]
//// [/app/bin/src/index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
/// <reference path="../lib/bar.d.ts" preserve="true" />
exports.x = y;
//# sourceMappingURL=../src/myMapRoot/index.js.map
//# sourceMappingURL=../../myMapRoot/src/index.js.map

//// [/app/bin/index.d.ts]
/// <reference path="../lib/bar.d.ts" preserve="true" />
//// [/app/bin/src/index.d.ts]
/// <reference path="../../lib/bar.d.ts" preserve="true" />
export declare const x: number;
6 changes: 3 additions & 3 deletions tests/baselines/reference/commonSourceDirectory_dts.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
===================================================================
JsFile: index.js
mapUrl: ../src/myMapRoot/index.js.map
mapUrl: ../../myMapRoot/src/index.js.map
sourceRoot: mySourceRoot/
sources: index.ts
sources: src/index.ts
===================================================================
-------------------------------------------------------------------
emittedFile:/app/bin/index.js
sourceFile:index.ts
emittedFile:/app/bin/src/index.js
sourceFile:src/index.ts
-------------------------------------------------------------------
>>>"use strict";
>>>Object.defineProperty(exports, "__esModule", { value: true });
Expand All @@ -26,7 +26,7 @@ sourceFile:index.ts
4 > ^^^
5 > ^
6 > ^
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
7 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1 >
>export const
2 >
Expand All @@ -41,4 +41,4 @@ sourceFile:index.ts
5 >Emitted(5, 14) Source(2, 19) + SourceIndex(0)
6 >Emitted(5, 15) Source(2, 20) + SourceIndex(0)
---
>>>//# sourceMappingURL=../src/myMapRoot/index.js.map
>>>//# sourceMappingURL=../../myMapRoot/src/index.js.map

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error TS5055: Cannot write file '/bar.js' because it would overwrite input file.
/root/a.ts(1,21): error TS6059: File '/foo.ts' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.
/root/a.ts(2,21): error TS6059: File '/bar.js' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.


!!! error TS5055: Cannot write file '/bar.js' because it would overwrite input file.
==== /root/tsconfig.json (0 errors) ====
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"/*": ["./src/*"]
},
"allowJs": true,
"outDir": "bin"
}
}

==== /root/a.ts (2 errors) ====
import { foo } from "/foo";
~~~~~~
!!! error TS6059: File '/foo.ts' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.
import { bar } from "/bar";
~~~~~~
!!! error TS6059: File '/bar.js' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.

==== /foo.ts (0 errors) ====
export function foo() {}

==== /bar.js (0 errors) ====
export function bar() {}

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import { bar } from "/bar";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = foo;
function foo() { }
//// [bar.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bar = bar;
function bar() { }
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error TS5055: Cannot write file '/bar.js' because it would overwrite input file.
/root/a.ts(1,21): error TS6059: File '/foo.ts' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.
/root/a.ts(2,21): error TS6059: File '/bar.js' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.


!!! error TS5055: Cannot write file '/bar.js' because it would overwrite input file.
==== /root/tsconfig.json (0 errors) ====
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["./src/*"]
},
"allowJs": true,
"outDir": "bin"
}
}

==== /root/a.ts (2 errors) ====
import { foo } from "/foo";
~~~~~~
!!! error TS6059: File '/foo.ts' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.
import { bar } from "/bar";
~~~~~~
!!! error TS6059: File '/bar.js' is not under 'rootDir' '/root'. 'rootDir' is expected to contain all source files.

==== /foo.ts (0 errors) ====
export function foo() {}

==== /bar.js (0 errors) ====
export function bar() {}

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ import { bar } from "/bar";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foo = foo;
function foo() { }
//// [bar.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bar = bar;
function bar() { }
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Found 1 error.


//// [/home/src/workspaces/project/outFile.js]
define("index", ["require", "exports", "ky"], function (require, exports, ky_1) {
define("src/index", ["require", "exports", "ky"], function (require, exports, ky_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.api = void 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Found 1 error.


//// [/home/src/workspaces/project/outFile.js]
define("index", ["require", "exports", "ky"], function (require, exports, ky_1) {
define("src/index", ["require", "exports", "ky"], function (require, exports, ky_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.api = void 0;
Expand Down
Loading
Loading