What exactly are peer dependencies and plugins

Viewed 1165

I've came across many articles and posts that discuss the topic of peer dependencies but haven't really grasped the concept. From what I understand, if coffee 1.0 depends on milk 1.0, I will have coffee 1.0 listed in my package.json file under dependencies and when I install my dependencies, milk 1.0 will automatically be downloaded in the node modules. If this is the case, what purpose do peer dependencies serve? In addition, what are plugins? All definitions explain them in terms of a host, but what would the host be in consideration of my aforementioned example?

1 Answers

What's a plugin

Let's take the example of Express JS. It's a Node.js web framework. It's a host package in the sense that it has many other packages inside (plugin packages) it to make things work. But these packages may not use Express JS for their functionality.

Twitter Bootstrap for example is a host package where let's say version 4.3 has jQuery version 3.1. jQuery is a plugin package which you're using inside Twitter Bootstrap. jQuery is a plugin for Twitter Bootstrap but jQuery doesn't use Twitter Bootstrap for its functionality.

What's a peer dependency

They are "dependencies" between plugins and their host package. Some way of saying, "I only work when plugged in to version 1.2.x of my host package, so if you install me, be sure that it's alongside a compatible host." We call this relationship a peer dependency.

source

Related