Nuxt/packages/utils/src/cjs.js

32 lines
645 B
JavaScript
Raw Normal View History

export function clearRequireCache(id) {
const entry = require.cache[id]
if (!entry || id.includes('node_modules')) {
return
}
if (entry.parent) {
2019-04-24 16:13:59 +00:00
entry.parent.children = entry.parent.children.filter(e => e.id !== id)
}
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
}