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

doc: include global node_modules in require.resolve description #20534

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ LOAD_AS_DIRECTORY(X)
2. LOAD_INDEX(X)

LOAD_NODE_MODULES(X, START)
1. let DIRS=NODE_MODULES_PATHS(START)
1. let DIRS = NODE_MODULES_PATHS(START)
2. for each DIR in DIRS:
a. LOAD_AS_FILE(DIR/X)
b. LOAD_AS_DIRECTORY(DIR/X)

NODE_MODULES_PATHS(START)
1. let PARTS = path split(START)
2. let I = count of PARTS - 1
3. let DIRS = []
3. let DIRS = [ GLOBAL_FOLDERS ]
Copy link
Member

Choose a reason for hiding this comment

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

The term “GLOBAL_FOLDERS” doesn’t appear to be defined anywhere; if you mean the list in line 424, could you alter that list as well to use this identical term?

Ideally, this term would also link down to that section.

Copy link
Contributor Author

@musgravejw musgravejw May 5, 2018

Choose a reason for hiding this comment

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

@ljharb What would be the best way to capture this? The main heading is regarding "loading from the global folders." Would it make sense to say Additionally, Node.js will search in the following global folders:?

Copy link
Member

Choose a reason for hiding this comment

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

Even just a sentence in the below section like “This list of GLOBAL_FOLDERS:” or something

Copy link
Member

Choose a reason for hiding this comment

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

It’d be cool if the mention in the algorithm itself could also be linked.

4. while I >= 0,
a. if PARTS[I] = "node_modules" CONTINUE
b. DIR = path join(PARTS[0 .. I] + "node_modules")
Expand Down Expand Up @@ -649,9 +649,11 @@ changes:
* `request` {string} The module path to resolve.
* `options` {Object}
* `paths` {string[]} Paths to resolve module location from. If present, these
paths are used instead of the default resolution paths. Note that each of
these paths is used as a starting point for the module resolution algorithm,
meaning that the `node_modules` hierarchy is checked from this location.
paths are used instead of the default resolution paths, with the exception
of global folders like `~/.node_modules`, which are always included. Note
that each of these paths is used as a starting point for the module
resolution algorithm, meaning that the `node_modules` hierarchy is checked
from this location.
* Returns: {string}

Use the internal `require()` machinery to look up the location of a module,
Expand Down