fix: honor ELECTRON_INSTALL_PLATFORM in getPlatformPath (#51029)

The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since #49981, `platform` is derived from
   `ELECTRON_INSTALL_PLATFORM || npm_config_platform || process.platform`.
2. Which executable path to use for the `isInstalled()` cache check and
   for the `path.txt` marker written after extraction, via
   `getPlatformPath()`.

`getPlatformPath()` was not updated with the rest of that change and
still falls back to `npm_config_platform || os.platform()` only.

As a result, passing `ELECTRON_INSTALL_PLATFORM` (as documented in
`docs/tutorial/installation.md`) causes the two to disagree: the
download fetches the requested platform's zip, but `path.txt` and the
path sanity check are written against the host platform's executable
name. That in turn makes `isInstalled()` always return `false` on
subsequent runs (forcing redundant re-downloads) and makes the
executable path recorded in `path.txt` wrong for the artifact that
was actually extracted (e.g. `electron` written alongside a
`darwin`/`win32` build).

Check `ELECTRON_INSTALL_PLATFORM` first, matching the resolution used
for `downloadArtifact`.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
This commit is contained in:
Asish Kumar
2026-04-28 21:37:05 +05:30
committed by GitHub
parent bbdeb50405
commit e235c3fff0

View File

@@ -96,7 +96,7 @@ function extractFile(zipPath) {
}
function getPlatformPath() {
const platform = process.env.npm_config_platform || os.platform();
const platform = process.env.ELECTRON_INSTALL_PLATFORM || process.env.npm_config_platform || os.platform();
switch (platform) {
case 'mas':