UNPKG

1.14 kBJavaScriptView Raw
1/*
2for each pkg in prefix that isn't a git repo
3 look for a new version of pkg that satisfies dep
4 if so, install it.
5 if not, then update it
6*/
7
8module.exports = update
9
10update.usage = "npm update [pkg]"
11
12var npm = require("./npm.js")
13 , asyncMap = require("slide").asyncMap
14 , log = require("npmlog")
15
16 // load these, just so that we know that they'll be available, in case
17 // npm itself is getting overwritten.
18 , install = require("./install.js")
19 , build = require("./build.js")
20
21update.completion = npm.commands.outdated.completion
22
23function update (args, cb) {
24 npm.commands.outdated(args, true, function (er, outdated) {
25 log.info("outdated", "updating", outdated)
26 if (er) return cb(er)
27
28 asyncMap(outdated, function (ww, cb) {
29 // [[ dir, dep, has, want, req ]]
30 var where = ww[0]
31 , dep = ww[1]
32 , want = ww[3]
33 , what = dep + "@" + want
34 , req = ww[5]
35 , url = require('url')
36
37 // use the initial installation method (repo, tar, git) for updating
38 if (url.parse(req).protocol) what = req
39 npm.commands.install(where, what, cb)
40 }, cb)
41 })
42}