"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/prune.js" (7 Feb 2017, 1532 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 // prune extraneous packages.
    2 
    3 module.exports = prune
    4 
    5 prune.usage = 'npm prune [[<@scope>/]<pkg>...] [--production]'
    6 
    7 var readInstalled = require('read-installed')
    8 var npm = require('./npm.js')
    9 var path = require('path')
   10 var readJson = require('read-package-json')
   11 var log = require('npmlog')
   12 
   13 prune.completion = require('./utils/completion/installed-deep.js')
   14 
   15 function prune (args, cb) {
   16   // check if is a valid package.json file
   17   var jsonFile = path.resolve(npm.dir, '..', 'package.json')
   18   readJson(jsonFile, log.warn, function (er) {
   19     if (er) return cb(er)
   20     next()
   21   })
   22 
   23   function next () {
   24     var opt = {
   25       depth: npm.config.get('depth'),
   26       dev: !npm.config.get('production') || npm.config.get('dev')
   27     }
   28     readInstalled(npm.prefix, opt, function (er, data) {
   29       if (er) return cb(er)
   30       prune_(args, data, cb)
   31     })
   32   }
   33 }
   34 
   35 function prune_ (args, data, cb) {
   36   npm.commands.unbuild(prunables(args, data, []), cb)
   37 }
   38 
   39 function prunables (args, data, seen) {
   40   var deps = data.dependencies || {}
   41   return Object.keys(deps).map(function (d) {
   42     if (typeof deps[d] !== 'object' || seen.indexOf(deps[d]) !== -1) return null
   43     seen.push(deps[d])
   44     if (deps[d].extraneous && (args.length === 0 || args.indexOf(d) !== -1)) {
   45       var extra = deps[d]
   46       delete deps[d]
   47       return extra.path
   48     }
   49     return prunables(args, deps[d], seen)
   50   }).filter(function (d) { return d !== null })
   51   .reduce(function FLAT (l, r) {
   52     return l.concat(Array.isArray(r) ? r.reduce(FLAT, []) : r)
   53   }, [])
   54 }