From 89dbf3896292ea55e1021c1a13bf6598bffa3636 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 14 Feb 2021 11:09:49 +0100 Subject: [PATCH] try to fix export in electron --- packages/api/src/controllers/runners.js | 6 +++--- packages/api/src/shell/index.js | 4 ++-- ...rocessCommunication.js => initializeApiEnvironment.js} | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) rename packages/api/src/shell/{registerProcessCommunication.js => initializeApiEnvironment.js} (50%) diff --git a/packages/api/src/controllers/runners.js b/packages/api/src/controllers/runners.js index e1c9a225..0abb6466 100644 --- a/packages/api/src/controllers/runners.js +++ b/packages/api/src/controllers/runners.js @@ -24,7 +24,7 @@ const requirePluginsTemplate = plugins => const scriptTemplate = script => ` const dbgateApi = require(process.env.DBGATE_API); -dbgateApi.registerProcessCommunication(); +dbgateApi.initializeApiEnvironment(); ${requirePluginsTemplate(extractPlugins(script))} require=null; async function run() { @@ -37,7 +37,7 @@ dbgateApi.runScript(run); const loaderScriptTemplate = (functionName, props, runid) => ` const dbgateApi = require(process.env.DBGATE_API); -dbgateApi.registerProcessCommunication(); +dbgateApi.initializeApiEnvironment(); ${requirePluginsTemplate(extractShellApiPlugins(functionName, props))} require=null; async function run() { @@ -96,10 +96,10 @@ module.exports = { console.log(`RUNNING SCRIPT ${scriptFile}`); // const subprocess = fork(scriptFile, ['--checkParent', '--max-old-space-size=8192'], { const subprocess = fork(scriptFile, ['--checkParent', ...process.argv.slice(3)], { - cwd: directory, stdio: ['ignore', 'pipe', 'pipe', 'ipc'], env: { DBGATE_API: process.argv[1], + DBGATE_CWD: directory, ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, path.join(pluginsdir(), name)])), }, }); diff --git a/packages/api/src/shell/index.js b/packages/api/src/shell/index.js index 492adc6f..fe965257 100644 --- a/packages/api/src/shell/index.js +++ b/packages/api/src/shell/index.js @@ -17,7 +17,7 @@ const requirePlugin = require('./requirePlugin'); const download = require('./download'); const executeQuery = require('./executeQuery'); const loadFile = require('./loadFile'); -const registerProcessCommunication = require('./registerProcessCommunication'); +const initializeApiEnvironment = require('./initializeApiEnvironment'); const dbgateApi = { queryReader, @@ -38,7 +38,7 @@ const dbgateApi = { registerPlugins, executeQuery, loadFile, - registerProcessCommunication, + initializeApiEnvironment, }; requirePlugin.initializeDbgateApi(dbgateApi); diff --git a/packages/api/src/shell/registerProcessCommunication.js b/packages/api/src/shell/initializeApiEnvironment.js similarity index 50% rename from packages/api/src/shell/registerProcessCommunication.js rename to packages/api/src/shell/initializeApiEnvironment.js index d090bd7c..5b6d14cf 100644 --- a/packages/api/src/shell/registerProcessCommunication.js +++ b/packages/api/src/shell/initializeApiEnvironment.js @@ -1,9 +1,13 @@ const { handleProcessCommunication } = require('../utility/processComm'); -async function registerProcessCommunication() { +async function initializeApiEnvironment() { process.on('message', async message => { handleProcessCommunication(message); }); + + if (process.env.DBGATE_CWD) { + process.chdir(process.env.DBGATE_CWD); + } } -module.exports = registerProcessCommunication; +module.exports = initializeApiEnvironment;