|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Workaround: electron@42 ships without a postinstall script and lazily |
| 4 | +# downloads its binary on the first require('electron'). Its install.js |
| 5 | +# uses @electron/get (ESM, loaded via require(esm)) and extract-zip. On |
| 6 | +# recent Node (observed on Node 26) the extract-zip stage silently exits |
| 7 | +# 0 without writing node_modules/electron/path.txt, so subsequent |
| 8 | +# require('electron') calls fail with ENOENT. |
| 9 | +# |
| 10 | +# This script downloads the binary with @electron/get (which works on its |
| 11 | +# own) and extracts it with the system `unzip`, then writes path.txt the |
| 12 | +# way install.js would have. |
| 13 | +# |
| 14 | +# TODO: try removing this script and the workflow call to it when |
| 15 | +# upgrading to electron 43 or newer -- upstream may have fixed the |
| 16 | +# install.js bug by then. |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +ELECTRON_DIR="node_modules/electron" |
| 21 | + |
| 22 | +# electron <42 has a working postinstall that writes path.txt itself, so |
| 23 | +# we only run when path.txt is missing. |
| 24 | +if [ -f "$ELECTRON_DIR/path.txt" ]; then |
| 25 | + exit 0 |
| 26 | +fi |
| 27 | + |
| 28 | +RED='\033[1;31m' |
| 29 | +NC='\033[0m' |
| 30 | +ELECTRON_VERSION=$(node -p "require('./$ELECTRON_DIR/package.json').version") |
| 31 | +printf "${RED}=====================================================================${NC}\n" |
| 32 | +printf "${RED}WARNING: applying broken-electron-installer workaround for electron@${ELECTRON_VERSION}.${NC}\n" |
| 33 | +printf "${RED}Try removing .github/scripts/install-electron.sh and its workflow call${NC}\n" |
| 34 | +printf "${RED}when upgrading to electron 43 or newer.${NC}\n" |
| 35 | +printf "${RED}=====================================================================${NC}\n" |
| 36 | + |
| 37 | +ZIPPATH=$(cd "$ELECTRON_DIR" && node -e "(async () => { |
| 38 | + const { downloadArtifact } = await import('@electron/get'); |
| 39 | + const { version } = require('./package.json'); |
| 40 | + const zipPath = await downloadArtifact({ version, artifactName: 'electron', platform: process.platform, arch: process.arch }); |
| 41 | + process.stdout.write(zipPath); |
| 42 | +})().catch(e => { console.error(e); process.exit(1); });") |
| 43 | + |
| 44 | +echo "Downloaded $ZIPPATH, extracting via system unzip..." |
| 45 | +mkdir -p "$ELECTRON_DIR/dist" |
| 46 | +unzip -q -o "$ZIPPATH" -d "$ELECTRON_DIR/dist" |
| 47 | + |
| 48 | +case "${RUNNER_OS:-$(uname -s)}" in |
| 49 | + Linux|Linux*) printf electron > "$ELECTRON_DIR/path.txt" ;; |
| 50 | + macOS|Darwin*) printf "Electron.app/Contents/MacOS/Electron" > "$ELECTRON_DIR/path.txt" ;; |
| 51 | + Windows|MINGW*|MSYS*|CYG*) printf electron.exe > "$ELECTRON_DIR/path.txt" ;; |
| 52 | + *) echo "ERROR: unknown OS '${RUNNER_OS:-$(uname -s)}'"; exit 1 ;; |
| 53 | +esac |
| 54 | + |
| 55 | +test -f "$ELECTRON_DIR/path.txt" || { echo "ERROR: path.txt missing after workaround"; ls -la "$ELECTRON_DIR/"; exit 1; } |
0 commit comments