"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/uninstall.js" (7 Feb 2017, 2362 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 'use strict'
    2 // remove a package.
    3 
    4 module.exports = uninstall
    5 module.exports.Uninstaller = Uninstaller
    6 
    7 var util = require('util')
    8 var path = require('path')
    9 var validate = require('aproba')
   10 var chain = require('slide').chain
   11 var readJson = require('read-package-json')
   12 var npm = require('./npm.js')
   13 var Installer = require('./install.js').Installer
   14 var getSaveType = require('./install/save.js').getSaveType
   15 var removeDeps = require('./install/deps.js').removeDeps
   16 var loadExtraneous = require('./install/deps.js').loadExtraneous
   17 var log = require('npmlog')
   18 var usage = require('./utils/usage')
   19 
   20 uninstall.usage = usage(
   21   'uninstall',
   22   'npm uninstall [<@scope>/]<pkg>[@<version>]... [--save|--save-dev|--save-optional]'
   23 )
   24 
   25 uninstall.completion = require('./utils/completion/installed-shallow.js')
   26 
   27 function uninstall (args, cb) {
   28   validate('AF', arguments)
   29   // the /path/to/node_modules/..
   30   var dryrun = !!npm.config.get('dry-run')
   31 
   32   if (args.length === 1 && args[0] === '.') args = []
   33   args = args.filter(function (a) {
   34     return path.resolve(a) !== where
   35   })
   36 
   37   var where = npm.config.get('global') || !args.length
   38             ? path.resolve(npm.globalDir, '..')
   39             : npm.prefix
   40 
   41   if (args.length) {
   42     new Uninstaller(where, dryrun, args).run(cb)
   43   } else {
   44     // remove this package from the global space, if it's installed there
   45     readJson(path.resolve(npm.localPrefix, 'package.json'), function (er, pkg) {
   46       if (er && er.code !== 'ENOENT' && er.code !== 'ENOTDIR') return cb(er)
   47       if (er) return cb(uninstall.usage)
   48       new Uninstaller(where, dryrun, [pkg.name]).run(cb)
   49     })
   50   }
   51 }
   52 
   53 function Uninstaller (where, dryrun, args) {
   54   validate('SBA', arguments)
   55   Installer.call(this, where, dryrun, args)
   56 }
   57 util.inherits(Uninstaller, Installer)
   58 
   59 Uninstaller.prototype.loadArgMetadata = function (next) {
   60   this.args = this.args.map(function (arg) { return {name: arg} })
   61   next()
   62 }
   63 
   64 Uninstaller.prototype.loadAllDepsIntoIdealTree = function (cb) {
   65   validate('F', arguments)
   66   log.silly('uninstall', 'loadAllDepsIntoIdealtree')
   67   var saveDeps = getSaveType(this.args)
   68 
   69   var cg = this.progress.loadAllDepsIntoIdealTree
   70   var steps = []
   71 
   72   steps.push(
   73     [removeDeps, this.args, this.idealTree, saveDeps, cg.newGroup('removeDeps')],
   74     [loadExtraneous, this.idealTree, cg.newGroup('loadExtraneous')])
   75   chain(steps, cb)
   76 }