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: use unfriendly name for preinstall hook #66

Merged
merged 1 commit into from
Oct 2, 2018
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: 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