From c06965c79fcd30629f88c34fa90d6230d4b2652f Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 17 Jan 2021 09:11:09 +0100 Subject: [PATCH] os dependend native modules --- .github/workflows/build-app.yaml | 3 +++ app/src/nativeModules.js | 10 ++-------- app/src/nativeModulesContent.js | 7 +++++++ fillNativeModules.js | 23 +++++++++++++++++++++++ package.json | 4 +++- packages/api/package.json | 4 +++- packages/api/src/nativeModules.js | 4 +--- packages/api/src/nativeModulesContent.js | 7 +++++++ 8 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 app/src/nativeModulesContent.js create mode 100644 fillNativeModules.js create mode 100644 packages/api/src/nativeModulesContent.js diff --git a/.github/workflows/build-app.yaml b/.github/workflows/build-app.yaml index 19850fcf..60b336d1 100644 --- a/.github/workflows/build-app.yaml +++ b/.github/workflows/build-app.yaml @@ -35,6 +35,9 @@ jobs: - name: setCurrentVersion run: | yarn setCurrentVersion + - name: fillNativeModulesElectron + run: | + yarn fillNativeModulesElectron - name: Publish run: | yarn run build:app diff --git a/app/src/nativeModules.js b/app/src/nativeModules.js index 70b8dd16..03a2f2c0 100644 --- a/app/src/nativeModules.js +++ b/app/src/nativeModules.js @@ -1,9 +1,3 @@ -const msnodesqlv8 = () => require('msnodesqlv8'); +const content = require('./nativeModulesContent'); -const win32Modules = { - msnodesqlv8, -}; - -module.exports = { - ...(process.platform == 'win32' ? win32Modules : {}), -}; +module.exports = content; diff --git a/app/src/nativeModulesContent.js b/app/src/nativeModulesContent.js new file mode 100644 index 00000000..b57b44e9 --- /dev/null +++ b/app/src/nativeModulesContent.js @@ -0,0 +1,7 @@ + +// this file is generated automatically by script fillNativeModules.js, do not edit it manually +const content = {}; + + + +module.exports = content; diff --git a/fillNativeModules.js b/fillNativeModules.js new file mode 100644 index 00000000..82f3ace8 --- /dev/null +++ b/fillNativeModules.js @@ -0,0 +1,23 @@ +const fs = require('fs'); + +let fillContent = ''; + +// if (!process.argv.includes('--electron')) { +if (process.platform == 'win32') { + fillContent += `content.msnodesqlv8 = () => require('msnodesqlv8');`; +} + +const getContent = (empty) => ` +// this file is generated automatically by script fillNativeModules.js, do not edit it manually +const content = {}; + +${empty ? '' : fillContent} + +module.exports = content; +`; + +fs.writeFileSync( + 'packages/api/src/nativeModulesContent.js', + getContent(process.argv.includes('--electron') ? true : false) +); +fs.writeFileSync('app/src/nativeModulesContent.js', getContent(false)); diff --git a/package.json b/package.json index feede77e..28572880 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,8 @@ "start:app:local": "cd app && yarn start:local", "setCurrentVersion": "node setCurrentVersion", "generatePadFile": "node generatePadFile", + "fillNativeModules": "node fillNativeModules", + "fillNativeModulesElectron": "node fillNativeModules --eletron", "copy:docker:build": "copyfiles packages/api/dist/* docker -f && copyfiles packages/web/build/* docker -u 2 && copyfiles \"packages/web/build/**/*\" docker -u 2", "prepare:docker": "yarn build:web:docker && yarn build:api && yarn copy:docker:build", @@ -35,7 +37,7 @@ "ts:api": "yarn workspace dbgate-api ts", "ts:web": "yarn workspace dbgate-web ts", "ts": "yarn ts:api && yarn ts:web", - "postinstall": "patch-package" + "postinstall": "patch-package && yarn fillNativeModules" }, "dependencies": { "concurrently": "^5.1.0", diff --git a/packages/api/package.json b/packages/api/package.json index ebca3349..508dbd2e 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -36,7 +36,6 @@ "http": "^0.0.0", "line-reader": "^0.4.0", "lodash": "^4.17.15", - "msnodesqlv8": "^2.0.10", "ncp": "^2.0.0", "nedb-promises": "^4.0.1", "node-cron": "^2.0.3", @@ -59,5 +58,8 @@ "typescript": "^3.7.4", "webpack": "^4.42.0", "webpack-cli": "^3.3.11" + }, + "optionalDependencies": { + "msnodesqlv8": "^2.0.10" } } diff --git a/packages/api/src/nativeModules.js b/packages/api/src/nativeModules.js index 24bc42b0..64907930 100644 --- a/packages/api/src/nativeModules.js +++ b/packages/api/src/nativeModules.js @@ -1,7 +1,5 @@ -const msnodesqlv8 = () => require('msnodesqlv8'); - const argIndex = process.argv.indexOf('--native-modules'); const redirectFile = argIndex > 0 ? process.argv[argIndex + 1] : null; // @ts-ignore -module.exports = redirectFile ? __non_webpack_require__(redirectFile) : { msnodesqlv8 }; +module.exports = redirectFile ? __non_webpack_require__(redirectFile) : require('./nativeModulesContent'); diff --git a/packages/api/src/nativeModulesContent.js b/packages/api/src/nativeModulesContent.js new file mode 100644 index 00000000..b57b44e9 --- /dev/null +++ b/packages/api/src/nativeModulesContent.js @@ -0,0 +1,7 @@ + +// this file is generated automatically by script fillNativeModules.js, do not edit it manually +const content = {}; + + + +module.exports = content;