@fesjs/utils
Version:
27 lines (24 loc) • 953 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
exports.isWindows = void 0;
const isWindows = exports.isWindows = typeof process !== 'undefined' && process.platform === 'win32';
// 暂时无法使用 jest 进行单元测试,原因可参见
// https://github.com/facebook/jest/issues/5741
function _default(cacheKey) {
// windows 下 require.cache 中路径 key 为类似 ‘c:\demo\.umirc.ts’
const cachePath = isWindows ? cacheKey.replace(/\//g, '\\') : cacheKey;
if (require.cache[cachePath]) {
const cacheParent = require.cache[cachePath].parent;
let i = (cacheParent === null || cacheParent === void 0 ? void 0 : cacheParent.children.length) || 0;
// 清理 require cache 中 parents 的引用
while (i--) {
if (cacheParent.children[i].id === cachePath) {
cacheParent.children.splice(i, 1);
}
}
delete require.cache[cachePath];
}
}