🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

bin-path-cli

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bin-path-cli

Execute the current package's binary.

0.5.0
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

bin-path-cli

Execute the current package's binary.

Like using npm link, but doesn't add your binary to the global path.

Demo with listr-cli.

Install

npm install --global bin-path-cli
Other Package Managers
yarn global add bin-path-cli

Usage

npx bin-path [source-map] [binary-name] [arguments or flags…]

Curent Working Directory

Inside of a directory with a package.json that specifies a binary either via bin or directories.bin, run via:

npx bin-path

If no binary is found, the bin-path command fails.

Arguments

Flags and arguments are passed as-is to your binary:

$ npx bin-path --some-flag arg1 arg2
Example
// cli.js
#!/usr/bin/env node
import process from "node:process";

const args = process.argv.slice(2);
console.log(`Arguments: [${args.join(", ")}]`);
$ npx bin-path arg1 arg2
#=> "Arguments: [arg1, arg2]"

Named binaries

If you have multiple exported binaries, they can be accessed by name if passed as the first argument to bin-path:

$ npx bin-path binary-name
Example
// package.json
"bin": {
	"foo": "./foo.js",
	"bar": "./bar.js"
}
# `foo` binary
$ npx bin-path foo --foo-flag

# `bar` binary
$ npx bin-path bar --bar-flag

Omitting a name searches for a binary with the same name as the project (i.e. name in package.json). This is the "default" binary.

Example
// package.json
"name": "foo",
"bin": {
	"foo": "./foo.js",
	"bar": "./bar.js"
}
# `foo` binary
$ npx bin-path --foo-flag

Source Mapping

If you're writing your binary in a language that compiles to JavaScript (e.g. TypeScript) and would like to test your source binary, you can map the built file to the source file by using the following format as the first argument to bin-path:

$ npx bin-path dist.js:::src.ts
Example
\__ dist/
    \__ cli.js
\__ src/
    \__ cli.ts
\__ package.json

Aliasing

The syntax for mapping to a source binary can be verbose. Adding the following as an alias to your .zshrc (or equivalent) could help:

alias bin-path-map="bin-path dist.js:::src.ts"

[!NOTE] The feature is under-tested and the syntax is subject to change. If you have any problems or suggestings, please file an issue.

  • get-bin-path - Get the current package's binary path.

Keywords

cli

FAQs

Package last updated on 01 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts