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
6 changed files with 25 additions and 68 deletions

View File

@@ -0,0 +1,42 @@
/**
* @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).
*/
import path, { join } from "path";
import { rebuild } from "@electron/rebuild"
import { readFileSync } from "fs";
function getElectronVersion(distDir: string) {
if (process.argv[3]) {
return process.argv[3];
}
const packageJsonPath = join(distDir, "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
return packageJson.devDependencies.electron;
}
function main() {
const distDir = path.resolve(process.argv[2]);
if (!distDir) {
console.error("Missing root dir as argument.");
process.exit(1);
}
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.
projectRootPath: distDir,
buildPath: distDir,
force: true,
electronVersion,
});
}
main();