Skip to content

Commit 05d739b

Browse files
committed
Add test that fails
1 parent 16faef1 commit 05d739b

File tree

4 files changed

+231
-1
lines changed

4 files changed

+231
-1
lines changed

src/harness/fakesHosts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace fakes {
4141
}
4242

4343
public write(message: string) {
44+
if (ts.Debug.isDebugging) console.log(message);
4445
this.output.push(message);
4546
}
4647

src/harness/virtualFileSystemWithWatch.ts

+1
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ interface Array<T> { length: number; [n: number]: T; }`
987987
}
988988

989989
write(message: string) {
990+
if (Debug.isDebugging) console.log(message);
990991
this.output.push(message);
991992
}
992993

src/testRunner/unittests/tsbuild/moduleResolution.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,36 @@ namespace ts.tscWatch {
8686
commandLineArgs: ["-b", "/src/packages/pkg1.tsconfig.json", "/src/packages/pkg2.tsconfig.json", "--verbose", "--traceResolution"],
8787
});
8888
});
89-
}
89+
90+
describe("unittests:: tsbuild:: moduleResolution:: impliedNodeFormat differs between projects for shared file", () => {
91+
verifyTscWithEdits({
92+
scenario: "moduleResolution",
93+
subScenario: "impliedNodeFormat differs between projects for shared file",
94+
fs: () => loadProjectFromFiles({
95+
"/src/projects/a/src/index.ts": "",
96+
"/src/projects/a/tsconfig.json": JSON.stringify({
97+
compilerOptions: { strict: true }
98+
}),
99+
"/src/projects/b/src/index.ts": Utils.dedent`
100+
import pg from "pg";
101+
pg.foo();
102+
`,
103+
"/src/projects/b/tsconfig.json": JSON.stringify({
104+
compilerOptions: { strict: true, module: "node16" }
105+
}),
106+
"/src/projects/b/package.json": JSON.stringify({
107+
name: "b",
108+
type: "module"
109+
}),
110+
"/src/projects/node_modules/@types/pg/index.d.ts": "export function foo(): void;",
111+
"/src/projects/node_modules/@types/pg/package.json": JSON.stringify({
112+
name: "@types/pg",
113+
types: "index.d.ts",
114+
}),
115+
}),
116+
modifyFs: fs => fs.writeFileSync("/lib/lib.es2022.full.d.ts", libFile.content),
117+
commandLineArgs: ["-b", "/src/projects/a", "/src/projects/b", "--verbose", "--traceResolution", "--explainFiles"],
118+
edits: noChangeOnlyRuns
119+
});
120+
});
121+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/lib/lib.es2022.full.d.ts]
18+
/// <reference no-default-lib="true"/>
19+
interface Boolean {}
20+
interface Function {}
21+
interface CallableFunction {}
22+
interface NewableFunction {}
23+
interface IArguments {}
24+
interface Number { toExponential: any; }
25+
interface Object {}
26+
interface RegExp {}
27+
interface String { charAt: any; }
28+
interface Array<T> { length: number; [n: number]: T; }
29+
30+
//// [/src/projects/a/src/index.ts]
31+
32+
33+
//// [/src/projects/a/tsconfig.json]
34+
{"compilerOptions":{"strict":true}}
35+
36+
//// [/src/projects/b/package.json]
37+
{"name":"b","type":"module"}
38+
39+
//// [/src/projects/b/src/index.ts]
40+
import pg from "pg";
41+
pg.foo();
42+
43+
44+
//// [/src/projects/b/tsconfig.json]
45+
{"compilerOptions":{"strict":true,"module":"node16"}}
46+
47+
//// [/src/projects/node_modules/@types/pg/index.d.ts]
48+
export function foo(): void;
49+
50+
//// [/src/projects/node_modules/@types/pg/package.json]
51+
{"name":"@types/pg","types":"index.d.ts"}
52+
53+
54+
55+
Output::
56+
/lib/tsc -b /src/projects/a /src/projects/b --verbose --traceResolution --explainFiles
57+
[12:00:22 AM] Projects in this build:
58+
* src/projects/a/tsconfig.json
59+
* src/projects/b/tsconfig.json
60+
61+
[12:00:23 AM] Project 'src/projects/a/tsconfig.json' is out of date because output file 'src/projects/a/src/index.js' does not exist
62+
63+
[12:00:24 AM] Building project '/src/projects/a/tsconfig.json'...
64+
65+
======== Resolving type reference directive 'pg', containing file '/src/projects/a/__inferred type names__.ts', root directory '/src/projects/node_modules/@types'. ========
66+
Resolving with primary search path '/src/projects/node_modules/@types'.
67+
Found 'package.json' at '/src/projects/node_modules/@types/pg/package.json'.
68+
'package.json' does not have a 'typesVersions' field.
69+
'package.json' does not have a 'typings' field.
70+
'package.json' has 'types' field 'index.d.ts' that references '/src/projects/node_modules/@types/pg/index.d.ts'.
71+
File '/src/projects/node_modules/@types/pg/index.d.ts' exist - use it as a name resolution result.
72+
Resolving real path for '/src/projects/node_modules/@types/pg/index.d.ts', result '/src/projects/node_modules/@types/pg/index.d.ts'.
73+
======== Type reference directive 'pg' was successfully resolved to '/src/projects/node_modules/@types/pg/index.d.ts', primary: true. ========
74+
lib/lib.d.ts
75+
Default library for target 'es3'
76+
src/projects/a/src/index.ts
77+
Matched by default include pattern '**/*'
78+
src/projects/node_modules/@types/pg/index.d.ts
79+
Entry point for implicit type library 'pg'
80+
[12:00:26 AM] Project 'src/projects/b/tsconfig.json' is out of date because output file 'src/projects/b/src/index.js' does not exist
81+
82+
[12:00:27 AM] Building project '/src/projects/b/tsconfig.json'...
83+
84+
File '/src/projects/b/src/package.json' does not exist.
85+
Found 'package.json' at '/src/projects/b/package.json'.
86+
'package.json' does not have a 'typesVersions' field.
87+
======== Resolving module 'pg' from '/src/projects/b/src/index.ts'. ========
88+
Module resolution kind is not specified, using 'Node16'.
89+
File '/src/projects/b/src/package.json' does not exist according to earlier cached lookups.
90+
File '/src/projects/b/package.json' exists according to earlier cached lookups.
91+
Loading module 'pg' from 'node_modules' folder, target file type 'TypeScript'.
92+
Directory '/src/projects/b/src/node_modules' does not exist, skipping all lookups in it.
93+
Directory '/src/projects/b/node_modules' does not exist, skipping all lookups in it.
94+
File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups.
95+
'package.json' does not have a 'typings' field.
96+
'package.json' has 'types' field 'index.d.ts' that references '/src/projects/node_modules/@types/pg/index.d.ts'.
97+
File '/src/projects/node_modules/@types/pg/index.d.ts' exist - use it as a name resolution result.
98+
Resolving real path for '/src/projects/node_modules/@types/pg/index.d.ts', result '/src/projects/node_modules/@types/pg/index.d.ts'.
99+
======== Module name 'pg' was successfully resolved to '/src/projects/node_modules/@types/pg/index.d.ts'. ========
100+
File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups.
101+
======== Resolving type reference directive 'pg', containing file '/src/projects/b/__inferred type names__.ts', root directory '/src/projects/node_modules/@types'. ========
102+
Resolving with primary search path '/src/projects/node_modules/@types'.
103+
File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups.
104+
'package.json' does not have a 'typings' field.
105+
'package.json' has 'types' field 'index.d.ts' that references '/src/projects/node_modules/@types/pg/index.d.ts'.
106+
File '/src/projects/node_modules/@types/pg/index.d.ts' exist - use it as a name resolution result.
107+
Resolving real path for '/src/projects/node_modules/@types/pg/index.d.ts', result '/src/projects/node_modules/@types/pg/index.d.ts'.
108+
======== Type reference directive 'pg' was successfully resolved to '/src/projects/node_modules/@types/pg/index.d.ts', primary: true. ========
109+
File '/lib/package.json' does not exist.
110+
File '/package.json' does not exist.
111+
src/projects/b/src/index.ts:1:8 - error TS1192: Module '"/src/projects/node_modules/@types/pg/index"' has no default export.
112+
113+
1 import pg from "pg";
114+
   ~~
115+
116+
lib/lib.es2022.full.d.ts
117+
Default library for target 'es2022'
118+
src/projects/node_modules/@types/pg/index.d.ts
119+
Imported via "pg" from file 'src/projects/b/src/index.ts'
120+
Entry point for implicit type library 'pg'
121+
src/projects/b/src/index.ts
122+
Matched by default include pattern '**/*'
123+
File is ECMAScript module because 'src/projects/b/package.json' has field "type" with value "module"
124+
125+
Found 1 error.
126+
127+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
128+
129+
130+
//// [/src/projects/a/src/index.js]
131+
"use strict";
132+
133+
134+
135+
136+
Change:: no-change-run
137+
Input::
138+
139+
140+
Output::
141+
/lib/tsc -b /src/projects/a /src/projects/b --verbose --traceResolution --explainFiles
142+
[12:00:28 AM] Projects in this build:
143+
* src/projects/a/tsconfig.json
144+
* src/projects/b/tsconfig.json
145+
146+
[12:00:29 AM] Project 'src/projects/a/tsconfig.json' is up to date because newest input 'src/projects/a/src/index.ts' is older than output 'src/projects/a/src/index.js'
147+
148+
[12:00:30 AM] Project 'src/projects/b/tsconfig.json' is out of date because output file 'src/projects/b/src/index.js' does not exist
149+
150+
[12:00:31 AM] Building project '/src/projects/b/tsconfig.json'...
151+
152+
File '/src/projects/b/src/package.json' does not exist.
153+
Found 'package.json' at '/src/projects/b/package.json'.
154+
'package.json' does not have a 'typesVersions' field.
155+
======== Resolving module 'pg' from '/src/projects/b/src/index.ts'. ========
156+
Module resolution kind is not specified, using 'Node16'.
157+
File '/src/projects/b/src/package.json' does not exist according to earlier cached lookups.
158+
File '/src/projects/b/package.json' exists according to earlier cached lookups.
159+
Loading module 'pg' from 'node_modules' folder, target file type 'TypeScript'.
160+
Directory '/src/projects/b/src/node_modules' does not exist, skipping all lookups in it.
161+
Directory '/src/projects/b/node_modules' does not exist, skipping all lookups in it.
162+
Found 'package.json' at '/src/projects/node_modules/@types/pg/package.json'.
163+
'package.json' does not have a 'typesVersions' field.
164+
'package.json' does not have a 'typings' field.
165+
'package.json' has 'types' field 'index.d.ts' that references '/src/projects/node_modules/@types/pg/index.d.ts'.
166+
File '/src/projects/node_modules/@types/pg/index.d.ts' exist - use it as a name resolution result.
167+
Resolving real path for '/src/projects/node_modules/@types/pg/index.d.ts', result '/src/projects/node_modules/@types/pg/index.d.ts'.
168+
======== Module name 'pg' was successfully resolved to '/src/projects/node_modules/@types/pg/index.d.ts'. ========
169+
File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups.
170+
======== Resolving type reference directive 'pg', containing file '/src/projects/b/__inferred type names__.ts', root directory '/src/projects/node_modules/@types'. ========
171+
Resolving with primary search path '/src/projects/node_modules/@types'.
172+
File '/src/projects/node_modules/@types/pg/package.json' exists according to earlier cached lookups.
173+
'package.json' does not have a 'typings' field.
174+
'package.json' has 'types' field 'index.d.ts' that references '/src/projects/node_modules/@types/pg/index.d.ts'.
175+
File '/src/projects/node_modules/@types/pg/index.d.ts' exist - use it as a name resolution result.
176+
Resolving real path for '/src/projects/node_modules/@types/pg/index.d.ts', result '/src/projects/node_modules/@types/pg/index.d.ts'.
177+
======== Type reference directive 'pg' was successfully resolved to '/src/projects/node_modules/@types/pg/index.d.ts', primary: true. ========
178+
File '/lib/package.json' does not exist.
179+
File '/package.json' does not exist.
180+
lib/lib.es2022.full.d.ts
181+
Default library for target 'es2022'
182+
src/projects/node_modules/@types/pg/index.d.ts
183+
Imported via "pg" from file 'src/projects/b/src/index.ts'
184+
Entry point for implicit type library 'pg'
185+
File is CommonJS module because 'src/projects/node_modules/@types/pg/package.json' does not have field "type"
186+
src/projects/b/src/index.ts
187+
Matched by default include pattern '**/*'
188+
File is ECMAScript module because 'src/projects/b/package.json' has field "type" with value "module"
189+
exitCode:: ExitStatus.Success
190+
191+
192+
//// [/src/projects/b/src/index.js]
193+
import pg from "pg";
194+
pg.foo();
195+
196+

0 commit comments

Comments
 (0)