bonsai-analyzer
Version:
Trim your dependency tree.
30 lines (24 loc) • 645 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getCollapsableParentOf;
function getCollapsableParentOf(modulesById, moduleId) {
const module = modulesById[moduleId];
if (!module) {
return null;
}
const requiredByCount = module.requiredBy.length;
if (requiredByCount === 0) {
return null;
} else if (requiredByCount === 1) {
return getCollapsableParentOf(modulesById, module.requiredBy[0].moduleId);
} else {
const requirementCount = module.requirements.length;
if (requirementCount === 0) {
return null;
} else {
return module;
}
}
}