diff --git a/frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts b/frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts index 41afbda70d3..a47d31dc4f7 100644 --- a/frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts +++ b/frontend/packages/console-dynamic-plugin-sdk/src/webpack/ConsoleRemotePlugin.ts @@ -149,6 +149,28 @@ const validateConsoleProvidedSharedModules = (pkg: ConsolePluginPackageJSON) => return result; }; +/** + * PatternFly packages that support dynamic modules to be used with webpack module federation. + * + * Console provided {@link sharedPluginModules} should NOT be listed here. + */ +const dynamicModulePatternFlyPackages = [ + '@patternfly/react-charts', + '@patternfly/react-core', + '@patternfly/react-data-view', + '@patternfly/react-icons', + '@patternfly/react-table', + '@patternfly/react-templates', +]; + +type DynamicModulePackageSpec = Partial<{ + /** @default 'dist/esm/index.js' */ + indexModule: string; + + /** @default 'module' */ + resolutionField: string; +}>; + export type ConsoleRemotePluginOptions = Partial<{ /** * Console dynamic plugin metadata. @@ -250,21 +272,10 @@ export type ConsoleRemotePluginOptions = Partial<{ * Each package listed here should include a `dist/dynamic` directory containing `package.json` * files that refer to specific modules of that package. * - * If not specified, the following packages will be included: - * - `@patternfly/react-core` - * - `@patternfly/react-icons` - * - `@patternfly/react-table` + * If not specified, use packages listed in {@link dynamicModulePatternFlyPackages} with default + * settings. */ - packageSpecs: Record< - string, - Partial<{ - /** @default 'dist/esm/index.js' */ - indexModule: string; - - /** @default 'module' */ - resolutionField: string; - }> - >; + packageSpecs: Record; /** * Import transformations will be applied to modules that match this filter. @@ -331,24 +342,24 @@ export class ConsoleRemotePlugin implements WebpackPluginInstance { path.resolve(process.cwd(), 'node_modules'), ]; - this.sharedDynamicModuleMaps = Object.entries( - this.adaptedOptions.sharedDynamicModuleSettings.packageSpecs ?? { - '@patternfly/react-core': {}, - '@patternfly/react-icons': {}, - '@patternfly/react-table': {}, - }, - ).reduce>( - (acc, [pkgName, { indexModule = 'dist/esm/index.js', resolutionField = 'module' }]) => { - const basePath = resolvedModulePaths - .map((p) => path.resolve(p, pkgName)) - .find((p) => fs.existsSync(p) && fs.statSync(p).isDirectory()); - - return basePath - ? { ...acc, [pkgName]: getDynamicModuleMap(basePath, indexModule, resolutionField) } - : acc; - }, - {}, - ); + const sharedDynamicModulePackageSpecs = + this.adaptedOptions.sharedDynamicModuleSettings.packageSpecs ?? + dynamicModulePatternFlyPackages.reduce>( + (acc, moduleName) => ({ ...acc, [moduleName]: {} }), + {}, + ); + + this.sharedDynamicModuleMaps = Object.entries(sharedDynamicModulePackageSpecs).reduce< + Record + >((acc, [pkgName, { indexModule = 'dist/esm/index.js', resolutionField = 'module' }]) => { + const basePath = resolvedModulePaths + .map((p) => path.resolve(p, pkgName)) + .find((p) => fs.existsSync(p) && fs.statSync(p).isDirectory()); + + return basePath + ? { ...acc, [pkgName]: getDynamicModuleMap(basePath, indexModule, resolutionField) } + : acc; + }, {}); } apply(compiler: Compiler) {