antfu-collective / ni

💡 Use the right package manager
MIT License
6.42k stars 210 forks source link

feat: implement `nrx` command #170

Closed Dimava closed 12 months ago

Dimava commented 1 year ago

Description

This PR adds nrx command, which is an "execute local binary" command:

> nrx cowsayjs moo
> npm exec --no cowsayjs moo
> yarn@1 run cowsayjs moo
> yarn exec cowsayjs moo
> pnpm exec cowsayjs moo

Unlike dlx-style commands (npx/yarn dlx) this can't install new packages and must use existing ones If the binary is missing, this command is guaranteed to fail

Linked Issues

(unrelated) #140

Additional context

This Draft PR is missing:

Please tell me if there is interest in this command, so I can either procees to making tests/docs or leave it as-is (it works for me locally, so I don't really need tests/docs if this is not going to be upstreamed)

Dimava commented 1 year ago

cc @antfu

antfu commented 12 months ago

Thanks for bringing this up, but sorry we no longer accept adding new commands.

mattrossman commented 6 months ago

@antfu Do you think this behavior could be achieved without adding a new command?

I use Firebase CLI and Prisma CLI in my projects (installed locally) and currently there is no way to reliably execute these with ni.

When using npm as a package manager, it works as expected because npx attempts to run local binaries before download. However, the translated commands for other package managers force a download from the registry, which causes either version mismatches or lookup failure.

Some packages use a different name for their package vs binary. For instance, the firebase CLI is distributed under the firebase-tools package. This means with npm I can write nlx firebase but with other package managers I have to write nlx firebase-tools.

Perhaps nlx could align more with npm's behavior, defaulting to local binaries before performing a registry lookup?