Skip to content

Conversation

@hardfist
Copy link
Contributor

@hardfist hardfist commented Aug 21, 2024

Summary

This pull request implements the Yarn PnP feature and closes #2236. Special thanks to @arcanis for implementing PnP resolution in rspack_resolver.

Differences from Webpack Implementation

Intercepting FS on the Rust Side

A significant part of Webpack’s implementation is that it leverages PnP runtime to intercept all filesystem calls in Node.js via the .pnp.cjs file, correctly handling Yarn’s zip file paths as regular files. However, intercepting all filesystem calls on the JavaScript side incurs a significant performance cost in Rspack. Therefore, for performance reasons, Rspack intercepts standard filesystem calls in a custom native FS implementation in rust side.

Enabling PnP Only When resolve.enablePnp is Set

For performance optimization, Yarn PnP is enabled by default only when running in a PnP environment (when process.versions.pnp is truthy). This avoids unnecessary overhead for users not utilizing Yarn PnP.

Limitations

After discussions with @arcanis, supporting multiple Yarn PnP resolver instances would complicate the implementation and negatively impact cache efficiency. Since multiple PnP instances are rarely used in most Yarn PnP applications, Rspack supports only a single PnP resolver instance. Consequently, only the root resolve.enablePnp setting is effective, and settings within module.rule have no impact. This approach suffices for most Yarn PnP applications.

Implementation Caveats

Yarn PnP requires filesystem interception for zip file calls, coupled the filesystem implementation with resolve.enablePnP configuration. Introducing a root enablePnP setting might decouple the filesystem and resolver but could also add confusion and complexity to the configuration. Therefore, I have adhered to the current implementation.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Aug 21, 2024
@netlify
Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 3dec441
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/677f55ca91be210008d1ae52

@hardfist hardfist changed the title chore: add test case feat(core): add yarn pnp support Aug 21, 2024
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Aug 21, 2024
@hardfist
Copy link
Contributor Author

!bench

@rspack-bot
Copy link

⏳ Triggered benchmark: Open

@hardfist hardfist requested review from SyMind and h-a-n-a August 21, 2024 07:19
@stale
Copy link

stale bot commented Oct 21, 2024

This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump").

@stale stale bot added the stale label Oct 21, 2024
@arcanis
Copy link
Contributor

arcanis commented Oct 21, 2024

Bump, I still have it in my backlog (I've been in on-and-off paternity leave since August, so my bandwidth has been limited - but I'm still very interested to bring it to the finish line).

@stale stale bot removed the stale label Oct 21, 2024
@hardfist
Copy link
Contributor Author

Bump, I still have it in my backlog (I've been in on-and-off paternity leave since August, so my bandwidth has been limited - but I'm still very interested to bring it to the finish line).

thank you, we'll continue investigating yarn pnp support

@stale
Copy link

stale bot commented Dec 21, 2024

This pull request has been automatically marked as stale because it has not had recent activity. If this pull request is still relevant, please leave any comment (for example, "bump").

@stale stale bot added the stale label Dec 21, 2024
@ZeWaka
Copy link

ZeWaka commented Dec 21, 2024

bump

@hardfist hardfist enabled auto-merge (squash) January 9, 2025 05:31
@hardfist hardfist merged commit 5b73853 into main Jan 9, 2025
30 checks passed
@hardfist hardfist deleted the yj/pnp-support branch January 9, 2025 05:31
@chenjiahan chenjiahan changed the title feat(core): add yarn pnp support feat(core): add Yarn PnP support Jan 9, 2025
@NyanHelsing
Copy link

nice work!!!

Cyberboss pushed a commit to tgstation/tgstation that referenced this pull request Apr 12, 2025
## About The Pull Request
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
## Why It's Good For The Game
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant


https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
## Changelog
vinylspiders pushed a commit to NovaSector/NovaSector that referenced this pull request Apr 15, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
vinylspiders pushed a commit to NovaSector/NovaSector that referenced this pull request Apr 15, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
vinylspiders pushed a commit to NovaSector/NovaSector that referenced this pull request Apr 16, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
vinylspiders pushed a commit to NovaSector/NovaSector that referenced this pull request Apr 16, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
Iajret pushed a commit to Fluffy-Frontier/FluffySTG that referenced this pull request Apr 16, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
lessthnthree pushed a commit to effigy-se/effigy that referenced this pull request Apr 19, 2025
## About The Pull Request
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
## Why It's Good For The Game
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant


https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
## Changelog
Shadow-Quill pushed a commit to Shadow-Quill/Bubberstation that referenced this pull request Apr 30, 2025
## About The Pull Request
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
## Why It's Good For The Game
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant


https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
## Changelog
XeonMations pushed a commit to XeonMations/The-Final-Nights that referenced this pull request May 4, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
Metekillot pushed a commit to Metekillot/TekquiemSS13 that referenced this pull request Jun 11, 2025
## About The Pull Request
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
## Why It's Good For The Game
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant


https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
## Changelog
siliconOpossum pushed a commit to siliconOpossum/MapleStationCode that referenced this pull request Sep 13, 2025
Old project that I have been waiting on for some time. We can swap out
our javascript bundler with a rust version. We still have webpack to
some extent because sass-loader requests it, but it's unused.

This was originally suggested by stylemistake years ago but it depended
on tgui using a modern browser #90397 and rspack supporting yarn pnp
web-infra-dev/rspack#7639.

I want to also replace jest with vitest for this PR since it's deep
internals and no one else is really tinkering here. Drafting for now
Both of these tools are the drop in replacement of the modern decade
Makes the dev server borderline instant

https://rspack.dev/misc/faq#what-are-the-advantages-of-rspack-compared-to-webpack--swc-loader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Yarn PnP workspace

8 participants