mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 19:04:48 +00:00
35 lines
699 B
JavaScript
35 lines
699 B
JavaScript
|
export function clearRequireCache(id) {
|
||
|
const entry = require.cache[id]
|
||
|
if (!entry || id.includes('node_modules')) {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if (entry.parent) {
|
||
|
const i = entry.parent.children.findIndex(e => e.id === id)
|
||
|
if (i > -1) {
|
||
|
entry.parent.children.splice(i, 1)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (const child of entry.children) {
|
||
|
clearRequireCache(child.id)
|
||
|
}
|
||
|
|
||
|
delete require.cache[id]
|
||
|
}
|
||
|
|
||
|
export function scanRequireTree(id, files = new Set()) {
|
||
|
const entry = require.cache[id]
|
||
|
if (!entry || id.includes('node_modules') || files.has(id)) {
|
||
|
return files
|
||
|
}
|
||
|
|
||
|
files.add(entry.id)
|
||
|
|
||
|
for (const child of entry.children) {
|
||
|
scanRequireTree(child.id, files)
|
||
|
}
|
||
|
|
||
|
return files
|
||
|
}
|