yarnpkg / yarnpkg/berry

[Bug?]: constraints + `workspaces focus` cause erroneous failures

Open
#5,992 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Self-service
  • I'd be willing to implement a fix
Describe the bug

If I have a constraint on e.g. the presence of a script, workspaces focus will cause that constraint to fail because as part of its implementation it mangles the package manifests:

https://github.com/yarnpkg/berry/blob/db6210f48355d2986e965f90009b22f18d3b6342/packages/plugin-workspace-tools/sources/commands/focus.ts#L83-L96C6

To reproduce

(The link to Sherlock is broken, and when I dug up an old version it appears to also be broken.)

I put a reproduction up at https://github.com/seansfkelley/yarn-repro

The important parts are:

[root package.json]
{
  "name": "yarn-repro",
  "workspaces": {
    "packages": [
      "packages/*"
    ]
  },
  "packageManager": "yarn@4.0.2"
}

[yarn.config.cjs]
module.exports = {
  constraints({ Yarn }) {
    for (const w of Yarn.workspaces({ ident: "a" })) {
      w.set("scripts.start", "exit 0");
    }
  },
};

[packages/a/package.json]
{
  "name": "a",
  "scripts": {
    "start": "exit 0"
  }
}

[packages/b/package.json]
{
  "name": "b"
}

[.yarnrc.yml]
enableConstraintsChecks: true

Then reproduce the issue with yarn workspaces focus b.

Environment
System:
    OS: macOS 13.6
    CPU: (12) arm64 Apple M2 Pro
  Binaries:
    Node: 20.9.0 - /private/var/folders/wg/zn78dyk51h5bvz0crq8x8w0h0000gp/T/xfs-3399e843/node
    Yarn: 4.0.2 - /private/var/folders/wg/zn78dyk51h5bvz0crq8x8w0h0000gp/T/xfs-3399e843/yarn
    npm: 10.1.0 - ~/.volta/tools/image/node/20.9.0/bin/npm
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/plugin-workspace-tools/sources/commands/focus.ts at the linked lines, then reproduce the failure with the provided repository using yarn workspaces focus b. Trace how focus alters manifests while constraints checks are enabled; done means the reproduced constraint no longer fails erroneously.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.