]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/config/defaults.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / config / defaults.js
1 // defaults, types, and shorthands.
2
3
4 var path = require("path")
5   , url = require("url")
6   , Stream = require("stream").Stream
7   , semver = require("semver")
8   , stableFamily = semver.parse(process.version)
9   , nopt = require("nopt")
10   , os = require("os")
11   , osenv = require("osenv")
12   , umask = require("../utils/umask")
13
14 var log
15 try {
16   log = require("npmlog")
17 } catch (er) {
18   var util = require("util")
19   log = { warn: function (m) {
20     console.warn(m + " " + util.format.apply(util, [].slice.call(arguments, 1)))
21   } }
22 }
23
24 exports.Umask = Umask
25 function Umask () {}
26 function validateUmask (data, k, val) {
27   return umask.validate(data, k, val)
28 }
29
30 function validateSemver (data, k, val) {
31   if (!semver.valid(val)) return false
32   data[k] = semver.valid(val)
33 }
34
35 function validateStream (data, k, val) {
36   if (!(val instanceof Stream)) return false
37   data[k] = val
38 }
39
40 nopt.typeDefs.semver = { type: semver, validate: validateSemver }
41 nopt.typeDefs.Stream = { type: Stream, validate: validateStream }
42 nopt.typeDefs.Umask = { type: Umask, validate: validateUmask }
43
44 nopt.invalidHandler = function (k, val, type) {
45   log.warn("invalid config", k + "=" + JSON.stringify(val))
46
47   if (Array.isArray(type)) {
48     if (type.indexOf(url) !== -1) type = url
49     else if (type.indexOf(path) !== -1) type = path
50   }
51
52   switch (type) {
53     case Umask:
54       log.warn("invalid config", "Must be umask, octal number in range 0000..0777")
55       break
56     case url:
57       log.warn("invalid config", "Must be a full url with 'http://'")
58       break
59     case path:
60       log.warn("invalid config", "Must be a valid filesystem path")
61       break
62     case Number:
63       log.warn("invalid config", "Must be a numeric value")
64       break
65     case Stream:
66       log.warn("invalid config", "Must be an instance of the Stream class")
67       break
68   }
69 }
70
71 if (!stableFamily || (+stableFamily.minor % 2)) stableFamily = null
72 else stableFamily = stableFamily.major + "." + stableFamily.minor
73
74 var defaults
75
76 var temp = osenv.tmpdir()
77 var home = osenv.home()
78
79 var uidOrPid = process.getuid ? process.getuid() : process.pid
80
81 if (home) process.env.HOME = home
82 else home = path.resolve(temp, "npm-" + uidOrPid)
83
84 var cacheExtra = process.platform === "win32" ? "npm-cache" : ".npm"
85 var cacheRoot = process.platform === "win32" && process.env.APPDATA || home
86 var cache = path.resolve(cacheRoot, cacheExtra)
87
88
89 var globalPrefix
90 Object.defineProperty(exports, "defaults", {get: function () {
91   if (defaults) return defaults
92
93   if (process.env.PREFIX) {
94     globalPrefix = process.env.PREFIX
95   } else if (process.platform === "win32") {
96     // c:\node\node.exe --> prefix=c:\node\
97     globalPrefix = path.dirname(process.execPath)
98   } else {
99     // /usr/local/bin/node --> prefix=/usr/local
100     globalPrefix = path.dirname(path.dirname(process.execPath))
101
102     // destdir only is respected on Unix
103     if (process.env.DESTDIR) {
104       globalPrefix = path.join(process.env.DESTDIR, globalPrefix)
105     }
106   }
107
108   defaults = {
109     access : null
110     , "always-auth" : false
111
112     , "bin-links" : true
113     , browser : null
114
115     , ca: null
116     , cafile: null
117
118     , cache : cache
119
120     , "cache-lock-stale": 60000
121     , "cache-lock-retries": 10
122     , "cache-lock-wait": 10000
123
124     , "cache-max": Infinity
125     , "cache-min": 10
126
127     , cert: null
128
129     , color : true
130     , depth: Infinity
131     , description : true
132     , dev : false
133     , editor : osenv.editor()
134     , "engine-strict": false
135     , force : false
136
137     , "fetch-retries": 2
138     , "fetch-retry-factor": 10
139     , "fetch-retry-mintimeout": 10000
140     , "fetch-retry-maxtimeout": 60000
141
142     , git: "git"
143     , "git-tag-version": true
144
145     , global : false
146     , globalconfig : path.resolve(globalPrefix, "etc", "npmrc")
147     , group : process.platform === "win32" ? 0
148             : process.env.SUDO_GID || (process.getgid && process.getgid())
149     , heading: "npm"
150     , "if-present": false
151     , "ignore-scripts": false
152     , "init-module": path.resolve(home, ".npm-init.js")
153     , "init-author-name" : ""
154     , "init-author-email" : ""
155     , "init-author-url" : ""
156     , "init-version": "1.0.0"
157     , "init-license": "ISC"
158     , json: false
159     , key: null
160     , link: false
161     , "local-address" : undefined
162     , loglevel : "warn"
163     , logstream : process.stderr
164     , long : false
165     , maxsockets : 50
166     , message : "%s"
167     , "node-version" : process.version
168     , npat : false
169     , "onload-script" : false
170     , optional: true
171     , parseable : false
172     , prefix : globalPrefix
173     , production: process.env.NODE_ENV === "production"
174     , "proprietary-attribs": true
175     , proxy :  null
176     , "https-proxy" : null
177     , "user-agent" : "npm/{npm-version} "
178                      + "node/{node-version} "
179                      + "{platform} "
180                      + "{arch}"
181     , "rebuild-bundle" : true
182     , registry : "https://registry.npmjs.org/"
183     , rollback : true
184     , save : false
185     , "save-bundle": false
186     , "save-dev" : false
187     , "save-exact" : false
188     , "save-optional" : false
189     , "save-prefix": "^"
190     , scope : ""
191     , searchopts: ""
192     , searchexclude: null
193     , searchsort: "name"
194     , shell : osenv.shell()
195     , shrinkwrap: true
196     , "sign-git-tag": false
197     , spin: true
198     , "strict-ssl": true
199     , tag : "latest"
200     , "tag-version-prefix" : "v"
201     , tmp : temp
202     , unicode : true
203     , "unsafe-perm" : process.platform === "win32"
204                     || process.platform === "cygwin"
205                     || !( process.getuid && process.setuid
206                        && process.getgid && process.setgid )
207                     || process.getuid() !== 0
208     , usage : false
209     , user : process.platform === "win32" ? 0 : "nobody"
210     , userconfig : path.resolve(home, ".npmrc")
211     , umask: process.umask ? process.umask() : umask.fromString("022")
212     , version : false
213     , versions : false
214     , viewer: process.platform === "win32" ? "browser" : "man"
215
216     , _exit : true
217   }
218
219   return defaults
220 }})
221
222 exports.types =
223   { access : [null, "restricted", "public"]
224   , "always-auth" : Boolean
225   , "bin-links": Boolean
226   , browser : [null, String]
227   , ca: [null, String, Array]
228   , cafile : path
229   , cache : path
230   , "cache-lock-stale": Number
231   , "cache-lock-retries": Number
232   , "cache-lock-wait": Number
233   , "cache-max": Number
234   , "cache-min": Number
235   , cert: [null, String]
236   , color : ["always", Boolean]
237   , depth : Number
238   , description : Boolean
239   , dev : Boolean
240   , editor : String
241   , "engine-strict": Boolean
242   , force : Boolean
243   , "fetch-retries": Number
244   , "fetch-retry-factor": Number
245   , "fetch-retry-mintimeout": Number
246   , "fetch-retry-maxtimeout": Number
247   , git: String
248   , "git-tag-version": Boolean
249   , global : Boolean
250   , globalconfig : path
251   , group : [Number, String]
252   , "https-proxy" : [null, url]
253   , "user-agent" : String
254   , "heading": String
255   , "if-present": Boolean
256   , "ignore-scripts": Boolean
257   , "init-module": path
258   , "init-author-name" : String
259   , "init-author-email" : String
260   , "init-author-url" : ["", url]
261   , "init-license": String
262   , "init-version": semver
263   , json: Boolean
264   , key: [null, String]
265   , link: Boolean
266   // local-address must be listed as an IP for a local network interface
267   // must be IPv4 due to node bug
268   , "local-address" : getLocalAddresses()
269   , loglevel : ["silent", "error", "warn", "http", "info", "verbose", "silly"]
270   , logstream : Stream
271   , long : Boolean
272   , maxsockets : Number
273   , message: String
274   , "node-version" : [null, semver]
275   , npat : Boolean
276   , "onload-script" : [null, String]
277   , optional: Boolean
278   , parseable : Boolean
279   , prefix: path
280   , production: Boolean
281   , "proprietary-attribs": Boolean
282   , proxy : [null, false, url] // allow proxy to be disabled explicitly
283   , "rebuild-bundle" : Boolean
284   , registry : [null, url]
285   , rollback : Boolean
286   , save : Boolean
287   , "save-bundle": Boolean
288   , "save-dev" : Boolean
289   , "save-exact" : Boolean
290   , "save-optional" : Boolean
291   , "save-prefix": String
292   , scope : String
293   , searchopts : String
294   , searchexclude: [null, String]
295   , searchsort: [ "name", "-name"
296                 , "description", "-description"
297                 , "author", "-author"
298                 , "date", "-date"
299                 , "keywords", "-keywords" ]
300   , shell : String
301   , shrinkwrap: Boolean
302   , "sign-git-tag": Boolean
303   , spin: ["always", Boolean]
304   , "strict-ssl": Boolean
305   , tag : String
306   , tmp : path
307   , unicode : Boolean
308   , "unsafe-perm" : Boolean
309   , usage : Boolean
310   , user : [Number, String]
311   , userconfig : path
312   , umask: Umask
313   , version : Boolean
314   , "tag-version-prefix" : String
315   , versions : Boolean
316   , viewer: String
317   , _exit : Boolean
318   }
319
320 function getLocalAddresses () {
321   var interfaces
322   // #8094: some environments require elevated permissions to enumerate
323   // interfaces, and synchronously throw EPERM when run without
324   // elevated privileges
325   try {
326     interfaces = os.networkInterfaces()
327   } catch (e) {
328     interfaces = {}
329   }
330
331   return Object.keys(interfaces).map(function (nic) {
332     return interfaces[nic].filter(function (addr) {
333       return addr.family === 'IPv4'
334     })
335     .map(function (addr) {
336       return addr.address
337     })
338   }).reduce(function (curr, next) {
339     return curr.concat(next)
340   }, []).concat(undefined)
341 }
342
343 exports.shorthands =
344   { s : ["--loglevel", "silent"]
345   , d : ["--loglevel", "info"]
346   , dd : ["--loglevel", "verbose"]
347   , ddd : ["--loglevel", "silly"]
348   , noreg : ["--no-registry"]
349   , N : ["--no-registry"]
350   , reg : ["--registry"]
351   , "no-reg" : ["--no-registry"]
352   , silent : ["--loglevel", "silent"]
353   , verbose : ["--loglevel", "verbose"]
354   , quiet: ["--loglevel", "warn"]
355   , q: ["--loglevel", "warn"]
356   , h : ["--usage"]
357   , H : ["--usage"]
358   , "?" : ["--usage"]
359   , help : ["--usage"]
360   , v : ["--version"]
361   , f : ["--force"]
362   , gangster : ["--force"]
363   , gangsta : ["--force"]
364   , desc : ["--description"]
365   , "no-desc" : ["--no-description"]
366   , "local" : ["--no-global"]
367   , l : ["--long"]
368   , m : ["--message"]
369   , p : ["--parseable"]
370   , porcelain : ["--parseable"]
371   , g : ["--global"]
372   , S : ["--save"]
373   , D : ["--save-dev"]
374   , E : ["--save-exact"]
375   , O : ["--save-optional"]
376   , y : ["--yes"]
377   , n : ["--no-yes"]
378   , B : ["--save-bundle"]
379   , C : ["--prefix"]
380   }