From ef04a62c5496bc3cebf178d9ac80f79a9a9f2ceb Mon Sep 17 00:00:00 2001 From: Martin P Date: Fri, 1 Jan 2016 16:15:09 +0100 Subject: [PATCH] Allow access to module cache through require.cache and require.resolve --- src/main/js/lib/require.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/js/lib/require.js b/src/main/js/lib/require.js index 4090e1d..b5bfc89 100644 --- a/src/main/js/lib/require.js +++ b/src/main/js/lib/require.js @@ -309,11 +309,18 @@ When resolving module names to file paths, ScriptCraft uses the following rules. return moduleInfo; } - function _requireClosure( parent ) { - return function requireBoundToParent( path, options ) { - var module = _require( parent, path , options); + function _requireClosure( parentFile ) { + var _boundRequire = function requireBoundToParent( path, options ) { + var module = _require( parentFile, path , options); return module.exports; }; + + _boundRequire.resolve = function resolveBoundToParent ( path ) { + return resolveModuleToFile(path, parentFile); + }; + _boundRequire.cache = _loadedModules; + + return _boundRequire; } var _loadedModules = {}; var _format = java.lang.String.format;