'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
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
const stackTrace = require('./stackTrace');
const each = require('./each');
const contain = require('./contain');
 
const path = require('path');
 
exports = function(id) {
    const filePath = findPath(id);
 
    if (!filePath) return;
    const mod = require.cache[filePath];
    if (!mod) return;
 
    const visited = {};
    function run(current) {
        visited[current.id] = true;
        each(current.children, child => {
            const { filename, id } = child;
            if (path.extname(filename) !== '.node' && !visited[id]) {
                run(child);
            }
        });
        delete require.cache[current.id];
    }
    run(mod);
 
    each(module.constructor._pathCache, (val, key) => {
        if (contain(key, filePath)) delete module.constructor._pathCache[key];
    });
};
 
function findPath(id) {
    if (id[0] === '.') {
        const stack = stackTrace();
        for (const item of stack) {
            const fileName = item.getFileName();
            if (fileName !== module.filename) {
                id = path.resolve(path.dirname(fileName), id);
                break;
            }
        }
    }
 
    try {
        return require.resolve(id);
    } catch (e) {}
}
 
module.exports = exports;