mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-12 15:44:06 -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 Vorpal = require('vorpal');
|
||||||
import { Args } from 'vorpal';
|
import { Args } from 'vorpal';
|
||||||
import { randomBytes } from 'crypto';
|
|
||||||
import * as config from 'config';
|
import * as config from 'config';
|
||||||
|
|
||||||
const open = require('open');
|
const open = require('open');
|
||||||
|
|
|
@ -10,12 +10,21 @@ import {
|
||||||
IN8nConfigNodes,
|
IN8nConfigNodes,
|
||||||
} from './';
|
} from './';
|
||||||
|
|
||||||
import { promises as fs } from 'fs';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as glob from 'glob-promise';
|
|
||||||
|
|
||||||
import * as config from 'config';
|
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 {
|
class LoadNodesAndCredentialsClass {
|
||||||
|
@ -43,7 +52,7 @@ class LoadNodesAndCredentialsClass {
|
||||||
];
|
];
|
||||||
for (const checkPath of checkPaths) {
|
for (const checkPath of checkPaths) {
|
||||||
try {
|
try {
|
||||||
await fs.access(checkPath);
|
await fsAccessAsync(checkPath);
|
||||||
// Folder exists, so use it.
|
// Folder exists, so use it.
|
||||||
this.nodeModulesPath = path.dirname(checkPath);
|
this.nodeModulesPath = path.dirname(checkPath);
|
||||||
break;
|
break;
|
||||||
|
@ -96,13 +105,13 @@ class LoadNodesAndCredentialsClass {
|
||||||
*/
|
*/
|
||||||
async getN8nNodePackages(): Promise<string[]> {
|
async getN8nNodePackages(): Promise<string[]> {
|
||||||
const packages: 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) {
|
if (file.indexOf('n8n-nodes-') !== 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it is really a folder
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +228,7 @@ class LoadNodesAndCredentialsClass {
|
||||||
const packagePath = path.join(this.nodeModulesPath, packageName);
|
const packagePath = path.join(this.nodeModulesPath, packageName);
|
||||||
|
|
||||||
// Read the data from the package.json file to see if any n8n data is defiend
|
// 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);
|
const packageFile = JSON.parse(packageFileString);
|
||||||
if (!packageFile.hasOwnProperty('n8n')) {
|
if (!packageFile.hasOwnProperty('n8n')) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -5,7 +5,12 @@ import {
|
||||||
INodeType,
|
INodeType,
|
||||||
} from 'n8n-workflow';
|
} 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 {
|
export class ReadBinaryFile implements INodeType {
|
||||||
|
@ -55,7 +60,7 @@ export class ReadBinaryFile implements INodeType {
|
||||||
|
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = await fs.readFile(filePath) as Buffer;
|
data = await fsReadFileAsync(filePath) as Buffer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ENOENT') {
|
if (error.code === 'ENOENT') {
|
||||||
throw new Error(`The file "${filePath}" could not be found.`);
|
throw new Error(`The file "${filePath}" could not be found.`);
|
||||||
|
|
|
@ -4,10 +4,17 @@ import {
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
import { promises as fs } from 'fs';
|
|
||||||
import * as glob from 'glob-promise';
|
import * as glob from 'glob-promise';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
import {
|
||||||
|
readFile as fsReadFile,
|
||||||
|
} from 'fs';
|
||||||
|
import { promisify } from "util";
|
||||||
|
|
||||||
|
const fsReadFileAsync = promisify(fsReadFile);
|
||||||
|
|
||||||
|
|
||||||
export class ReadBinaryFiles implements INodeType {
|
export class ReadBinaryFiles implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Read Binary Files',
|
displayName: 'Read Binary Files',
|
||||||
|
@ -56,7 +63,7 @@ export class ReadBinaryFiles implements INodeType {
|
||||||
let data: Buffer;
|
let data: Buffer;
|
||||||
let fileName: string;
|
let fileName: string;
|
||||||
for (const filePath of files) {
|
for (const filePath of files) {
|
||||||
data = await fs.readFile(filePath) as Buffer;
|
data = await fsReadFileAsync(filePath) as Buffer;
|
||||||
|
|
||||||
fileName = path.parse(filePath).base;
|
fileName = path.parse(filePath).base;
|
||||||
item = {
|
item = {
|
||||||
|
|
|
@ -8,7 +8,13 @@ import {
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
INodeType,
|
||||||
} from 'n8n-workflow';
|
} 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 {
|
export class WriteBinaryFile implements INodeType {
|
||||||
|
@ -62,7 +68,7 @@ export class WriteBinaryFile implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the file to disk
|
// 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) {
|
if (item.json === undefined) {
|
||||||
item.json = {};
|
item.json = {};
|
||||||
|
|
Loading…
Reference in a new issue