Skip to content
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

Closed
wants to merge 2 commits into from
Closed

ngtsc as a plugin! #34792

wants to merge 2 commits into from

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Jan 15, 2020

It's happening!!

This PR implements NgTscPlugin on top of some refactored compiler APIs. Hopefully this will allow integration with ts_library in the near future.

There's lots of rough edges left here, but it looks promising already!

@alxhub alxhub force-pushed the ngtsc/plugin branch 2 times, most recently from 1e39e60 to a51dfe9 Compare January 18, 2020 00:23
@alxhub alxhub added target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 18, 2020
@alxhub alxhub requested review from JoostK and alexeagle and removed request for JoostK January 18, 2020 00:23
@alxhub alxhub marked this pull request as ready for review January 18, 2020 00:31
@alxhub alxhub requested review from a team as code owners January 18, 2020 00:31
getNextProgram(): ts.Program;

prepareEmit(): {
transformers: {
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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?

Copy link
Member Author

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>,
Copy link
Contributor

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

Copy link
Member Author

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;
Copy link
Contributor

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

Copy link
Member Author

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);
Copy link
Contributor

@alexeagle alexeagle Jan 21, 2020

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

@JoostK JoostK left a 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>,
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Much cleaner!

Comment on lines 646 to 647
// not
// being assignable to `unknown` when wrapped in `Readonly`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird formatting here

Copy link
Member Author

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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[M in keyof Required<ExtendedTsCompilerHost>]: ExtendedTsCompilerHost[M]
[M in keyof Required<ExtendedTsCompilerHost>]: ExtendedTsCompilerHost[M];

Copy link
Member Author

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()');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message looks inaccurate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

packages/compiler-cli/src/ngtsc/core/src/host.ts Outdated Show resolved Hide resolved
@alxhub alxhub force-pushed the ngtsc/plugin branch 5 times, most recently from e2ccefe to 8f45d7c Compare January 21, 2020 22:40
Copy link
Member

@JoostK JoostK left a 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

packages/compiler-cli/src/ngtsc/core/api.ts Outdated Show resolved Hide resolved
return this.diagnostics.filter(diag => {
if (diag.file === file) {
return true;
} else if (isTemplateDiagnostic(diag) && diag.componentFile === file) {
Copy link
Member

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.

Copy link
Member Author

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.

@alxhub
Copy link
Member Author

alxhub commented Jan 21, 2020

This is blocked on the upstream g3 work to standardize the plugin API, as well as #34887 landing first.

@alexeagle
Copy link
Contributor

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

alxhub commented Feb 6, 2020

Presubmit

@alxhub alxhub added target: major This PR is targeted for the next major release action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed target: patch This PR is targeted for the next patch release action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 6, 2020
@alxhub
Copy link
Member Author

alxhub commented Feb 6, 2020

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 master-only - I'll open a separate PR with only the refactor commit for the 9.0.x branch.

@mhevery mhevery closed this in 14aa6d0 Feb 6, 2020
mhevery pushed a commit that referenced this pull request Feb 6, 2020
#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
alxhub added a commit to alxhub/angular that referenced this pull request Feb 11, 2020
…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
kara pushed a commit that referenced this pull request Feb 11, 2020
…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
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 13, 2020
…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
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 13, 2020
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
@LayZeeDK
Copy link
Contributor

So this is something Bazel-related? Would anyone care to explain what the big deal is? 🤔

sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 17, 2020
…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
sonukapoor pushed a commit to sonukapoor/angular that referenced this pull request Feb 17, 2020
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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants