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

Commit

Permalink
fix(fallback): allow fallback to local anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jun 9, 2017
1 parent c29e93a commit 569cf2c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
19 changes: 8 additions & 11 deletions auto-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ command_not_found_${opts.isBash ? 'handle' : 'handler'}() {
>&2 echo "command not found: $1"
return 127
fi
echo "$1 not found. Trying with npx..." >&2
if ! [[ $1 =~ @ ]]; then
>&2 echo "command not found: $1"
return 127
exec npx --no-install "$@"
fi
echo "$1 not found. Trying with npx..." >&2
npx ${opts.install ? '' : '--no-install '}$*
return $?
exec npx "$@"
}`
}

Expand All @@ -26,12 +23,12 @@ function __fish_command_not_found_on_interactive --on-event fish_prompt
functions --erase __fish_command_not_found_setup
function __fish_command_not_found_handler --on-event fish_command_not_found
if string match -q -v -r @ $argv[1]
echo "fish: Unknown command '$argv[1]'"
return 127
end
echo "$argv[1] not found. Trying with npx..." >&2
npx ${opts.install ? '' : '--no-install '}$argv
if string match -q -r @ $argv[1]
npx $argv
else
npx --no-install $argv
end
end
functions --erase __fish_command_not_found_on_interactive
Expand Down
4 changes: 3 additions & 1 deletion child.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ function runCommand (cmdPath, cmdOpts, opts) {
shell: opts.shell || !!opts.call,
stdio: opts.stdio || 'inherit'
}).catch({code: 'ENOENT'}, () => {
throw new Error(`npx: command not found: ${path.basename(cmdPath)}`)
const err = new Error(`npx: command not found: ${path.basename(cmdPath)}`)
err.exitCode = 127
throw err
})
}

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function getExistingPath (command, opts) {
} else {
return which(command).catch({code: 'ENOENT'}, err => {
if (!opts.install) {
err.exitCode = 127
throw err
}
})
Expand Down

0 comments on commit 569cf2c

Please sign in to comment.