mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 00:54:06 -08:00
11 lines
375 B
TypeScript
11 lines
375 B
TypeScript
import { createContext, Script } from 'vm';
|
|
|
|
const context = createContext({ require });
|
|
export const loadClassInIsolation = <T>(filePath: string, className: string) => {
|
|
if (process.platform === 'win32') {
|
|
filePath = filePath.replace(/\\/g, '/');
|
|
}
|
|
const script = new Script(`new (require('${filePath}').${className})()`);
|
|
return script.runInContext(context) as T;
|
|
};
|