$57 GRAYBYTE WORDPRESS FILE MANAGER $64

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/lib/node_modules/npm/lib/install/action/

HOME
Current File : /usr/lib/node_modules/npm/lib/install/action//remove.js
'use strict'
var path = require('path')
var fs = require('graceful-fs')
var rimraf = require('rimraf')
var asyncMap = require('slide').asyncMap
var mkdirp = require('gentle-fs').mkdir
var npm = require('../../npm.js')
var andIgnoreErrors = require('../and-ignore-errors.js')
var move = require('../../utils/move.js')
var isInside = require('path-is-inside')
var vacuum = require('fs-vacuum')

// This is weird because we want to remove the module but not it's node_modules folder
// allowing for this allows us to not worry about the order of operations
module.exports = function (staging, pkg, log, next) {
  log.silly('remove', pkg.path)
  if (pkg.target) {
    removeLink(pkg, next)
  } else {
    removeDir(pkg, log, next)
  }
}

function removeLink (pkg, next) {
  var base = isInside(pkg.path, npm.prefix) ? npm.prefix : pkg.path
  rimraf(pkg.path, (err) => {
    if (err) return next(err)
    vacuum(pkg.path, {base: base}, next)
  })
}

function removeDir (pkg, log, next) {
  var modpath = path.join(path.dirname(pkg.path), '.' + path.basename(pkg.path) + '.MODULES')

  move(path.join(pkg.path, 'node_modules'), modpath).then(unbuildPackage, unbuildPackage)

  function unbuildPackage (moveEr) {
    rimraf(pkg.path, moveEr ? andRemoveEmptyParents(pkg.path) : moveModulesBack)
  }

  function andRemoveEmptyParents (path) {
    return function (er) {
      if (er) return next(er)
      removeEmptyParents(pkg.path)
    }
  }

  function moveModulesBack () {
    fs.readdir(modpath, makeTarget)
  }

  function makeTarget (readdirEr, files) {
    if (readdirEr) return cleanup()
    if (!files.length) return cleanup()
    mkdirp(path.join(pkg.path, 'node_modules'), function (mkdirEr) { moveModules(mkdirEr, files) })
  }

  function moveModules (mkdirEr, files) {
    if (mkdirEr) return next(mkdirEr)
    asyncMap(files, function (file, done) {
      var from = path.join(modpath, file)
      var to = path.join(pkg.path, 'node_modules', file)
      // we ignore errors here, because they can legitimately happen, for instance,
      // bundled modules will be in both node_modules folders
      move(from, to).then(andIgnoreErrors(done), andIgnoreErrors(done))
    }, cleanup)
  }

  function cleanup () {
    rimraf(modpath, afterCleanup)
  }

  function afterCleanup (rimrafEr) {
    if (rimrafEr) log.warn('remove', rimrafEr)
    removeEmptyParents(path.resolve(pkg.path, '..'))
  }

  function removeEmptyParents (pkgdir) {
    fs.rmdir(pkgdir, function (er) {
      // FIXME: Make sure windows does what we want here
      if (er && er.code !== 'ENOENT') return next()
      removeEmptyParents(path.resolve(pkgdir, '..'))
    })
  }
}

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
31 Aug 2024 8.02 AM
root / root
0755
build.js
0.402 KB
10 Mar 2021 9.36 PM
root / root
0644
extract-worker.js
0.462 KB
10 Mar 2021 9.36 PM
root / root
0644
extract.js
3.87 KB
10 Mar 2021 9.36 PM
root / root
0644
fetch.js
0.512 KB
10 Mar 2021 9.36 PM
root / root
0644
finalize.js
3.814 KB
10 Mar 2021 9.36 PM
root / root
0644
global-install.js
0.641 KB
10 Mar 2021 9.36 PM
root / root
0644
global-link.js
0.282 KB
10 Mar 2021 9.36 PM
root / root
0644
install.js
0.26 KB
10 Mar 2021 9.36 PM
root / root
0644
move.js
3.094 KB
10 Mar 2021 9.36 PM
root / root
0644
postinstall.js
0.268 KB
10 Mar 2021 9.36 PM
root / root
0644
preinstall.js
0.266 KB
10 Mar 2021 9.36 PM
root / root
0644
prepare.js
1.03 KB
10 Mar 2021 9.36 PM
root / root
0644
refresh-package-json.js
1.495 KB
10 Mar 2021 9.36 PM
root / root
0644
remove.js
2.592 KB
10 Mar 2021 9.36 PM
root / root
0644
unbuild.js
0.644 KB
10 Mar 2021 9.36 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF