找出依赖检查器里的 bug

来自 软件架构入门
Node 24 进阶 4分钟 找出 1处问题

这个检查器承诺找出从领域代码到适配器代码的每条依赖路径,请找出缺陷。

JavaScript
function forbiddenDependencies(graph, domainModules, adapterModules) {
  const violations = [];
  for (const domain of domainModules) {
    for (const dependency of graph.get(domain) ?? []) {
      if (adapterModules.has(dependency)) {
        violations.push(`${domain} -> ${dependency}`);
      }
    }
  }
  return violations;
}

const graph = new Map([
  ['order', ['shared-money']],
  ['shared-money', ['postgres-decimal']],
]);
在试验场中打开
报告错误