3

When expressing the dependencies of a Debian package, you can use syntax like exim | mail-transport-agent to indicate that your package needs either exim or mail-transport-agent, but it doesn't care which.

I want to express something similar in NPM. Is there a way to do it? Specifically suppose I want my application to express a dependency on either mikesthing-impl1 v1.7 better or mikesthing-impl2 v2.1 or better. I'd like to be able to say something like:

dependencies: {
  "mikesthing": {
    "mikesthing-impl1": "^1.7",
    "mikesthing-impl2": "^2.1"
  }
}

Is there a way?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Mike Taylor
  • 733
  • 1
  • 5
  • 5

1 Answers1

2

No, there is no functionality within a package.json to specify that sort of logic. However, you can implement a postinstall script in the scripts that will be executed after all other dependencies have been installed and in which you can script out this kind (or any kind) of behavior.

e.g. (in package.json)

"scripts": {
  "postinstall": "./bin/postinstall"

A good place to start is to run npm view {package} to get back a JSON object that details what versions are available in the registry.

CaptEmulation
  • 4,416
  • 2
  • 17
  • 14
  • Thanks for this bad news -- hey, it's better to know, right? Unfortunately, a postinstall script won't get me what I want in this case. I could write a script that rejects the present package's installation unless at least one of the alternative dependencies is in place, but that would be a procedural implementation. What I need is a declaration -- something that other code can look at and understand. Oh well. You can't always get what you want. – Mike Taylor Aug 29 '17 at 09:58