@param {Context} context
({Yarn})
| 142 | |
| 143 | /** @param {Context} context */ |
| 144 | function enforceWorkspaceDependencies({Yarn}) { |
| 145 | for (const dependency of Yarn.dependencies()) { |
| 146 | if (dependency.type === 'peerDependencies') { |
| 147 | continue; |
| 148 | } |
| 149 | |
| 150 | for (const otherDependency of Yarn.dependencies({ident: dependency.ident})) { |
| 151 | if (otherDependency.type === 'peerDependencies') { |
| 152 | continue; |
| 153 | } |
| 154 | |
| 155 | if (isOurPackage(dependency)) { |
| 156 | // change back to workspaces:^ when we're ready for yarn to handle versioning |
| 157 | // don't check for consistency on our own packages because they can individually version and we don't bump EVERY package because of one change |
| 158 | // dependency.update(otherDependency.range); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // This finds all the peer dependencies and checks that everything up the |
| 164 | // workspace tree has the same peer dependency. |
| 165 | let seen = new Map(); |
| 166 | for (const dependency of Yarn.dependencies()) { |
| 167 | if (dependency.type === 'peerDependencies') { |
| 168 | for (const workspace of Yarn.workspaces()) { |
| 169 | if ( |
| 170 | // must check in manifest because yarn is reporting all peer in workspace.pkg.dependencies |
| 171 | // and doesn't differentiate between peer and dependencies |
| 172 | workspace.manifest.dependencies?.[dependency.workspace?.ident] && |
| 173 | !workspace.manifest.peerDependencies?.[dependency.ident] && |
| 174 | !workspace.manifest.dependencies?.[dependency.ident] |
| 175 | ) { |
| 176 | // eslint-disable-next-line max-depth |
| 177 | if (seen.has(workspace.ident) && !seen.get(workspace.ident).includes(dependency.ident)) { |
| 178 | seen.get(workspace.ident).push(dependency.ident); |
| 179 | workspace.set('peerDependencies', { |
| 180 | ...workspace.manifest.peerDependencies, |
| 181 | [dependency.ident]: dependency.range |
| 182 | }); |
| 183 | } else if (!seen.has(workspace.ident) && workspace.ident !== dependency.ident) { |
| 184 | seen.set(workspace.ident, [dependency.ident]); |
| 185 | workspace.set('peerDependencies', { |
| 186 | ...workspace.manifest.peerDependencies, |
| 187 | [dependency.ident]: dependency.range |
| 188 | }); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /** @param {Workspace} workspace */ |
| 197 | function isPublishing(workspace) { |
no test coverage detected