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