TopicsBabel.jsMonorepo Introduction

Description of the Template repo for the Lab “Extending JS”

Babel Monorepo

As many nowadays projects, the Babel project is a monorepo. It is a huge monorepo. This means that all the packages are in the same repository and they are published together.

To start with this lab you have to get familiar with mono repos first. See

The template monorepo

Workspaces are usually defined via the workspaces property of the package.json file, e.g:

{
  "name": "@ull-esit-pl-2425/babel-left-side-crguezl",
  "private": true,
  "workspaces": [
    "packages/babel-parser",
    "packages/babel-plugin-left-side",
    "packages/babel-plugin-left-side-support"
  ],
  "..." : "..."
}

Adding dependencies to a workspace

You may automate the required steps to define a new workspace using npm init. For example in a project that already has a package.json defined you can run:

npm init -w ./packages/a

This command will create the missing folders and a new package.json file (if needed) while also making sure to properly configure the "workspaces" property of your root project package.json.

Running commands in the context of workspaces

You can use the workspace configuration option to run commands in the context of a configured workspace.

npm version patch -ws 

This command will run the npm version patch command in all the workspaces defined in the package.json file.

Please note that you can also specify this argument multiple times in the command-line in order to target multiple workspaces, e.g:

npm run test --workspace=babel-parser --workspace=babel-plugin-left-side-support

See the scripts for publishing in the template package repo:

    "publishpatch": "npm version patch -ws && npm publish -ws",
    "publishminor": "npm version minor -ws && npm publish -ws",
    "publishmajor": "npm version major -ws && npm publish -ws",
    "publishactionpatch": "npm version patch -ws && npm run save && gh release create",
    "publishactionminor": "npm version minor -ws && npm run save && gh release create",
    "publishactionmajor": "npm version major -ws && npm run save && gh release create"
  • The publishaction* commands are used to publish the packages via the associated GitHub action. Notice the -ws option.
  • The publish* commands are used to publish the packages to the GitHub registry.

The save command is used to save the changes to the local repository.

"save": "git ci -am save; git push -u origin main; git push -u pl2425 main",