← All writing

Make the build prove what it loaded.

Same bytes, different modeTwo file specimens have matching bytes. One has the expected executable mode, the other does not. With the other checks satisfied, only the first may cross the loading boundary.File mode+xExecutable−xBit removedSame bytes+xRequiredResolverMay loadRefused
Same bytes, different modeA 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

rules_js and Yarn Plug'n'Play Infrastructure

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.One file specimen is attached to five numbered checks: content, type, mode, path and membership.123451 · Content2 · Type3 · Mode4 · Path5 · MembershipMatching inputSame bytes, different modeRefusedVerify before the resolver loads
Relationships meet exact inputs.

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

One file specimen is attached to five numbered checks: content, type, mode, path and membership.

Diagram key
Ring 1Content
The file's actual contents.
Ring 2Type
What kind of file entry it is.
Ring 3Mode
The file's permissions.
Ring 4Path
Its canonical location.
Ring 5Membership
Which files belong in the input.

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.The five numbered inspection rings spread into a cutaway around the same file specimen before loading.123451 · Content2 · Type3 · Mode4 · Path5 · MembershipMatching inputSame bytes, different modeRefusedVerify before the resolver loads
Identity is more than a filename.

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

The five numbered inspection rings spread into a cutaway around the same file specimen before loading.

Diagram key
Ring 1Content
The file's actual contents.
Ring 2Type
What kind of file entry it is.
Ring 3Mode
The file's permissions.
Ring 4Path
Its canonical location.
Ring 5Membership
Which files belong in the input.

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, on LinkedIn, opens in a new tab: 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.The five numbered checks align around the matching specimen. A changed specimen remains outside the verification boundary.123451 · Content2 · Type3 · Mode4 · Path5 · MembershipMatching inputSame bytes, different modeRefusedVerify before the resolver loads
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 bytesDifferent 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.

The five numbered checks align around the matching specimen. A changed specimen remains outside the verification boundary.

Diagram key
Upper-left card and connectorMatching input
The illustration shows an input that meets all five checks.
Five aligned ringsVerification boundary
Content, type, mode, path and membership must match.
Lower-right card and barrierChanged input
The illustration keeps the changed input outside.

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.