mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
Make n8n work with older node versions (<10)
This commit is contained in:
parent
b53d4c56ae
commit
034c70f6ab
|
@ -1,6 +1,5 @@
|
|||
import Vorpal = require('vorpal');
|
||||
import { Args } from 'vorpal';
|
||||
import { randomBytes } from 'crypto';
|
||||
import * as config from 'config';
|
||||
|
||||
const open = require('open');
|
||||
|
|
|
@ -10,12 +10,21 @@ import {
|
|||
IN8nConfigNodes,
|
||||
} from './';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as glob from 'glob-promise';
|
||||
|
||||
import * as config from 'config';
|
||||
import {
|
||||
access as fsAccess,
|
||||
readdir as fsReaddir,
|
||||
readFile as fsReadFile,
|
||||
stat as fsStat,
|
||||
} from 'fs';
|
||||
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 {
|
||||
|
@ -43,7 +52,7 @@ class LoadNodesAndCredentialsClass {
|
|||
];
|
||||
for (const checkPath of checkPaths) {
|
||||
try {
|
||||
await fs.access(checkPath);
|
||||
await fsAccessAsync(checkPath);
|
||||
// Folder exists, so use it.
|
||||
this.nodeModulesPath = path.dirname(checkPath);
|
||||
break;
|
||||
|
@ -96,13 +105,13 @@ class LoadNodesAndCredentialsClass {
|
|||
*/
|
||||
async getN8nNodePackages(): Promise<string[]> {
|
||||
const packages: string[] = [];
|
||||
for (const file of await fs.readdir(this.nodeModulesPath)) {
|
||||
for (const file of await fsReaddirAsync(this.nodeModulesPath)) {
|
||||
if (file.indexOf('n8n-nodes-') !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if it is really a folder
|
||||
if (!(await fs.stat(path.join(this.nodeModulesPath, file))).isDirectory()) {
|
||||
if (!(await fsStatAsync(path.join(this.nodeModulesPath, file))).isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -219,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 fs.readFile(path.join(packagePath, 'package.json'), 'utf8');
|
||||
const packageFileString = await fsReadFileAsync(path.join(packagePath, 'package.json'), 'utf8');
|
||||
const packageFile = JSON.parse(packageFileString);
|
||||
if (!packageFile.hasOwnProperty('n8n')) {
|
||||
return;
|
||||
|
|
|
@ -5,7 +5,12 @@ import {
|
|||
INodeType,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import {
|
||||
readFile as fsReadFile,
|
||||
} from 'fs';
|
||||
import { promisify } from "util";
|
||||
|
||||
const fsReadFileAsync = promisify(fsReadFile);
|
||||
|
||||
|
||||
export class ReadBinaryFile implements INodeType {
|
||||
|
@ -55,7 +60,7 @@ export class ReadBinaryFile implements INodeType {
|
|||
|
||||
let data;
|
||||
try {
|
||||
data = await fs.readFile(filePath) as Buffer;
|
||||
data = await fsReadFileAsync(filePath) as Buffer;
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT') {
|
||||
throw new Error(`The file "${filePath}" could not be found.`);
|
||||
|
|
|
@ -4,10 +4,17 @@ import {
|
|||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as glob from 'glob-promise';
|
||||
import * as path from 'path';
|
||||
|
||||
import {
|
||||
readFile as fsReadFile,
|
||||
} from 'fs';
|
||||
import { promisify } from "util";
|
||||
|
||||
const fsReadFileAsync = promisify(fsReadFile);
|
||||
|
||||
|
||||
export class ReadBinaryFiles implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Read Binary Files',
|
||||
|
@ -56,7 +63,7 @@ export class ReadBinaryFiles implements INodeType {
|
|||
let data: Buffer;
|
||||
let fileName: string;
|
||||
for (const filePath of files) {
|
||||
data = await fs.readFile(filePath) as Buffer;
|
||||
data = await fsReadFileAsync(filePath) as Buffer;
|
||||
|
||||
fileName = path.parse(filePath).base;
|
||||
item = {
|
||||
|
|
|
@ -8,7 +8,13 @@ import {
|
|||
INodeExecutionData,
|
||||
INodeType,
|
||||
} from 'n8n-workflow';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
import {
|
||||
writeFile as fsWriteFile,
|
||||
} from 'fs';
|
||||
import { promisify } from "util";
|
||||
|
||||
const fsWriteFileAsync = promisify(fsWriteFile);
|
||||
|
||||
|
||||
export class WriteBinaryFile implements INodeType {
|
||||
|
@ -62,7 +68,7 @@ export class WriteBinaryFile implements INodeType {
|
|||
}
|
||||
|
||||
// Write the file to disk
|
||||
await fs.writeFile(fileName, Buffer.from(item.binary[dataPropertyName].data, BINARY_ENCODING), 'binary');
|
||||
await fsWriteFileAsync(fileName, Buffer.from(item.binary[dataPropertyName].data, BINARY_ENCODING), 'binary');
|
||||
|
||||
if (item.json === undefined) {
|
||||
item.json = {};
|
||||
|
|
Loading…
Reference in a new issue