diff --git a/.github/scripts/check-tests.mjs b/.github/scripts/check-tests.mjs index 6c0f37b2aa6403..1e2e38e05b064b 100644 --- a/.github/scripts/check-tests.mjs +++ b/.github/scripts/check-tests.mjs @@ -1,11 +1,10 @@ -import fs from 'fs'; +import { readFile } from 'fs/promises'; import path from 'path'; import util from 'util'; import { exec } from 'child_process'; import { glob } from 'glob'; import ts from 'typescript'; -const readFileAsync = util.promisify(fs.readFile); const execAsync = util.promisify(exec); const filterAsync = async (asyncPredicate, arr) => { @@ -37,7 +36,7 @@ const isAbstractMethod = (node) => { // Function to check if a file has a function declaration, function expression, object method or class const hasFunctionOrClass = async (filePath) => { - const fileContent = await readFileAsync(filePath, 'utf-8'); + const fileContent = await readFile(filePath, 'utf-8'); const sourceFile = ts.createSourceFile(filePath, fileContent, ts.ScriptTarget.Latest, true); let hasFunctionOrClass = false; diff --git a/packages/cli/src/WebhookHelpers.ts b/packages/cli/src/WebhookHelpers.ts index 999740a19ba651..c429a06aa2f65a 100644 --- a/packages/cli/src/WebhookHelpers.ts +++ b/packages/cli/src/WebhookHelpers.ts @@ -9,8 +9,7 @@ import type express from 'express'; import { Container } from 'typedi'; import get from 'lodash/get'; -import stream from 'stream'; -import { promisify } from 'util'; +import { pipeline } from 'stream/promises'; import formidable from 'formidable'; import { BinaryDataService, NodeExecuteFunctions } from 'n8n-core'; @@ -65,8 +64,6 @@ import { NotFoundError } from './errors/response-errors/not-found.error'; import { InternalServerError } from './errors/response-errors/internal-server.error'; import { UnprocessableRequestError } from './errors/response-errors/unprocessable.error'; -const pipeline = promisify(stream.pipeline); - export const WEBHOOK_METHODS: IHttpRequestMethods[] = [ 'DELETE', 'GET', diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index a1ddf03ec74425..82664ed90ef294 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -5,9 +5,8 @@ import { Flags, type Config } from '@oclif/core'; import path from 'path'; import { mkdir } from 'fs/promises'; import { createReadStream, createWriteStream, existsSync } from 'fs'; -import stream from 'stream'; +import { pipeline } from 'stream/promises'; import replaceStream from 'replacestream'; -import { promisify } from 'util'; import glob from 'fast-glob'; import { sleep, jsonParse } from 'n8n-workflow'; @@ -31,7 +30,6 @@ import { BaseCommand } from './BaseCommand'; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires const open = require('open'); -const pipeline = promisify(stream.pipeline); export class Start extends BaseCommand { static description = 'Starts n8n. Makes Web-UI available and starts active workflows'; diff --git a/packages/node-dev/commands/new.ts b/packages/node-dev/commands/new.ts index 217ca21ba4148f..0912578936c99f 100644 --- a/packages/node-dev/commands/new.ts +++ b/packages/node-dev/commands/new.ts @@ -4,17 +4,12 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { Command } from '@oclif/core'; import * as changeCase from 'change-case'; -import * as fs from 'fs'; +import { access } from 'fs/promises'; import * as inquirer from 'inquirer'; import { join } from 'path'; import { createTemplate } from '../src'; -// eslint-disable-next-line @typescript-eslint/no-var-requires -const { promisify } = require('util'); - -const fsAccess = promisify(fs.access); - export class New extends Command { static description = 'Create new credentials/node'; @@ -113,7 +108,7 @@ export class New extends Command { // Check if node with the same name already exists in target folder // to not overwrite it by accident try { - await fsAccess(destinationFilePath); + await access(destinationFilePath); // File does already exist. So ask if it should be overwritten. const overwriteQuestion: inquirer.QuestionCollection = [ diff --git a/packages/node-dev/src/Create.ts b/packages/node-dev/src/Create.ts index b24fd7a5bda189..fffa2f66fc5ed3 100644 --- a/packages/node-dev/src/Create.ts +++ b/packages/node-dev/src/Create.ts @@ -1,13 +1,7 @@ -import * as fs from 'fs'; +import { copyFile } from 'fs/promises'; import type { ReplaceInFileConfig } from 'replace-in-file'; import { replaceInFile } from 'replace-in-file'; -// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires -const { promisify } = require('util'); - -// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call -const fsCopyFile = promisify(fs.copyFile); - /** * Creates a new credentials or node * @@ -22,7 +16,7 @@ export async function createTemplate( ): Promise { // Copy the file to then replace the values in it // eslint-disable-next-line @typescript-eslint/no-unsafe-call - await fsCopyFile(sourceFilePath, destinationFilePath); + await copyFile(sourceFilePath, destinationFilePath); // Replace the variables in the template file const options: ReplaceInFileConfig = { diff --git a/packages/nodes-base/nodes/Crypto/Crypto.node.ts b/packages/nodes-base/nodes/Crypto/Crypto.node.ts index e95ff7ef657636..5ce4ba5dcde6f5 100644 --- a/packages/nodes-base/nodes/Crypto/Crypto.node.ts +++ b/packages/nodes-base/nodes/Crypto/Crypto.node.ts @@ -1,7 +1,8 @@ import type { BinaryToTextEncoding } from 'crypto'; import { createHash, createHmac, createSign, getHashes, randomBytes } from 'crypto'; -import stream from 'stream'; -import { promisify } from 'util'; +import { pipeline } from 'stream/promises'; +import { v4 as uuid } from 'uuid'; +import set from 'lodash/set'; import type { IExecuteFunctions, INodeExecutionData, @@ -10,11 +11,6 @@ import type { JsonObject, } from 'n8n-workflow'; import { deepCopy, BINARY_ENCODING } from 'n8n-workflow'; -import set from 'lodash/set'; - -import { v4 as uuid } from 'uuid'; - -const pipeline = promisify(stream.pipeline); const unsupportedAlgorithms = [ 'RSA-MD4', diff --git a/packages/nodes-base/nodes/EditImage/EditImage.node.ts b/packages/nodes-base/nodes/EditImage/EditImage.node.ts index 7288b55776c7d7..867bfd64b01879 100644 --- a/packages/nodes-base/nodes/EditImage/EditImage.node.ts +++ b/packages/nodes-base/nodes/EditImage/EditImage.node.ts @@ -1,6 +1,5 @@ import { parse as pathParse } from 'path'; -import { writeFile as fsWriteFile } from 'fs'; -import { promisify } from 'util'; +import { writeFile as fsWriteFile, type FileHandle } from 'fs/promises'; import type { IDataObject, IExecuteFunctions, @@ -14,7 +13,6 @@ import type { import { deepCopy } from 'n8n-workflow'; import gm from 'gm'; import { file } from 'tmp-promise'; -const fsWriteFileAsync = promisify(fsWriteFile); import getSystemFonts from 'get-system-fonts'; const nodeOperations: INodePropertyOptions[] = [ @@ -1117,9 +1115,9 @@ export class EditImage implements INodeType { binaryPropertyName, ); - const { fd, path, cleanup } = await file(); + const { path, cleanup } = await file(); cleanupFunctions.push(cleanup); - await fsWriteFileAsync(fd, binaryDataBuffer); + await fsWriteFile(path, binaryDataBuffer); if (operations[0].operation === 'create') { // It seems like if the image gets created newly we have to create a new gm instance diff --git a/packages/nodes-base/nodes/Ftp/Ftp.node.ts b/packages/nodes-base/nodes/Ftp/Ftp.node.ts index 70f3ed726ae4d5..5913605692e6c0 100644 --- a/packages/nodes-base/nodes/Ftp/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp/Ftp.node.ts @@ -1,8 +1,10 @@ import { createWriteStream } from 'fs'; import { basename, dirname } from 'path'; import type { Readable } from 'stream'; -import { pipeline } from 'stream'; -import { promisify } from 'util'; +import { pipeline } from 'stream/promises'; +import { file as tmpFile } from 'tmp-promise'; +import ftpClient from 'promise-ftp'; +import sftpClient from 'ssh2-sftp-client'; import { BINARY_ENCODING, NodeApiError } from 'n8n-workflow'; import type { ICredentialDataDecryptedObject, @@ -16,10 +18,6 @@ import type { INodeTypeDescription, JsonObject, } from 'n8n-workflow'; -import { file as tmpFile } from 'tmp-promise'; - -import ftpClient from 'promise-ftp'; -import sftpClient from 'ssh2-sftp-client'; import { formatPrivateKey } from '@utils/utilities'; interface ReturnFtpItem { @@ -40,8 +38,6 @@ interface ReturnFtpItem { path: string; } -const streamPipeline = promisify(pipeline); - async function callRecursiveList( path: string, client: sftpClient | ftpClient, @@ -722,7 +718,7 @@ export class Ftp implements INodeType { const binaryFile = await tmpFile({ prefix: 'n8n-sftp-' }); try { const stream = await ftp!.get(path); - await streamPipeline(stream, createWriteStream(binaryFile.path)); + await pipeline(stream, createWriteStream(binaryFile.path)); const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i); const remoteFilePath = this.getNodeParameter('path', i) as string;