feat(nx/desktop): integrate rebuild at monorepo level

This commit is contained in:
Elian Doran 2025-05-06 09:09:56 +03:00
parent cf492a5f47
commit 19f6f3352d
No known key found for this signature in database
6 changed files with 25 additions and 68 deletions

View File

@ -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\")"
}
}
},

View File

@ -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",

View File

@ -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();

View File

@ -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",

9
pnpm-lock.yaml generated
View File

@ -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

View File

@ -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.