Skip to content

Commit

Permalink
fix: some install/uninstall fixes
Browse files Browse the repository at this point in the history
* check if plugin is valid before installing
* fix unlinking
  • Loading branch information
jdx committed Apr 21, 2018
1 parent 5a95c59 commit 59d91a2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"yarn": "^1.6.0"
},
"devDependencies": {
"@oclif/config": "^1.6.7",
"@oclif/config": "^1.6.12",
"@oclif/dev-cli": "^1.13.4",
"@oclif/errors": "^1.0.4",
"@oclif/plugin-help": "^1.2.5",
Expand Down
1 change: 1 addition & 0 deletions src/commands/plugins/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class PluginsUninstall extends Command {
`
static variableArgs = true
static args = [{name: 'plugin', description: 'plugin to uninstall', required: true}]
static aliases = ['plugins:unlink']

plugins = new Plugins(this.config)

Expand Down
13 changes: 8 additions & 5 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export default class Plugins {
}
await this.createPJSON()
await this.yarn.exec(['add', `${name}@${tag}`])
// const plugin = await this.loadPlugin(name, range || tag)
// if (!plugin.valid) {
// throw new Error('no commands found in plugin')
// }
const plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
throw new Error('plugin is invalid')
}
await this.add({name, tag: range || tag, type: 'user'})
} catch (err) {
await this.uninstall(name).catch(err => this.debug(err))
Expand Down Expand Up @@ -90,7 +90,10 @@ export default class Plugins {

async uninstall(name: string) {
try {
await this.yarn.exec(['remove', name])
const pjson = await this.pjson()
if ((pjson.oclif.plugins || []).find(p => typeof p === 'object' && p.type === 'user' && p.name === name)) {
await this.yarn.exec(['remove', name])
}
} finally {
await this.remove(name)
}
Expand Down
63 changes: 26 additions & 37 deletions test/commands/plugins/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,37 @@ import {expect, test} from '../../test'

describe('command', () => {
test
.command(['plugins:install', 'status'], {reset: true})
.command(['plugins:install', '@oclif/example-plugin-ts'], {reset: true})
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.contain('status '))
.do(output => expect(output.stdout).to.contain('@oclif/example-plugin-ts '))
.stdout()
.command(['status'], {reset: true})
.do(output => expect(output.stdout).to.contain('No known issues at this time'))
.command(['plugins:uninstall', '@heroku-cli/plugin-status'])
.command(['hello'], {reset: true})
.do(output => expect(output.stdout).to.contain('hello world'))
.command(['plugins:uninstall', '@heroku-cli/plugin-@oclif/example-plugin-ts'])
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
.it('installs and uninstalls status')
.it('installs and uninstalls @oclif/example-plugin-ts')
// test
// .command(['plugins:install', 'heroku-debug@beta'], {reset: true})
// .stdout()
// .command(['plugins'], {reset: true})
// .do(output => expect(output.stdout).to.match(/heroku-debug \d+\.\d+\.\d+-beta \(beta\)/))
// .it('installs @heroku-cli/plugin-status@beta')

test
.command(['plugins:install', '@heroku-cli/plugin-status'], {reset: true})
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.contain('status '))
.stdout()
.command(['status'], {reset: true})
.do(output => expect(output.stdout).to.contain('No known issues at this time'))
.it('installs @heroku-cli/plugin-status')

test
.command(['plugins:install', 'heroku-debug@beta'], {reset: true})
.stdout()
.command(['plugins'], {reset: true})
.do(output => expect(output.stdout).to.match(/heroku-debug \d+\.\d+\.\d+-beta \(beta\)/))
.it('installs @heroku-cli/plugin-status@beta')

test
.skip()
.command(['plugins:install', 'heroku-debug'])
.stdout()
.command(['plugins'])
.do(output => expect(output.stdout).to.contain('heroku-debug'))
.stdout()
.command(['debug'])
.do(output => expect(output.stdout).to.contain('foo'))
.command(['plugins:uninstall', 'heroku-debug'])
.stdout()
.command(['plugins'])
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))
.it('installs and uninstalls heroku-debug')
// test
// .skip()
// .command(['plugins:install', 'heroku-debug'])
// .stdout()
// .command(['plugins'])
// .do(output => expect(output.stdout).to.contain('heroku-debug'))
// .stdout()
// .command(['debug'])
// .do(output => expect(output.stdout).to.contain('foo'))
// .command(['plugins:uninstall', 'heroku-debug'])
// .stdout()
// .command(['plugins'])
// .do(output => expect(output.stdout).to.equal('no plugins installed\n'))
// .it('installs and uninstalls heroku-debug')
})
8 changes: 7 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@
debug "^3.1.0"
semver "^5.5.0"

"@oclif/config@^1.6.6", "@oclif/config@^1.6.7":
"@oclif/config@^1.6.12":
version "1.6.12"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.6.12.tgz#e422019e3a6e63a0e4bbb9d8ad8c8f6dab2c58af"
dependencies:
debug "^3.1.0"

"@oclif/config@^1.6.6":
version "1.6.7"
resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.6.7.tgz#0b924a4c99b08c19d40ec4661511ea5ce55c7a0b"
dependencies:
Expand Down

0 comments on commit 59d91a2

Please sign in to comment.