mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
22 lines
808 B
JavaScript
22 lines
808 B
JavaScript
export const isWindows = typeof process !== 'undefined' && process.platform === 'win32';
|
||
|
||
// 暂时无法使用 jest 进行单元测试,原因可参见
|
||
// https://github.com/facebook/jest/issues/5741
|
||
|
||
export default function (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?.children.length || 0;
|
||
// 清理 require cache 中 parents 的引用
|
||
while (i--) {
|
||
if (cacheParent.children[i].id === cachePath) {
|
||
cacheParent.children.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
delete require.cache[cachePath];
|
||
}
|
||
}
|