GithubHelp home page GithubHelp logo

ehmicky / get-bin-path Goto Github PK

View Code? Open in Web Editor NEW
36.0 3.0 5.0 10.91 MB

Get the current package's binary path

License: Apache License 2.0

JavaScript 88.90% TypeScript 11.10%
binary package-json npm path package unit-testing testing bin cwd executable

get-bin-path's Introduction

GitHub stats

get-bin-path's People

Contributors

allcontributors[bot] avatar dependabot[bot] avatar ehmicky avatar evocateur avatar kabirbaidhya avatar tommy-mitchell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

get-bin-path's Issues

Replace `read-pkg-up` with `escalade`

Guidelines

  • Please search other issues to make sure this feature has not already been requested.

Which problem is this feature request solving?

Reduce the amount of installed dependencies by switching to escalade

Describe the solution you'd like

Would you be open to a PR that replaces read-pkg-up with escalade?

Pull request (optional)

  • I can submit a pull request.

Add CLI for easier local testing

Guidelines

  • Please search other issues to make sure this feature has not already been requested.

Which problem is this feature request solving?

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.

Describe the solution you'd like

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.

Pull request (optional)

  • I can submit a pull request.

Support TypeScript projects by adding type declaration

Which problem is this feature request solving?

  • Support TypeScript - it doesn't right now. I'm trying out in a TS project and it throws error since it couldn't find the type def file for this package.
    import { getBinPath } from 'get-bin-path';
    
    const binPath = await getBinPath();
  • This is the error you'll get.
    image

Describe the solution you'd like

  • Add type declaration file.

Can you submit a pull request?

  • Yes

PR done #4

Fail if named binary isn't found

Guidelines

  • Please search other issues to make sure this feature has not already been requested.

Which problem is this feature request solving?

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:

get-bin-path/src/bin.js

Lines 15 to 20 in 30e582e

if (typeof packageBin === 'string') {
return packageBin
}
const paths = Object.keys(packageBin)
return paths.length === 1 ? packageBin[paths[0]] : packageBin[name]

Describe the solution you'd like

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.

Pull request (optional)

  • I can submit a pull request.

What’s a good way to use this in a TypeScript project?

Guidelines

  • Please search other issues to make sure this feature has not already been requested.

Which problem is this feature request solving?

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.

Describe the solution you'd like

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.

Pull request (optional)

  • I can submit a pull request.

`packagejson.directories.bin` isn't considered?

Guidelines

  • Please search other issues to make sure this feature has not already been requested.

Which problem is this feature request solving?

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.

Describe the solution you'd like

  • include directories.bin in search
  • determine course of action if both fields exist (the docs explicitly label this as an error, but I think npm and/or node allow it anyway? although I haven't thoroughly tested this)
  • if searching dir.bin folder, somehow resolve the bin path

Pull request (optional)

  • I can submit a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.