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: correctly forward dependency on @react-native-community/cli-server-api #49325

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: correctly forward dependency on `@react-native-community/cli-ser…
…ver-api`
  • Loading branch information
tido64 committed Feb 11, 2025
commit 95829a4d8f78bc73c4f440b588598d118110d14c
5 changes: 0 additions & 5 deletions packages/community-cli-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@
"peerDependencies": {
"@react-native-community/cli-server-api": "*"
},
"peerDependenciesMeta": {
"@react-native-community/cli-server-api": {
"optional": true
}
},
"engines": {
"node": ">=18"
}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"featureflags": "node ./scripts/featureflags/index.js"
},
"peerDependencies": {
"@react-native-community/cli-server-api": "*",
Copy link
Contributor

Choose a reason for hiding this comment

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

@tido64 @robhogan
mentioned that this will force cli-server-api to be installed (or at least result in a warning) also for expo users.

Can't we add this as direct dependency inside the template instead?

Copy link
Collaborator Author

@tido64 tido64 Feb 12, 2025

Choose a reason for hiding this comment

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

We still need it here for it to be hoisted correctly. But we can make it optional and make it a direct dependency in the template.

Edit: I meant to submit a PR to the template but got distracted. Will try to get to it later tonight.

Copy link
Contributor

Choose a reason for hiding this comment

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

We still need it here for it to be hoisted correctly

Why do we need it here specifically?

Copy link
Collaborator Author

@tido64 tido64 Feb 12, 2025

Choose a reason for hiding this comment

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

Basically, we declare that @react-native/community-cli-plugin depends on cli-server-api but that consumers need to satisfy this requirement. The only consumer of @react-native/community-cli-plugin is react-native, but you don't want react-native to depend on CLI any longer. So react-native needs to "forward" the dependency to its consumers, hence redeclare peer dependency. Without this, package managers won't correctly link the package.

However, since react-native has cli-server-api as peer dependency, it's probably fine to mark it as optional and add it in the template as a direct dependency to satisfy the requirement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

but you don't want react-native to depend on CLI any longer.

I think there is some cleanup to make sure react-native doesn't need to depend on @react-native/community-cli-plugin at all so this change wont' be required at all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there is some cleanup to make sure react-native doesn't need to depend on @react-native/community-cli-plugin at all so this change wont' be required at all

Yes, that would be the proper solution in the long run.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the time being, can't we just have:

  1. Remove the peerDependency here between react-native and @react-native-community/cli-server-api (so amend this line)
  2. Add the dependency on the template as per fix: @react-native/community-cli-plugin depends on @react-native-community/cli-server-api react-native-community/template#105

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've replied to this offline but I'll post it here as well for transparency: The short answer is, if you do it this way, package managers won't put @react-native-community/cli-server-api in a place where @react-native/community-cli-plugin will be able to find it.

Longer answer: See #49325 (comment)

"@types/react": "^19.0.0",
"react": "^19.0.0"
},
Expand Down
Loading