Skip to content

resolveModuleNames doesn't get host & options #31056

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

Closed
arcanis opened this issue Apr 22, 2019 · 4 comments · Fixed by #32641
Closed

resolveModuleNames doesn't get host & options #31056

arcanis opened this issue Apr 22, 2019 · 4 comments · Fixed by #32641
Assignees
Labels
API Relates to the public API for TypeScript Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@arcanis
Copy link

arcanis 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:

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

@sheetalkamat
Copy link
Member

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

@sheetalkamat sheetalkamat added API Relates to the public API for TypeScript Suggestion An idea for TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Apr 29, 2019
@DanielRosenwasser DanielRosenwasser added Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Apr 29, 2019
@DanielRosenwasser
Copy link
Member

@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
Copy link
Author

arcanis 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 🙂

@sheetalkamat
Copy link
Member

I think we can add compiler options but not the resolutionHost since resolution host in case of custom module resolution is the host itself and something host would need to create if they need since its only created when using our own module resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Fix Available A PR has been opened for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
4 participants