mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Fix supportedNodes for non-lazy loaded community packages (no-changelog) (#11329)
This commit is contained in:
committed by
GitHub
parent
1c52bf9362
commit
2d36b42798
@@ -1,99 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path');
|
||||
const glob = require('fast-glob');
|
||||
const uniq = require('lodash/uniq');
|
||||
const { LoggerProxy, getCredentialsForNode } = require('n8n-workflow');
|
||||
const { packageDir, writeJSON } = require('./common');
|
||||
const { loadClassInIsolation } = require('../dist/ClassLoader');
|
||||
|
||||
LoggerProxy.init(console);
|
||||
|
||||
const loadClass = (sourcePath) => {
|
||||
try {
|
||||
const [className] = path.parse(sourcePath).name.split('.');
|
||||
const filePath = path.resolve(packageDir, sourcePath);
|
||||
const instance = loadClassInIsolation(filePath, className);
|
||||
return { instance, sourcePath, className };
|
||||
} catch (e) {
|
||||
LoggerProxy.warn(`Failed to load ${sourcePath}: ${e.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
const generateKnownNodes = async () => {
|
||||
const nodeClasses = glob
|
||||
.sync('dist/nodes/**/*.node.js', { cwd: packageDir })
|
||||
.map(loadClass)
|
||||
// Ignore node versions
|
||||
.filter((nodeClass) => nodeClass && !/[vV]\d.node\.js$/.test(nodeClass.sourcePath));
|
||||
|
||||
const nodes = {};
|
||||
const nodesByCredential = {};
|
||||
|
||||
for (const { className, sourcePath, instance } of nodeClasses) {
|
||||
const nodeName = instance.description.name;
|
||||
nodes[nodeName] = { className, sourcePath };
|
||||
|
||||
for (const credential of getCredentialsForNode(instance)) {
|
||||
if (!nodesByCredential[credential.name]) {
|
||||
nodesByCredential[credential.name] = [];
|
||||
}
|
||||
|
||||
nodesByCredential[credential.name].push(nodeName);
|
||||
}
|
||||
}
|
||||
|
||||
LoggerProxy.info(`Detected ${Object.keys(nodes).length} nodes`);
|
||||
await writeJSON('known/nodes.json', nodes);
|
||||
return { nodes, nodesByCredential };
|
||||
};
|
||||
|
||||
const generateKnownCredentials = async (nodesByCredential) => {
|
||||
const credentialClasses = glob
|
||||
.sync(`dist/credentials/**/*.credentials.js`, { cwd: packageDir })
|
||||
.map(loadClass)
|
||||
.filter((data) => !!data);
|
||||
|
||||
for (const { instance } of credentialClasses) {
|
||||
if (Array.isArray(instance.extends)) {
|
||||
for (const extendedCredential of instance.extends) {
|
||||
nodesByCredential[extendedCredential] = [
|
||||
...(nodesByCredential[extendedCredential] ?? []),
|
||||
...(nodesByCredential[instance.name] ?? []),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const credentials = credentialClasses.reduce(
|
||||
(credentials, { className, sourcePath, instance }) => {
|
||||
const credentialName = instance.name;
|
||||
const credential = {
|
||||
className,
|
||||
sourcePath,
|
||||
};
|
||||
|
||||
if (Array.isArray(instance.extends)) {
|
||||
credential.extends = instance.extends;
|
||||
}
|
||||
|
||||
if (nodesByCredential[credentialName]) {
|
||||
credential.supportedNodes = Array.from(new Set(nodesByCredential[credentialName]));
|
||||
}
|
||||
|
||||
credentials[credentialName] = credential;
|
||||
|
||||
return credentials;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
LoggerProxy.info(`Detected ${Object.keys(credentials).length} credentials`);
|
||||
await writeJSON('known/credentials.json', credentials);
|
||||
return credentials;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const { nodesByCredential } = await generateKnownNodes();
|
||||
await generateKnownCredentials(nodesByCredential);
|
||||
})();
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { LoggerProxy, NodeHelpers } = require('n8n-workflow');
|
||||
const { LoggerProxy } = require('n8n-workflow');
|
||||
const { PackageDirectoryLoader } = require('../dist/DirectoryLoader');
|
||||
const { packageDir, writeJSON } = require('./common');
|
||||
|
||||
@@ -33,7 +33,7 @@ function findReferencedMethods(obj, refs = {}, latestName = '') {
|
||||
const loaderNodeTypes = Object.values(loader.nodeTypes);
|
||||
|
||||
const definedMethods = loaderNodeTypes.reduce((acc, cur) => {
|
||||
NodeHelpers.getVersionedNodeTypeAll(cur.type).forEach((type) => {
|
||||
loader.getVersionedNodeTypeAll(cur.type).forEach((type) => {
|
||||
const methods = type.description?.__loadOptionsMethods;
|
||||
|
||||
if (!methods) return;
|
||||
@@ -52,51 +52,21 @@ function findReferencedMethods(obj, refs = {}, latestName = '') {
|
||||
}, {});
|
||||
|
||||
const nodeTypes = loaderNodeTypes
|
||||
.map((data) => {
|
||||
const nodeType = NodeHelpers.getVersionedNodeType(data.type);
|
||||
NodeHelpers.applySpecialNodeParameters(nodeType);
|
||||
return data.type;
|
||||
})
|
||||
.map(({ type }) => type)
|
||||
.flatMap((nodeType) =>
|
||||
NodeHelpers.getVersionedNodeTypeAll(nodeType).map((item) => {
|
||||
loader.getVersionedNodeTypeAll(nodeType).map((item) => {
|
||||
const { __loadOptionsMethods, ...rest } = item.description;
|
||||
return rest;
|
||||
}),
|
||||
);
|
||||
|
||||
const knownCredentials = loader.known.credentials;
|
||||
const credentialTypes = Object.values(loader.credentialTypes).map((data) => {
|
||||
const credentialType = data.type;
|
||||
const supportedNodes = knownCredentials[credentialType.name].supportedNodes ?? [];
|
||||
if (supportedNodes.length > 0 && credentialType.httpRequestNode) {
|
||||
credentialType.httpRequestNode.hidden = true;
|
||||
}
|
||||
|
||||
credentialType.supportedNodes = supportedNodes;
|
||||
|
||||
if (!credentialType.iconUrl && !credentialType.icon) {
|
||||
for (const supportedNode of supportedNodes) {
|
||||
const nodeType = loader.nodeTypes[supportedNode]?.type.description;
|
||||
|
||||
if (!nodeType) continue;
|
||||
if (nodeType.icon) {
|
||||
credentialType.icon = nodeType.icon;
|
||||
credentialType.iconColor = nodeType.iconColor;
|
||||
break;
|
||||
}
|
||||
if (nodeType.iconUrl) {
|
||||
credentialType.iconUrl = nodeType.iconUrl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return credentialType;
|
||||
});
|
||||
|
||||
const credentialTypes = Object.values(loader.credentialTypes).map(({ type }) => type);
|
||||
const referencedMethods = findReferencedMethods(nodeTypes);
|
||||
|
||||
await Promise.all([
|
||||
writeJSON('known/nodes.json', loader.known.nodes),
|
||||
writeJSON('known/credentials.json', loader.known.credentials),
|
||||
writeJSON('types/credentials.json', credentialTypes),
|
||||
writeJSON('types/nodes.json', nodeTypes),
|
||||
writeJSON('methods/defined.json', definedMethods),
|
||||
Reference in New Issue
Block a user