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

Commit

Permalink
feat(prepare): allow prefetching of only specified deps
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 8, 2018
1 parent 86116eb commit e93fdbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/commands/prepare.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const Prepare = module.exports = {
command: 'prepare',
command: 'prepare [packages...]',
aliases: ['prep'],
describe: 'pre-fetch all dependencies',
describe: 'pre-fetch dependencies, or only the listed ones',
builder (y) {
return y.help().alias('help', 'h').options(Prepare.options)
},
Expand Down Expand Up @@ -32,7 +32,8 @@ async function prepare (argv) {
await installer({
log (level, ...args) {
return log[level](...args)
}
},
only: argv.packages
})
} catch (e) {
log.error('installer', e)
Expand Down
8 changes: 8 additions & 0 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Installer {
this.log = this.opts.log ||
((level, type, ...msgs) => process.emit(level, type, ...msgs))

this.onlyDeps = opts.only && new Set(opts.only)
this.pkg = null
this.tree = null
this.validLockHash = false
Expand Down Expand Up @@ -136,6 +137,13 @@ class Installer {
)
await this.checkLock()
this.tree = buildLogicalTree(this.pkg, this.pkg._shrinkwrap)
if (this.onlyDeps) {
for (const [key, dep] of this.tree.dependencies.entries()) {
if (!this.onlyDeps.has(key)) {
this.tree.delDep(dep)
}
}
}
this.log('silly', 'tree', this.tree)
this.expectedTotal = 0
this.tree.forEach((dep, next) => {
Expand Down

0 comments on commit e93fdbe

Please sign in to comment.