Skip to content

Commit

Permalink
chore: auto detect conversions
Browse files Browse the repository at this point in the history
Instead of giving additional parameter for npx conversions, now it automatically detects for this type of conversion
  • Loading branch information
Jay-Karia committed Aug 17, 2024
1 parent 4305b4b commit 41f299a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
5 changes: 2 additions & 3 deletions dist/npm-to-yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,8 @@ function npmToBun(_m, command) {
/**
* Converts between npm and yarn command
*/
function convert(str, to, executor) {
if (executor === void 0) { executor = false; }
if (executor) {
function convert(str, to) {
if (str.includes('npx')) {
return str.replace("npx", 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.

5 changes: 2 additions & 3 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.

2 changes: 1 addition & 1 deletion dist/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Converts between npm and yarn command
*/
export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun', executor?: boolean): string;
export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'): string;
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { executorCommands } from './utils'
/**
* Converts between npm and yarn command
*/
export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun', executor = false): string {
if (executor) {
export default function convert(str: string, to: 'npm' | 'yarn' | 'pnpm' | 'bun'): string {
if (str.includes('npx')) {
return str.replace("npx", executorCommands[to])
} else if (to === 'npm') {
return str.replace(/yarn(?: +([^&\n\r]*))?/gm, yarnToNPM)
Expand Down
6 changes: 3 additions & 3 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,19 @@ describe('NPX tests', () => {

describe('to Yarn', () => {
it.each(tests)('%s', (npmValue, yarnValue) => {
expect(convert(npmValue, 'yarn', true)).toEqual(yarnValue)
expect(convert(npmValue, 'yarn')).toEqual(yarnValue)
})
})

describe('to PNPM', () => {
it.each(tests)('%s', (npmValue, _yarnValue, pnpmValue) => {
expect(convert(npmValue, 'pnpm', true)).toEqual(pnpmValue)
expect(convert(npmValue, 'pnpm')).toEqual(pnpmValue)
})
})

describe('to Bun', () => {
it.each(tests)('%s', (npmValue, _yarnValue, _pnpmValue, bunValue) => {
expect(convert(npmValue, 'bun', true)).toEqual(bunValue)
expect(convert(npmValue, 'bun')).toEqual(bunValue)
})
})
})

0 comments on commit 41f299a

Please sign in to comment.