# link-bin-executable

> Helps creating a symbolic link to a (binary) executable in .bin during a package postinstall phase.

Latest version **1.0.3** (published 2024-08-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install link-bin-executable
pnpm add link-bin-executable
yarn add link-bin-executable
bun add link-bin-executable
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-08-11 |
| First published | 2023-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 1 |
| Unpacked size | 47.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ferdinand Prantl |
| Maintainers | prantlf |
| Keywords | install, bin, symlink, link, symbolic |

## Links

- npm: https://www.npmjs.com/package/link-bin-executable
- Repository: https://github.com/prantlf/link-bin-executable
- Homepage: https://github.com/prantlf/link-bin-executable#readme
- Issues: https://github.com/prantlf/link-bin-executable/issues
- npm.io page: https://npm.io/package/link-bin-executable

## Dependencies (1)

- [debug](https://npm.io/package/debug.md) ^4.3.6

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2024-08-11
- 1.0.2 — 2023-12-12
- 1.0.1 — 2023-12-12
- 1.0.0 — 2023-12-12
- 0.3.1 — 2023-11-04
- 0.3.0 — 2023-11-04
- 0.2.0 — 2023-11-01
- 0.1.1 — 2023-11-01
- 0.1.0 — 2023-11-01
- 0.0.1 — 2023-10-27

## README

# Link Executable to .bin

[![Latest version](https://img.shields.io/npm/v/link-bin-executable)
 ![Dependency status](https://img.shields.io/librariesio/release/npm/link-bin-executable)
](https://www.npmjs.com/package/link-bin-executable)
[![Coverage](https://codecov.io/gh/prantlf/link-bin-executable/branch/master/graph/badge.svg)](https://codecov.io/gh/prantlf/link-bin-executable)

Helps creating a symbolic link to a (binary) executable in `.bin` during a package postinstall phase.

Works well with [grab-github-release], if you want to download a binary executable from a GitHub release.

## Synopsis

A script to install to `.bin` by an entry in `bin` in `package.json`:

```js
#!/usr/bin/env node

import { runAndReplaceLink, reportError } from 'link-bin-executable'

try {
  await runAndReplaceLink({ name: 'myexecutable' })
} catch (err) {
  reportError(err)
}
```

A script to install to `.bin` by an entry in `scripts.postinstall` in `package.json`:

```js
import { installLink, reportError } from 'link-bin-executable'

try {
  await installLink({ name: 'myexecutable' })
} catch (err) {
  reportError(err)
}
```

## Installation

This package is usually installed as a local dependency:

```sh
$ npm i link-bin-executable
```

Make sure, that you use [Node.js] version 18 or newer.

## API

```ts
interface InstallLinkOptions {
  // primary name of the symbolic link to create and default executable name
  name?: string
  // names of the symbolic links to create; if not specified, `name` will be
  // created, otherwise only the specified names will be created
  linkNames?: string[]
  // package directory where the postinstall script runs
  packageDirectory: string
  // path to the executable to create the link to; if not specified, the file
  // named by `name` will be looked up in the package directory
  executable?: string
  // log debug messages on the standard output instead of being enabled
  // by the DEBUG environment variable and log on the standard error
  verbose?: boolean
}

// creates a symbolic link in the `.bin` directory to the executable available
// usually in the package directory
 *
// @param options see properties of `GrabOptions` for more information
export function installLink(options: InstallLinkOptions): Promise<void>

interface RunAndReplaceLinkOptions {
  // primary name of the symbolic link to replace and default executable name
  name?: string
  // names of the symbolic links to replace; if not specified, `name` will be
  // replaced, otherwise only the specified names will be replaced
  linkNames?: string[]
  // bin directory where the javascript stub runs
  scriptDirectory: string
  // path to the executable to create the link to; if not specified, the file
  // named by `name` will be looked up in the package directory
  executable?: string
  // log debug messages on the standard output instead of being enabled
  // by the DEBUG environment variable and log on the standard error
  verbose?: boolean
}

// replaces the just executed symbolic link to a javascript stub in the `.bin`
// directory by a link to the executable available usually in the package
// directory and delegates the process to the executable with the same arguments
 *
// @param options see properties of `GrabOptions` for more information
export function runAndReplaceLink(options: RunAndReplaceLinkOptions): Promise<void>

// prints the error message on the console and sets the process exit code
// if `runAndReplaceLink` failed; supposed to be called from a catch block
 *
// @param err error thrown from `runAndReplaceLink`
export function reportError(err: Error)
```

## Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.  Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

## License

Copyright (c) 2023-2024 Ferdinand Prantl

Licensed under the MIT license.

[Node.js]: http://nodejs.org/
[grab-github-release]: https://github.com/prantlf/grab-github-release

---
_Source: https://npm.io/package/link-bin-executable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
