Skip to content

Commit

Permalink
chore: build, format
Browse files Browse the repository at this point in the history
  • Loading branch information
nebrelbug committed Aug 29, 2024
1 parent ef16684 commit 84e5a06
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 25 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Tests can be run with `npm test`. Multiple tests check that parsing, rendering,
## 📦 Contributing to `npm-to-yarn` - Setup Guide

Install Dependencies

```sh copy
npm install
```
Expand All @@ -69,11 +70,12 @@ npm run start

A new file: `npm-to-yarn.mjs` is created in `dist` folder. <br>
Open `node` inside the terminal and write the following code to test new changes

```js
const npmToYarn = await import("./dist/npm-to-yarn.mjs")
const npmToYarn = await import('./dist/npm-to-yarn.mjs')
const convert = npmToYarn.default

convert("npm install react", "bun")
convert('npm install react', 'bun')
```

## Resources
Expand Down
21 changes: 15 additions & 6 deletions dist/npm-to-yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ var yarnCLICommands = [
'workspaces'
];
var executorCommands = {
"npm": "npx",
"yarn": "yarn dlx",
"pnpm": "pnpm dlx",
"bun": "bun x"
npm: 'npx',
yarn: 'yarn dlx',
pnpm: 'pnpm dlx',
bun: 'bun x'
};

function parse(command) {
Expand Down Expand Up @@ -625,8 +625,17 @@ function npmToBun(_m, command) {
* Converts between npm and yarn command
*/
function convert(str, 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';
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') {
Expand Down
2 changes: 1 addition & 1 deletion dist/npm-to-yarn.mjs.map

Large diffs are not rendered by default.

21 changes: 15 additions & 6 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.

19 changes: 15 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ 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') || 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'
export default function convert (str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'): string {
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)
Expand All @@ -21,4 +32,4 @@ export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'
} else {
return str.replace(/npm(?: +([^&\n\r]*))?/gm, npmToYarn)
}
}
}
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export const npmCLICommands = [
]

export const executorCommands = {
"npm": "npx",
"yarn": "yarn dlx",
"pnpm": "pnpm dlx",
"bun": "bun x"
}
npm: 'npx',
yarn: 'yarn dlx',
pnpm: 'pnpm dlx',
bun: 'bun x'
}

0 comments on commit 84e5a06

Please sign in to comment.