Skip to content

feat(options): Add an option for overriding the file system module in the JS API #5944

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

Merged
merged 12 commits into from
Jun 11, 2025

Conversation

EggDice
Copy link
Contributor

@EggDice EggDice commented May 2, 2025

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

The problem is described in the issue #5880
The solution creates an internal RollupFsModule type to describe the file system option. It passes the option to the plugins as part of the context.

Copy link

vercel bot commented May 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 4:30am

Copy link

codecov bot commented May 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.78%. Comparing base (f763394) to head (fb55136).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5944   +/-   ##
=======================================
  Coverage   98.78%   98.78%           
=======================================
  Files         270      270           
  Lines        8733     8735    +2     
  Branches     1509     1510    +1     
=======================================
+ Hits         8627     8629    +2     
  Misses         73       73           
  Partials       33       33           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I added some comments to the types to simplify and align them a little more.

@EggDice
Copy link
Contributor Author

EggDice commented May 29, 2025

@lukastaegert I have fixed your suggestions

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty to have another look through the interface and did some more changes, please have a look.

  • Looking at the flag and mode values, maybe it makes sense to keep them at string|number. An ad-hoc implementation would most likely ignore those values anyway without causing harm.
  • I changed the type of file paths to be only string in a few more places. As it turns out, that also means we can get rid of the encoding option for mkdtemp, readdir and realpath as that was only about the encoding of file paths
  • The type of binary file data should not be ArrayBuffer, that is an underlying utility type that is not well usable. It should be Uint8Array, which is a typed array interface that exists in the browser but which is also implemented by the NodeJS Buffer.
  • It might be really useful to support withFileTypes: true in readdir, and there was not much additional interface needed to support this if you limit to non-device directory entries.
  • Maybe it is fine to only support object options and not e.g. the short-hand buffer encoding for e.g. readFile. I assume this was mostly a historical artifact in the NodeJs interfaces from a time when there only was one option.

Have another look if this looks fine from your side.

@EggDice
Copy link
Contributor Author

EggDice commented Jun 7, 2025

Amazing! Thank you! <3

This should mostly work, the edge case that previously prompted it to be
replaced is now handled gracefully.
This will allow to make it much easier to use the browser build.
Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had another look through it from the perspective how this might benefit the browser build. One thing I found is that now, browser/src/fs.ts is basically the default for the browser build, so I extended this file so that it covers all functions in the API and extended types to ensure this file is updated as needed.
Second, I noticed we no longer need the special resolveId logic for the browser. That has the effect that now, you can make the browser build run entirely via supplying an in-memory file system without any further need for plugins. This is really nice, and I used the chance to extend the documentation to explain this approach.
I also added docs for the plugin option, together with the recommendation to use it to make plugins NodeJS-independent.

@EggDice
Copy link
Contributor Author

EggDice commented Jun 10, 2025

Wow, amazing news, thank you! 🎉

@lukastaegert lukastaegert enabled auto-merge June 11, 2025 04:30
@lukastaegert lukastaegert added this pull request to the merge queue Jun 11, 2025
Merged via the queue into rollup:master with commit eeca11a Jun 11, 2025
39 of 40 checks passed
Copy link

This PR has been released as part of rollup@4.43.0. You can test it via npm install rollup.

@aaacccount
Copy link

72858cb

github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Jul 29, 2025
Adds `this.fs` support which was added to rollup in
rollup/rollup#5944.

Note that while rollup/rollup#5944 adds
`options.fs`, this PR does not add that feature.
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.

Add an option for overriding the file system module in the JS API
3 participants