Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/metro/src/DeltaBundler/DeltaCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ export default class DeltaCalculator<T> extends EventEmitter {
return false;
}

_handleMultipleFileChanges = (changeEvent: ChangeEvent) => {
_handleMultipleFileChanges = (changeEvent: ?ChangeEvent) => {
// Some third party watchers emit a bare 'change' with no payload.
if (changeEvent == null || changeEvent.changes == null) {
return;
}
const {changes, logger, rootDir} = changeEvent;

// Process added files: deleted+added = modified, otherwise added
Expand Down
21 changes: 21 additions & 0 deletions packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,27 @@ describe.each(['posix', 'win32'])('DeltaCalculator (%s)', osPlatform => {
});
});

test('should ignore change events that omit the changes payload', async () => {
await deltaCalculator.getDelta({reset: false, shallow: false});

expect(() => {
fileWatcher.emit('change');
fileWatcher.emit('change', {});
}).not.toThrow();

const result = await deltaCalculator.getDelta({
reset: false,
shallow: false,
});

expect(result).toEqual({
added: new Map(),
modified: new Map(),
deleted: new Set(),
reset: false,
});
});

test('should emit an event when there is a relevant file change', done => {
deltaCalculator
.getDelta({reset: false, shallow: false})
Expand Down
6 changes: 5 additions & 1 deletion packages/metro/src/node-haste/DependencyGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ export default class DependencyGraph extends EventEmitter {
await this._initializedPromise;
}

_onHasteChange({changes, rootDir}: ChangeEvent) {
_onHasteChange(changeEvent: ?ChangeEvent) {
if (changeEvent == null || changeEvent.changes == null) {
return;
}
const {changes, rootDir} = changeEvent;
this._resolutionCache = new Map();
[
...changes.addedFiles,
Expand Down