0

I have three packages in my turborepo monorepo, top, middle, and bottom. top depends on middle and middle depends on bottom.

If I do this:

cd bottom
make some edits
cd ../middle
make some edits

I want to type something in that directory (middle) that will build everything that middle depends on (i.e. bottom) and middle itself.

I know I can cd to the root of the project and do this:

turbo run build --filter=middle...

but I want a command (or a script) that knows what directory I am in and basically says "build everything up to and including here"

Mike Hogan
  • 9,933
  • 9
  • 41
  • 71

2 Answers2

0

In case it's of use to any one, I added this to by .zshrc:

find-up () {
  path=$(pwd)
  while [[ "$path" != "" && ! -e "$path/$1" ]]; do
    path=${path%/*}
  done
  echo "$path"
}


bt () {
    ROOT_DIR=$(find-up "pnpm-workspace.yaml")
    PKG_NAME=$(npm pkg get name | sed -e s#\"##g)
    (cd $ROOT_DIR && pnpm run build --filter=$PKG_NAME...)
}

Now I can cd into middle and type bt (standing for build to) and it will build everything up to and including the current package. Would love to know a better way!

Mike Hogan
  • 9,933
  • 9
  • 41
  • 71
0

According to TurboRepo's documentation, you simply need to add "dependsOn": ["^build"] to the pipeline.build in turbo.json. When you run npm run build on the monorepo top folder, it should build in order according to the dependencies of each workspace.

Here is an example for the turbo.json file.

{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    "build": {
      // "A workspace's `build` command depends on its dependencies'
      // and devDependencies' `build` commands being completed first"
      "dependsOn": ["^build"],
      "outputs": [".next/**", "!.next/cache/**"]
    }
  }
jose
  • 220
  • 1
  • 12