aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/lib/install/action
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/install/action')
-rw-r--r--deps/npm/lib/install/action/extract-worker.js18
-rw-r--r--deps/npm/lib/install/action/extract.js57
-rw-r--r--deps/npm/lib/install/action/finalize.js2
-rw-r--r--deps/npm/lib/install/action/move.js10
-rw-r--r--deps/npm/lib/install/action/refresh-package-json.js13
-rw-r--r--deps/npm/lib/install/action/remove.js16
-rw-r--r--deps/npm/lib/install/action/unbuild.js16
7 files changed, 110 insertions, 22 deletions
diff --git a/deps/npm/lib/install/action/extract-worker.js b/deps/npm/lib/install/action/extract-worker.js
new file mode 100644
index 0000000000..24508c7804
--- /dev/null
+++ b/deps/npm/lib/install/action/extract-worker.js
@@ -0,0 +1,18 @@
+'use strict'
+
+const BB = require('bluebird')
+
+const extract = require('pacote/extract')
+const npmlog = require('npmlog')
+
+module.exports = (args, cb) => {
+ const parsed = typeof args === 'string' ? JSON.parse(args) : args
+ const spec = parsed[0]
+ const extractTo = parsed[1]
+ const opts = parsed[2]
+ if (!opts.log && opts.loglevel) {
+ opts.log = npmlog
+ opts.log.level = opts.loglevel
+ }
+ BB.resolve(extract(spec, extractTo, opts)).nodeify(cb)
+}
diff --git a/deps/npm/lib/install/action/extract.js b/deps/npm/lib/install/action/extract.js
index 437d7e57f7..5534e8b28a 100644
--- a/deps/npm/lib/install/action/extract.js
+++ b/deps/npm/lib/install/action/extract.js
@@ -2,19 +2,36 @@
const BB = require('bluebird')
-const fs = BB.promisifyAll(require('graceful-fs'))
+const stat = BB.promisify(require('graceful-fs').stat)
const gentlyRm = BB.promisify(require('../../utils/gently-rm.js'))
const log = require('npmlog')
const mkdirp = BB.promisify(require('mkdirp'))
const moduleName = require('../../utils/module-name.js')
const moduleStagingPath = require('../module-staging-path.js')
-const move = BB.promisify(require('../../utils/move.js'))
+const move = require('../../utils/move.js')
const npa = require('npm-package-arg')
+const npm = require('../../npm.js')
const packageId = require('../../utils/package-id.js')
-const pacote = require('pacote')
let pacoteOpts
const path = require('path')
+const localWorker = require('./extract-worker.js')
+const workerFarm = require('worker-farm')
+const WORKER_PATH = require.resolve('./extract-worker.js')
+let workers
+
+extract.init = () => {
+ workers = workerFarm({
+ maxConcurrentCallsPerWorker: npm.limit.fetch,
+ maxRetries: 1
+ }, WORKER_PATH)
+ return BB.resolve()
+}
+extract.teardown = () => {
+ workerFarm.end(workers)
+ workers = null
+ return BB.resolve()
+}
module.exports = extract
function extract (staging, pkg, log) {
log.silly('extract', packageId(pkg))
@@ -25,14 +42,34 @@ function extract (staging, pkg, log) {
const opts = pacoteOpts({
integrity: pkg.package._integrity
})
- return pacote.extract(
+ const args = [
pkg.package._resolved
? npa.resolve(pkg.package.name, pkg.package._resolved)
: pkg.package._requested,
extractTo,
opts
- ).then(() => {
- if (pkg.package.bundleDependencies) {
+ ]
+ return BB.fromNode((cb) => {
+ let launcher = localWorker
+ let msg = args
+ const spec = typeof args[0] === 'string' ? npa(args[0]) : args[0]
+ args[0] = spec.raw
+ if (spec.registry || spec.type === 'remote') {
+ // We can't serialize these options
+ opts.loglevel = opts.log.level
+ opts.log = null
+ opts.dirPacker = null
+ // workers will run things in parallel!
+ launcher = workers
+ try {
+ msg = JSON.stringify(msg)
+ } catch (e) {
+ return cb(e)
+ }
+ }
+ launcher(msg, cb)
+ }).then(() => {
+ if (pkg.package.bundleDependencies || anyBundled(pkg)) {
return readBundled(pkg, staging, extractTo)
}
}).then(() => {
@@ -40,8 +77,14 @@ function extract (staging, pkg, log) {
})
}
+function anyBundled (top, pkg) {
+ if (!pkg) pkg = top
+ return pkg.children.some((child) => child.fromBundle === top || anyBundled(top, child))
+}
+
function readBundled (pkg, staging, extractTo) {
return BB.map(pkg.children, (child) => {
+ if (!child.fromBundle) return
if (child.error) {
throw child.error
} else {
@@ -84,7 +127,7 @@ function finishModule (bundler, child, stageTo, stageFrom) {
return move(stageFrom, stageTo)
})
} else {
- return fs.statAsync(stageFrom).then(() => {
+ return stat(stageFrom).then(() => {
const bundlerId = packageId(bundler)
if (!getTree(bundler).warnings.some((w) => {
return w.code === 'EBUNDLEOVERRIDE'
diff --git a/deps/npm/lib/install/action/finalize.js b/deps/npm/lib/install/action/finalize.js
index ded2350dff..a50ec8a6bd 100644
--- a/deps/npm/lib/install/action/finalize.js
+++ b/deps/npm/lib/install/action/finalize.js
@@ -91,5 +91,5 @@ module.exports = function (staging, pkg, log) {
module.exports.rollback = function (top, staging, pkg, next) {
const requested = pkg.package._requested || getRequested(pkg)
if (requested && requested.type === 'directory') return next()
- gentlyRm(pkg.realpath, false, top, next)
+ gentlyRm(pkg.path, false, top, next)
}
diff --git a/deps/npm/lib/install/action/move.js b/deps/npm/lib/install/action/move.js
index 07649c3556..bc9bf6a883 100644
--- a/deps/npm/lib/install/action/move.js
+++ b/deps/npm/lib/install/action/move.js
@@ -46,7 +46,7 @@ function moveModuleOnly (from, to, log, done) {
log.silly('move', 'move existing destination node_modules away', toModules)
- move(toModules, tempToModules, removeDestination(done))
+ move(toModules, tempToModules).then(removeDestination(done), removeDestination(done))
function removeDestination (next) {
return function (er) {
@@ -62,7 +62,7 @@ function moveModuleOnly (from, to, log, done) {
function moveToModulesBack (next) {
return function () {
log.silly('move', 'move existing destination node_modules back', toModules)
- move(tempToModules, toModules, iferr(done, next))
+ move(tempToModules, toModules).then(next, done)
}
}
@@ -76,14 +76,14 @@ function moveModuleOnly (from, to, log, done) {
function moveNodeModules (next) {
return function () {
log.silly('move', 'move source node_modules away', fromModules)
- move(fromModules, tempFromModules, iferr(doMove(next), doMove(moveNodeModulesBack(next))))
+ move(fromModules, tempFromModules).then(doMove(moveNodeModulesBack(next)), doMove(next))
}
}
function doMove (next) {
return function () {
log.silly('move', 'move module dir to final dest', from, to)
- move(from, to, iferr(done, next))
+ move(from, to).then(next, done)
}
}
@@ -91,7 +91,7 @@ function moveModuleOnly (from, to, log, done) {
return function () {
mkdirp(from, iferr(done, function () {
log.silly('move', 'put source node_modules back', fromModules)
- move(tempFromModules, fromModules, iferr(done, next))
+ move(tempFromModules, fromModules).then(next, done)
}))
}
}
diff --git a/deps/npm/lib/install/action/refresh-package-json.js b/deps/npm/lib/install/action/refresh-package-json.js
index 6910803451..42f8012100 100644
--- a/deps/npm/lib/install/action/refresh-package-json.js
+++ b/deps/npm/lib/install/action/refresh-package-json.js
@@ -1,16 +1,20 @@
'use strict'
-const path = require('path')
+
const Bluebird = require('bluebird')
+
+const checkPlatform = Bluebird.promisify(require('npm-install-checks').checkPlatform)
+const getRequested = require('../get-requested.js')
+const npm = require('../../npm.js')
+const path = require('path')
const readJson = Bluebird.promisify(require('read-package-json'))
const updatePackageJson = Bluebird.promisify(require('../update-package-json'))
-const getRequested = require('../get-requested.js')
module.exports = function (staging, pkg, log) {
log.silly('refresh-package-json', pkg.realpath)
return readJson(path.join(pkg.path, 'package.json'), false).then((metadata) => {
Object.keys(pkg.package).forEach(function (key) {
- if (!isEmpty(pkg.package[key])) {
+ if (key !== 'dependencies' && !isEmpty(pkg.package[key])) {
metadata[key] = pkg.package[key]
}
})
@@ -22,7 +26,10 @@ module.exports = function (staging, pkg, log) {
delete metadata.readmeFilename
pkg.package = metadata
+ pkg.fakeChild = false
}).catch(() => 'ignore').then(() => {
+ return checkPlatform(pkg.package, npm.config.get('force'))
+ }).then(() => {
const requested = pkg.package._requested || getRequested(pkg)
if (requested.type !== 'directory') {
return updatePackageJson(pkg, pkg.path)
diff --git a/deps/npm/lib/install/action/remove.js b/deps/npm/lib/install/action/remove.js
index 9fe77c35e0..a852d10c5f 100644
--- a/deps/npm/lib/install/action/remove.js
+++ b/deps/npm/lib/install/action/remove.js
@@ -7,6 +7,8 @@ var mkdirp = require('mkdirp')
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
@@ -20,18 +22,20 @@ module.exports = function (staging, pkg, log, next) {
}
function removeLink (pkg, next) {
- npm.commands.unbuild(pkg.path, true, 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, unbuildPackage)
+ move(path.join(pkg.path, 'node_modules'), modpath).then(unbuildPackage, unbuildPackage)
function unbuildPackage (moveEr) {
- npm.commands.unbuild(pkg.path, true, function () {
- rimraf(pkg.path, moveEr ? andRemoveEmptyParents(pkg.path) : moveModulesBack)
- })
+ rimraf(pkg.path, moveEr ? andRemoveEmptyParents(pkg.path) : moveModulesBack)
}
function andRemoveEmptyParents (path) {
@@ -58,7 +62,7 @@ function removeDir (pkg, log, next) {
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, andIgnoreErrors(done))
+ move(from, to).then(andIgnoreErrors(done), andIgnoreErrors(done))
}, cleanup)
}
diff --git a/deps/npm/lib/install/action/unbuild.js b/deps/npm/lib/install/action/unbuild.js
new file mode 100644
index 0000000000..ce20df75d3
--- /dev/null
+++ b/deps/npm/lib/install/action/unbuild.js
@@ -0,0 +1,16 @@
+'use strict'
+var Bluebird = require('bluebird')
+var lifecycle = Bluebird.promisify(require('../../utils/lifecycle.js'))
+var packageId = require('../../utils/package-id.js')
+var rmStuff = Bluebird.promisify(require('../../unbuild.js').rmStuff)
+
+module.exports = function (staging, pkg, log) {
+ log.silly('unbuild', packageId(pkg))
+ return lifecycle(pkg.package, 'preuninstall', pkg.path, false, true).then(() => {
+ return lifecycle(pkg.package, 'uninstall', pkg.path, false, true)
+ }).then(() => {
+ return rmStuff(pkg.package, pkg.path)
+ }).then(() => {
+ return lifecycle(pkg.package, 'postuninstall', pkg.path, false, true)
+ })
+}