-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Resolve modules, type reference directives in context of referenced file #27560
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
Conversation
… the getSourceFile not return redirected file by its name
…an add tsserver tests as well
f469170
to
dd34314
Compare
Wow, there's a heck of a lot changes in this PR. My approach would more closely align with the old implementation:
That way you could get rid of all changes in |
module resolver passes current project reference so it can use the compiler options of the containing project. (instead of options it passes Project Reference since it is more future proof.) The changes in module resolver are needed so it can use compiler options of containing project instead of project it is building. |
I agree that it makes sense to pass compilerOptions to |
I don't think just passing compilerOptions is good idea since the current way (passing containing projectReference which sourceFile of config file apart from its commandline) lets host do custom action eg. your build expecially in watch mode or editor could reuse the resolution from that cache - this is not yet part of this change but its intended for future use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't looked at it in detail yet, but the approach made me want to see a test of a node module resolution project referencing a non-node one and vice versa (and ensuring the, eg, if a classic project referenced a node project, node module identifiers resolve in the declarations representing the dependent project).
I can add classic resolution in referenced project test case but note that in the current one I verify path mapping changes in referenced project are handled correctly. |
I specifically am calling out a change in module resolution scheme because they use differing underlying resolvers. |
@@ -4959,13 +4963,13 @@ namespace ts { | |||
* If resolveModuleNames is implemented then implementation for members from ModuleResolutionHost can be just | |||
* 'throw new Error("NotImplemented")' | |||
*/ | |||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): (ResolvedModule | undefined)[]; | |||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference): (ResolvedModule | undefined)[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when resolving module names in the root project, there will be no ResolvedProjectReference
. Therefore a custom CompilerHost has no access to the CompilerOptions of that project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not changed since it was original API as well. In general host already knows root compiler options. Eg. https://github.com/TypeStrong/ts-loader/blob/master/src/servicesHost.ts#L498
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general host already knows root compiler options.
Correct, although that only works when building exactly one project with that host. The current implementation of tsbuild.ts
(I know it's still considered internal) uses the same SolutionBuilderHost
to build all projects. That host cannot know about the compilerOptions of all projects. And since tsbuild can even handle multiple tsconfig.json files at once, there's no way the host could ever know the correct compilerOptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to change that. (the default compilerHost is for specific compilerOptions) Infact we want to change tsbuilder to create compiler host for each program separaterly but that's a todo for little later.
@weswigham @rbuckton Please review. |
This PR adds the ability to resolve module and type reference directives in the project direct file with its own options (eg project structure of A -> B -> C, while resolving modules/type reference directives in B we will use B's config file options to resolve it rather than using A's config file options)
Fixes #27200