mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
feat(cli): Load all nodes and credentials code in isolation - N8N-4362 (#3906)
[N8N-4362] Load all nodes and credentials code in isolation Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9267e8fb12
commit
b450e977a3
@@ -4,7 +4,7 @@
|
||||
import { promisify } from 'util';
|
||||
import { exec } from 'child_process';
|
||||
import { access as fsAccess, mkdir as fsMkdir } from 'fs/promises';
|
||||
|
||||
import { createContext, Script } from 'vm';
|
||||
import axios from 'axios';
|
||||
import { UserSettings } from 'n8n-core';
|
||||
import { LoggerProxy, PublicInstalledPackage } from 'n8n-workflow';
|
||||
@@ -235,3 +235,10 @@ export const isClientError = (error: Error): boolean => {
|
||||
export function isNpmError(error: unknown): error is { code: number; stdout: string } {
|
||||
return typeof error === 'object' && error !== null && 'code' in error && 'stdout' in error;
|
||||
}
|
||||
|
||||
const context = createContext({ require });
|
||||
export const loadClassInIsolation = (filePath: string, className: string) => {
|
||||
const script = new Script(`new (require('${filePath}').${className})()`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return script.runInContext(context);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user