From 1e1092e472f01edf6e8caf4190aa82cf7f4e473d Mon Sep 17 00:00:00 2001 From: Michael Clark <5285928+MikesGlitch@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:39:49 +0000 Subject: [PATCH] :electron: Separate build folders for easier switching between web and electron (#3801) * seperate build folders for easier switching between web and electron builds * gitignore * release notes * one directory back from electron * spelling mistake * Update 3801.md * test * making it correct * huh * urghh * again * account for api bundle which uses electron bundle for some reason * hu- * lets go * remove comment --- bin/package-electron | 2 +- packages/desktop-client/.gitignore | 1 + packages/desktop-client/vite.config.mts | 6 +++--- packages/desktop-electron/bin/update-client | 7 +++---- packages/desktop-electron/index.ts | 4 ++-- packages/desktop-electron/package.json | 2 +- .../src/platform/server/fs/index.electron.ts | 13 +++++++++---- .../loot-core/webpack/webpack.desktop.config.js | 2 +- upcoming-release-notes/3801.md | 6 ++++++ 9 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 upcoming-release-notes/3801.md diff --git a/bin/package-electron b/bin/package-electron index b827d0015a0..8203cc99df6 100755 --- a/bin/package-electron +++ b/bin/package-electron @@ -36,7 +36,7 @@ fi yarn workspace loot-core build:node -yarn workspace @actual-app/web build --mode=desktop +yarn workspace @actual-app/web build --mode=desktop # electron specific build yarn workspace desktop-electron update-client diff --git a/packages/desktop-client/.gitignore b/packages/desktop-client/.gitignore index f635ae3caaa..d00b9758da4 100644 --- a/packages/desktop-client/.gitignore +++ b/packages/desktop-client/.gitignore @@ -10,6 +10,7 @@ playwright-report # production build +build-electron build-stats stats.json diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mts index 0f921416bea..b61316d3b36 100644 --- a/packages/desktop-client/vite.config.mts +++ b/packages/desktop-client/vite.config.mts @@ -15,7 +15,7 @@ const addWatchers = (): Plugin => ({ configureServer(server) { server.watcher .add([ - path.resolve('../loot-core/lib-dist/*.js'), + path.resolve('../loot-core/lib-dist/electron/*.js'), path.resolve('../loot-core/lib-dist/browser/*.js'), ]) .on('all', function () { @@ -109,7 +109,7 @@ export default defineConfig(async ({ mode }) => { build: { target: 'es2022', sourcemap: true, - outDir: 'build', + outDir: mode === 'desktop' ? 'build-electron' : 'build', assetsDir: 'static', manifest: true, assetsInlineLimit: 0, @@ -148,7 +148,7 @@ export default defineConfig(async ({ mode }) => { extensions: resolveExtensions, }, plugins: [ - // Macos electron (desktop) builds do not support PWA + // electron (desktop) builds do not support PWA mode === 'desktop' ? undefined : VitePWA({ diff --git a/packages/desktop-electron/bin/update-client b/packages/desktop-electron/bin/update-client index 24da05f6fcd..d705152cc6c 100755 --- a/packages/desktop-electron/bin/update-client +++ b/packages/desktop-electron/bin/update-client @@ -4,7 +4,7 @@ ROOT=`dirname $0`/.. rm -rf ${ROOT}/build mkdir -p ${ROOT}/build -cp -r ${ROOT}/../desktop-client/build ${ROOT}/build/client-build +cp -r ${ROOT}/../desktop-client/build-electron ${ROOT}/build/client-build # Remove the embedded backend for the browser version. Will improve # this process @@ -14,9 +14,8 @@ rm -rf ${ROOT}/build/client-build/*.wasm rm -rf ${ROOT}/build/client-build/*.map # Copy loot-core into build directory -mkdir -p ${ROOT}/build/loot-core/lib-dist -ls ${ROOT}/build/loot-core/lib-dist -cp ${ROOT}/../loot-core/lib-dist/bundle.desktop.js ${ROOT}/build/loot-core/lib-dist/bundle.desktop.js +mkdir -p ${ROOT}/build/loot-core/lib-dist/electron +cp ${ROOT}/../loot-core/lib-dist/electron/bundle.desktop.js ${ROOT}/build/loot-core/lib-dist/electron/bundle.desktop.js cp ${ROOT}/../loot-core/default-db.sqlite ${ROOT}/build/loot-core/default-db.sqlite cp -r ${ROOT}/../loot-core/migrations ${ROOT}/build/loot-core/migrations diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts index 33085a2b22b..3a9d4e86089 100644 --- a/packages/desktop-electron/index.ts +++ b/packages/desktop-electron/index.ts @@ -32,8 +32,8 @@ import './security'; const isDev = !app.isPackaged; // dev mode if not packaged process.env.lootCoreScript = isDev - ? 'loot-core/lib-dist/bundle.desktop.js' // serve from local output in development (provides hot-reloading) - : path.resolve(__dirname, 'loot-core/lib-dist/bundle.desktop.js'); // serve from build in production + ? 'loot-core/lib-dist/electron/bundle.desktop.js' // serve from local output in development (provides hot-reloading) + : path.resolve(__dirname, 'loot-core/lib-dist/electron/bundle.desktop.js'); // serve from build in production // This allows relative URLs to be resolved to app:// which makes // local assets load correctly diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 4002e9220ac..db7550e480b 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -21,7 +21,7 @@ "!**/*.js.map", "!**/stats.json", "!build/client-build/sql-wasm.wasm", - "!build/loot-core/lib-dist/{browser,bundle.mobile*}" + "!build/loot-core/lib-dist/electron/{browser,bundle.mobile*}" ], "beforePack": "./build/beforePackHook.js", "mac": { diff --git a/packages/loot-core/src/platform/server/fs/index.electron.ts b/packages/loot-core/src/platform/server/fs/index.electron.ts index a0508c9d44d..587c8ff4258 100644 --- a/packages/loot-core/src/platform/server/fs/index.electron.ts +++ b/packages/loot-core/src/platform/server/fs/index.electron.ts @@ -10,10 +10,15 @@ export { getDocumentDir, getBudgetDir, _setDocumentDir } from './shared'; let rootPath = path.join(__dirname, '..', '..', '..', '..'); -if (__filename.match('bundle')) { - // The file name is not our filename and indicates that we're in the - // bundled form. Because of this, the root path is different. - rootPath = path.join(__dirname, '..'); +switch (path.basename(__filename)) { + case 'bundle.api.js': // api bundle uses the electron bundle - account for its file structure + rootPath = path.join(__dirname, '..'); + break; + case 'bundle.desktop.js': // electron app + rootPath = path.join(__dirname, '..', '..'); + break; + default: + break; } export const init = () => { diff --git a/packages/loot-core/webpack/webpack.desktop.config.js b/packages/loot-core/webpack/webpack.desktop.config.js index a6379dd5b85..2ce92a6f369 100644 --- a/packages/loot-core/webpack/webpack.desktop.config.js +++ b/packages/loot-core/webpack/webpack.desktop.config.js @@ -11,7 +11,7 @@ module.exports = { target: 'node', devtool: 'source-map', output: { - path: path.resolve(path.join(__dirname, '/../lib-dist')), + path: path.resolve(path.join(__dirname, '/../lib-dist/electron')), filename: 'bundle.desktop.js', sourceMapFilename: 'bundle.desktop.js.map', libraryTarget: 'commonjs2', diff --git a/upcoming-release-notes/3801.md b/upcoming-release-notes/3801.md new file mode 100644 index 00000000000..f2c5878e5f2 --- /dev/null +++ b/upcoming-release-notes/3801.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MikesGlitch] +--- + +Update build folder structure to allow separation of web and electron builds