Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use utility process #608

Draft
wants to merge 7 commits into
base: feat/2-5-0-release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .erb/configs/webpack.config.base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* Base webpack config used across other specific configs
*/

import path from 'path';
import { cwd } from 'process';
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
Expand Down Expand Up @@ -48,9 +44,6 @@ const configuration: webpack.Configuration = {
},
},

/**
* Determine the array of extensions that should be used to resolve modules.
*/
resolve: {
alias: { ...aliases },
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
Expand Down
18 changes: 2 additions & 16 deletions .erb/configs/webpack.config.main.prod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* Webpack config for production electron main process
*/

import path from 'path';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
Expand All @@ -10,21 +6,13 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import Dotenv from 'dotenv-webpack';
import baseConfig from './webpack.config.base';
import webpackPaths from './webpack.paths';
import checkNodeEnv from '../scripts/check-node-env';
import deleteSourceMaps from '../scripts/delete-source-maps';

checkNodeEnv('production');
deleteSourceMaps();

const devtoolsConfig = {
devtool: 'source-map',
};

const configuration: webpack.Configuration = {
...devtoolsConfig,

devtool: 'source-map',
mode: 'production',

target: 'electron-main',

entry: {
Expand Down Expand Up @@ -59,9 +47,7 @@ const configuration: webpack.Configuration = {
* NODE_ENV should be production so that modules do not perform certain
* development checks
*/
new webpack.EnvironmentPlugin({
NODE_ENV: 'production',
}),
new webpack.EnvironmentPlugin({ NODE_ENV: 'production' }),
new Dotenv({ ignoreStub: true }),
],

Expand Down
38 changes: 7 additions & 31 deletions .erb/configs/webpack.config.sync-engine.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
/**
* Build config for electron renderer process
*/

import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { merge } from 'webpack-merge';
import TerserPlugin from 'terser-webpack-plugin';
import baseConfig from './webpack.config.base';
import webpackPaths from './webpack.paths';
import Dotenv from 'dotenv-webpack';
import { cwd } from 'process';

const configuration: webpack.Configuration = {
mode: process.env.NODE_ENV as 'none' | 'development' | 'production' | undefined,

target: 'electron-renderer',
devtool: 'source-map',
mode: 'production',
target: 'electron-main',

module: {
rules: [{ test: /\.node$/, loader: 'node-loader' }],
},

entry: ['core-js', 'regenerator-runtime/runtime', path.join(webpackPaths.srcSyncEnginePath, 'index.ts')],
entry: [path.join(webpackPaths.srcSyncEnginePath, 'index.ts')],

output: {
path: webpackPaths.distSyncEnginePath,
publicPath: './',
filename: 'renderer.js',
library: {
type: 'umd',
},
},

resolve: {
alias: {
'virtual-drive/dist': path.resolve(cwd(), '../node-win/dist'),
},
filename: '[name].js',
},

optimization: {
Expand All @@ -49,16 +33,8 @@ const configuration: webpack.Configuration = {

plugins: [
new Dotenv({ ignoreStub: true }),

new HtmlWebpackPlugin({
filename: 'index.html',
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
},
isBrowser: false,
isDevelopment: process.env.NODE_ENV !== 'production',
new webpack.EnvironmentPlugin({
NODE_ENV: 'production',
}),
],
};
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ npm-debug.log.*
src/test/screenshots

*.db
dist
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"url": "https://github.com/internxt/drive-desktop"
},
"scripts": {
"abc": "tsc -p tsconfig.sync-engine.json && tsc-alias -p tsconfig.sync-engine.json",
"build": "concurrently \"npm run build:main\" \"npm run build:backups\" \"npm run build:renderer\" \"npm run build:sync-engine\"",
"build:main": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.prod.ts",
"build:renderer": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts",
"build:sync-engine": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.sync-engine.ts",
"build:sync-engine": "cross-env TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.sync-engine.ts",
"build:backups": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.backups.ts",
"rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir release/app",
"lint": "cross-env NODE_ENV=development eslint . --ext .ts,.tsx",
Expand All @@ -21,11 +22,9 @@
"publish": "ts-node ./.erb/scripts/clean.js dist && npm run build && electron-builder build --publish always",
"postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts && opencollective-postinstall",
"========== Start ==========": "",
"start": "ts-node ./.erb/scripts/check-port-in-use.js && npm run start:sync-engine && npm run start:renderer && npm run start:backups",
"start": "ts-node ./.erb/scripts/check-port-in-use.js && yarn abc && npm run start:renderer && npm run start:backups",
"start:main": "cross-env NODE_ENV=development electron -r ts-node/register/transpile-only -r tsconfig-paths/register ./src/apps/main/main.ts",
"start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts",
"start:sync": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.sync.ts",
"start:sync-engine": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.sync-engine.ts",
"start:backups": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.backups.ts",
"start:node-win": "cd ../node-win && yarn build:ts && cd ../drive-desktop && yarn start",
"========== Testing ==========": "",
Expand Down Expand Up @@ -203,10 +202,12 @@
"ts-essentials": "^10.0.4",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"tsc-alias": "^1.8.11",
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "^4.2.0",
"typescript": "^4.5.4",
"url-loader": "^4.1.1",
"virtual-drive": "../node-win",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.0.2",
"vitest-mock-extended": "^2.0.2",
Expand Down
12 changes: 6 additions & 6 deletions release/app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@ util-deprecate@^1.0.1:
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

uuid@^11.0.3:
version "11.0.5"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.0.5.tgz#07b46bdfa6310c92c3fb3953a8720f170427fc62"
integrity sha512-508e6IcKLrhxKdBbcA2b4KQZlLVp2+J5UwQ6F7Drckkc5N9ZJwFa4TgWtsww9UG8fGHbm6gbV19TdM5pQ4GaIA==
version "11.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.1.0.tgz#9549028be1753bb934fc96e2bca09bb4105ae912"
integrity sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==

uuid@^8.3.0, uuid@^8.3.2:
version "8.3.2"
Expand Down Expand Up @@ -1352,6 +1352,6 @@ yargs@^17.6.2, yargs@^17.7.2:
yargs-parser "^21.1.1"

zod@^3.24.1:
version "3.24.1"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.1.tgz#27445c912738c8ad1e9de1bea0359fa44d9d35ee"
integrity sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==
version "3.24.2"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.2.tgz#8efa74126287c675e92f46871cfc8d15c34372b3"
integrity sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==
24 changes: 24 additions & 0 deletions src/apps/main/background-processes/sync-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { getUser } from '../auth/service';
import { FetchWorkspacesService } from '../remote-sync/workspace/fetch-workspaces.service';
import { decryptMessageWithPrivateKey } from '@/apps/shared/crypto/service';
import configStore from '../config';
import { utilityProcess } from 'electron/main';
import electron from 'electron';
import { fork } from 'child_process';

interface WorkerConfig {
worker: BrowserWindow | null;
Expand Down Expand Up @@ -74,6 +77,27 @@ export async function spawnSyncEngineWorker(config: Config) {
Logger.info(`[MAIN] SPAWNING SYNC ENGINE WORKER for workspace ${providerName}: ${workspaceId}...`);
workers[workspaceId].startingWorker = true;

logger.debug({ msg: 'Testttttttttttttttttttttttttt', electron });

// const child = utilityProcess.fork(path.join(process.cwd(), 'dist', 'src', 'apps', 'sync-engine', 'index.js'));
// const child = utilityProcess.fork(path.join(process.cwd(), 'release', 'app', 'dist', 'sync-engine', 'main.js'));
// logger.debug({ msg: '🚀 ~ spawnSyncEngineWorker ~ child:', child });

// child.postMessage({ type: 'SET_CONFIG', config });
// child.on('message', (message) => {
// logger.debug({ msg: message });
// });

const child = fork(path.join('dist', 'src', 'apps', 'sync-engine', 'index.js'));

child.on('message', (message) => {
logger.debug({ msg: 'Received', message });
});

child.send({ greeting: 'Test' });

return;

const worker = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/main/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function cleanAndStartRemoteNotifications() {
});

socket.on('connect_error', (error) => {
Logger.error('❌ Remote notifications connect error: ', error);
// Logger.error('❌ Remote notifications connect error: ', error);
});

socket.on('event', async (data) => {
Expand Down
2 changes: 2 additions & 0 deletions src/apps/node-win.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { VirtualDrive, PinState, SyncState } from 'virtual-drive/dist';
export { VirtualDrive, PinState, SyncState };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DomainEventSubscribers } from '../../../context/virtual-drive/shared/infrastructure/DomainEventSubscribers';
import { DomainEventSubscribers } from '@/context/virtual-drive/shared/infrastructure/DomainEventSubscribers';
import { getUser } from '../../main/auth/service';
import { DependencyContainer } from './DependencyContainer';
import { buildBoundaryBridgeContainer } from './boundaryBridge/build';
Expand Down
Loading