Skip to content

Commit

Permalink
chore: vice versa conversions
Browse files Browse the repository at this point in the history
Now `yarn dlx`, `pnpm dlx` and `bun x` commands can be converted internally.
Previously it was only `npx`
  • Loading branch information
Jay-Karia committed Aug 17, 2024
1 parent 41f299a commit 75cc5c5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions dist/npm-to-yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,9 @@ function npmToBun(_m, command) {
* Converts between npm and yarn command
*/
function convert(str, to) {
if (str.includes('npx')) {
return str.replace("npx", executorCommands[to]);
if (str.includes('npx') || str.includes('yarn dlx') || str.includes('pnpm dlx') || str.includes('bun x')) {
var executor = str.includes('npx') ? 'npx' : str.includes('yarn dlx') ? 'yarn dlx' : str.includes('pnpm dlx') ? 'pnpm dlx' : 'bun x';
return str.replace(executor, executorCommands[to]);
}
else if (to === 'npm') {
return str.replace(/yarn(?: +([^&\n\r]*))?/gm, yarnToNPM);
Expand Down
2 changes: 1 addition & 1 deletion dist/npm-to-yarn.mjs.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/npm-to-yarn.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/npm-to-yarn.umd.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { executorCommands } from './utils'
* Converts between npm and yarn command
*/
export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'): string {
if (str.includes('npx')) {
return str.replace("npx", executorCommands[to])
if (str.includes('npx') || str.includes('yarn dlx') || str.includes('pnpm dlx') || str.includes('bun x')) {
const executor = str.includes('npx') ? 'npx' : str.includes('yarn dlx') ? 'yarn dlx' : str.includes('pnpm dlx') ? 'pnpm dlx' : 'bun x'
return str.replace(executor, executorCommands[to])
} else if (to === 'npm') {
return str.replace(/yarn(?: +([^&\n\r]*))?/gm, yarnToNPM)
} else if (to === 'pnpm') {
Expand Down

0 comments on commit 75cc5c5

Please sign in to comment.