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(@angular-devkit/build-optimizer): increase safety of code removal #19049

Merged
merged 2 commits into from Oct 12, 2020

Conversation

clydin
Copy link
Member

@clydin clydin commented Oct 11, 2020

This change lowers the potential for code to be errantly removed by the prefix functions and scrub file transformers. Only known safe modules are used with the prefix functions transformer as it can easily remove required module level side effects (as opposed to global level side effects) such as __decorate calls.
The scrub file transformer will now keep parameter metadata if non-Angular decorators are present. This allows libraries that use that information to continue to function.

Closes #14033
Closes #18621

@clydin clydin added the target: major This PR is targeted for the next major release label Oct 11, 2020
@google-cla google-cla bot added the cla: yes label Oct 11, 2020
@clydin clydin force-pushed the safer-build-optimizer branch 3 times, most recently from d381593 to 9722bd1 Compare October 11, 2020 20:59
getTransforms.push(
// getPrefixFunctionsTransformer is rather dangerous, apply only to known pure es5 modules.
// It will mark both `require()` calls and `console.log(stuff)` as pure.
// We only apply it to modules known to be side effect free, since we know they are safe.
// getPrefixFunctionsTransformer needs to be before getFoldFileTransformer.
getPrefixFunctionsTransformer,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know for which cases the prefix function transformer is needed in Angular?

Copy link
Member Author

@clydin clydin Oct 12, 2020

Choose a reason for hiding this comment

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

View Engine factory files need it and were already included in the safe side effect check.
Additionally, there are a variety call/new expressions in @angular/* involving the following:

[
  "ComponentFactoryResolver$1",
  "InjectionToken",
  "KeyRegistry",
  "Optional",
  "ObservableStrategy",
  "PromiseStrategy",
  "ReflectionCapabilities",
  "Reflector",
  "Version",
  "core_merge",
  "getClosureSafeProperty",
  "makeDecorator",
  "makeParamDecorator",
  "makePropDecorator",
  "tagSet",
  "tokenKey",
]

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

2 questions mainly.

And from the code changes, I am confident that this change also fixes #18621

This change lowers the potential for code to be errantly removed by the prefix functions and scrub file transformers.  Only known safe modules are used with the prefix functions transformer as it can easily remove required module level side effects (as opposed to global level side effects) such as `__decorate` calls.
The scrub file transformer will now keep metadata if non-Angular decorators are present. This allows libraries that use that information to continue to function.

Closes angular#14033
Closes angular#18621
… tests

The experimental Webpack Rollup pass no longer produces smaller sizes than the standard production build.
@clydin clydin added the action: merge The PR is ready for merge by the caretaker label Oct 12, 2020
@filipesilva filipesilva merged commit 755cb8d into angular:master Oct 12, 2020
@clydin clydin deleted the safer-build-optimizer branch October 12, 2020 15:04
@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 Nov 12, 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 target: major This PR is targeted for the next major release
Projects
None yet
3 participants