Skip to content

Commit c5433b3

Browse files
committed
chore: try fixing electron install
1 parent 5d74ff3 commit c5433b3

2 files changed

Lines changed: 59 additions & 17 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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; }

.github/workflows/tests.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,10 @@ jobs:
6767
npm install -D nw@${{ matrix.nw_version }}
6868
fi
6969
npm install
70-
if [ ! -f node_modules/electron/path.txt ]; then
71-
ZIPPATH=$(cd node_modules/electron && node -e "(async () => {
72-
const { downloadArtifact } = await import('@electron/get');
73-
const { version } = require('./package.json');
74-
const zipPath = await downloadArtifact({ version, artifactName: 'electron', platform: process.platform, arch: process.arch });
75-
process.stdout.write(zipPath);
76-
})().catch(e => { console.error(e); process.exit(1); });")
77-
echo "Downloaded $ZIPPATH, extracting via system unzip..."
78-
mkdir -p node_modules/electron/dist
79-
unzip -q -o "$ZIPPATH" -d node_modules/electron/dist
80-
case "$RUNNER_OS" in
81-
Linux) printf electron > node_modules/electron/path.txt ;;
82-
macOS) printf "Electron.app/Contents/MacOS/Electron" > node_modules/electron/path.txt ;;
83-
Windows) printf electron.exe > node_modules/electron/path.txt ;;
84-
esac
85-
fi
86-
test -f node_modules/electron/path.txt || { echo "ERROR: path.txt missing"; ls -la node_modules/electron/; exit 1; }
70+
# Workaround for broken electron@42 installer on modern Node.
71+
# Remove this call when upgrading to electron 43+ and the
72+
# upstream installer works again.
73+
.github/scripts/install-electron.sh
8774
8875
- run: |
8976
if [ "${RUNNER_OS}" = 'Linux' ]; then

0 commit comments

Comments
 (0)