Skip to content

Commit

Permalink
Cherry-pick PR #44008 into release-4.3 (#44029)
Browse files Browse the repository at this point in the history
Component commits:
8da9ed0 Test without change

5c1ae7a Update showing fix in #44004 works

Co-authored-by: Sheetal Nandi <[email protected]>
  • Loading branch information
TypeScript Bot and sheetalkamat authored May 10, 2021
1 parent d805ce8 commit 1d850c0
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/testRunner/unittests/tsbuild/moduleResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,25 @@ namespace ts.tscWatch {
commandLineArgs: ["-b", "packages/pkg1", "--verbose", "--traceResolution"],
changes: emptyArray
});

verifyTsc({
scenario: "moduleResolution",
subScenario: `type reference resolution uses correct options for different resolution options referenced project`,
fs: () => loadProjectFromFiles({
"/src/packages/pkg1_index.ts": `export const theNum: TheNum = "type1";`,
"/src/packages/pkg1.tsconfig.json": JSON.stringify({
compilerOptions: { composite: true, typeRoots: ["./typeroot1"] },
files: ["./pkg1_index.ts"]
}),
"/src/packages/typeroot1/sometype/index.d.ts": Utils.dedent`declare type TheNum = "type1";`,
"/src/packages/pkg2_index.ts": `export const theNum: TheNum2 = "type2";`,
"/src/packages/pkg2.tsconfig.json": JSON.stringify({
compilerOptions: { composite: true, typeRoots: ["./typeroot2"] },
files: ["./pkg2_index.ts"]
}),
"/src/packages/typeroot2/sometype/index.d.ts": Utils.dedent`declare type TheNum2 = "type2";`,
}),
commandLineArgs: ["-b", "/src/packages/pkg1.tsconfig.json", "/src/packages/pkg2.tsconfig.json", "--verbose", "--traceResolution"],
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
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/packages/pkg1.tsconfig.json]
{"compilerOptions":{"composite":true,"typeRoots":["./typeroot1"]},"files":["./pkg1_index.ts"]}

//// [/src/packages/pkg1_index.ts]
export const theNum: TheNum = "type1";

//// [/src/packages/pkg2.tsconfig.json]
{"compilerOptions":{"composite":true,"typeRoots":["./typeroot2"]},"files":["./pkg2_index.ts"]}

//// [/src/packages/pkg2_index.ts]
export const theNum: TheNum2 = "type2";

//// [/src/packages/typeroot1/sometype/index.d.ts]
declare type TheNum = "type1";

//// [/src/packages/typeroot2/sometype/index.d.ts]
declare type TheNum2 = "type2";



Output::
/lib/tsc -b /src/packages/pkg1.tsconfig.json /src/packages/pkg2.tsconfig.json --verbose --traceResolution
[12:00:00 AM] Projects in this build:
* src/packages/pkg1.tsconfig.json
* src/packages/pkg2.tsconfig.json

[12:00:00 AM] Project 'src/packages/pkg1.tsconfig.json' is out of date because output file 'src/packages/pkg1_index.js' does not exist

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

======== Resolving type reference directive 'sometype', containing file '/src/packages/__inferred type names__.ts', root directory '/src/packages/typeroot1'. ========
Resolving with primary search path '/src/packages/typeroot1'.
File '/src/packages/typeroot1/sometype/package.json' does not exist.
File '/src/packages/typeroot1/sometype/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/src/packages/typeroot1/sometype/index.d.ts', result '/src/packages/typeroot1/sometype/index.d.ts'.
======== Type reference directive 'sometype' was successfully resolved to '/src/packages/typeroot1/sometype/index.d.ts', primary: true. ========
[12:00:00 AM] Project 'src/packages/pkg2.tsconfig.json' is out of date because output file 'src/packages/pkg2_index.js' does not exist

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

======== Resolving type reference directive 'sometype', containing file '/src/packages/__inferred type names__.ts', root directory '/src/packages/typeroot2'. ========
Resolving with primary search path '/src/packages/typeroot2'.
File '/src/packages/typeroot2/sometype/package.json' does not exist.
File '/src/packages/typeroot2/sometype/index.d.ts' exist - use it as a name resolution result.
Resolving real path for '/src/packages/typeroot2/sometype/index.d.ts', result '/src/packages/typeroot2/sometype/index.d.ts'.
======== Type reference directive 'sometype' was successfully resolved to '/src/packages/typeroot2/sometype/index.d.ts', primary: true. ========
exitCode:: ExitStatus.Success


//// [/src/packages/pkg1.tsconfig.tsbuildinfo]
{"program":{"fileNames":["../../lib/lib.d.ts","./pkg1_index.ts","./typeroot1/sometype/index.d.ts"],"fileInfos":[{"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; };","affectsGlobalScope":true},"-9601687719-export const theNum: TheNum = \"type1\";",{"version":"-4557394441-declare type TheNum = \"type1\";","affectsGlobalScope":true}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}

//// [/src/packages/pkg1.tsconfig.tsbuildinfo.readable.baseline.txt]
{
"program": {
"fileNames": [
"../../lib/lib.d.ts",
"./pkg1_index.ts",
"./typeroot1/sometype/index.d.ts"
],
"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
},
"./pkg1_index.ts": {
"version": "-9601687719-export const theNum: TheNum = \"type1\";",
"signature": "-9601687719-export const theNum: TheNum = \"type1\";"
},
"./typeroot1/sometype/index.d.ts": {
"version": "-4557394441-declare type TheNum = \"type1\";",
"signature": "-4557394441-declare type TheNum = \"type1\";",
"affectsGlobalScope": true
}
},
"options": {
"composite": true
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../lib/lib.d.ts",
"./pkg1_index.ts",
"./typeroot1/sometype/index.d.ts"
]
},
"version": "FakeTSVersion",
"size": 868
}

//// [/src/packages/pkg1_index.d.ts]
/// <reference types="sometype" />
export declare const theNum: TheNum;


//// [/src/packages/pkg1_index.js]
"use strict";
exports.__esModule = true;
exports.theNum = void 0;
exports.theNum = "type1";


//// [/src/packages/pkg2.tsconfig.tsbuildinfo]
{"program":{"fileNames":["../../lib/lib.d.ts","./pkg2_index.ts","./typeroot2/sometype/index.d.ts"],"fileInfos":[{"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; };","affectsGlobalScope":true},"-12823281204-export const theNum: TheNum2 = \"type2\";",{"version":"-980425686-declare type TheNum2 = \"type2\";","affectsGlobalScope":true}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}

//// [/src/packages/pkg2.tsconfig.tsbuildinfo.readable.baseline.txt]
{
"program": {
"fileNames": [
"../../lib/lib.d.ts",
"./pkg2_index.ts",
"./typeroot2/sometype/index.d.ts"
],
"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
},
"./pkg2_index.ts": {
"version": "-12823281204-export const theNum: TheNum2 = \"type2\";",
"signature": "-12823281204-export const theNum: TheNum2 = \"type2\";"
},
"./typeroot2/sometype/index.d.ts": {
"version": "-980425686-declare type TheNum2 = \"type2\";",
"signature": "-980425686-declare type TheNum2 = \"type2\";",
"affectsGlobalScope": true
}
},
"options": {
"composite": true
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../lib/lib.d.ts",
"./pkg2_index.ts",
"./typeroot2/sometype/index.d.ts"
]
},
"version": "FakeTSVersion",
"size": 870
}

//// [/src/packages/pkg2_index.d.ts]
/// <reference types="sometype" />
export declare const theNum: TheNum2;


//// [/src/packages/pkg2_index.js]
"use strict";
exports.__esModule = true;
exports.theNum = void 0;
exports.theNum = "type2";


0 comments on commit 1d850c0

Please sign in to comment.