npm-to-yarn icon indicating copy to clipboard operation
npm-to-yarn copied to clipboard

feat: add `npx` conversions

Open Jay-Karia opened this issue 1 year ago • 6 comments

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

Jay-Karia avatar Aug 03 '24 05:08 Jay-Karia

@nebrelbug should I add tests before merging ?

Jay-Karia avatar Aug 04 '24 12:08 Jay-Karia

@Jay-Karia Yeah tests would be great, thanks

bgub avatar Aug 07 '24 21:08 bgub

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

bgub avatar Aug 12 '24 17:08 bgub

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

Jay-Karia avatar Aug 13 '24 12:08 Jay-Karia

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

slorber avatar Aug 13 '24 14:08 slorber

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

bgub avatar Aug 14 '24 21:08 bgub

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

Jay-Karia avatar Aug 17 '24 16:08 Jay-Karia

@nebrelbug Removed extra argument

Jay-Karia avatar Aug 18 '24 08:08 Jay-Karia

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.

lishaduck avatar Aug 25 '24 01:08 lishaduck

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

Jay-Karia avatar Aug 25 '24 04:08 Jay-Karia

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.

lishaduck avatar Aug 25 '24 19:08 lishaduck

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

bgub avatar Aug 26 '24 18:08 bgub

Yes

Jay-Karia avatar Aug 26 '24 23:08 Jay-Karia

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!

bgub avatar Aug 29 '24 09:08 bgub

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)

slorber avatar Aug 29 '24 11:08 slorber

is yarn exec supported in Yarn 1 ?

Jay-Karia avatar Aug 29 '24 12:08 Jay-Karia

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

slorber avatar Aug 29 '24 14:08 slorber