3 ms·
> NPM's approach to 'dependencies of dependencies' has a lot of fans. NPM's approach works for Javascript because package A importing libfoo-1.0 and package B
by derefr 11y ago
> NPM's approach to 'dependencies of dependencies' has a lot of fans.
NPM's approach works for Javascript because package A importing libfoo-1.0 and package B importing libfoo-2.3.11 doesn't cause any sort of global namespace collision for "Foo" within the JS runtime; each Foo is just a property of the object returned by require().
This isn't true of most other platforms; you can't e.g. import two versions of a Ruby library into the same Ruby runtime. (You can import two versions of an Erlang module into the same BEAM VM, but the second one will be treated as a code upgrade for the first. Processes that don't do a full-qualified tail-call will stay on the "old" version, though, so both versions can be loaded in parallel. There's still only one global "module table", though.)
On the other hand, the "packages get their own scratch namespaces which their dependencies can be exposed into" is true of Unix (or rather, can be made true by clever use of symlinks/chroots/etc.), which is why Nix can do what it does.
- awinter-py 11y agoSolid point -- the py import system uses global sys.modules, so npm-style nested deps couldn't happen on a vanilla python. That said, it's not impossible to hack the import command to use a different package tree per module. The main difficulty would be supporting the different ways of storing modules (eggs, filesystem, .so support).