Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tommy-mitchell/get-executable-bin-path
Get the current package's binary path and ensure it's executable.
https://github.com/tommy-mitchell/get-executable-bin-path
bin binary executable file fs nodejs package package-json path permissions shell terminal testing unit-testing
Last synced: 4 months ago
JSON representation
Get the current package's binary path and ensure it's executable.
- Host: GitHub
- URL: https://github.com/tommy-mitchell/get-executable-bin-path
- Owner: tommy-mitchell
- License: mit
- Created: 2024-07-10T15:53:17.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-07-10T16:31:08.000Z (7 months ago)
- Last Synced: 2024-09-18T12:24:24.640Z (5 months ago)
- Topics: bin, binary, executable, file, fs, nodejs, package, package-json, path, permissions, shell, terminal, testing, unit-testing
- Language: TypeScript
- Homepage: https://npm.im/get-executable-bin-path
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# 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
```sh
npm install --save-dev get-executable-bin-path
```Other Package Managers
```sh
yarn add --dev get-executable-bin-path
```## Usage
```ts
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`
### getExecutableBinPathSync(options?): `string`
#### options
Type: `object`
##### name
Type: `string`\
Default: `package.json` `name` fieldName of the binary. See [`get-bin-path`](https://github.com/ehmicky/get-bin-path#optionsname) 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
```ts
const binPath = await getExecutableBinPath();
//=> "…/dist/cli.js"const mappedBinPath = await getExecutableBinPath({
map: binPath => binPath.replace("dist", "src").replace(".js", ".ts"),
});
//=> "…/src/cli.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
- [get-bin-path](https://github.com/ehmicky/get-bin-path) - Get the current package's binary path.
- [bin-path-cli](https://github.com/tommy-mitchell/bin-path-cli) - Execute the current package's binary.
- [is-executable](https://github.com/sindresorhus/is-executable) - Check whether a file can be executed.
- [execa](https://github.com/sindresorhus/execa) - Process execution for humans.