Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(nx/desktop): integrate rebuild at monorepo level
Elian Doran19f6f3352d4f
diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex e18dcabdb6..2a700df332 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -18,8 +18,7 @@"@types/electron-squirrel-startup": "1.0.2","@triliumnext/server": "workspace:*","copy-webpack-plugin": "13.0.0",- "electron": "35.2.2",- "@electron/rebuild": "4.0.1",+ "electron": "35.2.2","@electron-forge/cli": "7.8.0","@electron-forge/maker-deb": "7.8.0","@electron-forge/maker-dmg": "7.8.0",@@ -55,12 +54,10 @@"cache": true,"configurations": {"default": {- "command": "cross-env DEBUG=* tsx scripts/rebuild.mts",- "cwd": "{projectRoot}"+ "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist"},"nixos": {- "command": "cross-env DEBUG=* tsx scripts/rebuild.mts $(nix-shell -p electron_33 --run \"electron --version\")",- "cwd": "{projectRoot}"+ "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist $(nix-shell -p electron_33 --run \"electron --version\")"}}},diff --git a/apps/edit-docs/package.json b/apps/edit-docs/package.jsonindex b7d38a3212..e5682a823c 100644--- a/apps/edit-docs/package.json+++ b/apps/edit-docs/package.json@@ -4,7 +4,6 @@"private": true,"description": "Desktop version of Trilium which imports the demo database (presented to new users at start-up) or the user guide and other documentation and saves the modifications for committing.","devDependencies": {- "@electron/rebuild": "4.0.1","@triliumnext/client": "workspace:*","@triliumnext/desktop": "workspace:*","@types/fs-extra": "11.0.4",@@ -17,19 +16,19 @@"targets": {"rebuild-deps": {"executor": "nx:run-commands",- "dependsOn": [ "build" ],+ "dependsOn": [+ "build"+ ],"defaultConfiguration": "default","cache": true,"configurations": {"default": {- "command": "cross-env DEBUG=* tsx scripts/rebuild.mts",- "cwd": "{projectRoot}"+ "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist"},"nixos": {- "command": "electron-rebuild -f -v $(nix-shell -p electron_35 --run \"electron --version\") dist/main.js -m dist",- "cwd": "{projectRoot}"+ "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist $(nix-shell -p electron_33 --run \"electron --version\")"}- }+ }},"serve": {"executor": "nx:run-commands",diff --git a/apps/edit-docs/scripts/rebuild.mts b/apps/edit-docs/scripts/rebuild.mtsdeleted file mode 100644index 1dc3c5b045..0000000000--- a/apps/edit-docs/scripts/rebuild.mts+++ /dev/null@@ -1,37 +0,0 @@-/**- * @module- *- * This script is used internally by the `rebuild-deps` target of the `desktop`. Normally we could use- * `electron-rebuild` CLI directly, but it would rebuild the monorepo-level dependencies and breaks- * the server build (and it doesn't expose a CLI option to override this).- */--// TODO: Deduplicate with apps/desktop/scripts/rebuild.ts.--import { fileURLToPath } from "url";-import { dirname, join } from "path";-import { rebuild } from "@electron/rebuild"-import { readFileSync } from "fs";--const scriptDir = dirname(fileURLToPath(import.meta.url));-const rootDir = join(scriptDir, "..");--function getElectronVersion() {- const packageJsonPath = join(rootDir, "package.json");- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));- return packageJson.devDependencies.electron;-}--function main() {- const distDir = join(rootDir, "dist");-- rebuild({- // We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.- projectRootPath: distDir,- buildPath: distDir,- force: true,- electronVersion: getElectronVersion(),- });-}--main();diff --git a/package.json b/package.jsonindex d433475781..44e22ba07c 100644--- a/package.json+++ b/package.json@@ -25,6 +25,7 @@"private": true,"devDependencies": {"@eslint/js": "^9.8.0",+ "@electron/rebuild": "4.0.1","@nx/devkit": "20.8.1","@nx/esbuild": "20.8.1","@nx/eslint": "20.8.1",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b03c44ff56..f171aef408 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -15,6 +15,9 @@ importers:specifier: ^4.21.2version: 4.21.2devDependencies:+ '@electron/rebuild':+ specifier: 4.0.1+ version: 4.0.1'@eslint/js':specifier: ^9.8.0version: 9.25.0@@ -354,9 +357,6 @@ importers:'@electron-forge/plugin-auto-unpack-natives':specifier: 7.8.0version: 7.8.0- '@electron/rebuild':- specifier: 4.0.1- version: 4.0.1'@triliumnext/server':specifier: workspace:*version: link:../server@@ -407,9 +407,6 @@ importers:specifier: 7.0.1version: 7.0.1devDependencies:- '@electron/rebuild':- specifier: 4.0.1- version: 4.0.1'@triliumnext/client':specifier: workspace:*version: link:../clientdiff --git a/apps/desktop/scripts/rebuild.mts b/scripts/electron-rebuild.mtssimilarity index 62%rename from apps/desktop/scripts/rebuild.mtsrename to scripts/electron-rebuild.mtsindex 70c599dcc1..1e38fcfdeb 100644--- a/apps/desktop/scripts/rebuild.mts+++ b/scripts/electron-rebuild.mts@@ -6,29 +6,29 @@* the server build (and it doesn't expose a CLI option to override this).*/-import { fileURLToPath } from "url";-import { dirname, join } from "path";+import path, { join } from "path";import { rebuild } from "@electron/rebuild"import { readFileSync } from "fs";-const scriptDir = dirname(fileURLToPath(import.meta.url));-const rootDir = join(scriptDir, "..");--function getElectronVersion() {- if (process.argv[2]) {- return process.argv[2];+function getElectronVersion(distDir: string) {+ if (process.argv[3]) {+ return process.argv[3];}- const packageJsonPath = join(rootDir, "package.json");+ const packageJsonPath = join(distDir, "package.json");const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));return packageJson.devDependencies.electron;}function main() {- const distDir = join(rootDir, "dist");- const electronVersion = getElectronVersion();+ const distDir = path.resolve(process.argv[2]);+ if (!distDir) {+ console.error("Missing root dir as argument.");+ process.exit(1);+ }- console.log(`Rebuilding with version ${electronVersion}...`);+ const electronVersion = getElectronVersion(distDir);+ console.log(`Rebuilding ${distDir} with version ${electronVersion}...`);rebuild({// We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.