From da19cb5dd15439c27d183f278eaafc103bdd59ed Mon Sep 17 00:00:00 2001 From: solimant Date: Thu, 23 Oct 2025 22:38:21 +0000 Subject: [PATCH] Fix package name plugin infix with yarn new Signed-off-by: solimant --- .changeset/funny-stars-open.md | 5 +++ .../loadPortableTemplateConfig.test.ts | 6 ++-- .../preparation/loadPortableTemplateConfig.ts | 35 ++++++++++++++----- 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 .changeset/funny-stars-open.md diff --git a/.changeset/funny-stars-open.md b/.changeset/funny-stars-open.md new file mode 100644 index 0000000000..336e68bac1 --- /dev/null +++ b/.changeset/funny-stars-open.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Fix inconsistent behavior in the `new` command for the `@internal` scope: it now consistently defaults to the `backstage-plugin-` infix whether the `--scope` option is not set or it's set to `internal`. diff --git a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.test.ts b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.test.ts index b8a7940bcf..f8167ef339 100644 --- a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.test.ts +++ b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.test.ts @@ -196,7 +196,7 @@ describe('loadPortableTemplateConfig', () => { private: true, version: '0.1.0', packageNamePrefix: '@internal/', - packageNamePluginInfix: 'plugin-', + packageNamePluginInfix: 'backstage-plugin-', }); }); @@ -316,7 +316,7 @@ describe('loadPortableTemplateConfig', () => { version: '0.1.0', private: true, packageNamePrefix: '@internal/', - packageNamePluginInfix: 'plugin-', + packageNamePluginInfix: 'backstage-plugin-', }); await expect( @@ -333,7 +333,7 @@ describe('loadPortableTemplateConfig', () => { version: '0.1.0', private: true, packageNamePrefix: '@internal/', - packageNamePluginInfix: 'plugin-', + packageNamePluginInfix: 'backstage-plugin-', }); }); }); diff --git a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts index 5ef61bfb6b..2e736d9c29 100644 --- a/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts +++ b/packages/cli/src/modules/new/lib/preparation/loadPortableTemplateConfig.ts @@ -70,6 +70,21 @@ type LoadConfigOptions = { overrides?: Partial; }; +function computePackageNamePluginInfix( + packageNamePrefix: string, + namePluginInfix?: string, +) { + const packageNamePluginInfix = + namePluginInfix ?? + (packageNamePrefix.includes('backstage') + ? defaults.packageNamePluginInfix + : 'backstage-plugin-'); + + return { + packageNamePluginInfix, + }; +} + export async function loadPortableTemplateConfig( options: LoadConfigOptions = {}, ): Promise { @@ -116,6 +131,16 @@ export async function loadPortableTemplateConfig( templateNameConflicts.set(pointer.name, rawPointer); } + const packageNamePrefix = + overrides.packageNamePrefix ?? + config?.globals?.namePrefix ?? + defaults.packageNamePrefix; + + const { packageNamePluginInfix } = computePackageNamePluginInfix( + packageNamePrefix, + overrides.packageNamePluginInfix ?? config?.globals?.namePluginInfix, + ); + return { isUsingDefaultTemplates: !config?.templates, templatePointers: templatePointerEntries.map(({ pointer }) => pointer), @@ -126,14 +151,8 @@ export async function loadPortableTemplateConfig( overrides.publishRegistry ?? config?.globals?.publishRegistry ?? defaults.publishRegistry, - packageNamePrefix: - overrides.packageNamePrefix ?? - config?.globals?.namePrefix ?? - defaults.packageNamePrefix, - packageNamePluginInfix: - overrides.packageNamePluginInfix ?? - config?.globals?.namePluginInfix ?? - defaults.packageNamePluginInfix, + packageNamePrefix, + packageNamePluginInfix, }; }