Comparing version 1.2.0 to 1.3.0
@@ -64,3 +64,3 @@ "use strict"; | ||
const fsRequireId = idCounter; | ||
const moduleCache = new Map(); | ||
const moduleCache = Object.create(null); | ||
function makeRequireFunction(parentModule) { | ||
@@ -93,13 +93,14 @@ const require = (modulePath) => { | ||
filePath = resolvedPath.filePath; | ||
if (moduleCache.has(filePath)) { | ||
return moduleCache.get(filePath).exports; | ||
let importedModule = moduleCache[filePath]; | ||
if (!importedModule) { | ||
importedModule = new module_1.default(filePath, parentModule); | ||
importedModule.filename = filePath; | ||
const sourceCode = mfs.readFileSync(filePath).toString(); | ||
(_b = loaders[resolvedPath.extension]) === null || _b === void 0 ? void 0 : _b.call(loaders, importedModule, sourceCode, makeRequireFunction, filePath, fsRequireId); | ||
moduleCache[filePath] = importedModule; | ||
} | ||
const newModule = new module_1.default(filePath, parentModule); | ||
newModule.filename = filePath; | ||
const sourceCode = mfs.readFileSync(filePath).toString(); | ||
(_b = loaders[resolvedPath.extension]) === null || _b === void 0 ? void 0 : _b.call(loaders, newModule, sourceCode, makeRequireFunction, filePath, fsRequireId); | ||
moduleCache.set(filePath, newModule); | ||
return newModule.exports; | ||
return importedModule.exports; | ||
}; | ||
require.id = fsRequireId; | ||
require.cache = moduleCache; | ||
return require; | ||
@@ -106,0 +107,0 @@ } |
@@ -11,5 +11,7 @@ /// <reference types="node" /> | ||
} | ||
export declare type ModuleCache = Record<string, Module>; | ||
export declare type fsRequire = { | ||
(modulePath: string): any; | ||
id: number; | ||
cache: ModuleCache; | ||
}; | ||
@@ -16,0 +18,0 @@ export declare const implicitExtensions: readonly [".js", ".json"]; |
{ | ||
"name": "fs-require", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Create a require() function from any file-system", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
12325
159