custom-require
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -7,2 +7,3 @@ /// <reference types="node" /> | ||
require(id: string): any; | ||
getCallerModule(): NodeModule; | ||
} |
"use strict"; | ||
var Module = require("module"); | ||
var callsite = require("callsite"); | ||
var CustomRequire = (function () { | ||
@@ -9,4 +10,5 @@ function CustomRequire(callback) { | ||
CustomRequire.prototype.require = function (id) { | ||
var requiredFilename = Module._resolveFilename(id, module, false); | ||
var res = require(id); | ||
var callerModule = this.getCallerModule(); | ||
var requiredFilename = Module._resolveFilename(id, callerModule, false); | ||
var res = callerModule.require(id); | ||
var cachedModule = Module._cache[requiredFilename]; | ||
@@ -16,2 +18,13 @@ cachedModule.__addCustomRequire(this); | ||
}; | ||
CustomRequire.prototype.getCallerModule = function () { | ||
var stack = callsite(); | ||
for (var i in stack) { | ||
var filename = stack[i].getFileName(); | ||
if (filename !== module.filename) { | ||
var resolvedFile = Module._resolveFilename(filename, module, false); | ||
return Module._cache[resolvedFile]; | ||
} | ||
} | ||
throw new Error("Cannot find parent module"); | ||
}; | ||
return CustomRequire; | ||
@@ -18,0 +31,0 @@ }()); |
@@ -34,3 +34,6 @@ { | ||
}, | ||
"version": "0.0.6" | ||
"version": "0.0.7", | ||
"dependencies": { | ||
"callsite": "^1.0.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
11541
92
1
1
+ Addedcallsite@^1.0.0
+ Addedcallsite@1.0.0(transitive)