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

@angular-devkit/build-optimizer strips non-Angular decorators #18621

Closed
2 of 15 tasks
kevindrecruit opened this issue Aug 26, 2020 · 1 comment · Fixed by #19049
Closed
2 of 15 tasks

@angular-devkit/build-optimizer strips non-Angular decorators #18621

kevindrecruit opened this issue Aug 26, 2020 · 1 comment · Fixed by #19049
Labels
area: devkit/build-optimizer freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@kevindrecruit
Copy link

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

No

Description

I understood from the description of the build-optimizer plugin, that non-Angular decorators should not be stripped.
https://www.npmjs.com/package/@angular-devkit/build-optimizer

However, I can see that decorated properties inside the constructor are removed, which prevents my team from using build-optimizer as part of the ng build command (we use inversifyjs to manage our dependencies outside of the Angular module).

Inside scrub-file.ts, the isDecorateAssignmentExpression method seems to be responsible for the decision to strip this metadata.

🔬 Minimal Reproduction

https://github.com/kevindrecruit/angular-build-optimizer-issue

🔥 Exception or Error

Using the minimum reproduction git repository, we can see the following error (which is specific to inversifyjs):

ERROR Error: Missing required @inject or @multiInject annotation in: argument 0 in class e.

The point is that the @inject() has been removed from the constructor where it is still needed.

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.0.7
Node: 12.18.3
OS: linux x64

Angular: 10.0.12
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.7
@angular-devkit/build-angular     0.1000.7
@angular-devkit/build-optimizer   0.1000.7
@angular-devkit/build-webpack     0.1000.7
@angular-devkit/core              10.0.7
@angular-devkit/schematics        10.0.7
@angular/cli                      10.0.7
@ngtools/webpack                  10.0.7
@schematics/angular               10.0.7
@schematics/update                0.1000.7
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0

Anything else relevant?

@alan-agius4 alan-agius4 added area: devkit/build-optimizer freq1: low Only reported by a handful of users who observe it rarely severity3: broken labels Aug 26, 2020
@ngbot ngbot bot modified the milestone: needsTriage Aug 26, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Aug 26, 2020
clydin added a commit to clydin/angular-cli that referenced this issue Oct 12, 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 metadata if non-Angular decorators are present. This allows libraries that use that information to continue to function.

Closes angular#14033
Closes angular#18621
filipesilva pushed a commit that referenced this issue Oct 12, 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 metadata if non-Angular decorators are present. This allows libraries that use that information to continue to function.

Closes #14033
Closes #18621
@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
area: devkit/build-optimizer freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants