Commit f20b9eb2 f20b9eb23bfea0465d3d513c6cc0a882222e005d by Ludovic Perrine

Search node_modules in parent directories until the root is reached (fixes #956)

1 parent b62c37d9
...@@ -248,7 +248,14 @@ CasperError.prototype = Object.getPrototypeOf(new Error()); ...@@ -248,7 +248,14 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
248 return resolveFile(path, fs.pathJoin(phantom.casperPath, 'modules')); 248 return resolveFile(path, fs.pathJoin(phantom.casperPath, 'modules'));
249 } 249 }
250 function nodeModulePath(path) { 250 function nodeModulePath(path) {
251 return resolveFile(path, fs.pathJoin(getCurrentScriptRoot(), 'node_modules')); 251 var resolved, prevBaseDir;
252 var baseDir = getCurrentScriptRoot();
253 do {
254 resolved = resolveFile(path, fs.pathJoin(baseDir, 'node_modules'));
255 prevBaseDir = baseDir;
256 baseDir = fs.absolute(fs.pathJoin(prevBaseDir, '..'));
257 } while (!resolved && baseDir !== '/' && baseDir !== prevBaseDir);
258 return resolved;
252 } 259 }
253 function localModulePath(path) { 260 function localModulePath(path) {
254 return resolveFile(path, phantom.casperScriptBaseDir || fs.workingDirectory); 261 return resolveFile(path, phantom.casperScriptBaseDir || fs.workingDirectory);
......