Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: require(<module>[, <version>]) + npm: put version in module install path #4744

Closed
blitmap opened this issue Jan 18, 2016 · 2 comments

Comments

@blitmap
Copy link

blitmap commented Jan 18, 2016

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. Add a 2nd parameter to require(<module>, <version>) for requesting a specific semantic version
  • 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?
  1. Install modules with their version in the path: node_modules/moment/1.4.8/index.js

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 break. 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.

Side-concern: npm ls --depth=0 would show all dependencies - not just your 'primary' dependencies. Some scripts might rely on this.


PS: I realize the 2 is npm-related, not node-related. I'm proposing this with the full text in both projects for completeness/coherency.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 18, 2016

Thanks for opening this issue. However, would you mind moving it to https://github.com/nodejs/ng?

@cjihrig cjihrig closed this as completed Jan 18, 2016
@blitmap
Copy link
Author

blitmap commented Jan 18, 2016

My mistake - will do 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants