This repository was archived by the owner on Aug 11, 2022. It is now read-only.
File tree Expand file treeCollapse file tree 2 files changed+57
-3
lines changedFilter options
+57
-3
lines changed Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
1
+
'use strict'
2
+
3
+
const BB = require('bluebird')
4
+
5
+
const extract = require('pacote/extract')
6
+
const npmlog = require('npmlog')
7
+
8
+
module.exports = (args, cb) => {
9
+
const parsed = typeof args === 'string' ? JSON.parse(args) : args
10
+
const spec = parsed[0]
11
+
const extractTo = parsed[1]
12
+
const opts = parsed[2]
13
+
if (!opts.log && opts.loglevel) {
14
+
opts.log = npmlog
15
+
opts.log.level = opts.loglevel
16
+
}
17
+
BB.resolve(extract(spec, extractTo, opts)).nodeify(cb)
18
+
}
Original file line number Diff line number Diff line change
@@ -10,11 +10,28 @@ const moduleName = require('../../utils/module-name.js')
10
10
const moduleStagingPath = require('../module-staging-path.js')
11
11
const move = require('../../utils/move.js')
12
12
const npa = require('npm-package-arg')
13
+
const npm = require('../../npm.js')
13
14
const packageId = require('../../utils/package-id.js')
14
-
const pacote = require('pacote')
15
15
let pacoteOpts
16
16
const path = require('path')
17
+
const localWorker = require('./extract-worker.js')
18
+
const workerFarm = require('worker-farm')
17
19
20
+
const WORKER_PATH = require.resolve('./extract-worker.js')
21
+
let workers
22
+
23
+
extract.init = () => {
24
+
workers = workerFarm({
25
+
maxConcurrentCallsPerWorker: npm.limit.fetch,
26
+
maxRetries: 1
27
+
}, WORKER_PATH)
28
+
return BB.resolve()
29
+
}
30
+
extract.teardown = () => {
31
+
workerFarm.end(workers)
32
+
workers = null
33
+
return BB.resolve()
34
+
}
18
35
module.exports = extract
19
36
function extract (staging, pkg, log) {
20
37
log.silly('extract', packageId(pkg))
@@ -25,13 +42,32 @@ function extract (staging, pkg, log) {
25
42
const opts = pacoteOpts({
26
43
integrity: pkg.package._integrity
27
44
})
28
-
return pacote.extract(
45
+
const args = [
29
46
pkg.package._resolved
30
47
? npa.resolve(pkg.package.name, pkg.package._resolved)
31
48
: pkg.package._requested,
32
49
extractTo,
33
50
opts
34
-
).then(() => {
51
+
]
52
+
return BB.fromNode((cb) => {
53
+
let launcher = localWorker
54
+
let msg = args
55
+
const spec = typeof args[0] === 'string' ? npa(args[0]) : args[0]
56
+
if (spec.registry || spec.type === 'remote') {
57
+
// We can't serialize these options
58
+
opts.loglevel = opts.log.level
59
+
opts.log = null
60
+
opts.dirPacker = null
61
+
// workers will run things in parallel!
62
+
launcher = workers
63
+
try {
64
+
msg = JSON.stringify(msg)
65
+
} catch (e) {
66
+
return cb(e)
67
+
}
68
+
}
69
+
launcher(msg, cb)
70
+
}).then(() => {
35
71
if (pkg.package.bundleDependencies) {
36
72
return readBundled(pkg, staging, extractTo)
37
73
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4