mirror of https://github.com/status-im/metro.git
Handle renames/deletes of modules correctly
Reviewed By: cpojer Differential Revision: D5845030 fbshipit-source-id: a33af56bf5a479768eaf64b42ec3251a724c0315
This commit is contained in:
parent
f9526cf486
commit
77f6ac080d
|
@ -167,6 +167,17 @@ class DeltaCalculator extends EventEmitter {
|
||||||
type: string,
|
type: string,
|
||||||
filePath: string,
|
filePath: string,
|
||||||
}): mixed => {
|
}): 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);
|
this._modifiedFiles.add(filePath);
|
||||||
|
|
||||||
// Notify users that there is a change in some of the bundle files. This
|
// Notify users that there is a change in some of the bundle files. This
|
||||||
|
|
|
@ -235,6 +235,21 @@ describe('DeltaCalculator', () => {
|
||||||
expect(onChangeFile.mock.calls.length).toBe(0);
|
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 () => {
|
it('should retry to build the last delta after getting an error', async () => {
|
||||||
await deltaCalculator.getDelta();
|
await deltaCalculator.getDelta();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue