fix(core): Unloading a community package should also unload all its files from require.cache (#16072)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-06-05 21:48:19 +02:00
committed by GitHub
parent dfdc2237af
commit 8c63ca7d57
3 changed files with 39 additions and 12 deletions

View File

@@ -523,22 +523,15 @@ export class LoadNodesAndCredentials {
const push = Container.get(Push);
Object.values(this.loaders).forEach(async (loader) => {
const { directory } = loader;
try {
await fsPromises.access(loader.directory);
await fsPromises.access(directory);
} catch {
// If directory doesn't exist, there is nothing to watch
return;
}
const realModulePath = path.join(await fsPromises.realpath(loader.directory), path.sep);
const reloader = debounce(async () => {
const modulesToUnload = Object.keys(require.cache).filter((filePath) =>
filePath.startsWith(realModulePath),
);
modulesToUnload.forEach((filePath) => {
delete require.cache[filePath];
});
loader.reset();
await loader.loadAll();
await this.postProcessLoaders();
@@ -549,11 +542,11 @@ export class LoadNodesAndCredentials {
? ['**/nodes.json', '**/credentials.json']
: ['**/*.js', '**/*.json'];
const files = await glob(toWatch, {
cwd: realModulePath,
cwd: directory,
ignore: ['node_modules/**'],
});
const watcher = watch(files, {
cwd: realModulePath,
cwd: directory,
ignoreInitial: true,
});
watcher.on('add', reloader).on('change', reloader).on('unlink', reloader);