Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Commit a69276e

Browse files
Noah Leighzkat
authored andcommitted
fix(windows): on Windows, throw useful error when package contains no 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
1 parent cf54e97 commit a69276e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ function npx (argv) {
8686
if (process.platform === 'win32') {
8787
bins = bins.filter(b => b !== 'etc' && b !== 'node_modules')
8888
}
89+
if (bins.length < 1) {
90+
throw new Error(Y()`command not found: ${argv.command}`)
91+
}
8992
const cmd = new RegExp(`^${argv.command}(?:\\.cmd)?$`, 'i')
9093
const matching = bins.find(b => b.match(cmd))
9194
return path.resolve(results.bin, bins[matching] || bins[0])

test/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,16 @@ test('noisy npx with --quiet arg on windows', {
281281
t.end()
282282
})
283283
})
284+
285+
test('nice error message when no binaries on windows', {
286+
skip: !isWindows && 'Only on Windows is the error message inscrutable'
287+
}, t => {
288+
return child.spawn('node', [
289+
NPX_ESC, '0'
290+
], {stdio: 'pipe'}).then(res => {
291+
throw new Error('Should not have succeeded')
292+
}, err => {
293+
t.equal(err.stderr.split('\n')[1].trim(), 'command not found: 0')
294+
t.end()
295+
})
296+
})

0 commit comments

Comments
 (0)