Skip to content

Commit

Permalink
fix: stop cli action & rethrow install error (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo committed Nov 10, 2020
1 parent 2b619fd commit 62040f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
27 changes: 16 additions & 11 deletions src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,22 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins
await this.config.runHook('plugins:preinstall', {
plugin: p,
})
if (p.type === 'npm') {
cli.action.start(
`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`,
)
plugin = await this.plugins.install(p.name, {
tag: p.tag,
force: flags.force,
})
} else {
cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
plugin = await this.plugins.install(p.url, {force: flags.force})
try {
if (p.type === 'npm') {
cli.action.start(
`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`,
)
plugin = await this.plugins.install(p.name, {
tag: p.tag,
force: flags.force,
})
} else {
cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
plugin = await this.plugins.install(p.url, {force: flags.force})
}
} catch (error) {
cli.action.stop(chalk.bold.red('failed'))
throw error
}
cli.action.stop(`installed v${plugin.version}`)
}
Expand Down
9 changes: 7 additions & 2 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export default class Plugins {
await this.createPJSON()
let plugin
const add = force ? ['add', '--force'] : ['add']
const invalidPluginError = new CLIError('plugin is invalid', {
suggestions: [
'Plugin failed to install because it does not appear to be a valid CLI plugin.\nIf you are sure it is, contact the CLI developer noting this error.',
],
})
if (name.includes(':')) {
// url
const url = name
Expand All @@ -63,7 +68,7 @@ export default class Plugins {
plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
await this.refresh(plugin.root)
if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
throw new Error('plugin is invalid')
throw invalidPluginError
}
await this.add({name, url, type: 'user'})
} else {
Expand All @@ -76,7 +81,7 @@ export default class Plugins {
await this.yarn.exec([...add, `${name}@${tag}`], yarnOpts)
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')
throw invalidPluginError
}
await this.refresh(plugin.root)
await this.add({name, tag: range || tag, type: 'user'})
Expand Down

0 comments on commit 62040f2

Please sign in to comment.