Skip to content

Commit

Permalink
Search NODE_PATH properly
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuswestin committed Jan 16, 2013
1 parent 60a2bda commit a05fa53
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/util.js
Expand Up @@ -115,10 +115,19 @@ function _findModuleMain(absModulePath, tryFileName) {
return foundPath
}

var _nodePaths = process.env.NODE_PATH.split(':')
var _pathnameGroupingRegex = /require\s*\(['"]([\w\/\.-]*)['"]\)/
function resolveRequireStatement(requireStmnt, currentPath) {
var rawPath = requireStmnt.match(_pathnameGroupingRegex)[1],
resolvedPath = resolve(rawPath, path.dirname(currentPath))

if (!resolvedPath && rawPath[0] != '.' && rawPath[0] != '/') {
for (var i=0; i<_nodePaths.length; i++) {
resolvedPath = _findModuleMain(path.resolve(_nodePaths[i], rawPath))
if (resolvedPath) { break }
}
}

if (!resolvedPath) { throw 'Could not resolve "'+rawPath+'" in "'+currentPath+'"' }
return resolvedPath
}
Expand Down

0 comments on commit a05fa53

Please sign in to comment.