Skip to content

Commit b5d38e2

Browse files
authored
fix: use unfriendly name for preinstall hook (#66)
1 parent 7cc37ca commit b5d38e2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/commands/plugins/install.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins
3535
for (let name of argv) {
3636
if (aliases[name] === null) this.error(`${name} is blacklisted`)
3737
name = aliases[name] || name
38-
let p = parsePlugin(name)
38+
let p = await this.parsePlugin(name)
3939
let plugin
4040
if (p.type === 'npm') {
4141
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
5050
cli.action.stop(`installed v${plugin.version}`)
5151
}
5252
}
53-
}
5453

55-
function parsePlugin(input: string): {name: string, tag: string, type: 'npm'} | {url: string, type: 'repo'} {
56-
if (input.includes('@') && input.includes('/')) {
57-
input = input.slice(1)
58-
let [name, tag = 'latest'] = input.split('@')
59-
return {name: '@' + name, tag, type: 'npm'}
60-
} else if (input.includes('/')) {
61-
if (input.includes(':')) return {url: input, type: 'repo'}
62-
else return {url: `https://github.com/${input}`, type: 'repo'}
63-
} else {
64-
let [name, tag = 'latest'] = input.split('@')
65-
return {name, tag, type: 'npm'}
54+
async parsePlugin(input: string): Promise<{name: string, tag: string, type: 'npm'} | {url: string, type: 'repo'}> {
55+
if (input.includes('@') && input.includes('/')) {
56+
input = input.slice(1)
57+
let [name, tag = 'latest'] = input.split('@')
58+
return {name: '@' + name, tag, type: 'npm'}
59+
} else if (input.includes('/')) {
60+
if (input.includes(':')) return {url: input, type: 'repo'}
61+
else return {url: `https://github.com/${input}`, type: 'repo'}
62+
} else {
63+
let [name, tag = 'latest'] = input.split('@')
64+
name = await this.plugins.maybeUnfriendlyName(name)
65+
return {name, tag, type: 'npm'}
66+
}
6667
}
6768
}

src/plugins.ts

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ export default class Plugins {
185185
return `@${scope}/plugin-${name}`
186186
}
187187

188+
async maybeUnfriendlyName(name: string): Promise<string> {
189+
const unfriendly = this.unfriendlyName(name)
190+
if (unfriendly && await this.npmHasPackage(unfriendly)) {
191+
return unfriendly
192+
}
193+
return name
194+
}
195+
188196
friendlyName(name: string): string {
189197
const scope = this.config.pjson.oclif.scope
190198
if (!scope) return name

0 commit comments

Comments
 (0)