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

chore: add all missing peer dependency statements #4243

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 39 additions & 2 deletions packages/styled-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,45 @@
"tslib": "2.5.0"
},
"peerDependencies": {
"react": ">= 16.8.0",
"react-dom": ">= 16.8.0"
"@emotion/is-prop-valid": "^1.2.1",
Copy link

Choose a reason for hiding this comment

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

I don't think this change will do what you think it will do they way it stands:

  • Listing packages as a peerDependency means styled-components expect the consuming application to have downloaded those dependencies beforehand, which I believe is not the case here (I might be wrong though 😄)

To achieve what you want (better dedupe on the consuming apps side) you can simply change the dependencies listed in the dependencies array to use the range syntax like you used here. NPM/Yarn will be smart and reuse the dependencies versions already present on the consuming side if there's a match for that range..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why they're defined in both peer and regular dependencies, with peerDependenciesMeta declaring all but "react" are optional

Choose a reason for hiding this comment

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

But since the dependencies array still defines fixed versions, it'll overwrite the peerDependenciesMeta, won't it? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested it linked against the styled-components-website repo and it seems to work as expected (at least using yarn.) A test version is published as styled-components@6.1.5-rc.0 if you want to give it a shot.

Copy link
Contributor Author

@quantizor quantizor Dec 27, 2023

Choose a reason for hiding this comment

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

Tested the explicit dependency + permissive peer dep with a bunch of different pms:

Worked (installed only the higher version): yarn, pnpm
Didn't work (installed both versions): npm, bun

The tricky thing is with react the range is really wide (16.8 and up basically.) I could move things out of peerDependencies into devDependencies, but basically no pm automatically installs peerDependencies out of the box so users would get hit with an error to add the dependency explicitly. The goal of this was to ensure the relevant libraries are available at least at the version we specify, with peerDependencies meant to deduplicate to a greater applicable version if defined in the client repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opened an issue against npm, I think yarn and pnpm behavior is correct.

Choose a reason for hiding this comment

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

Hmm, interesting one.. I expected PMs to make dependencies take precedence over peerDependencies as, to me, peerDependencies was purely informational to let consuming apps know that you expect something to be there.. However, that doesn't seem to be the behavior the accepted RFC you linked describes..

Even if they fix npm, it'll take time for people to adopt the version with the fix..
IMHO, if I consume a library that has a dependency: "A": "^1.1.0", I would think that library was integration-tested with that package with that version, although anything in the range might work..

The goal of this was to ensure the relevant libraries are available at least at the version we specify

You just precisely described (in my understanding) the dependencies array when used with ranges :D

Choose a reason for hiding this comment

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

I imported styled-components@6.1.5-rc.0 into the styled-components-website and ran yarn.. it did not take into account the peerDependencies array (that specifies postcss: ^8.4.31 - should've resolved postcss to 8.4.32)..

image

When I removed the peerDependencies and set the dependencies to be a range (postcss: ^8.4.0 for testing purposes), it resolved postcss to 8.4.32
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more obvious in the repo I linked in the bug ticket since that repo has postcss saved already at a higher version

"@emotion/unitless": ">= 0.8.0",
"@types/stylis": "^4.2.0",
"css-to-react-native": "^3.2.0",
"csstype": "^3.1.2",
"postcss": "^8.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
"shallowequal": "^1.1.0",
"tslib": "^2.5.0"
},
"peerDependenciesMeta": {
"@emotion/is-prop-valid": {
"optional": true
},
"@emotion/unitless": {
"optional": true
},
"@types/stylis": {
"optional": true
},
"css-to-react-native": {
"optional": true
},
"csstype": {
"optional": true
},
"postcss": {
"optional": true
},
"react-dom": {
"optional": true
},
"shallowequal": {
"optional": true
},
"tslib": {
"optional": true
}
},
"devDependencies": {
"@babel/core": "7.21.0",
Expand Down
31 changes: 29 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10039,8 +10039,35 @@ __metadata:
tslib: "npm:2.5.0"
typescript: "npm:4.9.5"
peerDependencies:
react: ">= 16.8.0"
react-dom: ">= 16.8.0"
"@emotion/is-prop-valid": ^1.2.1
"@emotion/unitless": ">= 0.8.0"
"@types/stylis": ^4.2.0
css-to-react-native: ^3.2.0
csstype: ^3.1.2
postcss: ^8.0.0
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
shallowequal: ^1.1.0
tslib: ^2.5.0
peerDependenciesMeta:
"@emotion/is-prop-valid":
optional: true
"@emotion/unitless":
optional: true
"@types/stylis":
optional: true
css-to-react-native:
optional: true
csstype:
optional: true
postcss:
optional: true
react-dom:
optional: true
shallowequal:
optional: true
tslib:
optional: true
languageName: unknown
linkType: soft

Expand Down