fix: do not throw when fs.close is getter-only - #262
Closed
dyk1454683243-sudo wants to merge 2 commits into
Closed
dyk1454683243-sudo wants to merge 2 commits into
dyk1454683243-sudo wants to merge 2 commits into
Conversation
Bundlers and ESM interop (Vite/esbuild) expose fs methods as getter-only properties, so `fs.close = ...` throws TypeError. Only assign when the property is writable or configurable, and materialize getter-only properties on the cloned export so it can still be patched. Fixes isaacs#257 Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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.
Fixes #257
Problem
On some Node / bundler setups (Vite, esbuild, ESM interop),
require('fs')is a namespace-style object whose methods are getter-only. graceful-fs then does:and throws:
This shows up through
fs-extra→graceful-fswhen the dependency graph is pre-bundled.Fix
fs.close/fs.closeSynconly when the property is writable or has a setter.defineProperty.fs.closecould not be assigned, still wrapcloseon the exported object so EMFILE retries keep working for graceful-fs callers.Normal Node is unchanged:
fs.closeremains a writable data property, so the existing assignment path is used.Tests
test/close-getter-only.js:closeis patched (defineProperty path)close/closeSyncstill open and close real file descriptorscloseloads without throwing and leaves the realfsmethod aloneclone()turns getter-only properties into writable data propertiesLocal
npm test: 49460 passing.Does not overlap with #261 (large
writeFile).