thymikee / jest-preset-angular

Jest configuration preset for Angular projects.
https://thymikee.github.io/jest-preset-angular/
MIT License
885 stars 306 forks source link

Angular no longer directly depends on core-js - should not be a peerDependency #266

Closed okunokentaro closed 5 years ago

okunokentaro commented 5 years ago

Hi there.

https://github.com/angular/angular-cli/blob/master/packages/schematics/angular/workspace/files/package.json.template#L22-L24

Currently, Angular CLI does not require core-js and is not installed. On the other hand, jest-preset-angular has peerDependencies dependencies in core-js.

It seems to me that we will be forced to do unnecessary installations and should be removed dependencies on core-js. Thanks.

wtho commented 5 years ago

According to the commit message https://github.com/angular/angular-cli/commit/a0a583adaaf8e739c375b914f249801660f33334, the "Angular Build System takes care of the dependencies".

As jest does not use the Angular Build System and requires some library to reflect the metadata in the decorators, my first suggestion would be to make it a dependency.

Do you know how Angular handles the reflection lib? Does it install it on-demand at the first build? Does Angular offer to use other libraries than core-js?

wtho commented 5 years ago

I just installed the latest anguar cli and created a brand new project. After that, the package.json still included core-js.

As we will need some metadata reflection, I think this is no option to remove the dependency.

Did you manage to create a project with the cli that did not install core-js? If so, can you give instructions to replicate this behavior? Also some more information on how Angular installs the metadata polyfill on-demand or if it does the reflection in some other way would be required to move this issue forward.

lacolaco commented 5 years ago

@wtho Hi. Angular CLI inserts reflect-metadata polyfill in the phase of build without --aot flag. It means the CLI requires core-js in node_modules for that behavior.

core-js is now a part of dependencies of @angular-devkit/build-angular, not peer.
https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/package.json#L22 So, Angular CLI no longer add core-js in the application's package.json.

I think jest-preset-angular cannot run without reflection-metadata. And as you said, surely it can depend on core-js as not a peer, like Angular CLI. I also think it is better than asking for additional installation to users.

The key is there is no longer guarantee the Angular applications have core-js.

lacolaco commented 5 years ago

That feature, adding JIT polyfill, is landed from v8. Current latest CLI doesn't support it. Try to use @angular/cli@next to confirm that!

wtho commented 5 years ago

Yeah, I can confirm it is located inside @angular-devkit/build-angular.

The key is there is no longer guarantee the Angular applications have core-js.

Ok so as long as Angular projects are built with @angular-devkit/build-angular, we can depend on it without taking extra space on the developer's drive.

Changing the peer dependency to a dependency will be the first step to make this preset compatible with Angular v8. Feel free to create a small PR if you like.

Also please note the dependency range should allow core-js v2 or v3, as there are still many Angular versions depending on v2.

wtho commented 5 years ago

Solved in #315