Skip to content

Commit 716569c

Browse files
authored
fix: allow tagged packages to be uninstalled (#202)
1 parent 1bc2c19 commit 716569c

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

src/commands/plugins/uninstall.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export default class PluginsUninstall extends Command {
3636
if (flags.verbose) this.plugins.verbose = true
3737
if (argv.length === 0) argv.push('.')
3838
for (const plugin of argv) {
39-
const friendly = this.plugins.friendlyName(plugin)
39+
const friendly = this.removeTags(this.plugins.friendlyName(plugin))
4040
cli.action.start(`Uninstalling ${friendly}`)
41-
const unfriendly = await this.plugins.hasPlugin(plugin)
41+
const unfriendly = await this.plugins.hasPlugin(this.removeTags(plugin))
4242
if (!unfriendly) {
4343
const p = this.config.plugins.find(p => p.name === plugin) as Plugin | undefined
4444
if (p) {
@@ -51,4 +51,19 @@ export default class PluginsUninstall extends Command {
5151
}
5252
}
5353
/* eslint-enable no-await-in-loop */
54+
55+
private removeTags(plugin: string) {
56+
if (plugin.includes('@')) {
57+
const chunked = plugin.split('@')
58+
const last = chunked[chunked.length - 1]
59+
60+
if (!last.includes('/') && chunked.length > 1) {
61+
chunked.pop()
62+
}
63+
64+
return chunked.join('@')
65+
}
66+
67+
return plugin
68+
}
5469
}

src/plugins.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,10 @@ export default class Plugins {
181181

182182
async hasPlugin(name: string) {
183183
const list = await this.list()
184-
return list.find(p => {
185-
if (this.friendlyName(p.name) === this.friendlyName(name)) return true
186-
if (p.type === 'link') {
187-
if (path.resolve(p.root) === path.resolve(name)) return true
188-
}
189-
return false
190-
})
184+
const friendly = list.find(p => this.friendlyName(p.name) === this.friendlyName(name))
185+
const unfriendly = list.find(p => this.unfriendlyName(p.name) === this.unfriendlyName(name))
186+
const link = list.find(p => p.type === 'link' && path.resolve(p.root) === path.resolve(name))
187+
return friendly ?? unfriendly ?? link ?? false
191188
}
192189

193190
async yarnNodeVersion(): Promise<string | undefined> {

test/commands/plugins/index.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ describe('command', () => {
1515
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
1616
.it('installs and uninstalls @oclif/example-plugin-ts')
1717

18+
test
19+
.command(['plugins:install', '@oclif/example-plugin-ts@latest'], {reset: true})
20+
.stdout()
21+
.command(['plugins'], {reset: true})
22+
.do(output => expect(output.stdout).to.contain('@oclif/example-plugin-ts'))
23+
.command(['plugins:uninstall', '@oclif/example-plugin-ts@latest'], {reset: true})
24+
.stdout()
25+
.command(['plugins'], {reset: true})
26+
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
27+
.it('installs and uninstalls @oclif/example-plugin-ts with tags')
28+
1829
test
1930
.command(['plugins:install', 'aliasme'], {reset: true})
2031
.stdout()

0 commit comments

Comments
 (0)