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

Npm.require submodule for packages loaded with Npm.depend() #3526

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions tools/server/boot.js
Expand Up @@ -129,10 +129,11 @@ Fiber(function () {
return require(name);
}

var nodeModuleDir =
path.resolve(serverDir, fileInfo.node_modules, name);
var nodeModuleBase = path.resolve(serverDir, fileInfo.node_modules);

if (fs.existsSync(nodeModuleDir)) {
var nodeModuleDir = path.resolve(nodeModuleBase, name);

if (fs.existsSync(path.resolve(nodeModuleBase, name.split("/")[0]))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong? Why are we only looking at the first part of name.split("/")? And what if name has no slash in it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think this looks like it could be right. Isn't the point that Npm.require("foo/bar") should be resolved by saying "if this package uses foo, then we should be trying to resolve "foo/bar" as within this module's foo"?

Node require has a bunch of different options; for example, require('foo/bar') can pull in a file that's called bar.js inside the foo package. Or that's called bar/index.js inside foo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If name has no slash then name.split('/')[0] === name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I now understand. Agreed.

return require(nodeModuleDir);
}
try {
Expand Down