Permalink
Browse files

make the compiler respect the NODE_PATH environment variable

  • Loading branch information...
1 parent a05fa53 commit 5f1ec2cfe856b505c38fdaa655cef4cdf41242d2 @marcuswestin committed Jan 17, 2013
Showing with 3 additions and 4 deletions.
  1. +3 −4 compiler.js
View
@@ -109,8 +109,8 @@ var _minifyRequireStatements = function(code, modules) {
return code
}
+var _nodePaths = process.env.NODE_PATH.split(':')
var _pathnameGroupingRegex = /require\s*\(['"]([\w\/\.-]*)['"]\)/
-
var _replaceRequireStatements = function(modulePath, code, modules, pathBase) {
var requireStatements = util.getRequireStatements(code)
@@ -120,8 +120,7 @@ var _replaceRequireStatements = function(modulePath, code, modules, pathBase) {
}
for (var i=0, requireStatement; requireStatement = requireStatements[i]; i++) {
- var rawModulePath = requireStatement.match(_pathnameGroupingRegex)[1],
- subModulePath = util.resolve(rawModulePath, pathBase).replace(/\.js$/, '')
+ var subModulePath = util.resolveRequireStatement(requireStatement, modulePath)
if (!subModulePath) {
throw new Error("Require Compiler Error: Cannot find module '"+ rawModulePath +"' (in '"+ modulePath +"')")
@@ -132,7 +131,7 @@ var _replaceRequireStatements = function(modulePath, code, modules, pathBase) {
if (!modules[subModulePath]) {
modules[subModulePath] = true
var newPathBase = path.dirname(subModulePath),
- newModuleCode = util.getCode(subModulePath + '.js')
+ newModuleCode = util.getCode(subModulePath)
_replaceRequireStatements(subModulePath, newModuleCode, modules, newPathBase)
modules.push(subModulePath)
}

0 comments on commit 5f1ec2c

Please sign in to comment.