Search code examples
angularversion-controlyarnpkglernamonorepo

Can I manage same version for all the sub-package in lerna monorepo?


my-lerna-repo/
package.json
packages/
    package-1/
        package.json
    package-2/
        package.json
            dependencies: {
                package-1
            }

I want to keep consistent version for for all the sub-packages. Also We have cross dependencies in sub-packages.

I want to achieve similar to how angular does.

https://github.com/angular/angular

They only manage package version at root level and in all sub-packages they mentioned 0.0.0-PLACEHOLDER. Build time it pick the version from root package.

Please let me know if there is any existing way to do this or I need to write my own custom script.


Solution

  • Based on Lerna documentation if you want to publish all packages under the same version you need to use zero (0) as the major Lerna version in lenra.json file.

    Note: If you have a major version zero, all updates are considered breaking. Because of that, running lerna publish with a major version zero and choosing any non-prerelease version number will cause new versions to be published for all packages, even if not all packages have changed since the last release.

    This is the mode that Babel is currently using. Use this if you want to automatically tie all package versions together. One issue with this approach is that a major change in any package will result in all packages having a new major version.

    Example: "0" or "0.1.0"

    {
      "packages": [
        "packages/*"
      ],
      "useWorkspaces": true,
      "npmClient": "yarn",
      "version": "0"
    }