christopherthielen / check-peer-dependencies

Checks peer dependencies of the current NodeJS package. Offers solutions for any that are unmet.
MIT License
60 stars 19 forks source link

fix: ignore peer dependencies of root package #55

Open danielterwiel opened 8 months ago

danielterwiel commented 8 months ago

This change will ignore the check for peerDependencies of the root package. Only consumers of this package should be checked for this peerDependency, not the package itself.

peerDependencies

In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.

Usecase

You are creating a library relying on react 18, but you don't want to bundle react, so you define a peerDependency. It will not pass check-peer-dependencies.

Reproduction

Add this to this project's package.json on the master branch (v4.3.0):

  "peerDependencies": {
    "react": "18.2.0"
  }
npm run build
node dist/cli.js

It will fail because the package itself requires react to be installed. While a peerDependency signals that the consumer of the package should satisify the installation of the peerDependency. Not the package itself.

NOTE: bumped version by a major version as this reduces strictness on which consumers of this package may rely on