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
7 changes: 4 additions & 3 deletions packages/metro/src/DeltaBundler/DeltaCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,12 @@ export default class DeltaCalculator<T> extends EventEmitter {
}
});

// An added file that already has a module in the graph was deleted and
// recreated while a build was in flight. The graph never saw the deletion,
// so the module it holds is stale and needs revisiting.
// An added file the graph already holds was deleted and recreated during
// a build, so its module is stale. It is modified, not added, since it
// never left the graph.
addedFiles.forEach((filePath: string) => {
if (this._graph.dependencies.has(filePath)) {
addedFiles.delete(filePath);
modifiedFiles.add(filePath);
}
});
Expand Down
22 changes: 22 additions & 0 deletions packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,28 @@ describe.each(['posix', 'win32'])('DeltaCalculator (%s)', osPlatform => {
expect(traverseDependencies.mock.calls[1][0]).toEqual([p('/bundle')]);
});

test('should not traverse a re-added file deleted after a failed delta', async () => {
await deltaCalculator.getDelta({reset: false, shallow: false});

// As after a delete and re-add during an earlier build.
emitChange({addedFiles: ['foo']});
traverseDependencies.mockRejectedValueOnce(new Error('Syntax error'));
await expect(
deltaCalculator.getDelta({reset: false, shallow: false}),
).rejects.toBeInstanceOf(Error);

emitChange({removedFiles: ['foo']});
traverseDependencies.mockResolvedValueOnce({
added: new Map(),
modified: new Map([[p('/bundle'), entryModule]]),
deleted: new Set([p('/foo')]),
});
await deltaCalculator.getDelta({reset: false, shallow: false});

expect(traverseDependencies).toHaveBeenCalledTimes(2);
expect(traverseDependencies.mock.calls[1][0]).toEqual([p('/bundle')]);
});

test('should traverse a file re-added while a successful delta was being built', async () => {
await deltaCalculator.getDelta({reset: false, shallow: false});

Expand Down
Loading