Skip to content

Commit

Permalink
Fix issues with exact an optional in npm-to-yarn
Browse files Browse the repository at this point in the history
The conversion of --save-* arguments like --save-exact, and --save-optional must come before the
conversion of the `\s*--save` argument, otherwise the whitespace from the `install --save` is
rewritten as `install--save`.
  • Loading branch information
andrewnicols committed May 10, 2022
1 parent b259c07 commit 0ca3e00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ var npmToYarnTable: Indexable = {
var ret = command
.replace('install', 'add')
.replace('--save-dev', '--dev')
.replace('--save-exact', '--exact')
.replace('--save-optional', '--optional')
.replace(/\s*--save/, '')
.replace('--no-package-lock', '--no-lockfile')
.replace('--save-optional', '--optional')
.replace('--save-exact', '--exact')
if (/ -(?:-global|g)(?![^\b])/.test(ret)) {
ret = ret.replace(/ -(?:-global|g)(?![^\b])/, '')
ret = 'global ' + ret
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ describe('NPM to Yarn tests', () => {
expect(convert('npm install', 'yarn')).toEqual('yarn install')
})

it('npm install --save-exact', () => {
expect(convert('npm install --save-exact', 'yarn')).toEqual('yarn add --exact')
})
it('npm install --save-optional', () => {
expect(convert('npm install --save-optional', 'yarn')).toEqual('yarn add --optional')
})

it('npm rebuild', () => {
expect(convert('npm rebuild', 'yarn')).toEqual('yarn add --force')
})
Expand Down

0 comments on commit 0ca3e00

Please sign in to comment.