"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable */
function purgeCache(moduleName) {
    // 遍历缓存来找到通过指定模块名载入的文件
    this.searchCache(moduleName, (mod) => {
        delete require.cache[mod.id];
        console.log('purge cache success', moduleName);
    });
    // 删除模块缓存的路径
    // 多谢@bentael指出这点
    Object.keys(module.constructor._pathCache).forEach((cacheKey) => {
        if (cacheKey.indexOf(moduleName) > 0) {
            delete module.constructor._pathCache[cacheKey];
        }
    });
}
exports.purgeCache = purgeCache;
/**
* 遍历缓存来查找通过特定模块名缓存下的模块
*/
function searchCache(moduleName, callback) {
    //  通过指定的名字resolve模块
    try {
        let mod = require.resolve(moduleName);
        // 检查该模块在缓存中是否被resolved并且被发现
        if (mod && ((mod = require.cache[mod]) !== undefined)) {
            // 递归的检查结果
            (function traverse(mod) {
                // 检查该模块的子模块并遍历它们
                mod.children.forEach((child) => {
                    traverse(child);
                });
                // 调用指定的callback方法，并将缓存的module当做参数传入
                callback(mod);
            }(mod));
        }
    }
    catch (err) {
        console.log('search cache error', moduleName);
    }
}
exports.searchCache = searchCache;
//# sourceMappingURL=require.js.map