Enhance plugin package input handling by clearing empty/invalid values and updating pre-population logic
Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
committed by
Patrik Oldsberg
parent
11060e329a
commit
769cb030b9
@@ -214,6 +214,56 @@ describe('collectTemplateParams', () => {
|
||||
packagePath: 'plugins/custom-backend-module-my-extension',
|
||||
});
|
||||
});
|
||||
|
||||
it('should re-prompt when pluginPackage is prefilled with an empty string', async () => {
|
||||
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
|
||||
pluginPackage: '@mycompany/plugin-custom-backend',
|
||||
});
|
||||
|
||||
await expect(
|
||||
collectPortableTemplateInput({
|
||||
...backendModuleOptions,
|
||||
prefilledParams: {
|
||||
pluginId: 'custom',
|
||||
moduleId: 'my-extension',
|
||||
pluginPackage: '',
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
roleParams: expect.objectContaining({
|
||||
pluginPackage: '@mycompany/plugin-custom-backend',
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(inquirer.prompt).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should re-prompt when pluginPackage is prefilled with an invalid name', async () => {
|
||||
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
|
||||
pluginPackage: '@mycompany/plugin-custom-backend',
|
||||
});
|
||||
|
||||
await expect(
|
||||
collectPortableTemplateInput({
|
||||
...backendModuleOptions,
|
||||
prefilledParams: {
|
||||
pluginId: 'custom',
|
||||
moduleId: 'my-extension',
|
||||
pluginPackage: 'INVALID PACKAGE NAME!',
|
||||
},
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
expect.objectContaining({
|
||||
roleParams: expect.objectContaining({
|
||||
pluginPackage: '@mycompany/plugin-custom-backend',
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(inquirer.prompt).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('frontend-plugin-module with pluginPackage', () => {
|
||||
|
||||
@@ -65,20 +65,28 @@ export async function collectPortableTemplateInput(
|
||||
...deprecatedParams,
|
||||
};
|
||||
|
||||
// Pre-populate pluginPackage for known plugins so the prompt is skipped
|
||||
// Pre-populate pluginPackage for known plugins so the prompt is skipped.
|
||||
// Also clear out empty/invalid values so they don't bypass the prompt.
|
||||
if (
|
||||
(template.role === 'backend-plugin-module' ||
|
||||
template.role === 'frontend-plugin-module') &&
|
||||
parameters.pluginId &&
|
||||
!parameters.pluginPackage
|
||||
template.role === 'backend-plugin-module' ||
|
||||
template.role === 'frontend-plugin-module'
|
||||
) {
|
||||
const knownPackages =
|
||||
template.role === 'backend-plugin-module'
|
||||
? knownBackendPluginPackageNameByPluginId
|
||||
: knownFrontendPluginPackageNameByPluginId;
|
||||
const knownPackage = knownPackages[parameters.pluginId as string];
|
||||
if (knownPackage) {
|
||||
parameters.pluginPackage = knownPackage;
|
||||
if (
|
||||
parameters.pluginPackage &&
|
||||
!isValidNpmPackageName(parameters.pluginPackage as string)
|
||||
) {
|
||||
delete parameters.pluginPackage;
|
||||
}
|
||||
|
||||
if (parameters.pluginId && !parameters.pluginPackage) {
|
||||
const knownPackages =
|
||||
template.role === 'backend-plugin-module'
|
||||
? knownBackendPluginPackageNameByPluginId
|
||||
: knownFrontendPluginPackageNameByPluginId;
|
||||
const knownPackage = knownPackages[parameters.pluginId as string];
|
||||
if (knownPackage) {
|
||||
parameters.pluginPackage = knownPackage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user