GʀᴜᴍᴘʏCᴀᴛ
GʀᴜᴍᴘʏCᴀᴛ

Reputation: 8972

With Syncpack on a turborepo how to set app version dependencies through a package?

In a turborepo with Syncpack setup if I have 10 apps that all use the same 30 dependencies how can I properly build that out in the .syncpackrc file?

within the app package.json

apps/foo

package.json:

  "dependencies": {
    "@repo/config-react": "workspace:*",
  },
  "devDependencies": {
    "@repo/config-react": "workspace:*",
  }

For example within my packages I have a config for React:

packages/config-react

package.json:

{
  "name": "@repo/config-react",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "react": "19.0.0",
    "react-dom": "19.0.0"
  },
  "devDependencies": {
    "@types/node": "22.10.1",
    "@types/react": "19.0.0",
    "@types/react-dom": "19.0.1"
  }
}

I then set it in .syncpackrc as:

{
  "versionGroups": [
    {
      "label": "React Version",
      "dependencies": [
        "react",
        "react-dom",
        "@types/node",
        "@types/react",
        "@types/react-dom"
      ],
      "packages": [
        "**"
      ],
      "snapTo": [
        "@repo/config-react"
      ]
    }
  ]
}

but is this the correct approach for package dependency version setting to persevere monorepo maintainability?

Upvotes: 1

Views: 52

Answers (1)

Jamie Mason
Jamie Mason

Reputation: 4211

When using the workspace protocol as you are doing, this config will be useful

{
  "versionGroups": [
    {
      "label": "use workspace protocol for local dependencies"
      // for every package in the monorepo
      "packages": ["**"],
      // for dependencies which are created in this monorepo
      "dependencies": ["$LOCAL"],
      // except for the .version property of package.json
      "dependencyTypes": ["!local"],
      // use workspace protocol
      "pinVersion": "workspace:*"
    }
  ]
}

If you want the versions of react, react-dom, @types/node, @types/react, @types/react-dom etc to be kept in sync – you're not required to create a version group for them to be discovered and synchronised, it is done by default.

Version Groups are only needed when you want to define a specific versioning strategy for just a subset of your packages, like we did above for local dependencies and the workspace protocol.

See also https://jamiemason.github.io/syncpack/guide/getting-started/

Upvotes: 0

Related Questions