Skip to content

fix: add Yarn PnP support via yarn exec#144

Open
SBoudrias wants to merge 1 commit into
oxc-project:mainfrom
SBoudrias:sboudrias/yarn-pnp-178
Open

fix: add Yarn PnP support via yarn exec#144
SBoudrias wants to merge 1 commit into
oxc-project:mainfrom
SBoudrias:sboudrias/yarn-pnp-178

Conversation

@SBoudrias

@SBoudrias SBoudrias commented Mar 18, 2026

Copy link
Copy Markdown

Problem

The plugin fails in projects using Yarn PnP mode because it hardcodes paths like node_modules/{pkg}/bin/{pkg}. Under Yarn PnP, there is no node_modules on disk — packages are zip-loaded from .yarn/cache/.

Solution

Detect Yarn PnP by checking for .pnp.cjs or .pnp.js at the worktree root, and switch the launch strategy:

  • Before: node {worktree}/node_modules/oxlint/bin/oxlint --lsp
  • After (Yarn PnP): yarn exec oxlint --lsp

Changes

  • src/lsp.rs: Added is_yarn_pnp() helper and get_default_command_and_args() trait method
  • src/oxlint.rs: Uses get_default_command_and_args() instead of manually constructing node <path>
  • src/oxfmt.rs: Same

Behaviour

Setup Result
npm / pnpm node_modules present → existing path logic (no regression)
Yarn PnP .pnp.cjs present → yarn exec oxlint --lsp
Yarn nodeLinker: node-modules No .pnp.cjs → existing path logic
No local install Falls back to extension-bundled binary
Custom binary override in settings Still applied after detection

When a project uses Yarn Berry's Plug'n'Play mode (.pnp.cjs/.pnp.js),
switch from `node node_modules/pkg/bin/pkg --lsp` to `yarn exec pkg --lsp`
since node_modules doesn't exist on disk under PnP.
@SBoudrias

Copy link
Copy Markdown
Author

I considered adding a config option to pass in a path, but that was more complicated given the bin path isn't detectable... But I do understand this adds a yarn PnP specific understanding to this project; hopefully it's not something you're fundamentally against. 🫰

@SBoudrias
SBoudrias marked this pull request as ready for review March 18, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant