123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- const loader = require('./loader');
- const Module = require('module');
- function isNativeModule(targetPath, parentModule) {
- const lookupPaths = Module._resolveLookupPaths(targetPath, parentModule, true);
-
- return lookupPaths === null ||
- (lookupPaths.length === 2 &&
- lookupPaths[1].length === 0 &&
- lookupPaths[0] === targetPath);
- }
- class Requizzle {
- constructor(options, cache) {
- this._options = options;
- this._cache = cache || {
- module: {},
- source: {}
- };
- }
-
- requizzle(targetPath) {
- const options = this._options;
- const parentModule = options.parent;
- let targetModule;
- let wrapper;
-
- if (isNativeModule(targetPath, parentModule)) {
- return require(targetPath);
- }
-
- targetPath = Module._resolveFilename(targetPath, parentModule);
- wrapper = loader.createWrapper(targetPath, parentModule, this._cache, this._options);
- targetModule = loader.load(targetPath, parentModule, wrapper, this._cache, this._options);
- return targetModule.exports;
- }
- }
- module.exports = Requizzle;
|