chore(scripts): fix electron rebuild failing due to Python on NixOS
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
import { join, resolve } from "path";
|
||||
import { cpSync, exists, existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
||||
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
||||
import { execSync } from "child_process";
|
||||
import { rebuild } from "@electron/rebuild"
|
||||
import { getElectronPath, isNixOS } from "./utils.mjs";
|
||||
import { isNixOS } from "./utils.mjs";
|
||||
|
||||
const workspaceRoot = join(import.meta.dirname, "..");
|
||||
|
||||
// On NixOS, re-execute this script inside `nix develop` to get access to Python and other build tools
|
||||
if (isNixOS() && !process.env.IN_NIX_SHELL) {
|
||||
console.log("Detected NixOS, re-running electron-rebuild inside 'nix develop'...");
|
||||
try {
|
||||
execSync("nix develop -c pnpm exec tsx scripts/electron-rebuild.mts", {
|
||||
cwd: workspaceRoot,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, IN_NIX_SHELL: "1" }
|
||||
});
|
||||
process.exit(0);
|
||||
} catch (e) {
|
||||
console.error("Failed to run electron-rebuild inside 'nix develop'.");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function copyNativeDependencies(projectRoot: string) {
|
||||
const destPath = join(projectRoot, "node_modules/better-sqlite3");
|
||||
|
||||
@@ -46,20 +62,8 @@ async function rebuildNativeDependencies(projectRoot: string) {
|
||||
|
||||
function determineElectronVersion(projectRoot: string) {
|
||||
const packageJson = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf-8"));
|
||||
|
||||
if (isNixOS()) {
|
||||
console.log("Detected NixOS, reading Electron version from PATH");
|
||||
|
||||
try {
|
||||
return execSync(`${getElectronPath()} --version`, { }).toString("utf-8");
|
||||
} catch (e) {
|
||||
console.error("Got error while trying to read the Electron version from shell. Make sure that an Electron version is in the PATH (e.g. `nix-shell -p electron`)");
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
console.log("Using Electron version from package.json");
|
||||
return packageJson.devDependencies.electron;
|
||||
}
|
||||
console.log("Using Electron version from package.json");
|
||||
return packageJson.devDependencies.electron;
|
||||
}
|
||||
|
||||
for (const projectRoot of [ "apps/desktop", "apps/edit-docs" ]) {
|
||||
|
||||
Reference in New Issue
Block a user