From 6b9d8f0d677763f29d29abd0816b1a5d40e858c8 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 11 Mar 2025 22:12:37 +0100 Subject: [PATCH 1/8] build(electron-forge): execute electron-forge commands in our "build" output context since we build TS and webpack ourselves and are not using any electron-forge plugins (at least at the moment) -> we should use the "build" folder as build context for electron-forge: in comparison to running electron-forge in the root folder of the project, this avoids electron-forge from packing the source code multiple times (e.g. once as uncompiled TS, then as compiled JS, and then (partially) a third time as webpack bundled JS files), same as some of the assets. to achieve this, we run our usual TS/Webpack build process, but then install the npm dependencies *inside* the build folder (as otherwise electron-forge would choke on the missing node_modules it and abort building). In theory we could avoid cd-ing into the build folder, by providing the "dir" as argument to electron-forge's CLI -- BUT that wouldn't play well with our CI, where we are passing --arch and --platform options to it, which need to come *before* the dir argument. since we now cd into the "build" folder, we also need to adjust the path in package.json "main" again --- bin/copy-dist.ts | 1 + package.json | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 03b0c751b..a2bfa7f25 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -30,6 +30,7 @@ try { "./package.json", "./LICENSE", "./README.md", + "./forge.config.cjs", "./src/views/", "./src/etapi/etapi.openapi.yaml", "./src/routes/api/openapi.json", diff --git a/package.json b/package.json index c824c074b..85bbe0212 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Build your personal knowledge base with TriliumNext Notes", "version": "0.92.3-beta", "license": "AGPL-3.0-only", - "main": "./build/electron-main.js", + "main": "./electron-main.js", "author": { "name": "TriliumNext Notes Team", "email": "contact@eliandoran.me", @@ -38,9 +38,10 @@ "electron:switch": "electron-rebuild", "docs:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_ENV=dev TRILIUM_PORT=37741 electron ./electron-docs-main.ts .", "docs:edit-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_PORT=37741 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-docs-main.ts .\"", - "electron-forge:start": "npm run build:prepare-dist && electron-forge start", - "electron-forge:make": "npm run build:prepare-dist && electron-forge make", - "electron-forge:package": "npm run build:prepare-dist && electron-forge package", + "electron-forge:prepare": "npm run build:prepare-dist && npm ci --omit=dev --prefix ./build", + "electron-forge:start": "npm run electron-forge:prepare && cd ./build && electron-forge start", + "electron-forge:make": "npm run electron-forge:prepare && cd ./build && electron-forge make", + "electron-forge:package": "npm run electron-forge:prepare && cd ./build && electron-forge package", "docs:build-backend": "rimraf ./docs/backend_api && typedoc ./docs/backend_api src/becca/entities/*.ts src/services/backend_script_api.ts src/services/sql.ts", "docs:build-frontend": "rimraf ./docs/frontend_api && jsdoc -c jsdoc-conf.json -d ./docs/frontend_api src/public/app/entities/*.js src/public/app/services/frontend_script_api.js src/public/app/widgets/basic_widget.js src/public/app/widgets/note_context_aware_widget.js src/public/app/widgets/right_panel_widget.js", "docs:build": "npm run docs:build-backend && npm run docs:build-frontend", From 11772860b63707bba2f05b1bd3f6fdc83ddd458b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Tue, 11 Mar 2025 22:23:59 +0100 Subject: [PATCH 2/8] build(electron-forge): stop copying unused .anonymize-database.sql as ressource --- forge.config.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge.config.cjs b/forge.config.cjs index b2b72c4d0..11d8c1fbd 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -130,7 +130,7 @@ module.exports = { }; function getExtraResourcesForPlatform() { - const resources = ["./bin/tpl/anonymize-database.sql"]; + const resources = []; const getScriptRessources = () => { const scripts = ["trilium-portable", "trilium-safe-mode", "trilium-no-cert-check"]; From 4ce2c10d72ceacf499f514a8f3fc764a3157a51e Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 12 Mar 2025 09:24:10 +0100 Subject: [PATCH 3/8] build(copy-dist): copy over the start scripts for now --- bin/copy-dist.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index a2bfa7f25..51364b2b9 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -31,6 +31,7 @@ try { "./LICENSE", "./README.md", "./forge.config.cjs", + "./bin/tpl/", "./src/views/", "./src/etapi/etapi.openapi.yaml", "./src/routes/api/openapi.json", From 1877d262964af6c4ad6782fdaa4b7419ee9f413b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 12 Mar 2025 09:26:18 +0100 Subject: [PATCH 4/8] chore(scripts): electron-forge:prepare -> copy node_modules folder as is MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit electron-forge does not like, if we get rid of devDeps ourselves already it seems. It *wants* to do it itself, otherwise build fails… It does seem to correctly strip all the devDeps though, at least there's that. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85bbe0212..5c1ffc4bb 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "electron:switch": "electron-rebuild", "docs:edit": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_ENV=dev TRILIUM_PORT=37741 electron ./electron-docs-main.ts .", "docs:edit-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data-docs TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_PORT=37741 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-docs-main.ts .\"", - "electron-forge:prepare": "npm run build:prepare-dist && npm ci --omit=dev --prefix ./build", + "electron-forge:prepare": "npm run build:prepare-dist && cp -r node_modules ./build", "electron-forge:start": "npm run electron-forge:prepare && cd ./build && electron-forge start", "electron-forge:make": "npm run electron-forge:prepare && cd ./build && electron-forge make", "electron-forge:package": "npm run electron-forge:prepare && cd ./build && electron-forge package", From b48fbbe583f6143e9ee1964ee2cbce4415879a1f Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 12 Mar 2025 09:36:06 +0100 Subject: [PATCH 5/8] build(copy-dist): copy over desktop.ejs for electron-forge as well it is required for Flatpak/Deb/RPM Linux packages --- bin/copy-dist.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/copy-dist.ts b/bin/copy-dist.ts index 51364b2b9..b3f79ad56 100644 --- a/bin/copy-dist.ts +++ b/bin/copy-dist.ts @@ -32,6 +32,7 @@ try { "./README.md", "./forge.config.cjs", "./bin/tpl/", + "./bin/electron-forge/desktop.ejs", "./src/views/", "./src/etapi/etapi.openapi.yaml", "./src/routes/api/openapi.json", From cc0931b4028fb72ceb98b87f16c5a5b568ff0668 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Mar 2025 08:09:53 +0100 Subject: [PATCH 6/8] build(electron-forge): set outDir to ./dist, to have the same behaviour as the Server builds since we run electron-forge inside the ./build folder, we need to go up a directory (using ../dist), to have it output to ./dist --- forge.config.cjs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/forge.config.cjs b/forge.config.cjs index 11d8c1fbd..dabcd7ca4 100644 --- a/forge.config.cjs +++ b/forge.config.cjs @@ -11,6 +11,9 @@ const baseLinuxMakerConfigOptions = { }; module.exports = { + // we run electron-forge inside the ./build folder, + // to have it output to ./dist, we need to go up a directory first + outDir: "../dist", packagerConfig: { executableName: "trilium", name: APP_NAME, From 67c752c11b38078cf7e158fc8951d0908163357e Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Mar 2025 08:21:12 +0100 Subject: [PATCH 7/8] ci: adjust build-electron action to use the newly introduced outDir "./dist" for electron-forge --- .github/actions/build-electron/action.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/build-electron/action.yml b/.github/actions/build-electron/action.yml index b5a140efc..51b022bed 100644 --- a/.github/actions/build-electron/action.yml +++ b/.github/actions/build-electron/action.yml @@ -97,7 +97,7 @@ runs: shell: bash run: | echo "Signing DMG file..." - dmg_file=$(find out -name "*.dmg" -print -quit) + dmg_file=$(find ./dist -name "*.dmg" -print -quit) if [ -n "$dmg_file" ]; then echo "Found DMG: $dmg_file" # Get the first valid signing identity from the keychain @@ -125,7 +125,7 @@ runs: # First check the .app bundle echo "Looking for .app bundle..." - app_bundle=$(find out -name "*.app" -print -quit) + app_bundle=$(find ./dist -name "*.app" -print -quit) if [ -n "$app_bundle" ]; then echo "Found app bundle: $app_bundle" echo "Verifying app bundle signing..." @@ -144,7 +144,7 @@ runs: # Then check DMG if it exists echo "Looking for DMG..." - dmg_file=$(find out -name "*.dmg" -print -quit) + dmg_file=$(find ./dist -name "*.dmg" -print -quit) if [ -n "$dmg_file" ]; then echo "Found DMG: $dmg_file" echo "Verifying DMG signing..." @@ -160,7 +160,7 @@ runs: # Finally check ZIP if it exists echo "Looking for ZIP..." - zip_file=$(find out -name "*.zip" -print -quit) + zip_file=$(find ./dist -name "*.zip" -print -quit) if [ -n "$zip_file" ]; then echo "Found ZIP: $zip_file" echo "Note: ZIP files are not code signed, but their contents should be" @@ -177,7 +177,7 @@ runs: # Look for DMG files recursively echo "Looking for DMG files..." - dmg_file=$(find out -name "*.dmg" -print -quit) + dmg_file=$(find ./dist -name "*.dmg" -print -quit) if [ -n "$dmg_file" ]; then echo "Found DMG: $dmg_file" cp "$dmg_file" "upload/TriliumNextNotes-${{ github.ref_name }}-macos-${{ inputs.arch }}.dmg" @@ -187,7 +187,7 @@ runs: # Look for ZIP files recursively echo "Looking for ZIP files..." - zip_file=$(find out -name "*.zip" -print -quit) + zip_file=$(find ./dist -name "*.zip" -print -quit) if [ -n "$zip_file" ]; then echo "Found ZIP: $zip_file" cp "$zip_file" "upload/TriliumNextNotes-${{ github.ref_name }}-macos-${{ inputs.arch }}.zip" @@ -199,7 +199,7 @@ runs: echo "Collecting artifacts for ${{ inputs.os }}..." for ext in ${{ inputs.extension }}; do echo "Looking for .$ext files..." - file=$(find out -name "*.$ext" -print -quit) + file=$(find ./dist -name "*.$ext" -print -quit) if [ -n "$file" ]; then echo "Found $file for extension $ext" cp "$file" "upload/TriliumNextNotes-${{ github.ref_name }}-${{ inputs.os }}-${{ inputs.arch }}.$ext" From 6a9342abce5213073c09e896169d8031bfac50e0 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Mar 2025 08:31:07 +0100 Subject: [PATCH 8/8] build(Docker): add a temporary exception for files that copy-dist tries to copy for electron-forge, as otherwise copy-dist will fail inside Docker build this will be fixed in an upcoming PR where I overhaul copy-dist to allow for build target specific copying of files --- .dockerignore | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 786c22ff9..a4e242a99 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,7 +5,6 @@ .prettier* electron* entitlements.plist -forge.config.cjs nodemon.json renovate.json trilium.iml @@ -34,4 +33,10 @@ npm-debug.log # exceptions -!/bin/copy-dist.ts \ No newline at end of file +!/bin/copy-dist.ts + +# temporary exception to make copy-dist inside Docker build not fail +# TriliumNextTODO: make copy-dist *not* requiring to copy this file for builds other than electron-forge +!forge.config.cjs +!/bin/tpl +!/bin/electron-forge/desktop.ejs \ No newline at end of file