mirror of https://github.com/status-im/metro.git
metro-memory-fs: fix createWriteStream autoClose behavior
Summary: In Node v6 there is no `final` function: https://nodejs.org/docs/v6.13.1/api/stream.html#stream_simplified_construction. It's not a problem however because we can preferentially use the `finish` event, that makes it more consistent with how `createReadStream` is implemented. I also added closing the fs on `error` events, as specified in the docs. **Test plan** yarn jest Closes https://github.com/facebook/metro/pull/150 Reviewed By: rafeca Differential Revision: D7215708 Pulled By: jeanlauliac fbshipit-source-id: 80921a245c8c87085a2ba83b84b1156a60aa1fb3
This commit is contained in:
parent
de35a73798
commit
d9e3d21922
|
@ -11,6 +11,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
jest.useRealTimers();
|
||||
|
||||
const MemoryFs = require('../index');
|
||||
|
||||
let fs;
|
||||
|
|
|
@ -497,20 +497,16 @@ class MemoryFs {
|
|||
}
|
||||
callback();
|
||||
},
|
||||
final: callback => {
|
||||
try {
|
||||
if (autoClose !== false) {
|
||||
this.closeSync(ffd);
|
||||
rst.emit('close');
|
||||
}
|
||||
} catch (error) {
|
||||
callback(error);
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
},
|
||||
});
|
||||
st = rst;
|
||||
if (autoClose !== false) {
|
||||
const doClose = () => {
|
||||
this.closeSync(ffd);
|
||||
rst.emit('close');
|
||||
};
|
||||
rst.on('finish', doClose);
|
||||
rst.on('error', doClose);
|
||||
}
|
||||
(st: any).path = filePath;
|
||||
(st: any).bytesWritten = 0;
|
||||
return st;
|
||||
|
|
Loading…
Reference in New Issue