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:
Diffstat (limited to 'lib/rewire.js')
-rw-r--r--lib/rewire.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/rewire.js b/lib/rewire.js
index 2a51e26..080847f 100644
--- a/lib/rewire.js
+++ b/lib/rewire.js
@@ -17,7 +17,7 @@ function restoreOriginalWrappers() {
/**
* Does actual rewiring the module. For further documentation @see index.js
*/
-function rewire(parentModule, filename, cache) {
+function rewire(parentModulePath, targetPath, cache) {
var testModule,
nodeRequire,
prepend,
@@ -37,21 +37,21 @@ function rewire(parentModule, filename, cache) {
}
// Checking params
- if (typeof filename !== "string") {
+ if (typeof targetPath !== "string") {
throw new TypeError("Filename must be a string");
}
// Resolve full filename relative to the parent module
- filename = Module._resolveFilename(filename, parentModule);
+ targetPath = Module._resolveFilename(targetPath, parentModulePath);
// Special support for older node versions that returned an array on Module._resolveFilename
// @see https://github.com/joyent/node/blob/865b077819a9271a29f982faaef99dc635b57fbc/lib/module.js#L319
- if (Array.isArray(filename)) {
- filename = filename[1];
+ if (Array.isArray(targetPath)) {
+ targetPath = targetPath[1];
}
// Create testModule as it would be created by require()
- testModule = new Module(filename, parentModule);
+ testModule = new Module(targetPath, parentModulePath);
// Patching requireProxy
nodeRequire = testModule.require;
@@ -66,7 +66,7 @@ function rewire(parentModule, filename, cache) {
// Check if the module uses the strict mode.
// If so we must ensure that "use strict"; stays at the beginning of the module.
- src = fs.readFileSync(filename, "utf8");
+ src = fs.readFileSync(targetPath, "utf8");
if (detectStrictMode(src) === true) {
prepend = ' "use strict"; ' + prepend;
}
@@ -82,8 +82,8 @@ function rewire(parentModule, filename, cache) {
// Store the rewired module in the cache when enabled
if (cache) {
- rewiredModules.push(filename); // save in private cache for .reset()
- require.cache[filename] = testModule;
+ rewiredModules.push(targetPath); // save in private cache for .reset()
+ require.cache[targetPath] = testModule;
}
// This is only necessary if nothing has been required within the module