Skip to content

Commit 70c3fcd

Browse files
committed
refactor: Extract loadNodesFromDir() from NodesPool for reuse
Move node-loading and filtering logic into a public loadNodesFromDir(dir) method so extensions can load nodes from additional directories without duplicating DISABLED_NODES, skipCategories, and community node checks.
1 parent 0167e3a commit 70c3fcd

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

packages/server/src/NodesPool.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ export class NodesPool {
2424
* Initialize nodes
2525
*/
2626
private async initializeNodes() {
27-
const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : []
2827
const packagePath = getNodeModulesPackagePath('flowise-components')
2928
const nodesPath = path.join(packagePath, 'dist', 'nodes')
30-
const nodeFiles = await this.getFiles(nodesPath)
31-
return Promise.all(
29+
const nodes = await this.loadNodesFromDir(nodesPath)
30+
Object.assign(this.componentNodes, nodes)
31+
}
32+
33+
/**
34+
* Load and filter nodes from a directory.
35+
* Applies DISABLED_NODES, skipCategories, and community node checks.
36+
* Used internally for flowise-components nodes and externally by
37+
* extension pools (e.g. EnterpriseNodesPool) to load additional nodes.
38+
*/
39+
async loadNodesFromDir(dir: string): Promise<IComponentNodes> {
40+
const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : []
41+
const nodes: IComponentNodes = {}
42+
const nodeFiles = await this.getFiles(dir)
43+
await Promise.all(
3244
nodeFiles.map(async (file) => {
3345
if (file.endsWith('.js')) {
3446
try {
@@ -69,7 +81,7 @@ export class NodesPool {
6981
const isDisabled = disabled_nodes.includes(newNodeInstance.name)
7082

7183
if (conditionOne && conditionTwo && !isDisabled) {
72-
this.componentNodes[newNodeInstance.name] = newNodeInstance
84+
nodes[newNodeInstance.name] = newNodeInstance
7385
}
7486
}
7587
} catch (err) {
@@ -78,6 +90,7 @@ export class NodesPool {
7890
}
7991
})
8092
)
93+
return nodes
8194
}
8295

8396
/**

0 commit comments

Comments
 (0)