diff --git a/packages/cli/src/GenericHelpers.ts b/packages/cli/src/GenericHelpers.ts index 74e9578fec..8dba633baa 100644 --- a/packages/cli/src/GenericHelpers.ts +++ b/packages/cli/src/GenericHelpers.ts @@ -3,14 +3,11 @@ import * as express from 'express'; import { join as pathJoin } from 'path'; import { readFile as fsReadFile, -} from 'fs'; -import { promisify } from 'util'; +} from 'fs/promises'; import { IDataObject } from 'n8n-workflow'; import { IPackageVersions } from './'; -const fsReadFileAsync = promisify(fsReadFile); - let versionCache: IPackageVersions | undefined; @@ -72,7 +69,7 @@ export async function getVersions(): Promise { return versionCache; } - const packageFile = await fsReadFileAsync(pathJoin(__dirname, '../../package.json'), 'utf8') as string; + const packageFile = await fsReadFile(pathJoin(__dirname, '../../package.json'), 'utf8') as string; const packageData = JSON.parse(packageFile); versionCache = { @@ -122,7 +119,7 @@ export async function getConfigValue(configKey: string): Promise => { 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; diff --git a/packages/node-dev/src/Build.ts b/packages/node-dev/src/Build.ts index ce2f16a263..4b470a6ff1 100644 --- a/packages/node-dev/src/Build.ts +++ b/packages/node-dev/src/Build.ts @@ -1,9 +1,13 @@ import { ChildProcess, spawn } from 'child_process'; const copyfiles = require('copyfiles'); + import { readFile as fsReadFile, +} from 'fs/promises'; +import { write as fsWrite, } from 'fs'; + import { join } from 'path'; import { file } from 'tmp-promise'; import { promisify } from 'util'; @@ -32,7 +36,7 @@ export async function createCustomTsconfig () { const tsconfigPath = join(__dirname, '../../src/tsconfig-build.json'); // Read the tsconfi file - const tsConfigString = await fsReadFileAsync(tsconfigPath, { encoding: 'utf8'}) as string; + const tsConfigString = await fsReadFile(tsconfigPath, { encoding: 'utf8'}) as string; const tsConfig = JSON.parse(tsConfigString); // Set absolute include paths diff --git a/packages/nodes-base/nodes/ExecuteWorkflow.node.ts b/packages/nodes-base/nodes/ExecuteWorkflow.node.ts index e4883cd4e8..7ca01e8327 100644 --- a/packages/nodes-base/nodes/ExecuteWorkflow.node.ts +++ b/packages/nodes-base/nodes/ExecuteWorkflow.node.ts @@ -1,9 +1,6 @@ import { readFile as fsReadFile, -} from 'fs'; -import { promisify } from 'util'; - -const fsReadFileAsync = promisify(fsReadFile); +} from 'fs/promises'; import { IExecuteFunctions } from 'n8n-core'; import { @@ -162,7 +159,7 @@ export class ExecuteWorkflow implements INodeType { let workflowJson; try { - workflowJson = await fsReadFileAsync(workflowPath, { encoding: 'utf8' }) as string; + workflowJson = await fsReadFile(workflowPath, { encoding: 'utf8' }) as string; } catch (error) { if (error.code === 'ENOENT') { throw new NodeOperationError(this.getNode(), `The file "${workflowPath}" could not be found.`); diff --git a/packages/nodes-base/nodes/ReadBinaryFile.node.ts b/packages/nodes-base/nodes/ReadBinaryFile.node.ts index 6b595d3b10..fe5a3d8bce 100644 --- a/packages/nodes-base/nodes/ReadBinaryFile.node.ts +++ b/packages/nodes-base/nodes/ReadBinaryFile.node.ts @@ -8,10 +8,7 @@ import { import { readFile as fsReadFile, -} from 'fs'; -import { promisify } from 'util'; - -const fsReadFileAsync = promisify(fsReadFile); +} from 'fs/promises'; export class ReadBinaryFile implements INodeType { @@ -64,7 +61,7 @@ export class ReadBinaryFile implements INodeType { let data; try { - data = await fsReadFileAsync(filePath) as Buffer; + data = await fsReadFile(filePath) as Buffer; } catch (error) { if (error.code === 'ENOENT') { throw new NodeOperationError(this.getNode(), `The file "${filePath}" could not be found.`); diff --git a/packages/nodes-base/nodes/ReadBinaryFiles.node.ts b/packages/nodes-base/nodes/ReadBinaryFiles.node.ts index 7a42764f35..509402bb21 100644 --- a/packages/nodes-base/nodes/ReadBinaryFiles.node.ts +++ b/packages/nodes-base/nodes/ReadBinaryFiles.node.ts @@ -9,10 +9,7 @@ import * as path from 'path'; import { readFile as fsReadFile, -} from 'fs'; -import { promisify } from 'util'; - -const fsReadFileAsync = promisify(fsReadFile); +} from 'fs/promises'; export class ReadBinaryFiles implements INodeType { @@ -61,7 +58,7 @@ export class ReadBinaryFiles implements INodeType { let item: INodeExecutionData; let data: Buffer; for (const filePath of files) { - data = await fsReadFileAsync(filePath) as Buffer; + data = await fsReadFile(filePath) as Buffer; item = { binary: { diff --git a/packages/nodes-base/nodes/WriteBinaryFile.node.ts b/packages/nodes-base/nodes/WriteBinaryFile.node.ts index 6c6f9a83ad..5796110119 100644 --- a/packages/nodes-base/nodes/WriteBinaryFile.node.ts +++ b/packages/nodes-base/nodes/WriteBinaryFile.node.ts @@ -13,10 +13,7 @@ import { import { writeFile as fsWriteFile, -} from 'fs'; -import { promisify } from 'util'; - -const fsWriteFileAsync = promisify(fsWriteFile); +} from 'fs/promises'; export class WriteBinaryFile implements INodeType { @@ -80,7 +77,7 @@ export class WriteBinaryFile implements INodeType { } // Write the file to disk - await fsWriteFileAsync(fileName, Buffer.from(item.binary[dataPropertyName].data, BINARY_ENCODING), 'binary'); + await fsWriteFile(fileName, Buffer.from(item.binary[dataPropertyName].data, BINARY_ENCODING), 'binary'); const newItem: INodeExecutionData = { json: {},