mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Unloading a community package should also unload all its files from require.cache (#16072)
This commit is contained in:
committed by
GitHub
parent
dfdc2237af
commit
8c63ca7d57
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user