mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
🎨 Set up linting and formatting (#2120)
* ⬆️ Upgrade TS to 4.3.5 * 👕 Add ESLint configs * 🎨 Add Prettier config * 📦 Add deps and commands * ⚡ Adjust global .editorconfig to new ruleset * 🔥 Remove unneeded local .editorconfig * 📦 Update deps in editor-ui * 🔨 Limit Prettier to only TS files * ⚡ Add recommended VSCode extensions * 👕 Fix build * 🔥 Remove Vue setting from global config * ⚡ Disable prefer-default-export per feedback * ✏️ Add forgotten divider * 👕 Disable no-plusplus * 👕 Disable class-methods-use-this * ✏️ Alphabetize overrides * 👕 Add one-var consecutive override * ⏪ Revert one-var consecutive override This reverts commit b9252cf935659ba6d76727ad484a1d3c00008fcc. * 🎨 👕 Lint and format workflow package (#2121) * 🎨 Format /workflow package * 👕 Lint /workflow package * 🎨 Re-format /workflow package * 👕 Re-lint /workflow package * ✏️ Fix typo * ⚡ Consolidate if-checks * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 🎨 👕 Lint and format node-dev package (#2122) * 🎨 Format /node-dev package * ⚡ Exclude templates from ESLint config This keeps the templates consistent with the codebase while preventing lint exceptions from being made part of the templates. * 👕 Lint /node-dev package * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🎨 👕 Lint and format core package (#2123) * 🎨 Format /core package * 👕 Lint /core package * 🎨 Re-format /core package * 👕 Re-lint /core package * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 🎨 👕 Lint and format cli package (#2124) * 🎨 Format /cli package * 👕 Exclude migrations from linting * 👕 Lint /cli package * 🎨 Re-format /cli package * 👕 Re-lint /cli package * 👕 Fix build * 🔥 Remove prefer-default-export exceptions * ⚡ Update exceptions in ActiveExecutions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 👕 fix lint issues * 🔧 use package specific linter, remove tslint command * 🔨 resolve build issue, sync dependencies * 🔧 change lint command Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com>
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import {
|
||||
CUSTOM_EXTENSION_ENV,
|
||||
UserSettings,
|
||||
} from 'n8n-core';
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
/* eslint-disable no-prototype-builtins */
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* eslint-disable @typescript-eslint/prefer-optional-chain */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-continue */
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
import { CUSTOM_EXTENSION_ENV, UserSettings } from 'n8n-core';
|
||||
import {
|
||||
CodexData,
|
||||
ICredentialType,
|
||||
@@ -11,12 +18,6 @@ import {
|
||||
LoggerProxy,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as config from '../config';
|
||||
|
||||
import {
|
||||
getLogger,
|
||||
} from '../src/Logger';
|
||||
|
||||
import {
|
||||
access as fsAccess,
|
||||
readdir as fsReaddir,
|
||||
@@ -25,18 +26,20 @@ import {
|
||||
} from 'fs/promises';
|
||||
import * as glob from 'fast-glob';
|
||||
import * as path from 'path';
|
||||
import { getLogger } from './Logger';
|
||||
import * as config from '../config';
|
||||
|
||||
const CUSTOM_NODES_CATEGORY = 'Custom Nodes';
|
||||
|
||||
|
||||
class LoadNodesAndCredentialsClass {
|
||||
nodeTypes: INodeTypeData = {};
|
||||
|
||||
credentialTypes: {
|
||||
[key: string]: ICredentialType
|
||||
[key: string]: ICredentialType;
|
||||
} = {};
|
||||
|
||||
excludeNodes: string[] | undefined = undefined;
|
||||
|
||||
includeNodes: string[] | undefined = undefined;
|
||||
|
||||
nodeModulesPath = '';
|
||||
@@ -64,6 +67,7 @@ class LoadNodesAndCredentialsClass {
|
||||
break;
|
||||
} catch (error) {
|
||||
// Folder does not exist so get next one
|
||||
// eslint-disable-next-line no-continue
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +94,9 @@ class LoadNodesAndCredentialsClass {
|
||||
|
||||
// Add folders from special environment variable
|
||||
if (process.env[CUSTOM_EXTENSION_ENV] !== undefined) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const customExtensionFolders = process.env[CUSTOM_EXTENSION_ENV]!.split(';');
|
||||
// eslint-disable-next-line prefer-spread
|
||||
customDirectories.push.apply(customDirectories, customExtensionFolders);
|
||||
}
|
||||
|
||||
@@ -99,7 +105,6 @@ class LoadNodesAndCredentialsClass {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the names of the packages which could
|
||||
* contain n8n nodes
|
||||
@@ -120,9 +125,11 @@ class LoadNodesAndCredentialsClass {
|
||||
if (!(await fsStat(nodeModulesPath)).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (isN8nNodesPackage) { results.push(`${relativePath}${file}`); }
|
||||
if (isN8nNodesPackage) {
|
||||
results.push(`${relativePath}${file}`);
|
||||
}
|
||||
if (isNpmScopedPackage) {
|
||||
results.push(...await getN8nNodePackagesRecursive(`${relativePath}${file}/`));
|
||||
results.push(...(await getN8nNodePackagesRecursive(`${relativePath}${file}/`)));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
@@ -138,6 +145,7 @@ class LoadNodesAndCredentialsClass {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async loadCredentialsFromFile(credentialName: string, filePath: string): Promise<void> {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
|
||||
const tempModule = require(filePath);
|
||||
|
||||
let tempCredential: ICredentialType;
|
||||
@@ -145,7 +153,9 @@ class LoadNodesAndCredentialsClass {
|
||||
tempCredential = new tempModule[credentialName]() as ICredentialType;
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) {
|
||||
throw new Error(`Class with name "${credentialName}" could not be found. Please check if the class is named correctly!`);
|
||||
throw new Error(
|
||||
`Class with name "${credentialName}" could not be found. Please check if the class is named correctly!`,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
@@ -154,7 +164,6 @@ class LoadNodesAndCredentialsClass {
|
||||
this.credentialTypes[tempCredential.name] = tempCredential;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads a node from a file
|
||||
*
|
||||
@@ -167,26 +176,34 @@ class LoadNodesAndCredentialsClass {
|
||||
let tempNode: INodeType;
|
||||
let fullNodeName: string;
|
||||
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires
|
||||
const tempModule = require(filePath);
|
||||
try {
|
||||
tempNode = new tempModule[nodeName]() as INodeType;
|
||||
this.addCodex({ node: tempNode, filePath, isCustom: packageName === 'CUSTOM' });
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`Error loading node "${nodeName}" from: "${filePath}"`);
|
||||
throw error;
|
||||
}
|
||||
|
||||
fullNodeName = packageName + '.' + tempNode.description.name;
|
||||
// eslint-disable-next-line prefer-const
|
||||
fullNodeName = `${packageName}.${tempNode.description.name}`;
|
||||
tempNode.description.name = fullNodeName;
|
||||
|
||||
if (tempNode.description.icon !== undefined &&
|
||||
tempNode.description.icon.startsWith('file:')) {
|
||||
if (tempNode.description.icon !== undefined && tempNode.description.icon.startsWith('file:')) {
|
||||
// If a file icon gets used add the full path
|
||||
tempNode.description.icon = 'file:' + path.join(path.dirname(filePath), tempNode.description.icon.substr(5));
|
||||
tempNode.description.icon = `file:${path.join(
|
||||
path.dirname(filePath),
|
||||
tempNode.description.icon.substr(5),
|
||||
)}`;
|
||||
}
|
||||
|
||||
if (tempNode.executeSingle) {
|
||||
this.logger.warn(`"executeSingle" will get deprecated soon. Please update the code of node "${packageName}.${nodeName}" to use "execute" instead!`, { filePath });
|
||||
this.logger.warn(
|
||||
`"executeSingle" will get deprecated soon. Please update the code of node "${packageName}.${nodeName}" to use "execute" instead!`,
|
||||
{ filePath },
|
||||
);
|
||||
}
|
||||
|
||||
if (this.includeNodes !== undefined && !this.includeNodes.includes(fullNodeName)) {
|
||||
@@ -212,7 +229,9 @@ class LoadNodesAndCredentialsClass {
|
||||
* @returns {CodexData}
|
||||
*/
|
||||
getCodex(filePath: string): CodexData {
|
||||
// eslint-disable-next-line global-require, import/no-dynamic-require, @typescript-eslint/no-var-requires
|
||||
const { categories, subcategories, alias } = require(`${filePath}on`); // .js to .json
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return {
|
||||
...(categories && { categories }),
|
||||
...(subcategories && { subcategories }),
|
||||
@@ -230,11 +249,7 @@ class LoadNodesAndCredentialsClass {
|
||||
* @param obj.isCustom Whether the node is custom
|
||||
* @returns {void}
|
||||
*/
|
||||
addCodex({ node, filePath, isCustom }: {
|
||||
node: INodeType;
|
||||
filePath: string;
|
||||
isCustom: boolean;
|
||||
}) {
|
||||
addCodex({ node, filePath, isCustom }: { node: INodeType; filePath: string; isCustom: boolean }) {
|
||||
try {
|
||||
const codex = this.getCodex(filePath);
|
||||
|
||||
@@ -246,6 +261,7 @@ class LoadNodesAndCredentialsClass {
|
||||
|
||||
node.description.codex = codex;
|
||||
} catch (_) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
this.logger.debug(`No codex available for: ${filePath.split('/').pop()}`);
|
||||
|
||||
if (isCustom) {
|
||||
@@ -264,7 +280,7 @@ class LoadNodesAndCredentialsClass {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async loadDataFromDirectory(setPackageName: string, directory: string): Promise<void> {
|
||||
const files = await glob(path.join(directory, '**/*\.@(node|credentials)\.js'));
|
||||
const files = await glob(path.join(directory, '**/*.@(node|credentials).js'));
|
||||
|
||||
let fileName: string;
|
||||
let type: string;
|
||||
@@ -283,7 +299,6 @@ class LoadNodesAndCredentialsClass {
|
||||
await Promise.all(loadPromises);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads nodes and credentials from the package with the given name
|
||||
*
|
||||
@@ -301,10 +316,12 @@ class LoadNodesAndCredentialsClass {
|
||||
return;
|
||||
}
|
||||
|
||||
let tempPath: string, filePath: string;
|
||||
let tempPath: string;
|
||||
let filePath: string;
|
||||
|
||||
// Read all node types
|
||||
let fileName: string, type: string;
|
||||
let fileName: string;
|
||||
let type: string;
|
||||
if (packageFile.n8n.hasOwnProperty('nodes') && Array.isArray(packageFile.n8n.nodes)) {
|
||||
for (filePath of packageFile.n8n.nodes) {
|
||||
tempPath = path.join(packagePath, filePath);
|
||||
@@ -314,18 +331,21 @@ class LoadNodesAndCredentialsClass {
|
||||
}
|
||||
|
||||
// Read all credential types
|
||||
if (packageFile.n8n.hasOwnProperty('credentials') && Array.isArray(packageFile.n8n.credentials)) {
|
||||
if (
|
||||
packageFile.n8n.hasOwnProperty('credentials') &&
|
||||
Array.isArray(packageFile.n8n.credentials)
|
||||
) {
|
||||
for (filePath of packageFile.n8n.credentials) {
|
||||
tempPath = path.join(packagePath, filePath);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[fileName, type] = path.parse(filePath).name.split('.');
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
this.loadCredentialsFromFile(fileName, tempPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
let packagesInformationInstance: LoadNodesAndCredentialsClass | undefined;
|
||||
|
||||
export function LoadNodesAndCredentials(): LoadNodesAndCredentialsClass {
|
||||
|
||||
Reference in New Issue
Block a user