-
Notifications
You must be signed in to change notification settings - Fork 286
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
NPM same logic as Node? #396
Comments
Node.js' module loading is described in the Modules API docs and the implementation in lib/module.js. Note that to find modules Node.js starts in the directory of the module that invoked |
@richardlau thank you for pointing out So |
The one in core, most likely. It takes shortcuts where it can, e.g., internalModuleStat() and internalModuleReadFile().
That's by definition the one in core. |
So NPM's reimplementation should follow core in any case, right?
If that is the case: Can Node.js expose the logic used to identify the prefix somehow like: |
Then it becomes official API and can't be changed anymore. That was expressly not my intent when I added internalModuleStat() and internalModuleReadFile(). |
@bnoordhuis I am not sure if this was clear but do not mean to say that |
What do you mean by prefix? The string 'node_modules'? That doesn't seem worthwhile, that's so set in stone it's never ever going to change. |
I am sorry: I meant the default output that you also get when calling |
Ah sorry, I see what you mean now. It kind of exists but it's scattered across lib/module.js. If npm wanted to use that, they should file an issue or pull request to make it public API. |
I just read through the NPM code and stumbled over:
find_prefix.js#L46
which basically looks-up the file-system tree to find where thenode_modules
orpackage.json
folder that should be used as root for the operation.This looks like this also needs to be done by
Node.js
in order to identify from where to load the packages.About that regard I have a few questions / problems:
The text was updated successfully, but these errors were encountered: