refactor(ivy): introduce the 'core' package and split apart NgtscProgram#34887
refactor(ivy): introduce the 'core' package and split apart NgtscProgram#34887alxhub wants to merge 1 commit intoangular:masterfrom
Conversation
JoostK
left a comment
There was a problem hiding this comment.
LGTM, with some more minor comments
There was a problem hiding this comment.
This would be worth having in a unit test, I don't think we have such a test at the moment.
There was a problem hiding this comment.
Agreed. This was a little tricky to do at this level of abstraction - I think we could benefit from some testing utilities here eventually. Still, the test looks pretty reasonable.
petebacondarwin
left a comment
There was a problem hiding this comment.
Nice cleanup! Lots of minor NITS. Nothing to get too worried about.
There was a problem hiding this comment.
This is a long line. Do we not worry about line length in READMEs?
There was a problem hiding this comment.
Line breaks in Markdown are semantic, so long lines are actually what we want here. Otherwise we're breaking the formatting.
There was a problem hiding this comment.
In github they're not: https://github.github.com/gfm/#paragraphs
You need an empty blank line to indicate an end of paragraph.
There was a problem hiding this comment.
I thought Webpack was synchronous with regard to Angular compilation?
There was a problem hiding this comment.
Nope! The actual TS side is (particularly the module resolution hooks that ngcc cares about). But the Angular analysis is async, because producing styleUrls or templateUrl contents might require running through another Webpack invocation, which I believe is accomplished by forking the webpack-ing process?
There was a problem hiding this comment.
Perhaps complete the example by describing what the return value might be?
There was a problem hiding this comment.
I believe path/to/containingFile.ts is supposed to be the example, but I've clarified it to be a lot more clear.
There was a problem hiding this comment.
By host do we really mean CompilerHost? Or can this interface be used in other contexts?
There was a problem hiding this comment.
It can be used in other contexts :) actually, the compiler has an internal interface named FileToModuleHost which is identical to this one. I've modified the PR to unify them (I like the name UnifiedModulesHost anyway as it's a lot more clear about what the intent of the interface is - a unified view of the module namespace.
There was a problem hiding this comment.
We could use absoluteFrom rather than resolve here, given that TS internal paths are guaranteed to be absolute.
There was a problem hiding this comment.
Is there a tsickle issue to track for this?
There was a problem hiding this comment.
Joost had me refactor them away. Comment deleted!
There was a problem hiding this comment.
Probably not part of this PR but it seems strange for this to be in the compiler rather than inside a trait? Am I missing something?
There was a problem hiding this comment.
Trait is an operation with a pretty specific shape - match a decorator or some other aspect of the class, extract information from it in local & global steps, and then add some static fields to the class (mimicking the execution of said decorator at runtime).
Other forms of static analysis & mutation, like detecting static methods or functions which return ModuleWithProviders, don't really fit this model. We could create a similar kind of abstraction (maybe upstream ngcc's Migration concept?).
There was a problem hiding this comment.
OK - may be for another PR :-)
dc8100b to
7af2ce9
Compare
Previously, NgtscProgram lived in the main @angular/compiler-cli package alongside the legacy View Engine compiler. As a result, the main package depended on all of the ngtsc internal packages, and a significant portion of ngtsc logic lived in NgtscProgram. This commit refactors NgtscProgram and moves the main logic of compilation into a new 'core' package. The new package defines a new API which enables implementers of TypeScript compilers (compilers built using the TS API) to support Angular transpilation as well. It involves a new NgCompiler type which takes a ts.Program and performs Angular analysis and transformations, as well as an NgCompilerHost which wraps an input ts.CompilerHost and adds any extra Angular files. Together, these two classes are used to implement a new NgtscProgram which adapts the legacy api.Program interface used by the View Engine compiler onto operations on the new types. The new NgtscProgram implementation is significantly smaller and easier to reason about. The new NgCompilerHost replaces the previous GeneratedShimsHostWrapper which lived in the 'shims' package. A new 'resource' package is added to support the HostResourceLoader which previously lived in the outer compiler package. As a result of the refactoring, the dependencies of the outer @angular/compiler-cli package on ngtsc internal packages are significantly trimmed. This refactoring was driven by the desire to build a plugin interface to the compiler so that tsc_wrapped (another consumer of the TS compiler APIs) can perform Angular transpilation on user request.
7af2ce9 to
dd02363
Compare
…ram (#34887) Previously, NgtscProgram lived in the main @angular/compiler-cli package alongside the legacy View Engine compiler. As a result, the main package depended on all of the ngtsc internal packages, and a significant portion of ngtsc logic lived in NgtscProgram. This commit refactors NgtscProgram and moves the main logic of compilation into a new 'core' package. The new package defines a new API which enables implementers of TypeScript compilers (compilers built using the TS API) to support Angular transpilation as well. It involves a new NgCompiler type which takes a ts.Program and performs Angular analysis and transformations, as well as an NgCompilerHost which wraps an input ts.CompilerHost and adds any extra Angular files. Together, these two classes are used to implement a new NgtscProgram which adapts the legacy api.Program interface used by the View Engine compiler onto operations on the new types. The new NgtscProgram implementation is significantly smaller and easier to reason about. The new NgCompilerHost replaces the previous GeneratedShimsHostWrapper which lived in the 'shims' package. A new 'resource' package is added to support the HostResourceLoader which previously lived in the outer compiler package. As a result of the refactoring, the dependencies of the outer @angular/compiler-cli package on ngtsc internal packages are significantly trimmed. This refactoring was driven by the desire to build a plugin interface to the compiler so that tsc_wrapped (another consumer of the TS compiler APIs) can perform Angular transpilation on user request. PR Close #34887
|
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. |
Previously, NgtscProgram lived in the main @angular/compiler-cli package
alongside the legacy View Engine compiler. As a result, the main package
depended on all of the ngtsc internal packages, and a significant portion of
ngtsc logic lived in NgtscProgram.
This commit refactors NgtscProgram and moves the main logic of compilation
into a new 'core' package. The new package defines a new API which enables
implementers of TypeScript compilers (compilers built using the TS API) to
support Angular transpilation as well. It involves a new NgCompiler type
which takes a ts.Program and performs Angular analysis and transformations,
as well as an NgCompilerHost which wraps an input ts.CompilerHost and adds
any extra Angular files.
Together, these two classes are used to implement a new NgtscProgram which
adapts the legacy api.Program interface used by the View Engine compiler
onto operations on the new types. The new NgtscProgram implementation is
significantly smaller and easier to reason about.
The new NgCompilerHost replaces the previous GeneratedShimsHostWrapper which
lived in the 'shims' package.
A new 'resource' package is added to support the HostResourceLoader which
previously lived in the outer compiler package.
As a result of the refactoring, the dependencies of the outer
@angular/compiler-cli package on ngtsc internal packages are significantly
trimmed.
This refactoring was driven by the desire to build a plugin interface to the
compiler so that tsc_wrapped (another consumer of the TS compiler APIs) can
perform Angular transpilation on user request.