Yarn Plug’n’Play

The way that Node.js installs and handles dependencies has been messy since the start. Today a PR by arcanis hopes to change the way that dependencies are installed and the way that node interacts with them.

The gist of the change from what I understand so far is this feature will A) cache all installed modules on the disk and while doing so create a table of where those modules exist, and b) inject a overrides of Module._load .

If loaded as a preloaded module (node -r ./.pnp.js), it will inject it- self into the Node environment and will transparently cause the require function to load files directly from the right location. The current implementation overrides Module._load, but Node 10 recently released a new API that we plan to use to register into the resolver.

That’s it.

With this comes a couple of issues when it comes to postinstall scripts and build processes in general. This generally slows down dependency installs and is a big bottleneck for installs. One of the proposed solutions here is WebAssembly.

On the long term we believe that post-install scripts are a problem by themselves (they still need an install step, and can lead to security issues), and we would suggest relying less on this feature in the future, possibly even deprecating it in the long term. While native modules have their usefulness, WebAssembly is becoming a more and more serious candidate for a portable bytecode as the months pass.

On the whole this doesn’t change much. This idea plays off of the notion that there should only be one version of a module installed on your machine at a time, an idea that pnp.js has been propagating.

I’m excited about this idea, and I think that this is a big step in the right direction when it comes to innovating how dependencies are installed and managed. Interested in how this is going to aid in helping deno, by simplifying how modules are handled.