Skip to content

Keep extended config's raw file, include, exclude relative to itself and correct it when setting extending options #42544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2021
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
31 changes: 8 additions & 23 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2617,14 +2617,17 @@ namespace ts {
if (ownConfig.extendedConfigPath) {
// copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios.
resolutionStack = resolutionStack.concat([resolvedPath]);
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors, extendedConfigCache);
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, resolutionStack, errors, extendedConfigCache);
if (extendedConfig && isSuccessfulParsedTsconfig(extendedConfig)) {
const baseRaw = extendedConfig.raw;
const raw = ownConfig.raw;
let relativeDifference: string | undefined ;
const setPropertyInRawIfNotUndefined = (propertyName: string) => {
const value = raw[propertyName] || baseRaw[propertyName];
if (value) {
raw[propertyName] = value;
if (!raw[propertyName] && baseRaw[propertyName]) {
raw[propertyName] = map(baseRaw[propertyName], (path: string) => isRootedDiskPath(path) ? path : combinePaths(
relativeDifference ||= convertToRelativePath(getDirectoryPath(ownConfig.extendedConfigPath!), basePath, createGetCanonicalFileName(host.useCaseSensitiveFileNames)),
path
));
}
};
setPropertyInRawIfNotUndefined("include");
Expand Down Expand Up @@ -2786,7 +2789,6 @@ namespace ts {
sourceFile: TsConfigSourceFile | undefined,
extendedConfigPath: string,
host: ParseConfigHost,
basePath: string,
resolutionStack: string[],
errors: Push<Diagnostic>,
extendedConfigCache?: ESMap<string, ExtendedConfigCacheEntry>
Expand All @@ -2801,25 +2803,8 @@ namespace ts {
else {
extendedResult = readJsonConfigFile(extendedConfigPath, path => host.readFile(path));
if (!extendedResult.parseDiagnostics.length) {
const extendedDirname = getDirectoryPath(extendedConfigPath);
extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, extendedDirname,
extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, getDirectoryPath(extendedConfigPath),
getBaseFileName(extendedConfigPath), resolutionStack, errors, extendedConfigCache);

if (isSuccessfulParsedTsconfig(extendedConfig)) {
// Update the paths to reflect base path
const relativeDifference = convertToRelativePath(extendedDirname, basePath, identity);
const updatePath = (path: string) => isRootedDiskPath(path) ? path : combinePaths(relativeDifference, path);
const mapPropertiesInRawIfNotUndefined = (propertyName: string) => {
if (raw[propertyName]) {
raw[propertyName] = map(raw[propertyName], updatePath);
}
};

const { raw } = extendedConfig;
mapPropertiesInRawIfNotUndefined("include");
mapPropertiesInRawIfNotUndefined("exclude");
mapPropertiesInRawIfNotUndefined("files");
}
}
if (extendedConfigCache) {
extendedConfigCache.set(path, { extendedResult, extendedConfig });
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"unittests/services/transpile.ts",
"unittests/tsbuild/amdModulesWithOut.ts",
"unittests/tsbuild/configFileErrors.ts",
"unittests/tsbuild/configFileExtends.ts",
"unittests/tsbuild/containerOnlyReferenced.ts",
"unittests/tsbuild/declarationEmit.ts",
"unittests/tsbuild/demo.ts",
Expand Down
52 changes: 52 additions & 0 deletions src/testRunner/unittests/tsbuild/configFileExtends.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace ts {
describe("unittests:: tsbuild:: configFileExtends:: when tsconfig extends another config", () => {
function getConfigExtendsWithIncludeFs() {
return loadProjectFromFiles({
"/src/tsconfig.json": JSON.stringify({
references: [
{ path: "./shared/tsconfig.json" },
{ path: "./webpack/tsconfig.json" }
],
files: []
}),
"/src/shared/tsconfig-base.json": JSON.stringify({
include: ["./typings-base/"]
}),
"/src/shared/typings-base/globals.d.ts": `type Unrestricted = any;`,
"/src/shared/tsconfig.json": JSON.stringify({
extends: "./tsconfig-base.json",
compilerOptions: {
composite: true,
outDir: "../target-tsc-build/",
rootDir: ".."
},
files: ["./index.ts"]
}),
"/src/shared/index.ts": `export const a: Unrestricted = 1;`,
"/src/webpack/tsconfig.json": JSON.stringify({
extends: "../shared/tsconfig-base.json",
compilerOptions: {
composite: true,
outDir: "../target-tsc-build/",
rootDir: ".."
},
files: ["./index.ts"],
references: [{ path: "../shared/tsconfig.json" }]
}),
"/src/webpack/index.ts": `export const b: Unrestricted = 1;`,
});
}
verifyTsc({
scenario: "configFileExtends",
subScenario: "when building solution with projects extends config with include",
fs: getConfigExtendsWithIncludeFs,
commandLineArgs: ["--b", "/src/tsconfig.json", "--v", "--listFiles"],
});
verifyTsc({
scenario: "configFileExtends",
subScenario: "when building project uses reference and both extend config with include",
fs: getConfigExtendsWithIncludeFs,
commandLineArgs: ["--b", "/src/webpack/tsconfig.json", "--v", "--listFiles"],
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
Input::
//// [/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };

//// [/src/shared/index.ts]
export const a: Unrestricted = 1;

//// [/src/shared/tsconfig-base.json]
{"include":["./typings-base/"]}

//// [/src/shared/tsconfig.json]
{"extends":"./tsconfig-base.json","compilerOptions":{"composite":true,"outDir":"../target-tsc-build/","rootDir":".."},"files":["./index.ts"]}

//// [/src/shared/typings-base/globals.d.ts]
type Unrestricted = any;

//// [/src/tsconfig.json]


//// [/src/webpack/index.ts]
export const b: Unrestricted = 1;

//// [/src/webpack/tsconfig.json]
{"extends":"../shared/tsconfig-base.json","compilerOptions":{"composite":true,"outDir":"../target-tsc-build/","rootDir":".."},"files":["./index.ts"],"references":[{"path":"../shared/tsconfig.json"}]}



Output::
/lib/tsc --b /src/webpack/tsconfig.json --v --listFiles
[12:00:00 AM] Projects in this build:
* src/shared/tsconfig.json
* src/webpack/tsconfig.json

[12:00:00 AM] Project 'src/shared/tsconfig.json' is out of date because output file 'src/target-tsc-build/shared/index.js' does not exist

[12:00:00 AM] Building project '/src/shared/tsconfig.json'...

/lib/lib.d.ts
/src/shared/index.ts
/src/shared/typings-base/globals.d.ts
[12:00:00 AM] Project 'src/webpack/tsconfig.json' is out of date because output file 'src/target-tsc-build/webpack/index.js' does not exist

[12:00:00 AM] Building project '/src/webpack/tsconfig.json'...

/lib/lib.d.ts
/src/webpack/index.ts
/src/shared/typings-base/globals.d.ts
exitCode:: ExitStatus.Success


//// [/src/target-tsc-build/shared/index.d.ts]
export declare const a: Unrestricted;


//// [/src/target-tsc-build/shared/index.js]
"use strict";
exports.__esModule = true;
exports.a = void 0;
exports.a = 1;


//// [/src/target-tsc-build/shared/tsconfig.tsbuildinfo]
{
"program": {
"fileInfos": {
"../../../lib/lib.d.ts": {
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true
},
"../../shared/index.ts": {
"version": "-22125360210-export const a: Unrestricted = 1;",
"signature": "-478734393-export declare const a: Unrestricted;\r\n",
"affectsGlobalScope": false
},
"../../shared/typings-base/globals.d.ts": {
"version": "4725476611-type Unrestricted = any;",
"signature": "4725476611-type Unrestricted = any;",
"affectsGlobalScope": true
}
},
"options": {
"composite": true,
"outDir": "..",
"rootDir": "../..",
"listFiles": true,
"configFilePath": "../../shared/tsconfig.json"
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../../lib/lib.d.ts",
"../../shared/index.ts",
"../../shared/typings-base/globals.d.ts"
]
},
"version": "FakeTSVersion"
}

//// [/src/target-tsc-build/webpack/index.d.ts]
export declare const b: Unrestricted;


//// [/src/target-tsc-build/webpack/index.js]
"use strict";
exports.__esModule = true;
exports.b = void 0;
exports.b = 1;


//// [/src/target-tsc-build/webpack/tsconfig.tsbuildinfo]
{
"program": {
"fileInfos": {
"../../../lib/lib.d.ts": {
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true
},
"../../webpack/index.ts": {
"version": "-14405273073-export const b: Unrestricted = 1;",
"signature": "-5074241048-export declare const b: Unrestricted;\r\n",
"affectsGlobalScope": false
},
"../../shared/typings-base/globals.d.ts": {
"version": "4725476611-type Unrestricted = any;",
"signature": "4725476611-type Unrestricted = any;",
"affectsGlobalScope": true
}
},
"options": {
"composite": true,
"outDir": "..",
"rootDir": "../..",
"listFiles": true,
"configFilePath": "../../webpack/tsconfig.json"
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../../lib/lib.d.ts",
"../../shared/typings-base/globals.d.ts",
"../../webpack/index.ts"
]
},
"version": "FakeTSVersion"
}

Loading