From 1e926f68a3d48207109173d01b78c9e78ee3efec Mon Sep 17 00:00:00 2001 From: Bob Bergman Date: Tue, 2 Oct 2018 16:45:40 -0600 Subject: [PATCH] fix: use unfriendly name for preinstall hook --- src/commands/plugins/install.ts | 27 ++++++++++++++------------- src/plugins.ts | 8 ++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/commands/plugins/install.ts b/src/commands/plugins/install.ts index 9dbc6b5e..8dadfa5e 100644 --- a/src/commands/plugins/install.ts +++ b/src/commands/plugins/install.ts @@ -35,7 +35,7 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins for (let name of argv) { if (aliases[name] === null) this.error(`${name} is blacklisted`) name = aliases[name] || name - let p = parsePlugin(name) + let p = await this.parsePlugin(name) let plugin if (p.type === 'npm') { cli.action.start(`Installing plugin ${chalk.cyan(this.plugins.friendlyName(p.name))}`) @@ -50,18 +50,19 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins cli.action.stop(`installed v${plugin.version}`) } } -} -function parsePlugin(input: string): {name: string, tag: string, type: 'npm'} | {url: string, type: 'repo'} { - if (input.includes('@') && input.includes('/')) { - input = input.slice(1) - let [name, tag = 'latest'] = input.split('@') - return {name: '@' + name, tag, type: 'npm'} - } else if (input.includes('/')) { - if (input.includes(':')) return {url: input, type: 'repo'} - else return {url: `https://github.com/${input}`, type: 'repo'} - } else { - let [name, tag = 'latest'] = input.split('@') - return {name, tag, type: 'npm'} + async parsePlugin(input: string): Promise<{name: string, tag: string, type: 'npm'} | {url: string, type: 'repo'}> { + if (input.includes('@') && input.includes('/')) { + input = input.slice(1) + let [name, tag = 'latest'] = input.split('@') + return {name: '@' + name, tag, type: 'npm'} + } else if (input.includes('/')) { + if (input.includes(':')) return {url: input, type: 'repo'} + else return {url: `https://github.com/${input}`, type: 'repo'} + } else { + let [name, tag = 'latest'] = input.split('@') + name = await this.plugins.maybeUnfriendlyName(name) + return {name, tag, type: 'npm'} + } } } diff --git a/src/plugins.ts b/src/plugins.ts index af2b04db..821a36c2 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -185,6 +185,14 @@ export default class Plugins { return `@${scope}/plugin-${name}` } + async maybeUnfriendlyName(name: string): Promise { + const unfriendly = this.unfriendlyName(name) + if (unfriendly && await this.npmHasPackage(unfriendly)) { + return unfriendly + } + return name + } + friendlyName(name: string): string { const scope = this.config.pjson.oclif.scope if (!scope) return name