Skip to content

Commit d8da27c

Browse files
authored
refactor: Extract loadNodesFromDir() from NodesPool for reuse (#5904)
Move node-loading and filtering logic into a public loadNodesFromDir(dir) method so extensions can load nodes from additional directories
1 parent 5294592 commit d8da27c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

packages/server/src/NodesPool.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@ 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+
*/
36+
async loadNodesFromDir(dir: string): Promise<IComponentNodes> {
37+
const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : []
38+
const nodes: IComponentNodes = {}
39+
const nodeFiles = await this.getFiles(dir)
40+
await Promise.all(
3241
nodeFiles.map(async (file) => {
3342
if (file.endsWith('.js')) {
3443
try {
@@ -69,7 +78,7 @@ export class NodesPool {
6978
const isDisabled = disabled_nodes.includes(newNodeInstance.name)
7079

7180
if (conditionOne && conditionTwo && !isDisabled) {
72-
this.componentNodes[newNodeInstance.name] = newNodeInstance
81+
nodes[newNodeInstance.name] = newNodeInstance
7382
}
7483
}
7584
} catch (err) {
@@ -78,6 +87,7 @@ export class NodesPool {
7887
}
7988
})
8089
)
90+
return nodes
8191
}
8292

8393
/**

0 commit comments

Comments
 (0)