-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up yarn constraints and update dependencies to match rules
- Loading branch information
1 parent
bf0d931
commit 04fffc3
Showing
5 changed files
with
129 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** @type {import("@yarnpkg/types")} */ | ||
const { defineConfig } = require("@yarnpkg/types") | ||
|
||
/** | ||
* This rule will enforce that a workspace MUST depend on the same version of a dependency as the one used by the other workspaces | ||
* | ||
* @param {import("@yarnpkg/types").Yarn.Constraints.Context} context | ||
* */ | ||
const enforceConsistentDependenciesAcrossTheProject = ({ Yarn }) => { | ||
for (const dep of Yarn.dependencies()) { | ||
if (dep.type === "peerDependencies") continue | ||
for (const otherDep of Yarn.dependencies({ ident: dep.ident })) { | ||
if (otherDep.type === "peerDependencies") continue | ||
dep.update(otherDep.range) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* This rule will enfore that the :^workspace protocol will be used when referencing packages in this project | ||
* | ||
* @param {import("@yarnpkg/types").Yarn.Constraints.Context} context | ||
* */ | ||
const enforceWorkspaceDependenciesWhereAvailable = ({ Yarn }) => { | ||
for (const workspace of Yarn.workspaces()) { | ||
for (const workspacePackageDep of Yarn.dependencies({ | ||
ident: workspace.ident | ||
})) { | ||
if (workspacePackageDep.type === "peerDependencies") continue | ||
workspacePackageDep.update("workspace:^") | ||
} | ||
} | ||
} | ||
|
||
module.exports = defineConfig({ | ||
async constraints(context) { | ||
enforceConsistentDependenciesAcrossTheProject(context) | ||
enforceWorkspaceDependenciesWhereAvailable(context) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters