Skip to content

Commit

Permalink
fix: use unfriendly name for preinstall hook (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Oct 2, 2018
1 parent 7cc37ca commit b5d38e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))}`)
Expand All @@ -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'}
}
}
}
8 changes: 8 additions & 0 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ export default class Plugins {
return `@${scope}/plugin-${name}`
}

async maybeUnfriendlyName(name: string): Promise<string> {
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
Expand Down

0 comments on commit b5d38e2

Please sign in to comment.