diff --git a/.changeset/true-results-shake.md b/.changeset/true-results-shake.md new file mode 100644 index 0000000000..ab0f1210b3 --- /dev/null +++ b/.changeset/true-results-shake.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Fixes an issue where using the `backstage-cli new --scope` command with a scope that already includes the `@` symbol (e.g., `@backstage-community`) would result in a double `@@` prefix in the generated package name, causing invalid `package.json` files. diff --git a/packages/cli/src/modules/new/commands/new.test.ts b/packages/cli/src/modules/new/commands/new.test.ts index 77ee96cd09..2183d80062 100644 --- a/packages/cli/src/modules/new/commands/new.test.ts +++ b/packages/cli/src/modules/new/commands/new.test.ts @@ -23,6 +23,8 @@ describe.each([ [undefined, undefined, undefined], ['internal', '@internal/', 'backstage-plugin-'], ['internal/', '@internal/', 'backstage-plugin-'], + ['@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-'], diff --git a/packages/cli/src/modules/new/commands/new.ts b/packages/cli/src/modules/new/commands/new.ts index 9d09f42cf3..a38316dd62 100644 --- a/packages/cli/src/modules/new/commands/new.ts +++ b/packages/cli/src/modules/new/commands/new.ts @@ -42,7 +42,10 @@ export default async (opts: ArgOptions) => { let pluginInfix: string | undefined = undefined; let packagePrefix: string | undefined = undefined; if (scope) { - packagePrefix = scope.includes('/') ? `@${scope}` : `@${scope}/`; + const normalizedScope = scope.startsWith('@') ? scope : `@${scope}`; + packagePrefix = normalizedScope.includes('/') + ? normalizedScope + : `${normalizedScope}/`; pluginInfix = scope.includes('backstage') ? 'plugin-' : 'backstage-plugin-'; }