Skip to content
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 3 commits into from
May 15, 2018

Conversation

sheetalkamat
Copy link
Member

Before this change we would use "typings" | "types" entry when resolving typescript extension and "main" field when resolving js extensions. Thus the package json having no typings field and main pointing to anything in subdirectory would never be resolved as relative file path. With this change, we would use main field to relatively resolve the typescript files, thus trying to find .d.ts file corresponding to the main js file
Fixes #23502

@mhegazy mhegazy requested a review from a user May 15, 2018 20:21
@mhegazy
Copy link
Contributor

mhegazy commented May 15, 2018

@andy-ms can you please review.

@@ -1047,9 +1049,18 @@ namespace ts {
}

function loadModuleFromPackageJson(jsonContent: PackageJsonPathFields, extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): PathAndExtension | undefined {
const file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript && extensions !== Extensions.Json, jsonContent, candidate, state);
let file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript && extensions !== Extensions.Json, jsonContent, candidate, state);
Copy link

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 separate readTypes and readMain parameters, if we might want both at once.

Copy link
Member Author

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.

@sheetalkamat sheetalkamat merged commit 77168e5 into master May 15, 2018
@sheetalkamat sheetalkamat deleted the packageJsonWithMainInSubDirectory branch May 15, 2018 21:18
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript Language service not finding symbolic linked (junction) npm module
2 participants