Skip to content

Commit 268214f

Browse files
authored
chore: add sha256 hash to packageManager field (#325)
<!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? Are there any issues or other links reviewers should consult to understand this pull request better? For instance: * Fixes #12345 * See: #67890 --> The root `package.json` previously set `packageManager` to `yarn@4.16.0` with no integrity hash. Corepack supports an optional `+sha256.<hash>` suffix that pins the Yarn binary to a known checksum, ensuring that anyone running `corepack` against this repo gets the exact same Yarn binary that was vetted. This PR adds the sha256 hash to the `packageManager` field. A new `expectYarnPackageManager` constraint asserts that `packageManager` starts with `yarn@` and includes a sha256 hash, so the hash can evolve when Yarn is bumped without requiring a constraint change at the same time. ## Examples See `MetaMask/core#9122` for the equivalent change in the `core` monorepo.
1 parent 113f33b commit 268214f

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"engines": {
8888
"node": "^20 || ^22 || >=24"
8989
},
90-
"packageManager": "yarn@4.16.0",
90+
"packageManager": "yarn@4.16.0+sha256.ba05224324578801b9cc98170d64aa50b9a36733b440fb0942306da3fbbdc7d1",
9191
"lavamoat": {
9292
"allowScripts": {
9393
"@lavamoat/preinstall-always-fail": false,

yarn.config.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,29 @@ function expectExports(workspace) {
222222
});
223223
}
224224

225+
/**
226+
* Expect that the workspace has a package manager set, and that it is Yarn with
227+
* a sha256 hash.
228+
*
229+
* @param {Workspace} workspace - The workspace to check.
230+
*/
231+
function expectYarnPackageManager(workspace) {
232+
expectWorkspaceField(workspace, 'packageManager');
233+
234+
const { packageManager } = workspace.manifest;
235+
if (!packageManager.startsWith('yarn@')) {
236+
workspace.error(
237+
`Expected packageManager to start with "yarn@<version>", but got "${packageManager}".`,
238+
);
239+
}
240+
241+
if (!packageManager.includes('sha256')) {
242+
workspace.error(
243+
`Expected packageManager to include a sha256 hash, but got "${packageManager}".`,
244+
);
245+
}
246+
}
247+
225248
module.exports = defineConfig({
226249
/**
227250
* Define the constraints for this project.
@@ -263,6 +286,9 @@ module.exports = defineConfig({
263286
// The package must specify the expected minimum Node versions
264287
workspace.set('engines.node', '^20 || ^22 || >=24');
265288

289+
// The package must specify Yarn as the package manager, with a sha256 hash.
290+
expectYarnPackageManager(workspace);
291+
266292
// The package must provide the location of the CommonJS-compatible
267293
// entrypoint and its matching type declaration file.
268294
workspace.set('main', './dist/index.cjs');

0 commit comments

Comments
 (0)