Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question(config): how to depend on a local package with a semver range? #242

Closed
Zamiell opened this issue Sep 5, 2024 · 3 comments
Closed

Comments

@Zamiell
Copy link

Zamiell commented Sep 5, 2024

Consider a monorepo like this:

monorepo/
└── packages/
    ├── foo
    |   └── package.json
    └── bar
        └── package.json

If bar depends on foo, and foo is at "1.0.1", and bar specifics foo as "^1.0.1", syncpack will throw a spurious error:

✘ foo ^1.0.1 → 1.0.1 packages\foo\package.json > dependencies [LocalPackageMismatch]

The documentation says this:

As a sensible default, syncpack defines a monorepo-wide exact version policy as a starting point which can be tuned from there. If your project uses exact versions everywhere, and you always want them to be identical, you will not need to define any configuration.

However, in this case, I expect "^1.0.1" to be identical to "1.0.1". In other words, Synpack should respect the carot (or tilde).

@Zamiell Zamiell changed the title Monorepo packages that depend on other monorepo packages are not checked Monorepo packages that depend on other monorepo packages are not compatible with the carot operator Sep 6, 2024
@JamieMason
Copy link
Owner

Could you create a reproduction please? Thanks

@Zamiell
Copy link
Author

Zamiell commented Sep 7, 2024

See: https://github.com/Zamiell/syncpack-bug

@JamieMason
Copy link
Owner

Hey @Zamiell, I just got a chance to take a look.

This looks correct as far as I can tell, we can learn a bit more about why if we take a closer look at the quote from the documentation:

As a sensible default, syncpack defines a monorepo-wide exact version policy as a starting point

What this is saying is that by default they must be identical.

"^1.0.1" === "1.0.1"
// false

which can be tuned from there.

☝ and that it's possible to change this

If your project uses exact versions everywhere, and you always want them to be identical, you will not need to define any configuration.

Your project doesn't use exact versions everywhere, and you don't always want them to be identical, so you will need to define some configuration.

Tune this of course to your real project, but what we are saying in this repo is that we want prod dependencies to use a caret:

{
  "semverGroups": [
    {
      "dependencies": ["foo"],
      "range": "^"
    }
  ]
}

syncpack will now classify this as SatisfiesLocal instead of DiffersToLocal.

There is a stack of work to do but I really would like to write some guides etc on these kinds of things. Hopefully this helps a little at least.

@JamieMason JamieMason changed the title Monorepo packages that depend on other monorepo packages are not compatible with the carot operator question(config): how to depend on a local package with a semver range? Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants