Nodejs Monorepo

Use changesets as monorepo mananger.


GitHub - atlassian/changesets: πŸ¦‹ A way to manage your versioning and changelogs with a focus on monorepos

Use Changesets as monorepo managerπŸ”—

Init a monorepoπŸ”—

mkdir monorepo && cd monorepo
git init
# Add .gitignore file for nodejs <>
npm init --yes

Add "private":"true" to the root package.json

npm init -w packages/a
npm init -w packages/b
npm init -w packages/c

Let c depends a and b,


"dependencies": {

to packages/c/package.json

Install changesetsπŸ”—

Also see here

npm install -D @changesets/cli && npx changeset init

This action will add a .changeset folder, and a couple of files to help you out:

You should change the .changeset/config.json -> baseBranch to yourself main branch, also change access to public

Commit current files.

git add .
git commit -m "feat: init"

That’s done.


First publishπŸ”—

First publish you should just use the follow command to publish your module

npx changeset publish

Future changesπŸ”—

You should see changesets philosophy

You should first create an intent to change, that said, before what ever changes you want to make, you should create a intent change

npx changeset

…Make some changes

Now, generate new version, changeset will take care your dependences,

Note, by default, if a upgrade from 1.0.1 to 1.0.2, c depends on a@^1.0.1, then c package.json will not change, cause npm will auto update a@^1.0.1 to the last version 1.0.2 if you want change to the exact version every time, you can set the config to

 "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
    "updateInternalDependents": "always"
npx changeset version

Then, you can publish it.

npx changeset publish
git add .
git commit -m "chore: version"
git push --follow-tags

With CIπŸ”—

I’ll use Github Actions as example.

The CI workflow assume that you use εΌ€ε‘ζŠ€ε·§ζ”Άθ— as your git workflow.

Note, you can use @changesets/changelog-github as your changelog format log. with this, you can generate a log like this , without this, then the log will only include commit link > npm i -D @changesets/changelog-github

  "changelog": [
    { "repo": "theowenyoung/monorepo-example" }
  1. Create a script in root package.json
  "scripts": {
    "version-packages": "changeset version",
    "release": "changeset publish"
  1. Create github actions workflows
mkdir -p .github/workflows
touch .github/workflows/release.yml

With the following content:

name: Release

      - main

    name: Release
    runs-on: ubuntu-latest
      - name: Checkout Repo
        uses: actions/checkout@master
          # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
          fetch-depth: 0

      - name: Setup Node.js 12.x
        uses: actions/setup-node@master
          node-version: 12.x
      - name: Setup NPM Latest
        run: npm i -g npm
      - name: Install Dependencies
        run: npm i

      - name: Create Release Pull Request or Publish to npm
        uses: changesets/action@master
          # this expects you to have a script called release which does a build for your packages and calls changeset publish
          publish: npm run release
          version: npm run version-packages
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  1. Add NPM_TOKEN to your github repo secret settings

By εΌ€ε‘ζŠ€ε·§ζ”Άθ—

npm token create


Every time you use npx changeset to generate a new changeset intent, and the change is pulled to the main branch, then CI will create a pull request to generate a new version, and after the pull request was merged, CI will publish npm packages, and create a new release.

Category: Dev 
Published:   πŸ“ Edit this page


Have you written a response to this? Let me know the article or tweet URL (Article or tweet content needs to include the URL of this article, learn more about webmention here).

The response will be automatically collected by bot, and another bot will automatically post it here within 24 hours, I wrote an article about how to achieve this. You can also send your response via mail or Twitter DM