实现说明
各个操作都建立在顶层绑定之上:before、after、removed、added。
使用要点
- 跑完文件,输出里会留下标记——
removed:、added:、changed:。
常见问题
有需要管理的依赖吗?
没有。无需声明或安装任何依赖。 状态都挂在模块顶层:before、after、removed。
核心语句
const before = new Set(['auth', 'billing', 'search', 'admin']);
const after = new Set(['billing', 'search', 'reports']);
代码示例
const before = new Set(['auth', 'billing', 'search', 'admin']);
const after = new Set(['billing', 'search', 'reports']);
// difference: keys only present in 'before' — candidates to decommission.
const removed = before.difference(after);
console.log('removed:', [...removed]);
// The mirrored call answers the other direction: what was added.
const added = after.difference(before);
console.log('added:', [...added]);
// symmetricDifference: changed on either side — the deploy diff itself.
const changed = before.symmetricDifference(after);
console.log('changed:', [...changed]);
// Cross-check: union minus intersection equals the symmetric difference.
const union = before.union(after);
const shared = before.intersection(after);
console.log('agrees:', [...union.difference(shared)].join() === [...changed].join());