Skip to content

Commit f98730a

Browse files
committed
Add test for custom conditions
1 parent e83ca2a commit f98730a

11 files changed

+239
-1
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ export function hybridModuleNameResolver(moduleName: string, containingFile: str
15241524
if (getResolveJsonModule(compilerOptions)) {
15251525
extensions |= Extensions.Json;
15261526
}
1527-
return nodeModuleNameResolverWorker(NodeResolutionFeatures.HybridDefault, moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference);
1527+
return nodeModuleNameResolverWorker(getNodeResolutionFeatures(compilerOptions), moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference);
15281528
}
15291529

15301530
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;

src/testRunner/compilerRunner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class CompilerTest {
163163
"useUnknownInCatchVariables",
164164
"noUncheckedIndexedAccess",
165165
"noPropertyAccessFromIndexSignature",
166+
"resolvePackageJsonExports",
167+
"resolvePackageJsonImports",
166168
];
167169
private fileName: string;
168170
private justName: string;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tests/cases/conformance/moduleResolution/customConditions.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "lodash",
6+
"version": "1.0.0",
7+
"main": "index.js",
8+
"exports": {
9+
"browser": "./browser.js",
10+
"webpack": "./webpack.js",
11+
"default": "./index.js"
12+
}
13+
}
14+
15+
//// [index.d.ts]
16+
declare const _: "index";
17+
export = _;
18+
19+
//// [browser.d.ts]
20+
declare const _: "browser";
21+
export default _;
22+
23+
//// [webpack.d.ts]
24+
declare const _: "webpack";
25+
export = _;
26+
27+
//// [index.ts]
28+
import _ from "lodash";
29+
30+
31+
//// [index.js]
32+
"use strict";
33+
exports.__esModule = true;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== /node_modules/lodash/index.d.ts ===
2+
declare const _: "index";
3+
>_ : Symbol(_, Decl(index.d.ts, 0, 13))
4+
5+
export = _;
6+
>_ : Symbol(_, Decl(index.d.ts, 0, 13))
7+
8+
=== /node_modules/lodash/browser.d.ts ===
9+
declare const _: "browser";
10+
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))
11+
12+
export default _;
13+
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))
14+
15+
=== /node_modules/lodash/webpack.d.ts ===
16+
declare const _: "webpack";
17+
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))
18+
19+
export = _;
20+
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))
21+
22+
=== /index.ts ===
23+
import _ from "lodash";
24+
>_ : Symbol(_, Decl(index.ts, 0, 6))
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
"======== Resolving module 'lodash' from '/index.ts'. ========",
3+
"Explicitly specified module resolution kind: 'Hybrid'.",
4+
"File '/package.json' does not exist.",
5+
"Loading module 'lodash' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.",
6+
"Found 'package.json' at '/node_modules/lodash/package.json'.",
7+
"'package.json' does not have a 'typesVersions' field.",
8+
"File '/node_modules/lodash.ts' does not exist.",
9+
"File '/node_modules/lodash.tsx' does not exist.",
10+
"File '/node_modules/lodash.d.ts' does not exist.",
11+
"'package.json' does not have a 'typings' field.",
12+
"'package.json' does not have a 'types' field.",
13+
"'package.json' has 'main' field 'index.js' that references '/node_modules/lodash/index.js'.",
14+
"File '/node_modules/lodash/index.js' does not exist.",
15+
"Loading module as file / folder, candidate module location '/node_modules/lodash/index.js', target file types: TypeScript, Declaration.",
16+
"File name '/node_modules/lodash/index.js' has a '.js' extension - stripping it.",
17+
"File '/node_modules/lodash/index.ts' does not exist.",
18+
"File '/node_modules/lodash/index.tsx' does not exist.",
19+
"File '/node_modules/lodash/index.d.ts' exist - use it as a name resolution result.",
20+
"Resolving real path for '/node_modules/lodash/index.d.ts', result '/node_modules/lodash/index.d.ts'.",
21+
"======== Module name 'lodash' was successfully resolved to '/node_modules/lodash/index.d.ts' with Package ID 'lodash/index.d.ts@1.0.0'. ========"
22+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== /node_modules/lodash/index.d.ts ===
2+
declare const _: "index";
3+
>_ : "index"
4+
5+
export = _;
6+
>_ : "index"
7+
8+
=== /node_modules/lodash/browser.d.ts ===
9+
declare const _: "browser";
10+
>_ : "browser"
11+
12+
export default _;
13+
>_ : "browser"
14+
15+
=== /node_modules/lodash/webpack.d.ts ===
16+
declare const _: "webpack";
17+
>_ : "webpack"
18+
19+
export = _;
20+
>_ : "webpack"
21+
22+
=== /index.ts ===
23+
import _ from "lodash";
24+
>_ : "index"
25+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tests/cases/conformance/moduleResolution/customConditions.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "lodash",
6+
"version": "1.0.0",
7+
"main": "index.js",
8+
"exports": {
9+
"browser": "./browser.js",
10+
"webpack": "./webpack.js",
11+
"default": "./index.js"
12+
}
13+
}
14+
15+
//// [index.d.ts]
16+
declare const _: "index";
17+
export = _;
18+
19+
//// [browser.d.ts]
20+
declare const _: "browser";
21+
export default _;
22+
23+
//// [webpack.d.ts]
24+
declare const _: "webpack";
25+
export = _;
26+
27+
//// [index.ts]
28+
import _ from "lodash";
29+
30+
31+
//// [index.js]
32+
"use strict";
33+
exports.__esModule = true;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== /node_modules/lodash/index.d.ts ===
2+
declare const _: "index";
3+
>_ : Symbol(_, Decl(index.d.ts, 0, 13))
4+
5+
export = _;
6+
>_ : Symbol(_, Decl(index.d.ts, 0, 13))
7+
8+
=== /node_modules/lodash/browser.d.ts ===
9+
declare const _: "browser";
10+
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))
11+
12+
export default _;
13+
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))
14+
15+
=== /node_modules/lodash/webpack.d.ts ===
16+
declare const _: "webpack";
17+
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))
18+
19+
export = _;
20+
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))
21+
22+
=== /index.ts ===
23+
import _ from "lodash";
24+
>_ : Symbol(_, Decl(index.ts, 0, 6))
25+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
"======== Resolving module 'lodash' from '/index.ts'. ========",
3+
"Explicitly specified module resolution kind: 'Hybrid'.",
4+
"File '/package.json' does not exist.",
5+
"Loading module 'lodash' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.",
6+
"Found 'package.json' at '/node_modules/lodash/package.json'.",
7+
"'package.json' does not have a 'typesVersions' field.",
8+
"Saw non-matching condition 'browser'.",
9+
"Matched 'exports' condition 'webpack'.",
10+
"Using 'exports' subpath '.' with target './webpack.js'.",
11+
"File name '/node_modules/lodash/webpack.js' has a '.js' extension - stripping it.",
12+
"File '/node_modules/lodash/webpack.ts' does not exist.",
13+
"File '/node_modules/lodash/webpack.tsx' does not exist.",
14+
"File '/node_modules/lodash/webpack.d.ts' exist - use it as a name resolution result.",
15+
"Resolving real path for '/node_modules/lodash/webpack.d.ts', result '/node_modules/lodash/webpack.d.ts'.",
16+
"======== Module name 'lodash' was successfully resolved to '/node_modules/lodash/webpack.d.ts' with Package ID 'lodash/webpack.d.ts@1.0.0'. ========"
17+
]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== /node_modules/lodash/index.d.ts ===
2+
declare const _: "index";
3+
>_ : "index"
4+
5+
export = _;
6+
>_ : "index"
7+
8+
=== /node_modules/lodash/browser.d.ts ===
9+
declare const _: "browser";
10+
>_ : "browser"
11+
12+
export default _;
13+
>_ : "browser"
14+
15+
=== /node_modules/lodash/webpack.d.ts ===
16+
declare const _: "webpack";
17+
>_ : "webpack"
18+
19+
export = _;
20+
>_ : "webpack"
21+
22+
=== /index.ts ===
23+
import _ from "lodash";
24+
>_ : "webpack"
25+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// @moduleResolution: hybrid
2+
// @customConditions: webpack, browser
3+
// @resolvePackageJsonExports: true, false
4+
// @traceResolution: true
5+
6+
// @Filename: /node_modules/lodash/package.json
7+
{
8+
"name": "lodash",
9+
"version": "1.0.0",
10+
"main": "index.js",
11+
"exports": {
12+
"browser": "./browser.js",
13+
"webpack": "./webpack.js",
14+
"default": "./index.js"
15+
}
16+
}
17+
18+
// @Filename: /node_modules/lodash/index.d.ts
19+
declare const _: "index";
20+
export = _;
21+
22+
// @Filename: /node_modules/lodash/browser.d.ts
23+
declare const _: "browser";
24+
export default _;
25+
26+
// @Filename: /node_modules/lodash/webpack.d.ts
27+
declare const _: "webpack";
28+
export = _;
29+
30+
// @Filename: /index.ts
31+
import _ from "lodash";

0 commit comments

Comments
 (0)