From 6dcadb9fc8618d45e696169135141dde4a9780b0 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 12 Feb 2013 12:03:52 -0800 Subject: [PATCH] blog: Peer Dependencies article Thanks, @domenic --- doc/blog/npm/peer-dependencies.md | 133 ++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 doc/blog/npm/peer-dependencies.md diff --git a/doc/blog/npm/peer-dependencies.md b/doc/blog/npm/peer-dependencies.md new file mode 100644 index 00000000000..97cb990ead8 --- /dev/null +++ b/doc/blog/npm/peer-dependencies.md @@ -0,0 +1,133 @@ +category: npm +title: Peer Dependencies +date: 2013-02-08T00:00:00Z +author: Domenic Denicola + +Reposted from [Domenic's +blog](http://domenic.me/2013/02/08/peer-dependencies/) with +permission. Thanks! + +npm is awesome as a package manager. In particular, it handles sub-dependencies very well: if my package depends on +`request` version 2 and `some-other-library`, but `some-other-library` depends on `request` version 1, the resulting +dependency graph looks like: + +```text +├── request@2.12.0 +└─┬ some-other-library@1.2.3 + └── request@1.9.9 +``` + +This is, generally, great: now `some-other-library` has its own copy of `request` v1 that it can use, while not +interfering with my package's v2 copy. Everyone's code works! + +## The Problem: Plugins + +There's one use case where this falls down, however: *plugins*. A plugin package is meant to be used with another "host" +package, even though it does not always directly *use* the host package. There are many examples of this pattern in the +Node.js package ecosystem already: + +- Grunt [plugins](http://gruntjs.com/#plugins-all) +- Chai [plugins](http://chaijs.com/plugins) +- Levelup [plugins](https://npmjs.org/package/level-hooks) +- Express [middleware](http://expressjs.com/api.html#middleware) +- Winston [transports](https://github.com/flatiron/winston/blob/master/docs/transports.md) + +Even if you're not familiar with any of those use cases, surely you recall "jQuery plugins" from back when you were a +client-side developer: little `