Reputation: 4404
Let's say i have a library that contains multiple parts, say A and B.
In an application I require that library but use part A only. That is defined thru an config setting in the application that can read dynamically.
Now A and B have different requirements to other packages.
How could I only require A dependencies if only A is used?
The obvious answer would be to split that library into two libraries. But the library is currently not split and that would require a big effort of work and would completely change the workflow - which we don't want. Think of eg. Zend Framework which is also only a single library.
Upvotes: 0
Views: 55
Reputation: 41934
The best way to do this is by removing both A and B from your "require" section and adding them to the "suggest" section instead (including a short description):
{
...
"suggest": {
"a/a": "to be able to use X (1.*)",
"b/b": "to be able to use Y (~1.3)"
}
}
Now, when a user installs the package, it'll get a message showing the suggested packages:
package/package suggests installing "a/a": to be able to use X (1.*)
package/package susgests installing "b/b": to be able to use Y (~1.3)
The user installing the package should now determine theirselves if they want to also require "a/a" or "b/b".
While this solution is one of the most used and most simple, it is a better option to split the package. See also "There’s no such thing as an optional dependency"
Upvotes: 1