Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Search NODE_PATH properly

  • Loading branch information...
commit a05fa53de7087b66005dddfa124d9da6e527b13c 1 parent 60a2bda
@marcuswestin authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/util.js
View
9 lib/util.js
@@ -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
}
Please sign in to comment.
Something went wrong with that request. Please try again.