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

docs: clarify what peerDependenciesMeta does #7433

Merged
merged 3 commits into from
May 1, 2024
Merged

Conversation

xuhdev
Copy link
Contributor

@xuhdev xuhdev commented Apr 27, 2024

No description provided.

@xuhdev xuhdev requested a review from a team as a code owner April 27, 2024 05:59
@xuhdev xuhdev closed this Apr 27, 2024
@xuhdev xuhdev deleted the patch-2 branch April 27, 2024 06:01
@xuhdev xuhdev restored the patch-2 branch May 1, 2024 05:05
@xuhdev xuhdev reopened this May 1, 2024
@wraithgar
Copy link
Member

The whole section needs to be removed if it does not apply to the currently supported version of npm. We don't need to document old unsupported versions.

@xuhdev xuhdev changed the title clarify npm warning only occurs on version 3-6 clarify what peerDependenciesMeta does May 1, 2024
@xuhdev
Copy link
Contributor Author

xuhdev commented May 1, 2024

@wraithgar Got it, I've updated the PR. peerDependenciesMeta is still used by the latest npm, but the current doc seems to have missed the most important points while talks a lot about the behavior of old npm versions.

@wraithgar wraithgar changed the title clarify what peerDependenciesMeta does docs: clarify what peerDependenciesMeta does May 1, 2024
Comment on lines 823 to 824
dependencies to be marked as optional. Npm would not automatically install
optional peer dependencies. This allows you to
Copy link
Member

Choose a reason for hiding this comment

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

Npm would not automatically install optional peer dependencies.

This is a very confusing and potentially misleading sentence. At a glance it reads that npm does not install optional peer dependencies. In fact it does, it just does not raise an error if they can not be installed.

Copy link
Contributor Author

@xuhdev xuhdev May 1, 2024

Choose a reason for hiding this comment

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

I tried this myself, npm seems to not install optional peer dependencies by default. I"m on npm version 10.7.0.

  1. mkdir my-package && cd my-package
  2. Save the following file to package.json:
{
  "name": "tea-latte",
  "version": "1.3.5",
  "peerDependencies": {
    "lodash": "4.17.21",
    "core-js": "3.37.0"
  },
  "peerDependenciesMeta": {
    "lodash": {
      "optional": true
    }
  }
}
  1. npm install.

Observe that node_module doesn't contain lodash, but it contains core-js.

Then:

  1. npm pack (which generates tea-latte-1.3.5.tgz)
  2. mkdir ../user && cd ../user
  3. npm install ../my-package/tea-latte-1.3.5.tgz

Same effect, only core-js is installed, not lodash.

Copy link
Member

@wraithgar wraithgar May 1, 2024

Choose a reason for hiding this comment

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

Well then my memory of the situation was wrong. I must have gotten optional and optional peer dependencies confused. Thanks.

@wraithgar
Copy link
Member

Small grammar suggestion and we can land this.

@wraithgar wraithgar merged commit f6fff32 into npm:latest May 1, 2024
7 checks passed
@xuhdev xuhdev deleted the patch-2 branch May 1, 2024 19:26
@github-actions github-actions bot mentioned this pull request May 1, 2024
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.

None yet

2 participants