1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
module.exports = rebuild
var readInstalled = require("./utils/read-installed")
, asyncMap = require("./utils/async-map")
, semver = require("semver")
, log = require("./utils/log")
, path = require("path")
, npm = require("../npm")
rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]"
rebuild.completion = function (args, index, cb) {
var installedPkgs = require("./utils/completion/installed-packages")
installedPkgs(args, index, true, true, cb)
}
function rebuild (args, cb) {
readInstalled(npm.prefix, function (er, data) {
if (er) return cb(er)
var set = filter(data, args)
, folders = Object.keys(set)
if (!folders.length) return cb()
asyncMap(folders, npm.commands.build, function (er) {
if (er) return cb(er)
folders.forEach(function (f) {
console.log(set[f] + " " + f)
})
cb()
})
})
}
function filter (data, args, set) {
if (!set) set = {}
if (set.hasOwnProperty(data.path)) return set
var pass
if (!args.length) pass = true // rebuild everything
else if (data.name) {
for (var i = 0, l = args.length; i < l; i ++) {
var arg = args[i]
, nv = arg.split("@")
, n = nv.shift()
, v = nv.join("@")
if (n !== data.name) continue
if (!semver.satisfies(data.version, v)) continue
pass = true
break
}
}
if (pass) {
set[data.path] = data._id
}
// need to also dive through kids, always.
// since this isn't an install these won't get auto-built unless
// they're not dependencies.
Object.keys(data.dependencies || {}).forEach(function (d) {
var dep = data.dependencies[d]
if (typeof dep === "string") return
filter(dep, args, set)
})
return set
}
|