"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/rebuild.js" (8 Mar 2017, 2160 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 
    2 module.exports = rebuild
    3 
    4 var readInstalled = require('read-installed')
    5 var semver = require('semver')
    6 var log = require('npmlog')
    7 var npm = require('./npm.js')
    8 var npa = require('npm-package-arg')
    9 var usage = require('./utils/usage')
   10 var output = require('./utils/output.js')
   11 
   12 rebuild.usage = usage(
   13   'rebuild',
   14   'npm rebuild [[<@scope>/<name>]...]'
   15 )
   16 
   17 rebuild.completion = require('./utils/completion/installed-deep.js')
   18 
   19 function rebuild (args, cb) {
   20   var opt = { depth: npm.config.get('depth'), dev: true }
   21   readInstalled(npm.prefix, opt, function (er, data) {
   22     log.info('readInstalled', typeof data)
   23     if (er) return cb(er)
   24     var set = filter(data, args)
   25     var folders = Object.keys(set).filter(function (f) {
   26       return f !== npm.prefix
   27     })
   28     if (!folders.length) return cb()
   29     log.silly('rebuild set', folders)
   30     cleanBuild(folders, set, cb)
   31   })
   32 }
   33 
   34 function cleanBuild (folders, set, cb) {
   35   npm.commands.build(folders, function (er) {
   36     if (er) return cb(er)
   37     output(folders.map(function (f) {
   38       return set[f] + ' ' + f
   39     }).join('\n'))
   40     cb()
   41   })
   42 }
   43 
   44 function filter (data, args, set, seen) {
   45   if (!set) set = {}
   46   if (!seen) seen = {}
   47   if (set.hasOwnProperty(data.path)) return set
   48   if (seen.hasOwnProperty(data.path)) return set
   49   seen[data.path] = true
   50   var pass
   51   if (!args.length) pass = true // rebuild everything
   52   else if (data.name && data._id) {
   53     for (var i = 0, l = args.length; i < l; i++) {
   54       var arg = args[i]
   55       var nv = npa(arg)
   56       var n = nv.name
   57       var v = nv.rawSpec
   58       if (n !== data.name) continue
   59       if (!semver.satisfies(data.version, v, true)) continue
   60       pass = true
   61       break
   62     }
   63   }
   64   if (pass && data._id) {
   65     log.verbose('rebuild', 'path, id', [data.path, data._id])
   66     set[data.path] = data._id
   67   }
   68   // need to also dive through kids, always.
   69   // since this isn't an install these won't get auto-built unless
   70   // they're not dependencies.
   71   Object.keys(data.dependencies || {}).forEach(function (d) {
   72     // return
   73     var dep = data.dependencies[d]
   74     if (typeof dep === 'string') return
   75     filter(dep, args, set, seen)
   76   })
   77   return set
   78 }