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

Commit

Permalink
feat(extract): add support for --only and --also
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 21, 2018
1 parent 0001568 commit ad143ae
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Installer {
extractTree (tree) {
this.log.silly('extractTree', 'extracting dependencies to node_modules/')
return tree.forEachAsync((dep, next) => {
if (dep.dev && this.config.get('production')) { return }
if (!this.checkDepEnv(dep)) { return }
const depPath = dep.path(this.prefix)
const spec = npa.resolve(dep.name, dep.version, this.prefix)
if (dep.isRoot) {
Expand Down Expand Up @@ -166,6 +166,21 @@ class Installer {
}, {concurrency: 50, Promise: BB})
}

checkDepEnv (dep) {
const includeDev = (
// Covers --dev and --development (from npm config itself)
this.config.get('dev') ||
(
!/^prod(uction)?$/.test(this.config.get('only')) &&
!this.config.get('production')
) ||
/^dev(elopment)?$/.test(this.config.get('only')) ||
/^dev(elopment)?$/.test(this.config.get('also'))
)
const includeProd = !/^dev(elopment)?$/.test(this.config.get('only'))
return (dep.dev && includeDev) || (!dep.dev && includeProd)
}

buildTree (tree) {
this.log.silly('buildTree', 'finalizing tree and running scripts')
return tree.forEachAsync((dep, next) => {
Expand Down

0 comments on commit ad143ae

Please sign in to comment.