Skip to content

Commit f150343

Browse files
authored
fix: Fix issue with some community nodes not displaying correctly (#17866)
1 parent 491f2fa commit f150343

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

packages/cli/src/community-packages/community-packages.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const {
5757

5858
const asyncExec = promisify(exec);
5959

60-
const INVALID_OR_SUSPICIOUS_PACKAGE_NAME = /[^0-9a-z@\-./]/;
60+
const INVALID_OR_SUSPICIOUS_PACKAGE_NAME = /[^0-9a-z@\-._/]/;
6161

6262
type PackageJson = {
6363
name: 'installed-nodes';

packages/frontend/editor-ui/src/utils/nodeTypeUtils.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ResourceMapperField } from 'n8n-workflow';
2-
import { isResourceMapperFieldListStale } from './nodeTypesUtils';
2+
import { isCommunityPackageName, isResourceMapperFieldListStale } from './nodeTypesUtils';
33

44
describe('isResourceMapperFieldListStale', () => {
55
const baseField: ResourceMapperField = {
@@ -73,3 +73,57 @@ describe('isResourceMapperFieldListStale', () => {
7373
expect(isResourceMapperFieldListStale(oldFields, newFields)).toBe(true);
7474
});
7575
});
76+
77+
describe('isCommunityPackageName', () => {
78+
// Standard community package names
79+
it('should identify standard community node package names', () => {
80+
expect(isCommunityPackageName('n8n-nodes-example')).toBe(true);
81+
expect(isCommunityPackageName('n8n-nodes-custom')).toBe(true);
82+
expect(isCommunityPackageName('n8n-nodes-test')).toBe(true);
83+
});
84+
85+
// Scoped package names
86+
it('should identify scoped community node package names', () => {
87+
expect(isCommunityPackageName('@username/n8n-nodes-example')).toBe(true);
88+
expect(isCommunityPackageName('@org/n8n-nodes-custom')).toBe(true);
89+
expect(isCommunityPackageName('@test-scope/n8n-nodes-test-name')).toBe(true);
90+
});
91+
92+
it('should identify scoped packages with other characters', () => {
93+
expect(isCommunityPackageName('n8n-nodes-my_package')).toBe(true);
94+
expect(isCommunityPackageName('@user/n8n-nodes-with_underscore')).toBe(true);
95+
expect(isCommunityPackageName('@user_name/n8n-nodes-example')).toBe(true);
96+
expect(isCommunityPackageName('@n8n-io/n8n-nodes-test')).toBe(true);
97+
expect(isCommunityPackageName('@n8n.io/n8n-nodes-test')).toBe(true);
98+
});
99+
100+
it('should handle mixed cases', () => {
101+
expect(isCommunityPackageName('@user-name_org/n8n-nodes-mixed-case_example')).toBe(true);
102+
expect(isCommunityPackageName('@mixed_style-org/n8n-nodes-complex_name-format')).toBe(true);
103+
expect(isCommunityPackageName('@my.mixed_style-org/n8n-nodes-complex_name-format')).toBe(true);
104+
});
105+
106+
// Official n8n packages that should not be identified as community packages
107+
it('should not identify official n8n packages as community nodes', () => {
108+
expect(isCommunityPackageName('@n8n/n8n-nodes-example')).toBe(false);
109+
expect(isCommunityPackageName('n8n-nodes-base')).toBe(false);
110+
});
111+
112+
// Additional edge cases
113+
it('should handle edge cases correctly', () => {
114+
// Non-matching patterns
115+
expect(isCommunityPackageName('not-n8n-nodes')).toBe(false);
116+
expect(isCommunityPackageName('n8n-core')).toBe(false);
117+
118+
// With node name after package
119+
expect(isCommunityPackageName('n8n-nodes-example.NodeName')).toBe(true);
120+
expect(isCommunityPackageName('@user/n8n-nodes-example.NodeName')).toBe(true);
121+
});
122+
123+
// Multiple executions to test regex state
124+
it('should work correctly with multiple consecutive calls', () => {
125+
expect(isCommunityPackageName('@user/n8n-nodes-example')).toBe(true);
126+
expect(isCommunityPackageName('n8n-nodes-base')).toBe(false);
127+
expect(isCommunityPackageName('@test-scope/n8n-nodes-test')).toBe(true);
128+
});
129+
});

packages/frontend/editor-ui/src/utils/nodeTypesUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131

3232
const CRED_KEYWORDS_TO_FILTER = ['API', 'OAuth1', 'OAuth2'];
3333
const NODE_KEYWORDS_TO_FILTER = ['Trigger'];
34-
const COMMUNITY_PACKAGE_NAME_REGEX = /^(?!@n8n\/)(@\w+\/)?n8n-nodes-(?!base\b)\b\w+/g;
34+
const COMMUNITY_PACKAGE_NAME_REGEX = /^(?!@n8n\/)(@[\w.-]+\/)?n8n-nodes-(?!base\b)\b\w+/g;
3535
const RESOURCE_MAPPER_FIELD_NAME_REGEX = /value\[\"(.+)\"\]/;
3636

3737
export function getAppNameFromCredType(name: string) {

0 commit comments

Comments
 (0)