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

Yarn 4: Respect enableTransparentWorkspaces: false when resolving workspace dependencies #8989

Open
1 task done
me4502 opened this issue Aug 12, 2024 · 3 comments
Open
1 task done
Labels
area: prune turbo prune kind: bug Something isn't working

Comments

@me4502
Copy link

me4502 commented Aug 12, 2024

Verify canary release

  • I verified that the issue exists in the latest Turborepo canary release.

Link to code that reproduces this issue

https://github.com/me4502/turborepo-reproduction

What package manager are you using / does the bug impact?

Yarn v2/v3/v4 (node_modules linker only)

What operating system are you using?

Mac

Which canary version will you have in your reproduction?

2.0.12-canary.3

Describe the Bug

When a dependency using Yarn's npm: protocol exists that has the same name as a workspace in the repo, turborepo incorrectly builds the repo with that name. This causes issues in cases where FFI-requiring packages are built on CI and used purely via NPM rather than local workspaces.

Expected Behavior

As these dependencies come from npm, and not the workspace of the same name, the workspace should not be built nor considered part of turborepo's dependency graph.

To Reproduce

  1. Clone https://github.com/me4502/turborepo-reproduction
  2. Run yarn in the root of the repo
  3. cd to workspaces/a
  4. Run yarn build:turbo

As can be seen in the output, the buffer workspace's build script has been incorrectly run, despite it not being a dependency of the a workspace.

Additional context

The important parts of this setup are that there's a package called buffer being used by workspace a, and a workspace also named buffer. The repro is setup to specifically use the dependency from npm, so it should not be building the workspace copy as it's redundant (and in the case of FFI dependencies, potentially impossible from local development machines).

@me4502 me4502 added kind: bug Something isn't working needs: triage New issues get this label. Remove it after triage labels Aug 12, 2024
@chris-olszewski chris-olszewski changed the title Turborepo incorrectly builds workspace when yarn npm: protocol dependency of the same name is present Yarn 4: Respect enableTransparentWorkspaces: false when resolving workspace dependencies Aug 12, 2024
@chris-olszewski chris-olszewski removed the needs: triage New issues get this label. Remove it after triage label Aug 12, 2024
@chris-olszewski
Copy link
Member

Thanks for the report. Just documenting for myself that we're doing the correct behavior for default Yarn 4 settings, but if enableTransparentWorkspaces: false is set, we need to change our dependency resolution behavior to respect that.

@chris-olszewski chris-olszewski added the area: prune turbo prune label Aug 26, 2024
@romanofski
Copy link
Contributor

I had a look at this out of curiosity. If I'm not mistaken the fix is likely addressing the TODO in crates/turborepo-repository/src/package_graph/dep_splitter.rs?:

    fn is_external(&self) -> bool {
        // The npm protocol for yarn by default still uses the workspace package if the
        // workspace version is in a compatible semver range. See https://github.com/yarnpkg/berry/discussions/4015
        // For now, we will just assume if the npm protocol is being used and the
        // version matches its an internal dependency which matches the existing
        // behavior before this additional logic was added.

        // TODO: extend this to support the `enableTransparentWorkspaces` yarn option
        self.protocol.map_or(false, |p| p != "npm")
    }

@romanofski
Copy link
Contributor

@chris-olszewski I've hacked on this in a branch here romanofski@8b7166d If I did find the right locations to change, I wonder whether the config file representation for the package managers is not already a bottle neck.

Currently the npmrc and yarnrc configs are exposed as simple booleans, but perhaps should actually be represented more abstractly? Like instead of passing in the *rc instances in the DependencySplitter it might make sense to have an abstracted object exposing options for the dependency resolution. That can then be created with either the nprmc or yarnrc or whatever it is?

Anyway, guess if there is 5 mins to have a quick look at the branch/patch I'd appreciate some pointers in the right direction. I'll continue having a look at the integration tests since that's needed too.

chris-olszewski added a commit that referenced this issue Dec 19, 2024
…erry (#9626)

### Description

This implements a fix for #8989 to honour `enableTransparentWorkspaces`
in a yarn config.

The patch folds the config setting into the existing
`link_workspace_packages` npm settings as they're equivalent.

Massive Kudos to @me4502 as she helped throughout the implementation
process with testing and figuring things out.

### Testing Instructions

* Use https://github.com/me4502/turborepo-reproduction reproducer
* Run compiled turbo build against workspace `a`:
`turborepo/target/debug/turbo build --force --skip-infer --no-daemon
--filter a`

---------

Co-authored-by: Chris Olszewski <chris.olszewski@vercel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: prune turbo prune kind: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants