fix(utils): handled undefined cjs entries

[release]
This commit is contained in:
Pooya Parsa 2020-01-21 13:51:58 +01:00
parent a84f31d2a9
commit d8b84fe263

View File

@ -3,15 +3,14 @@ export function isExternalDependency (id) {
} }
export function clearRequireCache (id) { export function clearRequireCache (id) {
let entry const entry = getRequireCacheItem(id)
try {
entry = require.cache[id] if (!entry) {
} catch (e) {
delete require.cache[id] delete require.cache[id]
return return
} }
if (!entry || isExternalDependency(id)) { if (isExternalDependency(id)) {
return return
} }
@ -27,15 +26,14 @@ export function clearRequireCache (id) {
} }
export function scanRequireTree (id, files = new Set()) { export function scanRequireTree (id, files = new Set()) {
let entry const entry = getRequireCacheItem(id)
try {
entry = require.cache[id] if (!entry) {
} catch (e) {
files.add(id) files.add(id)
return files return files
} }
if (!entry || isExternalDependency(id) || files.has(id)) { if (isExternalDependency(id) || files.has(id)) {
return files return files
} }
@ -48,6 +46,13 @@ export function scanRequireTree (id, files = new Set()) {
return files return files
} }
export function getRequireCacheItem (id) {
try {
return require.cache[id]
} catch (e) {
}
}
export function tryRequire (id) { export function tryRequire (id) {
try { try {
return require(id) return require(id)