2019-07-10 10:45:49 +00:00
|
|
|
export function clearRequireCache (id) {
|
2019-04-11 10:04:21 +00:00
|
|
|
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)
|
2019-04-11 10:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const child of entry.children) {
|
|
|
|
clearRequireCache(child.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
delete require.cache[id]
|
|
|
|
}
|
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
export function scanRequireTree (id, files = new Set()) {
|
2019-04-11 10:04:21 +00:00
|
|
|
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
|
|
|
|
}
|
2019-09-26 12:10:54 +00:00
|
|
|
|
|
|
|
export function tryRequire (id) {
|
|
|
|
try {
|
|
|
|
return require(id)
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPKG (id) {
|
|
|
|
return tryRequire(id + '/package.json')
|
|
|
|
}
|