Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Sep 25, 2018

Partial fix for #27302

Doesn't completely fix the issue since the newly installed ATA @types package doesn't replace the resolution of the local JS package, even though it should (since that's what happens when you reload the editor).

@ghost ghost requested a review from sheetalkamat September 25, 2018 21:31
if (file.resolvedModules) {
file.resolvedModules.forEach((resolvedModule, name) => {
// pick unresolved non-relative names
if ((!resolvedModule || !extensionIsTS(resolvedModule.extension)) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also ignore json resolution ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would come up, because this code will only apply to non-relative imports, and we only resolve to .json for relative imports with an explicit .json extension, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no we resolve any json resolution with ".json" extension

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get a global import to ever resolve to a '.json' file -- if I import "foo", it looks in node_modules/foo/index.ts, .tsx, .d.ts, .js, and .jsx, but not .json. If I import "foo.json" that looks for node_modules/foo.json/index.ts etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will resolve to "node_modules/foo/index.json" when you import "foo.json" or import of "foo/lib.json" will resolve to "node_modules/foo/lib.json"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK, "foo/lib.json" can import a json module. Shouldn't we still look for a type definition for the package though?

@sheetalkamat
Copy link
Member

For the other part you also want to fix resolveNamesWithLocalCache in resolutionCache.ts where we check hasInvalidatedNonRelativeUnresolvedImport && just absence of resolution

@ghost
Copy link
Author

ghost commented Sep 26, 2018

@sheetalkamat Good to merge this first part?

@sheetalkamat
Copy link
Member

I would have you do other part right here since these both changes are related and better to be handled in one change.

return primaryResult;
}
=======
function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, redirectedReference?: ResolvedProjectReference): CachedResolvedModuleWithFailedLookupLocations {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix the merge conflict

@sheetalkamat
Copy link
Member

Where are the other changes in the project?

@ghost
Copy link
Author

ghost commented Oct 29, 2018

A lot of changes were moved to #28092 which we might want to merge first.

@sheetalkamat
Copy link
Member

I don't think we should merge this. This change needs to be separate and need to handle the ATA change in project and resolution cache.

@ghost
Copy link
Author

ghost commented Oct 30, 2018

Here's what I used to reproduce the issue:

  • Delete the types cache (On my computer, this means going to ~/.cache/typescript and rm -r 3.2)
  • Create an empty test folder
  • npm install abs
  • Create a file a.js containing const abs = require("abs");
  • Go-to-definition will continue taking you to node_modules/abs/index.js no matter how long you wait. But restarting fixes this.

But in this branch:

  • Have to rm -r 3.2 before every test!
  • At first, clicking on abs takes you to node_modules/abs/index.js.
  • But after a few seconds, it takes you to @types/abs/index.d.ts from the typings cache. No restart needed.

@ghost
Copy link
Author

ghost commented Oct 30, 2018

Closing in favor of #28236, which doesn't require us to have watchers on the typesCache, which is redundant since typingsInstaller should handle that anyway. (Thanks @sheetalkamat for pointing that out.)

@ghost ghost closed this Oct 30, 2018
@ghost ghost deleted the importATA branch October 30, 2018 18:51
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

This pull request was closed.
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.

2 participants