Hello all,
In a previous work, I introduced a mechanism to make it easier for Webjar Maven projects to build their resources using npm.
I’m in the process of refining this mechanism to use pnpm instead.
The two main benefits are
- Workspace | pnpm - allowing to group all packages in a common workspace, making it easy to have packages depending on each other
- Catalogs | pnpm - allowing to share package dependencies uniformly in a workspace.
This is also an important step to be able to move packages from cristal to xwiki-platform, which are already based on pnpm workspaces.
To track this work, see XCOMMONS-3464 and the following PRs:
- xwiki-commons XCOMMONS-3464: Migrate to pnpm by manuelleduc · Pull Request #1487 · xwiki/xwiki-commons · GitHub
- xwiki-platform XCOMMONS-3464: Migrate to pnpm by manuelleduc · Pull Request #4721 · xwiki/xwiki-platform · GitHub
Commons PR description
I’m duplicating and expanding the content of the PR description here to ease the reading.
npm is replaced by pnpm in webjar-node.
This allows us to have all the webjar-node modules as a pnpm workspace (see XCOMMONS-3464: Migrate to pnpm by manuelleduc · Pull Request #4721 · xwiki/xwiki-platform · GitHub).
This also allows us to use pnpm catalogs which is a recent mechanism to centralize dependency versions instead of duplicating them in all packages.
We experienced it in Cristal first and proved successful and greatly simplified npm dependencies upgrades.
This is also well supported by renovate.
An additional benefit is that the lock file is now unique at the root of the repository instead of one for each module.
Because of having all the packages in the pnpm workspace, I stopped moving the JavaScript sources to target before starting the build.
This is important because when the sources are moved, they are not part of the workspace anymore (or with a duplicated package id), and this is breaking dependency resolution.
The main cons I’d like to highlight is that since the JavaScript build is now done “inplace”, a dist and a node_modules are created during the build (they are git ignore, but are still there).
To the best of my knowledge, this approach is the best option we have.
Having all the build artifacts in the target directories while preserving a sound pnpm workspace would imply tweaking versioned files (e.g., pnpm-workspace.yml at build time), which seems worse than producing git ignored directories at build time.
Conclusion
This is a breaking change for webjar-node. I consider this ok since this was introduced in June this year and can be considered as unstable. To my knowledge, only the Cristal Integration extension is using it outside XS.
The production of git ignored directories outside the Maven target directory is unusual, and I’d like to validate that this is not creating unforeseen issues.
Thanks!