Skip to content

Commit a02f7a4

Browse files
rekmarksclaude
andcommitted
fix: prevent non-private packages from having private workspace production deps
Add a yarn constraint that errors when a published (`@metamask/`) package lists a private (`@ocap/`) workspace package in production dependencies (`dependencies` or `peerDependencies`) via the `workspace:` protocol. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3f04211 commit a02f7a4

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

yarn.config.cjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ module.exports = defineConfig({
169169
// All non-root package must have valid "changelog:update" and
170170
// "changelog:validate" scripts.
171171
expectCorrectWorkspaceChangelogScripts(workspace);
172+
173+
// Non-private packages must not have production dependencies on private workspace packages.
174+
expectNoPrivateWorkspaceProductionDependencies(Yarn, workspace);
172175
}
173176

174177
// Non-published packages must not specify the following keys except from the ones that are exempted
@@ -827,6 +830,36 @@ function expectConsistentDependenciesAndDevDependencies(Yarn) {
827830
}
828831
}
829832

833+
/**
834+
* Expect that non-private workspace packages do not have production
835+
* dependencies (anything except `devDependencies`) using the `workspace:`
836+
* protocol that resolve to private packages.
837+
*
838+
* @param {Yarn} Yarn - The Yarn "global".
839+
* @param {Workspace} workspace - The workspace to check.
840+
*/
841+
function expectNoPrivateWorkspaceProductionDependencies(Yarn, workspace) {
842+
for (const dependency of Yarn.dependencies({ workspace })) {
843+
if (dependency.type === 'devDependencies') {
844+
continue;
845+
}
846+
847+
if (!dependency.range.startsWith('workspace:')) {
848+
continue;
849+
}
850+
851+
const dependencyWorkspace = Yarn.workspace({ ident: dependency.ident });
852+
if (
853+
dependencyWorkspace !== null &&
854+
dependencyWorkspace.manifest.private === true
855+
) {
856+
dependency.error(
857+
`Non-private package "${workspace.manifest.name}" must not depend on private package "${dependency.ident}" in "${dependency.type}"`,
858+
);
859+
}
860+
}
861+
}
862+
830863
/**
831864
* Expect that the workspace has a README.md file, and that it is a non-empty
832865
* string. The README.md is expected to:

0 commit comments

Comments
 (0)