Hello, As part of working on OFBIZ-12789 to see if we could further utilise NPM as a repository of various javascript modules rather than keep those modules' sources in the OFBiz source repository, I went down a bit of a rabbit hole changing the OFBiz build to allow node/npm use in multiple OFBiz components (gradle sub-projects).
My aim was to allow a plugin to be able to use npm modules without having to modify the ofbiz-framework parent build.gradle file. The current use of npm for common-theme involves configuration applied in the root build.gradle file. The result was a 'convention' plugin, created in ofbiz-framework/buildSrc which describes how the Gradle Node Plugin should be applied to a gradle project. OFBiz components wishing to use node when building can 'apply' the ofbiz-node-conventions plugin to their gradle sub-project which will: - apply and configure the com.github.node-gradle plugin - configure the plugin to use 'npm install' or 'npm ci' depending on if the CI environment variable is defined. - run 'npm install/ci' as part of the 'classes' parent gradle task, ensuring npm modules have been retrieved regardless of whether gradle is being used to build, run or create a distribution of OFBiz. - clean up retrieved node_modules as part of the parent project's 'cleanAll' task. These changes can be viewed in PR ( https://github.com/apache/ofbiz-framework/pull/621). [ Note: Gradle documents relating to 'convention' plugins: - https://docs.gradle.org/current/samples/sample_convention_plugins.html - https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources ] A corresponding PR has been created for ofbiz-plugins ( https://github.com/apache/ofbiz-plugins/pull/77). This PR introduces a change to the example plugin to demonstrate use of the Gradle Node Plugin in an OFBiz plugin component. In the case of the example plugin, a small Typescript React web application, created using Vite, has been integrated to show an OFBiz screen can be rendered to include CSS and javascript created by an npm build step. If there is an appetite to keep this functionality in the example plugin, perhaps we can extend the react app to call the REST api to retrieve and display live OFBiz data. I think these changes will be very useful for plugins which need to incorporate a web front-end, such as eCommerce, rest-api (swagger), solr and webpos. These plugins all use some externally sourced javascript modules which should hopefully be available from NPM. In my opinion it would be great to get these modules out of the OFBiz sources and retrieve them at build time. QUESTIONS Any concerns about this approach to retrieving javascript code at build time? We already decided to take this approach with common-theme, but applying the pattern more widely will increase the time it takes to perform an initial build. Subsequent builds should be faster since node_modules would have already been downloaded by all components using the build pattern. Should we apply these changes to Release 22.01? I would like to do so as I think it will make it easier for system integrators to deploy more feature rich plugins with OFBiz. However I do appreciate that we need to stop making changes to 22.01 at some point otherwise we'll keep delaying its eventual release. However again, if these changes are useful for system integrators, then it could be years before they can use them in a future 23.xx/24.xx release. Please give the PRs a try and let me know what you think. Thanks, Dan. -- Daniel Watford
