Skip to content

Commit

Permalink
Backport PR jupyterlab#490: Fix finding dependents for deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Dec 12, 2022
1 parent 0147905 commit 482dbae
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion packages/application/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,35 @@ namespace Private {
add(id);
}

const sorted = topologicSort(edges);
// Filter edges
// - Get all packages that dependent on the package to be deactivated
const newEdges = edges.filter(edge => edge[1] === id);
let oldSize = 0;
while (newEdges.length > oldSize) {
const previousSize = newEdges.length;
// Get all packages that dependent on packages that will be deactivated
const packagesOfInterest = newEdges
.map(edge => edge[0])
.reduce<string[]>((agg, value) => {
if (agg.indexOf(value) == -1) {
agg.push(value);
}
return agg;
}, []);
for (const poi of packagesOfInterest) {
edges
.filter(edge => edge[1] === poi)
.forEach(edge => {
// We check it is not already included to deal with circular dependencies
if (newEdges.indexOf(edge) == -1) {
newEdges.push(edge);
}
});
}
oldSize = previousSize;
}

const sorted = topologicSort(newEdges);
const index = findIndex(sorted, candidate => candidate === id);

if (index === -1) {
Expand Down

0 comments on commit 482dbae

Please sign in to comment.