Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
30 changes: 9 additions & 21 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,6 @@
"category": "Error",
"code": 1464
},

"The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.": {
"category": "Error",
"code": 1470
Expand Down Expand Up @@ -1849,7 +1848,6 @@
"category": "Error",
"code": 1546
},

"The types of '{0}' are incompatible between these types.": {
"category": "Error",
"code": 2200
Expand Down Expand Up @@ -1890,7 +1888,6 @@
"category": "Error",
"code": 2208
},

"The project root is ambiguous, but is required to resolve export map entry '{0}' in file '{1}'. Supply the `rootDir` compiler option to disambiguate.": {
"category": "Error",
"code": 2209
Expand All @@ -1907,7 +1904,6 @@
"category": "Message",
"code": 2212
},

"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
Expand Down Expand Up @@ -2888,7 +2884,6 @@
"category": "Error",
"code": 2568
},

"Could not find name '{0}'. Did you mean '{1}'?": {
"category": "Error",
"code": 2570
Expand Down Expand Up @@ -3129,7 +3124,6 @@
"category": "Error",
"code": 2639
},

"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
"category": "Error",
"code": 2649
Expand Down Expand Up @@ -4007,7 +4001,6 @@
"category": "Error",
"code": 2881
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
Expand Down Expand Up @@ -4452,7 +4445,6 @@
"category": "Error",
"code": 4128
},

"The current host does not support the '{0}' option.": {
"category": "Error",
"code": 5001
Expand All @@ -4465,6 +4457,10 @@
"category": "Error",
"code": 5010
},
"Inferred common source directory differs from tsconfig directory, output layout will be changed.": {
"category": "Error",
"code": 5011
},
"Cannot read file '{0}': {1}.": {
"category": "Error",
"code": 5012
Expand Down Expand Up @@ -4717,7 +4713,10 @@
"category": "Error",
"code": 5110
},

"Visit https://aka.ms/ts6 for migration information.": {
"category": "Message",
"code": 5111
},
"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
"code": 6000
Expand Down Expand Up @@ -5661,7 +5660,6 @@
"category": "Error",
"code": 6266
},

"Directory '{0}' has no containing package.json scope. Imports will not resolve.": {
"category": "Message",
"code": 6270
Expand Down Expand Up @@ -5754,7 +5752,6 @@
"category": "Message",
"code": 6294
},

"Enable project compilation": {
"category": "Message",
"code": 6302
Expand Down Expand Up @@ -6037,7 +6034,6 @@
"category": "Message",
"code": 6421
},

"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
"code": 6500
Expand Down Expand Up @@ -6562,7 +6558,6 @@
"category": "Message",
"code": 6808
},

"one of:": {
"category": "Message",
"code": 6900
Expand Down Expand Up @@ -6691,7 +6686,6 @@
"category": "Error",
"code": 6931
},

"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",
"code": 7005
Expand Down Expand Up @@ -6914,7 +6908,6 @@
"category": "Error",
"code": 7061
},

"You cannot rename this element.": {
"category": "Error",
"code": 8000
Expand Down Expand Up @@ -7059,7 +7052,6 @@
"category": "Error",
"code": 8039
},

"Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit.": {
"category": "Error",
"code": 9005
Expand Down Expand Up @@ -7292,7 +7284,6 @@
"category": "Error",
"code": 18003
},

"File is a CommonJS module; it may be converted to an ES module.": {
"category": "Suggestion",
"code": 80001
Expand Down Expand Up @@ -7333,7 +7324,6 @@
"category": "Suggestion",
"code": 80010
},

"Add missing 'super()' call": {
"category": "Message",
"code": 90001
Expand Down Expand Up @@ -7554,7 +7544,6 @@
"category": "Message",
"code": 90071
},

"Convert function to an ES2015 class": {
"category": "Message",
"code": 95001
Expand Down Expand Up @@ -8323,7 +8312,6 @@
"category": "Message",
"code": 95197
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
"code": 18004
Expand Down Expand Up @@ -8520,4 +8508,4 @@
"category": "Error",
"code": 18061
}
}
}
19 changes: 18 additions & 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 All @@ -664,6 +664,23 @@ export function getCommonSourceDirectory(
return commonSourceDirectory;
}

/** @internal */
export function getComputedCommonSourceDirectory(
emittedFiles: readonly string[],
currentDirectory: string,
getCanonicalFileName: GetCanonicalFileName,
): string {
let commonSourceDirectory = computeCommonSourceDirectoryOfFilenames(emittedFiles, currentDirectory, getCanonicalFileName);

if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
// Make sure directory path ends with directory separator so this string can directly
// used to replace with "" to get the relative path of the source file and the relative path doesn't
// start with / making it rooted path
commonSourceDirectory += directorySeparator;
}
return commonSourceDirectory;
}

/** @internal */
export function getCommonSourceDirectoryOfConfig({ options, fileNames }: ParsedCommandLine, ignoreCase: boolean): string {
return getCommonSourceDirectory(
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
22 changes: 22 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import {
GetCanonicalFileName,
getCommonSourceDirectory as ts_getCommonSourceDirectory,
getCommonSourceDirectoryOfConfig,
getComputedCommonSourceDirectory,
getDeclarationDiagnostics as ts_getDeclarationDiagnostics,
getDefaultLibFileName,
getDirectoryPath,
Expand Down Expand Up @@ -4293,6 +4294,27 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
}
}

if (
!options.noEmit &&
!options.composite &&
!options.rootDir &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't want to do this check if rootDir is specified, because the user should already have a working rootDir, or will otherwise get errors on individual files. Users who have a rootDir now also have to have their outputs double-checked.

options.configFilePath &&
(options.outDir || // there is --outDir specified
(getEmitDeclarations(options) && options.declarationDir)) // there is --declarationDir specified
) {
// Check if rootDir inferred changed and issue diagnostic
const dir = getCommonSourceDirectory();
const emittedFiles = mapDefined(files, file => !file.isDeclarationFile && sourceFileMayBeEmitted(file, program) ? file.fileName : undefined);
const dir59 = getComputedCommonSourceDirectory(emittedFiles, currentDirectory, getCanonicalFileName);
if (dir59 !== "" && getCanonicalFileName(dir) !== getCanonicalFileName(dir59)) {
// change in layout
programDiagnostics.addConfigDiagnostic(createCompilerDiagnosticFromMessageChain(chainDiagnosticMessages(
chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Visit_https_Colon_Slash_Slashaka_ms_Slashts6_for_migration_information),
Diagnostics.Inferred_common_source_directory_differs_from_tsconfig_directory_output_layout_will_be_changed,
)));
}
}

if (options.checkJs && !getAllowJSCompilerOption(options)) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs");
}
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
32 changes: 32 additions & 0 deletions tests/baselines/reference/commonSourceDirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,35 @@ foo_1.x + bar_1.y;
//// [/app/bin/index.d.ts]
/// <reference path="../../types/bar.d.ts" preserve="true" />
export {};


//// [DtsFileErrors]


error TS5011: Inferred common source directory differs from tsconfig directory, output layout will be changed.
Visit https://aka.ms/ts6 for migration information.


!!! error TS5011: Inferred common source directory differs from tsconfig directory, output layout will be changed.
!!! 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;
}

24 changes: 24 additions & 0 deletions tests/baselines/reference/commonSourceDirectory_dts.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error TS5011: Inferred common source directory differs from tsconfig directory, output layout will be changed.
Visit https://aka.ms/ts6 for migration information.


!!! error TS5011: Inferred common source directory differs from tsconfig directory, output layout will be changed.
!!! error TS5011: Visit https://aka.ms/ts6 for migration information.
==== /app/tsconfig.json (0 errors) ====
{
"compilerOptions": {
"outDir": "bin",
"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;

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.

Loading