Subsecciones
- If X is a core module,
- return the core module
- STOP
- If X begins with './' or '/' or '../'
LOAD_AS_FILE(Y + X)
LOAD_AS_DIRECTORY(Y + X)
LOAD_NODE_MODULES(X, dirname(Y))
- THROW "not found"
- If X is a file, load X as JavaScript text. STOP
- If X.js is a file, load X.js as JavaScript text. STOP
- If X.node is a file, load X.node as binary addon. STOP
- If X/package.json is a file,
a. Parse X/package.json, and look for "main" field.
b. let M = X + (json main field)
c.
LOAD_AS_FILE(M)
- If X/index.js is a file, load X/index.js as JavaScript text. STOP
- If X/index.node is a file, load X/index.node as binary addon. STOP
- let
DIRS=NODE_MODULES_PATHS(START)
- for each DIR in DIRS:
a.
LOAD_AS_FILE(DIR/X)
b. LOAD_AS_DIRECTORY(DIR/X)
- let PARTS = path split(START)
- let ROOT = index of first instance of "node_modules" in PARTS, or 0
- let I = count of PARTS - 1
- let DIRS = []
- while I > ROOT,
a. if PARTS[I] = "node_modules" CONTINUE
c. DIR = path join(PARTS[0 .. I] + "node_modules")
b. DIRS = DIRS + DIR
c. let I = I - 1
- return DIRS
Casiano Rodriguez León
2015-01-07