Skip to content

Commit

Permalink
fix: add missing conversion for link/ln/unlink
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 15, 2023
1 parent 08c746a commit 043cf08
Show file tree
Hide file tree
Showing 8 changed files with 392 additions and 381 deletions.
691 changes: 345 additions & 346 deletions dist/npm-to-yarn.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/npm-to-yarn.mjs.map

Large diffs are not rendered by default.

31 changes: 15 additions & 16 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.

13 changes: 3 additions & 10 deletions src/npmToYarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ const npmToYarnTable = {
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)
},
Expand Down Expand Up @@ -122,9 +116,8 @@ const npmToYarnTable = {
}
return args.filter(item => item !== '--scope')
},
start: 'start',
stop: 'stop',
test: 'test'
ln: 'link',
un: 'unlink'
}

export function npmToYarn (_m: string, command: string): string {
Expand All @@ -136,7 +129,7 @@ export function npmToYarn (_m: string, command: string): string {
}

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

Expand Down
15 changes: 12 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
export const unchangedCLICommands = ['test', 'login', 'logout', 'link', 'publish', 'cache']
export const unchangedCLICommands = [
'test',
'login',
'logout',
'link',
'unlink',
'publish',
'cache',
'start',
'stop',
'test'
]

export const yarnCLICommands = [
'init',
Expand Down Expand Up @@ -29,8 +40,6 @@ export const yarnCLICommands = [
'self-update',
'tag',
'team',
'link',
'unlink',
'upgrade',
'upgrade-interactive',
'version',
Expand Down
5 changes: 1 addition & 4 deletions src/yarnToNpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function convertAddRemoveArgs (args: string[]) {
const yarnToNpmTable = {
add (args: string[]) {
if (args.length === 2 && args[1] === '--force') {
return ['rebuild'];
return ['rebuild']
}
args[0] = 'install'
if (
Expand Down Expand Up @@ -71,9 +71,6 @@ const yarnToNpmTable = {
init: 'init',
create: 'init',
run: 'run',
start: 'start',
stop: 'stop',
test: 'test',
global (args: string[]) {
switch (args[1]) {
case 'add':
Expand Down
14 changes: 14 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('NPM to Yarn tests', () => {
})

it('Simple convert works w/ remove', () => {
expect(convert('npm r squirrelly', 'yarn')).toEqual('yarn remove squirrelly')
expect(convert('npm remove squirrelly', 'yarn')).toEqual('yarn remove squirrelly')
expect(convert('npm uninstall squirrelly', 'yarn')).toEqual('yarn remove squirrelly')
})

Expand Down Expand Up @@ -171,6 +173,13 @@ describe('NPM to Yarn tests', () => {
expect(convert('npm ls --production', 'yarn')).toEqual('yarn list --production')
expect(convert('npm ls --development', 'yarn')).toEqual('yarn list --development')
})

it('npm link/unlink', () => {
expect(convert('npm ln custom', 'yarn')).toEqual('yarn link custom')
expect(convert('npm link custom', 'yarn')).toEqual('yarn link custom')
expect(convert('npm unlink custom', 'yarn')).toEqual('yarn unlink custom')
expect(convert('npm un custom', 'yarn')).toEqual('yarn unlink custom')
})
})

describe('Yarn to NPM tests', () => {
Expand Down Expand Up @@ -295,4 +304,9 @@ describe('Yarn to NPM tests', () => {
expect(convert('yarn list --production', 'npm')).toEqual('npm ls --production')
expect(convert('yarn list --development', 'npm')).toEqual('npm ls --development')
})

it('npm link/unlink', () => {
expect(convert('yarn link custom', 'npm')).toEqual('npm link custom')
expect(convert('yarn unlink custom', 'npm')).toEqual('npm unlink custom')
})
})

0 comments on commit 043cf08

Please sign in to comment.