8000 feat: uninstall command `nrm` (#17) · antfu-collective/ni@0b6ac9d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 0b6ac9d

Browse files
vltanskyantfu
andauthored
feat: uninstall command nrm (#17)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 460aac2 commit 0b6ac9d

File tree

9 files changed

+108
-3
lines changed

9 files changed

+108
-3
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,36 @@ if the corresponding node manager is not present, this command will install it g
128128

129129
<br>
130130

131+
### `nrm` - uninstall
132+
133+
```bash
134+
nrm
135+
136+
# npm uninstall axios
137+
# yarn remove axios
138+
# pnpm remove axios
139+
```
140+
141+
```bash
142+
nrm @types/node -D
143+
144+
# npm uninstall @types/node -D
145+
# yarn remove @types/node -D
146+
# pnpm remove @types/node -D
147+
```
148+
149+
```bash
150+
nrm -g iroiro
151+
152+
# npm uninstall -g iroiro
153+
# yarn global remove iroiro
154+
# pnpm remove -g iroiro
155+
156+
# this uses default agent, regardless your current working directory
157+
```
158+
159+
<br>
160+
131161
### Config
132162

133163
```ini

bin/nrm.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
require('../dist/nrm')

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"nci": "bin/nci.js",
2121
"nr": "bin/nr.js",
2222
"nu": "bin/nu.js",
23-
"nx": "bin/nx.js"
23+
"nx": "bin/nx.js",
24+
"nrm": "bin/nrm.js"
2425
},
2526
"bugs": {
2627
"url": "https://github.com/antfu/ni/issues"
@@ -34,8 +35,9 @@
3435
"nr": "esno src/nr.ts",
3536
"nu": "esno src/nu.ts",
3637
"nx": "esno src/nx.ts",
38+
"nrm": "esno src/nrm.ts",
3739
"dev": "esno src/ni.ts",
38-
"build": "rimraf dist && tsup src/ni.ts src/nci.ts src/nr.ts src/nu.ts src/nx.ts src/index.ts --format cjs,esm --dts",
40+
"build": "rimraf dist && tsup src/ni.ts src/nci.ts src/nr.ts src/nu.ts src/nx.ts src/nrm.ts src/index.ts --format cjs,esm --dts",
3941
"release": "npx git-ensure && npx bumpp --commit --push --tag",
4042
"lint": "eslint \"**/*.ts\"",
4143
"lint:fix": "npm run lint -- --fix",

src/agents.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const AGENTS = {
1414
'upgrade': 'npm update {0}',
1515
'upgrade-interactive': null,
1616
'execute': 'npx {0}',
17+
'uninstall': 'npm uninstall {0}',
18+
'global_uninstall': 'npm uninstall -g {0}',
1719
},
1820
yarn: {
1921
'run': 'yarn run {0}',
@@ -24,6 +26,8 @@ export const AGENTS = {
2426
'upgrade': 'yarn upgrade {0}',
2527
'upgrade-interactive': 'yarn upgrade-interactive',
2628
'execute': 'yarn dls {0}',
29+
'uninstall': 'yarn remove {0}',
30+
'global_uninstall': 'yarn global remove {0}',
2731
},
2832
pnpm: {
2933
'run': npmRun('pnpm'),
@@ -34,6 +38,8 @@ export const AGENTS = {
3438
'upgrade': 'pnpm update {0}',
3539
'upgrade-interactive': 'pnpm update -i',
3640
'execute': 'pnpx {0}',
41+
'uninstall': 'pnpm remove {0}',
42+
'global_uninstall': 'pnpm remove -g {0}',
3743
},
3844
}
3945

src/commands.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export function getCommand(
1616

1717
if (!c)
1818
throw new Error(`Command "${command}" is not support by agent "${agent}"`)
19-
2019
return c.replace('{0}', args.join(' ')).trim()
2120
}
2221

@@ -61,6 +60,13 @@ export function parseNu(agent: Agent, args: string[]): string {
6160
return getCommand(agent, 'upgrade', args)
6261
}
6362

63+
64+
export function parseNrm(agent: Agent, args: string[]): string {
65+
if (args.includes('-g'))
66+
return getCommand(agent, 'global_uninstall', exclude(args, '-g'))
67+
return getCommand(agent, 'uninstall', args)
68+
}
69+
6470
export function parseNx(agent: Agent, args: string[]): string {
6571
return getCommand(agent, 'execute', args)
6672
}

src/nrm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { parseNrm } from './commands'
2+
import { runCli } from './runner'
3+
4+
runCli(parseNrm)

test/nrm/npm.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import test, { ExecutionContext } from 'ava'
2+
import { parseNrm } from '../../src/commands'
3+
4+
const agent = 'npm'
5+
const _ = (arg: string, expected: string) => (t: ExecutionContext) => {
6+
t.is(
7+
parseNrm(agent, arg.s 10000 plit(' ').filter(Boolean)),
8+
expected,
9+
)
10+
}
11+
12+
test('single remove', _('axios', 'npm uninstall axios'))
13+
14+
test('multiple', _('eslint @types/node', 'npm uninstall eslint @types/node'))
15+
16+
test('-D', _('eslint @types/node -D', 'npm uninstall eslint @types/node -D'))
17+
18+
test('global', _('eslint -g', 'npm uninstall -g eslint'))

test/nrm/pnpm.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import test, { ExecutionContext } from 'ava'
2+
import { parseNrm } from '../../src/commands'
3+
4+
const agent = 'pnpm'
5+
const _ = (arg: string, expected: string) => (t: ExecutionContext) => {
6+
t.is(
7+
parseNrm(agent, arg.split(' ').filter(Boolean)),
8+
expected,
9+
)
10+
}
11+
12+
test('single remove', _('axios', 'pnpm remove axios'))
13+
14+
test('multiple', _('eslint @types/node', 'pnpm remove eslint @types/node'))
15+
16+
test('-D', _('eslint @types/node -D', 'pnpm remove eslint @types/node -D'))
17+
18+
test('global', _('eslint -g', 'pnpm remove -g eslint'))

test/nrm/yarn.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import test, { ExecutionContext } from 'ava'
2+
import { parseNrm } from '../../src/commands'
3+
4+
const agent = 'yarn'
5+
const _ = (arg: string, expected: string) => (t: ExecutionContext) => {
6+
t.is(
7+
parseNrm(agent, arg.split(' ').filter(Boolean)),
8+
expected,
9+
)
10+
}
11+
12+
test('single remove', _('axios', 'yarn remove axios'))
13+
14+
test('multiple', _('eslint @types/node', 'yarn remove eslint @types/node'))
15+
16+
test('-D', _('eslint @types/node -D', 'yarn remove eslint @types/node -D'))
17+
18+
test('global', _('eslint ni -g', 'yarn global remove eslint ni'))

0 commit comments

Comments
 (0)
0