fix: handle version arrays in node parser for correct version extraction
- Fixed extractVersion to properly handle nodes with version arrays like [1, 1.1, 1.2] - Updated detectVersioned to mark nodes with version arrays as versioned - Added test script to verify version extraction - Gmail Trigger now correctly shows version 1.2 instead of 1 - All 97 nodes with version arrays now show their latest version - Database rebuilt with correct versions for all affected nodes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -120,27 +120,56 @@ export class NodeParser {
|
||||
}
|
||||
|
||||
private extractVersion(nodeClass: any): string {
|
||||
// Handle VersionedNodeType with defaultVersion
|
||||
if (nodeClass.baseDescription?.defaultVersion) {
|
||||
return nodeClass.baseDescription.defaultVersion.toString();
|
||||
}
|
||||
|
||||
// Handle VersionedNodeType with nodeVersions
|
||||
if (nodeClass.nodeVersions) {
|
||||
const versions = Object.keys(nodeClass.nodeVersions);
|
||||
return Math.max(...versions.map(Number)).toString();
|
||||
}
|
||||
|
||||
// Check instance for nodeVersions
|
||||
// Check instance for nodeVersions and version arrays
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
|
||||
// Handle instance-level nodeVersions
|
||||
if (instance?.nodeVersions) {
|
||||
const versions = Object.keys(instance.nodeVersions);
|
||||
return Math.max(...versions.map(Number)).toString();
|
||||
}
|
||||
|
||||
// Handle version array in description (e.g., [1, 1.1, 1.2])
|
||||
if (instance?.description?.version) {
|
||||
const version = instance.description.version;
|
||||
if (Array.isArray(version)) {
|
||||
// Find the maximum version from the array
|
||||
const maxVersion = Math.max(...version.map((v: any) => parseFloat(v.toString())));
|
||||
return maxVersion.toString();
|
||||
} else if (typeof version === 'number' || typeof version === 'string') {
|
||||
return version.toString();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
// Some nodes might require parameters to instantiate
|
||||
// Try to get version from class-level description
|
||||
}
|
||||
|
||||
return nodeClass.description?.version || '1';
|
||||
// Also check class-level description for version array
|
||||
const description = this.getNodeDescription(nodeClass);
|
||||
if (description?.version) {
|
||||
if (Array.isArray(description.version)) {
|
||||
const maxVersion = Math.max(...description.version.map((v: any) => parseFloat(v.toString())));
|
||||
return maxVersion.toString();
|
||||
} else if (typeof description.version === 'number' || typeof description.version === 'string') {
|
||||
return description.version.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Default to version 1
|
||||
return '1';
|
||||
}
|
||||
|
||||
private detectVersioned(nodeClass: any): boolean {
|
||||
@@ -149,14 +178,28 @@ export class NodeParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check instance-level nodeVersions
|
||||
// Check instance-level nodeVersions and version arrays
|
||||
try {
|
||||
const instance = typeof nodeClass === 'function' ? new nodeClass() : nodeClass;
|
||||
|
||||
// Check for nodeVersions
|
||||
if (instance?.nodeVersions) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check for version array in description
|
||||
if (instance?.description?.version && Array.isArray(instance.description.version)) {
|
||||
return true;
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
// Some nodes might require parameters to instantiate
|
||||
// Try to check class-level description
|
||||
}
|
||||
|
||||
// Also check class-level description for version array
|
||||
const description = this.getNodeDescription(nodeClass);
|
||||
if (description?.version && Array.isArray(description.version)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
90
src/scripts/test-version-extraction.ts
Normal file
90
src/scripts/test-version-extraction.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { NodeParser } from '../parsers/node-parser';
|
||||
|
||||
// Test script to verify version extraction from different node types
|
||||
|
||||
async function testVersionExtraction() {
|
||||
console.log('Testing version extraction from different node types...\n');
|
||||
|
||||
const parser = new NodeParser();
|
||||
|
||||
// Test cases
|
||||
const testCases = [
|
||||
{
|
||||
name: 'Gmail Trigger (version array)',
|
||||
nodeType: 'nodes-base.gmailTrigger',
|
||||
expectedVersion: '1.2',
|
||||
expectedVersioned: true
|
||||
},
|
||||
{
|
||||
name: 'HTTP Request (VersionedNodeType)',
|
||||
nodeType: 'nodes-base.httpRequest',
|
||||
expectedVersion: '4.2',
|
||||
expectedVersioned: true
|
||||
},
|
||||
{
|
||||
name: 'Code (version array)',
|
||||
nodeType: 'nodes-base.code',
|
||||
expectedVersion: '2',
|
||||
expectedVersioned: true
|
||||
}
|
||||
];
|
||||
|
||||
// Load nodes from packages
|
||||
const basePackagePath = process.cwd() + '/node_modules/n8n/node_modules/n8n-nodes-base';
|
||||
|
||||
for (const testCase of testCases) {
|
||||
console.log(`\nTesting: ${testCase.name}`);
|
||||
console.log(`Node Type: ${testCase.nodeType}`);
|
||||
|
||||
try {
|
||||
// Find the node file
|
||||
const nodeName = testCase.nodeType.split('.')[1];
|
||||
|
||||
// Try different paths
|
||||
const possiblePaths = [
|
||||
`${basePackagePath}/dist/nodes/${nodeName}.node.js`,
|
||||
`${basePackagePath}/dist/nodes/Google/Gmail/GmailTrigger.node.js`,
|
||||
`${basePackagePath}/dist/nodes/HttpRequest/HttpRequest.node.js`,
|
||||
`${basePackagePath}/dist/nodes/Code/Code.node.js`
|
||||
];
|
||||
|
||||
let nodeClass = null;
|
||||
for (const path of possiblePaths) {
|
||||
try {
|
||||
const module = require(path);
|
||||
nodeClass = module[Object.keys(module)[0]];
|
||||
if (nodeClass) break;
|
||||
} catch (e) {
|
||||
// Try next path
|
||||
}
|
||||
}
|
||||
|
||||
if (!nodeClass) {
|
||||
console.log('❌ Could not load node');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse the node
|
||||
const parsed = parser.parse(nodeClass, 'n8n-nodes-base');
|
||||
|
||||
console.log(`Loaded node: ${parsed.displayName} (${parsed.nodeType})`);
|
||||
console.log(`Extracted version: ${parsed.version}`);
|
||||
console.log(`Is versioned: ${parsed.isVersioned}`);
|
||||
console.log(`Expected version: ${testCase.expectedVersion}`);
|
||||
console.log(`Expected versioned: ${testCase.expectedVersioned}`);
|
||||
|
||||
if (parsed.version === testCase.expectedVersion &&
|
||||
parsed.isVersioned === testCase.expectedVersioned) {
|
||||
console.log('✅ PASS');
|
||||
} else {
|
||||
console.log('❌ FAIL');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(`❌ Error: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run the test
|
||||
testVersionExtraction().catch(console.error);
|
||||
Reference in New Issue
Block a user