fix: Fix Windows development environments (no-changelog) (#4720)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2022-11-24 17:36:57 +01:00 committed by GitHub
parent 07e4743a3e
commit aec08275aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,25 +2,23 @@
const path = require('path'); const path = require('path');
const glob = require('fast-glob'); const glob = require('fast-glob');
const { createContext, Script } = require('vm');
const { LoggerProxy } = require('n8n-workflow'); const { LoggerProxy } = require('n8n-workflow');
const { packageDir, writeJSON } = require('./common'); const { packageDir, writeJSON } = require('./common');
const { loadClassInIsolation } = require('../dist/ClassLoader');
LoggerProxy.init({ LoggerProxy.init({
log: console.log.bind(console), log: console.log.bind(console),
warn: console.warn.bind(console), warn: console.warn.bind(console),
}); });
const context = Object.freeze(createContext({ require }));
const loadClass = (sourcePath) => { const loadClass = (sourcePath) => {
try { try {
const [className] = path.parse(sourcePath).name.split('.'); const [className] = path.parse(sourcePath).name.split('.');
const absolutePath = path.resolve(packageDir, sourcePath); const filePath = path.resolve(packageDir, sourcePath);
const script = new Script(`new (require('${absolutePath}').${className})()`); const instance = loadClassInIsolation(filePath, className);
const instance = script.runInContext(context);
return { instance, sourcePath, className }; return { instance, sourcePath, className };
} catch (e) { } catch (e) {
LoggerProxy.warn('Failed to load %s: %s', sourcePath, e.message); LoggerProxy.warn(`Failed to load ${sourcePath}: ${e.message}`);
} }
}; };