diff --git a/apps/desktop/package.json b/apps/desktop/package.json index e18dcabdb..2a700df33 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.json index b7d38a321..e5682a823 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.mts deleted file mode 100644 index 1dc3c5b04..000000000 --- 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.json index d43347578..44e22ba07 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.yaml index b03c44ff5..f171aef40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,6 +15,9 @@ importers: specifier: ^4.21.2 version: 4.21.2 devDependencies: + '@electron/rebuild': + specifier: 4.0.1 + version: 4.0.1 '@eslint/js': specifier: ^9.8.0 version: 9.25.0 @@ -354,9 +357,6 @@ importers: '@electron-forge/plugin-auto-unpack-natives': specifier: 7.8.0 version: 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.1 version: 7.0.1 devDependencies: - '@electron/rebuild': - specifier: 4.0.1 - version: 4.0.1 '@triliumnext/client': specifier: workspace:* version: link:../client diff --git a/apps/desktop/scripts/rebuild.mts b/scripts/electron-rebuild.mts similarity index 62% rename from apps/desktop/scripts/rebuild.mts rename to scripts/electron-rebuild.mts index 70c599dcc..1e38fcfde 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.