{"id":16208510,"url":"https://github.com/ehmicky/get-bin-path","last_synced_at":"2025-04-30T06:42:08.487Z","repository":{"id":39759786,"uuid":"194656150","full_name":"ehmicky/get-bin-path","owner":"ehmicky","description":"Get the current package's binary path","archived":false,"fork":false,"pushed_at":"2024-09-14T16:52:53.000Z","size":11340,"stargazers_count":36,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-11T10:17:07.738Z","etag":null,"topics":["bin","binary","cli","cwd","dependency-management","es6","executable","javascript","library","nodejs","npm","package","package-json","package-manager","path","shell","terminal","testing","typescript","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ehmicky.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-01T11:02:12.000Z","updated_at":"2024-09-14T16:52:57.000Z","dependencies_parsed_at":"2024-04-22T20:36:58.867Z","dependency_job_id":"b665220b-d0ad-4e24-b9b4-d70bd661fb0f","html_url":"https://github.com/ehmicky/get-bin-path","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehmicky%2Fget-bin-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehmicky%2Fget-bin-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehmicky%2Fget-bin-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ehmicky%2Fget-bin-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ehmicky","download_url":"https://codeload.github.com/ehmicky/get-bin-path/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251658163,"owners_count":21622817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bin","binary","cli","cwd","dependency-management","es6","executable","javascript","library","nodejs","npm","package","package-json","package-manager","path","shell","terminal","testing","typescript","unit-testing"],"created_at":"2024-10-10T10:17:22.978Z","updated_at":"2025-04-30T06:42:08.475Z","avatar_url":"https://github.com/ehmicky.png","language":"JavaScript","readme":"\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/ehmicky/design/main/get-bin-path/get-bin-path_dark.svg\"/\u003e\n  \u003cimg alt=\"get-bin-path logo\" src=\"https://raw.githubusercontent.com/ehmicky/design/main/get-bin-path/get-bin-path.svg\" width=\"500\"/\u003e\n\u003c/picture\u003e\n\n[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js\u0026colorA=404040\u0026logoColor=66cc33)](https://www.npmjs.com/package/get-bin-path)\n[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript\u0026colorA=404040\u0026logoColor=0096ff)](/src/main.d.ts)\n[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov\u0026colorA=404040)](https://codecov.io/gh/ehmicky/get-bin-path)\n[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon\u0026colorA=404040\u0026logoColor=9590F9)](https://fosstodon.org/@ehmicky)\n[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium\u0026colorA=404040)](https://medium.com/@ehmicky)\n\nGet the current package's binary path (using the `package.json`\n[`bin`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin) or\n[`directories.bin`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#directoriesbin)\nfield).\n\nThis is useful when testing a package's binary. Using `get-bin-path` (as opposed\nto hard-coding the path to the binary):\n\n- validates that the `package.json` `bin` or `directories.bin` field is\n  correctly setup\n- decouples the binary path from the tests, which allows moving the file without\n  rewriting the tests\n\n# Examples\n\n```js\nimport { getBinPath } from 'get-bin-path'\n\n// `binPath` is the absolute path to the current package's binary\nconst binPath = await getBinPath()\n```\n\n```js\n// Test runner\nimport test from 'ava'\n// Library to execute child processes / commands\nimport { execa } from 'execa'\n\nimport { getBinPath } from 'get-bin-path'\n\nconst binPath = await getBinPath()\n\ntest('Binary file should return \"true\"', async (t) =\u003e {\n  const { stdout } = await execa(binPath)\n  t.is(stdout, 'true')\n})\n```\n\n# Install\n\n```\nnpm install get-bin-path\n```\n\nThis package works in Node.js \u003e=18.18.0.\n\nThis is an ES module. It must be loaded using\n[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c),\nnot `require()`. If TypeScript is used, it must be configured to\n[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html),\nnot CommonJS.\n\n# API\n\n## getBinPath(options?)\n\n[`options`](#options): `object`\\\n_Returns_: `Promise\u003cstring | undefined\u003e`\n\nReturns the current package's binary absolute path. When no `package.json` or\nbinary can be found, `undefined` is returned instead.\n\n```js\nimport { getBinPath } from 'get-bin-path'\n\nconst binPath = await getBinPath()\n```\n\n## getBinPathSync(options?)\n\n[`options`](#options): `object`\\\n_Returns_: `string | undefined`\n\nSame but synchronous.\n\n```js\nimport { getBinPathSync } from 'get-bin-path'\n\nconst binPath = getBinPathSync()\n```\n\n### options\n\n_Type_: `object`\n\n#### options.name\n\n_Type_: `string`\\\n_Default_: `package.json` `name` field\n\nName of the binary.\n\nOnly needs to be specified when the package exports several binaries in the\n`package.json`\n[`bin`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin) or\n[`directories.bin`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#directoriesbin)\nfield.\n\n```json\n{\n  \"name\": \"foo\",\n  \"bin\": {\n    \"foo\": \"path/to/foo.js\",\n    \"bar\": \"path/to/bar.js\"\n  }\n}\n```\n\nWhen the `package.json`'s `bin` or `directories.bin` field is a `string`, the\npackage\n[`name` field](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#name)\nmust match the `name` option.\n\n#### options.cwd\n\n_Type_: `string`\\\n_Default_: Current directory\n\nOverride the current directory, which is used when retrieving the\n`package.json`.\n\n# See also\n\n- [`bin-path-cli`](https://github.com/tommy-mitchell/bin-path-cli): execute the\n  current package's binary\n- [`execa`](https://github.com/sindresorhus/execa): process execution for humans\n\n# Support\n\nFor any question, _don't hesitate_ to [submit an issue on GitHub](../../issues).\n\nEveryone is welcome regardless of personal background. We enforce a\n[Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and\ninclusive environment.\n\n# Contributing\n\nThis project was made with ❤️. The simplest way to give back is by starring and\nsharing it online.\n\nIf the documentation is unclear or has a typo, please click on the page's `Edit`\nbutton (pencil icon) and suggest a correction.\n\nIf you would like to help us fix a bug or add a new feature, please check our\n[guidelines](CONTRIBUTING.md). Pull requests are welcome!\n\nThanks go to our wonderful contributors:\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://fosstodon.org/@ehmicky\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/8136211?v=4?s=100\" width=\"100px;\" alt=\"ehmicky\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eehmicky\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/ehmicky/get-bin-path/commits?author=ehmicky\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#design-ehmicky\" title=\"Design\"\u003e🎨\u003c/a\u003e \u003ca href=\"#ideas-ehmicky\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/ehmicky/get-bin-path/commits?author=ehmicky\" title=\"Documentation\"\u003e📖\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/evocateur/evocateur\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/5605?v=4?s=100\" width=\"100px;\" alt=\"Daniel Stockman\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDaniel Stockman\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/ehmicky/get-bin-path/commits?author=evocateur\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/kabirbaidhya\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/3315763?v=4?s=100\" width=\"100px;\" alt=\"Kabir Baidhya\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKabir Baidhya\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/ehmicky/get-bin-path/commits?author=kabirbaidhya\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/NMinhNguyen\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/2852660?v=4?s=100\" width=\"100px;\" alt=\"Minh Nguyen\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMinh Nguyen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-NMinhNguyen\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/tmillr\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/45028928?v=4?s=100\" width=\"100px;\" alt=\"Tyler Miller\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTyler Miller\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-tmillr\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://tommymitchell.io\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1403701?v=4?s=100\" width=\"100px;\" alt=\"Tommy\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eTommy\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#ideas-tommy-mitchell\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"https://github.com/ehmicky/get-bin-path/commits?author=tommy-mitchell\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehmicky%2Fget-bin-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fehmicky%2Fget-bin-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fehmicky%2Fget-bin-path/lists"}