mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
⚡ Use native fs promise where possible (#1684)
This commit is contained in:
@@ -14,15 +14,9 @@ import {
|
||||
readdir as fsReaddir,
|
||||
readFile as fsReadFile,
|
||||
stat as fsStat,
|
||||
} from 'fs';
|
||||
} from 'fs/promises';
|
||||
import * as glob from 'glob-promise';
|
||||
import * as path from 'path';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const fsAccessAsync = promisify(fsAccess);
|
||||
const fsReaddirAsync = promisify(fsReaddir);
|
||||
const fsReadFileAsync = promisify(fsReadFile);
|
||||
const fsStatAsync = promisify(fsStat);
|
||||
|
||||
|
||||
class LoadNodesAndCredentialsClass {
|
||||
@@ -49,7 +43,7 @@ class LoadNodesAndCredentialsClass {
|
||||
];
|
||||
for (const checkPath of checkPaths) {
|
||||
try {
|
||||
await fsAccessAsync(checkPath);
|
||||
await fsAccess(checkPath);
|
||||
// Folder exists, so use it.
|
||||
this.nodeModulesPath = path.dirname(checkPath);
|
||||
break;
|
||||
@@ -102,13 +96,13 @@ class LoadNodesAndCredentialsClass {
|
||||
const getN8nNodePackagesRecursive = async (relativePath: string): Promise<string[]> => {
|
||||
const results: string[] = [];
|
||||
const nodeModulesPath = `${this.nodeModulesPath}/${relativePath}`;
|
||||
for (const file of await fsReaddirAsync(nodeModulesPath)) {
|
||||
for (const file of await fsReaddir(nodeModulesPath)) {
|
||||
const isN8nNodesPackage = file.indexOf('n8n-nodes-') === 0;
|
||||
const isNpmScopedPackage = file.indexOf('@') === 0;
|
||||
if (!isN8nNodesPackage && !isNpmScopedPackage) {
|
||||
continue;
|
||||
}
|
||||
if (!(await fsStatAsync(nodeModulesPath)).isDirectory()) {
|
||||
if (!(await fsStat(nodeModulesPath)).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
if (isN8nNodesPackage) { results.push(`${relativePath}${file}`); }
|
||||
@@ -234,7 +228,7 @@ class LoadNodesAndCredentialsClass {
|
||||
const packagePath = path.join(this.nodeModulesPath, packageName);
|
||||
|
||||
// Read the data from the package.json file to see if any n8n data is defiend
|
||||
const packageFileString = await fsReadFileAsync(path.join(packagePath, 'package.json'), 'utf8');
|
||||
const packageFileString = await fsReadFile(path.join(packagePath, 'package.json'), 'utf8');
|
||||
const packageFile = JSON.parse(packageFileString);
|
||||
if (!packageFile.hasOwnProperty('n8n')) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user