From 77f6ac080d2efea9487ee4a902a77940feead07e Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Sat, 16 Sep 2017 08:58:19 -0700 Subject: [PATCH] Handle renames/deletes of modules correctly Reviewed By: cpojer Differential Revision: D5845030 fbshipit-source-id: a33af56bf5a479768eaf64b42ec3251a724c0315 --- .../src/DeltaBundler/DeltaCalculator.js | 11 +++++++++++ .../__tests__/DeltaCalculator-test.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js b/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js index 68bb4e6f..42bd015f 100644 --- a/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro-bundler/src/DeltaBundler/DeltaCalculator.js @@ -167,6 +167,17 @@ class DeltaCalculator extends EventEmitter { type: string, filePath: string, }): mixed => { + // We do not want to keep track of deleted files, since this can cause + // issues when moving files (or even deleting files). + // The only issue with this approach is that the user removes a file that + // is needed, the bundler will still create a correct bundle (since it + // won't detect any modified file). Once we have our own dependency + // traverser in Delta Bundler this will be easy to fix. + if (type === 'delete') { + this._dependencies.delete(filePath); + return; + } + this._modifiedFiles.add(filePath); // Notify users that there is a change in some of the bundle files. This diff --git a/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js b/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js index 17fd4965..45bb2c68 100644 --- a/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js +++ b/packages/metro-bundler/src/DeltaBundler/__tests__/DeltaCalculator-test.js @@ -235,6 +235,21 @@ describe('DeltaCalculator', () => { expect(onChangeFile.mock.calls.length).toBe(0); }); + it('should not emit an event when there is a file deleted', async () => { + jest.useFakeTimers(); + + const onChangeFile = jest.fn(); + await deltaCalculator.getDelta(); + + deltaCalculator.on('delete', onChangeFile); + + fileWatcher.emit('change', {eventsQueue: [{filePath: '/foo'}]}); + + jest.runAllTimers(); + + expect(onChangeFile.mock.calls.length).toBe(0); + }); + it('should retry to build the last delta after getting an error', async () => { await deltaCalculator.getDelta();