-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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(ivy): ngcc - prefer JavaScript source files when resolving module… #30017
Conversation
e479741
to
69b2f33
Compare
host.getCurrentDirectory(), file => host.getCanonicalFileName(file)); | ||
host.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference) => { | ||
return moduleNames.map(moduleName => { | ||
const {resolvedModule} = ts.resolveModuleName( |
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 know @petebacondarwin ran into some issues trying to use this function, with how terribly it performed. I'm guessing the ts.ModuleResolutionCache
mitigates that considerably. I actually imagine TS has a similar implementation internally.
@petebacondarwin, do you have any perf concerns here? Otherwise this LGTM.
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.
This is almost the same code as what TS uses by default, with one difference: TypeScript's default logic has an additional caching layer, besides the module resolution cache:
See loadWithLocalCache
:
https://github.com/Microsoft/TypeScript/blob/b534fb4849eca0a792199fb6c0cb8849fece1cfd/src/compiler/program.ts#L409-L426
I think we should land #29643 and then consider using the |
Until/if this PR lands, is there a suggested workaround that can be done locally? I'd love to test IVY but use angularfire2 extensively. |
Now that #29643 has landed we should be able to move this PR along. |
69b2f33
to
cb5f2fa
Compare
I rebased this and derived a custom compiler host based on
I can't really foresee if the above would be at all accurate/cover our use-cases. |
… imports Packages that do not follow APF may have the declaration files in the same directory as one source format, typically ES5. This is problematic for ngcc, as it needs to create a TypeScript program with all JavaScript sources of an entry-point, whereas TypeScript's module resolution mechanism would have resolved an internal module import to the external facing .d.ts declaration file, instead of the JavaScript source file. This behavior results in the program to be analysed being incomplete. This commit introduces a custom compiler host that recognizes the above scenario and rewires the resolution of a .d.ts declaration file to its JavaScript counterpart, if applicable. Fixes angular#29939
cb5f2fa
to
a39c404
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the ℹ️ Googlers: Go here for more info. |
Sometimes we need to override module resolution behaviour. We do this by implementing the optional method `resolveModuleNames()` on `CompilerHost`. This commit ensures that we always try this method first before falling back to the standard `ts.resolveModuleName`
951fe43
to
a0d356d
Compare
Caretaker (merge-assistance): @JoostK and @petebacondarwin have boths signed CLAs. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
Sometimes we need to override module resolution behaviour. We do this by implementing the optional method `resolveModuleNames()` on `CompilerHost`. This commit ensures that we always try this method first before falling back to the standard `ts.resolveModuleName` PR Close #30017
… imports (angular#30017) Packages that do not follow APF may have the declaration files in the same directory as one source format, typically ES5. This is problematic for ngcc, as it needs to create a TypeScript program with all JavaScript sources of an entry-point, whereas TypeScript's module resolution mechanism would have resolved an internal module import to the external facing .d.ts declaration file, instead of the JavaScript source file. This behavior results in the program to be analysed being incomplete. This commit introduces a custom compiler host that recognizes the above scenario and rewires the resolution of a .d.ts declaration file to its JavaScript counterpart, if applicable. Fixes angular#29939 PR Close angular#30017
…ar#30017) Sometimes we need to override module resolution behaviour. We do this by implementing the optional method `resolveModuleNames()` on `CompilerHost`. This commit ensures that we always try this method first before falling back to the standard `ts.resolveModuleName` PR Close angular#30017
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
… imports
Packages that do not follow APF may have the declaration files in the same
directory as one source format, typically ES5. This is problematic for ngcc,
as it needs to create a TypeScript program with all JavaScript sources of
an entry-point, whereas TypeScript's module resolution mechanism would have
resolved an internal module import to the external facing .d.ts declaration
file, instead of the JavaScript source file. This behavior results in the
program to be analysed being incomplete.
This commit introduces a custom compiler host that recognizes the above
scenario and rewires the resolution of a .d.ts declaration file to its
JavaScript counterpart, if applicable.
Fixes #29939