From e6675123d88d04f83cb80bb6a1da1fe1553d43c8 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Tue, 17 Mar 2026 10:37:38 +0100 Subject: [PATCH] Refactor plugin package validation to trim and check for valid npm package names Signed-off-by: Vincenzo Scamporlino --- .../preparation/collectPortableTemplateInput.test.ts | 12 ++++++++++-- .../lib/preparation/collectPortableTemplateInput.ts | 6 ++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.test.ts b/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.test.ts index 7436793630..f76fec6329 100644 --- a/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.test.ts +++ b/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.test.ts @@ -237,7 +237,11 @@ describe('collectTemplateParams', () => { }), ); - expect(inquirer.prompt).toHaveBeenCalled(); + expect(inquirer.prompt).toHaveBeenCalledWith( + expect.arrayContaining([ + expect.objectContaining({ name: 'pluginPackage' }), + ]), + ); }); it('should re-prompt when pluginPackage is prefilled with an invalid name', async () => { @@ -262,7 +266,11 @@ describe('collectTemplateParams', () => { }), ); - expect(inquirer.prompt).toHaveBeenCalled(); + expect(inquirer.prompt).toHaveBeenCalledWith( + expect.arrayContaining([ + expect.objectContaining({ name: 'pluginPackage' }), + ]), + ); }); }); diff --git a/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.ts b/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.ts index 0c89eff6f9..415774d6ac 100644 --- a/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.ts +++ b/packages/cli-module-new/src/lib/preparation/collectPortableTemplateInput.ts @@ -71,10 +71,8 @@ export async function collectPortableTemplateInput( template.role === 'backend-plugin-module' || template.role === 'frontend-plugin-module' ) { - if ( - parameters.pluginPackage && - !isValidNpmPackageName(parameters.pluginPackage as string) - ) { + const pluginPkg = (parameters.pluginPackage as string | undefined)?.trim(); + if (!pluginPkg || !isValidNpmPackageName(pluginPkg)) { delete parameters.pluginPackage; }