get-executable-bin-path
Get the current package's binary path and ensure it's executable.
Useful for making sure your CLIs are configured correctly.
Install
npm install --save-dev get-executable-bin-path
Other Package Managers
yarn add --dev get-executable-bin-path
Usage
import anyTest, { type TestFn } from "ava";
import { execa } from "execa";
import { getExecutableBinPath } from "get-executable-bin-path";
const test = anyTest as TestFn<{
binPath: string;
}>;
test.before("setup context", async t => {
t.context.binPath = await getExecutableBinPath();
});
test("main", async t => {
const { stdout } = await execa(t.context.binPath);
t.is(stdout, );
});
API
getExecutableBinPath(options?): Promise<string>
getExecutableBinPathSync(options?): string
options
Type: object
name
Type: string
Default: package.json
name
field
Name of the binary. See get-bin-path
for more details.
cwd
Type: string
Default: process.cwd()
Override the current directory. Used when retrieving the package.json
.
map
Type: (binPath: string) => string
An optional mapping that resolves to a binary's path.
This can be used to get the path of the source binary, for example.
Example
const binPath = await getExecutableBinPath();
const mappedBinPath = await getExecutableBinPath({
map: binPath => binPath.replace("dist", "src").replace(".js", ".ts"),
});
BinaryPathNotFoundError
The error thrown when a given binary cannot be resolved.
BinaryNotExecutableError
The error thrown when a given binary is not executable or resolvable.
Related