Skip to content

Commit 84e5a06

Browse files
committed
chore: build, format
1 parent ef16684 commit 84e5a06

File tree

7 files changed

+56
-25
lines changed

7 files changed

+56
-25
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Tests can be run with `npm test`. Multiple tests check that parsing, rendering,
5757
## 📦 Contributing to `npm-to-yarn` - Setup Guide
5858

5959
Install Dependencies
60+
6061
```sh copy
6162
npm install
6263
```
@@ -69,11 +70,12 @@ npm run start
6970

7071
A new file: `npm-to-yarn.mjs` is created in `dist` folder. <br>
7172
Open `node` inside the terminal and write the following code to test new changes
73+
7274
```js
73-
const npmToYarn = await import("./dist/npm-to-yarn.mjs")
75+
const npmToYarn = await import('./dist/npm-to-yarn.mjs')
7476
const convert = npmToYarn.default
7577

76-
convert("npm install react", "bun")
78+
convert('npm install react', 'bun')
7779
```
7880

7981
## Resources

dist/npm-to-yarn.mjs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ var yarnCLICommands = [
4848
'workspaces'
4949
];
5050
var executorCommands = {
51-
"npm": "npx",
52-
"yarn": "yarn dlx",
53-
"pnpm": "pnpm dlx",
54-
"bun": "bun x"
51+
npm: 'npx',
52+
yarn: 'yarn dlx',
53+
pnpm: 'pnpm dlx',
54+
bun: 'bun x'
5555
};
5656

5757
function parse(command) {
@@ -625,8 +625,17 @@ function npmToBun(_m, command) {
625625
* Converts between npm and yarn command
626626
*/
627627
function convert(str, to) {
628-
if (str.includes('npx') || str.includes('yarn dlx') || str.includes('pnpm dlx') || str.includes('bun x')) {
629-
var executor = str.includes('npx') ? 'npx' : str.includes('yarn dlx') ? 'yarn dlx' : str.includes('pnpm dlx') ? 'pnpm dlx' : 'bun x';
628+
if (str.includes('npx') ||
629+
str.includes('yarn dlx') ||
630+
str.includes('pnpm dlx') ||
631+
str.includes('bun x')) {
632+
var executor = str.includes('npx')
633+
? 'npx'
634+
: str.includes('yarn dlx')
635+
? 'yarn dlx'
636+
: str.includes('pnpm dlx')
637+
? 'pnpm dlx'
638+
: 'bun x';
630639
return str.replace(executor, executorCommands[to]);
631640
}
632641
else if (to === 'npm') {

dist/npm-to-yarn.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/npm-to-yarn.umd.js

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/npm-to-yarn.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ import { executorCommands } from './utils'
88
/**
99
* Converts between npm and yarn command
1010
*/
11-
export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'): string {
12-
if (str.includes('npx') || str.includes('yarn dlx') || str.includes('pnpm dlx') || str.includes('bun x')) {
13-
const executor = str.includes('npx') ? 'npx' : str.includes('yarn dlx') ? 'yarn dlx' : str.includes('pnpm dlx') ? 'pnpm dlx' : 'bun x'
11+
export default function convert (str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'): string {
12+
if (
13+
str.includes('npx') ||
14+
str.includes('yarn dlx') ||
15+
str.includes('pnpm dlx') ||
16+
str.includes('bun x')
17+
) {
18+
const executor = str.includes('npx')
19+
? 'npx'
20+
: str.includes('yarn dlx')
21+
? 'yarn dlx'
22+
: str.includes('pnpm dlx')
23+
? 'pnpm dlx'
24+
: 'bun x'
1425
return str.replace(executor, executorCommands[to])
1526
} else if (to === 'npm') {
1627
return str.replace(/yarn(?: +([^&\n\r]*))?/gm, yarnToNPM)
@@ -21,4 +32,4 @@ export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'
2132
} else {
2233
return str.replace(/npm(?: +([^&\n\r]*))?/gm, npmToYarn)
2334
}
24-
}
35+
}

src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ export const npmCLICommands = [
110110
]
111111

112112
export const executorCommands = {
113-
"npm": "npx",
114-
"yarn": "yarn dlx",
115-
"pnpm": "pnpm dlx",
116-
"bun": "bun x"
117-
}
113+
npm: 'npx',
114+
yarn: 'yarn dlx',
115+
pnpm: 'pnpm dlx',
116+
bun: 'bun x'
117+
}

0 commit comments

Comments
 (0)