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

Fix type reference directive resolution #936

Merged
merged 2 commits into from May 18, 2019

Conversation

andrewbranch
Copy link
Contributor

Fixes #934
Fixes #919

There was really no way to know this without debugging, but getting default typeRoots for a project doesn't work if the module resolution host doesn't implement getCurrentDirectory(). Arguably the language service API shouldn’t treat it as optional, or should emit a warning if it’s missing, or fall back to the default from ts.sys (maybe I'll bring this up to Sheetal, but it certainly wouldn't land until 3.6), but I think a good policy for ts-loader would be to implement all members of any kind of Host, especially if it’s as easy a just including things from ts.sys. It is kind of misleading because there are other places (I think CompilerHost is an example) where missing optional members get filled in with good defaults.

resolveTypeReferenceDirective(
directive,
containingFile,
_redirectedReference
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't related to the particular repro provided, but it seemed like a place that might be broken for even edgier edge cases

@@ -512,16 +518,17 @@ function makeResolveTypeReferenceDirective(
| undefined
): ResolveTypeReferenceDirective {
if (customResolveTypeReferenceDirective === undefined) {
return (directive: string, containingFile: string) =>
return (directive, containingFile, redirectedReference) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Contextual parameter types FTW 😄

@johnnyreilly
Copy link
Member

Heya @andrewbranch!

thanks for this! Will take a look now

directoryExists: compiler.sys.directoryExists
directoryExists: compiler.sys.directoryExists,
getCurrentDirectory: compiler.sys.getCurrentDirectory,
getDirectories: compiler.sys.getDirectories
};
Copy link
Member

Choose a reason for hiding this comment

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

So if I understand this correctly, the fix is the implementation of these:

    directoryExists: compiler.sys.directoryExists,
    getCurrentDirectory: compiler.sys.getCurrentDirectory,
    getDirectories: compiler.sys.getDirectories

?

That's interesting. I wish it was more "fail fast" here if it actually needed these...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, specifically getCurrentDirectory. I agree. I'll suggest something like this to the team.

@johnnyreilly
Copy link
Member

johnnyreilly commented May 18, 2019

Arguably the language service API shouldn’t treat it as optional, or should emit a warning if it’s missing, or fall back to the default from ts.sys

This is very interesting. Completely agree

but I think a good policy for ts-loader would be to implement all members of any kind of Host, especially if it’s as easy a just including things from ts.sys. It is kind of misleading because there are other places (I think CompilerHost is an example) where missing optional members get filled in with good defaults.

Yeah - agree!

Could you update the package.json and the CHANGELOG.md please? Then once we've got passing tests I can ship a release without further ado! Since this is a bugfix I guess this takes us to 6.0.1 😄

@andrewbranch
Copy link
Contributor Author

Done 👍

@andrewbranch
Copy link
Contributor Author

Hold on the release, I've got another fix coming

@andrewbranch
Copy link
Contributor Author

I'm going to mercifully let CI off the hook of finishing testing my updates to the CHANGELOG—save some electricity, you know

@andrewbranch andrewbranch merged commit 0399864 into TypeStrong:master May 18, 2019
@andrewbranch andrewbranch deleted the bug/module-resolution branch May 23, 2019 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants