diff --git a/packages/metro/src/DeltaBundler/DeltaCalculator.js b/packages/metro/src/DeltaBundler/DeltaCalculator.js index 58ca935a..ac8dec5b 100644 --- a/packages/metro/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro/src/DeltaBundler/DeltaCalculator.js @@ -220,6 +220,7 @@ class DeltaCalculator extends EventEmitter { this._deletedFiles.add(filePath); this._modifiedFiles.delete(filePath); } else { + this._deletedFiles.delete(filePath); this._modifiedFiles.add(filePath); } diff --git a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js index 5ba4847d..72b4175b 100644 --- a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js @@ -313,6 +313,30 @@ describe('DeltaCalculator', () => { expect(traverseDependencies.mock.calls[0][0]).toEqual(['/bundle']); }); + it('should not do unnecessary work when adding a file after deleting it', async () => { + await deltaCalculator.getDelta(); + + // First delete a file + fileWatcher.emit('change', { + eventsQueue: [{type: 'delete', filePath: '/foo'}], + }); + + // Then add it again + fileWatcher.emit('change', {eventsQueue: [{filePath: '/foo'}]}); + + traverseDependencies.mockReturnValue( + Promise.resolve({ + added: new Map([['/foo', edgeModule]]), + deleted: new Set(), + }), + ); + + await deltaCalculator.getDelta(); + + expect(traverseDependencies).toHaveBeenCalledTimes(1); + expect(traverseDependencies.mock.calls[0][0]).toEqual(['/foo']); + }); + describe('getTransformerOptions()', () => { it('should calculate the transform options correctly', async () => { expect(await deltaCalculator.getTransformerOptions()).toEqual({ diff --git a/packages/metro/src/DeltaBundler/__tests__/traverseDependencies-test.js b/packages/metro/src/DeltaBundler/__tests__/traverseDependencies-test.js index ec74d79c..b3b602bc 100644 --- a/packages/metro/src/DeltaBundler/__tests__/traverseDependencies-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/traverseDependencies-test.js @@ -221,28 +221,6 @@ describe('edge cases', () => { }); }); - it('modify a file and delete it afterwards', async () => { - const edges = new Map(); - await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges); - - mockedDependencyTree.set(moduleFoo.path, [moduleBar]); - - // Modify /baz, rename it to /qux and modify it again. - expect( - getPaths( - await traverseDependencies( - ['/baz', '/foo'], - dependencyGraph, - {}, - edges, - ), - ), - ).toEqual({ - added: new Set(['/foo']), - deleted: new Set(['/baz']), - }); - }); - it('move a file to a different folder', async () => { const edges = new Map(); await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);