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

feat(semver): support ranges for workspace dependencies #124

Closed
ecraig12345 opened this issue Mar 14, 2023 · 8 comments
Closed

feat(semver): support ranges for workspace dependencies #124

ecraig12345 opened this issue Mar 14, 2023 · 8 comments

Comments

@ecraig12345
Copy link

Description

Unless I'm missing something, syncpack only seems to support exact versions for workspace dependencies.

Sometimes it would be helpful to have the option of allowing a range, but verifying that the range matches the current version. Some example scenarios:

  • Specify dev deps on the repo's internal tooling package(s) as *
  • Specify deps on repo packages as ^x.y.z (this can reduce duplication for consumers if they depend on multiple packages from the repo)

The behavior with this setting enabled would be that given a workspace package with version 1.2.3:

  • Correct: consistently use ^1.0.0, ~1.2.0, *, etc
  • Incorrect: ^0.9.0, ^1.3.0, ~1.1.0, etc (or inconsistent semver spec)

Suggested Solution

I'm not sure exactly where this should fit into the config. The most obvious thing I could think of (which I tried before filing this) is putting it in semverGroups like this:

    "semverGroups": [
      {
        "range": "^",
        "dependencyTypes": ["workspace"],
        "packages": ["**"],
        "dependencies": ["**"]
      }
    ]

Help Needed

I might be able to implement this if you point to the right place.

@JamieMason
Copy link
Owner

JamieMason commented Mar 14, 2023

On an initial glance it may be enough just to remove this line

import { isSemver } from '../../lib/is-semver';

It was an assumption I had that the version would/should always exactly match given the origin of that package is there in the same monorepo.

@ecraig12345
Copy link
Author

Did you mean this line?

if (instance.isWorkspace()) return setSemverRange('', version);

I made that change locally and ran it against this repo/branch (with some further updates to the config), and still got errors.

This is the config I used. It also gave the exact same results without the semverGroups.

  "syncpack": {
    "dependencyTypes": [
      "dev",
      "prod",
      "peer",
      "workspace"
    ],
    "semverGroups": [
      {
        "range": "^",
        "dependencyTypes": ["workspace"],
        "packages": ["**"],
        "dependencies": ["**"]
      }
    ]
  }

Sample of the errors:

✘ @lage-run/cache 0.4.3 is developed in this repo at packages/cache/package.json
  ^0.4.3 in dependencies of packages/cli/package.json
  ^0.4.3 in dependencies of packages/scheduler/package.json
✘ @lage-run/cli 0.10.1 is developed in this repo at packages/cli/package.json
  ^0.10.1 in dependencies of packages/e2e-tests/package.json
  ^0.10.1 in devDependencies of packages/lage/package.json

@JamieMason
Copy link
Owner

No problem I'll take a look

@JamieMason
Copy link
Owner

I've done some work on this, I'm on holiday next week but the next release will include it.

I've been thinking that workspace: should be treated as a new kind of semver range but I need to check that over – I noticed recently in fluid framework (I test against that repo locally) that you have workspace:~ which I hadn't seen before, so the ~ portion of that would need some special handing adding.

- export type SemverRange = '' | '*' | '>' | '>=' | '.x' | '<' | '<=' | '^' | '~';
+ export type SemverRange = '' | '*' | '>' | '>=' | '.x' | '<' | '<=' | '^' | '~' | 'workspace:';

@ecraig12345
Copy link
Author

Thanks! I guess I should have clarified that by "workspace dependencies" I assumed it meant just "packages defined within the same workspace." I haven't personally used the workspace: syntax.

@jonathanj
Copy link

I've been thinking that workspace: should be treated as a new kind of semver range but I need to check that over – I noticed recently in fluid framework (I test against that repo locally) that you have workspace:~ which I hadn't seen before, so the ~ portion of that would need some special handing adding.

- export type SemverRange = '' | '*' | '>' | '>=' | '.x' | '<' | '<=' | '^' | '~';
+ export type SemverRange = '' | '*' | '>' | '>=' | '.x' | '<' | '<=' | '^' | '~' | 'workspace:';

I generally use workspace:* within my workspace packages, although the Yarn docs on the topic say that the other ranges work too (but recommend the use of workspace:*).

My syncpack config ended up ignoring myorg/** packages and dependencies because I couldn't get syncpack to recognise and treat them as workspace local dependencies.

@JamieMason
Copy link
Owner

Thanks! I guess I should have clarified that by "workspace dependencies" I assumed it meant just "packages defined within the same workspace." I haven't personally used the workspace: syntax.
@ecraig12345

My bad, I keep confusing the various things "workspace" can refer to. Ok, I think I have a fix for this locally but it's not everything you're looking for. It will allow ranges to be used when you depend on a package which is developed locally, but those range versions will need to be identical to each other as per current syncpack behaviour. At a later date though hopefully #128 can deliver some support for ranges being satisfied.

I generally use workspace:* within my workspace packages, although the Yarn docs on the topic say that the other ranges work too (but recommend the use of workspace:*).
@jonathanj

I'm tempted to limit support to only workspace:* now you mention it, at least in the first drop.

My syncpack config ended up ignoring myorg/** packages and dependencies because I couldn't get syncpack to recognise and treat them as workspace local dependencies.
@jonathanj

Can you create an issue for this scenario so it can be looked into?

Thanks both

@JamieMason JamieMason changed the title Support ranges for workspace dependencies feat(versions): support ranges for workspace dependencies May 28, 2023
@JamieMason JamieMason changed the title feat(versions): support ranges for workspace dependencies feat(semver): support ranges for workspace dependencies May 28, 2023
JamieMason added a commit that referenced this issue May 28, 2023
Closes #124

When using the `workspace` dependency type, packages installing that dependency
no longer have to exactly match the `version` property of the package.json of
origin.

If the version or version range used by every dependent package matches, it is
considered valid.

Closes #130

JavaScript config files now have support for TypeScript IntelliSense.

https://jamiemason.github.io/syncpack/config-file#typescript-intellisense

Closes #114
Refs #109
Refs #125

Unsupported versions can now at least be managed via `pinVersion`, where
previously anything which was not valid semver would be ignored.

Refs #111
Refs #132

TypeScript IntelliSense support helps catch invalid config, but more work is
needed to display useful error messages at runtime.

Refs #48
Refs #3

Syncpack's internals are now better organised, so providing a Node.js API and
general lint and fix CLI commands are now closer to being released.

BREAKING CHANGES:

Although they are still not auto-fixable, unsupported versions which were
previously ignored are now acknowledged, which may introduce mismatches which
previously would have been considered valid.

This release was also a huge rewrite of Syncpack's internals and, while there
is a large amount of tests, some scenarios may have been missed.

If you run into any problems, please create an issue.
JamieMason added a commit that referenced this issue May 28, 2023
Closes #124

When using the `workspace` dependency type, packages installing that dependency no longer have to exactly match the `version` property of the package.json of origin.

If the version or version range used by every dependent package matches, it is considered valid.

Closes #130
Closes #131

JavaScript config files now have support for TypeScript IntelliSense.

https://jamiemason.github.io/syncpack/config-file#typescript-intellisense

Closes #114
Refs #109
Refs #125

Unsupported versions can now at least be managed via `pinVersion`, where previously anything which was not valid semver would be ignored.

Refs #111
Refs #132

TypeScript IntelliSense support helps catch invalid config, but more work is needed to display useful error messages at runtime.

Refs #48
Refs #3

Syncpack's internals are now better organised, so providing a Node.js API and general lint and fix CLI commands are now closer to being released.

BREAKING CHANGES:

- `fix-mismatches` will now exit with a status code of 1 if there are mismatches among unsupported versions which syncpack cannot auto-fix.
- Although they are still not auto-fixable, unsupported versions which were previously ignored are now acknowledged, which may introduce mismatches which previously would have been considered valid.
- This release was also a huge rewrite of Syncpack's internals and, while there is a large amount of tests, some scenarios may have been missed.
- If you run into any problems, please create an issue.
JamieMason added a commit that referenced this issue May 28, 2023
### #124

When using the `workspace` dependency type, packages installing that dependency no longer have to exactly match the `version` property of the package.json of origin.

Closes #124

If the version or version range used by every dependent package matches, it is considered valid.

### #130, #131

JavaScript config files now have support for TypeScript IntelliSense.

Closes #130
Closes #131

https://jamiemason.github.io/syncpack/config-file#typescript-intellisense

### #109, #114, #125

Unsupported versions can now at least be managed via `pinVersion`, where previously anything which was not valid semver would be ignored.

Closes #114

### #111, #132

TypeScript IntelliSense support helps catch invalid config, but more work is needed to display useful error messages at runtime.

### #48, #3

Syncpack's internals are now better organised, so providing a Node.js API and general lint and fix CLI commands are now closer to being released.

BREAKING CHANGE:

- `fix-mismatches` will now exit with a status code of 1 if there are mismatches among unsupported versions which syncpack cannot auto-fix.
- Although they are still not auto-fixable, unsupported versions which were previously ignored are now acknowledged, which may introduce mismatches which previously would have been considered valid.
- This release was also a huge rewrite of Syncpack's internals and, while there is a large amount of tests, some scenarios may have been missed.
- If you run into any problems, please create an issue.
@JamieMason
Copy link
Owner

Released in [email protected], please let me know if you run into any issues.

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

3 participants