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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
process.title = "npm"
var npm = exports
, config = require("./lib/config")
, set = require("./lib/utils/set")
, get = require("./lib/utils/get")
, ini = require("./lib/utils/ini")
, log = require("./lib/utils/log")
, fs = require("./lib/utils/graceful-fs")
, errorHandler = require("./lib/utils/error-handler")
, path = require("path")
npm.commands = {}
npm.ELIFECYCLE = {}
npm.E404 = {}
if (process.getuid() === 0) {
log.error( "\nRunning npm as root is not recommended!\n"
+ "Seriously, don't do this!\n", "sudon't!")
}
try {
var j = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))+"")
npm.version = j.version
npm.nodeVersionRequired = j.engines.node
} catch (ex) {
log(ex, "error reading version")
npm.version = ex
}
var commandCache = {}
; [ "install"
, "activate"
, "deactivate"
, "uninstall"
, "build"
, "link"
, "publish"
, "tag"
, "adduser"
, "config"
, "help"
, "cache"
, "test"
, "stop"
, "start"
, "restart"
, "unpublish"
, "list"
, "ls"
, "rm"
, "owner"
, "update"
, "update-dependents"
, "view"
, "repl"
, "rebuild"
, "bundle"
, "outdated"
, "init"
].forEach(function (c) {
Object.defineProperty(npm.commands, c, { get : function () {
c = c === "list" ? "ls"
: c === "rm" ? "uninstall"
: c
if (c in commandCache) return commandCache[c]
return commandCache[c] = require(__dirname+"/lib/"+c)
}, enumerable: true})
})
npm.load = function (opts, cb) {
// don't assume that npm is installed in any particular spot, since this
// might conceivably be a bootstrap attempt.
var log = require("./lib/utils/log")
log.waitForConfig()
ini.resolveConfigs(conf, function (er) {
if (er) return errorHandler(er, opts.exit)
npm.config.set("root", ini.get("root"))
cb(null, true)
})
}
// Local store for package data, so it won't have to be fetched/read more than
// once in a single pass. TODO: cache this to disk somewhere when we're using
// the registry, to cut down on HTTP calls.
var registry = {}
npm.set = function (key, val) {
if (typeof key === "object" && !val && key._id) {
val = key
key = key._id
}
return set(registry, key, val)
}
npm.get = function (key) { return get(registry, key) }
var path = require("path")
npm.config =
{ get : function (key) { return ini.get(key) }
, set : function (key, val) { return ini.set(key, val, "cli") }
, del : function (key, val) { return ini.del(key, val, "cli") }
}
Object.defineProperty(npm, "root",
{ get : function () { return npm.config.get("root") }
, set : function (r) {
r = r.charAt(0) === "/" ? r
: path.join(process.execPath, "..", "..", r)
return npm.config.set("root", r)
}
, enumerable : true
})
Object.defineProperty(npm, "dir",
{ get : function () { return path.join(npm.root, ".npm") }
, enumerable : true
})
Object.defineProperty(npm, "cache",
{ get : function () { return path.join(npm.root, ".npm", ".cache") }
, enumerable : true
})
var tmpFolder
Object.defineProperty(npm, "tmp",
{ get : function () {
if (!tmpFolder) tmpFolder = "npm-"+Date.now()
return path.join(npm.config.get("tmproot"), tmpFolder)
}
, enumerable : true
})
|