Handle renames/deletes of modules correctly

Reviewed By: cpojer

Differential Revision: D5845030

fbshipit-source-id: a33af56bf5a479768eaf64b42ec3251a724c0315
This commit is contained in:
Rafael Oleza 2017-09-16 08:58:19 -07:00 committed by Facebook Github Bot
parent f9526cf486
commit 77f6ac080d
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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();