Skip to content

Commit

Permalink
fix: add test cases for reported issues
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 12, 2023
1 parent 7b54605 commit bcef280
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
10 changes: 5 additions & 5 deletions dist/npm-to-yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ var npmToYarnTable = {
if (args[1] && !unchangedCLICommands.includes(args[1]) && !yarnCLICommands.includes(args[1])) {
args.splice(0, 1);
}
var index = args.findIndex(function (a) { return a === '--'; });
if (index >= 0) {
args.splice(index, 1);
}
return args;
},
exec: function (args) {
Expand Down Expand Up @@ -278,8 +274,12 @@ var npmToYarnTable = {
};
function npmToYarn(_m, command) {
var args = parse((command || '').trim());
var index = args.findIndex(function (a) { return a === '--'; });
if (index >= 0) {
args.splice(index, 1);
}
if (unchangedCLICommands.includes(args[0])) {
return 'yarn ' + command;
return 'yarn ' + args.join(' ');
}
else if (args[0] in npmToYarnTable) {
var converter = npmToYarnTable[args[0]];
Expand Down
2 changes: 1 addition & 1 deletion dist/npm-to-yarn.mjs.map

Large diffs are not rendered by default.

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

11 changes: 6 additions & 5 deletions src/npmToYarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ const npmToYarnTable = {
if (args[1] && !unchangedCLICommands.includes(args[1]) && !yarnCLICommands.includes(args[1])) {
args.splice(0, 1)
}
const index = args.findIndex((a) => a === '--')
if (index >= 0) {
args.splice(index, 1)
}
return args
},
exec(args: string[]) {
Expand Down Expand Up @@ -97,8 +93,13 @@ const npmToYarnTable = {
export function npmToYarn(_m: string, command: string): string {
let args = parse((command || '').trim())

const index = args.findIndex((a) => a === '--')
if (index >= 0) {
args.splice(index, 1)
}

if (unchangedCLICommands.includes(args[0])) {
return 'yarn ' + command
return 'yarn ' + args.join(' ')
} else if (args[0] in npmToYarnTable) {
const converter = npmToYarnTable[args[0] as keyof typeof npmToYarnTable]

Expand Down
8 changes: 8 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('NPM to Yarn tests', () => {
'yarn add squirrelly --optional'
)
expect(convert('npm i squirrelly --save-exact', 'yarn')).toEqual('yarn add squirrelly --exact')
expect(convert('npm install pkg --save-exact', 'yarn')).toEqual('yarn add pkg --exact')
})

it('Simple convert works w/ remove', () => {
Expand Down Expand Up @@ -70,6 +71,13 @@ describe('NPM to Yarn tests', () => {
expect(convert('npm test', 'yarn')).toEqual('yarn test')
})

it('npm with dash-dash', () => {
expect(convert('npm run test -- --version', 'yarn')).toEqual('yarn run test --version')
expect(convert('npm run test -- -v', 'yarn')).toEqual('yarn run test -v')
expect(convert('npm test -- --version', 'yarn')).toEqual('yarn test --version')
expect(convert('npm test -- -v', 'yarn')).toEqual('yarn test -v')
})

it('npm init', () => {
expect(convert('npm init', 'yarn')).toEqual('yarn init')
expect(convert('npm init -y', 'yarn')).toEqual('yarn init -y')
Expand Down

0 comments on commit bcef280

Please sign in to comment.