---
title: "Yarn PnP integrity in Bazel"
description: "What should a build verify before loading a dependency resolver? My Bazel and Yarn work checks the agreement between files, dependencies, and paths."
url: https://mh0pe.github.io/blog/integrity-bound-yarn-pnp-for-bazel/
author: "Madison Hope Steiner"
published: 2026-10-08
modified: 2026-10-08
---

[← All writing](https://mh0pe.github.io/blog/)

# Make the build prove what it loaded.

**Same bytes, different mode** A file can have the expected contents and still be the wrong input. Here only the executable bit changes: the second specimen no longer matches and must not load.

Bringing a project's own Yarn Plug'n'Play state into Bazel with an explicit integrity boundary.

[rules\_js: the zero-install importer design and tests](https://github.com/aspect-build/rules_js/pull/2957)

By [Madison Hope Steiner](https://mh0pe.github.io/about/)

rules\_js and Yarn Plug'n'Play Infrastructure

**In this article**

Verify inputs before loading

At a glance

Use the project's existing dependency state, verify that the pieces agree, then allow code to load.

A build system needs to know more than which dependency names a project declared. It needs to know which files those names resolve to, whether the resolver and dependency graph agree, and whether the files available at execution match the inputs the project intended.

My rules\_js contribution explores that boundary for Yarn Plug'n'Play, which resolves packages without a conventional node\_modules tree. After maintainer feedback, I moved from an exporter design to a zero-install importer: Bazel consumes the project's own checked-in state rather than asking Yarn to recreate it during the build.

## Respect the state the project already owns.

The importer does not run Yarn and does not construct a node\_modules directory. Its caller supplies the lockfile, PnP graph, resolver, configuration, integrity manifest, and the cache or unpacked files those records reference. That makes the adoption boundary visible: these are the project's inputs, not a second dependency installation.

Five numbered rings surround a file specimen. Each number identifies a different property to check: a filename alone cannot establish identity.

**Relationships meet exact inputs.**

The dependency map and the files it describes approach the same verification boundary.

**Diagram key**

**Ring 1: Content**
The file's actual contents.

**Ring 2: Type**
What kind of file entry it is.

**Ring 3: Mode**
The file's permissions.

**Ring 4: Path**
Its canonical location.

**Ring 5: Membership**
Which files belong in the input.

- [rules\_js: the zero-install importer design and tests](https://github.com/aspect-build/rules_js/pull/2957)

The resolver and lockfile tell related but different stories. One describes what a dependency request resolves to; the other records the intended package relationships. Cross-checking those relationships is important because individually valid files can still disagree with each other.

**Validity includes the relationship.**

1. Read the lockfile and graph
2. Cross-check their bindings
3. Verify the referenced files

Checking a file in isolation is different from checking that it belongs to the dependency state being executed.

## Bind more than the bytes.

The integrity manifest includes file type and executable mode as well as content hashes. Those details affect what a build can do. An executable becoming ordinary data, or a path becoming a symlink, changes the execution contract even if a filename looks familiar.

The numbered rings spread into a cutaway around the same file specimen, so each check can be inspected before loading.

**Identity is more than a filename.**

Content, type, mode, canonical path and membership all belong in the check.

**Diagram key**

**Ring 1: Content**
The file's actual contents.

**Ring 2: Type**
What kind of file entry it is.

**Ring 3: Mode**
The file's permissions.

**Ring 4: Path**
Its canonical location.

**Ring 5: Membership**
Which files belong in the input.

- [rules\_js: the zero-install importer design and tests](https://github.com/aspect-build/rules_js/pull/2957)

The verifier also checks canonical paths and exact tree membership before the resolver is loaded. This is a point where refusing an unexpected shape is more useful than guessing what the author meant. The implementation's tests exercise changed archives, mutated configuration, traversal, symlinks, and unpacked-file membership.

I made a similar argument about ASH's caches in [A content cache is a chain of evidence](https://www.linkedin.com/pulse/content-cache-chain-evidence-madison-hope-steiner-cissp-uhsxf/): a reusable entry needs its identity and the policy that allowed it, not only its contents.

## Keep the usable boundary specific.

This is an experimental public implementation with deliberate limits. The contribution records Yarn 4 runtime execution, Yarn 3 import and verification, and a CommonJS PnP boundary. Rules that require a linked node\_modules layout are a different integration shape, not something this importer silently emulates.

The rings align before loading. The matching card connects from the upper left; the changed card stays behind the thick barrier at the right.

**Match before loading.**

An illustrative matching input passes; a changed input remains outside. The article links the actual implementation and its limits.

**Same filename and bytes** ** Different file mode**

Two illustrated inputs can look identical. A different mode or unlisted member is enough to stop loading. This example does not extend the experiment beyond its supported scope.

**Diagram key**

**Upper-left card and connector: Matching input**
The illustration shows an input that meets all five checks.

**Five aligned rings: Verification boundary**
Content, type, mode, path and membership must match.

**Lower-right card and barrier: Changed input**
The illustration keeps the changed input outside.

- [The public integrity-bound PnP implementation](https://github.com/mh0pe/rules_js/tree/codex/yarn-lock-repo-cache-v2.3.7)

The design lesson I take from it is broader than the particular package manager. When two systems meet, decide which one owns the state. Then make the relationship between the inputs explicit enough to verify. That is often clearer than adding another conversion layer and hoping the resulting files remain equivalent.

**For a closer technical look**

- The public implementation includes pnp\_js\_binary, pnp\_js\_test, and pnp\_verify\_test wrappers.
- The final review distinguishes direct validation from earlier Bazel runs and does not claim the full final-head Yarn 4 Bazel gate passed.
- ESM PnP loaders and linked node\_modules layouts are outside the documented support boundary.

## What I take from it

Check that the resolver files match the declared dependencies and locations before allowing the build to load them.

## Code and further reading

- [rules\_js: the zero-install importer design and tests](https://github.com/aspect-build/rules_js/pull/2957)
- [The public integrity-bound PnP implementation](https://github.com/mh0pe/rules_js/tree/codex/yarn-lock-repo-cache-v2.3.7)

Covers work from August 2026 Posted October 8, 2026

Also on

- On DEV from Dec 10
- [Hashnode](https://mh0pe.hashnode.dev/integrity-bound-yarn-pnp-for-bazel)
- In editorial review at HackerNoon
- On daily.dev from Dec 10

- [Build systems](https://mh0pe.github.io/blog/?tag=Build%20systems#topic-infrastructure)
- [Supply-chain integrity](https://mh0pe.github.io/blog/?tag=Supply-chain%20integrity#topic-infrastructure)
- [Reproducibility](https://mh0pe.github.io/blog/?tag=Reproducibility#topic-infrastructure)

[What the Yarn importer makes possible in my rules\_js fork](https://mh0pe.github.io/capabilities/#capability-rules-js-pnp)

## Read next.

Security

### [The tools are part of the result.](https://mh0pe.github.io/blog/reproducible-security-checks/)

Why I added a pinned scanner environment to ASH, and what reproducibility can and cannot tell you.
