feat: add `npx` conversions
This PR adds a new type of conversions (for npx).
The command npx create-next-app is converted into:
yarn dlx create-next-app (yarn)
pnpm dlx create-next-app (pnpm)
bun x create-next-app (bun)
API Usage:
To apply this conversions the convert function is modified with a new parameter: executor : boolean with default value false.
function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun', executor: boolean = false)
Here's a code example.
convert("npx create-next-app", "yarn", true);
// yarn dlx create-next-app
convert("npx create-next-app", "bun", true);
// bun x create-next-app
Closes #48
@nebrelbug should I add tests before merging ?
@Jay-Karia Yeah tests would be great, thanks
@slorber, I'd love to hear your thoughts about this proposal since Docusaurus is one of the main users of npm-to-yarn.
https://github.com/facebook/docusaurus/issues/10355
Yes that looks like a useful feature to add that we could use on the Docusaurus website
@Jay-Karia I think for ease of use, it should detect whether or not it is an executor command (test for npx|pnpm dlx|...) automatically rather than requiring an extra argument flag.
@nebrelbug Should we consider updating the version to: 2.3.0 or 3.0.0 after this feature?
@nebrelbug Removed extra argument
pnpm uses pnpmx and Bun uses bunx shorthands, which are both shorter and easier to remember, though there have been bugs with the shims not getting installed in the past. Don't know about yarn.
bunx has bugs in windows.
pnpmx does not exists, it's either pnpm exec or pnpm dlx. Same goes with yarn
bunxhas bugs in windows.
Ah, didn't know that. I only use it on macOS.
pnpmxdoes not exists, it's eitherpnpm execorpnpm dlx.
Sorry, typo. I meant pnpx. Apparently they deprecated it though, so I guess it still still stands that you should use pnpm dlx.
@Jay-Karia thanks for the great work! I think we should probably update to a major version. Do you think this is ready to merge?
Yes
I just merged this (with the CLI, not through the web client) and released in https://github.com/nebrelbug/npm-to-yarn/releases/tag/v3.0.0! Thanks for your help!
Note: that's a bit unfortunate but it looks like yarn dlx is not supported by Yarn 1
For this reason the limits the adoption of this feature. I don't think it's a good idea to use it on the Docusaurus website because many users use Yarn 1 (including ourselves)
is yarn exec supported in Yarn 1 ?
I don't see it listed here: https://classic.yarnpkg.com/en/docs/cli/
However yarn exec echo "Hello" works but it doesn't seem to be a decent alternative to npx