diff --git a/packages/utils/src/cjs.js b/packages/utils/src/cjs.js index 1add0c35f0..c70825b20f 100644 --- a/packages/utils/src/cjs.js +++ b/packages/utils/src/cjs.js @@ -3,6 +3,10 @@ export function isExternalDependency (id) { } export function clearRequireCache (id) { + if (isExternalDependency(id)) { + return + } + const entry = getRequireCacheItem(id) if (!entry) { @@ -10,10 +14,6 @@ export function clearRequireCache (id) { return } - if (isExternalDependency(id)) { - return - } - if (entry.parent) { entry.parent.children = entry.parent.children.filter(e => e.id !== id) } @@ -26,6 +26,10 @@ export function clearRequireCache (id) { } export function scanRequireTree (id, files = new Set()) { + if (isExternalDependency(id) || files.has(id)) { + return files + } + const entry = getRequireCacheItem(id) if (!entry) { @@ -33,10 +37,6 @@ export function scanRequireTree (id, files = new Set()) { return files } - if (isExternalDependency(id) || files.has(id)) { - return files - } - files.add(entry.id) for (const child of entry.children) {