fix: do not throw when fs is not extensible - #263
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
Store the shared retry queue off the fs object when it is not extensible (ESM node:fs namespace), while keeping the existing Symbol-on-fs publish path when Object.isExtensible(fs) is true. Fixes isaacs#245 Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
nyc loads node_modules/graceful-fs before tests, which already publishes the queue Symbol on the real fs. Load this tree against a cloned, Object.preventExtensions fs-like object instead. 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 #245
Bug
In ESM,
import * as fs from 'node:fs'is a non-extensible namespace object.graceful-fspublished the shared retry queue withObject.defineProperty(fs, Symbol.for('graceful-fs.queue'), …)and threw:Reproduced on current
mainbyObject.preventExtensions(require('fs'))thenrequire('graceful-fs').Fix
fs(orglobal) is not extensible, skip defining the queue Symbol on that object instead of throwing.fspublish path whenObject.isExtensible(fs)is true, so CJS / multi-copy queue sharing is unchanged.fs, useglobal[Symbol.for('graceful-fs.queue')](already used for cross-version sharing) and a module-local array as fallbacks.enqueue/retry/resetQueue) go throughgetQueue()so the fallback is used.This is a separate change from #262 (getter-only
fs.close).Tests
test/non-extensible-fs.js: load this tree against a cloned,Object.preventExtensionsfs-like object (nyc preloadsnode_modules/graceful-fsonto the realfs). Asserts load does not throw, file ops still work, the queue is not defined on the non-extensible object, later loads share the global queue, and EMFILE retries still drain that queue.test/queue-published-on-fs.js: extensible CJSfsstill gets the Symbol and shares one array withglobal.Local
npm test: 49472 passing.Claim-check
closed_by_pull_requests.total_countwas 0fs/ ESM /Symbol(graceful-fs.queue)