Skip to content

Commit a72bc26

Browse files
authored
Backport PR #490: Fix finding dependents for deactivation (#491)
1 parent 0147905 commit a72bc26

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

packages/application/src/index.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,35 @@ namespace Private {
890890
add(id);
891891
}
892892

893-
const sorted = topologicSort(edges);
893+
// Filter edges
894+
// - Get all packages that dependent on the package to be deactivated
895+
const newEdges = edges.filter(edge => edge[1] === id);
896+
let oldSize = 0;
897+
while (newEdges.length > oldSize) {
898+
const previousSize = newEdges.length;
899+
// Get all packages that dependent on packages that will be deactivated
900+
const packagesOfInterest = newEdges
901+
.map(edge => edge[0])
902+
.reduce<string[]>((agg, value) => {
903+
if (agg.indexOf(value) == -1) {
904+
agg.push(value);
905+
}
906+
return agg;
907+
}, []);
908+
for (const poi of packagesOfInterest) {
909+
edges
910+
.filter(edge => edge[1] === poi)
911+
.forEach(edge => {
912+
// We check it is not already included to deal with circular dependencies
913+
if (newEdges.indexOf(edge) == -1) {
914+
newEdges.push(edge);
915+
}
916+
});
917+
}
918+
oldSize = previousSize;
919+
}
920+
921+
const sorted = topologicSort(newEdges);
894922
const index = findIndex(sorted, candidate => candidate === id);
895923

896924
if (index === -1) {

0 commit comments

Comments
 (0)