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:
committed by
Patrik Oldsberg
parent
58fb21967a
commit
e6675123d8
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user