MCPcopy Create free account
hub / github.com/adobe/react-spectrum / enforceWorkspaceDependencies

Function enforceWorkspaceDependencies

yarn.config.cjs:144–198  ·  view source on GitHub ↗

@param {Context} context

({Yarn})

Source from the content-addressed store, hash-verified

142
143/** @param {Context} context */
144function 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 // Do not turn optional peers into required peers of dependent workspaces.
168 if (
169 dependency.type === 'peerDependencies' &&
170 !dependency.workspace.manifest.peerDependenciesMeta?.[dependency.ident]?.optional
171 ) {
172 for (const workspace of Yarn.workspaces()) {
173 if (
174 // must check in manifest because yarn is reporting all peer in workspace.pkg.dependencies
175 // and doesn't differentiate between peer and dependencies
176 workspace.manifest.dependencies?.[dependency.workspace?.ident] &&
177 !workspace.manifest.peerDependencies?.[dependency.ident] &&
178 !workspace.manifest.dependencies?.[dependency.ident]
179 ) {
180 // eslint-disable-next-line max-depth
181 if (seen.has(workspace.ident) && !seen.get(workspace.ident).includes(dependency.ident)) {
182 seen.get(workspace.ident).push(dependency.ident);
183 workspace.set('peerDependencies', {
184 ...workspace.manifest.peerDependencies,
185 [dependency.ident]: dependency.range
186 });
187 } else if (!seen.has(workspace.ident) && workspace.ident !== dependency.ident) {
188 seen.set(workspace.ident, [dependency.ident]);
189 workspace.set('peerDependencies', {
190 ...workspace.manifest.peerDependencies,
191 [dependency.ident]: dependency.range
192 });
193 }
194 }
195 }
196 }
197 }
198}
199
200/** @param {Workspace} workspace */
201function isPublishing(workspace) {

Callers 1

yarn.config.cjsFile · 0.85

Calls 4

isOurPackageFunction · 0.85
pushMethod · 0.80
hasMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected