mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
refactor(core): Replace promisify-d node calls with native promises (no-changelog) (#8464)
This commit is contained in:
parent
238b54c77b
commit
5cb55270b7
5
.github/scripts/check-tests.mjs
vendored
5
.github/scripts/check-tests.mjs
vendored
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -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<void> {
|
||||
// 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 = {
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { parse as pathParse } from 'path';
|
||||
import { writeFile as fsWriteFile } from 'fs';
|
||||
import { promisify } from 'util';
|
||||
import { writeFile as fsWriteFile } 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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue