fix(desktop): resolve electronDist to the actual electron install location (#48081)

After the June lockfile regeneration (#46652) floated electron and reshuffled
npm workspace hoisting, the desktop pack fails with "The specified electronDist
does not exist". apps/desktop/package.json pointed electronDist at the repo
root (../../node_modules/electron/dist) while npm now installs electron nested
under apps/desktop/node_modules/electron. The two contradict, so a clean
install can never package the app (Windows + macOS).

- electronDist -> node_modules/electron/dist (resolved relative to apps/desktop,
  i.e. the workspace-local install npm actually produces).
- hermes_cli/main.py, scripts/install.sh, scripts/install.ps1: add a runtime
  electron-dir resolver that prefers apps/desktop/node_modules/electron and
  falls back to the root hoist, so dist checks + the mirror re-download work
  under either npm layout.
- patch-electron-builder-mac-binary.cjs: try the workspace-local Electron.app
  before the root hoist in the macOS binary-restore fallback (sibling site no
  PR touched).
- test: assert build.electronDist resolves to where the lockfile installs
  electron, so a future hoist change (root <-> nested) can't silently break it.

Salvages the overlapping work in #48003 (sitkarev), #48012 (omegazheng), and
#48033 (james47kjv).

Co-authored-by: sitkarev <59806492+sitkarev@users.noreply.github.com>
Co-authored-by: omegazheng <zheng@omegasys.eu>
Co-authored-by: james47kjv <220877172+james47kjv@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-17 18:08:01 -05:00
committed by GitHub
co-authored by sitkarev omegazheng james47kjv
parent 016bce1a09
commit f8098c6b6f
8 changed files with 167 additions and 46 deletions
+27
View File
@@ -616,6 +616,33 @@ def test_electron_dist_ok_per_platform(tmp_path, monkeypatch, platform, rel):
assert cli_main._electron_dist_ok(tmp_path) is True
def test_electron_dir_prefers_workspace_local_package(tmp_path):
"""npm may nest electron under apps/desktop; resolve there over the root hoist."""
root_electron = tmp_path / "node_modules" / "electron"
local_electron = tmp_path / "apps" / "desktop" / "node_modules" / "electron"
root_electron.mkdir(parents=True)
local_electron.mkdir(parents=True)
assert cli_main._electron_dir(tmp_path) == local_electron
def test_electron_dir_falls_back_to_root_hoist(tmp_path):
"""When npm hoists electron to the repo root, resolve there."""
root_electron = tmp_path / "node_modules" / "electron"
root_electron.mkdir(parents=True)
assert cli_main._electron_dir(tmp_path) == root_electron
def test_electron_dist_ok_finds_workspace_local_binary(tmp_path, monkeypatch):
"""A nested apps/desktop electron with a valid binary counts as ok."""
monkeypatch.setattr(cli_main.sys, "platform", "linux")
binp = tmp_path / "apps" / "desktop" / "node_modules" / "electron" / "dist" / "electron"
binp.parent.mkdir(parents=True)
binp.write_text("", encoding="utf-8")
assert cli_main._electron_dist_ok(tmp_path) is True
def test_redownload_electron_dist_noop_when_present(tmp_path, monkeypatch):
"""Already-healthy dist → no download, so an unrelated build failure can't
trigger a needless ~200 MB refetch."""