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
This commit is contained in:
Panagiotis Papadopoulos 2025-03-11 22:12:37 +01:00
parent 10de4e798b
commit 6b9d8f0d67
2 changed files with 6 additions and 4 deletions

View File

@ -30,6 +30,7 @@ try {
"./package.json", "./package.json",
"./LICENSE", "./LICENSE",
"./README.md", "./README.md",
"./forge.config.cjs",
"./src/views/", "./src/views/",
"./src/etapi/etapi.openapi.yaml", "./src/etapi/etapi.openapi.yaml",
"./src/routes/api/openapi.json", "./src/routes/api/openapi.json",

View File

@ -4,7 +4,7 @@
"description": "Build your personal knowledge base with TriliumNext Notes", "description": "Build your personal knowledge base with TriliumNext Notes",
"version": "0.92.3-beta", "version": "0.92.3-beta",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"main": "./build/electron-main.js", "main": "./electron-main.js",
"author": { "author": {
"name": "TriliumNext Notes Team", "name": "TriliumNext Notes Team",
"email": "contact@eliandoran.me", "email": "contact@eliandoran.me",
@ -38,9 +38,10 @@
"electron:switch": "electron-rebuild", "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": "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 .\"", "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:prepare": "npm run build:prepare-dist && npm ci --omit=dev --prefix ./build",
"electron-forge:make": "npm run build:prepare-dist && electron-forge make", "electron-forge:start": "npm run electron-forge:prepare && cd ./build && electron-forge start",
"electron-forge:package": "npm run build:prepare-dist && electron-forge package", "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-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-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", "docs:build": "npm run docs:build-backend && npm run docs:build-frontend",