Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(constraints): allow exceptions for dependency-range consistency #4772

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,35 @@ function expectControllerDependenciesListedAsPeerDependencies(
}
}

/**
* Filter out dependency ranges which are not to be considered in `expectConsistentDependenciesAndDevDependencies`.
*
* @param {string} dependencyIdent - The dependency being filtered for
* @param {Map<string, Dependency>} dependenciesByRange - Dependencies by range
* @returns {Map<string, Dependency>} The resulting map.
*/
function getInconsistentDependenciesAndDevDependencies(
dependencyIdent,
dependenciesByRange,
) {
const ALLOWED_INCONSISTENT_DEPENDENCIES = Object.entries({
// '@metamask/foo': ['^1.0.0'],
});
Comment on lines +728 to +730
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be near the top of the file?

Copy link
Contributor Author

@legobeat legobeat Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking co-locating is clearer (esp since other exceptions are also currently inlined) but I will move it out of the function body in a follow-up!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (const [
allowedPackage,
ignoredRange,
] of ALLOWED_INCONSISTENT_DEPENDENCIES) {
if (allowedPackage === dependencyIdent) {
return new Map(
Object.entries(dependenciesByRange).filter(
([range]) => !ignoredRange.includes(range),
),
);
}
}
return dependenciesByRange;
}

/**
* Expect that all version ranges in `dependencies` and `devDependencies` for
* the same dependency across the entire monorepo are the same. As it is
Expand All @@ -732,18 +761,24 @@ function expectConsistentDependenciesAndDevDependencies(Yarn) {
dependencyIdent,
dependenciesByRange,
] of nonPeerDependenciesByIdent.entries()) {
const dependencyRanges = [...dependenciesByRange.keys()].sort();
if (dependenciesByRange.size > 1) {
for (const dependencies of dependenciesByRange.values()) {
for (const dependency of dependencies) {
dependency.error(
`Expected version range for ${dependencyIdent} (in ${
dependency.type
}) to be consistent across monorepo. Pick one: ${inspect(
dependencyRanges,
)}`,
);
}
if (dependenciesByRange.size <= 1) {
continue;
}
const dependenciesToConsider =
getInconsistentDependenciesAndDevDependencies(
dependencyIdent,
dependenciesByRange,
);
const dependencyRanges = [...dependenciesToConsider.keys()].sort();
for (const dependencies of dependenciesToConsider.values()) {
for (const dependency of dependencies) {
dependency.error(
`Expected version range for ${dependencyIdent} (in ${
dependency.type
}) to be consistent across monorepo. Pick one: ${inspect(
dependencyRanges,
)}`,
);
}
}
}
Expand Down
Loading