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