"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/config/defaults.js" (7 Feb 2017, 10221 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // defaults, types, and shorthands.
    2 
    3 var path = require('path')
    4 var url = require('url')
    5 var Stream = require('stream').Stream
    6 var semver = require('semver')
    7 var stableFamily = semver.parse(process.version)
    8 var nopt = require('nopt')
    9 var os = require('os')
   10 var osenv = require('osenv')
   11 var umask = require('../utils/umask')
   12 var hasUnicode = require('has-unicode')
   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 var globalPrefix
   89 Object.defineProperty(exports, 'defaults', {get: function () {
   90   if (defaults) return defaults
   91 
   92   if (process.env.PREFIX) {
   93     globalPrefix = process.env.PREFIX
   94   } else if (process.platform === 'win32') {
   95     // c:\node\node.exe --> prefix=c:\node\
   96     globalPrefix = path.dirname(process.execPath)
   97   } else {
   98     // /usr/local/bin/node --> prefix=/usr/local
   99     globalPrefix = path.dirname(path.dirname(process.execPath))
  100 
  101     // destdir only is respected on Unix
  102     if (process.env.DESTDIR) {
  103       globalPrefix = path.join(process.env.DESTDIR, globalPrefix)
  104     }
  105   }
  106 
  107   defaults = {
  108     access: null,
  109     'always-auth': false,
  110     also: null,
  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     'dry-run': false,
  134     editor: osenv.editor(),
  135     'engine-strict': false,
  136     force: false,
  137 
  138     'fetch-retries': 2,
  139     'fetch-retry-factor': 10,
  140     'fetch-retry-mintimeout': 10000,
  141     'fetch-retry-maxtimeout': 60000,
  142 
  143     git: 'git',
  144     'git-tag-version': true,
  145 
  146     global: false,
  147     globalconfig: path.resolve(globalPrefix, 'etc', 'npmrc'),
  148     'global-style': false,
  149     group: process.platform === 'win32' ? 0
  150             : process.env.SUDO_GID || (process.getgid && process.getgid()),
  151     heading: 'npm',
  152     'if-present': false,
  153     'ignore-scripts': false,
  154     'init-module': path.resolve(home, '.npm-init.js'),
  155     'init-author-name': '',
  156     'init-author-email': '',
  157     'init-author-url': '',
  158     'init-version': '1.0.0',
  159     'init-license': 'ISC',
  160     json: false,
  161     key: null,
  162     'legacy-bundling': false,
  163     link: false,
  164     'local-address': undefined,
  165     loglevel: 'warn',
  166     logstream: process.stderr,
  167     long: false,
  168     maxsockets: 50,
  169     message: '%s',
  170     'node-version': process.version,
  171     npat: false,
  172     'onload-script': false,
  173     only: null,
  174     optional: true,
  175     parseable: false,
  176     prefix: globalPrefix,
  177     production: process.env.NODE_ENV === 'production',
  178     'progress': !process.env.TRAVIS && !process.env.CI,
  179     'proprietary-attribs': true,
  180     proxy: null,
  181     'https-proxy': null,
  182     'user-agent': 'npm/{npm-version} ' +
  183                     'node/{node-version} ' +
  184                     '{platform} ' +
  185                     '{arch}',
  186     'rebuild-bundle': true,
  187     registry: 'https://registry.npmjs.org/',
  188     rollback: true,
  189     save: false,
  190     'save-bundle': false,
  191     'save-dev': false,
  192     'save-exact': false,
  193     'save-optional': false,
  194     'save-prefix': '^',
  195     scope: '',
  196     searchopts: '',
  197     searchexclude: null,
  198     searchsort: 'name',
  199     shell: osenv.shell(),
  200     shrinkwrap: true,
  201     'sign-git-tag': false,
  202     'strict-ssl': true,
  203     tag: 'latest',
  204     'tag-version-prefix': 'v',
  205     tmp: temp,
  206     unicode: hasUnicode(),
  207     'unsafe-perm': process.platform === 'win32' ||
  208                      process.platform === 'cygwin' ||
  209                      !(process.getuid && process.setuid &&
  210                        process.getgid && process.setgid) ||
  211                      process.getuid() !== 0,
  212     usage: false,
  213     user: process.platform === 'win32' ? 0 : 'nobody',
  214     userconfig: path.resolve(home, '.npmrc'),
  215     umask: process.umask ? process.umask() : umask.fromString('022'),
  216     version: false,
  217     versions: false,
  218     viewer: process.platform === 'win32' ? 'browser' : 'man',
  219 
  220     _exit: true
  221   }
  222 
  223   return defaults
  224 }})
  225 
  226 exports.types = {
  227   access: [null, 'restricted', 'public'],
  228   'always-auth': Boolean,
  229   also: [null, 'dev', 'development'],
  230   'bin-links': Boolean,
  231   browser: [null, String],
  232   ca: [null, String, Array],
  233   cafile: path,
  234   cache: path,
  235   'cache-lock-stale': Number,
  236   'cache-lock-retries': Number,
  237   'cache-lock-wait': Number,
  238   'cache-max': Number,
  239   'cache-min': Number,
  240   cert: [null, String],
  241   color: ['always', Boolean],
  242   depth: Number,
  243   description: Boolean,
  244   dev: Boolean,
  245   'dry-run': Boolean,
  246   editor: String,
  247   'engine-strict': Boolean,
  248   force: Boolean,
  249   'fetch-retries': Number,
  250   'fetch-retry-factor': Number,
  251   'fetch-retry-mintimeout': Number,
  252   'fetch-retry-maxtimeout': Number,
  253   git: String,
  254   'git-tag-version': Boolean,
  255   global: Boolean,
  256   globalconfig: path,
  257   'global-style': Boolean,
  258   group: [Number, String],
  259   'https-proxy': [null, url],
  260   'user-agent': String,
  261   'heading': String,
  262   'if-present': Boolean,
  263   'ignore-scripts': Boolean,
  264   'init-module': path,
  265   'init-author-name': String,
  266   'init-author-email': String,
  267   'init-author-url': ['', url],
  268   'init-license': String,
  269   'init-version': semver,
  270   json: Boolean,
  271   key: [null, String],
  272   'legacy-bundling': Boolean,
  273   link: Boolean,
  274   // local-address must be listed as an IP for a local network interface
  275   // must be IPv4 due to node bug
  276   'local-address': getLocalAddresses(),
  277   loglevel: ['silent', 'error', 'warn', 'http', 'info', 'verbose', 'silly'],
  278   logstream: Stream,
  279   long: Boolean,
  280   maxsockets: Number,
  281   message: String,
  282   'node-version': [null, semver],
  283   npat: Boolean,
  284   'onload-script': [null, String],
  285   only: [null, 'dev', 'development', 'prod', 'production'],
  286   optional: Boolean,
  287   parseable: Boolean,
  288   prefix: path,
  289   production: Boolean,
  290   progress: Boolean,
  291   'proprietary-attribs': Boolean,
  292   proxy: [null, false, url], // allow proxy to be disabled explicitly
  293   'rebuild-bundle': Boolean,
  294   registry: [null, url],
  295   rollback: Boolean,
  296   save: Boolean,
  297   'save-bundle': Boolean,
  298   'save-dev': Boolean,
  299   'save-exact': Boolean,
  300   'save-optional': Boolean,
  301   'save-prefix': String,
  302   scope: String,
  303   searchopts: String,
  304   searchexclude: [null, String],
  305   searchsort: [
  306     'name', '-name',
  307     'description', '-description',
  308     'author', '-author',
  309     'date', '-date',
  310     'keywords', '-keywords'
  311   ],
  312   shell: String,
  313   shrinkwrap: Boolean,
  314   'sign-git-tag': Boolean,
  315   'strict-ssl': Boolean,
  316   tag: String,
  317   tmp: path,
  318   unicode: Boolean,
  319   'unsafe-perm': Boolean,
  320   usage: Boolean,
  321   user: [Number, String],
  322   userconfig: path,
  323   umask: Umask,
  324   version: Boolean,
  325   'tag-version-prefix': String,
  326   versions: Boolean,
  327   viewer: String,
  328   _exit: Boolean
  329 }
  330 
  331 function getLocalAddresses () {
  332   var interfaces
  333   // #8094: some environments require elevated permissions to enumerate
  334   // interfaces, and synchronously throw EPERM when run without
  335   // elevated privileges
  336   try {
  337     interfaces = os.networkInterfaces()
  338   } catch (e) {
  339     interfaces = {}
  340   }
  341 
  342   return Object.keys(interfaces).map(function (nic) {
  343     return interfaces[nic].filter(function (addr) {
  344       return addr.family === 'IPv4'
  345     })
  346     .map(function (addr) {
  347       return addr.address
  348     })
  349   }).reduce(function (curr, next) {
  350     return curr.concat(next)
  351   }, []).concat(undefined)
  352 }
  353 
  354 exports.shorthands = {
  355   s: ['--loglevel', 'silent'],
  356   d: ['--loglevel', 'info'],
  357   dd: ['--loglevel', 'verbose'],
  358   ddd: ['--loglevel', 'silly'],
  359   noreg: ['--no-registry'],
  360   N: ['--no-registry'],
  361   reg: ['--registry'],
  362   'no-reg': ['--no-registry'],
  363   silent: ['--loglevel', 'silent'],
  364   verbose: ['--loglevel', 'verbose'],
  365   quiet: ['--loglevel', 'warn'],
  366   q: ['--loglevel', 'warn'],
  367   h: ['--usage'],
  368   H: ['--usage'],
  369   '?': ['--usage'],
  370   help: ['--usage'],
  371   v: ['--version'],
  372   f: ['--force'],
  373   gangster: ['--force'],
  374   gangsta: ['--force'],
  375   desc: ['--description'],
  376   'no-desc': ['--no-description'],
  377   'local': ['--no-global'],
  378   l: ['--long'],
  379   m: ['--message'],
  380   p: ['--parseable'],
  381   porcelain: ['--parseable'],
  382   g: ['--global'],
  383   S: ['--save'],
  384   D: ['--save-dev'],
  385   E: ['--save-exact'],
  386   O: ['--save-optional'],
  387   y: ['--yes'],
  388   n: ['--no-yes'],
  389   B: ['--save-bundle'],
  390   C: ['--prefix']
  391 }