nebrelbug / npm-to-yarn

Convert npm CLI commands to yarn, and vice versa
https://nebrelbug.github.io/npm-to-yarn/test.html
MIT License
34 stars 9 forks source link

feat: add `npx` conversions #53

Closed Jay-Karia closed 2 months ago

Jay-Karia commented 3 months ago

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)

Automatically detects executor commands and converts it

Here's a code example.

convert("npx create-next-app", "yarn");
// yarn dlx create-next-app

Closes #48

Jay-Karia commented 3 months ago

@nebrelbug should I add tests before merging ?

nebrelbug commented 3 months ago

@Jay-Karia Yeah tests would be great, thanks

nebrelbug commented 2 months ago

@slorber, I'd love to hear your thoughts about this proposal since Docusaurus is one of the main users of npm-to-yarn.

Jay-Karia commented 2 months ago

https://github.com/facebook/docusaurus/issues/10355

slorber commented 2 months ago

Yes that looks like a useful feature to add that we could use on the Docusaurus website

nebrelbug commented 2 months ago

@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.

Jay-Karia commented 2 months ago

@nebrelbug Should we consider updating the version to: 2.3.0 or 3.0.0 after this feature?

Jay-Karia commented 2 months ago

@nebrelbug Removed extra argument

lishaduck commented 2 months ago

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.

Jay-Karia commented 2 months ago

bunx has bugs in windows. pnpmx does not exists, it's either pnpm exec or pnpm dlx. Same goes with yarn

lishaduck commented 2 months ago

bunx has bugs in windows.

Ah, didn't know that. I only use it on macOS.

pnpmx does not exists, it's either pnpm exec or pnpm dlx.

Sorry, typo. I meant pnpx. Apparently they deprecated it though, so I guess it still still stands that you should use pnpm dlx.

nebrelbug commented 2 months ago

@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?

Jay-Karia commented 2 months ago

Yes

nebrelbug commented 2 months ago

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!

slorber commented 2 months ago

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)

Jay-Karia commented 2 months ago

is yarn exec supported in Yarn 1 ?

slorber commented 2 months ago

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