Skip to content

Commit

Permalink
Merge pull request #14097 from clkamp/wip-distance-order
Browse files Browse the repository at this point in the history
fix(core): revisit dependencies w/ possibly higher distance
  • Loading branch information
kamilmysliwiec authored Nov 8, 2024
2 parents 3081f54 + 2c8982a commit 84bf570
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/core/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,20 @@ export class DependenciesScanner {
// Skip "InternalCoreModule" from calculating distance
modulesGenerator.next();

const modulesStack = [];
const calculateDistance = (moduleRef: Module, distance = 1) => {
if (!moduleRef || modulesStack.includes(moduleRef)) {
const calculateDistance = (moduleRef: Module, distance = 1, modulesStack = []) => {
const localModulesStack = [...modulesStack];
if (!moduleRef || localModulesStack.includes(moduleRef)) {
return;
}
modulesStack.push(moduleRef);
localModulesStack.push(moduleRef);

const moduleImports = moduleRef.imports;
moduleImports.forEach(importedModuleRef => {
if (importedModuleRef) {
if (distance > importedModuleRef.distance) {
importedModuleRef.distance = distance;
}
calculateDistance(importedModuleRef, distance + 1);
calculateDistance(importedModuleRef, distance + 1, localModulesStack);
}
});
};
Expand Down

0 comments on commit 84bf570

Please sign in to comment.