mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
fix: Make nodes.exclude and nodes.include work with lazy-loaded nodes (#4833)
This commit is contained in:
committed by
GitHub
parent
a09ff27f43
commit
85241fd230
@@ -1,8 +1,32 @@
|
|||||||
/* eslint-disable no-restricted-syntax */
|
/* eslint-disable no-restricted-syntax */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as core from 'n8n-core';
|
import convict from 'convict';
|
||||||
|
import { UserSettings } from 'n8n-core';
|
||||||
|
import { jsonParse } from 'n8n-workflow';
|
||||||
|
|
||||||
|
convict.addFormat({
|
||||||
|
name: 'nodes-list',
|
||||||
|
// @ts-ignore
|
||||||
|
validate(values: string[], { env }: { env: string }): void {
|
||||||
|
try {
|
||||||
|
if (!Array.isArray(values)) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const value of values) {
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
throw new TypeError(`${env} is not a valid Array of strings.`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
coerce(rawValue: string): string[] {
|
||||||
|
return jsonParse(rawValue, { errorMessage: 'nodes-list needs to be valid JSON' });
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const schema = {
|
export const schema = {
|
||||||
database: {
|
database: {
|
||||||
@@ -716,47 +740,14 @@ export const schema = {
|
|||||||
nodes: {
|
nodes: {
|
||||||
include: {
|
include: {
|
||||||
doc: 'Nodes to load',
|
doc: 'Nodes to load',
|
||||||
format: function check(rawValue: string): void {
|
format: 'nodes-list',
|
||||||
if (rawValue === '') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const values = JSON.parse(rawValue);
|
|
||||||
if (!Array.isArray(values)) {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const value of values) {
|
|
||||||
if (typeof value !== 'string') {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new TypeError(`The Nodes to include is not a valid Array of strings.`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
default: undefined,
|
default: undefined,
|
||||||
env: 'NODES_INCLUDE',
|
env: 'NODES_INCLUDE',
|
||||||
},
|
},
|
||||||
exclude: {
|
exclude: {
|
||||||
doc: 'Nodes not to load',
|
doc: 'Nodes not to load',
|
||||||
format: function check(rawValue: string): void {
|
format: 'nodes-list',
|
||||||
try {
|
default: undefined,
|
||||||
const values = JSON.parse(rawValue);
|
|
||||||
if (!Array.isArray(values)) {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const value of values) {
|
|
||||||
if (typeof value !== 'string') {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new TypeError(`The Nodes to exclude is not a valid Array of strings.`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
default: '[]',
|
|
||||||
env: 'NODES_EXCLUDE',
|
env: 'NODES_EXCLUDE',
|
||||||
},
|
},
|
||||||
errorTriggerType: {
|
errorTriggerType: {
|
||||||
@@ -804,7 +795,7 @@ export const schema = {
|
|||||||
location: {
|
location: {
|
||||||
doc: 'Log file location; only used if log output is set to file.',
|
doc: 'Log file location; only used if log output is set to file.',
|
||||||
format: String,
|
format: String,
|
||||||
default: path.join(core.UserSettings.getUserN8nFolderPath(), 'logs/n8n.log'),
|
default: path.join(UserSettings.getUserN8nFolderPath(), 'logs/n8n.log'),
|
||||||
env: 'N8N_LOG_FILE_LOCATION',
|
env: 'N8N_LOG_FILE_LOCATION',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -861,7 +852,7 @@ export const schema = {
|
|||||||
},
|
},
|
||||||
localStoragePath: {
|
localStoragePath: {
|
||||||
format: String,
|
format: String,
|
||||||
default: path.join(core.UserSettings.getUserN8nFolderPath(), 'binaryData'),
|
default: path.join(UserSettings.getUserN8nFolderPath(), 'binaryData'),
|
||||||
env: 'N8N_BINARY_DATA_STORAGE_PATH',
|
env: 'N8N_BINARY_DATA_STORAGE_PATH',
|
||||||
doc: 'Path for binary data storage in "filesystem" mode',
|
doc: 'Path for binary data storage in "filesystem" mode',
|
||||||
},
|
},
|
||||||
|
|||||||
3
packages/cli/src/config/types.d.ts
vendored
3
packages/cli/src/config/types.d.ts
vendored
@@ -77,7 +77,8 @@ type ToReturnType<T extends ConfigOptionPath> = T extends NumericPath
|
|||||||
type ExceptionPaths = {
|
type ExceptionPaths = {
|
||||||
'queue.bull.redis': object;
|
'queue.bull.redis': object;
|
||||||
binaryDataManager: IBinaryDataConfig;
|
binaryDataManager: IBinaryDataConfig;
|
||||||
'nodes.include': undefined;
|
'nodes.exclude': string[] | undefined;
|
||||||
|
'nodes.include': string[] | undefined;
|
||||||
'userManagement.isInstanceOwnerSetUp': boolean;
|
'userManagement.isInstanceOwnerSetUp': boolean;
|
||||||
'userManagement.skipInstanceOwnerSetup': boolean;
|
'userManagement.skipInstanceOwnerSetup': boolean;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ export abstract class DirectoryLoader {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected readonly directory: string,
|
protected readonly directory: string,
|
||||||
private readonly excludeNodes?: string,
|
protected readonly excludeNodes: string[] = [],
|
||||||
private readonly includeNodes?: string,
|
protected readonly includeNodes: string[] = [],
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
abstract loadAll(): Promise<void>;
|
abstract loadAll(): Promise<void>;
|
||||||
@@ -69,11 +69,11 @@ export abstract class DirectoryLoader {
|
|||||||
|
|
||||||
const fullNodeName = `${packageName}.${tempNode.description.name}`;
|
const fullNodeName = `${packageName}.${tempNode.description.name}`;
|
||||||
|
|
||||||
if (this.includeNodes !== undefined && !this.includeNodes.includes(fullNodeName)) {
|
if (this.includeNodes.length && !this.includeNodes.includes(fullNodeName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.excludeNodes?.includes(fullNodeName)) {
|
if (this.excludeNodes.includes(fullNodeName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,6 +338,28 @@ export class LazyPackageDirectoryLoader extends PackageDirectoryLoader {
|
|||||||
this.types.nodes = await this.readJSON('dist/types/nodes.json');
|
this.types.nodes = await this.readJSON('dist/types/nodes.json');
|
||||||
this.types.credentials = await this.readJSON('dist/types/credentials.json');
|
this.types.credentials = await this.readJSON('dist/types/credentials.json');
|
||||||
|
|
||||||
|
if (this.includeNodes.length) {
|
||||||
|
const allowedNodes: typeof this.known.nodes = {};
|
||||||
|
for (const nodeName of this.includeNodes) {
|
||||||
|
allowedNodes[nodeName] = this.known.nodes[nodeName];
|
||||||
|
}
|
||||||
|
this.known.nodes = allowedNodes;
|
||||||
|
|
||||||
|
this.types.nodes = this.types.nodes.filter((nodeType) =>
|
||||||
|
this.includeNodes.includes(nodeType.name),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.excludeNodes.length) {
|
||||||
|
for (const nodeName of this.excludeNodes) {
|
||||||
|
delete this.known.nodes[nodeName];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.types.nodes = this.types.nodes.filter(
|
||||||
|
(nodeType) => !this.excludeNodes.includes(nodeType.name),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Logger.debug(`Lazy Loading credentials and nodes from ${this.packageJson.name}`, {
|
Logger.debug(`Lazy Loading credentials and nodes from ${this.packageJson.name}`, {
|
||||||
credentials: this.types.credentials?.length ?? 0,
|
credentials: this.types.credentials?.length ?? 0,
|
||||||
nodes: this.types.nodes?.length ?? 0,
|
nodes: this.types.nodes?.length ?? 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user