Skip to content

Commit

Permalink
feat: configurable pluginPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 18, 2023
1 parent dbdb4df commit a071ef1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export default class Plugins {
}

friendlyName(name: string): string {
const {scope} = this.config.pjson.oclif
const {pluginPrefix, scope} = this.config.pjson.oclif
if (!scope) return name
const match = name.match(`@${scope}/plugin-(.+)`)
const match = name.match(`@${scope}/${pluginPrefix ?? 'plugin'}-(.+)`)
if (!match) return name
return match[1]
}
Expand Down Expand Up @@ -256,9 +256,9 @@ export default class Plugins {

unfriendlyName(name: string): string | undefined {
if (name.includes('@')) return
const {scope} = this.config.pjson.oclif
const {pluginPrefix, scope} = this.config.pjson.oclif
if (!scope) return
return `@${scope}/plugin-${name}`
return `@${scope}/${pluginPrefix ?? 'plugin'}-${name}`
}

async uninstall(name: string): Promise<void> {
Expand Down
14 changes: 14 additions & 0 deletions test/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe('Plugins', () => {
beforeEach(async () => {
sandbox = createSandbox()
config = await Config.load(process.cwd())
config.pjson.oclif = {
...config.pjson.oclif,
pluginPrefix: undefined,
}
plugins = new Plugins(config)
// @ts-expect-error because savePJSON is private
saveStub = sandbox.stub(plugins, 'savePJSON').resolves()
Expand Down Expand Up @@ -85,6 +89,11 @@ describe('Plugins', () => {
sandbox.stub(config.pjson.oclif, 'scope').value(null)
expect(plugins.friendlyName(linkedPlugin.name)).to.equal('@oclif/plugin-linked')
})

it('should return friendly name for plugin when pluginPrefix is defined', () => {
sandbox.stub(config.pjson.oclif, 'pluginPrefix').value('foo')
expect(plugins.friendlyName('@oclif/foo-bar')).to.equal('bar')
})
})

describe('unfriendlyName', () => {
Expand All @@ -100,6 +109,11 @@ describe('Plugins', () => {
sandbox.stub(config.pjson.oclif, 'scope').value(null)
expect(plugins.unfriendlyName(linkedPlugin.name)).to.be.undefined
})

it('should return full name when pluginPrefix is defined', () => {
sandbox.stub(config.pjson.oclif, 'pluginPrefix').value('foo')
expect(plugins.unfriendlyName('bar')).to.equal('@oclif/foo-bar')
})
})

describe('maybeUnfriendlyName', () => {
Expand Down

0 comments on commit a071ef1

Please sign in to comment.