From 08c746a881a6dc05200e6569849e0f61efbd0261 Mon Sep 17 00:00:00 2001 From: Armano Date: Sun, 12 Feb 2023 15:32:58 +0100 Subject: [PATCH] fix: add missing aliases and correct rebuild logic --- dist/npm-to-yarn.mjs | 111 +++++++++++++++++++++++------------- dist/npm-to-yarn.mjs.map | 2 +- dist/npm-to-yarn.umd.js | 111 +++++++++++++++++++++++------------- dist/npm-to-yarn.umd.js.map | 2 +- src/npmToYarn.ts | 94 ++++++++++++++++++++---------- src/yarnToNpm.ts | 14 ++++- test/index.spec.ts | 12 ++++ 7 files changed, 232 insertions(+), 114 deletions(-) diff --git a/dist/npm-to-yarn.mjs b/dist/npm-to-yarn.mjs index 253aad7..dd10517 100644 --- a/dist/npm-to-yarn.mjs +++ b/dist/npm-to-yarn.mjs @@ -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': @@ -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); @@ -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) { diff --git a/dist/npm-to-yarn.mjs.map b/dist/npm-to-yarn.mjs.map index 9e24d4e..7cc73d6 100644 --- a/dist/npm-to-yarn.mjs.map +++ b/dist/npm-to-yarn.mjs.map @@ -1 +1 @@ -{"version":3,"file":"npm-to-yarn.mjs","sources":["../src/utils.ts","../src/command.ts","../src/yarnToNpm.ts","../src/npmToYarn.ts","../src/index.ts"],"sourcesContent":["export const unchangedCLICommands = ['test', 'login', 'logout', 'link', 'publish', 'cache']\n\nexport const yarnCLICommands = [\n 'init',\n 'run',\n 'add',\n 'audit',\n 'autoclean',\n 'bin',\n 'check',\n 'config',\n 'create',\n 'dedupe',\n 'generate-lock-entry',\n 'global',\n 'help',\n 'import',\n 'info',\n 'install',\n 'licenses',\n 'list',\n 'lockfile',\n 'outdated',\n 'owner',\n 'pack',\n 'policies',\n 'prune',\n 'remove',\n 'self-update',\n 'tag',\n 'team',\n 'link',\n 'unlink',\n 'upgrade',\n 'upgrade-interactive',\n 'version',\n 'versions',\n 'why',\n 'workspace',\n 'workspaces'\n]\n\nexport const npmCLICommands = [\n 'init',\n 'run',\n 'access',\n 'adduser',\n 'audit',\n 'bin',\n 'bugs',\n 'build',\n 'bundle',\n 'ci',\n 'completion',\n 'config',\n 'dedupe',\n 'deprecate',\n 'dist-tag',\n 'docs',\n 'doctor',\n 'edit',\n 'explore',\n 'exec',\n 'fund',\n 'help-search',\n 'help',\n 'hook',\n 'install-ci-test',\n 'install-test',\n 'install',\n 'ls',\n 'list',\n 'npm',\n 'org',\n 'outdated',\n 'owner',\n 'pack',\n 'ping',\n 'prefix',\n 'profile',\n 'prune',\n 'rebuild',\n 'repo',\n 'restart',\n 'root',\n 'run-script',\n 'search',\n 'shrinkwrap',\n 'star',\n 'stars',\n 'start',\n 'stop',\n 'team',\n 'token',\n 'uninstall',\n 'unpublish',\n 'update',\n 'version',\n 'view',\n 'whoami'\n]\n","export function parse (command: string) {\n const args: string[] = []\n let lastQuote: string | false = false\n let escaped = false\n let part = ''\n for (let i = 0; i < command.length; ++i) {\n const char = command.charAt(i)\n if (char === '\\\\') {\n part += char\n escaped = true\n } else {\n if (char === ' ' && !lastQuote) {\n args.push(part)\n part = ''\n } else if (!escaped && (char === '\"' || char === \"'\")) {\n part += char\n if (char === lastQuote) {\n lastQuote = false\n } else if (!lastQuote) {\n lastQuote = char\n }\n } else {\n part += char\n }\n escaped = false\n }\n }\n args.push(part)\n return args\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nfunction convertAddRemoveArgs (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--no-lockfile':\n return '--no-package-lock'\n case '--dev':\n return '--save-dev'\n case '--optional':\n return '--save-optional'\n case '--exact':\n return '--save-exact'\n default:\n return item\n }\n })\n}\n\nconst yarnToNpmTable = {\n add (args: string[]) {\n if (args[1] === '--force') {\n return ['rebuild']\n }\n args[0] = 'install'\n if (!args.includes('--dev') && !args.includes('--exact') && !args.includes('--optional')) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n remove (args: string[]) {\n args[0] = 'uninstall'\n if (!args.includes('--dev')) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n version (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--major':\n return 'major'\n case '--minor':\n return 'minor'\n case '--patch':\n return 'patch'\n default:\n return item\n }\n })\n },\n install: 'install',\n list (args: string[]) {\n args[0] = 'ls'\n const patternIndex = args.findIndex(item => item === '--pattern')\n if (patternIndex >= 0 && args[patternIndex + 1]) {\n const packages = args[patternIndex + 1].replace(/[\"']([^\"']+)[\"']/, '$1').split('|')\n args.splice(patternIndex, 2, packages.join(' '))\n }\n return args\n },\n init: 'init',\n create: 'init',\n run: 'run',\n start: 'start',\n stop: 'stop',\n test: 'test',\n global (args: string[]) {\n switch (args[1]) {\n case 'add':\n args.shift()\n args = yarnToNpmTable.add(args)\n args.push('--global')\n return args\n case 'remove':\n args.shift()\n args = yarnToNpmTable.remove(args)\n args.push('--global')\n return args\n case 'list':\n args.shift()\n args = yarnToNpmTable.list(args)\n args.push('--global')\n return args\n // case 'bin':\n // case 'upgrade':\n default:\n args.push(\"\\n# couldn't auto-convert command\")\n return args\n }\n }\n}\n\nexport function yarnToNPM (_m: string, command: string): string {\n command = (command || '').trim()\n if (command === '') {\n return 'npm install'\n }\n let args = parse(command)\n const firstCommand = (/\\w+/.exec(command) || [''])[0]\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'npm ' + command\n } else if (args[0] in yarnToNpmTable) {\n const converter = yarnToNpmTable[args[0] as keyof typeof yarnToNpmTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'npm ' + args.filter(Boolean).join(' ')\n } else if (!yarnCLICommands.includes(firstCommand)) {\n // i.e., yarn grunt -> npm run grunt\n return 'npm run ' + command\n } else {\n return 'npm ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nconst npmToYarnTable = {\n install (args: string[]) {\n if (args.length === 1) {\n return args\n }\n args[0] = 'add'\n\n if (args.includes('--global') || args.includes('-g')) {\n args.unshift('global')\n }\n\n return args.map(item => {\n if (item === '--save-dev' || item === '-D') return '--dev'\n else if (item === '--save' || item === '-S') return ''\n else if (item === '--no-package-lock') return '--no-lockfile'\n else if (item === '--save-optional') return '--optional'\n else if (item === '--save-exact' || item === '-E') return '--exact'\n else if (item === '--global' || item === '-g') return ''\n return item\n })\n },\n i (args: string[]) {\n args[0] = 'install'\n return npmToYarnTable.install(args)\n },\n uninstall (args: string[]) {\n args[0] = 'remove'\n\n if (args.includes('--global') || args.includes('-g')) {\n args.unshift('global')\n }\n\n return args.map(item => {\n if (item === '--save-dev') return '--dev'\n else if (item === '--save') return ''\n else if (item === '--no-package-lock') return '--no-lockfile'\n else if (item === '--global' || item === '-g') return ''\n return item\n })\n },\n version (args: string[]) {\n return args.map(item => {\n if (['major', 'minor', 'patch'].includes(item)) return `--${item}`\n return item\n })\n },\n rebuild (args: string[]) {\n args[0] = 'add --force'\n return args\n },\n run (args: string[]) {\n if (args[1] && !unchangedCLICommands.includes(args[1]) && !yarnCLICommands.includes(args[1])) {\n args.splice(0, 1)\n }\n return args\n },\n exec (args: string[]) {\n args[0] = 'run'\n return npmToYarnTable.run(args)\n },\n ls (args: string[]) {\n args[0] = 'list'\n\n let ended = false\n const packages = args.filter((item, id) => {\n if (id > 0 && !ended) {\n ended = item.startsWith('-')\n return !ended\n }\n return false\n })\n if (packages.length > 0) {\n args.splice(1, packages.length, '--pattern', '\"' + packages.join('|') + '\"')\n }\n return args\n },\n list (args: string[]) {\n return npmToYarnTable.ls(args)\n },\n init (args: string[]) {\n if (args[1] && !args[1].startsWith('-')) {\n args[0] = 'create'\n }\n return args.filter(item => item !== '--scope')\n },\n start: 'start',\n stop: 'stop',\n test: 'test'\n}\n\nexport function npmToYarn (_m: string, command: string): string {\n let args = parse((command || '').trim())\n\n const index = args.findIndex(a => a === '--')\n if (index >= 0) {\n args.splice(index, 1)\n }\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'yarn ' + args.join(' ')\n } else if (args[0] in npmToYarnTable) {\n const converter = npmToYarnTable[args[0] as keyof typeof npmToYarnTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'yarn ' + args.filter(Boolean).join(' ')\n } else {\n return 'yarn ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { yarnToNPM } from './yarnToNpm'\nimport { npmToYarn } from './npmToYarn'\n\n/**\n * Converts between npm and yarn command\n */\nexport default function convert (str: string, to: 'npm' | 'yarn'): string {\n if (to === 'npm') {\n return str.replace(/yarn(?: +([^&\\n\\r]*))?/gm, yarnToNPM)\n } else {\n return str.replace(/npm(?: +([^&\\n\\r]*))?/gm, npmToYarn)\n }\n}\n"],"names":[],"mappings":"AAAO,IAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;AAEpF,IAAM,eAAe,GAAG;IAC7B,MAAM;IACN,KAAK;IACL,KAAK;IACL,OAAO;IACP,WAAW;IACX,KAAK;IACL,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,qBAAqB;IACrB,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,MAAM;IACN,SAAS;IACT,UAAU;IACV,MAAM;IACN,UAA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ts","../src/index.ts"],"sourcesContent":["export const unchangedCLICommands = ['test', 'login', 'logout', 'link', 'publish', 'cache']\n\nexport const yarnCLICommands = [\n 'init',\n 'run',\n 'add',\n 'audit',\n 'autoclean',\n 'bin',\n 'check',\n 'config',\n 'create',\n 'dedupe',\n 'generate-lock-entry',\n 'global',\n 'help',\n 'import',\n 'info',\n 'install',\n 'licenses',\n 'list',\n 'lockfile',\n 'outdated',\n 'owner',\n 'pack',\n 'policies',\n 'prune',\n 'remove',\n 'self-update',\n 'tag',\n 'team',\n 'link',\n 'unlink',\n 'upgrade',\n 'upgrade-interactive',\n 'version',\n 'versions',\n 'why',\n 'workspace',\n 'workspaces'\n]\n\nexport const npmCLICommands = [\n 'init',\n 'run',\n 'access',\n 'adduser',\n 'audit',\n 'bin',\n 'bugs',\n 'build',\n 'bundle',\n 'ci',\n 'completion',\n 'config',\n 'dedupe',\n 'deprecate',\n 'dist-tag',\n 'docs',\n 'doctor',\n 'edit',\n 'explore',\n 'exec',\n 'fund',\n 'help-search',\n 'help',\n 'hook',\n 'install-ci-test',\n 'install-test',\n 'install',\n 'ls',\n 'list',\n 'npm',\n 'org',\n 'outdated',\n 'owner',\n 'pack',\n 'ping',\n 'prefix',\n 'profile',\n 'prune',\n 'rebuild',\n 'repo',\n 'restart',\n 'root',\n 'run-script',\n 'search',\n 'shrinkwrap',\n 'star',\n 'stars',\n 'start',\n 'stop',\n 'team',\n 'token',\n 'uninstall',\n 'unpublish',\n 'update',\n 'version',\n 'view',\n 'whoami'\n]\n","export function parse (command: string) {\n const args: string[] = []\n let lastQuote: string | false = false\n let escaped = false\n let part = ''\n for (let i = 0; i < command.length; ++i) {\n const char = command.charAt(i)\n if (char === '\\\\') {\n part += char\n escaped = true\n } else {\n if (char === ' ' && !lastQuote) {\n args.push(part)\n part = ''\n } else if (!escaped && (char === '\"' || char === \"'\")) {\n part += char\n if (char === lastQuote) {\n lastQuote = false\n } else if (!lastQuote) {\n lastQuote = char\n }\n } else {\n part += char\n }\n escaped = false\n }\n }\n args.push(part)\n return args\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nfunction convertAddRemoveArgs (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--no-lockfile':\n return '--no-package-lock'\n case '--production':\n return '--save-prod'\n case '--dev':\n return '--save-dev'\n case '--optional':\n return '--save-optional'\n case '--exact':\n return '--save-exact'\n default:\n return item\n }\n })\n}\n\nconst yarnToNpmTable = {\n add (args: string[]) {\n if (args.length === 2 && args[1] === '--force') {\n return ['rebuild'];\n }\n args[0] = 'install'\n if (\n !args.includes('--dev') &&\n !args.includes('--force') &&\n !args.includes('--exact') &&\n !args.includes('--optional') &&\n !args.includes('--production')\n ) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n remove (args: string[]) {\n args[0] = 'uninstall'\n if (!args.includes('--dev')) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n version (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--major':\n return 'major'\n case '--minor':\n return 'minor'\n case '--patch':\n return 'patch'\n default:\n return item\n }\n })\n },\n install: 'install',\n list (args: string[]) {\n args[0] = 'ls'\n const patternIndex = args.findIndex(item => item === '--pattern')\n if (patternIndex >= 0 && args[patternIndex + 1]) {\n const packages = args[patternIndex + 1].replace(/[\"']([^\"']+)[\"']/, '$1').split('|')\n args.splice(patternIndex, 2, packages.join(' '))\n }\n return args\n },\n init: 'init',\n create: 'init',\n run: 'run',\n start: 'start',\n stop: 'stop',\n test: 'test',\n global (args: string[]) {\n switch (args[1]) {\n case 'add':\n args.shift()\n args = yarnToNpmTable.add(args)\n args.push('--global')\n return args\n case 'remove':\n args.shift()\n args = yarnToNpmTable.remove(args)\n args.push('--global')\n return args\n case 'list':\n args.shift()\n args = yarnToNpmTable.list(args)\n args.push('--global')\n return args\n // case 'bin':\n // case 'upgrade':\n default:\n args.push(\"\\n# couldn't auto-convert command\")\n return args\n }\n }\n}\n\nexport function yarnToNPM (_m: string, command: string): string {\n command = (command || '').trim()\n if (command === '') {\n return 'npm install'\n }\n let args = parse(command)\n const firstCommand = (/\\w+/.exec(command) || [''])[0]\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'npm ' + command\n } else if (args[0] in yarnToNpmTable) {\n const converter = yarnToNpmTable[args[0] as keyof typeof yarnToNpmTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'npm ' + args.filter(Boolean).join(' ')\n } else if (!yarnCLICommands.includes(firstCommand)) {\n // i.e., yarn grunt -> npm run grunt\n return 'npm run ' + command\n } else {\n return 'npm ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nfunction convertInstallArgs (args: string[]) {\n if (args.includes('--global') || args.includes('-g')) {\n args.unshift('global')\n }\n\n return args.map(item => {\n switch (item) {\n case '--save-dev':\n case '-D':\n return '--dev'\n case '--save-prod':\n case '-P':\n return '--production'\n case '--no-package-lock':\n return '--no-lockfile'\n case '--save-optional':\n case '-O':\n return '--optional'\n case '--save-exact':\n case '-E':\n return '--exact'\n case '--save':\n case '-S':\n case '--global':\n case '-g':\n return ''\n default:\n return item\n }\n })\n}\n\nconst npmToYarnTable = {\n install (args: string[]) {\n if (args.length === 1) {\n return ['install']\n }\n args[0] = 'add'\n\n return convertInstallArgs(args)\n },\n i (args: string[]) {\n return npmToYarnTable.install(args)\n },\n uninstall (args: string[]) {\n args[0] = 'remove'\n\n return convertInstallArgs(args)\n },\n remove (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n un (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n unlink (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n r (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n rm (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n version (args: string[]) {\n return args.map(item => {\n switch (item) {\n case 'major':\n return '--major'\n case 'minor':\n return '--minor'\n case 'patch':\n return '--patch'\n default:\n return item\n }\n })\n },\n rb (args: string[]) {\n return npmToYarnTable.rebuild(args)\n },\n rebuild (args: string[]) {\n args[0] = 'add'\n args.push('--force')\n return args\n },\n run (args: string[]) {\n if (args[1] && !unchangedCLICommands.includes(args[1]) && !yarnCLICommands.includes(args[1])) {\n args.splice(0, 1)\n }\n return args\n },\n exec (args: string[]) {\n args[0] = 'run'\n return npmToYarnTable.run(args)\n },\n ls (args: string[]) {\n args[0] = 'list'\n\n let ended = false\n const packages = args.filter((item, id) => {\n if (id > 0 && !ended) {\n ended = item.startsWith('-')\n return !ended\n }\n return false\n })\n if (packages.length > 0) {\n args.splice(1, packages.length, '--pattern', '\"' + packages.join('|') + '\"')\n }\n return args\n },\n list (args: string[]) {\n return npmToYarnTable.ls(args)\n },\n init (args: string[]) {\n if (args[1] && !args[1].startsWith('-')) {\n args[0] = 'create'\n }\n return args.filter(item => item !== '--scope')\n },\n start: 'start',\n stop: 'stop',\n test: 'test'\n}\n\nexport function npmToYarn (_m: string, command: string): string {\n let args = parse((command || '').trim())\n\n const index = args.findIndex(a => a === '--')\n if (index >= 0) {\n args.splice(index, 1)\n }\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'yarn ' + args.join(' ')\n } else if (args[0] in npmToYarnTable) {\n const converter = npmToYarnTable[args[0] as keyof typeof npmToYarnTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'yarn ' + args.filter(Boolean).join(' ')\n } else {\n return 'yarn ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { yarnToNPM } from './yarnToNpm'\nimport { npmToYarn } from './npmToYarn'\n\n/**\n * Converts between npm and yarn command\n */\nexport default function convert (str: string, to: 'npm' | 'yarn'): string {\n if (to === 'npm') {\n return str.replace(/yarn(?: +([^&\\n\\r]*))?/gm, yarnToNPM)\n } else {\n return str.replace(/npm(?: +([^&\\n\\r]*))?/gm, npmToYarn)\n }\n}\n"],"names":[],"mapp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AG,CAAC,CAAA;AAChC,KAAA;AAAM,SAAA,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,cAAc,EAAE;QACpC,IAAM,SAAS,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAgC,CAAC,CAAA;AAExE,QAAA,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE;AACnC,YAAA,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;AACvB,SAAA;AAAM,aAAA;AACL,YAAA,IAAI,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;AACpB,SAAA;AAED,QAAA,OAAO,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAChD,KAAA;AAAM,SAAA;AACL,QAAA,OAAO,OAAO,GAAG,OAAO,GAAG,mCAAmC,CAAA;AAC/D,KAAA;AACH;;ACrJA;;AAEG;AACW,SAAU,OAAO,CAAE,GAAW,EAAE,EAAkB,EAAA;IAC9D,IAAI,EAAE,KAAK,KAAK,EAAE;QAChB,OAAO,GAAG,CAAC,OAAO,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAA;AAC1D,KAAA;AAAM,SAAA;QACL,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,SAAS,CAAC,CAAA;AACzD,KAAA;AACH;;;;"} \ No newline at end of file diff --git a/dist/npm-to-yarn.umd.js b/dist/npm-to-yarn.umd.js index ec32326..a00ecd5 100644 --- a/dist/npm-to-yarn.umd.js +++ b/dist/npm-to-yarn.umd.js @@ -85,6 +85,8 @@ switch (item) { case '--no-lockfile': return '--no-package-lock'; + case '--production': + return '--save-prod'; case '--dev': return '--save-dev'; case '--optional': @@ -98,11 +100,15 @@ } 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); @@ -198,61 +204,86 @@ } } - 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) { diff --git a/dist/npm-to-yarn.umd.js.map b/dist/npm-to-yarn.umd.js.map index afb9a04..2d4177f 100644 --- a/dist/npm-to-yarn.umd.js.map +++ b/dist/npm-to-yarn.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"npm-to-yarn.umd.js","sources":["../src/utils.ts","../src/command.ts","../src/yarnToNpm.ts","../src/npmToYarn.ts","../src/index.ts"],"sourcesContent":["export const unchangedCLICommands = ['test', 'login', 'logout', 'link', 'publish', 'cache']\n\nexport const yarnCLICommands = [\n 'init',\n 'run',\n 'add',\n 'audit',\n 'autoclean',\n 'bin',\n 'check',\n 'config',\n 'create',\n 'dedupe',\n 'generate-lock-entry',\n 'global',\n 'help',\n 'import',\n 'info',\n 'install',\n 'licenses',\n 'list',\n 'lockfile',\n 'outdated',\n 'owner',\n 'pack',\n 'policies',\n 'prune',\n 'remove',\n 'self-update',\n 'tag',\n 'team',\n 'link',\n 'unlink',\n 'upgrade',\n 'upgrade-interactive',\n 'version',\n 'versions',\n 'why',\n 'workspace',\n 'workspaces'\n]\n\nexport const npmCLICommands = [\n 'init',\n 'run',\n 'access',\n 'adduser',\n 'audit',\n 'bin',\n 'bugs',\n 'build',\n 'bundle',\n 'ci',\n 'completion',\n 'config',\n 'dedupe',\n 'deprecate',\n 'dist-tag',\n 'docs',\n 'doctor',\n 'edit',\n 'explore',\n 'exec',\n 'fund',\n 'help-search',\n 'help',\n 'hook',\n 'install-ci-test',\n 'install-test',\n 'install',\n 'ls',\n 'list',\n 'npm',\n 'org',\n 'outdated',\n 'owner',\n 'pack',\n 'ping',\n 'prefix',\n 'profile',\n 'prune',\n 'rebuild',\n 'repo',\n 'restart',\n 'root',\n 'run-script',\n 'search',\n 'shrinkwrap',\n 'star',\n 'stars',\n 'start',\n 'stop',\n 'team',\n 'token',\n 'uninstall',\n 'unpublish',\n 'update',\n 'version',\n 'view',\n 'whoami'\n]\n","export function parse (command: string) {\n const args: string[] = []\n let lastQuote: string | false = false\n let escaped = false\n let part = ''\n for (let i = 0; i < command.length; ++i) {\n const char = command.charAt(i)\n if (char === '\\\\') {\n part += char\n escaped = true\n } else {\n if (char === ' ' && !lastQuote) {\n args.push(part)\n part = ''\n } else if (!escaped && (char === '\"' || char === \"'\")) {\n part += char\n if (char === lastQuote) {\n lastQuote = false\n } else if (!lastQuote) {\n lastQuote = char\n }\n } else {\n part += char\n }\n escaped = false\n }\n }\n args.push(part)\n return args\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nfunction convertAddRemoveArgs (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--no-lockfile':\n return '--no-package-lock'\n case '--dev':\n return '--save-dev'\n case '--optional':\n return '--save-optional'\n case '--exact':\n return '--save-exact'\n default:\n return item\n }\n })\n}\n\nconst yarnToNpmTable = {\n add (args: string[]) {\n if (args[1] === '--force') {\n return ['rebuild']\n }\n args[0] = 'install'\n if (!args.includes('--dev') && !args.includes('--exact') && !args.includes('--optional')) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n remove (args: string[]) {\n args[0] = 'uninstall'\n if (!args.includes('--dev')) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n version (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--major':\n return 'major'\n case '--minor':\n return 'minor'\n case '--patch':\n return 'patch'\n default:\n return item\n }\n })\n },\n install: 'install',\n list (args: string[]) {\n args[0] = 'ls'\n const patternIndex = args.findIndex(item => item === '--pattern')\n if (patternIndex >= 0 && args[patternIndex + 1]) {\n const packages = args[patternIndex + 1].replace(/[\"']([^\"']+)[\"']/, '$1').split('|')\n args.splice(patternIndex, 2, packages.join(' '))\n }\n return args\n },\n init: 'init',\n create: 'init',\n run: 'run',\n start: 'start',\n stop: 'stop',\n test: 'test',\n global (args: string[]) {\n switch (args[1]) {\n case 'add':\n args.shift()\n args = yarnToNpmTable.add(args)\n args.push('--global')\n return args\n case 'remove':\n args.shift()\n args = yarnToNpmTable.remove(args)\n args.push('--global')\n return args\n case 'list':\n args.shift()\n args = yarnToNpmTable.list(args)\n args.push('--global')\n return args\n // case 'bin':\n // case 'upgrade':\n default:\n args.push(\"\\n# couldn't auto-convert command\")\n return args\n }\n }\n}\n\nexport function yarnToNPM (_m: string, command: string): string {\n command = (command || '').trim()\n if (command === '') {\n return 'npm install'\n }\n let args = parse(command)\n const firstCommand = (/\\w+/.exec(command) || [''])[0]\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'npm ' + command\n } else if (args[0] in yarnToNpmTable) {\n const converter = yarnToNpmTable[args[0] as keyof typeof yarnToNpmTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'npm ' + args.filter(Boolean).join(' ')\n } else if (!yarnCLICommands.includes(firstCommand)) {\n // i.e., yarn grunt -> npm run grunt\n return 'npm run ' + command\n } else {\n return 'npm ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nconst npmToYarnTable = {\n install (args: string[]) {\n if (args.length === 1) {\n return args\n }\n args[0] = 'add'\n\n if (args.includes('--global') || args.includes('-g')) {\n args.unshift('global')\n }\n\n return args.map(item => {\n if (item === '--save-dev' || item === '-D') return '--dev'\n else if (item === '--save' || item === '-S') return ''\n else if (item === '--no-package-lock') return '--no-lockfile'\n else if (item === '--save-optional') return '--optional'\n else if (item === '--save-exact' || item === '-E') return '--exact'\n else if (item === '--global' || item === '-g') return ''\n return item\n })\n },\n i (args: string[]) {\n args[0] = 'install'\n return npmToYarnTable.install(args)\n },\n uninstall (args: string[]) {\n args[0] = 'remove'\n\n if (args.includes('--global') || args.includes('-g')) {\n args.unshift('global')\n }\n\n return args.map(item => {\n if (item === '--save-dev') return '--dev'\n else if (item === '--save') return ''\n else if (item === '--no-package-lock') return '--no-lockfile'\n else if (item === '--global' || item === '-g') return ''\n return item\n })\n },\n version (args: string[]) {\n return args.map(item => {\n if (['major', 'minor', 'patch'].includes(item)) return `--${item}`\n return item\n })\n },\n rebuild (args: string[]) {\n args[0] = 'add --force'\n return args\n },\n run (args: string[]) {\n if (args[1] && !unchangedCLICommands.includes(args[1]) && !yarnCLICommands.includes(args[1])) {\n args.splice(0, 1)\n }\n return args\n },\n exec (args: string[]) {\n args[0] = 'run'\n return npmToYarnTable.run(args)\n },\n ls (args: string[]) {\n args[0] = 'list'\n\n let ended = false\n const packages = args.filter((item, id) => {\n if (id > 0 && !ended) {\n ended = item.startsWith('-')\n return !ended\n }\n return false\n })\n if (packages.length > 0) {\n args.splice(1, packages.length, '--pattern', '\"' + packages.join('|') + '\"')\n }\n return args\n },\n list (args: string[]) {\n return npmToYarnTable.ls(args)\n },\n init (args: string[]) {\n if (args[1] && !args[1].startsWith('-')) {\n args[0] = 'create'\n }\n return args.filter(item => item !== '--scope')\n },\n start: 'start',\n stop: 'stop',\n test: 'test'\n}\n\nexport function npmToYarn (_m: string, command: string): string {\n let args = parse((command || '').trim())\n\n const index = args.findIndex(a => a === '--')\n if (index >= 0) {\n args.splice(index, 1)\n }\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'yarn ' + args.join(' ')\n } else if (args[0] in npmToYarnTable) {\n const converter = npmToYarnTable[args[0] as keyof typeof npmToYarnTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'yarn ' + args.filter(Boolean).join(' ')\n } else {\n return 'yarn ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { yarnToNPM } from './yarnToNpm'\nimport { npmToYarn } from './npmToYarn'\n\n/**\n * Converts between npm and yarn command\n */\nexport default function convert (str: string, to: 'npm' | 'yarn'): string {\n if (to === 'npm') {\n return str.replace(/yarn(?: +([^&\\n\\r]*))?/gm, yarnToNPM)\n } else {\n return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G,OAAO,GAAG,mCAAmC,CAAA;EAC/D,KAAA;EACH;;ECjHA;;EAEG;EACW,SAAU,OAAO,CAAE,GAAW,EAAE,EAAkB,EAAA;MAC9D,IAAI,EAAE,KAAK,KAAK,EAAE;UAChB,OAAO,GAAG,CAAC,OAAO,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAA;EAC1D,KAAA;EAAM,SAAA;UACL,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,SAAS,CAAC,CAAA;EACzD,KAAA;EACH;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"npm-to-yarn.umd.js","sources":["../src/utils.ts","../src/command.ts","../src/yarnToNpm.ts","../src/npmToYarn.ts","../src/index.ts"],"sourcesContent":["export const unchangedCLICommands = ['test', 'login', 'logout', 'link', 'publish', 'cache']\n\nexport const yarnCLICommands = [\n 'init',\n 'run',\n 'add',\n 'audit',\n 'autoclean',\n 'bin',\n 'check',\n 'config',\n 'create',\n 'dedupe',\n 'generate-lock-entry',\n 'global',\n 'help',\n 'import',\n 'info',\n 'install',\n 'licenses',\n 'list',\n 'lockfile',\n 'outdated',\n 'owner',\n 'pack',\n 'policies',\n 'prune',\n 'remove',\n 'self-update',\n 'tag',\n 'team',\n 'link',\n 'unlink',\n 'upgrade',\n 'upgrade-interactive',\n 'version',\n 'versions',\n 'why',\n 'workspace',\n 'workspaces'\n]\n\nexport const npmCLICommands = [\n 'init',\n 'run',\n 'access',\n 'adduser',\n 'audit',\n 'bin',\n 'bugs',\n 'build',\n 'bundle',\n 'ci',\n 'completion',\n 'config',\n 'dedupe',\n 'deprecate',\n 'dist-tag',\n 'docs',\n 'doctor',\n 'edit',\n 'explore',\n 'exec',\n 'fund',\n 'help-search',\n 'help',\n 'hook',\n 'install-ci-test',\n 'install-test',\n 'install',\n 'ls',\n 'list',\n 'npm',\n 'org',\n 'outdated',\n 'owner',\n 'pack',\n 'ping',\n 'prefix',\n 'profile',\n 'prune',\n 'rebuild',\n 'repo',\n 'restart',\n 'root',\n 'run-script',\n 'search',\n 'shrinkwrap',\n 'star',\n 'stars',\n 'start',\n 'stop',\n 'team',\n 'token',\n 'uninstall',\n 'unpublish',\n 'update',\n 'version',\n 'view',\n 'whoami'\n]\n","export function parse (command: string) {\n const args: string[] = []\n let lastQuote: string | false = false\n let escaped = false\n let part = ''\n for (let i = 0; i < command.length; ++i) {\n const char = command.charAt(i)\n if (char === '\\\\') {\n part += char\n escaped = true\n } else {\n if (char === ' ' && !lastQuote) {\n args.push(part)\n part = ''\n } else if (!escaped && (char === '\"' || char === \"'\")) {\n part += char\n if (char === lastQuote) {\n lastQuote = false\n } else if (!lastQuote) {\n lastQuote = char\n }\n } else {\n part += char\n }\n escaped = false\n }\n }\n args.push(part)\n return args\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nfunction convertAddRemoveArgs (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--no-lockfile':\n return '--no-package-lock'\n case '--production':\n return '--save-prod'\n case '--dev':\n return '--save-dev'\n case '--optional':\n return '--save-optional'\n case '--exact':\n return '--save-exact'\n default:\n return item\n }\n })\n}\n\nconst yarnToNpmTable = {\n add (args: string[]) {\n if (args.length === 2 && args[1] === '--force') {\n return ['rebuild'];\n }\n args[0] = 'install'\n if (\n !args.includes('--dev') &&\n !args.includes('--force') &&\n !args.includes('--exact') &&\n !args.includes('--optional') &&\n !args.includes('--production')\n ) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n remove (args: string[]) {\n args[0] = 'uninstall'\n if (!args.includes('--dev')) {\n args.push('--save')\n }\n return convertAddRemoveArgs(args)\n },\n version (args: string[]) {\n return args.map(item => {\n switch (item) {\n case '--major':\n return 'major'\n case '--minor':\n return 'minor'\n case '--patch':\n return 'patch'\n default:\n return item\n }\n })\n },\n install: 'install',\n list (args: string[]) {\n args[0] = 'ls'\n const patternIndex = args.findIndex(item => item === '--pattern')\n if (patternIndex >= 0 && args[patternIndex + 1]) {\n const packages = args[patternIndex + 1].replace(/[\"']([^\"']+)[\"']/, '$1').split('|')\n args.splice(patternIndex, 2, packages.join(' '))\n }\n return args\n },\n init: 'init',\n create: 'init',\n run: 'run',\n start: 'start',\n stop: 'stop',\n test: 'test',\n global (args: string[]) {\n switch (args[1]) {\n case 'add':\n args.shift()\n args = yarnToNpmTable.add(args)\n args.push('--global')\n return args\n case 'remove':\n args.shift()\n args = yarnToNpmTable.remove(args)\n args.push('--global')\n return args\n case 'list':\n args.shift()\n args = yarnToNpmTable.list(args)\n args.push('--global')\n return args\n // case 'bin':\n // case 'upgrade':\n default:\n args.push(\"\\n# couldn't auto-convert command\")\n return args\n }\n }\n}\n\nexport function yarnToNPM (_m: string, command: string): string {\n command = (command || '').trim()\n if (command === '') {\n return 'npm install'\n }\n let args = parse(command)\n const firstCommand = (/\\w+/.exec(command) || [''])[0]\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'npm ' + command\n } else if (args[0] in yarnToNpmTable) {\n const converter = yarnToNpmTable[args[0] as keyof typeof yarnToNpmTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'npm ' + args.filter(Boolean).join(' ')\n } else if (!yarnCLICommands.includes(firstCommand)) {\n // i.e., yarn grunt -> npm run grunt\n return 'npm run ' + command\n } else {\n return 'npm ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { unchangedCLICommands, yarnCLICommands } from './utils'\nimport { parse } from './command'\n\nfunction convertInstallArgs (args: string[]) {\n if (args.includes('--global') || args.includes('-g')) {\n args.unshift('global')\n }\n\n return args.map(item => {\n switch (item) {\n case '--save-dev':\n case '-D':\n return '--dev'\n case '--save-prod':\n case '-P':\n return '--production'\n case '--no-package-lock':\n return '--no-lockfile'\n case '--save-optional':\n case '-O':\n return '--optional'\n case '--save-exact':\n case '-E':\n return '--exact'\n case '--save':\n case '-S':\n case '--global':\n case '-g':\n return ''\n default:\n return item\n }\n })\n}\n\nconst npmToYarnTable = {\n install (args: string[]) {\n if (args.length === 1) {\n return ['install']\n }\n args[0] = 'add'\n\n return convertInstallArgs(args)\n },\n i (args: string[]) {\n return npmToYarnTable.install(args)\n },\n uninstall (args: string[]) {\n args[0] = 'remove'\n\n return convertInstallArgs(args)\n },\n remove (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n un (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n unlink (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n r (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n rm (args: string[]) {\n return npmToYarnTable.uninstall(args)\n },\n version (args: string[]) {\n return args.map(item => {\n switch (item) {\n case 'major':\n return '--major'\n case 'minor':\n return '--minor'\n case 'patch':\n return '--patch'\n default:\n return item\n }\n })\n },\n rb (args: string[]) {\n return npmToYarnTable.rebuild(args)\n },\n rebuild (args: string[]) {\n args[0] = 'add'\n args.push('--force')\n return args\n },\n run (args: string[]) {\n if (args[1] && !unchangedCLICommands.includes(args[1]) && !yarnCLICommands.includes(args[1])) {\n args.splice(0, 1)\n }\n return args\n },\n exec (args: string[]) {\n args[0] = 'run'\n return npmToYarnTable.run(args)\n },\n ls (args: string[]) {\n args[0] = 'list'\n\n let ended = false\n const packages = args.filter((item, id) => {\n if (id > 0 && !ended) {\n ended = item.startsWith('-')\n return !ended\n }\n return false\n })\n if (packages.length > 0) {\n args.splice(1, packages.length, '--pattern', '\"' + packages.join('|') + '\"')\n }\n return args\n },\n list (args: string[]) {\n return npmToYarnTable.ls(args)\n },\n init (args: string[]) {\n if (args[1] && !args[1].startsWith('-')) {\n args[0] = 'create'\n }\n return args.filter(item => item !== '--scope')\n },\n start: 'start',\n stop: 'stop',\n test: 'test'\n}\n\nexport function npmToYarn (_m: string, command: string): string {\n let args = parse((command || '').trim())\n\n const index = args.findIndex(a => a === '--')\n if (index >= 0) {\n args.splice(index, 1)\n }\n\n if (unchangedCLICommands.includes(args[0])) {\n return 'yarn ' + args.join(' ')\n } else if (args[0] in npmToYarnTable) {\n const converter = npmToYarnTable[args[0] as keyof typeof npmToYarnTable]\n\n if (typeof converter === 'function') {\n args = converter(args)\n } else {\n args[0] = converter\n }\n\n return 'yarn ' + args.filter(Boolean).join(' ')\n } else {\n return 'yarn ' + command + \"\\n# couldn't auto-convert command\"\n }\n}\n","import { yarnToNPM } from './yarnToNpm'\nimport { npmToYarn } from './npmToYarn'\n\n/**\n * Converts between npm and yarn command\n */\nexport default function convert (str: string, to: 'npm' | 'yarn'): string {\n if (to === 'npm') {\n return str.replace(/yarn(?: +([^&\\n\\r]*))?/gm, yarnToNPM)\n } else {\n return str.replace(/npm(?: +([^&\\n\\r]*))?/gm, npmToYarn)\n }\n}\n"],"names":[],"mappings":";;;;;;EAAO,IAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;EAEpF,IAAM,eAAe,GAAG;MAC7B,MAAM;MACN,KAAK;MACL,KAAK;MACL,OAAO;MACP,WAAW;MACX,KAAK;MACL,OAAO;MACP,QAAQ;MACR,QAAQ;MACR,QAAQ;MACR,qBAAqB;MACrB,QAAQ;MACR,MAAM;MACN,QAAQ;MACR,MAAM;MACN,SAAS;MACT,UAAU;MACV,MAAM;MACN,UAAU;MACV,UAAU;MACV,OAAO;MACP,MAAM;MACN,UAAU;MACV,OAAO;MACP,QAAQ;MACR,aAAa;MACb,KAAK;MACL,MAAM;MACN,MAAM;MACN,QAAQ;MACR,SAAS;MACT,qBAAqB;MACrB,SAAS;MACT,UAAU;MACV,KAAK;MACL,WAAW;MACX,YAAY;GACb;;ECxCK,SAAU,KAAK,CAAE,OAAe,EAAA;MACpC,IAAM,IAAI,GAAa,EAAE,CAAA;MACzB,IAAI,SAAS,GAAmB,KAAK,CAAA;MACrC,IAAI,OAAO,GAAG,KAAK,CAAA;MACnB,IAAI,IAAI,GAAG,EAAE,CAAA;EACb,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAA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E,SAAS,CAAC,CAAA;EACzD,KAAA;EACH;;;;;;;;"} \ No newline at end of file diff --git a/src/npmToYarn.ts b/src/npmToYarn.ts index 94d6d1f..1210889 100644 --- a/src/npmToYarn.ts +++ b/src/npmToYarn.ts @@ -1,54 +1,90 @@ import { unchangedCLICommands, yarnCLICommands } from './utils' import { parse } from './command' +function convertInstallArgs (args: string[]) { + if (args.includes('--global') || args.includes('-g')) { + args.unshift('global') + } + + return args.map(item => { + switch (item) { + case '--save-dev': + case '-D': + return '--dev' + case '--save-prod': + case '-P': + return '--production' + case '--no-package-lock': + return '--no-lockfile' + case '--save-optional': + case '-O': + return '--optional' + case '--save-exact': + case '-E': + return '--exact' + case '--save': + case '-S': + case '--global': + case '-g': + return '' + default: + return item + } + }) +} + const npmToYarnTable = { install (args: string[]) { if (args.length === 1) { - return args + return ['install'] } args[0] = 'add' - if (args.includes('--global') || args.includes('-g')) { - args.unshift('global') - } - - return args.map(item => { - if (item === '--save-dev' || item === '-D') return '--dev' - else if (item === '--save' || item === '-S') return '' - else if (item === '--no-package-lock') return '--no-lockfile' - else if (item === '--save-optional') return '--optional' - else if (item === '--save-exact' || item === '-E') return '--exact' - else if (item === '--global' || item === '-g') return '' - return item - }) + return convertInstallArgs(args) }, i (args: string[]) { - args[0] = 'install' return npmToYarnTable.install(args) }, uninstall (args: string[]) { args[0] = 'remove' - if (args.includes('--global') || args.includes('-g')) { - args.unshift('global') - } - - return args.map(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 (args: string[]) { + return npmToYarnTable.uninstall(args) + }, + un (args: string[]) { + return npmToYarnTable.uninstall(args) + }, + unlink (args: string[]) { + return npmToYarnTable.uninstall(args) + }, + r (args: string[]) { + return npmToYarnTable.uninstall(args) + }, + rm (args: string[]) { + return npmToYarnTable.uninstall(args) }, version (args: string[]) { return args.map(item => { - if (['major', 'minor', 'patch'].includes(item)) return `--${item}` - return item + switch (item) { + case 'major': + return '--major' + case 'minor': + return '--minor' + case 'patch': + return '--patch' + default: + return item + } }) }, + rb (args: string[]) { + return npmToYarnTable.rebuild(args) + }, rebuild (args: string[]) { - args[0] = 'add --force' + args[0] = 'add' + args.push('--force') return args }, run (args: string[]) { diff --git a/src/yarnToNpm.ts b/src/yarnToNpm.ts index 639f90e..3499642 100644 --- a/src/yarnToNpm.ts +++ b/src/yarnToNpm.ts @@ -6,6 +6,8 @@ function convertAddRemoveArgs (args: string[]) { switch (item) { case '--no-lockfile': return '--no-package-lock' + case '--production': + return '--save-prod' case '--dev': return '--save-dev' case '--optional': @@ -20,11 +22,17 @@ function convertAddRemoveArgs (args: string[]) { const yarnToNpmTable = { add (args: string[]) { - if (args[1] === '--force') { - return ['rebuild'] + 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) diff --git a/test/index.spec.ts b/test/index.spec.ts index ca506b6..265af84 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -70,8 +70,11 @@ describe('NPM to Yarn tests', () => { }) it('npm install --save-optional', () => { expect(convert('npm install --save-optional', 'yarn')).toEqual('yarn add --optional') + expect(convert('npm i -O', 'yarn')).toEqual('yarn add --optional') expect(convert('npm i --save-optional', 'yarn')).toEqual('yarn add --optional') expect(convert('npm i --save-optional test', 'yarn')).toEqual('yarn add --optional test') + expect(convert('npm i -O', 'yarn')).toEqual('yarn add --optional') + expect(convert('npm i -O test', 'yarn')).toEqual('yarn add --optional test') }) it('npm install --save-dev', () => { expect(convert('npm install --save-dev', 'yarn')).toEqual('yarn add --dev') @@ -79,9 +82,16 @@ describe('NPM to Yarn tests', () => { expect(convert('npm i --save-dev', 'yarn')).toEqual('yarn add --dev') expect(convert('npm i -D', 'yarn')).toEqual('yarn add --dev') }) + it('npm install --save-prod', () => { + expect(convert('npm install --save-prod', 'yarn')).toEqual('yarn add --production') + expect(convert('npm i --save-prod', 'yarn')).toEqual('yarn add --production') + }) it('npm rebuild', () => { expect(convert('npm rebuild', 'yarn')).toEqual('yarn add --force') + expect(convert('npm rb', 'yarn')).toEqual('yarn add --force') + expect(convert('npm rebuild package', 'yarn')).toEqual('yarn add package --force') + expect(convert('npm rb package', 'yarn')).toEqual('yarn add package --force') }) it("npm whoami can't auto-convert to yarn", () => { @@ -175,6 +185,7 @@ describe('Yarn to NPM tests', () => { expect(convert('yarn add squirrelly --exact', 'npm')).toEqual( 'npm install squirrelly --save-exact' ) + expect(convert('yarn add test --production', 'npm')).toEqual('npm install test --save-prod') }) it('Convert with dev works', () => { @@ -218,6 +229,7 @@ describe('Yarn to NPM tests', () => { it('yarn add --force', () => { expect(convert('yarn add --force', 'npm')).toEqual('npm rebuild') + expect(convert('yarn add package --force', 'npm')).toEqual('npm install package --force') }) it('Version works', () => {