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

Commit

Permalink
feat(exec): auto-guess binaries when different from pkg name
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `npx ember-cli` and such things will now execute the
binary based on some guesswork, but only when using the shorthand format
for npx execution, with no `-p` option or `-c`. This might cause npx to
unintentionally execute the wrong binary if the package in question has
multiple non-matching binaries, but that should be rare.
  • Loading branch information
zkat committed Jun 24, 2017
1 parent 8d071da commit 139c434
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,26 @@ function main (argv) {
require('update-notifier')({pkg: require('./package.json')}).notify()
// Some npm packages need to be installed. Let's install them!
return ensurePackages(argv.package, argv).then(results => {
results && !argv.q && console.error(Y()`npx: installed ${
results.added.length + results.updated.length
} in ${(Date.now() - startTime) / 1000}s`)
}).then(() => existing)
if (results && results.added && results.updated && !argv.q) {
console.error(Y()`npx: installed ${
results.added.length + results.updated.length
} in ${(Date.now() - startTime) / 1000}s`)
}
if (
argv.command &&
!existing &&
!argv.packageRequested &&
argv.package.length === 1
) {
return promisify(fs.readdir)(results.bin).then(bins => {
const cmd = new RegExp(`^${argv.command}(?:\\.cmd)?$`, 'i')
const matching = bins.find(b => b.match(cmd))
return path.resolve(results.bin, bins[matching] || bins[0])
})
} else {
return existing
}
})
} else {
// We can skip any extra installation, 'cause everything exists.
return existing
Expand Down Expand Up @@ -116,6 +132,9 @@ function ensurePackages (specs, opts) {
// This is intentional, since npx assumes that if you went through
// the trouble of doing `-p`, you're rather have that one. Right? ;)
process.env.PATH = `${bins}${PATH_SEP}${process.env.PATH}`
if (!info) { info = {} }
info.prefix = prefix
info.bin = bins
return info
})
})
Expand Down

0 comments on commit 139c434

Please sign in to comment.