diff options
author | Johannes <johannes.ewald@roomieplanet.de> | 2012-06-21 02:24:09 +0400 |
---|---|---|
committer | Johannes <johannes.ewald@roomieplanet.de> | 2012-06-21 02:24:09 +0400 |
commit | 0c860734dc28a679d9214ee9c5b5ff95e00eed55 (patch) | |
tree | 2b76efd42c12f331b79e61fb88ac480119d971c3 /lib/index.js | |
parent | ce972e2b1a9a43f6c19a68a5701b1b3b1bcc67f8 (diff) |
removed "use strict"; to avoid influencing not-strict modules
Diffstat (limited to 'lib/index.js')
-rw-r--r-- | lib/index.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/index.js b/lib/index.js index a6dbcd6..0960dd6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,15 +1,10 @@ -"use strict"; // run code in ES5 strict mode
-
-var rewireModule = require("./rewire.js");
+var rewireModule;
/**
* This function is needed to determine the calling parent module.
* Thus rewire acts exactly the same like require() in the test module.
*
* @param {!String} request Path to the module that shall be rewired. Use it exactly like require().
- * @param {Object} mocks An object with mocks. Keys should be the exactly same like they're required in the target module. So if you write require("../../myModules/myModuleA.js") you need to pass {"../../myModules/myModuleA.js": myModuleAMock}.
- * @param {Object} injections If you pass an object, all keys of the object will be vars within the module. You can also eval a string. Please note: All scripts are injected at the end of the module. So if there is any code in your module that is executed during require(), your injected variables will be undefined at this point. For example: passing {console: {...}} will cause all calls of console.log() to throw an exception if they're executed during require().
- * @param {Array} leaks An array with variable names that should be exported. These variables are accessible via myModule.__
* @param {Boolean} cache Indicates whether the rewired module should be cached by node so subsequent calls of require() will return the rewired module. Subsequent calls of rewire() will always overwrite the cache.
* @return {*} the rewired module
*/
@@ -23,6 +18,16 @@ function rewire(request, cache) { return rewireModule(module.parent, request, cache);
}
-rewire.reset = rewireModule.reset;
+// Conditional require for different environments
+if (process.title === "browser") {
+ module.exports = require("./browserify/browserifyRewire.js");
+} else {
+ // Putting (require) within brackets is a hack to disable browserify require sniffing
+ // @see https://github.com/substack/node-browserify/issues/132#issuecomment-5281470
+ rewireModule = (require)("./rewire.js");
+
+ rewire.reset = rewireModule.reset;
+ rewire.browserify = (require)("./browserify/browserifyMiddleware.js");
-module.exports = rewire;
\ No newline at end of file + module.exports = rewire;
+}
|