patternfly-react
patternfly-react copied to clipboard
Generate dist/dynamic-modules.json for relevant packages
This PR modifies scripts/build-single-packages.js so that it also generates a dist/dynamic-modules.json file for each package containing dynamic modules.
$ find . -name dynamic-modules.json
./packages/react-charts/dist/dynamic-modules.json
./packages/react-core/dist/dynamic-modules.json
./packages/react-icons/dist/dynamic-modules.json
./packages/react-table/dist/dynamic-modules.json
We generate dynamic-modules.json files to make it easier for consuming projects to share specific PatternFly dynamic modules (instead of sharing the whole package indexes) via webpack module federation.
Each dynamic-modules.json file maps package index exports to their corresponding dynamic modules, for example:
// packages/react-core/dist/dynamic-modules.json
{
"ASTERISK": "dist/dynamic/helpers/htmlConstants",
"AboutModal": "dist/dynamic/components/AboutModal",
"AboutModalProps": "dist/dynamic/components/AboutModal",
"Accordion": "dist/dynamic/components/Accordion",
"AccordionContent": "dist/dynamic/components/Accordion",
"AccordionContentProps": "dist/dynamic/components/Accordion",
"AccordionExpandableContentBody": "dist/dynamic/components/Accordion",
"AccordionExpandableContentBodyProps": "dist/dynamic/components/Accordion",
"AccordionItem": "dist/dynamic/components/Accordion",
"AccordionItemProps": "dist/dynamic/components/Accordion",
"AccordionProps": "dist/dynamic/components/Accordion",
"AccordionToggle": "dist/dynamic/components/Accordion",
"AccordionToggleProps": "dist/dynamic/components/Accordion",
// ...
}
The algorithm that parses dynamic module information favors non-deprecated modules with most specific file paths, for example dist/dynamic/components/Wizard/hooks is favored over dist/dynamic/components/Wizard.
Note: this code is ported from openshift/console#13521
Preview: https://patternfly-react-pr-10046.surge.sh
A11y report: https://patternfly-react-pr-10046-a11y.surge.sh
@vojtechszocs @Hyperkid123 I'm noticing here that the generated react-core/dist/dynamic-modules.json file is listing:
...
"Modal": "dist/dynamic/next/components/Modal",
"ModalBox": "dist/dynamic/components/Modal",
...
So i'm not sure this is accounting for next components correctly.
@vojtechszocs I think the next/deprecated modules should not be listed. There are conflicting names and the API difference will cause unexpected issues.
@Hyperkid123 @nicolethoen
You are right, module paths containing either "next" or "deprecated" should be excluded.
This issue also exists in OpenShift Console dynamic plugin SDK code (dynamic-module-parser.ts).
I'll update this PR as well as relevant Console code.
@nicolethoen PR updated, please have a look.
Dynamic modules nested under
deprecatedornextdirectories are ignored.