Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
There is also a lesser known peerDependency section for creators of libraries!
peerDependency is useful when your library requires an upstream application to have a dependency installed.
An example is if you create a React component. You do not want to specify the dependency in the dependency section. It is possible this may create conflicts in the App. So instead you use the peerDependency section. This will tell the installer "Hey, this also needs React to work!"
Other use-cases of peerDependency is if a library is optional. For example, if I am writing a library that outputs some text to the console, I might check to see if colors is installed. If so, I will colorize the text, if not, then It'll just be black and white. It's up to the upstream application to install the dependency.
There is also a lesser known
peerDependency
section for creators of libraries!peerDependency
is useful when your library requires an upstream application to have a dependency installed.An example is if you create a React component. You do not want to specify the dependency in the
dependency
section. It is possible this may create conflicts in the App. So instead you use thepeerDependency
section. This will tell the installer "Hey, this also needs React to work!"Other use-cases of
peerDependency
is if a library is optional. For example, if I am writing a library that outputs some text to the console, I might check to see ifcolors
is installed. If so, I will colorize the text, if not, then It'll just be black and white. It's up to the upstream application to install the dependency.Cheers!
Thanks for sharing, that's really useful!