n8n/packages/core/src/ClassLoader.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

11 lines
375 B
TypeScript
Raw Normal View History

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;
};