Skip to content

fix: honor ELECTRON_INSTALL_PLATFORM in getPlatformPath#51029

Merged
jkleinsc merged 1 commit into
electron:mainfrom
officialasishkumar:fix/install-platform-path-env-var
Apr 28, 2026
Merged

fix: honor ELECTRON_INSTALL_PLATFORM in getPlatformPath#51029
jkleinsc merged 1 commit into
electron:mainfrom
officialasishkumar:fix/install-platform-path-env-var

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Description of Change

Fixes #51027.

npm/install.js resolves the target platform in two places and the two disagree when the documented ELECTRON_INSTALL_PLATFORM env var is used.

downloadArtifact honors the new env var (added in #49981):

const platform = process.env.ELECTRON_INSTALL_PLATFORM
  || process.env.npm_config_platform
  || process.platform;

But getPlatformPath(), which produces the executable path written to path.txt and compared in isInstalled(), was not updated and still only checks npm_config_platform. On, for example, a Linux host running ELECTRON_INSTALL_PLATFORM=darwin npm install electron, the darwin zip is downloaded but path.txt is written as electron (the Linux executable name) — so subsequent isInstalled() checks always fail (forcing redundant re-downloads) and any tool reading path.txt sees the wrong filename for the artifact that was actually extracted.

Bring getPlatformPath() in line with the download resolution by checking ELECTRON_INSTALL_PLATFORM first.

Checklist

Release Notes

Notes: Fixed ELECTRON_INSTALL_PLATFORM being ignored when resolving the Electron executable path during postinstall, which caused path.txt to be written for the host platform instead of the requested target and made isInstalled() always re-download on subsequent installs.

@officialasishkumar officialasishkumar requested a review from a team as a code owner April 13, 2026 22:53
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Apr 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Apr 13, 2026
@codebytere codebytere requested a review from erickzhao April 14, 2026 10:31

@erickzhao erickzhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@erickzhao erickzhao added the target/42-x-y PR should also be added to the "42-x-y" branch. label Apr 14, 2026
@erickzhao

Copy link
Copy Markdown
Member

The original PRs are landing in 42-x-y so I'm backporting this there.

@officialasishkumar you'll need to sign your commits to land a PR in the Electron org. Thanks in advance!

@erickzhao erickzhao added the semver/minor backwards-compatible functionality label Apr 14, 2026
@erickzhao erickzhao added the semver/patch backwards-compatible bug fixes label Apr 14, 2026
@erickzhao erickzhao added api-review/requested 🗳 and removed semver/minor backwards-compatible functionality labels Apr 14, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Apr 14, 2026
@ckerr

ckerr commented Apr 15, 2026

Copy link
Copy Markdown
Member

@officialasishkumar looks like all of CI is green except for the "commits need to be signed" check. Can you force-push up the branch with signed commits?

@itsananderson itsananderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@officialasishkumar officialasishkumar force-pushed the fix/install-platform-path-env-var branch from b352ba7 to 5bfb1b3 Compare April 16, 2026 17:28
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Apr 16, 2026
@officialasishkumar

Copy link
Copy Markdown
Contributor Author

done

@codebytere

Copy link
Copy Markdown
Member

@officialasishkumar you'll need to rebase

The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since electron#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>
@officialasishkumar officialasishkumar force-pushed the fix/install-platform-path-env-var branch from 5bfb1b3 to 99d44b7 Compare April 22, 2026 08:21
@officialasishkumar

Copy link
Copy Markdown
Contributor Author

Rebased onto main and re-signed the commit.

@jkleinsc

Copy link
Copy Markdown
Member

Merging as CI failure unrelated to PR change.

@jkleinsc jkleinsc merged commit e235c3f into electron:main Apr 28, 2026
65 of 67 checks passed
@release-clerk

release-clerk Bot commented Apr 28, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed ELECTRON_INSTALL_PLATFORM being ignored when resolving the Electron executable path during postinstall, which caused path.txt to be written for the host platform instead of the requested target and made isInstalled() always re-download on subsequent installs.

@trop

trop Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "42-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/42-x-y and removed target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 28, 2026
@trop

trop Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

@erickzhao has manually backported this PR to "42-x-y", please check out #51370

@erickzhao

Copy link
Copy Markdown
Member

Auto backport failed due to linter changes, created one myself.

ckerr pushed a commit to erickzhao/ericktron that referenced this pull request Apr 30, 2026
…#51029)

The postinstall script resolves two things from the target platform:

1. Which artifact to download, via `downloadArtifact({ platform, ... })`.
   Since electron#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>
jkleinsc pushed a commit that referenced this pull request May 5, 2026
…51370)

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

* run oxfmt

---------

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
Co-authored-by: Asish Kumar <87874775+officialasishkumar@users.noreply.github.com>
Co-authored-by: Keeley Hammond <vertedinde@electronjs.org>
@trop trop Bot added merged/42-x-y PR was merged to the "42-x-y" branch. and removed in-flight/42-x-y labels May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/42-x-y PR was merged to the "42-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

npm/install.js: getPlatformPath ignores documented ELECTRON_INSTALL_PLATFORM env var

6 participants