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

fix(ngcc): bad package resilience #36083

Conversation

petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Mar 16, 2020

Compiling @mat-datetimepicker/core : module as esm5
...
Error: Failed to compile entry-point @mat-datetimepicker/core (module as esm5) due to compilation errors:
...
Compiling ng-zorro-antd/message : module as esm5
Warning: Skipping processing of @mat-datetimepicker/moment because its dependency @mat-datetimepicker/core failed to compile.
Compiling @angular/flex-layout : module as esm5

@petebacondarwin petebacondarwin added type: bug/fix target: major This PR is targeted for the next major release comp: ngcc labels Mar 16, 2020
@ngbot ngbot bot modified the milestone: needsTriage Mar 16, 2020
@petebacondarwin petebacondarwin force-pushed the ngcc-bad-package-resilience branch 7 times, most recently from 08ff318 to fb73362 Compare March 16, 2020 17:33
@petebacondarwin petebacondarwin marked this pull request as ready for review March 16, 2020 17:40
@pullapprove pullapprove bot requested a review from JoostK March 16, 2020 17:40
@petebacondarwin petebacondarwin requested review from gkalpak and JoostK and removed request for JoostK March 16, 2020 17:40
@petebacondarwin petebacondarwin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 16, 2020
@petebacondarwin
Copy link
Member Author

I need to run a check against the CLI branch on ngcc-validation too.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

I generally like this (with minor comments/suggestions) 👍
Also, great job spliting it up into cleanly separated commits 💯

Just a couple of thoughts/concerns:

  1. I think I would prefer to have a consistent default value for errorOnFailedEntryPoint (false), regardless of how ngcc is called. I feel like it complicates things for little benefit otherwise. Especially given that changing the default based on programmatic call or not is orthogonal to the knowledge one has for the entry-points.
    If anything, it might make sense to change the default value depending on whether the target option is set, but that would complicate things even more. (Even so, I would probably prefer this over the current behavior.)
    I can be definitely convinced otherwise, though. What are your thoughts?

  2. Previously, ngcc operated under the assumption that the found format properties would either be successfully compiled or the operation would halt altogether. This gave us the freedom to arbitrarily associate DTS processing with the first found format property. Now, this assumption is no longer true: It is theoretically possible that processing of es2015 for entry-point foo/bar (which has processDts: true) fails, but processing module for the same entry-point (with processDts: false) succeeds.
    Should we rethink how we associate DTS processing with specific entry-point formats? (Note that this might complicate things significantly for parallel mode.)
    Given the above and the fact that there is avery low probability for it to cause problems, I tend to believe it is better to keep operating under the current assumptions. We could also cancel/skip processing of all formats of an entry-point as soon as the task with processDts: true for that entry-point fails, but the extra compication is probably not worth it.

packages/compiler-cli/ngcc/src/execution/utils.ts Outdated Show resolved Hide resolved
packages/compiler-cli/ngcc/src/execution/utils.ts Outdated Show resolved Hide resolved
packages/compiler-cli/ngcc/main-ngcc.ts Outdated Show resolved Hide resolved
packages/compiler-cli/ngcc/main-ngcc.ts Show resolved Hide resolved
packages/compiler-cli/ngcc/src/main.ts Show resolved Hide resolved
packages/compiler-cli/ngcc/src/main.ts Outdated Show resolved Hide resolved
@kara kara added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 17, 2020
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.

Excellent work!

I do agree with @gkalpak on the choice of the default value of the option, I'd prefer it to be always the same independent of the usage, or indeed be derived from targetedEntryPoint.

@petebacondarwin petebacondarwin force-pushed the ngcc-bad-package-resilience branch 5 times, most recently from fd991ae to 902eb1e Compare March 18, 2020 14:03
@petebacondarwin
Copy link
Member Author

Regarding the defaults. I have made both programmatic and command line version of errorOnFailedEntryPoint default to true.

This will mean that the CLI will need to add this option to the async CLI integration point to benefit from this.

I was not happy to make the default false since that would change the behaviour for the sync CLI integration point, where we definitely want the processing to fail if it comes up against a bad entry-point.

Furthermore, I don't believe that we should tie this errorOnFailedEntryPoint feature to whether we are targeting a specific package or not. They should be independent of each other.

@petebacondarwin petebacondarwin removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 18, 2020
@petebacondarwin
Copy link
Member Author

Of course now the problem will be that the CLI needs to provide a command line option but it will fail if there is a version mismatch and the option is not yet available on the versions of Angular compiler-cli...

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

Some minor comments. Otherwise lgtm 👍

@gkalpak
Copy link
Member

gkalpak commented Mar 18, 2020

BTW, the 4th commit message needs updating wrt the current defaults for errorOnFailedEntryPoint.

This sets up the task execution to be able to report failed compiles
Moving the definition of the `onTaskCompleted` callback into `mainNgcc()`
allows it to be configured based on options passed in there more easily.
This will be the case when we want to configure whether to log or throw
an error for tasks that failed to be processed successfully.

This commit also creates two new folders and moves the code around a bit
to make it easier to navigate the code§:

* `execution/tasks`: specific helpers such as task completion handlers
* `execution/tasks/queues`: the `TaskQueue` implementations and helpers
Later when we implement the ability to continue processing when tasks have
failed to compile, we will also need to avoid processing tasks that depend
upon the failed task.

This refactoring exposes this list of dependent tasks in a way that can be
used to skip processing of tasks that depend upon a failed task.

It also changes the blocking model of the parallel mode of operation so
that non-typings tasks are now blocked on their corresponding typings task.
Previously the non-typings tasks could be triggered to run in parallel to
the typings task, since they do not have a hard dependency on each other,
but this made it difficult to skip task correctly if the typings task failed,
since it was possible that a non-typings task was already in flight when
the typings task failed. The result of this is a small potential degradation
of performance in async parallel processing mode, in the rare cases that
there were not enough unblocked tasks to make use of all the available
workers.
@petebacondarwin petebacondarwin force-pushed the ngcc-bad-package-resilience branch 2 times, most recently from bf0f800 to 408714f Compare March 18, 2020 20:40
Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

LGTM 🎉 👌 💯

Commit message typo:

-This change adds a new `errorOnFailedEntryPoint` option to `mainNgcc` specifies whether ngcc should ...
+This change adds a new `errorOnFailedEntryPoint` option to `mainNgcc` that specifies whether ngcc should ...

packages/compiler-cli/ngcc/main-ngcc.ts Outdated Show resolved Hide resolved
Previously, when an entry-point contained code that caused its compilation
to fail, ngcc would exit in the middle of processing, possibly leaving other
entry-points in a corrupt state.

This change adds a new `errorOnFailedEntryPoint` option to `mainNgcc` that
specifies whether ngcc should exit immediately or log an error and continue
processing other entry-points.

The default is `false` so that ngcc will not error but continue processing
as much as possible. This is useful in post-install hooks, and async CLI
integration, where we do not have as much control over which entry-points
should be processed.

The option is forced to true if the `targetEntryPointPath` is provided,
such as the sync integration with the CLI, since in that case it is targeting
an entry-point that will actually be used in the current project so we do want
ngcc to exit with an error at that point.
When two entry-points overlap, ngcc may attempt to process some
files twice. Previously, when this occured ngcc would just exit with an
error preventing any other entry-points from being processed.

This commit changes ngcc so that if `errorOnFailedEntryPoint` is false, it will
simply log an error and continue to process entry-points. This is useful when
ngcc is processing the entire node_modules folder and there are some invalid
entry-points that the project doesn't actually use.
@petebacondarwin
Copy link
Member Author

ngcc-validation is green : https://app.circleci.com/pipelines/github/angular/ngcc-validation/2438/workflows/9fdc3ecd-4984-4626-b3ee-8a10906df6da

@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 18, 2020
AndrewKushnir pushed a commit that referenced this pull request Mar 18, 2020
Moving the definition of the `onTaskCompleted` callback into `mainNgcc()`
allows it to be configured based on options passed in there more easily.
This will be the case when we want to configure whether to log or throw
an error for tasks that failed to be processed successfully.

This commit also creates two new folders and moves the code around a bit
to make it easier to navigate the code§:

* `execution/tasks`: specific helpers such as task completion handlers
* `execution/tasks/queues`: the `TaskQueue` implementations and helpers

PR Close #36083
AndrewKushnir pushed a commit that referenced this pull request Mar 18, 2020
…36083)

Later when we implement the ability to continue processing when tasks have
failed to compile, we will also need to avoid processing tasks that depend
upon the failed task.

This refactoring exposes this list of dependent tasks in a way that can be
used to skip processing of tasks that depend upon a failed task.

It also changes the blocking model of the parallel mode of operation so
that non-typings tasks are now blocked on their corresponding typings task.
Previously the non-typings tasks could be triggered to run in parallel to
the typings task, since they do not have a hard dependency on each other,
but this made it difficult to skip task correctly if the typings task failed,
since it was possible that a non-typings task was already in flight when
the typings task failed. The result of this is a small potential degradation
of performance in async parallel processing mode, in the rare cases that
there were not enough unblocked tasks to make use of all the available
workers.

PR Close #36083
AndrewKushnir pushed a commit that referenced this pull request Mar 18, 2020
Previously, when an entry-point contained code that caused its compilation
to fail, ngcc would exit in the middle of processing, possibly leaving other
entry-points in a corrupt state.

This change adds a new `errorOnFailedEntryPoint` option to `mainNgcc` that
specifies whether ngcc should exit immediately or log an error and continue
processing other entry-points.

The default is `false` so that ngcc will not error but continue processing
as much as possible. This is useful in post-install hooks, and async CLI
integration, where we do not have as much control over which entry-points
should be processed.

The option is forced to true if the `targetEntryPointPath` is provided,
such as the sync integration with the CLI, since in that case it is targeting
an entry-point that will actually be used in the current project so we do want
ngcc to exit with an error at that point.

PR Close #36083
AndrewKushnir pushed a commit that referenced this pull request Mar 18, 2020
When two entry-points overlap, ngcc may attempt to process some
files twice. Previously, when this occured ngcc would just exit with an
error preventing any other entry-points from being processed.

This commit changes ngcc so that if `errorOnFailedEntryPoint` is false, it will
simply log an error and continue to process entry-points. This is useful when
ngcc is processing the entire node_modules folder and there are some invalid
entry-points that the project doesn't actually use.

PR Close #36083
@petebacondarwin petebacondarwin deleted the ngcc-bad-package-resilience branch March 19, 2020 09:22
@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 Apr 19, 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 target: major This PR is targeted for the next major release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants