Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop cli action & rethrow install error #195

Merged
merged 1 commit into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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