diff --git a/.changeset/thick-deers-destroy.md b/.changeset/thick-deers-destroy.md new file mode 100644 index 0000000000..1b5cad1d64 --- /dev/null +++ b/.changeset/thick-deers-destroy.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Fix a bug in the translation of the deprecated `--scope` option for the `new` command that could cause plugins to have `backstage-backstage-plugin` in their name. diff --git a/packages/cli/src/commands/new/new.test.ts b/packages/cli/src/commands/new/new.test.ts new file mode 100644 index 0000000000..e1cb3b0ffa --- /dev/null +++ b/packages/cli/src/commands/new/new.test.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createNewPackage } from '../../lib/new/createNewPackage'; +import { default as newCommand } from './new'; + +jest.mock('../../lib/new/createNewPackage'); + +describe.each([ + [undefined, undefined, undefined], + ['internal', '@internal/', 'backstage-plugin-'], + ['internal/', '@internal/', 'backstage-plugin-'], + ['acme-backstage', '@acme-backstage/', 'plugin-'], + ['acme-backstage/', '@acme-backstage/', 'plugin-'], + ['acme-backstage-plugins', '@acme-backstage-plugins/', 'plugin-'], +])('new', (scope, prefix, infix) => { + beforeEach(() => { + jest.resetAllMocks(); + }); + + it(`should generate naming options for --scope=${scope}`, async () => { + await newCommand({ scope, option: [], skipInstall: false }); + expect(createNewPackage).toHaveBeenCalledWith( + expect.objectContaining({ + configOverrides: { + packageNamePrefix: prefix, + packageNamePluginInfix: infix, + }, + }), + ); + }); +}); diff --git a/packages/cli/src/commands/new/new.ts b/packages/cli/src/commands/new/new.ts index 5c06555905..970034429c 100644 --- a/packages/cli/src/commands/new/new.ts +++ b/packages/cli/src/commands/new/new.ts @@ -42,10 +42,7 @@ export default async (opts: ArgOptions) => { let pluginInfix: string | undefined = undefined; let packagePrefix: string | undefined = undefined; if (scope) { - const backstagePrefix = scope.startsWith('backstage') ? '' : 'backstage-'; - packagePrefix = scope.includes('/') - ? `@${scope}${backstagePrefix}` - : `@${scope}/${backstagePrefix}`; + packagePrefix = scope.includes('/') ? `@${scope}` : `@${scope}/`; pluginInfix = scope.includes('backstage') ? 'plugin-' : 'backstage-plugin-'; }