Refactor plugin package validation to trim and check for valid npm package names

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2026-03-17 10:37:38 +01:00
committed by Patrik Oldsberg
parent 58fb21967a
commit e6675123d8
2 changed files with 12 additions and 6 deletions
@@ -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' }),
]),
);
});
});
@@ -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;
}