This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
modules.js
57 lines (45 loc) · 1.54 KB
/
modules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var path = require('path')
, resolve = require('./resolve')
, loading = require('./loading')
, assert = require('assert')
var registerExtension = function(){console.log('require.registerExtension() removed. Use require.extensions instead');}
exports.resolveModuleFilename = resolve.resolveModuleFilename
exports.useCache = useCache
function useCache(moduleCache) {
var newExports = {}
for (i in exports){
newExports[i] = exports[i]
}
newExports.loadModule = function (request,parent,make) {
return loading.loadModule(request,parent,make,moduleCache)
}
newExports.defaultLoad = function (id,filename,parent,make) {
return loading.defaultLoad(id,filename,parent,make,moduleCache)
}
newExports.mamake = function (resolve,load,make){
return loading.mamake (resolve,load,make,moduleCache)
}
newExports.makeRequire = function (module,tools){
return loading.makeRequire(module,initTools(tools))
}
newExports.makeMake = function (tools){
return loading.makeMake(initTools(tools))
}
function initTools(tools){
tools = tools || {}
tools.cache = tools.cache || moduleCache
return tools
}
newExports.uncache = function (module) {
delete moduleCache[module.filename]
}
newExports.moduleCache = moduleCache
newExports.makeWrapRequire = makeWrapRequire
function makeWrapRequire (wrap){//adapter to use old interface...
return function (this_module){
return wrap(newExports.makeRequire(this_module),this_module)
}
}
return newExports;
}
module.exports = useCache({})