Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes <johannes.ewald@roomieplanet.de>2012-08-18 18:34:13 +0400
committerJohannes <johannes.ewald@roomieplanet.de>2012-08-18 18:34:13 +0400
commitc5d8fab07f0edc568e45e0747f863afd5876abc2 (patch)
treeab57b94703d16087fbb6c81e4bdb5d1ae6217d19 /lib/index.js
parent657b9e84018014d15916c86274b8ee35b9386627 (diff)
- Introduced webpack bundler for rewire (work in progress, some tests are not running)
Diffstat (limited to 'lib/index.js')
-rw-r--r--lib/index.js57
1 files changed, 24 insertions, 33 deletions
diff --git a/lib/index.js b/lib/index.js
index 491599a..4105917 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,33 +1,24 @@
-var rewireModule;
-
-/**
- * Adds a special setter and getter to the module located at filename. After the module has been rewired, you can
- * call myModule.__set__(name, value) and myModule.__get__(name) to manipulate private variables.
- *
- * @param {!String} filename Path to the module that shall be rewired. Use it exactly like require().
- * @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
- */
-function rewire(filename, cache) {
- if (cache === undefined) {
- cache = true;
- }
-
- return rewireModule(module.parent, filename, cache);
-}
-
-// Conditional require for different environments
-if (process.title === "browser") {
- module.exports = require("./browserify/browserifyRewire.js");
-} else {
- delete require.cache[__filename]; // deleting self from module cache so the parent module is always up to date
-
- // Putting (require) within brackets is a hack to disable browserify's require sniffing
- // @see https://github.com/substack/node-browserify/issues/132#issuecomment-5281470
- rewireModule = (require)("./internalRewire.js");
-
- rewire.reset = rewireModule.reset;
- rewire.browserify = (require)("./browserify/browserifyMiddleware.js");
-
- module.exports = rewire;
-}
+var rewireModule = require("./internalRewire.js");
+
+/**
+ * Adds a special setter and getter to the module located at filename. After the module has been rewired, you can
+ * call myModule.__set__(name, value) and myModule.__get__(name) to manipulate private variables.
+ *
+ * @param {!String} filename Path to the module that shall be rewired. Use it exactly like require().
+ * @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
+ */
+function rewire(filename, cache) {
+ if (cache === undefined) {
+ cache = true;
+ }
+
+ return rewireModule(module.parent, filename, cache);
+}
+
+rewire.reset = rewireModule.reset;
+rewire.browserify = require("./bundlers/browserify/browserifyMiddleware.js");
+
+module.exports = rewire;
+
+delete require.cache[__filename]; // deleting self from module cache so the parent module is always up to date \ No newline at end of file