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

[Bug?]: prefersUnplugged should take precedence over pkg.conditions #4749

Closed
1 task done
jonaskuske opened this issue Aug 15, 2022 · 3 comments · May be fixed by #4822
Closed
1 task done

[Bug?]: prefersUnplugged should take precedence over pkg.conditions #4749

jonaskuske opened this issue Aug 15, 2022 · 3 comments · May be fixed by #4822
Labels
bug Something isn't working upholded Real issues without formal reproduction

Comments

@jonaskuske
Copy link
Contributor

Self-service

  • I'd be willing to implement a fix

Describe the bug

In this comment, esbuild was recommended to add prefersUnplugged: false to its optional platform-specific deps so they don't get extracted: #3317 (comment). And indeed, all esbuild variants include the preferUnplugged key: https://unpkg.com/browse/esbuild-linux-arm@0.15.3/package.json

Unfortunately the prefersUnplugged key is ignored and all of the optional deps are extracted anyway, because the pkg.conditions !== null check takes precedence over preferUnplugged:

if (pkg.conditions != null)
return true;
if (customPackageData.manifest.preferUnplugged !== null)
return customPackageData.manifest.preferUnplugged;

These checks should be in reverse order. By reversing the two checks, everything works: esbuild is unplugged but its optional dependencies are not. When running esbuild, it copies the correct platform-specific binary into its writable, unplugged dir and executes it.

And if you change the location where esbuild stores the platform-specific binary (as I proposed in this PR: evanw/esbuild#2457), it even works with enableScripts: false and nothing unplugged.

To reproduce

mkdir repro && cd $_
yarn init -2 -y
yarn add esbuild
# should be empty but prints opt dep:
ls .yarn/unplugged | grep -P 'esbuild-(?!(npm))'

Environment

System:
    OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Binaries:
    Node: 16.14.2 - /tmp/xfs-96532741/node
    Yarn: 3.2.2 - /tmp/xfs-96532741/yarn
    npm: 8.5.0 - /mnt/wslg/runtime-dir/fnm_multishells/15691_1660563665547/bin/npm

Additional context

No response

@jonaskuske jonaskuske added the bug Something isn't working label Aug 15, 2022
jonaskuske added a commit to jonaskuske/berry that referenced this issue Sep 6, 2022
@yarnbot

This comment was marked as outdated.

@yarnbot yarnbot added the stale Issues that didn't get attention label Sep 14, 2022
@merceyz merceyz added upholded Real issues without formal reproduction and removed stale Issues that didn't get attention labels Sep 14, 2022
@evanw
Copy link

evanw commented Dec 3, 2022

FYI esbuild now uses prefersUnplugged: true as of version 0.15.15. Your documentation recommends extracting to node_modules/.cache but your users don't like that as it causes the node_modules directory to be created when it otherwise isn't needed. So to avoid needing to create node_modules/.cache, all of esbuild's platform-specific packages now request to be unplugged.

@jonaskuske
Copy link
Contributor Author

Yep, followed those developments! Creating node_modules just for .cache, .vite etc is annoying indeed, should've probably been somewhere in .yarn/tmp or so, not to annoy users. Anyway, guess I'll have to live with unplugged esbuild packages :)
Checking in .yarn/unplugged is annoying, but guess the whole 0-installs idea is dying anyway with native deps like esbuild or swc becoming more and more common. Yarn 4 stopped defaulting to 0-installs too I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upholded Real issues without formal reproduction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants