"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/config/load-prefix.js" (8 Mar 2017, 1333 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 module.exports = loadPrefix
    2 
    3 var findPrefix = require('./find-prefix.js')
    4 var path = require('path')
    5 
    6 function loadPrefix (cb) {
    7   var cli = this.list[0]
    8 
    9   Object.defineProperty(this, 'prefix',
   10     {
   11       set: function (prefix) {
   12         var g = this.get('global')
   13         this[g ? 'globalPrefix' : 'localPrefix'] = prefix
   14       }.bind(this),
   15       get: function () {
   16         var g = this.get('global')
   17         return g ? this.globalPrefix : this.localPrefix
   18       }.bind(this),
   19       enumerable: true
   20     })
   21 
   22   Object.defineProperty(this, 'globalPrefix',
   23     {
   24       set: function (prefix) {
   25         this.set('prefix', prefix)
   26       }.bind(this),
   27       get: function () {
   28         return path.resolve(this.get('prefix'))
   29       }.bind(this),
   30       enumerable: true
   31     })
   32 
   33   var p
   34   Object.defineProperty(this, 'localPrefix',
   35     { set: function (prefix) { p = prefix },
   36       get: function () { return p },
   37     enumerable: true })
   38 
   39   // try to guess at a good node_modules location.
   40   // If we are *explicitly* given a prefix on the cli, then
   41   // always use that.  otherwise, infer local prefix from cwd.
   42   if (Object.prototype.hasOwnProperty.call(cli, 'prefix')) {
   43     p = path.resolve(cli.prefix)
   44     process.nextTick(cb)
   45   } else {
   46     findPrefix(process.cwd(), function (er, found) {
   47       p = found
   48       cb(er)
   49     })
   50   }
   51 }