diff --git a/src/plugins.ts b/src/plugins.ts index 7fe80e5d..98778de0 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -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] } @@ -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 { diff --git a/test/plugins.test.ts b/test/plugins.test.ts index 587203b2..c329db2c 100644 --- a/test/plugins.test.ts +++ b/test/plugins.test.ts @@ -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() @@ -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', () => { @@ -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', () => {