From 786f3e8d406f6e2d026eebd04117f9855d8a5fbb Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Feb 2025 22:51:51 +0100 Subject: [PATCH 01/18] chore(scripts): namespace server:start --- .gitpod.yml | 2 +- README-ZH_CN.md | 2 +- README.es.md | 2 +- README.it.md | 2 +- README.ja.md | 2 +- README.md | 2 +- README.ru.md | 2 +- docs/X4N03xLYEWnN.html | 4 ++-- docs/XxqZW6JjkW2g.html | 2 +- docs/backend_api/index.html | 2 +- docs/backend_api/media/README-ZH_CN.md | 2 +- docs/backend_api/media/README.es.md | 2 +- docs/backend_api/media/README.it.md | 2 +- docs/backend_api/media/README.ja.md | 2 +- docs/backend_api/media/README.md | 2 +- docs/backend_api/media/README.ru.md | 2 +- docs/btM6L9JtG301.html | 2 +- package.json | 4 ++-- 18 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 2b77be7b7..f87a115d0 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -4,7 +4,7 @@ image: tasks: - before: nvm install 20.15.1 && nvm use 20.15.1 init: npm install - command: npm run start-server + command: npm run server:start ports: - port: 8080 diff --git a/README-ZH_CN.md b/README-ZH_CN.md index f6aa860b1..1f6bbaf55 100644 --- a/README-ZH_CN.md +++ b/README-ZH_CN.md @@ -78,7 +78,7 @@ Trilium 也提供 Flatpak: ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 致谢 diff --git a/README.es.md b/README.es.md index a2ea94144..bfa57fe45 100644 --- a/README.es.md +++ b/README.es.md @@ -86,7 +86,7 @@ Clone localmente y ejecute ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 Reconocimientos diff --git a/README.it.md b/README.it.md index a778230c7..750027c1a 100644 --- a/README.it.md +++ b/README.it.md @@ -73,7 +73,7 @@ Clona localmente ed esegui ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 Riconoscimenti diff --git a/README.ja.md b/README.ja.md index 110b779c5..757638770 100644 --- a/README.ja.md +++ b/README.ja.md @@ -54,7 +54,7 @@ Trilium は Flatpak としても提供されます: ```shell npm install -npm run start-server +npm run server:start ``` ## 📢 シャウトアウト diff --git a/README.md b/README.md index e2a81aa4c..0170c8135 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ You can also read [Patterns of personal knowledge base](https://triliumnext.gith git clone https://github.com/TriliumNext/Notes.git cd Notes npm install -npm run start-server +npm run server:start ``` ### Documentation diff --git a/README.ru.md b/README.ru.md index d78738915..e2336efb3 100644 --- a/README.ru.md +++ b/README.ru.md @@ -44,7 +44,7 @@ Trilium предоставляется в виде десктопного при ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 Благодарности diff --git a/docs/X4N03xLYEWnN.html b/docs/X4N03xLYEWnN.html index 2b686480d..9e9bcfef6 100644 --- a/docs/X4N03xLYEWnN.html +++ b/docs/X4N03xLYEWnN.html @@ -38,12 +38,12 @@
-

The native node bindings

better-sqlite3 has native Node bindings. With updates of better-sqlite3, but also of Electron and Node.js versions, these bindings need to be updated.

Note that Electron and Node.js versions need different versions of these bindings, since Electron usually packs a different version of Node.js.

During development, npm install tries to build or reuse prebuilt natives for the current Node.js version. This makes npm run start-server work out of the box. Trying to run npm run start-electron with these versions generally causes an error such as this:

Uncaught Exception:
+                

The native node bindings

better-sqlite3 has native Node bindings. With updates of better-sqlite3, but also of Electron and Node.js versions, these bindings need to be updated.

Note that Electron and Node.js versions need different versions of these bindings, since Electron usually packs a different version of Node.js.

During development, npm install tries to build or reuse prebuilt natives for the current Node.js version. This makes npm run server:start work out of the box. Trying to run npm run start-electron with these versions generally causes an error such as this:

Uncaught Exception:
 Error: The module '/Users/elian/Projects/Notes/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
 was compiled against a different Node.js version using
 NODE_MODULE_VERSION 108. This version of Node.js requires
 NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
-the module (for instance, using `npm rebuild` or `npm install`).

How the natives are handled

Locally, this can be fixed by rebuilding the binaries, which is what npm run switch-electron does, which uses electron-rebuild under the hood.

When the deliveries are built (see Build deliveries locally), it is not feasible to rebuild the dependencies since we are building for multiple platforms. Luckily, better-sqlite3 provides these prebuilt binaries from us, available as artifacts on their GitHub releases page

The build script manages the natives for better-sqlite3 by keeping a copy of the .node file for every platform in bin/better-sqlite3.

Whenever the version of better-sqlite3 changes, the .node files must also be renewed based on their releases page. To simplify this process, a script was created in bin/better-sqlite3/update.sh.

How to update the natives

The update script needs to know the version of Electron or Node.js for which to download the prebuilt binaries.

If you get errors during download, check on the releases page to ensure that this particular combination of Electron/Node actually exists for the given release.

To determine the NODE_MODULE_VERSION that is required, look for This version of Node.js requires
NODE_MODULE_VERSION in the error when starting Trilium via:

  • npm run start-electron (or run any Electron delivery), case in which the ELECTRON_VERSION variable needs to be changed.
  • npm run start-server (or run the Linux server delivery), case in which the NODE_VERSION variable needs to be changed.

Check which files got changed after running the update script and for each platform that got changed, test it locally via Build deliveries locally or via the CI.

+the module (for instance, using `npm rebuild` or `npm install`).

How the natives are handled

Locally, this can be fixed by rebuilding the binaries, which is what npm run switch-electron does, which uses electron-rebuild under the hood.

When the deliveries are built (see Build deliveries locally), it is not feasible to rebuild the dependencies since we are building for multiple platforms. Luckily, better-sqlite3 provides these prebuilt binaries from us, available as artifacts on their GitHub releases page

The build script manages the natives for better-sqlite3 by keeping a copy of the .node file for every platform in bin/better-sqlite3.

Whenever the version of better-sqlite3 changes, the .node files must also be renewed based on their releases page. To simplify this process, a script was created in bin/better-sqlite3/update.sh.

How to update the natives

The update script needs to know the version of Electron or Node.js for which to download the prebuilt binaries.

If you get errors during download, check on the releases page to ensure that this particular combination of Electron/Node actually exists for the given release.

To determine the NODE_MODULE_VERSION that is required, look for This version of Node.js requires
NODE_MODULE_VERSION in the error when starting Trilium via:

Check which files got changed after running the update script and for each platform that got changed, test it locally via Build deliveries locally or via the CI.

diff --git a/docs/XxqZW6JjkW2g.html b/docs/XxqZW6JjkW2g.html index 3307c8c4f..666d8ae9f 100644 --- a/docs/XxqZW6JjkW2g.html +++ b/docs/XxqZW6JjkW2g.html @@ -38,7 +38,7 @@
-

Server live reload

If running the server using npm run start-server, the server will watch for changes in src/public and trigger a frontend reload if that occurs.

Electron live reload

Similarly, npm run start-electron supports live refresh  as well.

However, a core difference is that Electron watches dist/src/public instead of src/public since Electron runs on its own copy of the files.

To ameliorate that, a separate watch script has been implemented which automatically copies files from src/public to dist/src/public whenever a change is detected. To run it:

npm run 

Technical details

+

Server live reload

If running the server using npm run server:start, the server will watch for changes in src/public and trigger a frontend reload if that occurs.

Electron live reload

Similarly, npm run start-electron supports live refresh  as well.

However, a core difference is that Electron watches dist/src/public instead of src/public since Electron runs on its own copy of the files.

To ameliorate that, a separate watch script has been implemented which automatically copies files from src/public to dist/src/public whenever a change is detected. To run it:

npm run 

Technical details

diff --git a/docs/backend_api/index.html b/docs/backend_api/index.html index 612058e6f..6c27bd07a 100644 --- a/docs/backend_api/index.html +++ b/docs/backend_api/index.html @@ -71,7 +71,7 @@

To install TriliumNext on your own server (including via Docker from Dockerhub) follow the server installation docs.

See wiki for complete list of documentation pages.

You can also read Patterns of personal knowledge base to get some inspiration on how you might use TriliumNext.

-
git clone https://github.com/TriliumNext/Notes.git
cd Notes
npm install
npm run start-server +
git clone https://github.com/TriliumNext/Notes.git
cd Notes
npm install
npm run server:start

Head on over to our Docs repo

diff --git a/docs/backend_api/media/README-ZH_CN.md b/docs/backend_api/media/README-ZH_CN.md index f6aa860b1..1f6bbaf55 100644 --- a/docs/backend_api/media/README-ZH_CN.md +++ b/docs/backend_api/media/README-ZH_CN.md @@ -78,7 +78,7 @@ Trilium 也提供 Flatpak: ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 致谢 diff --git a/docs/backend_api/media/README.es.md b/docs/backend_api/media/README.es.md index a2ea94144..bfa57fe45 100644 --- a/docs/backend_api/media/README.es.md +++ b/docs/backend_api/media/README.es.md @@ -86,7 +86,7 @@ Clone localmente y ejecute ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 Reconocimientos diff --git a/docs/backend_api/media/README.it.md b/docs/backend_api/media/README.it.md index a778230c7..750027c1a 100644 --- a/docs/backend_api/media/README.it.md +++ b/docs/backend_api/media/README.it.md @@ -73,7 +73,7 @@ Clona localmente ed esegui ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 Riconoscimenti diff --git a/docs/backend_api/media/README.ja.md b/docs/backend_api/media/README.ja.md index 110b779c5..757638770 100644 --- a/docs/backend_api/media/README.ja.md +++ b/docs/backend_api/media/README.ja.md @@ -54,7 +54,7 @@ Trilium は Flatpak としても提供されます: ```shell npm install -npm run start-server +npm run server:start ``` ## 📢 シャウトアウト diff --git a/docs/backend_api/media/README.md b/docs/backend_api/media/README.md index 1800f667e..c427d98d0 100644 --- a/docs/backend_api/media/README.md +++ b/docs/backend_api/media/README.md @@ -102,7 +102,7 @@ You can also read [Patterns of personal knowledge base](https://triliumnext.gith git clone https://github.com/TriliumNext/Notes.git cd Notes npm install -npm run start-server +npm run server:start ``` ### Documentation diff --git a/docs/backend_api/media/README.ru.md b/docs/backend_api/media/README.ru.md index d78738915..e2336efb3 100644 --- a/docs/backend_api/media/README.ru.md +++ b/docs/backend_api/media/README.ru.md @@ -44,7 +44,7 @@ Trilium предоставляется в виде десктопного при ```shell npm install -npm run start-server +npm run server:start ``` ## 👏 Благодарности diff --git a/docs/btM6L9JtG301.html b/docs/btM6L9JtG301.html index a16f503c9..3edf3154a 100644 --- a/docs/btM6L9JtG301.html +++ b/docs/btM6L9JtG301.html @@ -38,7 +38,7 @@
-

Run server

Run with default settings:

npm run start-server

Run with custom port:

TRILIUM_PORT=8082 npm run start-server

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run start-electron

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run switch-server
+

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run start-electron

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run switch-server
diff --git a/package.json b/package.json index 9829a639f..65bc95ddc 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,11 @@ }, "type": "module", "scripts": { - "start-server": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", + "server:start": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", "start-server-safe": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", "start-server-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", "start-test-server": "npm run switch-server && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", - "qstart-server": "npm run switch-server && npm run start-server", + "qstart-server": "npm run switch-server && npm run server:start", "start-electron": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", "start-electron-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "start-electron-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", From f3dda940ec149e67425206bf99b5d4a51195794b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Feb 2025 23:00:53 +0100 Subject: [PATCH 02/18] chore(scripts): namespace server server:start-safe server:start-no-dir server:start-test server:qstart --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 65bc95ddc..14f731c44 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,10 @@ "type": "module", "scripts": { "server:start": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", - "start-server-safe": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", - "start-server-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", - "start-test-server": "npm run switch-server && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", - "qstart-server": "npm run switch-server && npm run server:start", + "server:start-safe": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", + "server:start-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", + "server:start-test": "npm run switch-server && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", + "server:qstart": "npm run switch-server && npm run server:start", "start-electron": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", "start-electron-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "start-electron-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", From 7b062badf032643b49b04d3c2c4d017ceac4aa90 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Feb 2025 23:18:57 +0100 Subject: [PATCH 03/18] chore(scripts): namespace server server:switch --- docs/btM6L9JtG301.html | 2 +- package.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/btM6L9JtG301.html b/docs/btM6L9JtG301.html index 3edf3154a..64a04eb8a 100644 --- a/docs/btM6L9JtG301.html +++ b/docs/btM6L9JtG301.html @@ -38,7 +38,7 @@
-

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run start-electron

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run switch-server
+

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run start-electron

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch
diff --git a/package.json b/package.json index 14f731c44..3b117de43 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,9 @@ "server:start": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", "server:start-safe": "cross-env TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", "server:start-no-dir": "cross-env TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/main.ts", - "server:start-test": "npm run switch-server && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", - "server:qstart": "npm run switch-server && npm run server:start", + "server:start-test": "npm run server:switch && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", + "server:qstart": "npm run server:switch && npm run server:start", + "server:switch": "rimraf ./node_modules/better-sqlite3 && npm install", "start-electron": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", "start-electron-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "start-electron-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", @@ -34,7 +35,6 @@ "start-electron-prod-no-dir": "npm run prepare-dist && cross-env TRILIUM_ENV=dev electron --inspect=5858 .", "start-electron-prod-no-dir-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "qstart-electron": "npm run switch-electron && npm run start-electron", - "switch-server": "rimraf ./node_modules/better-sqlite3 && npm install", "switch-electron": "electron-rebuild", "build-backend-docs": "rimraf ./docs/backend_api && typedoc ./docs/backend_api src/becca/entities/*.ts src/services/backend_script_api.ts src/services/sql.ts", "build-frontend-docs": "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", From 469519f5dfe6a67ebb48bc7dde13429ee26e5ac7 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Thu, 13 Feb 2025 23:25:38 +0100 Subject: [PATCH 04/18] chore(scripts): namespace electron:start --- docs/X4N03xLYEWnN.html | 4 ++-- docs/XxqZW6JjkW2g.html | 2 +- docs/btM6L9JtG301.html | 2 +- package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/X4N03xLYEWnN.html b/docs/X4N03xLYEWnN.html index 9e9bcfef6..dca059b84 100644 --- a/docs/X4N03xLYEWnN.html +++ b/docs/X4N03xLYEWnN.html @@ -38,12 +38,12 @@
-

The native node bindings

better-sqlite3 has native Node bindings. With updates of better-sqlite3, but also of Electron and Node.js versions, these bindings need to be updated.

Note that Electron and Node.js versions need different versions of these bindings, since Electron usually packs a different version of Node.js.

During development, npm install tries to build or reuse prebuilt natives for the current Node.js version. This makes npm run server:start work out of the box. Trying to run npm run start-electron with these versions generally causes an error such as this:

Uncaught Exception:
+                

The native node bindings

better-sqlite3 has native Node bindings. With updates of better-sqlite3, but also of Electron and Node.js versions, these bindings need to be updated.

Note that Electron and Node.js versions need different versions of these bindings, since Electron usually packs a different version of Node.js.

During development, npm install tries to build or reuse prebuilt natives for the current Node.js version. This makes npm run server:start work out of the box. Trying to run npm run electron:start with these versions generally causes an error such as this:

Uncaught Exception:
 Error: The module '/Users/elian/Projects/Notes/node_modules/better-sqlite3/build/Release/better_sqlite3.node'
 was compiled against a different Node.js version using
 NODE_MODULE_VERSION 108. This version of Node.js requires
 NODE_MODULE_VERSION 116. Please try re-compiling or re-installing
-the module (for instance, using `npm rebuild` or `npm install`).

How the natives are handled

Locally, this can be fixed by rebuilding the binaries, which is what npm run switch-electron does, which uses electron-rebuild under the hood.

When the deliveries are built (see Build deliveries locally), it is not feasible to rebuild the dependencies since we are building for multiple platforms. Luckily, better-sqlite3 provides these prebuilt binaries from us, available as artifacts on their GitHub releases page

The build script manages the natives for better-sqlite3 by keeping a copy of the .node file for every platform in bin/better-sqlite3.

Whenever the version of better-sqlite3 changes, the .node files must also be renewed based on their releases page. To simplify this process, a script was created in bin/better-sqlite3/update.sh.

How to update the natives

The update script needs to know the version of Electron or Node.js for which to download the prebuilt binaries.

If you get errors during download, check on the releases page to ensure that this particular combination of Electron/Node actually exists for the given release.

To determine the NODE_MODULE_VERSION that is required, look for This version of Node.js requires
NODE_MODULE_VERSION in the error when starting Trilium via:

  • npm run start-electron (or run any Electron delivery), case in which the ELECTRON_VERSION variable needs to be changed.
  • npm run server:start (or run the Linux server delivery), case in which the NODE_VERSION variable needs to be changed.

Check which files got changed after running the update script and for each platform that got changed, test it locally via Build deliveries locally or via the CI.

+the module (for instance, using `npm rebuild` or `npm install`).

How the natives are handled

Locally, this can be fixed by rebuilding the binaries, which is what npm run switch-electron does, which uses electron-rebuild under the hood.

When the deliveries are built (see Build deliveries locally), it is not feasible to rebuild the dependencies since we are building for multiple platforms. Luckily, better-sqlite3 provides these prebuilt binaries from us, available as artifacts on their GitHub releases page

The build script manages the natives for better-sqlite3 by keeping a copy of the .node file for every platform in bin/better-sqlite3.

Whenever the version of better-sqlite3 changes, the .node files must also be renewed based on their releases page. To simplify this process, a script was created in bin/better-sqlite3/update.sh.

How to update the natives

The update script needs to know the version of Electron or Node.js for which to download the prebuilt binaries.

If you get errors during download, check on the releases page to ensure that this particular combination of Electron/Node actually exists for the given release.

To determine the NODE_MODULE_VERSION that is required, look for This version of Node.js requires
NODE_MODULE_VERSION in the error when starting Trilium via:

  • npm run electron:start (or run any Electron delivery), case in which the ELECTRON_VERSION variable needs to be changed.
  • npm run server:start (or run the Linux server delivery), case in which the NODE_VERSION variable needs to be changed.

Check which files got changed after running the update script and for each platform that got changed, test it locally via Build deliveries locally or via the CI.

diff --git a/docs/XxqZW6JjkW2g.html b/docs/XxqZW6JjkW2g.html index 666d8ae9f..25b34176c 100644 --- a/docs/XxqZW6JjkW2g.html +++ b/docs/XxqZW6JjkW2g.html @@ -38,7 +38,7 @@
-

Server live reload

If running the server using npm run server:start, the server will watch for changes in src/public and trigger a frontend reload if that occurs.

Electron live reload

Similarly, npm run start-electron supports live refresh  as well.

However, a core difference is that Electron watches dist/src/public instead of src/public since Electron runs on its own copy of the files.

To ameliorate that, a separate watch script has been implemented which automatically copies files from src/public to dist/src/public whenever a change is detected. To run it:

npm run 

Technical details

  • This mechanism is managed at server level by watching for changes inservices/ws.ts.
+

Server live reload

If running the server using npm run server:start, the server will watch for changes in src/public and trigger a frontend reload if that occurs.

Electron live reload

Similarly, npm run electron:start supports live refresh  as well.

However, a core difference is that Electron watches dist/src/public instead of src/public since Electron runs on its own copy of the files.

To ameliorate that, a separate watch script has been implemented which automatically copies files from src/public to dist/src/public whenever a change is detected. To run it:

npm run 

Technical details

  • This mechanism is managed at server level by watching for changes inservices/ws.ts.
diff --git a/docs/btM6L9JtG301.html b/docs/btM6L9JtG301.html index 64a04eb8a..4608a1ead 100644 --- a/docs/btM6L9JtG301.html +++ b/docs/btM6L9JtG301.html @@ -38,7 +38,7 @@
-

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run start-electron

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch
+

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run electron:start

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch
diff --git a/package.json b/package.json index 3b117de43..4d5bfec2f 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "server:start-test": "npm run server:switch && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", "server:qstart": "npm run server:switch && npm run server:start", "server:switch": "rimraf ./node_modules/better-sqlite3 && npm install", - "start-electron": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", + "electron:start": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", "start-electron-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "start-electron-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", "start-electron-no-dir-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", From 06890585d2b9e63d458dc5a91ed4bf0d55554e94 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 07:36:49 +0100 Subject: [PATCH 05/18] chore(scripts): namespace "electron:" --- docs/btM6L9JtG301.html | 2 +- package.json | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/btM6L9JtG301.html b/docs/btM6L9JtG301.html index 4608a1ead..6188237d3 100644 --- a/docs/btM6L9JtG301.html +++ b/docs/btM6L9JtG301.html @@ -38,7 +38,7 @@
-

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run electron:start

To run Electron using the same data directory as the production version:

npm run start-electron-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch
+

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run electron:start

To run Electron using the same data directory as the production version:

npm run electron:start-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch
diff --git a/package.json b/package.json index 4d5bfec2f..04fbb65ec 100644 --- a/package.json +++ b/package.json @@ -27,15 +27,15 @@ "server:qstart": "npm run server:switch && npm run server:start", "server:switch": "rimraf ./node_modules/better-sqlite3 && npm install", "electron:start": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", - "start-electron-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", - "start-electron-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", - "start-electron-no-dir-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", - "start-electron-prod": "npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron-main.js --inspect=5858 .", - "start-electron-prod-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", - "start-electron-prod-no-dir": "npm run prepare-dist && cross-env TRILIUM_ENV=dev electron --inspect=5858 .", - "start-electron-prod-no-dir-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", - "qstart-electron": "npm run switch-electron && npm run start-electron", - "switch-electron": "electron-rebuild", + "electron:start-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", + "electron:start-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", + "electron:start-nix-no-dir": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", + "electron:start-prod": "npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron-main.js --inspect=5858 .", + "electron:start-prod-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", + "electron:start-prod-no-dir": "npm run prepare-dist && cross-env TRILIUM_ENV=dev electron --inspect=5858 .", + "electron:start-prod-no-dir-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", + "electron:qstart": "npm run electron:switch && npm run electron:start", + "electron:switch": "electron-rebuild", "build-backend-docs": "rimraf ./docs/backend_api && typedoc ./docs/backend_api src/becca/entities/*.ts src/services/backend_script_api.ts src/services/sql.ts", "build-frontend-docs": "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", "build-docs": "npm run build-backend-docs && npm run build-frontend-docs", From 0145636fc51d04835a1d6a6811178b5084369247 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 07:39:01 +0100 Subject: [PATCH 06/18] chore(scripts): namespace "electron:" reorder entries --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 04fbb65ec..f1a30b350 100644 --- a/package.json +++ b/package.json @@ -27,13 +27,13 @@ "server:qstart": "npm run server:switch && npm run server:start", "server:switch": "rimraf ./node_modules/better-sqlite3 && npm install", "electron:start": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", - "electron:start-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "electron:start-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", + "electron:start-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "electron:start-nix-no-dir": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "electron:start-prod": "npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron-main.js --inspect=5858 .", - "electron:start-prod-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "electron:start-prod-no-dir": "npm run prepare-dist && cross-env TRILIUM_ENV=dev electron --inspect=5858 .", - "electron:start-prod-no-dir-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", + "electron:start-prod-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", + "electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "electron:qstart": "npm run electron:switch && npm run electron:start", "electron:switch": "electron-rebuild", "build-backend-docs": "rimraf ./docs/backend_api && typedoc ./docs/backend_api src/becca/entities/*.ts src/services/backend_script_api.ts src/services/sql.ts", From 688eb4d93f52c6dfd0c5ba77f175959697765061 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:31:07 +0100 Subject: [PATCH 07/18] chore(scripts): namespace "docs:" --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f1a30b350..73af47986 100644 --- a/package.json +++ b/package.json @@ -36,9 +36,9 @@ "electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "electron:qstart": "npm run electron:switch && npm run electron:start", "electron:switch": "electron-rebuild", - "build-backend-docs": "rimraf ./docs/backend_api && typedoc ./docs/backend_api src/becca/entities/*.ts src/services/backend_script_api.ts src/services/sql.ts", - "build-frontend-docs": "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", - "build-docs": "npm run build-backend-docs && npm run build-frontend-docs", + "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", "webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", "test-playwright": "playwright test", "test": "cross-env TRILIUM_DATA_DIR=./data-test vitest", From d2e8f946a0bae86cd35afa100c2c8c0daf698903 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:35:46 +0100 Subject: [PATCH 08/18] chore(scripts): namespace "chore:ci-update-nightly-version" --- .github/workflows/nightly.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 2b1fbe57e..f7cee700a 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -38,7 +38,7 @@ jobs: shell: bash run: npm ci - name: Update nightly version - run: npm run ci-update-nightly-version + run: npm run chore:ci-update-nightly-version - name: Run the build uses: ./.github/actions/build-electron with: diff --git a/package.json b/package.json index 73af47986..29577415c 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "generate-document": "cross-env nodemon ./bin/generate_document.ts 1000", "generate-openapi": "node bin/generate-openapi.js", - "ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts", + "chore:ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts", "prettier-check": "prettier . --check", "prettier-fix": "prettier . --write" }, From 47002aa95ad155bb50b7179a755e9fd388861b9b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:38:18 +0100 Subject: [PATCH 09/18] chore(scripts): namespace "chore:update-build-info" --- .github/actions/build-electron/action.yml | 2 +- .github/actions/build-server/action.yml | 2 +- bin/release.sh | 2 +- docs/mPGbEmYGitWe.html | 2 +- package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/actions/build-electron/action.yml b/.github/actions/build-electron/action.yml index b55ffea4b..e4081b906 100644 --- a/.github/actions/build-electron/action.yml +++ b/.github/actions/build-electron/action.yml @@ -33,7 +33,7 @@ runs: run: sed -e "s/case 'armv7l'/case 'arm64'/g" -e "s/return 'arm'/return 'aarch64'/g" -i node_modules/@electron-forge/maker-flatpak/dist/MakerFlatpak.js - name: Update build info shell: bash - run: npm run update-build-info + run: npm run chore:update-build-info - name: Run electron-forge shell: bash run: npm run make-electron -- --arch=${{ inputs.arch }} diff --git a/.github/actions/build-server/action.yml b/.github/actions/build-server/action.yml index 694005c1b..cf8057c70 100644 --- a/.github/actions/build-server/action.yml +++ b/.github/actions/build-server/action.yml @@ -18,7 +18,7 @@ runs: MATRIX_ARCH: ${{ inputs.arch }} shell: bash run: | - npm run update-build-info + npm run chore:update-build-info ./bin/build-server.sh - name: Prepare artifacts shell: bash diff --git a/bin/release.sh b/bin/release.sh index fea1e030f..74559a88c 100755 --- a/bin/release.sh +++ b/bin/release.sh @@ -32,7 +32,7 @@ mv package.json.tmp package.json git add package.json -npm run update-build-info +npm run chore:update-build-info git add src/services/build.ts diff --git a/docs/mPGbEmYGitWe.html b/docs/mPGbEmYGitWe.html index a66680a97..017d198b7 100644 --- a/docs/mPGbEmYGitWe.html +++ b/docs/mPGbEmYGitWe.html @@ -38,7 +38,7 @@
-
  • Provides context about when the build was made and the corresponding Git revision.
  • The information is displayed to the client when going in the about dialog.
  • The build information is hard-coded in src/services/build.ts. This file is generated automatically via npm run update-build-info which itself is run automatically whenever making a build in the CI, or a local delivery.
+
  • Provides context about when the build was made and the corresponding Git revision.
  • The information is displayed to the client when going in the about dialog.
  • The build information is hard-coded in src/services/build.ts. This file is generated automatically via npm run chore:update-build-info which itself is run automatically whenever making a build in the CI, or a local delivery.
diff --git a/package.json b/package.json index 29577415c..8d81b7cc3 100644 --- a/package.json +++ b/package.json @@ -48,12 +48,12 @@ "package-electron": "electron-forge package", "prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", "watch-dist": "tsx ./bin/watch-dist.ts", - "update-build-info": "tsx bin/update-build-info.ts", "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "generate-document": "cross-env nodemon ./bin/generate_document.ts 1000", "generate-openapi": "node bin/generate-openapi.js", + "chore:update-build-info": "tsx bin/update-build-info.ts", "chore:ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts", "prettier-check": "prettier . --check", "prettier-fix": "prettier . --write" From 9cddb1deac183596327678da7b819bce388875f8 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:41:34 +0100 Subject: [PATCH 10/18] chore(scripts): namespace "build:webpack" --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- bin/copy-trilium.sh | 2 +- package.json | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 959c244a9..620c13789 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN cp -R build/src/* src/. && \ cp build/docker_healthcheck.js . && \ rm docker_healthcheck.ts && \ npm install && \ - npm run webpack && \ + npm run build:webpack && \ npm prune --omit=dev && \ npm cache clean --force && \ cp -r src/public/app/doc_notes src/public/app-dist/. && \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index f7b49b94c..cac6d1871 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -24,7 +24,7 @@ RUN cp -R build/src/* src/. && \ cp build/docker_healthcheck.js . && \ rm docker_healthcheck.ts && \ npm install && \ - npm run webpack && \ + npm run build:webpack && \ npm prune --omit=dev && \ npm cache clean --force && \ cp -r src/public/app/doc_notes src/public/app-dist/. && \ diff --git a/bin/copy-trilium.sh b/bin/copy-trilium.sh index 221e8a0ea..e1d0e197f 100755 --- a/bin/copy-trilium.sh +++ b/bin/copy-trilium.sh @@ -23,7 +23,7 @@ rm -rf "$DIR" mkdir -pv "$DIR" echo Webpack start -npm run webpack +npm run build:webpack echo Webpack finish echo "Copying Trilium to build directory $DIR" diff --git a/package.json b/package.json index 8d81b7cc3..2f9f1a406 100644 --- a/package.json +++ b/package.json @@ -39,12 +39,12 @@ "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", - "webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", + "build:webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", "test-playwright": "playwright test", "test": "cross-env TRILIUM_DATA_DIR=./data-test vitest", "test-coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", "start-electron-forge": "npm run prepare-dist && electron-forge start", - "make-electron": "npm run webpack && npm run prepare-dist && electron-forge make", + "make-electron": "npm run build:webpack && npm run prepare-dist && electron-forge make", "package-electron": "electron-forge package", "prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", "watch-dist": "tsx ./bin/watch-dist.ts", From 4f6085a1a4e1e15c132f8cb4fb6f0b2bc222ece7 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:43:41 +0100 Subject: [PATCH 11/18] chore(scripts): namespace "build:prepare-dist" --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 2f9f1a406..95b51dc71 100644 --- a/package.json +++ b/package.json @@ -30,23 +30,23 @@ "electron:start-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", "electron:start-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", "electron:start-nix-no-dir": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", - "electron:start-prod": "npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron-main.js --inspect=5858 .", - "electron:start-prod-no-dir": "npm run prepare-dist && cross-env TRILIUM_ENV=dev electron --inspect=5858 .", - "electron:start-prod-nix": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", - "electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", + "electron:start-prod": "npm run build:prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron-main.js --inspect=5858 .", + "electron:start-prod-no-dir": "npm run build:prepare-dist && cross-env TRILIUM_ENV=dev electron --inspect=5858 .", + "electron:start-prod-nix": "electron-rebuild --version 33.3.1 && npm run build:prepare-dist && cross-env TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", + "electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run build:prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "electron:qstart": "npm run electron:switch && npm run electron:start", "electron:switch": "electron-rebuild", "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", "build:webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", + "build:prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", "test-playwright": "playwright test", "test": "cross-env TRILIUM_DATA_DIR=./data-test vitest", "test-coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", - "start-electron-forge": "npm run prepare-dist && electron-forge start", - "make-electron": "npm run build:webpack && npm run prepare-dist && electron-forge make", + "start-electron-forge": "npm run build:prepare-dist && electron-forge start", + "make-electron": "npm run build:webpack && npm run build:prepare-dist && electron-forge make", "package-electron": "electron-forge package", - "prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", "watch-dist": "tsx ./bin/watch-dist.ts", "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", From d23734dd3f091b257d5893ea17e52c67c65ca43a Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:44:25 +0100 Subject: [PATCH 12/18] chore(scripts): add some line breaks for better separation --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 95b51dc71..1cd4c29e4 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "server:start-test": "npm run server:switch && rimraf ./data-test && cross-env TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 nodemon src/main.ts", "server:qstart": "npm run server:switch && npm run server:start", "server:switch": "rimraf ./node_modules/better-sqlite3 && npm install", + "electron:start": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./electron-main.ts --inspect=5858 .", "electron:start-no-dir": "cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_ENV=dev electron --inspect=5858 .", "electron:start-nix": "electron-rebuild --version 33.3.1 && cross-env NODE_OPTIONS=\"--import tsx\" TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./electron-main.ts --inspect=5858 .\"", @@ -36,11 +37,14 @@ "electron:start-prod-nix-no-dir": "electron-rebuild --version 33.3.1 && npm run build:prepare-dist && cross-env TRILIUM_ENV=dev nix-shell -p electron_33 --run \"electron ./dist/electron-main.js --inspect=5858 .\"", "electron:qstart": "npm run electron:switch && npm run electron:start", "electron:switch": "electron-rebuild", + "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", + "build:webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", "build:prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", + "test-playwright": "playwright test", "test": "cross-env TRILIUM_DATA_DIR=./data-test vitest", "test-coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", From 5f5d7b54320981f87b2a2f3cb5127f92c61591c6 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:48:14 +0100 Subject: [PATCH 13/18] chore(scripts): namespace "electron-forge:*" --- .github/actions/build-electron/action.yml | 2 +- package.json | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/actions/build-electron/action.yml b/.github/actions/build-electron/action.yml index e4081b906..76e8161b5 100644 --- a/.github/actions/build-electron/action.yml +++ b/.github/actions/build-electron/action.yml @@ -36,7 +36,7 @@ runs: run: npm run chore:update-build-info - name: Run electron-forge shell: bash - run: npm run make-electron -- --arch=${{ inputs.arch }} + run: npm run electron-forge:make -- --arch=${{ inputs.arch }} - name: Prepare artifacts shell: bash run: | diff --git a/package.json b/package.json index 1cd4c29e4..ab706733d 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,10 @@ "electron:qstart": "npm run electron:switch && npm run electron:start", "electron:switch": "electron-rebuild", + "electron-forge:start": "npm run build:prepare-dist && electron-forge start", + "electron-forge:make": "npm run build:webpack && npm run build:prepare-dist && electron-forge make", + "electron-forge:package": "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", @@ -48,9 +52,6 @@ "test-playwright": "playwright test", "test": "cross-env TRILIUM_DATA_DIR=./data-test vitest", "test-coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", - "start-electron-forge": "npm run build:prepare-dist && electron-forge start", - "make-electron": "npm run build:webpack && npm run build:prepare-dist && electron-forge make", - "package-electron": "electron-forge package", "watch-dist": "tsx ./bin/watch-dist.ts", "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", From ae41555b514bd0398225e710dc08920b763810f6 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:50:43 +0100 Subject: [PATCH 14/18] chore(scripts): namespace "test:*" --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ab706733d..7cb3974ad 100644 --- a/package.json +++ b/package.json @@ -49,9 +49,10 @@ "build:webpack": "tsx node_modules/webpack/bin/webpack.js -c webpack.config.ts", "build:prepare-dist": "rimraf ./dist && tsc && tsx ./bin/copy-dist.ts", - "test-playwright": "playwright test", "test": "cross-env TRILIUM_DATA_DIR=./data-test vitest", - "test-coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", + "test:coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", + "test:playwright": "playwright test", + "watch-dist": "tsx ./bin/watch-dist.ts", "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", From 218a88972566d064ebf6508cd4abb5f70293aab4 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:54:05 +0100 Subject: [PATCH 15/18] chore(scripts): namespace "dev:*" --- package.json | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7cb3974ad..2b6457a20 100644 --- a/package.json +++ b/package.json @@ -53,16 +53,17 @@ "test:coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", "test:playwright": "playwright test", - "watch-dist": "tsx ./bin/watch-dist.ts", + "dev:watch-dist": "tsx ./bin/watch-dist.ts", + "dev:prettier-check": "prettier . --check", + "dev:prettier-fix": "prettier . --write", + "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "generate-document": "cross-env nodemon ./bin/generate_document.ts 1000", "generate-openapi": "node bin/generate-openapi.js", "chore:update-build-info": "tsx bin/update-build-info.ts", - "chore:ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts", - "prettier-check": "prettier . --check", - "prettier-fix": "prettier . --write" + "chore:ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts" }, "dependencies": { "@braintree/sanitize-url": "7.1.1", From 0cace7f3f9da5799dbf5158de3ba3aff60a64739 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 08:56:45 +0100 Subject: [PATCH 16/18] chore(scripts): add integration test servers to namespace "test:*" --- package.json | 7 ++++--- playwright.config.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2b6457a20..aa0756308 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,14 @@ "test:coverage": "cross-env TRILIUM_DATA_DIR=./data-test vitest --coverage", "test:playwright": "playwright test", + "test:integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", + "test:integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", + "test:integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", + "dev:watch-dist": "tsx ./bin/watch-dist.ts", "dev:prettier-check": "prettier . --check", "dev:prettier-fix": "prettier . --write", - "integration-edit-db": "cross-env TRILIUM_INTEGRATION_TEST=edit TRILIUM_PORT=8081 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", - "integration-mem-db": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", - "integration-mem-db-dev": "cross-env TRILIUM_INTEGRATION_TEST=memory TRILIUM_PORT=8082 TRILIUM_ENV=dev TRILIUM_DATA_DIR=./integration-tests/db nodemon src/main.ts", "generate-document": "cross-env nodemon ./bin/generate_document.ts 1000", "generate-openapi": "node bin/generate-openapi.js", "chore:update-build-info": "tsx bin/update-build-info.ts", diff --git a/playwright.config.ts b/playwright.config.ts index 9015af28e..e5377db4b 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -74,7 +74,7 @@ export default defineConfig({ /* Run your local dev server before starting the tests */ webServer: !process.env.TRILIUM_DOCKER ? { - command: 'npm run integration-mem-db-dev', + command: 'npm run test:integration-mem-db-dev', url: SERVER_URL, reuseExistingServer: !process.env.CI, } : undefined, From 21d18b1bdfecd8da448abcf574e39618e4199b6d Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 09:00:42 +0100 Subject: [PATCH 17/18] chore(scripts): add generate-* to namespace "chore:*" --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index aa0756308..53070e6ed 100644 --- a/package.json +++ b/package.json @@ -61,10 +61,10 @@ "dev:prettier-check": "prettier . --check", "dev:prettier-fix": "prettier . --write", - "generate-document": "cross-env nodemon ./bin/generate_document.ts 1000", - "generate-openapi": "node bin/generate-openapi.js", "chore:update-build-info": "tsx bin/update-build-info.ts", - "chore:ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts" + "chore:ci-update-nightly-version": "tsx ./bin/update-nightly-version.ts", + "chore:generate-document": "cross-env nodemon ./bin/generate_document.ts 1000", + "chore:generate-openapi": "node bin/generate-openapi.js" }, "dependencies": { "@braintree/sanitize-url": "7.1.1", From e89d1b24131700a76302fb063f0fbde5b9d4a023 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Fri, 14 Feb 2025 09:11:35 +0100 Subject: [PATCH 18/18] chore(scripts): fix electron:switch in docs --- docs/X4N03xLYEWnN.html | 2 +- docs/btM6L9JtG301.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/X4N03xLYEWnN.html b/docs/X4N03xLYEWnN.html index dca059b84..b8e844cba 100644 --- a/docs/X4N03xLYEWnN.html +++ b/docs/X4N03xLYEWnN.html @@ -43,7 +43,7 @@ Error: The module '/Users/elian/Projects/Notes/node_modules/better-sqlite3/build was compiled against a different Node.js version using NODE_MODULE_VERSION 108. This version of Node.js requires NODE_MODULE_VERSION 116. Please try re-compiling or re-installing -the module (for instance, using `npm rebuild` or `npm install`).

How the natives are handled

Locally, this can be fixed by rebuilding the binaries, which is what npm run switch-electron does, which uses electron-rebuild under the hood.

When the deliveries are built (see Build deliveries locally), it is not feasible to rebuild the dependencies since we are building for multiple platforms. Luckily, better-sqlite3 provides these prebuilt binaries from us, available as artifacts on their GitHub releases page

The build script manages the natives for better-sqlite3 by keeping a copy of the .node file for every platform in bin/better-sqlite3.

Whenever the version of better-sqlite3 changes, the .node files must also be renewed based on their releases page. To simplify this process, a script was created in bin/better-sqlite3/update.sh.

How to update the natives

The update script needs to know the version of Electron or Node.js for which to download the prebuilt binaries.

If you get errors during download, check on the releases page to ensure that this particular combination of Electron/Node actually exists for the given release.

To determine the NODE_MODULE_VERSION that is required, look for This version of Node.js requires
NODE_MODULE_VERSION in the error when starting Trilium via:

Check which files got changed after running the update script and for each platform that got changed, test it locally via Build deliveries locally or via the CI.

+the module (for instance, using `npm rebuild` or `npm install`).

How the natives are handled

Locally, this can be fixed by rebuilding the binaries, which is what npm run electron:switch does, which uses electron-rebuild under the hood.

When the deliveries are built (see Build deliveries locally), it is not feasible to rebuild the dependencies since we are building for multiple platforms. Luckily, better-sqlite3 provides these prebuilt binaries from us, available as artifacts on their GitHub releases page

The build script manages the natives for better-sqlite3 by keeping a copy of the .node file for every platform in bin/better-sqlite3.

Whenever the version of better-sqlite3 changes, the .node files must also be renewed based on their releases page. To simplify this process, a script was created in bin/better-sqlite3/update.sh.

How to update the natives

The update script needs to know the version of Electron or Node.js for which to download the prebuilt binaries.

If you get errors during download, check on the releases page to ensure that this particular combination of Electron/Node actually exists for the given release.

To determine the NODE_MODULE_VERSION that is required, look for This version of Node.js requires
NODE_MODULE_VERSION in the error when starting Trilium via:

Check which files got changed after running the update script and for each platform that got changed, test it locally via Build deliveries locally or via the CI.

diff --git a/docs/btM6L9JtG301.html b/docs/btM6L9JtG301.html index 6188237d3..f8a6b4701 100644 --- a/docs/btM6L9JtG301.html +++ b/docs/btM6L9JtG301.html @@ -38,7 +38,7 @@
-

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run switch-electron

Then run Electron:

npm run electron:start

To run Electron using the same data directory as the production version:

npm run electron:start-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch
+

Run server

Run with default settings:

npm run server:start

Run with custom port:

TRILIUM_PORT=8082 npm run server:start

Run Electron

Rebuild better-sqlite3 dependency:

npm run electron:switch

Then run Electron:

npm run electron:start

To run Electron using the same data directory as the production version:

npm run electron:start-no-dir

When done, switch back the better-sqlite3 dependency:

npm run server:switch