[Solved] Can we have a 'version' in the top level package.json?

What will happen if I add a ‘version’ to the top level package.json?

To clarify, this version would represent the version of your app/site code – not the Redwood version it is currently using?

yes, agreed.

I really like version-bump-prompt to manage my version numbers

while I can step into the web & api and version them independently, that’s a PITA

thanks

Is this a question for the nx-workspace team instead?

Adding a version field to the top level package.json of an app created with CRWA (e.g. yarn create redwood-app my-redwood-app) is an issue for yarn. Your Redwood app is a monorepo using Yarn Workspaces. Yarn’s docs on versioning show using versions in each “side” (workspace, e.g. api and web) but not in the root package.json - and the default in the CRWA is to set the workspace versions to 0.0.0 with the expectation that you will manage versioning for each separately.

To get a single command to bump your workspace versions together, you could either set up Lerna to manage the monorepo (and then use Lerna’s version command), or add scripts to handle it for your Yarn Workspaces like:

  "scripts": {
    "version:api": "cd api && yarn version --new-version $npm_package_version  --no-git-tag-version",
    "version:web": "cd web && yarn version --new-version $npm_package_version  --no-git-tag-version",
    "postversion": "yarn version:api && yarn version:web"
  }

And then to bump the default CRWA app to version 0.0.1, run yarn version --patch. Please note the above isn’t tested - just an idea.

If you do go the Lerna route and want to publish all packages under the same version, you need to use zero (0) as the major Lerna version in your lerna.json file.

1 Like

Ah, yarn workspaces (not nx) ok – I’ll go look over there.

My primary issue is I can’t use the same version number on multiple workspaces. Attempting to do so results in a duplicate tag error. For this project I’m deploying the web & api workspaces in parallel so I’d like there to be one vers/build

And Yarn workspaces comes to the rescue !!

yarn version apply all --new-version 0.5.0

This applied a version number to the workspace root package.json

Now bump -tpa works to bump the version number of the whole monorepo

Nice !!

(bump, courtesy of version-bump-prompt)

1 Like