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

resolveModuleNames doesn't get `host` & `options` #31056

Open
arcanis opened this issue Apr 22, 2019 · 3 comments

Comments

Projects
None yet
4 participants
@arcanis
Copy link

commented Apr 22, 2019

TypeScript Version: master

Search Terms: resolveModuleNames resolveTypeReferenceDirectives

Actual behavior:

The resolveModuleNames hook (and its sister resolveTypeReferenceDirectives) don't get direct access to the options and resolutionHost value. It's left to the user to populate them (as shown in the documentation).

While it worked ok until now since the options are known before injecting the hook, it now causes issues with the Watch API. In this situation, the options are extracted by the internals of createWatchProgram and we don't get to access them.

We theoretically could retrieve them from watchProgram.getProgram().getCompilerOptions(), except that it requires to have the watchProgram object to begin with ... which doesn't happen until createWatchProgram returns, by which point TS will already have tried and failed the initial compilation.

Expected behavior:

The options parameter (and arguably the resolutionHost as well) should be passed as parameter to the custom resolveModuleNames and resolveTypeReferenceDirective functions. This would allow to call ts.resolveModuleName without relying on indirect sources.

Related Issues:

Realytics/fork-ts-checker-webpack-plugin#258 (comment)

@sheetalkamat

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

Seems to me we need getCompilerOptions on WatchOfConfigFile<T> so one can get compiler options without having to get program. I don't think we should change resolveModuleNames and resolveTypeReferenceDirectives api as those are intentionally similar to CompilerHost api methods

@DanielRosenwasser

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

@arcanis any interest in sending a PR? Should be relatively scoped.

@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.6.0 milestone Apr 29, 2019

@arcanis

This comment has been minimized.

Copy link
Author

commented Apr 30, 2019

Seems to me we need getCompilerOptions on WatchOfConfigFile<T> so one can get compiler options without having to get program.

I don't think that would work for the same reason: we don't get access to WatchOfConfigFile<T> until after createWatchProgram returns, by which point TS will have already run (and thus failed) the initial compilation.

@arcanis any interest in sending a PR? Should be relatively scoped.

If we agree on the fix I can take a look late May unless someone beats me to it 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.