Merge pull request #31771 from elaine-mattos/fix/cli-new-scope-arg-value

Fix `backstage-cli` new scope arg value
This commit is contained in:
Ben Lambert
2025-11-18 09:53:59 +01:00
committed by GitHub
3 changed files with 11 additions and 1 deletions
+5
View File
@@ -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.
@@ -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-'],
+4 -1
View File
@@ -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-';
}