From d0fdca73cdfd4ca7e152d4c8a5d0bb616f336480 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Wed, 11 Apr 2018 09:41:32 -0700 Subject: [PATCH] metro-memory-fs: Do not report a file change when reading a file Reviewed By: jeanlauliac Differential Revision: D7584517 fbshipit-source-id: 55f87d15c723f697ea00c357da1d36f5d31accbb --- packages/metro-memory-fs/src/__tests__/index-test.js | 9 +++++++++ packages/metro-memory-fs/src/index.js | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/metro-memory-fs/src/__tests__/index-test.js b/packages/metro-memory-fs/src/__tests__/index-test.js index 3781ff1f..6542d292 100644 --- a/packages/metro-memory-fs/src/__tests__/index-test.js +++ b/packages/metro-memory-fs/src/__tests__/index-test.js @@ -429,6 +429,15 @@ describe('watch', () => { watcher.close(); }); + it('does not report changes when just reading a file', () => { + const changedPaths = []; + fs.writeFileSync('/foo.txt', ''); + const watcher = collectWatchEvents('/', {}, changedPaths); + fs.readFileSync('/foo.txt'); + expect(changedPaths).toEqual([]); + watcher.close(); + }); + function collectWatchEvents(entPath, options, events) { return fs.watch(entPath, options, (eventName, filePath) => { events.push([eventName, filePath]); diff --git a/packages/metro-memory-fs/src/index.js b/packages/metro-memory-fs/src/index.js index 3d7a5e2e..1497050e 100644 --- a/packages/metro-memory-fs/src/index.js +++ b/packages/metro-memory-fs/src/index.js @@ -197,7 +197,9 @@ class MemoryFs { closeSync = (fd: number): void => { const desc = this._getDesc(fd); - this._emitFileChange(desc.nodePath.slice(), {eventType: 'change'}); + if (desc.writable) { + this._emitFileChange(desc.nodePath.slice(), {eventType: 'change'}); + } this._fds.delete(fd); };