Skip to content

Commit

Permalink
Add back buildAll
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderGugel committed Sep 8, 2016
1 parent 9186736 commit a2afb02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 39 deletions.
21 changes: 9 additions & 12 deletions src/todo/build.js → src/build_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const LIFECYCLE_SCRIPTS = [
'postinstall'
]


// error class used for representing an error that occurs due to a lifecycle
// script that exits with a non-zero status code.
inherits(FailedBuildError, Error)
Expand All @@ -39,12 +38,10 @@ export function FailedBuildError () {
* @param {String} dep.script - script to be executed (usually using `sh`).
* @return {Observable} - observable sequence of the returned exit code.
*/
export const build = nodeModules => dep => {
const {target, script} = dep

return Observable.create((observer) => {
// some packages do expect a defined `npm_execpath` env
// eg. https://github.com/chrisa/node-dtrace-provider/blob/v0.6.0/scripts/install.js#L19
export const build = nodeModules => ({target, script}) =>
Observable.create(observer => {
// some packages do expect a defined `npm_execpath` env, e.g.
// https://github.com/chrisa/node-dtrace-provider/blob/v0.6.0/scripts/install.js#L19
const env = {npm_execpath: '', ...process.env}

env.PATH = [
Expand All @@ -57,7 +54,6 @@ export const build = nodeModules => dep => {
cwd: path.join(nodeModules, target, 'package'),
env,
stdio: 'inherit'
// shell: true // does break `dtrace-provider@0.6.0` build
})
childProcess.on('error', (error) => {
observer.error(error)
Expand All @@ -67,14 +63,13 @@ export const build = nodeModules => dep => {
observer.complete()
})
})
}

/**
* extract lifecycle scripts from supplied dependency.
* @param {Dep} dep - dependency to be parsed.
* @return {Array.<Object>} - array of script targets to be executed.
*/
export function parseLifecycleScripts ({target, pkgJson: {scripts = {}}}) {
export const parseLifecycleScripts = ({target, pkgJson: {scripts = {}}}) => {
const results = []
for (let i = 0; i < LIFECYCLE_SCRIPTS.length; i++) {
const name = LIFECYCLE_SCRIPTS[i]
Expand All @@ -92,13 +87,15 @@ export function parseLifecycleScripts ({target, pkgJson: {scripts = {}}}) {
* @return {Observable} - empty observable sequence that will be completed once
* all lifecycle scripts have been executed.
*/
export const buildAll = nodeModules => o =>
o
export default function buildAll (nodeModules) {
return this
::map(parseLifecycleScripts)
::mergeMap(scripts => ArrayObservable.create(scripts))
// build dependencies sequentially.
::concatMap(build(nodeModules))
::every(code => code === 0)
::filter(ok => !ok)
::_do(() => {
throw new FailedBuildError()
})
}
21 changes: 15 additions & 6 deletions src/install_cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ import {mergeStatic} from 'rxjs/operator/merge'
import {publishReplay} from 'rxjs/operator/publishReplay'
import {skip} from 'rxjs/operator/skip'

import buildAll from './build_all'
import fetchAll from './fetch_all'
import linkAll from './link_all'
import resolveAll from './resolve_all'
import {fromArgv, fromFs, save} from './pkg_json'
import {init as initCache} from './cache'

function installAll (dir) {
return mergeStatic(
this::linkAll(),
this::fetchAll(dir)
function installAll (dir, shouldBuild) {
return concatStatic(
mergeStatic(
this::linkAll(),
this::fetchAll(dir)
),
shouldBuild
? this::buildAll(dir)
: EmptyObservable.create()
)
}

Expand All @@ -26,7 +32,10 @@ const parseArgv = ({_, production}) => ({
})

const shouldSave = argv =>
!!(argv.save || argv['save-dev'] || argv['save-optional'])
argv.save || argv['save-dev'] || argv['save-optional']

const shouldBuild = argv =>
argv.build

export default config => (cwd, argv) => {
const {isExplicit, isProd} = parseArgv(argv)
Expand All @@ -53,7 +62,7 @@ export default config => (cwd, argv) => {
::resolveAll(dir, config)
::skip(1)
::publishReplay().refCount()
::installAll(dir)
::installAll(dir, shouldBuild(argv))

return concatStatic(
initCache(),
Expand Down
21 changes: 0 additions & 21 deletions src:_install_cmd.js

This file was deleted.

0 comments on commit a2afb02

Please sign in to comment.