Skip to content

--moduleResolution hybrid #2

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
86dd5da
Add options
andrewbranch Oct 20, 2022
8846f31
Add customConditions option
andrewbranch Oct 21, 2022
9bc0f07
Add first tests
andrewbranch Oct 24, 2022
4545afb
CJS constructs are not allowed
andrewbranch Oct 24, 2022
e82e61d
Add another test
andrewbranch Oct 24, 2022
038783d
Fix extension adding/replacing priority
andrewbranch Oct 25, 2022
870d807
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 8, 2022
a482180
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 15, 2022
89bcd01
Update test to reflect the choice not to block on unrecognized extens…
andrewbranch Nov 16, 2022
6074661
Add auto-imports and string completions tests
andrewbranch Nov 17, 2022
9e03db2
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 18, 2022
c4320a2
Comment test
andrewbranch Nov 18, 2022
f04f1b5
Auto-imports of declaration files cannot use .ts extension
andrewbranch Nov 18, 2022
29039de
Have declaration file auto imports default to extensionless instead
andrewbranch Nov 18, 2022
e83ca2a
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 18, 2022
f98730a
Add test for custom conditions
andrewbranch Nov 18, 2022
5a01dd6
Fix indentation
andrewbranch Nov 18, 2022
4dd6d01
Add baseline showing resolvePackageJsonImports/Exports compatibility
andrewbranch Nov 18, 2022
81b9e70
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Nov 28, 2022
f6fa5f3
Fix test and prevent CJS require from resolving
andrewbranch Nov 28, 2022
aeb23be
Update unit test baselines
andrewbranch Nov 28, 2022
e0c0375
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 5, 2022
f9414aa
Fix bad merge conflict resolution
andrewbranch Dec 5, 2022
dadc1a8
Make resolvedUsingTsExtension optional
andrewbranch Dec 5, 2022
5089aab
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 5, 2022
a88b8ad
Update missed baselines
andrewbranch Dec 6, 2022
224bb10
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 6, 2022
b2e283c
Revert now-unnecessary API implementation changes
andrewbranch Dec 6, 2022
30afa86
Clean up
andrewbranch Dec 9, 2022
0baca5b
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 9, 2022
6e763d9
Update baselines to es5 emit
andrewbranch Dec 9, 2022
22fbb44
Merge branch 'module-resolution/ts-extensions' into module-resolution…
andrewbranch Dec 13, 2022
d4a3b3c
Rename to `bundler`
andrewbranch Dec 13, 2022
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
Prev Previous commit
Next Next commit
Add test for custom conditions
  • Loading branch information
andrewbranch committed Nov 18, 2022
commit f98730abf6c94327ea86e9e68fad17a16b1aa878
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,7 @@ export function hybridModuleNameResolver(moduleName: string, containingFile: str
if (getResolveJsonModule(compilerOptions)) {
extensions |= Extensions.Json;
}
return nodeModuleNameResolverWorker(NodeResolutionFeatures.HybridDefault, moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference);
return nodeModuleNameResolverWorker(getNodeResolutionFeatures(compilerOptions), moduleName, containingDirectory, compilerOptions, host, cache, extensions, /*isConfigLookup*/ false, redirectedReference);
}

export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache, redirectedReference?: ResolvedProjectReference): ResolvedModuleWithFailedLookupLocations;
Expand Down
2 changes: 2 additions & 0 deletions src/testRunner/compilerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class CompilerTest {
"useUnknownInCatchVariables",
"noUncheckedIndexedAccess",
"noPropertyAccessFromIndexSignature",
"resolvePackageJsonExports",
"resolvePackageJsonImports",
];
private fileName: string;
private justName: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/conformance/moduleResolution/customConditions.ts] ////

//// [package.json]
{
"name": "lodash",
"version": "1.0.0",
"main": "index.js",
"exports": {
"browser": "./browser.js",
"webpack": "./webpack.js",
"default": "./index.js"
}
}

//// [index.d.ts]
declare const _: "index";
export = _;

//// [browser.d.ts]
declare const _: "browser";
export default _;

//// [webpack.d.ts]
declare const _: "webpack";
export = _;

//// [index.ts]
import _ from "lodash";


//// [index.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== /node_modules/lodash/index.d.ts ===
declare const _: "index";
>_ : Symbol(_, Decl(index.d.ts, 0, 13))

export = _;
>_ : Symbol(_, Decl(index.d.ts, 0, 13))

=== /node_modules/lodash/browser.d.ts ===
declare const _: "browser";
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))

export default _;
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))

=== /node_modules/lodash/webpack.d.ts ===
declare const _: "webpack";
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))

export = _;
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))

=== /index.ts ===
import _ from "lodash";
>_ : Symbol(_, Decl(index.ts, 0, 6))

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
"======== Resolving module 'lodash' from '/index.ts'. ========",
"Explicitly specified module resolution kind: 'Hybrid'.",
"File '/package.json' does not exist.",
"Loading module 'lodash' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.",
"Found 'package.json' at '/node_modules/lodash/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"File '/node_modules/lodash.ts' does not exist.",
"File '/node_modules/lodash.tsx' does not exist.",
"File '/node_modules/lodash.d.ts' does not exist.",
"'package.json' does not have a 'typings' field.",
"'package.json' does not have a 'types' field.",
"'package.json' has 'main' field 'index.js' that references '/node_modules/lodash/index.js'.",
"File '/node_modules/lodash/index.js' does not exist.",
"Loading module as file / folder, candidate module location '/node_modules/lodash/index.js', target file types: TypeScript, Declaration.",
"File name '/node_modules/lodash/index.js' has a '.js' extension - stripping it.",
"File '/node_modules/lodash/index.ts' does not exist.",
"File '/node_modules/lodash/index.tsx' does not exist.",
"File '/node_modules/lodash/index.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/lodash/index.d.ts', result '/node_modules/lodash/index.d.ts'.",
"======== Module name 'lodash' was successfully resolved to '/node_modules/lodash/index.d.ts' with Package ID 'lodash/index.d.ts@1.0.0'. ========"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== /node_modules/lodash/index.d.ts ===
declare const _: "index";
>_ : "index"

export = _;
>_ : "index"

=== /node_modules/lodash/browser.d.ts ===
declare const _: "browser";
>_ : "browser"

export default _;
>_ : "browser"

=== /node_modules/lodash/webpack.d.ts ===
declare const _: "webpack";
>_ : "webpack"

export = _;
>_ : "webpack"

=== /index.ts ===
import _ from "lodash";
>_ : "index"

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/conformance/moduleResolution/customConditions.ts] ////

//// [package.json]
{
"name": "lodash",
"version": "1.0.0",
"main": "index.js",
"exports": {
"browser": "./browser.js",
"webpack": "./webpack.js",
"default": "./index.js"
}
}

//// [index.d.ts]
declare const _: "index";
export = _;

//// [browser.d.ts]
declare const _: "browser";
export default _;

//// [webpack.d.ts]
declare const _: "webpack";
export = _;

//// [index.ts]
import _ from "lodash";


//// [index.js]
"use strict";
exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== /node_modules/lodash/index.d.ts ===
declare const _: "index";
>_ : Symbol(_, Decl(index.d.ts, 0, 13))

export = _;
>_ : Symbol(_, Decl(index.d.ts, 0, 13))

=== /node_modules/lodash/browser.d.ts ===
declare const _: "browser";
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))

export default _;
>_ : Symbol(_, Decl(browser.d.ts, 0, 13))

=== /node_modules/lodash/webpack.d.ts ===
declare const _: "webpack";
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))

export = _;
>_ : Symbol(_, Decl(webpack.d.ts, 0, 13))

=== /index.ts ===
import _ from "lodash";
>_ : Symbol(_, Decl(index.ts, 0, 6))

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
"======== Resolving module 'lodash' from '/index.ts'. ========",
"Explicitly specified module resolution kind: 'Hybrid'.",
"File '/package.json' does not exist.",
"Loading module 'lodash' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.",
"Found 'package.json' at '/node_modules/lodash/package.json'.",
"'package.json' does not have a 'typesVersions' field.",
"Saw non-matching condition 'browser'.",
"Matched 'exports' condition 'webpack'.",
"Using 'exports' subpath '.' with target './webpack.js'.",
"File name '/node_modules/lodash/webpack.js' has a '.js' extension - stripping it.",
"File '/node_modules/lodash/webpack.ts' does not exist.",
"File '/node_modules/lodash/webpack.tsx' does not exist.",
"File '/node_modules/lodash/webpack.d.ts' exist - use it as a name resolution result.",
"Resolving real path for '/node_modules/lodash/webpack.d.ts', result '/node_modules/lodash/webpack.d.ts'.",
"======== Module name 'lodash' was successfully resolved to '/node_modules/lodash/webpack.d.ts' with Package ID 'lodash/webpack.d.ts@1.0.0'. ========"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== /node_modules/lodash/index.d.ts ===
declare const _: "index";
>_ : "index"

export = _;
>_ : "index"

=== /node_modules/lodash/browser.d.ts ===
declare const _: "browser";
>_ : "browser"

export default _;
>_ : "browser"

=== /node_modules/lodash/webpack.d.ts ===
declare const _: "webpack";
>_ : "webpack"

export = _;
>_ : "webpack"

=== /index.ts ===
import _ from "lodash";
>_ : "webpack"

31 changes: 31 additions & 0 deletions tests/cases/conformance/moduleResolution/customConditions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @moduleResolution: hybrid
// @customConditions: webpack, browser
// @resolvePackageJsonExports: true, false
// @traceResolution: true

// @Filename: /node_modules/lodash/package.json
{
"name": "lodash",
"version": "1.0.0",
"main": "index.js",
"exports": {
"browser": "./browser.js",
"webpack": "./webpack.js",
"default": "./index.js"
}
}

// @Filename: /node_modules/lodash/index.d.ts
declare const _: "index";
export = _;

// @Filename: /node_modules/lodash/browser.d.ts
declare const _: "browser";
export default _;

// @Filename: /node_modules/lodash/webpack.d.ts
declare const _: "webpack";
export = _;

// @Filename: /index.ts
import _ from "lodash";