-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmoduse.js
More file actions
25 lines (23 loc) · 728 Bytes
/
moduse.js
File metadata and controls
25 lines (23 loc) · 728 Bytes
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
const moduleName = process.env.AID_MODULE
const Module = require('module')
const { cleanLoadStack } = require('./lib/cleanStack')
const { printMessage } = require('./lib/print')
if (!moduleName) {
printMessage('You need to set this env variable: AID_MODULE=somenameorpath ')
}
let localCache
Object.defineProperty(Module._cache, moduleName, {
configurable: false,
get () {
const e = {}
Error.stackTraceLimit = Infinity
Error.captureStackTrace(e)
const loadStack = cleanLoadStack(e.stack)
printMessage(`module cache hit for '${moduleName}' ${loadStack.join('\n')}`)
return localCache
},
set (newValue) {
printMessage(`cache populated for '${moduleName}'`)
localCache = newValue
}
})