turborepo

a turborepo pipeline task that depends on a root package.json task that does not execute in each package


I have a root package.json task that does not execute in every package that calls yarn tsc.

Currently, I have it as a prebuild script in the root package.json:

"prebuild": "yarn tsc",

Is there anyway to specify this as a dependsOn element of build in the turborepo.json?

If I add tsc like below then it will get executed in the each package which is not what I want.

"pipeline": {
  "tsc": {
    "dependsOn": ["generate"],
    "outputs": ["dist-types/**"]
  },
  "build": {
    "dependsOn": ["tsc", "^build"],
    "outputs": ["dist/**"]
  },

Solution

  • Use the //# prefix to specify a root tasks

    "pipeline": {
      "//#tsc": {
        "dependsOn": ["generate"],
        "outputs": ["dist-types/**"]
      },
      "build": {
        "dependsOn": ["//#tsc", "^build"],
        "outputs": ["dist/**"]
      }
    

    https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks#running-tasks-from-the-root