fix: extension auto-load crashes directus if local extension is removed (#20259)

This commit is contained in:
daedalus
2023-10-31 21:19:19 -04:00
committed by GitHub
parent ca85e15003
commit 3a4abb10cb
2 changed files with 12 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'@directus/api': patch
---
Fixed an issue where removing a local extension with autoload true resulted in a crash.

View File

@@ -1,7 +1,13 @@
import { createRequire } from 'node:module';
import logger from '../logger.js';
const require = createRequire(import.meta.url);
export function deleteFromRequireCache(modulePath: string): void {
delete require.cache[require.resolve(modulePath)];
try {
const moduleCachePath = require.resolve(modulePath);
delete require.cache[moduleCachePath];
} catch (error) {
logger.trace(`Module cache not found for ${modulePath}, skipped cache delete.`);
}
}