Using Yarn
The issue with the original npm package resolution algorithm was that it was created in a resilient but naïve way. This does not mean that the algorithm was simple. Rather, here, we refer to the fact that no exotic tricks or experience optimizations have been considered. Instead of trying to optimize (that is, lower) the number of packages available on the local disk, it was designed to put the packages into the same hierarchy as they were declared in. This results in a filesystem view as shown in Figure 3.1:
Figure 3.1 – Example filesystem snapshot after installing packages using npm
The naïve way of handling package installations is certainly a great way to ensure that everything is installed correctly, but not ideal in terms of performance. Looking at Figure 3.1, there may be some optimizations possible.
Let’s add some example package names and versions to Figure 3.1 to see the opportunities for optimization. In Figure...