How to configure a project based on a distribution to ensure versions are consistent with the distribution#
When you have a project that is based on a distribution, we need to make sure that the versions of the frontend packages in the project are consistent with the versions in the distribution and that these versions are all in sync across all the build.
We achieve the enforcement of the versions by running a script upgrade-distribution.js along with a custom pnpm configuration via .pnpmfile.cjs that ensures the distribution versions are used when installing dependencies.
We can set up this script and configuration in any project based on a distribution, and in the future we will include it in the frontend template for kitconcept projects based on a distribution.
upgrade-distribution.js#
frontend/scripts/upgrade-distribution.js keeps local frontend distribution config in sync with repository.toml and the add-on package dependencies.
What it reads#
repository.toml([frontend.package]):base_package(distribution package name)path(path to the frontend add-on package)
<path>/package.json: finds the distribution version declared forbase_packagenpm metadata via
pnpm view:distribution
dependenciesdistribution
volto_version(falls back to installed packagevolto_version)
existing
frontend/volto.config.js(only to preserveaddonsandtheme)
What it writes#
frontend/volto.config.jsrewrites the file
preserves existing
addonsandthemeupdates
distributionto:nameversionvolto_versiondependencies
frontend/mrs.developer.jsonsets
core.tagto the resolved distributionvolto_version
How Makefile uses it#
In frontend/Makefile, target upgrade runs:
node scripts/upgrade-distribution.jspnpm exec prettier --log-level silent --write volto.config.js
This means the script is the first step that updates the files it controls (volto.config.js and mrs.developer.json) before dependency resolution and installation.
Setting up upgrade-distribution.js and the configuration#
In the future it will be included in the frontend template for kitconcept projects based on a distribution.
For now, you can follow these instructions:
Copy it from
frontend/scripts/upgrade-distribution.jsin this repository to your projectfrontend/scriptsfolder. Createfrontend/scriptsif it doesn't exist in your project.Make sure to have a
repository.tomlin your project root with the required fields ([frontend.package]withbase_packageandpath).Make sure to have the distribution package declared as a dependency in your add-on
package.json.Copy
frontend/scripts/.pnpmfile.cjsto your projectfrontendfolder.Amend your
frontend/Makefileto add a newupgradecommand. It should look like this:
upgrade:
node scripts/upgrade-distribution.js
pnpm exec prettier --log-level silent --write volto.config.js
Copy
frontend/scripts/internalChecks.test.tsto your add-onsrcfolder. This will add a test that checks that the distribution versions are consistent with the distribution package dependencies. You might have to installvitestas a dev dependency to run the test.Run
make upgradefrom yourfrontendfolder to trigger the update and install flow.Check the changes in
frontend/volto.config.jsandfrontend/mrs.developer.jsonto verify the update.Run the tests
make testto verify the internal check.