Skip to content

Commit

Permalink
fix: add missing aliases and correct rebuild logic
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 12, 2023
1 parent 9c3b360 commit 08c746a
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 114 deletions.
111 changes: 71 additions & 40 deletions dist/npm-to-yarn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function convertAddRemoveArgs(args) {
switch (item) {
case '--no-lockfile':
return '--no-package-lock';
case '--production':
return '--save-prod';
case '--dev':
return '--save-dev';
case '--optional':
Expand All @@ -92,11 +94,15 @@ function convertAddRemoveArgs(args) {
}
var yarnToNpmTable = {
add: function (args) {
if (args[1] === '--force') {
if (args.length === 2 && args[1] === '--force') {
return ['rebuild'];
}
args[0] = 'install';
if (!args.includes('--dev') && !args.includes('--exact') && !args.includes('--optional')) {
if (!args.includes('--dev') &&
!args.includes('--force') &&
!args.includes('--exact') &&
!args.includes('--optional') &&
!args.includes('--production')) {
args.push('--save');
}
return convertAddRemoveArgs(args);
Expand Down Expand Up @@ -192,61 +198,86 @@ function yarnToNPM(_m, command) {
}
}

var npmToYarnTable = {
install: function (args) {
if (args.length === 1) {
return args;
}
args[0] = 'add';
if (args.includes('--global') || args.includes('-g')) {
args.unshift('global');
}
return args.map(function (item) {
if (item === '--save-dev' || item === '-D')
function convertInstallArgs(args) {
if (args.includes('--global') || args.includes('-g')) {
args.unshift('global');
}
return args.map(function (item) {
switch (item) {
case '--save-dev':
case '-D':
return '--dev';
else if (item === '--save' || item === '-S')
return '';
else if (item === '--no-package-lock')
case '--save-prod':
case '-P':
return '--production';
case '--no-package-lock':
return '--no-lockfile';
else if (item === '--save-optional')
case '--save-optional':
case '-O':
return '--optional';
else if (item === '--save-exact' || item === '-E')
case '--save-exact':
case '-E':
return '--exact';
else if (item === '--global' || item === '-g')
case '--save':
case '-S':
case '--global':
case '-g':
return '';
return item;
});
default:
return item;
}
});
}
var npmToYarnTable = {
install: function (args) {
if (args.length === 1) {
return ['install'];
}
args[0] = 'add';
return convertInstallArgs(args);
},
i: function (args) {
args[0] = 'install';
return npmToYarnTable.install(args);
},
uninstall: function (args) {
args[0] = 'remove';
if (args.includes('--global') || args.includes('-g')) {
args.unshift('global');
}
return args.map(function (item) {
if (item === '--save-dev')
return '--dev';
else if (item === '--save')
return '';
else if (item === '--no-package-lock')
return '--no-lockfile';
else if (item === '--global' || item === '-g')
return '';
return item;
});
return convertInstallArgs(args);
},
remove: function (args) {
return npmToYarnTable.uninstall(args);
},
un: function (args) {
return npmToYarnTable.uninstall(args);
},
unlink: function (args) {
return npmToYarnTable.uninstall(args);
},
r: function (args) {
return npmToYarnTable.uninstall(args);
},
rm: function (args) {
return npmToYarnTable.uninstall(args);
},
version: function (args) {
return args.map(function (item) {
if (['major', 'minor', 'patch'].includes(item))
return "--".concat(item);
return item;
switch (item) {
case 'major':
return '--major';
case 'minor':
return '--minor';
case 'patch':
return '--patch';
default:
return item;
}
});
},
rb: function (args) {
return npmToYarnTable.rebuild(args);
},
rebuild: function (args) {
args[0] = 'add --force';
args[0] = 'add';
args.push('--force');
return args;
},
run: function (args) {
Expand Down
2 changes: 1 addition & 1 deletion dist/npm-to-yarn.mjs.map

Large diffs are not rendered by default.

111 changes: 71 additions & 40 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.

Loading

0 comments on commit 08c746a

Please sign in to comment.