1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
'use strict'
const BB = require('bluebird')
const npa = require('npm-package-arg')
const workerFarm = require('worker-farm')
const extractionWorker = require('./worker.js')
const WORKER_PATH = require.resolve('./worker.js')
module.exports = {
startWorkers () {
this._workers = workerFarm({
maxConcurrentCallsPerWorker: 20,
maxRetries: 1
}, WORKER_PATH)
},
stopWorkers () {
workerFarm.end(this._workers)
},
child (name, child, childPath, config, opts) {
const spec = npa.resolve(name, child.version)
const additionalToPacoteOpts = {}
if (typeof opts.dirPacker !== 'undefined') {
additionalToPacoteOpts.dirPacker = opts.dirPacker
}
const childOpts = config.toPacote(Object.assign({
integrity: child.integrity,
resolved: child.resolved
}, additionalToPacoteOpts))
const args = [spec, childPath, childOpts]
return BB.fromNode((cb) => {
let launcher = extractionWorker
let msg = args
const spec = typeof args[0] === 'string' ? npa(args[0]) : args[0]
childOpts.loglevel = opts.log.level
if (spec.registry || spec.type === 'remote') {
// We can't serialize these options
childOpts.config = null
childOpts.log = null
childOpts.dirPacker = null
// workers will run things in parallel!
launcher = this._workers
try {
msg = JSON.stringify(msg)
} catch (e) {
return cb(e)
}
}
launcher(msg, cb)
})
}
}
|