Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit e93fdbe

Browse files
committed
feat(prepare): allow prefetching of only specified deps
1 parent 86116eb commit e93fdbe

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/commands/prepare.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

33
const Prepare = module.exports = {
4-
command: 'prepare',
4+
command: 'prepare [packages...]',
55
aliases: ['prep'],
6-
describe: 'pre-fetch all dependencies',
6+
describe: 'pre-fetch dependencies, or only the listed ones',
77
builder (y) {
88
return y.help().alias('help', 'h').options(Prepare.options)
99
},
@@ -32,7 +32,8 @@ async function prepare (argv) {
3232
await installer({
3333
log (level, ...args) {
3434
return log[level](...args)
35-
}
35+
},
36+
only: argv.packages
3637
})
3738
} catch (e) {
3839
log.error('installer', e)

lib/installer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Installer {
4343
this.log = this.opts.log ||
4444
((level, type, ...msgs) => process.emit(level, type, ...msgs))
4545

46+
this.onlyDeps = opts.only && new Set(opts.only)
4647
this.pkg = null
4748
this.tree = null
4849
this.validLockHash = false
@@ -136,6 +137,13 @@ class Installer {
136137
)
137138
await this.checkLock()
138139
this.tree = buildLogicalTree(this.pkg, this.pkg._shrinkwrap)
140+
if (this.onlyDeps) {
141+
for (const [key, dep] of this.tree.dependencies.entries()) {
142+
if (!this.onlyDeps.has(key)) {
143+
this.tree.delDep(dep)
144+
}
145+
}
146+
}
139147
this.log('silly', 'tree', this.tree)
140148
this.expectedTotal = 0
141149
this.tree.forEach((dep, next) => {

0 commit comments

Comments
 (0)