feat(vfs): add @scratchyjs/vfs private in-memory filesystem package#30
Merged
feat(vfs): add @scratchyjs/vfs private in-memory filesystem package#30
Conversation
Contributor
Co-authored-by: Asjas <3828967+Asjas@users.noreply.github.com> Agent-Logs-Url: https://github.com/Asjas/scratchyjs/sessions/6d7584ec-1d78-4447-90c3-b17e079b7e88
Copilot
AI
changed the title
[WIP] Add private package for Node.js virtual file system
feat(vfs): add @scratchyjs/vfs private in-memory filesystem package
Mar 23, 2026
Contributor
|
📚 Docs preview deployed https://scratchyjs-docs-pr-30.asjas.workers.dev Updates automatically on every push to this PR. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new private workspace package, @scratchyjs/vfs, providing an in-memory filesystem plus a node:fs monkey-patching layer so tests can use realistic FS behavior without vi.mock("node:fs").
Changes:
- Introduces
MemoryProvider(in-memory tree), routing helpers, POSIX-style error helpers, and Stats/Dirent-like objects. - Implements
VirtualFileSystemthat mounts/unmounts by patchingnode:fssync + promises APIs (and optionallyprocess.cwd/chdir). - Adds a comprehensive Vitest suite for provider behavior and
node:fsinterception.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds the new packages/vfs importer entry. |
| packages/vfs/package.json | Defines new private package metadata, exports, and typecheck script. |
| packages/vfs/tsconfig.json | Adds package TS config extending repo defaults. |
| packages/vfs/src/errors.ts | POSIX-style ErrnoException factories used across provider/VFS. |
| packages/vfs/src/stats.ts | Defines VfsStats plus helpers to create file/dir/symlink stats. |
| packages/vfs/src/router.ts | Mount-point routing helpers (isUnderMountPoint, getRelativePath). |
| packages/vfs/src/memory-provider.ts | Implements the in-memory filesystem operations. |
| packages/vfs/src/file-system.ts | Implements VirtualFileSystem plus node:fs + process.cwd/chdir hooks. |
| packages/vfs/src/index.ts | Exposes public API (create, exports). |
| packages/vfs/src/index.test.ts | Adds unit/integration tests for provider + mount interception. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: A-J Roos <asjasroos@pm.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: A-J Roos <asjasroos@pm.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: A-J Roos <asjasroos@pm.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: A-J Roos <asjasroos@pm.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: A-J Roos <asjasroos@pm.me>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: A-J Roos <asjasroos@pm.me>
Copilot stopped work on behalf of
Asjas due to an error
March 23, 2026 07:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the Node.js virtual filesystem API from nodejs/node#61478 as a private, local TypeScript package so tests can use a real in-memory FS instead of
vi.mock('node:fs').Package structure
src/errors.ts– POSIX error factory helpers (createENOENT,createEEXIST,createENOTDIR,createEISDIR,createENOTEMPTY)src/stats.ts–makeStats()factory that returns a plain object satisfyingfs.Stats(replaces the internalgetStatsFromBindingfrom the upstream PR)src/router.ts–isUnderMountPoint/getRelativePathpath helpers; usespath.posix.joinper reviewer feedback on the upstream PRsrc/memory-provider.ts–MemoryProviderclass: full in-memory tree backed by aMap<string, MemoryNode>; supports file/directory CRUD,readdir,stat,lstat, recursive mkdir/rm,renamesrc/file-system.ts–VirtualFileSystemclass: wraps a provider and monkey-patchesnode:fssync/async/promises surface onmount(), restores originals onunmount(); exposesaddFile()/addDirectory()convenience helperssrc/index.ts– Public API:create(mountPoint)factory +VirtualFileSystemtype exportUsage in tests
Calling
mount()replacesreadFileSync,writeFileSync,existsSync,statSync,mkdirSync,readdirSync,rmSync,unlinkSync, and theirfs.promisesequivalents. All other paths fall through to the real filesystem unchanged.Notable deviations from the upstream PR
path.posix.joinused throughout (upstream reviewer requestedpath.joinover manual string concatenation)makeDirHelperfactory eliminates the empty stub pattern; each VFS instance gets its own scopedaddDirectoryprocess.cwd()/process.chdir()are also virtualised while mounted so relative-path tests stay hermetic🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.