ehmicky / get-bin-path Goto Github PK
View Code? Open in Web Editor NEWGet the current package's binary path
License: Apache License 2.0
Get the current package's binary path
License: Apache License 2.0
Reduce the amount of installed dependencies by switching to escalade
Would you be open to a PR that replaces read-pkg-up
with escalade
?
This package uses ES modules. If you're seeing the following error message:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module
This means you're using require()
to load this package. An import
or import()
statement should be used instead. For more information, see this blog post.
When developing a CLI, there’s always a bit of overhead in testing manually by having to type node cli.js …
(or more for nested paths). This isn’t hard to do, but it adds noise and can get cumbersome in certain situations.
Adding a command like bin-path …
would both make manual testing a CLI easier, and ensure that you’re matching the behavior of your tests.
Which problem is this feature request solving?
import { getBinPath } from 'get-bin-path';
const binPath = await getBinPath();
Describe the solution you'd like
Can you submit a pull request?
PR done #4
From the description of options.name
, it sounds like get-bin-path
would search specifically for the given named binary:
Name of the binary. Only needs to be specified when the package exports several binaries.
However, getRelativeBinPath
short-circuits to the default unnamed binary if bin
is a string:
Lines 15 to 20 in 30e582e
I think a "strict names" or something option would be good to add, that causes get-bin-path
to error if options.name
doesn't match any named binaries, or the name of the project if bin
is a string. (Similar for directories.bin
, but I'm not familiar with how it works.)
This would be useful for bin-path-cli
, because I'm adding a feature that attempts to use the first argument to find a named binary, and removes said argument if the given binary is found. However, getBinPath()
returning the default binary causes this to fail.
This library works great for testing CLIs written in plain JS, but with a build step (such as with TS), tests can only be run on the built solution. If I set my tests up to use a transpiler like ts-node
or tsx
, that means I don’t get to use get-bin-path
at all.
Maybe there could be an option to rewrite the base path?
// package.json
{
"bin": "dist/cli.js"
}
// test.ts
const binPath = await getBinPath({rewritePath: "src"});
//=> "src/cli.ts"
The option needs a better name, of course.
I was looking through your code and it seems that directories.bin
isn't considered. Is this intentional? My npm skills are a bit rusty, but from what I could gather, directories.bin
is a valid (and mutually-exclusive) alternative to bin
for specifying package binaries. I was just wondering why it was left out? I imagine it could potentially be a breaking change to implement now however.
npm help package.json
bin
~
~
~
Note that you can also set the executable files using directories.bin #directoriesbin.
See npm help folders for more info on executables.
~
~
~
directories.bin
If you specify a bin directory in directories.bin, all the files in that folder will be added.
Because of the way the bin directive works, specifying both a bin path and
setting directories.bin is an error. If you want to specify individual
files, use bin, and for all the files in an existing bin directory, use directories.bin.
directories.bin
in searchA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.