Skip to content

Conversation

@arcanis
Copy link
Member

@arcanis arcanis commented Sep 22, 2025

What's the problem this PR addresses?

The current implementation of file handles on Node.js was a little heavy-handed, as we were going through our own FileHandle class, bypassing the Node.js one. Should our implementation be behind (which is the case), userland would also rely on the outdated implementation rather than the stock Node.js one.

Fixes #6890

How did you fix it?

We now only use our own FileHandle implementation for files located within zip archives.

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

arcanis added a commit that referenced this pull request Nov 7, 2025
## What's the problem this PR addresses?

Fixes #6890
Fixes #6145

Node's
[implementation](https://github.com/nodejs/node/blob/94cbb7758282bf5db837412f7cb3698f17ac1af3/lib/internal/fs/promises.js#L648)
of `FileHandle#read` allows reading into `TypedArray`s and `DataView`s
(collectively known as `ArrayBufferView`s, and checks for them using
`ArrayBuffer.isView()`.

On the other hand, our implementation checks using `Buffer.isBuffer()`
and thus only allows `Buffer`. If an `ArrayBufferView` is given, it
treats them as an options bag and pass its `.buffer` (which is an
`ArrayBuffer`) as the sink to the backing fs. If the backing fs is
Node's native `fs` then it would throw.

## How did you fix it?

Allow `ArrayBufferView`s by checking with `ArrayBuffer.isView()` as in
Node's implementation.

Because the underlying `FakeFS` interface only allows `Buffer` (and
changing that would be a breaking change), a `Buffer` backed by the
`ArrayBufferView` is used. (Q: Should we make that change next major?)

Also un-vendored the TypeScript types if the exact same type is
available from `@types/node` along the way. AFAICT those were vendored
because those types wasn't available at first? \cc @merceyz

This fix should be orthogonal to #6919 

## Checklist

<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).

<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.

<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

---------

Co-authored-by: Maël Nison <[email protected]>
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.

[Bug?]: Incorrect FS return type under PnP

2 participants