This is just my naive proposal but I'd like to suggest 2 things:
1) Install modules with their version in the path: node_modules/moment/1.4.8/index.js
2) Add a 2nd parameter to require(<module>, <version>) for requesting a specific semantic version
3) Potentially add requireVersion(<module>, <version>) specifically for this
require('./module') would be equivalent to: require('./module', '*')
I've never used * in package.json, does it take the latest version or the first it finds?
Note: Modules sometimes change names, so you'd see node_modules/extendr/1.4.2 and then node_modules/extendible/1.4.3. A later version with a different module name would NOT go to the same node_modules/extendr.
I believe this would make it possible to install all dependencies in the first level of node_modules and allow loading modules like slots.
My reasoning is that if you need a specific version of something it should be reflected in your source code, not just package.json.
This would be making a change to require() which is 'Locked', but because it's an optional 2nd parameter I think it's acceptable to meddle with. Previously I had thought require('./module', 'a', 'b', 'c') might pass those extra arguments to a module in arguments - but it seems not. Providing a version there would be a non-breaking change.
In the future one might want to provide arguments to modules: require('./module', 'a', 'b', 'c')
Maybe a separate function could be: requireVersion(module, version, arguments...)
Side-concern: npm ls --depth=0 would show all dependencies - not just your 'primary' dependencies. Some scripts might rely on this.
Recently npm changed to install dependencies in a 'flatter' way.
https://docs.npmjs.com/how-npm-works/npm3
This is just my naive proposal but I'd like to suggest 2 things:
1) Install modules with their version in the path:
node_modules/moment/1.4.8/index.js
2) Add a 2nd parameter torequire(<module>, <version>)
for requesting a specific semantic version 3) Potentially addrequireVersion(<module>, <version>)
specifically for thisrequire('./module')
would be equivalent to:require('./module', '*')
I've never used*
inpackage.json
, does it take the latest version or the first it finds? Note: Modules sometimes change names, so you'd seenode_modules/extendr/1.4.2
and thennode_modules/extendible/1.4.3
. A later version with a different module name would NOT go to the samenode_modules/extendr
.I believe this would make it possible to install all dependencies in the first level of
node_modules
and allow loading modules like slots.My reasoning is that if you need a specific version of something it should be reflected in your source code, not just
package.json
.This would be making a change to
require()
which is 'Locked', but because it's an optional 2nd parameter I think it's acceptable to meddle with. Previously I had thoughtrequire('./module', 'a', 'b', 'c')
might pass those extra arguments to a module inarguments
- but it seems not. Providing a version there would be a non-breaking change.In the future one might want to provide arguments to modules:
require('./module', 'a', 'b', 'c')
Maybe a separate function could be:requireVersion(module, version, arguments...)
Side-concern:
npm ls --depth=0
would show all dependencies - not just your 'primary' dependencies. Some scripts might rely on this.