-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
ngtsc as a plugin! #34792
ngtsc as a plugin! #34792
Conversation
1e39e60
to
a51dfe9
Compare
getNextProgram(): ts.Program; | ||
|
||
prepareEmit(): { | ||
transformers: { |
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.
could you use the type ts.CustomTransformers
here?
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.
Done.
* enable progress to be made in parallel, the upstream interface isn't implemented directly. | ||
* Instead, `TscPlugin` here is structurally assignable to what tsc_wrapped expects. | ||
*/ | ||
interface TscPlugin { |
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.
could you add a member name = 'ngtsc'
so that it matches the interface LitPlugin introduced for gathering diagnostics?
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.
Done.
*/ | ||
interface TscPlugin { | ||
wrapHost( | ||
host: PluginCompilerHost, inputFiles: ReadonlyArray<string>, |
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.
why does this need to be a PluginCompilerHost
? in our work last week we wrapped a ts.CompilerHost
which was the only thing constructed at this point
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've refactored it to take a ts.CompilerHost
plus the optional fileNameToModuleName
.
interface TscPlugin { | ||
wrapHost( | ||
host: PluginCompilerHost, inputFiles: ReadonlyArray<string>, | ||
options: ts.CompilerOptions): ts.CompilerHost; |
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.
and I think it needs to return a PluginCompilerHost so we can locate the inputFiles when we construct a ts.Program
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.
Done.
if (file === undefined) { | ||
return this.diagnostics; | ||
} else { | ||
return this.diagnostics.filter(diag => diag.file === file); |
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 broken - diag.file
is the .ng.html file but file
is the .ts file
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.
Fixed.
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.
Stellar work! I like how the compiler objects are nicely separated and how the shim generator host has been centralized into the NgCompilerHost
. Some minor comments for your consideration.
compilation.traitCompiler, compilation.reflector, importRewriter, | ||
compilation.defaultImportTracker, compilation.isCore, this.closureCompilerEnabled), | ||
// clang-format off | ||
aliasTransformFactory(compilation.traitCompiler.exportStatements) as ts.TransformerFactory<ts.SourceFile>, |
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.
Would it be possible to change the type of aliasTransformFactory
to get rid of the ts.Bundle
in its generic type argument?
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.
Done. Much cleaner!
// not | ||
// being assignable to `unknown` when wrapped in `Readonly`). |
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.
Weird formatting here
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.
👍
* optional). | ||
*/ | ||
export type RequiredCompilerHostDelegations = { | ||
[M in keyof Required<ExtendedTsCompilerHost>]: ExtendedTsCompilerHost[M] |
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.
[M in keyof Required<ExtendedTsCompilerHost>]: ExtendedTsCompilerHost[M] | |
[M in keyof Required<ExtendedTsCompilerHost>]: ExtendedTsCompilerHost[M]; |
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.
👍
|
||
get compiler(): NgCompiler { | ||
if (this._compiler === null) { | ||
throw new Error('Lifecycle error: getDiagnostics() called before setupCompilation()'); |
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 message looks inaccurate.
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.
Fixed :)
e2ccefe
to
8f45d7c
Compare
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.
LGTM, with some more minor comments
return this.diagnostics.filter(diag => { | ||
if (diag.file === file) { | ||
return true; | ||
} else if (isTemplateDiagnostic(diag) && diag.componentFile === file) { |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I'm gonna defer it because we don't have any testing infrastructure that invokes the compiler at this level yet.
This is blocked on the upstream g3 work to standardize the plugin API, as well as #34887 landing first. |
Should be unblocked for g3sync now - I commented out the relevant bit in tsc_wrapped |
This commit moves the calculation of `ignoreFiles` - the set of files to be ignored by a consumer of the `NgCompiler` API - from its `prepareEmit` operation to its initialization. It's now available as a field on `NgCompiler`. This will allow a consumer to skip gathering diagnostics for `ignoreFiles` as well as skip emit.
This commit implements an experimental integration with tsc_wrapped, where it can load the Angular compiler as a plugin and perform Angular transpilation at a user's request. This is an alternative to the current ngc_wrapped mechanism, which is a fork of tsc_wrapped from several years ago. tsc_wrapped has improved significantly since then, and this feature will allow Angular to benefit from those improvements. Currently the plugin API between tsc_wrapped and the Angular compiler is a work in progress, so NgTscPlugin does not yet implement any interfaces from @bazel/typescript (the home of tsc_wrapped). Instead, an interface is defined locally to guide this standardization.
Caretaker: I cannot force g3 status ("This SHA and context has reached the maximum number of statuses" error). Presubmits are good (only Ivy failures are screenshot diffs & timeouts). This is ready to merge. I've marked it as |
#34792) This commit implements an experimental integration with tsc_wrapped, where it can load the Angular compiler as a plugin and perform Angular transpilation at a user's request. This is an alternative to the current ngc_wrapped mechanism, which is a fork of tsc_wrapped from several years ago. tsc_wrapped has improved significantly since then, and this feature will allow Angular to benefit from those improvements. Currently the plugin API between tsc_wrapped and the Angular compiler is a work in progress, so NgTscPlugin does not yet implement any interfaces from @bazel/typescript (the home of tsc_wrapped). Instead, an interface is defined locally to guide this standardization. PR Close #34792
…ngular#34792) This commit moves the calculation of `ignoreFiles` - the set of files to be ignored by a consumer of the `NgCompiler` API - from its `prepareEmit` operation to its initialization. It's now available as a field on `NgCompiler`. This will allow a consumer to skip gathering diagnostics for `ignoreFiles` as well as skip emit. PR Close angular#34792
…34792) (#35346) This commit moves the calculation of `ignoreFiles` - the set of files to be ignored by a consumer of the `NgCompiler` API - from its `prepareEmit` operation to its initialization. It's now available as a field on `NgCompiler`. This will allow a consumer to skip gathering diagnostics for `ignoreFiles` as well as skip emit. PR Close #34792 PR Close #35346
…ngular#34792) This commit moves the calculation of `ignoreFiles` - the set of files to be ignored by a consumer of the `NgCompiler` API - from its `prepareEmit` operation to its initialization. It's now available as a field on `NgCompiler`. This will allow a consumer to skip gathering diagnostics for `ignoreFiles` as well as skip emit. PR Close angular#34792
angular#34792) This commit implements an experimental integration with tsc_wrapped, where it can load the Angular compiler as a plugin and perform Angular transpilation at a user's request. This is an alternative to the current ngc_wrapped mechanism, which is a fork of tsc_wrapped from several years ago. tsc_wrapped has improved significantly since then, and this feature will allow Angular to benefit from those improvements. Currently the plugin API between tsc_wrapped and the Angular compiler is a work in progress, so NgTscPlugin does not yet implement any interfaces from @bazel/typescript (the home of tsc_wrapped). Instead, an interface is defined locally to guide this standardization. PR Close angular#34792
So this is something Bazel-related? Would anyone care to explain what the big deal is? 🤔 |
…ngular#34792) This commit moves the calculation of `ignoreFiles` - the set of files to be ignored by a consumer of the `NgCompiler` API - from its `prepareEmit` operation to its initialization. It's now available as a field on `NgCompiler`. This will allow a consumer to skip gathering diagnostics for `ignoreFiles` as well as skip emit. PR Close angular#34792
angular#34792) This commit implements an experimental integration with tsc_wrapped, where it can load the Angular compiler as a plugin and perform Angular transpilation at a user's request. This is an alternative to the current ngc_wrapped mechanism, which is a fork of tsc_wrapped from several years ago. tsc_wrapped has improved significantly since then, and this feature will allow Angular to benefit from those improvements. Currently the plugin API between tsc_wrapped and the Angular compiler is a work in progress, so NgTscPlugin does not yet implement any interfaces from @bazel/typescript (the home of tsc_wrapped). Instead, an interface is defined locally to guide this standardization. PR Close angular#34792
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. |
It's happening!!
This PR implements
NgTscPlugin
on top of some refactored compiler APIs. Hopefully this will allow integration withts_library
in the near future.There's lots of rough edges left here, but it looks promising already!