JamieMason / syncpack

Consistent dependency versions in large JavaScript Monorepos.
https://jamiemason.github.io/syncpack/
MIT License
1.34k stars 44 forks source link

Question: how to have a dependency in both peer and dev? #225

Open crfrolik opened 1 month ago

crfrolik commented 1 month ago

My config:

{
  "semverGroups": [
    {
      "label": "dev dependencies are ~ prefixed",
      "range": "~",
      "dependencyTypes": ["dev"],
      "dependencies": ["**"],
      "packages": ["**"]
    },
    {
      "label": "prod and peer dependencies are ^ prefixed",
      "range": "^",
      "dependencyTypes": ["prod", "peer"],
      "dependencies": ["**"],
      "packages": ["**"]
    }
  ]
}

This works fine except I want to have a dependency foo that's in both devDependencies and peerDependencies:

{
  "devDependencies": {
    "foo": "~1.0.0"
  },
  "peerDependencies": {
    "foo": "^1.0.0"
  }
}

syncpack lint gives an error for this.

= Default Version Group ========================================================
✘ foo ~1.0.0 → ^1.0.0 package.json > devDependencies [HighestSemverMismatch]

How can I configure this so lint won't complain?

JamieMason commented 4 weeks ago

Hi @crfrolik, this is because they are in the same Version Group.

Syncpack needs teaching about the rules of your project if you do not have a monorepo-wide single version policy. The Start Small section of the Getting Started guide I think is relevant here.

If you move one of them into a separate group then they will no longer be compared. There are lots of ways you might choose to organise your project, and the best way will be up to you, but the simplest example that would fix this specific case might be to mirror how you are slicing the project by semver range rules:

{
  "semverGroups": [
    {
      "label": "dev dependencies are ~ prefixed",
      "range": "~",
      "dependencyTypes": ["dev"],
      "dependencies": ["**"],
      "packages": ["**"]
    },
    {
      "label": "prod and peer dependencies are ^ prefixed",
      "range": "^",
      "dependencyTypes": ["prod", "peer"],
      "dependencies": ["**"],
      "packages": ["**"]
    }
  ],
  "versionGroups": [
    {
      "label": "dev dependencies should use the same version",
      "range": "~",
      "dependencyTypes": ["dev"]
    },
    {
      "label": "prod and peer dependencies should use the same version",
      "dependencyTypes": ["prod", "peer"]
    }
  ]
}

Hope this helps, shout if you need any more help.