Commit 8294febf 8294febfbbbd606fc26d41d464b527488d277a67 by Laurent Jouanneau

Bootstrap.js: specific support of patchRequire for SlimerJS

SlimerJS provides an API to indicate paths where modules
can be found: require.paths (CommonJS specification).
So patchRequire is not needed for SlimerJS.
1 parent 812461f9
......@@ -171,6 +171,8 @@ CasperError.prototype = Object.getPrototypeOf(new Error());
*
* var require = patchRequire(require);
* var utils = require('utils');
*
* Useless for SlimerJS
*/
function patchRequire(require) {
if (require.patched) {
......@@ -290,10 +292,22 @@ 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
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;}
}
else {
// patch require
global.__require = require;
global.patchRequire = patchRequire; // must be called in every casperjs module as of 1.1
global.require = patchRequire(global.require);
}
// casper cli args
phantom.casperArgs = require('cli').parse(phantomArgs);
......@@ -302,6 +316,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);
}
// casper loading status flag
phantom.casperLoaded = true;
......