3 ms·
I do not understand why they just didn't have a two level directory structure: node_modules/[module_name]/[version] Then it would be flat and support multiple
by bhouston 11y ago
I do not understand why they just didn't have a two level directory structure:
node_modules/[module_name]/[version]
Then it would be flat and support multiple versions of the same module in a way that is completely deterministic and also fully deduplicated.
This new system is unnecessarily complex.
- JaRail 11y agoThe file system layout is constrained by how dependency resolution works. For example, a require() call has a very (computationally) simple algorithm. I certainly agree that your suggestion simplifies file-system layouts. The tradeoff is that the complexity shifts to other parts of the system. That said, I'm not a fan of the v3 approach. I'd have preferred a central package cache with a structure similar to your suggestion. I'd add that each package in the cache should have all of its dependencies resolved in its own /node_modules/ dir with symlinks. Unfortunately, I still can't see a nice way to handle peer dependencies. Peer dependencies require the ability to walk up the file system to resolve, which you can't do with symlinks.
- DCoder 11y agoWith that approach, the module loader needs to know which version of a module to load for you when you require() something - in the general case that can't be done without parsing your package.json . This would require changes to node itself, not just npm, as well as all the external tools that implemented node's current require algorithm.