Skip to content

[Feature] Aliases workspace:^ and workspace:~ #2658

Closed

Description

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

I would like that versions of workspace package dependencies to refer to the latest available version, and at the same time make them compatible with future security patches or minor improvements.

Right now there is workspace:* which updates the version of a workspace dependency automatically on release. This is good because the package.json#dependencies always point to versions known to work with the package and tested (if tests are run before release).

But it's excessively specific. workspace: * is substituted with an exact version like "dep": "1.0.0", which is incompatible with future security patches or minor improvements of the dependency.

Describe the solution you'd like

I would like to specify "dep": "workspace:~" and to be substituted on release with the current version of "dep" but allowing security patches, e.g. "dep": "workspace:~1.0.0". Also I think it would be useful to specify "dep": "workspace:^" and get "dep": "workspace:^1.0.0".

Describe the drawbacks of your solution

More complexity and there is a risk of creating technical debt

Describe alternatives you've considered

Specifying full workspace versions workspace:~0.9.0 and running a script before release to bump the version number, but it's kind of ugly.

Related
pnpm/pnpm#3116

Activity

  1. arcanis commented on Mar 30, 2021

    @arcanis
    Member

    Yep, I'd be open to have support for workspace:~ and workspace:^ 👍

  2. certainlynotprithvi commented on Apr 22, 2021

    @certainlynotprithvi

    Hi @arcanis @javier-garcia-meteologica I would like a try at this issue

    So just to write out my understanding

    If the workspace has dependencies a:1.0.0, b:2.0.0 c:3.0.0 with a,b,c being npm packages, the following declarations should be the result of this enhancement

    a: workspace:* => a: 1.0.0
    b: workspace:^ => b: ^2.0.0
    c: workspace:~ => c: ~3.0.0

  3. javier-garcia-meteologica commented on Apr 22, 2021

    @javier-garcia-meteologica
    Author

    @certainlynotprithvi that is right, those substitutions have to be made when the project is packed.

    For internal dependency resolution, the behavior of workspace:^ and workspace:~ is the same as workspace:*. That is, they point to a project in the workspace that matches the name of the package.

  4. arcanis commented on Apr 22, 2021

    @arcanis
    Member

    Indeed 👍

    For the pack translation logic, the relevant source code is here:

    for (const dependencyType of DEPENDENCY_TYPES) {
    for (const descriptor of workspace.manifest.getForScope(dependencyType).values()) {
    const matchingWorkspace = project.tryWorkspaceByDescriptor(descriptor);
    const range = structUtils.parseRange(descriptor.range);
    if (range.protocol !== WORKSPACE_PROTOCOL)
    continue;
    if (matchingWorkspace === null) {
    if (project.tryWorkspaceByIdent(descriptor) === null) {
    throw new ReportError(MessageName.WORKSPACE_NOT_FOUND, `${structUtils.prettyDescriptor(project.configuration, descriptor)}: No local workspace found for this range`);
    }
    } else {
    let versionToWrite: string;
    // For workspace:path/to/workspace and workspace:* we look up the workspace version
    if (structUtils.areDescriptorsEqual(descriptor, matchingWorkspace.anchoredDescriptor) || range.selector === `*`)
    versionToWrite = matchingWorkspace.manifest.version ?? `0.0.0`;
    else
    // for workspace:version we simply strip the protocol
    versionToWrite = range.selector;
    rawManifest[dependencyType][structUtils.stringifyIdent(descriptor)] = versionToWrite;
    }
    }
    }

    For the workspace selection, the relevant line is here:

    if (protocol === WorkspaceResolver.protocol && pathname === `*`)

    Note that we'll also need tests, which would be implemented here:
    https://github.com/yarnpkg/berry/blob/a546d725d9f3f9b9881a9d973b48c241935d1910/packages/acceptance-tests/pkg-tests-specs/sources/protocols/workspace.test.ts

  5. added a commit that references this issue on Aug 8, 2021
    4908ce4
  6. added a commit that references this issue on Aug 12, 2021
    df469b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions