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

Commit

Permalink
fix(windows): on Windows, throw useful error when package contains no…
Browse files Browse the repository at this point in the history
… binaries(#142)

Fixes: #137 

* fixed(index): on Windows, throw useful error when package contains no binaries

* test(index): test that on Windows,  a useful error message is returned when there are no binaries
  • Loading branch information
Noah Leigh authored and zkat committed Mar 8, 2018
1 parent cf54e97 commit a69276e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ function npx (argv) {
if (process.platform === 'win32') {
bins = bins.filter(b => b !== 'etc' && b !== 'node_modules')
}
if (bins.length < 1) {
throw new Error(Y()`command not found: ${argv.command}`)
}
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])
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,16 @@ test('noisy npx with --quiet arg on windows', {
t.end()
})
})

test('nice error message when no binaries on windows', {
skip: !isWindows && 'Only on Windows is the error message inscrutable'
}, t => {
return child.spawn('node', [
NPX_ESC, '0'
], {stdio: 'pipe'}).then(res => {
throw new Error('Should not have succeeded')
}, err => {
t.equal(err.stderr.split('\n')[1].trim(), 'command not found: 0')
t.end()
})
})

0 comments on commit a69276e

Please sign in to comment.