Skip to content

Commit

Permalink
fix: allow tagged packages to be uninstalled (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadian authored Nov 19, 2020
1 parent 1bc2c19 commit 716569c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
19 changes: 17 additions & 2 deletions src/commands/plugins/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default class PluginsUninstall extends Command {
if (flags.verbose) this.plugins.verbose = true
if (argv.length === 0) argv.push('.')
for (const plugin of argv) {
const friendly = this.plugins.friendlyName(plugin)
const friendly = this.removeTags(this.plugins.friendlyName(plugin))
cli.action.start(`Uninstalling ${friendly}`)
const unfriendly = await this.plugins.hasPlugin(plugin)
const unfriendly = await this.plugins.hasPlugin(this.removeTags(plugin))
if (!unfriendly) {
const p = this.config.plugins.find(p => p.name === plugin) as Plugin | undefined
if (p) {
Expand All @@ -51,4 +51,19 @@ export default class PluginsUninstall extends Command {
}
}
/* eslint-enable no-await-in-loop */

private removeTags(plugin: string) {
if (plugin.includes('@')) {
const chunked = plugin.split('@')
const last = chunked[chunked.length - 1]

if (!last.includes('/') && chunked.length > 1) {
chunked.pop()
}

return chunked.join('@')
}

return plugin
}
}
11 changes: 4 additions & 7 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,10 @@ export default class Plugins {

async hasPlugin(name: string) {
const list = await this.list()
return list.find(p => {
if (this.friendlyName(p.name) === this.friendlyName(name)) return true
if (p.type === 'link') {
if (path.resolve(p.root) === path.resolve(name)) return true
}
return false
})
const friendly = list.find(p => this.friendlyName(p.name) === this.friendlyName(name))
const unfriendly = list.find(p => this.unfriendlyName(p.name) === this.unfriendlyName(name))
const link = list.find(p => p.type === 'link' && path.resolve(p.root) === path.resolve(name))
return friendly ?? unfriendly ?? link ?? false
}

async yarnNodeVersion(): Promise<string | undefined> {
Expand Down
11 changes: 11 additions & 0 deletions test/commands/plugins/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ describe('command', () => {
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
.it('installs and uninstalls @oclif/example-plugin-ts')

test
.command(['plugins:install', '@oclif/example-plugin-ts@latest'], {reset: true})
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.contain('@oclif/example-plugin-ts'))
.command(['plugins:uninstall', '@oclif/example-plugin-ts@latest'], {reset: true})
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
.it('installs and uninstalls @oclif/example-plugin-ts with tags')

test
.command(['plugins:install', 'aliasme'], {reset: true})
.stdout()
Expand Down

0 comments on commit 716569c

Please sign in to comment.