npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Allow any one of specified packages in peerDependencies

This is a feature request.

Currently, NPM checks for all the packages specified in peerDependencies.

Devs should be able to specify a list of packages with versions and tell NPM that if any one of these packages is present, the peer dep is satisfied.

Use Case
I maintain a Linter. It has a plugin mechanism similar to ESLint’s. All plugins should specify the linter’s NPM package name and version range in their peerDependencies.

The problem is - I recently had to change the name of this linter. It is now available from both the old NPM package name (let’s call that foo) and the new one (bar).

Now, the plugins for this linter should be able to tell NPM that either foo or bar is acceptable as a peer dep.

I’m thinking something on the lines of:

  "peerDependencies": {
    "anyOf": [
      { "foo": "^1.0.3", "bar": "^1.0.0" },
      { "lorem": "^1.0.3", "ipsum": "^1.0.0" }

The above translates to: I want either foo or bar AND either lorem or ipsum to satisfy my peer deps.

Before I refine this idea, I’d like to know if this is a reasonable request.
Happy to clarify any doubts.

See original issue
See the code where the changes will be required.

(I’m totally new to this forum and went through the community guidelines, but in case you find something wrong with my post, let me know.)

No worries, your post is good :+1:t3:


I believe that this question will become even more relevant, now that @hapi/hapi has been published. Packages that depended on hapi >= 17 are likely still compatible with @hapi/hapi >= 17.9.0 <= 18.3.1, but I can’t suss out how to specify a semver statement that refers to two different packages at the same time, such that either hapi or @hapi/hapi are installed.

I believe that this will require plugin authors to provide a new revision to target the new @hapi/hapi, with no other changes, and then consumers of their plugin will need to carefully choose which version of the plugin they specify based on what Hapi release is being used in their project. That seems sub-optimal.