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

Commit

Permalink
feat(package): report number of temp packages installed
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jun 20, 2017
1 parent 6714992 commit 5b7fe8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions child.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ module.exports.spawn = spawn
function spawn (cmd, args, opts) {
return BB.fromNode(cb => {
const child = cp.spawn(cmd, args, opts)
let stdout = ''
let stderr = ''
child.stdout && child.stdout.on('data', d => { stdout += d })
child.stderr && child.stderr.on('data', d => { stderr += d })
child.on('error', cb)
child.on('close', code => {
if (code) {
const err = new Error(Y`Command failed: ${cmd} ${args.join(' ')}`)
err.exitCode = code
cb(err)
} else {
cb()
} else if (child.stdout || child.stderr) {
cb(null, {code, stdout, stderr})
}
})
})
Expand Down
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function main (argv) {
return
}

const startTime = Date.now()

// First, we look to see if we're inside an npm project, and grab its
// bin path. This is exactly the same as running `$ npm bin`.
return localBinPath(process.cwd()).then(local => {
Expand All @@ -66,7 +68,11 @@ function main (argv) {
}
if ((!existing && !argv.call) || argv.packageRequested) {
// Some npm packages need to be installed. Let's install them!
return ensurePackages(argv.package, argv).then(() => existing)
return ensurePackages(argv.package, argv).then(results => {
console.error(Y`npx: installed ${
results.added.length + results.updated.length
} in ${(Date.now() - startTime) / 1000}s`)
}).then(() => existing)
} else {
// We can skip any extra installation, 'cause everything exists.
return existing
Expand Down Expand Up @@ -159,12 +165,12 @@ function buildArgs (specs, prefix, opts) {
}

module.exports._installPackages = installPackages
function installPackages (specs, prefix, npmOpts) {
const args = buildArgs(specs, prefix, npmOpts)
return which(npmOpts.npm).then(npmPath => {
function installPackages (specs, prefix, opts) {
const args = buildArgs(specs, prefix, opts)
return which(opts.npm).then(npmPath => {
return child.spawn(npmPath, args, {
stdio: [0, 'ignore', 2]
}).catch(err => {
stdio: [0, 'pipe', 2]
}).then(deets => deets.stdout ? JSON.parse(deets.stdout) : null, err => {
if (err.exitCode) {
err.message = Y`Install for ${specs} failed with code ${err.exitCode}`
}
Expand Down

0 comments on commit 5b7fe8d

Please sign in to comment.