Commit 9b80a0e4 9b80a0e4c5b13f61ecb59d5e24fa6ffc93de20a9 by hexid

Allow usage of require.paths, while maintaining support for versions of PhantomJ…

…S that don't support it
1 parent 5c80139c
......@@ -352,22 +352,23 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
};
})(phantom.casperPath);
if ("slimer" in global) {
// for SlimerJS, use the standard API to declare directories
// where to search modules
if ("paths" in global.require) {
// declare a dummy patchRequire function
global.patchRequire = function(req) {return req;};
require.paths.push(fs.pathJoin(phantom.casperPath, 'modules'));
require.paths.push(fs.workingDirectory);
// declare a dummy patchRequire function
require.globals.patchRequire = global.patchRequire = function(req) { return req;};
require.globals.CasperError = CasperError;
phantom.casperEngine = "slimerjs";
}
else {
// patch require
} else {
global.__require = require;
global.patchRequire = patchRequire; // must be called in every casperjs module as of 1.1
global.require = patchRequire(global.require);
}
if ("slimer" in global) {
require.globals.patchRequire = global.patchRequire;
require.globals.CasperError = CasperError;
phantom.casperEngine = "slimerjs";
} else {
phantom.casperEngine = "phantomjs";
}
......@@ -378,11 +379,13 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
initCasperCli(phantom.casperArgs);
}
if ("slimer" in global && phantom.casperScriptBaseDir) {
// initCasperCli has set casperScriptBaseDir
// use it instead of fs.workingDirectory
require.paths.pop();
require.paths.push(phantom.casperScriptBaseDir);
if ("paths" in global.require) {
if ((phantom.casperScriptBaseDir || "").indexOf(fs.workingDirectory) === 0) {
require.paths.push(phantom.casperScriptBaseDir);
} else {
require.paths.push(fs.pathJoin(fs.workingDirectory, phantom.casperScriptBaseDir));
}
require.paths.push(fs.pathJoin(require.paths[require.paths.length-1], 'node_modules'));
}
// casper loading status flag
......