UNPKG

1.19 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 , lifecycle = require("./utils/lifecycle.js")
14 , asyncMap = require("slide").asyncMap
15 , log = require("npmlog")
16
17 // load these, just so that we know that they'll be available, in case
18 // npm itself is getting overwritten.
19 , install = require("./install.js")
20 , build = require("./build.js")
21
22update.completion = npm.commands.outdated.completion
23
24function update (args, cb) {
25 npm.commands.outdated(args, true, function (er, outdated) {
26 log.info("outdated", "updating", outdated)
27 if (er) return cb(er)
28
29 asyncMap(outdated, function (ww, cb) {
30 // [[ dir, dep, has, want, req ]]
31 var where = ww[0]
32 , dep = ww[1]
33 , want = ww[3]
34 , what = dep + "@" + want
35 , req = ww[5]
36 , url = require('url')
37
38 // use the initial installation method (repo, tar, git) for updating
39 if (url.parse(req).protocol) what = req
40 npm.commands.install(where, what, cb)
41 }, cb)
42 })
43}