-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Resolve using package json's "main" field when resolving typescript extensions #24112
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
7be8595
Add test for module resolution with package json containing main fiel…
sheetalkamat 22d5b0e
Do not remove extension js or jsx from the subModuleName if the subMo…
sheetalkamat dc50fe5
Apart from typing, use main field in package json to resolve typescri…
sheetalkamat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...elines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//// [tests/cases/compiler/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.ts] //// | ||
|
||
//// [package.json] | ||
{ "name": "foo", "version": "1.2.3", "main": "src/index.js" } | ||
|
||
//// [index.d.ts] | ||
export const x: number; | ||
|
||
//// [index.ts] | ||
import { x } from "foo"; | ||
|
||
|
||
//// [index.js] | ||
"use strict"; | ||
exports.__esModule = true; |
8 changes: 8 additions & 0 deletions
8
...s/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== /node_modules/foo/src/index.d.ts === | ||
export const x: number; | ||
>x : Symbol(x, Decl(index.d.ts, 0, 12)) | ||
|
||
=== /index.ts === | ||
import { x } from "foo"; | ||
>x : Symbol(x, Decl(index.ts, 0, 8)) | ||
|
26 changes: 26 additions & 0 deletions
26
...eference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
"======== Resolving module 'foo' from '/index.ts'. ========", | ||
"Module resolution kind is not specified, using 'NodeJs'.", | ||
"Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", | ||
"'package.json' does not have a 'typings' field.", | ||
"'package.json' does not have a 'types' field.", | ||
"'package.json' has 'main' field 'src/index.js' that references '/node_modules/foo/src/index.js'.", | ||
"Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/src/[email protected]'.", | ||
"File '/node_modules/foo.ts' does not exist.", | ||
"File '/node_modules/foo.tsx' does not exist.", | ||
"File '/node_modules/foo.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 'src/index.js' that references '/node_modules/foo/src/index.js'.", | ||
"File '/node_modules/foo/src/index.js' does not exist.", | ||
"Loading module as file / folder, candidate module location '/node_modules/foo/src/index.js', target file type 'TypeScript'.", | ||
"File '/node_modules/foo/src/index.js.ts' does not exist.", | ||
"File '/node_modules/foo/src/index.js.tsx' does not exist.", | ||
"File '/node_modules/foo/src/index.js.d.ts' does not exist.", | ||
"File name '/node_modules/foo/src/index.js' has a '.js' extension - stripping it.", | ||
"File '/node_modules/foo/src/index.ts' does not exist.", | ||
"File '/node_modules/foo/src/index.tsx' does not exist.", | ||
"File '/node_modules/foo/src/index.d.ts' exist - use it as a name resolution result.", | ||
"Resolving real path for '/node_modules/foo/src/index.d.ts', result '/node_modules/foo/src/index.d.ts'.", | ||
"======== Module name 'foo' was successfully resolved to '/node_modules/foo/src/index.d.ts'. ========" | ||
] |
8 changes: 8 additions & 0 deletions
8
...nes/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== /node_modules/foo/src/index.d.ts === | ||
export const x: number; | ||
>x : number | ||
|
||
=== /index.ts === | ||
import { x } from "foo"; | ||
>x : number | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...s/cases/compiler/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @traceResolution: true | ||
|
||
// @Filename: /node_modules/foo/package.json | ||
{ "name": "foo", "version": "1.2.3", "main": "src/index.js" } | ||
|
||
// @Filename: /node_modules/foo/src/index.d.ts | ||
export const x: number; | ||
|
||
// @Filename: /index.ts | ||
import { x } from "foo"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: might just modify
tryReadPackageJsonFields
to take separatereadTypes
andreadMain
parameters, if we might want both at once.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most both cases different conditions determine if we read main types so i would rather leave it as is.