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

Commit

Permalink
feat(ignore): add --ignore-existing option (#20)
Browse files Browse the repository at this point in the history
Fixes: #15
Fixes: #16
  • Loading branch information
zkat committed Jun 3, 2017
1 parent 17db461 commit 0866a83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## SYNOPSIS

`npx [--package|-p <package>] [--cache <path>] [--save-dev|-D] [--save-prod|-P] [--save-optional|-O] [--save-bundle|-B] [--save-exact|-E] [--global|-g] [--prefix|-C] [--userconfig <path>] [-c <string>] [--version|-v] [--] <command>[@version] [command-arg]...`
`npx [--package|-p <package>] [--cache <path>] [--save-dev|-D] [--save-prod|-P] [--save-optional|-O] [--save-bundle|-B] [--save-exact|-E] [--global|-g] [--prefix|-C] [--userconfig <path>] [-c <string>] [--ignore-existing] [--version|-v] [--] <command>[@version] [command-arg]...`

## INSTALL

Expand All @@ -14,9 +14,11 @@

Executes `<command>` either from a local `node_modules/.bin`, or from a central cache, installing any packages needed in order for `<command>` to run.

By default, `<command>` will be installed prior to execution. An optional `@version` may be appended to specify the package version required.
By default, `npx` will check whether `<command>` exists in `$PATH`, or in the local project binaries, and execute that. If `<command>` is not found, it will be installed prior to execution.

If a version specifier is included, or if `--package` is used, npx will ignore the version of the package in the current path, if it exists.
An optional `@version` may be appended to specify the package version required, which defaults to `latest` only if `<command>` is not in the path. If the command is already present and no explicit version specifier was requested, the existing command will be used.

If a version specifier is included, or if `--package` is used, npx will ignore the version of the package in the current path, if it exists. This can also be forced with the `--ignore-existing` flag.

* `-p, --package <package>` - define the package to be installed. This defaults to the value of `<command>`. This is only needed for packages with multiple binaries if you want to call one of the other executables, or where the binary name does not match the package name. If this option is provided `<command>` will be executed as-is, without interpreting `@version` if it's there.

Expand All @@ -36,6 +38,8 @@ If a version specifier is included, or if `--package` is used, npx will ignore t

* `--shell-auto-fallback [shell]` - Generates shell code to override your shell's "command not found" handler with one that calls `npx`. Tries to figure out your shell, or you can pass its name (either `bash`, `fish`, or `zsh`) as an option. See below for how to install.

* `--ignore-existing` - If this flag is set, npx will not look in `$PATH`, or in the current package's `node_modules/.bin` for an existing version before deciding whether to install. Binaries in those paths will still be available for execution, but will be shadowed by any packages requested by this install.

* `-v, --version` - Show the current npx version.

## EXAMPLES
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ function getExistingPath (command, opts) {
opts.global ||
opts.prefix ||
opts.cmdHadVersion ||
opts.packageRequested
opts.packageRequested ||
opts.ignoreExisting
) {
return BB.resolve(false)
} else {
Expand Down
6 changes: 5 additions & 1 deletion parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const npa = require('npm-package-arg')
const yargs = require('yargs')

const usage = `$0 [--package|-p <package>] [--cache <path>] [--save-dev|-D] [--save-prod|-P] [--save-optional|-O] [--save-bundle|-B] [--save-exact|-E] [--global|-g] [--prefix|-C] [--userconfig <path>] [-c <string>] [--shell-auto-fallback [shell]] [--version|-v] [--] <command>[@version] [command-arg]...`
const usage = `$0 [--package|-p <package>] [--cache <path>] [--save-dev|-D] [--save-prod|-P] [--save-optional|-O] [--save-bundle|-B] [--save-exact|-E] [--global|-g] [--prefix|-C] [--userconfig <path>] [-c <string>] [--shell-auto-fallback [shell]] [--ignore-existing] [--version|-v] [--] <command>[@version] [command-arg]...`

module.exports = parseArgs
function parseArgs () {
Expand Down Expand Up @@ -74,6 +74,10 @@ function parseArgs () {
requireArg: false,
type: 'string'
})
.option('ignore-existing', {
describe: 'Ignores existing binaries in $PATH, or in the local project. This forces npx to do a temporary install and use the latest version.',
type: 'boolean'
})
.version()
.alias('version', 'v')

Expand Down

0 comments on commit 0866a83

Please sign in to comment.