This fixes the following issues: * After a community node is installed, we were not calling `postProcessLoaders`, which was causing a bunch of unexpected behaviors, and sometimes even crashes. This was only happening in the session where the package was installed. After a crash, the restarted service was working without these issues. * After a community node is installed, the icon for the nodes and credentials were missing in the UI, as we were creating one icons route per installed package at startup, and this did not handle newly installed packages. restarting the service fixes this issue as well. Fixes https://community.n8n.io/t/showing-weird-count-on-community-nodes/23035
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import path from 'path';
|
|
import { realpath, access } from 'fs/promises';
|
|
|
|
import type { LoadNodesAndCredentialsClass } from '@/LoadNodesAndCredentials';
|
|
import type { NodeTypesClass } from '@/NodeTypes';
|
|
import type { Push } from '@/push';
|
|
|
|
export const reloadNodesAndCredentials = async (
|
|
loadNodesAndCredentials: LoadNodesAndCredentialsClass,
|
|
nodeTypes: NodeTypesClass,
|
|
push: Push,
|
|
) => {
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
const { default: debounce } = await import('lodash.debounce');
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
const { watch } = await import('chokidar');
|
|
|
|
Object.values(loadNodesAndCredentials.loaders).forEach(async (loader) => {
|
|
try {
|
|
await access(loader.directory);
|
|
} catch {
|
|
// If directory doesn't exist, there is nothing to watch
|
|
return;
|
|
}
|
|
|
|
const realModulePath = path.join(await 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 loadNodesAndCredentials.postProcessLoaders();
|
|
await loadNodesAndCredentials.generateTypesForFrontend();
|
|
nodeTypes.applySpecialNodeParameters();
|
|
push.send('nodeDescriptionUpdated', undefined);
|
|
}, 100);
|
|
|
|
const toWatch = loader.isLazyLoaded
|
|
? ['**/nodes.json', '**/credentials.json']
|
|
: ['**/*.js', '**/*.json'];
|
|
watch(toWatch, { cwd: realModulePath }).on('change', reloader);
|
|
});
|
|
};
|