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

Fixing dependencies to support yarn2 strict mode #6942

Closed

Conversation

zemd
Copy link

@zemd zemd commented Dec 21, 2020

Yarn2 PnP strict mode requires that dependencies were strictly defined within packages which use them and yarn2 throw an exception during the project launch.

Error: @loopback/repository-json-schema tried to access @loopback/repository (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: @loopback/repository (via "@loopback/repository")

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@zemd zemd force-pushed the chore/yarn2-pnp-strict-mode-support branch from 2145fe5 to 6a9d2e1 Compare December 21, 2020 10:08
Copy link
Member

@achrinza achrinza left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I've left some initial remarks 👇

Comment on lines 26 to +29
"@loopback/core": "^2.13.1"
},
"dependencies": {
"@loopback/repository": "^3.3.0",
Copy link
Member

Choose a reason for hiding this comment

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

Would Yarn2 PnP be satisfied with it being referenced as a peerDependency instead?

The reason for peerDependency is so that only a single version of the package is used across the project and its dependencies (See #5959). Adding @loopback/repository as a hard dependency would break this paradigm.

Though it got me curious if there's any other LB4 packages that have the same issue.

We also probably should update our CI pipeline to test with Yarn2 PnP.

Suggested change
"@loopback/core": "^2.13.1"
},
"dependencies": {
"@loopback/repository": "^3.3.0",
"@loopback/core": "^2.13.1"
"@loopback/repository": "^3.3.0"
},
"dependencies": {

Copy link
Member

Choose a reason for hiding this comment

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

-1. Our extensions are intentionally using peer dependencies for @loopback/repository, as explained in the comment above.

To fix the problem you are observing with Yarn2 PnP, we should find the place that's depending on @loopback/openapi-v3 but not fulfilling it's peer dependency on @loopback/repository. I think we need to add @loopback/repository to peerDependencies of @loopback/rest.

https://github.com/strongloop/loopback-next/blob/81fab94a16f09da8d6251cef68c33b127861c0d4/packages/rest/package.json#L26-L32

Copy link
Member

Choose a reason for hiding this comment

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

We also probably should update our CI pipeline to test with Yarn2 PnP.

That's a great idea 👍 Would you @achrinza mind opening a new GH issue for that?

@@ -10,6 +10,7 @@
"access": "public"
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.0.2",
Copy link
Member

Choose a reason for hiding this comment

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

Any reason/benefit for the switch? AFAIK, both are actively maintained as aliases.

Copy link
Member

Choose a reason for hiding this comment

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

Let's not mix multiple kinds of changes in a single pull request please.

Either switch the swagger parser implementation, or fix dependencies to enable yarn2, but don't do both.

Copy link
Contributor

@mschnee mschnee left a comment

Choose a reason for hiding this comment

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

If adding support for yarn2/pnp, we should probably be diligent and also consider updating the travis configuration to support yarn2-based installations in addition to the current npm ci install.

Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

Thank you @zemd for the pull request. I agree we should support Yarn2 strict mode 👍

I find several aspects of your proposal problematic, please take a look at my comments below 👇🏻

@@ -38,3 +38,6 @@ benchmark/dist
# Docs preview
docs/_loopback.io/
docs/_preview/

# IDE files
/.idea
Copy link
Member

Choose a reason for hiding this comment

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

I believe we are intentionally not listing .idea files in .gitignore, advising users to setup a global ignore rule instead.

If you think it's time to change that, then please open a new pull request where we can discuss the change on it's own, independently on feature/bug fix work.

@@ -10,6 +10,7 @@
"access": "public"
},
"dependencies": {
"@apidevtools/swagger-parser": "^10.0.2",
Copy link
Member

Choose a reason for hiding this comment

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

Let's not mix multiple kinds of changes in a single pull request please.

Either switch the swagger parser implementation, or fix dependencies to enable yarn2, but don't do both.

Comment on lines 26 to +29
"@loopback/core": "^2.13.1"
},
"dependencies": {
"@loopback/repository": "^3.3.0",
Copy link
Member

Choose a reason for hiding this comment

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

-1. Our extensions are intentionally using peer dependencies for @loopback/repository, as explained in the comment above.

To fix the problem you are observing with Yarn2 PnP, we should find the place that's depending on @loopback/openapi-v3 but not fulfilling it's peer dependency on @loopback/repository. I think we need to add @loopback/repository to peerDependencies of @loopback/rest.

https://github.com/strongloop/loopback-next/blob/81fab94a16f09da8d6251cef68c33b127861c0d4/packages/rest/package.json#L26-L32

Comment on lines 26 to +29
"@loopback/core": "^2.13.1"
},
"dependencies": {
"@loopback/repository": "^3.3.0",
Copy link
Member

Choose a reason for hiding this comment

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

We also probably should update our CI pipeline to test with Yarn2 PnP.

That's a great idea 👍 Would you @achrinza mind opening a new GH issue for that?

@stale
Copy link

stale bot commented Jul 14, 2021

This pull request has been marked stale because it has not seen activity within two months. It will be closed within 14 days of being stale unless there is new activity.

@stale stale bot added the stale label Jul 14, 2021
@stale
Copy link

stale bot commented Jul 28, 2021

This pull request has been closed due to continued inactivity. If you are interested in finishing the proposed changes, then feel free to re-open this pull request or open a new one.

@stale stale bot closed this Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants