@param {Context} context
({Yarn})
| 90 | |
| 91 | /** @param {Context} context */ |
| 92 | function enforceNoCircularDependencies({Yarn}) { |
| 93 | // enforce that there are no circular dependencies between our packages |
| 94 | function addDep(workspace, seen = new Set()) { |
| 95 | if (seen.has(workspace.ident)) { |
| 96 | let arr = [...seen]; |
| 97 | let index = arr.indexOf(workspace.ident); |
| 98 | // ok for pkg to depend on itself |
| 99 | if (arr.slice(index).length > 1) { |
| 100 | // better to error the constraints early for this for a more meaningful error message |
| 101 | throw new Error( |
| 102 | `Circular dependency detected: ${arr.slice(index).join(' -> ')} -> ${workspace.ident}` |
| 103 | ); |
| 104 | } else { |
| 105 | return; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | seen.add(workspace.ident); |
| 110 | |
| 111 | for (let d of Yarn.dependencies({ident: workspace.ident})) { |
| 112 | if (d.type === 'peerDependencies') { |
| 113 | continue; |
| 114 | } |
| 115 | addDep(d.workspace, seen); |
| 116 | } |
| 117 | |
| 118 | seen.delete(workspace.ident); |
| 119 | } |
| 120 | |
| 121 | for (const workspace of Yarn.workspaces()) { |
| 122 | addDep(workspace); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /** @param {Dependency} dependency */ |
| 127 | function isOurPackage(dependency) { |