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

Workspace Protocol with "workspace:^" in Peer Dependencies doesn't work #590

Closed
ghiscoding opened this issue Apr 27, 2023 Discussed in #587 · 0 comments
Closed

Workspace Protocol with "workspace:^" in Peer Dependencies doesn't work #590

ghiscoding opened this issue Apr 27, 2023 Discussed in #587 · 0 comments
Labels
bug Something isn't working has PR

Comments

@ghiscoding
Copy link
Member

Discussed in #587

Originally posted by ma-multipla April 25, 2023
I'm having trouble comprehending the purpose of a specific code fragment. In the context of utilizing the workspace protocol for peer dependencies (e.g. "workspace:^"). Yarn Berry's default behavior is to substitute them with the locally resolved version upon generating the tarball through yarn pack. However, with the current Lerna version, the workspace protocol remains unaltered when applied to peer dependencies, resulting in incompatibility with package managers that don't support the protocol, such as npm.

Using the --allow-peer-dependencies-update flag only bumps the version in specific cases and in my case it only removed the "workspace:" portion, leaving the "^". I've read the documentation about the flag, but I have difficulties seeing the benefits of the current approach.
My questions is as follows:

Why isn't the --allow-peer-dependencies-update flag enabled by default for the workspace protocol and why is it only bumping the workspace protocol when the version is specified like this "workspace:^1.2.0". This essentially makes it not possible to only use the npm range operator without specifying the version, e.g. "workspace:^". Why would you want this?
The documentation is also a bit misleading:

{
  "name": "B",
  "dependencies": {
    "A": "workspace:^1.2.0"   // will update to "workspace:^1.3.0",
    "B": "^0.4.0":            // will update to "^0.5.0"
   },
  "peerDependencies": {
    "A": "workspace:^1.2.0"   // will update to "workspace:^1.3.0"
    "B": ">=0.2.0":           // will not be updateed because range with operator (>=) are skipped
  }
}

https://github.com/lerna-lite/lerna-lite/blob/main/packages/version/README.md#with-flag-enabled

It will update to "^1.3.0" not "workspace:^1.3.0". My expectation would be that either "workspace:^" as well as "workspace:^1.2.0" should lead to a version bump to "^1.3.0" considering the example above.

Here's the code snippet in question:

// Perform certain actions when there are peer dependencies
if (this.peerDependencies?.[depName]) {
  // If the user allows peer bump and it's a regular semver version, add it to the array of dependencies to potentially bump
  // However, don't do this when the semver has a range with an operator, e.g., bump ("^2.0.0") but not (">=2.0.0" or "workspace:<2.0.0" or "workspace:*")
  // prettier-ignore
  if (allowPeerDependenciesUpdate && /^(workspace:)?[~^]?[\d\.]+([\-]+[\w\.\-\+]+)*$/i.test(this.peerDependencies[depName] || '')) {
    updatingDependencies.push(this.peerDependencies);
  }
  // When peer bump is disabled, some peerDependencies might not be reviewed and could still have the `workspace:` prefix, so ensure to remove any of these prefixes
  else if (updatedByCommand === 'publish' && this.peerDependencies[depName].startsWith('workspace:')) {
    this.peerDependencies[depName] = this.peerDependencies[depName].replace('workspace:', '');
  }
}

Source: Lerna Lite Core Package.ts

@ghiscoding ghiscoding added bug Something isn't working has PR labels Apr 27, 2023
@ghiscoding ghiscoding changed the title Handling Workspace Protocol in Peer Dependencies with Lerna Workspace Protocol with "workspace:^" in Peer Dependencies doesn't work Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has PR
Projects
None yet
Development

No branches or pull requests

1 participant