From 516d007c22bf9ecc414c08128d72fa605804517f Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 17 Apr 2021 17:31:32 +0200 Subject: [PATCH] fix --- packages/api/src/controllers/runners.js | 4 ++-- packages/api/src/shell/requirePlugin.js | 17 ++--------------- packages/api/src/utility/directories.js | 14 ++++++++++---- plugins/dbgate-plugin-csv/package.json | 1 + plugins/dbgate-plugin-excel/package.json | 1 + plugins/dbgate-plugin-mongo/package.json | 1 + plugins/dbgate-plugin-mssql/package.json | 1 + plugins/dbgate-plugin-mysql/package.json | 1 + plugins/dbgate-plugin-postgres/package.json | 1 + 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/api/src/controllers/runners.js b/packages/api/src/controllers/runners.js index d239031b..9daa640e 100644 --- a/packages/api/src/controllers/runners.js +++ b/packages/api/src/controllers/runners.js @@ -5,7 +5,7 @@ const uuidv1 = require('uuid/v1'); const byline = require('byline'); const socket = require('../utility/socket'); const { fork } = require('child_process'); -const { rundir, uploadsdir, pluginsdir, getPluginPath, packagedPluginList } = require('../utility/directories'); +const { rundir, uploadsdir, pluginsdir, getPluginBackendPath, packagedPluginList } = require('../utility/directories'); const { extractShellApiPlugins, extractShellApiFunctionName } = require('dbgate-tools'); const { handleProcessCommunication } = require('../utility/processComm'); @@ -101,7 +101,7 @@ module.exports = { env: { ...process.env, DBGATE_API: global['dbgateApiModulePath'] || process.argv[1], - ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginPath(name)])), + ..._.fromPairs(pluginNames.map(name => [`PLUGIN_${_.camelCase(name)}`, getPluginBackendPath(name)])), }, }); const pipeDispatcher = severity => data => diff --git a/packages/api/src/shell/requirePlugin.js b/packages/api/src/shell/requirePlugin.js index fdc1b2f5..7ed0b557 100644 --- a/packages/api/src/shell/requirePlugin.js +++ b/packages/api/src/shell/requirePlugin.js @@ -1,6 +1,6 @@ const path = require('path'); const fs = require('fs'); -const { pluginsdir, packagedPluginsDir } = require('../utility/directories'); +const { pluginsdir, packagedPluginsDir, getPluginBackendPath } = require('../utility/directories'); const nativeModules = require('../nativeModules'); const platformInfo = require('../utility/platformInfo'); @@ -10,26 +10,13 @@ const dbgateEnv = { dbgateApi: null, nativeModules, }; - -function getModulePath(packageName) { - const packagedModulePath = platformInfo.isDevMode - ? path.join(packagedPluginsDir(), packageName, 'src', 'backend', 'index.js') - : path.join(packagedPluginsDir(), packageName, 'dist', 'backend.js'); - - if (fs.existsSync(packagedModulePath)) { - return packagedModulePath; - } - - return path.join(pluginsdir(), packageName, 'dist', 'backend.js'); -} - function requirePlugin(packageName, requiredPlugin = null) { if (!packageName) throw new Error('Missing packageName in plugin'); if (loadedPlugins[packageName]) return loadedPlugins[packageName]; if (requiredPlugin == null) { let module; - const modulePath = getModulePath(packageName); + const modulePath = getPluginBackendPath(packageName); console.log(`Loading module ${packageName} from ${modulePath}`); try { // @ts-ignore diff --git a/packages/api/src/utility/directories.js b/packages/api/src/utility/directories.js index 2a178109..e318c159 100644 --- a/packages/api/src/utility/directories.js +++ b/packages/api/src/utility/directories.js @@ -60,9 +60,15 @@ function packagedPluginsDir() { const packagedPluginList = packagedPluginsDir() != null ? fs.readdirSync(packagedPluginsDir()).filter(x => x.startsWith('dbgate-plugin-')) : []; -function getPluginPath(packageName) { - if (packagedPluginList.includes(packageName)) return path.join(packagedPluginsDir(), packageName); - return path.join(pluginsdir(), packageName); +function getPluginBackendPath(packageName) { + if (packagedPluginList.includes(packageName)) { + if (platformInfo.isDevMode) { + return path.join(packagedPluginsDir(), packageName, 'src', 'backend', 'index.js'); + } + return path.join(packagedPluginsDir(), packageName, 'dist', 'backend.js'); + } + + return path.join(pluginsdir(), packageName, 'dist', 'backend.js'); } module.exports = { @@ -76,5 +82,5 @@ module.exports = { filesdir, packagedPluginsDir, packagedPluginList, - getPluginPath, + getPluginBackendPath, }; diff --git a/plugins/dbgate-plugin-csv/package.json b/plugins/dbgate-plugin-csv/package.json index 80199736..0d58f2a7 100644 --- a/plugins/dbgate-plugin-csv/package.json +++ b/plugins/dbgate-plugin-csv/package.json @@ -18,6 +18,7 @@ "dbgateplugin" ], "files": [ + "src", "dist", "icon.svg" ], diff --git a/plugins/dbgate-plugin-excel/package.json b/plugins/dbgate-plugin-excel/package.json index 37696734..00c052ca 100644 --- a/plugins/dbgate-plugin-excel/package.json +++ b/plugins/dbgate-plugin-excel/package.json @@ -19,6 +19,7 @@ ], "files": [ "dist", + "src", "icon.svg" ], "scripts": { diff --git a/plugins/dbgate-plugin-mongo/package.json b/plugins/dbgate-plugin-mongo/package.json index d960c1a8..32f8920b 100644 --- a/plugins/dbgate-plugin-mongo/package.json +++ b/plugins/dbgate-plugin-mongo/package.json @@ -18,6 +18,7 @@ ], "files": [ "dist", + "src", "icon.svg" ], "scripts": { diff --git a/plugins/dbgate-plugin-mssql/package.json b/plugins/dbgate-plugin-mssql/package.json index 95fe02a0..8d7e437d 100644 --- a/plugins/dbgate-plugin-mssql/package.json +++ b/plugins/dbgate-plugin-mssql/package.json @@ -18,6 +18,7 @@ ], "files": [ "dist", + "src", "icon.svg" ], "scripts": { diff --git a/plugins/dbgate-plugin-mysql/package.json b/plugins/dbgate-plugin-mysql/package.json index bf577d7a..d62acbb9 100644 --- a/plugins/dbgate-plugin-mysql/package.json +++ b/plugins/dbgate-plugin-mysql/package.json @@ -18,6 +18,7 @@ ], "files": [ "dist", + "src", "icon.svg" ], "scripts": { diff --git a/plugins/dbgate-plugin-postgres/package.json b/plugins/dbgate-plugin-postgres/package.json index d2c2af46..ed570864 100644 --- a/plugins/dbgate-plugin-postgres/package.json +++ b/plugins/dbgate-plugin-postgres/package.json @@ -17,6 +17,7 @@ ], "files": [ "dist", + "src", "icon.svg" ], "scripts": {