Skip to content

Commit 221cf55

Browse files
authoredSep 22, 2022
package.json exports should have priority over typesVersions (#50890)
* package.json `exports` should have priority over `typesVersions` * Test some versioned conditions too
1 parent acb8977 commit 221cf55

12 files changed

+1022
-18
lines changed
 

‎src/compiler/moduleNameResolver.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -2437,12 +2437,7 @@ namespace ts {
24372437
}
24382438
}
24392439

2440-
const { packageName, rest } = parsePackageName(moduleName);
24412440
const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => {
2442-
// package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them)
2443-
if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) {
2444-
return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value;
2445-
}
24462441
let pathAndExtension =
24472442
loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
24482443
loadNodeModuleFromDirectoryWorker(
@@ -2466,20 +2461,24 @@ namespace ts {
24662461
return withPackageId(packageInfo, pathAndExtension);
24672462
};
24682463

2469-
if (rest !== "") { // If "rest" is empty, we just did this search above.
2470-
const packageDirectory = combinePaths(nodeModulesDirectory, packageName);
2471-
2472-
// Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings.
2464+
const { packageName, rest } = parsePackageName(moduleName);
2465+
const packageDirectory = combinePaths(nodeModulesDirectory, packageName);
2466+
if (rest !== "") {
2467+
// Previous `packageInfo` may have been from a nested package.json; ensure we have the one from the package root now.
24732468
packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state);
2474-
if (packageInfo && packageInfo.contents.versionPaths) {
2475-
if (state.traceEnabled) {
2476-
trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, version, rest);
2477-
}
2478-
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host);
2479-
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state);
2480-
if (fromPaths) {
2481-
return fromPaths.value;
2482-
}
2469+
}
2470+
// package exports are higher priority than file/directory/typesVersions lookups and (and, if there's exports present, blocks them)
2471+
if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) {
2472+
return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value;
2473+
}
2474+
if (rest !== "" && packageInfo && packageInfo.contents.versionPaths) {
2475+
if (state.traceEnabled) {
2476+
trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.contents.versionPaths.version, version, rest);
2477+
}
2478+
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host);
2479+
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state);
2480+
if (fromPaths) {
2481+
return fromPaths.value;
24832482
}
24842483
}
24852484

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
2+
The file is in the program because:
3+
Root file specified for compilation
4+
/main.cts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
5+
If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
6+
/main.cts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
7+
/main.cts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
8+
/main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
9+
If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
10+
/main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
11+
/main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
12+
13+
14+
!!! error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
15+
!!! error TS6504: The file is in the program because:
16+
!!! error TS6504: Root file specified for compilation
17+
==== /node_modules/exports-and-types-versions/package.json (0 errors) ====
18+
{
19+
"name": "exports-and-types-versions",
20+
"version": "1.0.0",
21+
"exports": {
22+
"./foo": "./dist/foo.js",
23+
"./yep": {
24+
"types": "./types/foo.d.ts",
25+
"default": "./dist/foo.js"
26+
},
27+
"./versioned-yep": {
28+
"types@>=4": "./types/foo.d.ts"
29+
},
30+
"./versioned-nah": {
31+
"types@<4": "./types/foo.d.ts"
32+
}
33+
},
34+
"typesVersions": {
35+
"*": {
36+
"foo": ["./types/foo.d.ts"],
37+
"nope": ["./types/foo.d.ts"],
38+
"versioned-nah": ["./types/foo.d.ts"]
39+
}
40+
}
41+
}
42+
43+
==== /node_modules/exports-and-types-versions/dist/foo.js (0 errors) ====
44+
module.exports = {};
45+
46+
==== /node_modules/exports-and-types-versions/types/foo.d.ts (0 errors) ====
47+
export {};
48+
49+
==== /node_modules/just-types-versions/package.json (0 errors) ====
50+
{
51+
"name": "just-types-versions",
52+
"version": "1.0.0",
53+
"typesVersions": {
54+
"*": {
55+
"foo": ["./types/foo.d.ts"]
56+
}
57+
}
58+
}
59+
60+
==== /node_modules/just-types-versions/types/foo.d.ts (0 errors) ====
61+
export {};
62+
63+
==== /main.cts (3 errors) ====
64+
import {} from "exports-and-types-versions/foo";
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66+
!!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
67+
!!! error TS7016: If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
68+
import {} from "exports-and-types-versions/nope";
69+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+
!!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
71+
import {} from "exports-and-types-versions/yep";
72+
import {} from "exports-and-types-versions/versioned-yep";
73+
import {} from "exports-and-types-versions/versioned-nah";
74+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75+
!!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
76+
import {} from "just-types-versions/foo";
77+
78+
==== /main.mts (3 errors) ====
79+
import {} from "exports-and-types-versions/foo";
80+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81+
!!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
82+
!!! error TS7016: If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
83+
import {} from "exports-and-types-versions/nope";
84+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85+
!!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
86+
import {} from "exports-and-types-versions/yep";
87+
import {} from "exports-and-types-versions/versioned-yep";
88+
import {} from "exports-and-types-versions/versioned-nah";
89+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90+
!!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
91+
import {} from "just-types-versions/foo";
92+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//// [tests/cases/conformance/node/nodeModulesExportsBlocksTypesVersions.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "exports-and-types-versions",
6+
"version": "1.0.0",
7+
"exports": {
8+
"./foo": "./dist/foo.js",
9+
"./yep": {
10+
"types": "./types/foo.d.ts",
11+
"default": "./dist/foo.js"
12+
},
13+
"./versioned-yep": {
14+
"types@>=4": "./types/foo.d.ts"
15+
},
16+
"./versioned-nah": {
17+
"types@<4": "./types/foo.d.ts"
18+
}
19+
},
20+
"typesVersions": {
21+
"*": {
22+
"foo": ["./types/foo.d.ts"],
23+
"nope": ["./types/foo.d.ts"],
24+
"versioned-nah": ["./types/foo.d.ts"]
25+
}
26+
}
27+
}
28+
29+
//// [foo.js]
30+
module.exports = {};
31+
32+
//// [foo.d.ts]
33+
export {};
34+
35+
//// [package.json]
36+
{
37+
"name": "just-types-versions",
38+
"version": "1.0.0",
39+
"typesVersions": {
40+
"*": {
41+
"foo": ["./types/foo.d.ts"]
42+
}
43+
}
44+
}
45+
46+
//// [foo.d.ts]
47+
export {};
48+
49+
//// [main.cts]
50+
import {} from "exports-and-types-versions/foo";
51+
import {} from "exports-and-types-versions/nope";
52+
import {} from "exports-and-types-versions/yep";
53+
import {} from "exports-and-types-versions/versioned-yep";
54+
import {} from "exports-and-types-versions/versioned-nah";
55+
import {} from "just-types-versions/foo";
56+
57+
//// [main.mts]
58+
import {} from "exports-and-types-versions/foo";
59+
import {} from "exports-and-types-versions/nope";
60+
import {} from "exports-and-types-versions/yep";
61+
import {} from "exports-and-types-versions/versioned-yep";
62+
import {} from "exports-and-types-versions/versioned-nah";
63+
import {} from "just-types-versions/foo";
64+
65+
66+
//// [main.cjs]
67+
"use strict";
68+
Object.defineProperty(exports, "__esModule", { value: true });
69+
//// [main.mjs]
70+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== /node_modules/exports-and-types-versions/types/foo.d.ts ===
2+
export {};
3+
No type information for this code.
4+
No type information for this code.=== /node_modules/just-types-versions/types/foo.d.ts ===
5+
export {};
6+
No type information for this code.
7+
No type information for this code.=== /main.cts ===
8+
import {} from "exports-and-types-versions/foo";
9+
No type information for this code.import {} from "exports-and-types-versions/nope";
10+
No type information for this code.import {} from "exports-and-types-versions/yep";
11+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
12+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
13+
No type information for this code.import {} from "just-types-versions/foo";
14+
No type information for this code.
15+
No type information for this code.=== /main.mts ===
16+
import {} from "exports-and-types-versions/foo";
17+
No type information for this code.import {} from "exports-and-types-versions/nope";
18+
No type information for this code.import {} from "exports-and-types-versions/yep";
19+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
20+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
21+
No type information for this code.import {} from "just-types-versions/foo";
22+
No type information for this code.
23+
No type information for this code.

‎tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=node16).trace.json

+260
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== /node_modules/exports-and-types-versions/types/foo.d.ts ===
2+
export {};
3+
No type information for this code.
4+
No type information for this code.=== /node_modules/just-types-versions/types/foo.d.ts ===
5+
export {};
6+
No type information for this code.
7+
No type information for this code.=== /main.cts ===
8+
import {} from "exports-and-types-versions/foo";
9+
No type information for this code.import {} from "exports-and-types-versions/nope";
10+
No type information for this code.import {} from "exports-and-types-versions/yep";
11+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
12+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
13+
No type information for this code.import {} from "just-types-versions/foo";
14+
No type information for this code.
15+
No type information for this code.=== /main.mts ===
16+
import {} from "exports-and-types-versions/foo";
17+
No type information for this code.import {} from "exports-and-types-versions/nope";
18+
No type information for this code.import {} from "exports-and-types-versions/yep";
19+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
20+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
21+
No type information for this code.import {} from "just-types-versions/foo";
22+
No type information for this code.
23+
No type information for this code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
2+
The file is in the program because:
3+
Root file specified for compilation
4+
/main.cts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
5+
If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
6+
/main.cts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
7+
/main.cts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
8+
/main.mts(1,16): error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
9+
If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
10+
/main.mts(2,16): error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
11+
/main.mts(5,16): error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
12+
13+
14+
!!! error TS6504: File '/node_modules/exports-and-types-versions/dist/foo.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
15+
!!! error TS6504: The file is in the program because:
16+
!!! error TS6504: Root file specified for compilation
17+
==== /node_modules/exports-and-types-versions/package.json (0 errors) ====
18+
{
19+
"name": "exports-and-types-versions",
20+
"version": "1.0.0",
21+
"exports": {
22+
"./foo": "./dist/foo.js",
23+
"./yep": {
24+
"types": "./types/foo.d.ts",
25+
"default": "./dist/foo.js"
26+
},
27+
"./versioned-yep": {
28+
"types@>=4": "./types/foo.d.ts"
29+
},
30+
"./versioned-nah": {
31+
"types@<4": "./types/foo.d.ts"
32+
}
33+
},
34+
"typesVersions": {
35+
"*": {
36+
"foo": ["./types/foo.d.ts"],
37+
"nope": ["./types/foo.d.ts"],
38+
"versioned-nah": ["./types/foo.d.ts"]
39+
}
40+
}
41+
}
42+
43+
==== /node_modules/exports-and-types-versions/dist/foo.js (0 errors) ====
44+
module.exports = {};
45+
46+
==== /node_modules/exports-and-types-versions/types/foo.d.ts (0 errors) ====
47+
export {};
48+
49+
==== /node_modules/just-types-versions/package.json (0 errors) ====
50+
{
51+
"name": "just-types-versions",
52+
"version": "1.0.0",
53+
"typesVersions": {
54+
"*": {
55+
"foo": ["./types/foo.d.ts"]
56+
}
57+
}
58+
}
59+
60+
==== /node_modules/just-types-versions/types/foo.d.ts (0 errors) ====
61+
export {};
62+
63+
==== /main.cts (3 errors) ====
64+
import {} from "exports-and-types-versions/foo";
65+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
66+
!!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
67+
!!! error TS7016: If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
68+
import {} from "exports-and-types-versions/nope";
69+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70+
!!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
71+
import {} from "exports-and-types-versions/yep";
72+
import {} from "exports-and-types-versions/versioned-yep";
73+
import {} from "exports-and-types-versions/versioned-nah";
74+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75+
!!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
76+
import {} from "just-types-versions/foo";
77+
78+
==== /main.mts (3 errors) ====
79+
import {} from "exports-and-types-versions/foo";
80+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81+
!!! error TS7016: Could not find a declaration file for module 'exports-and-types-versions/foo'. '/node_modules/exports-and-types-versions/dist/foo.js' implicitly has an 'any' type.
82+
!!! error TS7016: If the 'exports-and-types-versions' package actually exposes this module, try adding a new declaration (.d.ts) file containing `declare module 'exports-and-types-versions/foo';`
83+
import {} from "exports-and-types-versions/nope";
84+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85+
!!! error TS2307: Cannot find module 'exports-and-types-versions/nope' or its corresponding type declarations.
86+
import {} from "exports-and-types-versions/yep";
87+
import {} from "exports-and-types-versions/versioned-yep";
88+
import {} from "exports-and-types-versions/versioned-nah";
89+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90+
!!! error TS2307: Cannot find module 'exports-and-types-versions/versioned-nah' or its corresponding type declarations.
91+
import {} from "just-types-versions/foo";
92+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//// [tests/cases/conformance/node/nodeModulesExportsBlocksTypesVersions.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "exports-and-types-versions",
6+
"version": "1.0.0",
7+
"exports": {
8+
"./foo": "./dist/foo.js",
9+
"./yep": {
10+
"types": "./types/foo.d.ts",
11+
"default": "./dist/foo.js"
12+
},
13+
"./versioned-yep": {
14+
"types@>=4": "./types/foo.d.ts"
15+
},
16+
"./versioned-nah": {
17+
"types@<4": "./types/foo.d.ts"
18+
}
19+
},
20+
"typesVersions": {
21+
"*": {
22+
"foo": ["./types/foo.d.ts"],
23+
"nope": ["./types/foo.d.ts"],
24+
"versioned-nah": ["./types/foo.d.ts"]
25+
}
26+
}
27+
}
28+
29+
//// [foo.js]
30+
module.exports = {};
31+
32+
//// [foo.d.ts]
33+
export {};
34+
35+
//// [package.json]
36+
{
37+
"name": "just-types-versions",
38+
"version": "1.0.0",
39+
"typesVersions": {
40+
"*": {
41+
"foo": ["./types/foo.d.ts"]
42+
}
43+
}
44+
}
45+
46+
//// [foo.d.ts]
47+
export {};
48+
49+
//// [main.cts]
50+
import {} from "exports-and-types-versions/foo";
51+
import {} from "exports-and-types-versions/nope";
52+
import {} from "exports-and-types-versions/yep";
53+
import {} from "exports-and-types-versions/versioned-yep";
54+
import {} from "exports-and-types-versions/versioned-nah";
55+
import {} from "just-types-versions/foo";
56+
57+
//// [main.mts]
58+
import {} from "exports-and-types-versions/foo";
59+
import {} from "exports-and-types-versions/nope";
60+
import {} from "exports-and-types-versions/yep";
61+
import {} from "exports-and-types-versions/versioned-yep";
62+
import {} from "exports-and-types-versions/versioned-nah";
63+
import {} from "just-types-versions/foo";
64+
65+
66+
//// [main.cjs]
67+
"use strict";
68+
Object.defineProperty(exports, "__esModule", { value: true });
69+
//// [main.mjs]
70+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== /node_modules/exports-and-types-versions/types/foo.d.ts ===
2+
export {};
3+
No type information for this code.
4+
No type information for this code.=== /node_modules/just-types-versions/types/foo.d.ts ===
5+
export {};
6+
No type information for this code.
7+
No type information for this code.=== /main.cts ===
8+
import {} from "exports-and-types-versions/foo";
9+
No type information for this code.import {} from "exports-and-types-versions/nope";
10+
No type information for this code.import {} from "exports-and-types-versions/yep";
11+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
12+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
13+
No type information for this code.import {} from "just-types-versions/foo";
14+
No type information for this code.
15+
No type information for this code.=== /main.mts ===
16+
import {} from "exports-and-types-versions/foo";
17+
No type information for this code.import {} from "exports-and-types-versions/nope";
18+
No type information for this code.import {} from "exports-and-types-versions/yep";
19+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
20+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
21+
No type information for this code.import {} from "just-types-versions/foo";
22+
No type information for this code.
23+
No type information for this code.

‎tests/baselines/reference/nodeModulesExportsBlocksTypesVersions(module=nodenext).trace.json

+264
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== /node_modules/exports-and-types-versions/types/foo.d.ts ===
2+
export {};
3+
No type information for this code.
4+
No type information for this code.=== /node_modules/just-types-versions/types/foo.d.ts ===
5+
export {};
6+
No type information for this code.
7+
No type information for this code.=== /main.cts ===
8+
import {} from "exports-and-types-versions/foo";
9+
No type information for this code.import {} from "exports-and-types-versions/nope";
10+
No type information for this code.import {} from "exports-and-types-versions/yep";
11+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
12+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
13+
No type information for this code.import {} from "just-types-versions/foo";
14+
No type information for this code.
15+
No type information for this code.=== /main.mts ===
16+
import {} from "exports-and-types-versions/foo";
17+
No type information for this code.import {} from "exports-and-types-versions/nope";
18+
No type information for this code.import {} from "exports-and-types-versions/yep";
19+
No type information for this code.import {} from "exports-and-types-versions/versioned-yep";
20+
No type information for this code.import {} from "exports-and-types-versions/versioned-nah";
21+
No type information for this code.import {} from "just-types-versions/foo";
22+
No type information for this code.
23+
No type information for this code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// @module: node16,nodenext
2+
// @traceResolution: true
3+
// @noImplicitAny: true
4+
5+
// @Filename: /node_modules/exports-and-types-versions/package.json
6+
{
7+
"name": "exports-and-types-versions",
8+
"version": "1.0.0",
9+
"exports": {
10+
"./foo": "./dist/foo.js",
11+
"./yep": {
12+
"types": "./types/foo.d.ts",
13+
"default": "./dist/foo.js"
14+
},
15+
"./versioned-yep": {
16+
"types@>=4": "./types/foo.d.ts"
17+
},
18+
"./versioned-nah": {
19+
"types@<4": "./types/foo.d.ts"
20+
}
21+
},
22+
"typesVersions": {
23+
"*": {
24+
"foo": ["./types/foo.d.ts"],
25+
"nope": ["./types/foo.d.ts"],
26+
"versioned-nah": ["./types/foo.d.ts"]
27+
}
28+
}
29+
}
30+
31+
// @Filename: /node_modules/exports-and-types-versions/dist/foo.js
32+
module.exports = {};
33+
34+
// @Filename: /node_modules/exports-and-types-versions/types/foo.d.ts
35+
export {};
36+
37+
// @Filename: /node_modules/just-types-versions/package.json
38+
{
39+
"name": "just-types-versions",
40+
"version": "1.0.0",
41+
"typesVersions": {
42+
"*": {
43+
"foo": ["./types/foo.d.ts"]
44+
}
45+
}
46+
}
47+
48+
// @Filename: /node_modules/just-types-versions/types/foo.d.ts
49+
export {};
50+
51+
// @Filename: /main.cts
52+
import {} from "exports-and-types-versions/foo";
53+
import {} from "exports-and-types-versions/nope";
54+
import {} from "exports-and-types-versions/yep";
55+
import {} from "exports-and-types-versions/versioned-yep";
56+
import {} from "exports-and-types-versions/versioned-nah";
57+
import {} from "just-types-versions/foo";
58+
59+
// @Filename: /main.mts
60+
import {} from "exports-and-types-versions/foo";
61+
import {} from "exports-and-types-versions/nope";
62+
import {} from "exports-and-types-versions/yep";
63+
import {} from "exports-and-types-versions/versioned-yep";
64+
import {} from "exports-and-types-versions/versioned-nah";
65+
import {} from "just-types-versions/foo";

0 commit comments

Comments
 (0)
Please sign in to comment.