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

[Feature Request] Support for Yarn 2 "workspace ranges" #598

Open
heejongahn opened this issue May 28, 2021 · 2 comments · May be fixed by #674
Open

[Feature Request] Support for Yarn 2 "workspace ranges" #598

heejongahn opened this issue May 28, 2021 · 2 comments · May be fixed by #674

Comments

@heejongahn
Copy link

heejongahn commented May 28, 2021

Affected Packages

@changesets/cli

Problem

First off, thanks for the great tool!

Yarn 2 introduces a feature called workspace ranges.

With workspace ranges, you can specify the intent of "depend on the current version of local workspace package, whatever the actual published version it may be". If you think about the workflow you're simutaneously modifying multiple packages, this can be extremely useful.

The transformation of workspace:... version to actual versions that npm can understand is handled by yarn at publish time.

When a workspace is packed into an archive (whether it's through yarn pack or one of the publish commands like yarn npm publish), we dynamically replace any workspace: dependency by:

  • The corresponding version in the target workspace (if you use * or a project-relative path)
  • The associated semver range (for any other range type)

However, as current changeset publish command only supports either npm or pnpm as publish client, this transformation cannot take place, and changeset publish aborts with:

🦋  error TypeError: Invalid comparator: packages/my-package
🦋  error     at Comparator.parse (/home/runner/work/npm-packages/npm-packages/.yarn/cache/semver-npm-5.7.1-40bcea106b-06ff0ed753.zip/node_modules/semver/semver.js:754:11)
🦋  error     at new Comparator (/home/runner/work/npm-packages/npm-packages/.yarn/cache/semver-npm-5.7.1-40bcea106b-06ff0ed753.zip/node_modules/semver/semver.js:737:8)
🦋  error     at Range.<anonymous> (/home/runner/work/npm-packages/npm-packages/.yarn/cache/semver-npm-5.7.1-40bcea106b-06ff0ed753.zip/node_modules/semver/semver.js:925:12)
🦋  error     at Array.map (<anonymous>)
🦋  error     at Range.parseRange (/home/runner/work/npm-packages/npm-packages/.yarn/cache/semver-npm-5.7.1-40bcea106b-06ff0ed753.zip/node_modules/semver/semver.js:924:13)
🦋  error     at Range.<anonymous> (/home/runner/work/npm-packages/npm-packages/.yarn/cache/semver-npm-5.7.1-40bcea106b-06ff0ed753.zip/node_modules/semver/semver.js:867:17)
🦋  error     at Array.map (<anonymous>)
🦋  error     at new Range (/home/runner/work/npm-packages/npm-packages/.yarn/cache/semver-npm-5.7.1-40bcea106b-06ff0ed753.zip/node_modules/semver/semver.js:866:40)
🦋  error     at versionPackage (/home/runner/work/npm-packages/npm-packages/.yarn/cache/@changesets-apply-release-plan-npm-5.0.0-19ff54c5d1-d43561e831.zip/node_modules/@changesets/apply-release-plan/dist/apply-release-plan.cjs.dev.js:160:9)
🦋  error     at /home/runner/work/npm-packages/npm-packages/.yarn/cache/@changesets-apply-release-plan-npm-5.0.0-19ff54c5d1-d43561e831.zip/node_modules/@changesets/apply-release-plan/dist/apply-release-plan.cjs.dev.js:312:12

Proposed solution

If either

It would be awesome!

@Andarist
Copy link
Member

I've created a pull request that attempts to fix the issues mentioned here. I will setup snapshot releases for this PR soon-ish but in the meantime I would love to ask if there are any people willing to test this stuff out in their projects.

@notaphplover
Copy link

For those using pnpm: since this issue is not likely to be solved soon, consider using wildcard aliases instead of relative path aliases as workaround:

package.json

{
  "dependencies": {
    "foo": "workspace:*"
  }
}

instead of

package.json

{
  "dependencies": {
    "foo": "workspace:./path/to/the/package"
  }
}

This references are the ones currently used in the pnpm monorepo, which is also using changeset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants