Skip to content

fix(memfs): resolve relative streams from virtual cwd - #1271

Open
xianjianlf2 wants to merge 1 commit into
streamich:masterfrom
xianjianlf2:fix/create-write-stream-relative-900
Open

fix(memfs): resolve relative streams from virtual cwd#1271
xianjianlf2 wants to merge 1 commit into
streamich:masterfrom
xianjianlf2:fix/create-write-stream-relative-900

Conversation

@xianjianlf2

Copy link
Copy Markdown
Contributor

Summary

  • resolve Superblock relative paths against the volume's process-like cwd instead of the host process cwd
  • give the default memfs export and memfs() helper a virtual-root cwd by default
  • add regression coverage for relative createWriteStream paths on memfs() and the default fs export

Fixes #900.

Tests

  • yarn build
  • yarn jest packages/memfs/src/tests/memfs.process.test.ts --runInBand
  • yarn jest packages/fs-node/src/tests/volume.process.test.ts --runInBand
  • yarn prettier --check packages/fs-core/src/Superblock.ts packages/fs-node/src/tests/volume.process.test.ts packages/memfs/src/tests/memfs.process.test.ts packages/memfs/src/index.ts
  • node runtime check for default fs.createWriteStream('relative') and memfs().fs.createWriteStream('relative')

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes relative-path stream operations in memfs by ensuring path resolution uses the virtual filesystem鈥檚 own process-like cwd() rather than the host Node.js process working directory, matching expected fs semantics and addressing #900.

Changes:

  • Resolve Superblock relative paths against the volume鈥檚 configured process.cwd() for core filesystem operations.
  • Set the default exported memfs instance (and memfs() helper default) to use a virtual-root cwd ('/') so relative paths land inside the volume.
  • Add regression tests covering relative createWriteStream() behavior for both memfs() instances and the default exported fs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/memfs/src/index.ts Introduces a process-like wrapper to provide a virtual cwd and updates default volume initialization to avoid host-cwd resolution.
packages/memfs/src/tests/memfs.process.test.ts Adds regression coverage for relative createWriteStream() paths on memfs() and the default exported fs.
packages/fs-node/src/tests/volume.process.test.ts Verifies that relative writes resolve against a custom process.cwd() when provided to a Volume.
packages/fs-core/src/Superblock.ts Routes filename-to-steps resolution through the volume鈥檚 process.cwd() so relative paths resolve within the virtual FS context.

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.

Using createWriteStream does not work as intended

2 participants