diff --git a/fillNativeModules.js b/fillNativeModules.js index 82f3ace8..780292b5 100644 --- a/fillNativeModules.js +++ b/fillNativeModules.js @@ -2,7 +2,6 @@ const fs = require('fs'); let fillContent = ''; -// if (!process.argv.includes('--electron')) { if (process.platform == 'win32') { fillContent += `content.msnodesqlv8 = () => require('msnodesqlv8');`; } diff --git a/packages/api/src/controllers/connections.js b/packages/api/src/controllers/connections.js index cedf0b79..c937418c 100644 --- a/packages/api/src/controllers/connections.js +++ b/packages/api/src/controllers/connections.js @@ -46,7 +46,7 @@ module.exports = { raw: true, }, test(req, res) { - const subprocess = fork(process.argv[1], ['connectProcess', ...process.argv.slice(3)]); + const subprocess = fork(process.argv[1], ['--start-process', 'connectProcess', ...process.argv.slice(3)]); subprocess.on('message', resp => { if (handleProcessCommunication(resp, subprocess)) return; // @ts-ignore diff --git a/packages/api/src/controllers/databaseConnections.js b/packages/api/src/controllers/databaseConnections.js index 62cd560c..5b8c5b1f 100644 --- a/packages/api/src/controllers/databaseConnections.js +++ b/packages/api/src/controllers/databaseConnections.js @@ -40,7 +40,11 @@ module.exports = { const existing = this.opened.find(x => x.conid == conid && x.database == database); if (existing) return existing; const connection = await connections.get({ conid }); - const subprocess = fork(process.argv[1], ['databaseConnectionProcess', ...process.argv.slice(3)]); + const subprocess = fork(process.argv[1], [ + '--start-process', + 'databaseConnectionProcess', + ...process.argv.slice(3), + ]); const lastClosed = this.closed[`${conid}/${database}`]; const newOpened = { conid, @@ -127,7 +131,7 @@ module.exports = { } else { existing = await this.ensureOpened(conid, database); } - + return { status: 'ok', connectionStatus: existing ? existing.status : null, diff --git a/packages/api/src/controllers/serverConnections.js b/packages/api/src/controllers/serverConnections.js index 41683a37..527992b8 100644 --- a/packages/api/src/controllers/serverConnections.js +++ b/packages/api/src/controllers/serverConnections.js @@ -30,7 +30,11 @@ module.exports = { const existing = this.opened.find(x => x.conid == conid); if (existing) return existing; const connection = await connections.get({ conid }); - const subprocess = fork(process.argv[1], ['serverConnectionProcess', ...process.argv.slice(3)]); + const subprocess = fork(process.argv[1], [ + '--start-process', + 'serverConnectionProcess', + ...process.argv.slice(3), + ]); const newOpened = { conid, subprocess, diff --git a/packages/api/src/controllers/sessions.js b/packages/api/src/controllers/sessions.js index d33d4ba8..cf066e5b 100644 --- a/packages/api/src/controllers/sessions.js +++ b/packages/api/src/controllers/sessions.js @@ -65,7 +65,7 @@ module.exports = { async create({ conid, database }) { const sesid = uuidv1(); const connection = await connections.get({ conid }); - const subprocess = fork(process.argv[1], ['sessionProcess', ...process.argv.slice(3)]); + const subprocess = fork(process.argv[1], ['--start-process', 'sessionProcess', ...process.argv.slice(3)]); const newOpened = { conid, database, diff --git a/packages/api/src/index.js b/packages/api/src/index.js index 8f740c07..87e072da 100644 --- a/packages/api/src/index.js +++ b/packages/api/src/index.js @@ -1,15 +1,14 @@ const shell = require('./shell'); +const processArgs = require('./utility/processArgs'); -const argument = process.argv[2]; -if (argument && argument.endsWith('Process')) { +if (processArgs.startProcess) { const proc = require('./proc'); - - const module = proc[argument]; + const module = proc[processArgs.startProcess]; module.start(); -} else if (!module['parent'] && !process.argv.includes('--checkParent')) { +} else if (!module['parent'] && !processArgs.checkParent) { const main = require('./main'); - main.start(argument); + main.start(); } module.exports = { diff --git a/packages/api/src/main.js b/packages/api/src/main.js index c60368b0..044f2308 100644 --- a/packages/api/src/main.js +++ b/packages/api/src/main.js @@ -29,8 +29,9 @@ const scheduler = require('./controllers/scheduler'); const { rundir } = require('./utility/directories'); const platformInfo = require('./utility/platformInfo'); +const processArgs = require('./utility/processArgs'); -function start(argument = null) { +function start() { // console.log('process.argv', process.argv); const app = express(); @@ -91,7 +92,7 @@ function start(argument = null) { } } - if (argument == '--dynport') { + if (processArgs.dynport) { childProcessChecker(); findFreePort(53911, function (err, port) { diff --git a/packages/api/src/shell/runScript.js b/packages/api/src/shell/runScript.js index 859dfd7b..6b5fb2a5 100644 --- a/packages/api/src/shell/runScript.js +++ b/packages/api/src/shell/runScript.js @@ -1,7 +1,8 @@ const childProcessChecker = require('../utility/childProcessChecker'); +const processArgs = require('../utility/processArgs'); async function runScript(func) { - if (process.argv.includes('--checkParent')) { + if (processArgs.checkParent) { childProcessChecker(); } try { diff --git a/packages/api/src/utility/DatastoreProxy.js b/packages/api/src/utility/DatastoreProxy.js index 6f2a3113..e7e23fe7 100644 --- a/packages/api/src/utility/DatastoreProxy.js +++ b/packages/api/src/utility/DatastoreProxy.js @@ -29,7 +29,7 @@ class DatastoreProxy { async ensureSubprocess() { if (!this.subprocess) { - this.subprocess = fork(process.argv[1], ['jslDatastoreProcess', ...process.argv.slice(3)]); + this.subprocess = fork(process.argv[1], ['--start-process', 'jslDatastoreProcess', ...process.argv.slice(3)]); this.subprocess.on('message', message => { // @ts-ignore diff --git a/packages/api/src/utility/platformInfo.js b/packages/api/src/utility/platformInfo.js index e2e35e89..2141df45 100644 --- a/packages/api/src/utility/platformInfo.js +++ b/packages/api/src/utility/platformInfo.js @@ -1,15 +1,15 @@ const fs = require('fs'); const os = require('os'); const path = require('path'); +const processArgs = require('./processArgs'); -const p = process; -const platform = p.env.OS_OVERRIDE ? p.env.OS_OVERRIDE : p.platform; +const platform = process.env.OS_OVERRIDE ? process.env.OS_OVERRIDE : process.platform; const isWindows = platform === 'win32'; const isMac = platform === 'darwin'; const isLinux = platform === 'linux'; const isDocker = fs.existsSync('/home/dbgate-docker/public'); -const isDevMode = p.env.DEVMODE == '1'; -const isNpmDist = p.argv[2] == 'startNodeWeb'; +const isDevMode = process.env.DEVMODE == '1'; +const isNpmDist = !!global['dbgateApiModulePath']; // function moduleAvailable(name) { // try { @@ -20,7 +20,7 @@ const isNpmDist = p.argv[2] == 'startNodeWeb'; // } // } -const isElectronBundle = p.argv.indexOf('--is-electron-bundle') >= 0; +const isElectronBundle = processArgs.isElectronBundle; const platformInfo = { isWindows, @@ -30,13 +30,13 @@ const platformInfo = { isElectronBundle, isDevMode, isNpmDist, - isSnap: p.env.ELECTRON_SNAP == 'true', - isPortable: isWindows && p.env.PORTABLE_EXECUTABLE_DIR, - isAppImage: p.env.DESKTOPINTEGRATION === 'AppImageLauncher', - sshAuthSock: p.env.SSH_AUTH_SOCK, + isSnap: process.env.ELECTRON_SNAP == 'true', + isPortable: isWindows && process.env.PORTABLE_EXECUTABLE_DIR, + isAppImage: process.env.DESKTOPINTEGRATION === 'AppImageLauncher', + sshAuthSock: process.env.SSH_AUTH_SOCK, environment: process.env.NODE_ENV, platform, - runningInWebpack: !!p.env.WEBPACK_DEV_SERVER_URL, + runningInWebpack: !!process.env.WEBPACK_DEV_SERVER_URL, defaultKeyFile: path.join(os.homedir(), '.ssh/id_rsa'), }; diff --git a/packages/api/src/utility/processArgs.js b/packages/api/src/utility/processArgs.js new file mode 100644 index 00000000..e93fb0b4 --- /dev/null +++ b/packages/api/src/utility/processArgs.js @@ -0,0 +1,21 @@ +function getNamedArg(name) { + const argIndex = process.argv.indexOf(name); + if (argIndex > 0) { + return process.argv[argIndex + 1]; + } + return null; +} + +const checkParent = process.argv.includes('--checkParent'); +const dynport = process.argv.includes('--dynport'); +const nativeModules = getNamedArg('--native-modules'); +const startProcess = getNamedArg('--start-process'); +const isElectronBundle = process.argv.includes('--is-electron-bundle'); + +module.exports = { + checkParent, + nativeModules, + startProcess, + dynport, + isElectronBundle, +}; diff --git a/packages/dbgate/bin/dbgate.js b/packages/dbgate/bin/dbgate.js index 81c01649..60e7d19e 100755 --- a/packages/dbgate/bin/dbgate.js +++ b/packages/dbgate/bin/dbgate.js @@ -6,4 +6,4 @@ const dbgateApi = require('dbgate-api'); global.dbgateApiModulePath = require.resolve('dbgate-api'); global.dbgateApiPackagedPluginsPath = path.dirname(global.dbgateApiModulePath); -dbgateApi.getMainModule().start('startNodeWeb'); +dbgateApi.getMainModule().start();