feat(core)!: Stop loading community nodes from node_modules (#6396)

All custom/community nodes should be installed in `~/.n8n/nodes`.
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-06-07 13:58:14 +02:00 committed by कारतोफ्फेलस्क्रिप्ट™
parent f024d8be5a
commit a45a2c8c41

View file

@ -66,21 +66,23 @@ export class LoadNodesAndCredentials implements INodesAndCredentials {
this.downloadFolder = UserSettings.getUserN8nFolderDownloadedNodesPath(); this.downloadFolder = UserSettings.getUserN8nFolderDownloadedNodesPath();
// Load nodes from `n8n-nodes-base` and any other `n8n-nodes-*` package in the main `node_modules` // Load nodes from `n8n-nodes-base`
const pathsToScan = [ const basePathsToScan = [
// In case "n8n" package is in same node_modules folder. // In case "n8n" package is in same node_modules folder.
path.join(CLI_DIR, '..'), path.join(CLI_DIR, '..'),
// In case "n8n" package is the root and the packages are // In case "n8n" package is the root and the packages are
// in the "node_modules" folder underneath it. // in the "node_modules" folder underneath it.
path.join(CLI_DIR, 'node_modules'), path.join(CLI_DIR, 'node_modules'),
// Path where all community nodes are installed
path.join(this.downloadFolder, 'node_modules'),
]; ];
for (const nodeModulesDir of pathsToScan) { for (const nodeModulesDir of basePathsToScan) {
await this.loadNodesFromNodeModules(nodeModulesDir); await this.loadNodesFromNodeModules(nodeModulesDir, 'n8n-nodes-base');
} }
// Load nodes from any other `n8n-nodes-*` packages in the download directory
// This includes the community nodes
await this.loadNodesFromNodeModules(path.join(this.downloadFolder, 'node_modules'));
await this.loadNodesFromCustomDirectories(); await this.loadNodesFromCustomDirectories();
await this.postProcessLoaders(); await this.postProcessLoaders();
this.injectCustomApiCallOptions(); this.injectCustomApiCallOptions();
@ -127,12 +129,15 @@ export class LoadNodesAndCredentials implements INodesAndCredentials {
await writeStaticJSON('credentials', this.types.credentials); await writeStaticJSON('credentials', this.types.credentials);
} }
private async loadNodesFromNodeModules(nodeModulesDir: string): Promise<void> { private async loadNodesFromNodeModules(
const globOptions = { cwd: nodeModulesDir, onlyDirectories: true }; nodeModulesDir: string,
const installedPackagePaths = [ packageName?: string,
...(await glob('n8n-nodes-*', { ...globOptions, deep: 1 })), ): Promise<void> {
...(await glob('@*/n8n-nodes-*', { ...globOptions, deep: 2 })), const installedPackagePaths = await glob(packageName ?? ['n8n-nodes-*', '@*/n8n-nodes-*'], {
]; cwd: nodeModulesDir,
onlyDirectories: true,
deep: 1,
});
for (const packagePath of installedPackagePaths) { for (const packagePath of installedPackagePaths) {
try { try {