From 9b651cf4f889c57389da373981509a26b957ea0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 20 Apr 2023 16:21:07 +0200 Subject: [PATCH] refactor: Accumulate `loadOptions` from all node versions to validate (no-changelog) (#6014) :zap: Accumulate loadOptions from node versions to validate --- packages/core/bin/generate-ui-types | 9 +++++++-- packages/core/src/DirectoryLoader.ts | 13 ++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/core/bin/generate-ui-types b/packages/core/bin/generate-ui-types index 8f98f2fc04..76ceae31fc 100755 --- a/packages/core/bin/generate-ui-types +++ b/packages/core/bin/generate-ui-types @@ -31,7 +31,7 @@ function findReferencedMethods(obj, refs = {}, latestName = '') { (async () => { const loader = new PackageDirectoryLoader(packageDir); - await loader.loadAll({ withLoadOptionsMethods: true }); + await loader.loadAll(); const credentialTypes = Object.values(loader.credentialTypes).map((data) => data.type); @@ -45,7 +45,12 @@ function findReferencedMethods(obj, refs = {}, latestName = '') { const { name } = type.description; - acc[name] = acc[name] ? acc[name].push(methods) : methods; + if (acc[name]) { + acc[name] = [...new Set([...acc[name], ...methods])]; + return; + } + + acc[name] = methods; }); return acc; diff --git a/packages/core/src/DirectoryLoader.ts b/packages/core/src/DirectoryLoader.ts index 0d2d9020c9..0fba8399d3 100644 --- a/packages/core/src/DirectoryLoader.ts +++ b/packages/core/src/DirectoryLoader.ts @@ -44,8 +44,6 @@ export abstract class DirectoryLoader { types: Types = { nodes: [], credentials: [] }; - withLoadOptionsMethods = false; // only for validation during build - constructor( readonly directory: string, protected readonly excludeNodes: string[] = [], @@ -102,10 +100,13 @@ export abstract class DirectoryLoader { this.fixIconPath(versionNode.description, filePath); } + for (const version of Object.values(tempNode.nodeVersions)) { + this.addLoadOptionsMethods(version); + } + const currentVersionNode = tempNode.nodeVersions[tempNode.currentVersion]; this.addCodex({ node: currentVersionNode, filePath, isCustom }); nodeVersion = tempNode.currentVersion; - if (this.withLoadOptionsMethods) this.addLoadOptionsMethods(currentVersionNode); if (currentVersionNode.hasOwnProperty('executeSingle')) { Logger.warn( @@ -114,7 +115,7 @@ export abstract class DirectoryLoader { ); } } else { - if (this.withLoadOptionsMethods) this.addLoadOptionsMethods(tempNode); + this.addLoadOptionsMethods(tempNode); // Short renaming to avoid type issues nodeVersion = Array.isArray(tempNode.description.version) @@ -306,9 +307,7 @@ export class PackageDirectoryLoader extends DirectoryLoader { this.packageName = this.packageJson.name; } - override async loadAll(options = { withLoadOptionsMethods: false }) { - this.withLoadOptionsMethods = options.withLoadOptionsMethods; - + override async loadAll() { await this.readPackageJson(); const { n8n } = this.packageJson;