Repository navigation
feat: add MemoryFileSystem module - #6573
lloydrichards wants to merge 48 commits into
Conversation
🦋 Changeset detectedLatest commit: c911454 The changes in this PR will be included in the next version bump. This PR includes changesets to release 35 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds an isolated in-memory ChangesMemoryFileSystem
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant FileSystem
participant Volume
participant WatchStream
FileSystem->>Volume: mutate filesystem state
Volume->>Volume: commit normalized transition
Volume->>WatchStream: publish filesystem event
WatchStream-->>FileSystem: emit watched path event
Suggested labels: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/effect/src/internal/memoryFileSystem.ts`:
- Around line 769-810: Update the recursive makeDirectory creation flow to
accumulate every newly created path instead of overwriting createdPath on each
iteration. Emit a Create event for each created directory in creation order,
including intermediate paths such as /a and /a/b, while preserving the existing
empty-event behavior when no directory is created.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 054f14df-a2f1-4ce3-8637-2eefbe37f869
📒 Files selected for processing (4)
.changeset/puny-queens-spend.mdpackages/effect/src/MemoryFileSystem.tspackages/effect/src/internal/memoryFileSystem.tspackages/effect/test/MemoryFileSystem.test.ts
a52dfd4 to
cda9755
Compare
cda9755 to
f295caf
Compare
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
f295caf to
5e0c97e
Compare
|
Used the changes to the test suite (#6555) to align the behavior of File.seek and the missig watch target with Node and Deno impl |
|
Not necessarily useful for the review, but could be interesting in context: I've written an article on the process I used to build out this PR |
|
@lloydrichards I borrowed the code from this PR, built it out as a temporary package in my effect utilities monorepo. I have started using it in tests in a couple projects: tsdoctor, vitest-agent and savvy-web. These are just my initial attempts at using it to clean up my tests. There are some quirks with integrating with actual file IO, mainly I often use async file handling and there are some visibility problems but, overall, it let me stop writing a bunch of verbose and brittle fixtures for parts of my programs and sped up test runs a lot. I tailored the implementation to my specific needs, but having a base construct for this in the core would be helpful, imo. Thanks for building this out. |
Glad to hear its been useful 😄 If you have any feedback or suggestions, especially around the issues you had with async, do let me know. I was working mostly off the test suite in #6555 which still had some open questions on the direction so it would be good if your use case covers some of this ambiguity. @fubhy I'm gonna give you a gentle nudge as well to see if there is anything I can do to help with getting this reviewed. Like I mentioned there are some open questions in the #6555 with the test suite, but this might be more down to reinforcing behavioral conformance between the different |
c0528bd to
94cc3cb
Compare
|
I'm going to be pausing development on this PR for the time being in favour of building a community package so I can explore a few side-quests: This is a bit of a step in complexity from the FileSystem implementation but unlocks some really interesting possibilities for integrations, permissions and virtual builds. I'll make this PR as draft for now and if anyone want to help contribute or has wishes for what is possible they are welcome to submit issues or PRs This does mean though that you can use this right away with: npm install @effect-vfs/memoryimport { MemoryFileSystem } from "@effect-vfs/memory"
import { Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
yield* fs.writeFileString("/settings.json", JSON.stringify({ mode: "preview" }))
return yield* fs.readFileString("/settings.json")
})
const settings = await Effect.runPromise(
program.pipe(Effect.provide(MemoryFileSystem.layer))
)
console.log(settings)@spencerbeggs Still looking for feedback so if you feel like trying this out instead of your package, let me know whats still missing |
3fb0cd3 to
36519eb
Compare
Type
Description
Adds an in-memory layer for
FileSystem, useful for testing filesystem-dependent code without creating and cleaning up host directories, and for dry-run or preview flows. The motivating use case is stack-effect#108.This builds on the
VirtualFileSystemin #9960 and ports the MemoryFileSystem adapter behavior fromeffect-vfs. VFS owns filesystem state, path resolution, links, metadata, and resource lifetimes. The adapter implements theFileSystemcontract, whileFileSystem.makesupplies derived helpers such as globbing.MemoryFileSystem.layerprovides an isolated volume with an empty/tmpdirectory.MemoryFileSystem.makeis a scoped constructor. Open files and watches have their own acquisition scopes, and the filesystem inherits VFS's finite limits.Review guide
The watcher commits come first, followed by the MemoryFileSystem adapter and its tests. Watching lives in VFS so other adapters can reuse it. The main review areas are caller lifetime, subscription cleanup, rename event ordering, and overflow recovery through
MemoryFileSystem.isWatchOverflow.The adapter tests cover the shared FileSystem and glob contracts, file cursors, copy cleanup, hard-link preservation, and scoped temporary files.
Full repository type checking currently reports unrelated dependency and type-resolution errors outside this change.
Related
This is part 2 of 2 in a stack made with GitButler: