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: correct peer dependencies #272

Merged
merged 1 commit into from
Dec 6, 2021
Merged

fix: correct peer dependencies #272

merged 1 commit into from
Dec 6, 2021

Conversation

timdeschryver
Copy link
Member

@timdeschryver timdeschryver commented Dec 6, 2021

Closes #270

@timdeschryver timdeschryver merged commit b074490 into main Dec 6, 2021
@the-ult
Copy link
Contributor

the-ult commented Dec 9, 2021

Hey @timdeschryver

How did this resolve the dependencies issue?

I refactored the angular.json to workspace.json and using the per project configuration with project.json

https://blog.nrwl.io/per-project-configuration-storybook-support-for-angular-12-auto-refresh-for-dependency-graph-and-bcd2d1e06658

Atm angular-testing-library has both a angular.json and a workspace.json

Seems like you did a revert?

When building testing-library from within my old upgrade-to-angular-13 branche. I see that @angular/forms is somehow included

Screenshot 2021-12-09 at 22 14 00

Which is weird. (unless it is used in testing-library somewhere?)
Nx generates the package.json based on the dependencies. It adds the missing dependencies.

projects/testing-library/package.json

  "peerDependencies": {
    "@angular/common": ">= 13.0.0",
    "@angular/platform-browser": ">= 13.0.0",
    "@angular/animations": ">= 13.0.0",  // ! this shouldn't be here either
    "@angular/router": ">= 13.0.0",
    "@angular/core": ">= 13.0.0"
  },
  "dependencies": {
    "@testing-library/dom": "^8.0.0",
    "tslib": "^2.0.0"
  },

dist/@testing-library/angular/package.json

"peerDependencies": {
    "@angular/common": ">= 13.0.0",
    "@angular/platform-browser": ">= 13.0.0",
    "@angular/animations": ">= 13.0.0",
    "@angular/router": ">= 13.0.0",
    "@angular/core": ">= 13.0.0",
    "@angular/forms": "13.0.2",  // added bij NX
    "rxjs": "^7.4.0",
    "@testing-library/user-event": "^13.5.0" // added by NX
  },
  "dependencies": {
    "@testing-library/dom": "^8.0.0",
    "tslib": "^2.0.0"
  },

angular/forms

Screenshot 2021-12-09 at 22 19 07

As you can see @angular/forms is used by the tests. And somehow NX thinks @angular/forms is needed for the library as well.

FIX

Adding the @angular/forms as devDependencies to the project resolves this.
(and the same with @testing-library/user-event)

Question
Does testing-library-angular need any @angular/.. lib
as peerDependency? Or are they only used for the example app or tests?

A search gives these results:
Screenshot 2021-12-09 at 22 27 08

Which would mean only these are needed as peerDependencies in projects/testing-library/package.json and also only as dependencies in the root package.json.

    "@angular/common": ">= 13.0.0",
    "@angular/platform-browser": ">= 13.0.0",
    "@angular/router": ">= 13.0.0",
    "@angular/core": ">= 13.0.0"

All other @angular/.. dependencies should/could be added to the devDependencies .. ??

@the-ult
Copy link
Contributor

the-ult commented Dec 9, 2021

I could create a new PR with the new fixes.
And still using the per project configuration etc..

@timdeschryver
Copy link
Member Author

@the-ult I re-added the angular.json file as a quick fix. It's probably better to add them as a dev dependency, but I wasn't aware that that would be the proper fix. Another problem is that the build task in the angular file also includes some post-build scripts, which should also be added to the nx file.

@the-ult
Copy link
Contributor

the-ult commented Dec 9, 2021

I 'll try to make a new PR next week.

Not sure if adding them to the devDependencies is the fix. But from the quick test, it seems to work and generate a proper package.json.

And thinking: dependencies should only include the dependencies you'll need for production it seems logical, not needing them for the testing-library

We could ask somebody from the nx team if the above is actually needed. Might be a bug in NX. They should probably skip imports/dependencies, which are only used in tests.

@timdeschryver
Copy link
Member Author

@the-ult fyi, it seems like we already got the post-build steps covered - so the only problem are the dependencies.

https://github.com/testing-library/angular-testing-library/blob/main/projects/testing-library/project.json#L38

@the-ult
Copy link
Contributor

the-ult commented Dec 14, 2021

Indeed.
I'll try and create a PR tomorrow 👍

@timdeschryver
Copy link
Member Author

No rush though @the-ult

the-ult added a commit to the-ult/angular-testing-library that referenced this pull request Jan 6, 2022
…vDependencies

@angular/forms and @testing-library/user-event
are only used in tests and should not be exported
in the package.json for production.

@see: testing-library#272 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

... has incorrect peer dependency "@angular/forms@13.0.2"
2 participants