Skip to content

Commit

Permalink
fix: add npm create command
Browse files Browse the repository at this point in the history
  • Loading branch information
m1m0zzz committed Dec 7, 2024
1 parent 0b7979c commit 1ce4c0e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/npmToBun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function npmToBun (_m: string, command: string): string {
args = args.slice(1)
} else if (!args[1].startsWith('-')) {
cmd = 'bunx'
args[1] = `create-${args[1]}`
args[1] = `create-${args[1].replace('@latest', '')}`
args = args.slice(1)
} else {
args[0] = 'init'
Expand Down
7 changes: 7 additions & 0 deletions src/npmToPnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,16 @@ const npmToPnpmTable = {
init (args: string[]) {
if (args[1] && !args[1].startsWith('-')) {
args[0] = 'create'
const m = args[1].match(/(.+)@latest/)
if (m) {
args[1] = m[1]
}
}
return args.filter(item => item !== '--scope')
},
create (args: string[]) {
return npmToPnpmTable.init(args)
},
ln: 'link',
t: 'test',
test: 'test',
Expand Down
7 changes: 7 additions & 0 deletions src/npmToYarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ const npmToYarnTable = {
init (args: string[]) {
if (args[1] && !args[1].startsWith('-')) {
args[0] = 'create'
const m = args[1].match(/(.+)@latest/)
if (m) {
args[1] = m[1]
}
}
return args.filter(item => item !== '--scope')
},
create (args: string[]) {
return npmToYarnTable.init(args)
},
ln: 'link',
t: 'test',
tst: 'test',
Expand Down
15 changes: 14 additions & 1 deletion test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ describe('NPM tests', () => {
'pnpm create react-app ./my-react-app',
'bunx create-react-app ./my-react-app',
],
// create
[
'npm create react-app ./my-react-app',
'yarn create react-app ./my-react-app',
'pnpm create react-app ./my-react-app',
'bunx create-react-app ./my-react-app',
],
[
'npm create vite@latest',
'yarn create vite',
'pnpm create vite',
'bunx create-vite',
],
// list
['npm list', 'yarn list', 'pnpm list', 'bun pm ls'],
['npm ls', 'yarn list', 'pnpm ls', 'bun pm ls'],
Expand Down Expand Up @@ -648,4 +661,4 @@ describe('to bun x tests', () => {
expect(convert(npmValue, 'bun')).toEqual(bunValue)
})
})
})
})

0 comments on commit 1ce4c0e

Please sign in to comment.