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:

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

+

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

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 .\"",