You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately these classes are defined in the node.js fs module using property getter/setter functions. The getter/setter from the fs module are copied to the cloned object, so we are actually updating the internal fs variable.
The fix for this is to set the updated values using Object.defineProperty with an updated get/set mimicking the core fs module but pointing to a gfs variable. Not sure if this would be considered a breaking change for gfs? On specific way this can be a real issue is fs.WriteStream.open does not honor the autoClose: false option which was added in node.js 5.
Failing test-case:
'use strict';constfs=require('fs');constt=require('tap');// Save originals before loading graceful-fsconstnames=['ReadStream','WriteStream','FileReadStream','FileWriteStream'];constorig=names.reduce((orig,name)=>Object.assign(orig,{[name]: fs[name]}),{});constgfs=require('graceful-fs');if(names.some(name=>gfs[name]===orig[name])){t.fail('This test cannot be run under nyc');process.exit(1);}names.forEach(name=>{t.ok(fs[name]===orig[name],`fs.${name} unchanged`);});
fs.createReadStream and fs.createWriteStream are not monkey-patched like this but they are effected as they use fs.ReadStream and fs.WriteStream.
The text was updated successfully, but these errors were encountered:
fs
is cloned by copying property descriptors to a new object. We replace the stream classes:And later:
Unfortunately these classes are defined in the node.js
fs
module using property getter/setter functions. The getter/setter from thefs
module are copied to the cloned object, so we are actually updating the internalfs
variable.The fix for this is to set the updated values using
Object.defineProperty
with an updated get/set mimicking the corefs
module but pointing to a gfs variable. Not sure if this would be considered a breaking change for gfs? On specific way this can be a real issue isfs.WriteStream.open
does not honor theautoClose: false
option which was added in node.js 5.Failing test-case:
fs.createReadStream
andfs.createWriteStream
are not monkey-patched like this but they are effected as they usefs.ReadStream
andfs.WriteStream
.The text was updated successfully, but these errors were encountered: