mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-27 04:12:38 -08:00
52f740b9e8
* add typedi * convert ActiveWorkflowRunner into an injectable service * convert ExternalHooks into an injectable service * convert InternalHooks into an injectable service * convert LoadNodesAndCredentials into an injectable service * convert NodeTypes and CredentialTypes into an injectable service * convert ActiveExecutions into an injectable service * convert WaitTracker into an injectable service * convert Push into an injectable service * convert ActiveWebhooks and TestWebhooks into an injectable services * handle circular references, and log errors when a circular dependency is found
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import path from 'path';
|
|
import { realpath, access } from 'fs/promises';
|
|
|
|
import type { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
|
import type { NodeTypes } from '@/NodeTypes';
|
|
import type { Push } from '@/push';
|
|
|
|
export const reloadNodesAndCredentials = async (
|
|
loadNodesAndCredentials: LoadNodesAndCredentials,
|
|
nodeTypes: NodeTypes,
|
|
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);
|
|
});
|
|
};
|