Skip to content

Commit 62040f2

Browse files
authored
fix: stop cli action & rethrow install error (#195)
1 parent 2b619fd commit 62040f2

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/commands/plugins/install.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,22 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins
5555
await this.config.runHook('plugins:preinstall', {
5656
plugin: p,
5757
})
58-
if (p.type === 'npm') {
59-
cli.action.start(
60-
`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`,
61-
)
62-
plugin = await this.plugins.install(p.name, {
63-
tag: p.tag,
64-
force: flags.force,
65-
})
66-
} else {
67-
cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
68-
plugin = await this.plugins.install(p.url, {force: flags.force})
58+
try {
59+
if (p.type === 'npm') {
60+
cli.action.start(
61+
`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`,
62+
)
63+
plugin = await this.plugins.install(p.name, {
64+
tag: p.tag,
65+
force: flags.force,
66+
})
67+
} else {
68+
cli.action.start(`Installing plugin ${chalk.cyan(p.url)}`)
69+
plugin = await this.plugins.install(p.url, {force: flags.force})
70+
}
71+
} catch (error) {
72+
cli.action.stop(chalk.bold.red('failed'))
73+
throw error
6974
}
7075
cli.action.stop(`installed v${plugin.version}`)
7176
}

src/plugins.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export default class Plugins {
5555
await this.createPJSON()
5656
let plugin
5757
const add = force ? ['add', '--force'] : ['add']
58+
const invalidPluginError = new CLIError('plugin is invalid', {
59+
suggestions: [
60+
'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.',
61+
],
62+
})
5863
if (name.includes(':')) {
5964
// url
6065
const url = name
@@ -63,7 +68,7 @@ export default class Plugins {
6368
plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
6469
await this.refresh(plugin.root)
6570
if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
66-
throw new Error('plugin is invalid')
71+
throw invalidPluginError
6772
}
6873
await this.add({name, url, type: 'user'})
6974
} else {
@@ -76,7 +81,7 @@ export default class Plugins {
7681
await this.yarn.exec([...add, `${name}@${tag}`], yarnOpts)
7782
plugin = await Config.load({devPlugins: false, userPlugins: false, root: path.join(this.config.dataDir, 'node_modules', name), name})
7883
if (!plugin.valid && !this.config.plugins.find(p => p.name === '@oclif/plugin-legacy')) {
79-
throw new Error('plugin is invalid')
84+
throw invalidPluginError
8085
}
8186
await this.refresh(plugin.root)
8287
await this.add({name, tag: range || tag, type: 'user'})

0 commit comments

Comments
 (0)