mirror of https://github.com/status-im/metro.git
Delta Calculator: handle files that have been added from one side and deleted from another
Reviewed By: davidaurelio Differential Revision: D6665792 fbshipit-source-id: fa8f241bdfc88d77f5662c31796b0644988187cd
This commit is contained in:
parent
de77f0340b
commit
f5198ad15f
|
@ -178,6 +178,30 @@ describe('edge cases', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should not try to remove wrong dependencies when renaming files', async () => {
|
||||
const edges = new Map();
|
||||
await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);
|
||||
|
||||
// Rename /foo to /foo-renamed, but keeping all its dependencies.
|
||||
const moduleFooRenamed = createModule({
|
||||
path: '/foo-renamed',
|
||||
name: 'foo-renamed',
|
||||
});
|
||||
mockedDependencyTree.set(entryModule.path, [moduleFooRenamed]);
|
||||
mockedDependencyTree.set(moduleFooRenamed.path, [moduleBar, moduleBaz]);
|
||||
mockedDependencies.add(moduleFooRenamed);
|
||||
mockedDependencies.delete(moduleFoo);
|
||||
|
||||
// Call traverseDependencies with /foo, /qux and /baz, simulating that the
|
||||
// user has modified the 3 files.
|
||||
expect(
|
||||
await traverseDependencies(['/bundle'], dependencyGraph, {}, edges),
|
||||
).toEqual({
|
||||
added: new Set(['/foo-renamed']),
|
||||
deleted: new Set(['/foo']),
|
||||
});
|
||||
});
|
||||
|
||||
it('modify a file and delete it afterwards', async () => {
|
||||
const edges = new Map();
|
||||
await initialTraverseDependencies('/bundle', dependencyGraph, {}, edges);
|
||||
|
|
|
@ -68,7 +68,15 @@ async function traverseDependencies(
|
|||
added.add(path);
|
||||
}
|
||||
for (const path of change.deleted) {
|
||||
deleted.add(path);
|
||||
// If a path has been marked both as added and deleted, it means that this
|
||||
// path is a dependency of a renamed file (or that dependency has been
|
||||
// removed from one path but added back in a different path). In this case
|
||||
// the addition and deletion "get cancelled".
|
||||
if (added.has(path)) {
|
||||
added.delete(path);
|
||||
} else {
|
||||
deleted.add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue