Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/scripts/install-electron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
#
# Workaround: electron@42 ships without a postinstall script and lazily
# downloads its binary on the first require('electron'). Its install.js
# uses @electron/get (ESM, loaded via require(esm)) and extract-zip. On
# recent Node (observed on Node 26) the extract-zip stage silently exits
# 0 without writing node_modules/electron/path.txt, so subsequent
# require('electron') calls fail with ENOENT.
#
# This script downloads the binary with @electron/get (which works on its
# own) and extracts it with the system `unzip`, then writes path.txt the
# way install.js would have.
#
# TODO: try removing this script and the workflow call to it when
# upgrading to electron 43 or newer -- upstream may have fixed the
# install.js bug by then.

set -euo pipefail

ELECTRON_DIR="node_modules/electron"

# electron <42 has a working postinstall that writes path.txt itself, so
# we only run when path.txt is missing.
if [ -f "$ELECTRON_DIR/path.txt" ]; then
exit 0
fi

RED='\033[1;31m'
NC='\033[0m'
ELECTRON_VERSION=$(node -p "require('./$ELECTRON_DIR/package.json').version")
printf "${RED}=====================================================================${NC}\n"
printf "${RED}WARNING: applying broken-electron-installer workaround for electron@${ELECTRON_VERSION}.${NC}\n"
printf "${RED}Try removing .github/scripts/install-electron.sh and its workflow call${NC}\n"
printf "${RED}when upgrading to electron 43 or newer.${NC}\n"
printf "${RED}=====================================================================${NC}\n"

ZIPPATH=$(cd "$ELECTRON_DIR" && node -e "(async () => {
const { downloadArtifact } = await import('@electron/get');
const { version } = require('./package.json');
const zipPath = await downloadArtifact({ version, artifactName: 'electron', platform: process.platform, arch: process.arch });
process.stdout.write(zipPath);
})().catch(e => { console.error(e); process.exit(1); });")

echo "Downloaded $ZIPPATH, extracting via system unzip..."
mkdir -p "$ELECTRON_DIR/dist"
unzip -q -o "$ZIPPATH" -d "$ELECTRON_DIR/dist"

case "${RUNNER_OS:-$(uname -s)}" in
Linux|Linux*) printf electron > "$ELECTRON_DIR/path.txt" ;;
macOS|Darwin*) printf "Electron.app/Contents/MacOS/Electron" > "$ELECTRON_DIR/path.txt" ;;
Windows|MINGW*|MSYS*|CYG*) printf electron.exe > "$ELECTRON_DIR/path.txt" ;;
*) echo "ERROR: unknown OS '${RUNNER_OS:-$(uname -s)}'"; exit 1 ;;
esac

test -f "$ELECTRON_DIR/path.txt" || { echo "ERROR: path.txt missing after workaround"; ls -la "$ELECTRON_DIR/"; exit 1; }
49 changes: 22 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
name: Tests

on:
- pull_request
- push
on: push

env:
CI: 1

defaults:
run:
shell: bash

jobs:
main:
defaults:
run:
shell: bash

strategy:
matrix:
include:
Expand All @@ -21,20 +19,13 @@ jobs:
node_version: latest
electron_version: latest
experimental: false
- os: ubuntu-latest
node_version: 16
electron_version: latest
experimental: false
- os: ubuntu-latest
node_version: 14
electron_version: latest
electron_version: 41
nw_version: 0.81.0
experimental: true

# Different electron version
- os: ubuntu-latest
node_version: latest
electron_version: 16
experimental: true
- os: ubuntu-latest
node_version: latest
electron_version: 13
Expand All @@ -46,7 +37,7 @@ jobs:
electron_version: latest
experimental: true
- os: windows-latest
node_version: builtin # For an unknown reason, setup-node freezes
node_version: latest
electron_version: latest
experimental: true

Expand All @@ -55,19 +46,23 @@ jobs:
continue-on-error: ${{ matrix.experimental }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node_version }}
if: matrix.node_version != 'builtin'

- run: npm config set script-shell 'bash'
if: runner.os == 'Windows'

- run: npm install

- run: npm install -D electron@${{ matrix.electron_version }}
if: matrix.electron_version != 'latest'
- run: |
if [ "${{ matrix.electron_version }}" != 'latest' ]; then
npm install -D electron@${{ matrix.electron_version }}
fi
if [ -n "${{ matrix.nw_version }}" ]; then
npm install -D nw@${{ matrix.nw_version }}
fi
npm install
# Workaround for broken electron@42 installer on modern Node.
# Remove this call when upgrading to electron 43+ and the
# upstream installer works again.
.github/scripts/install-electron.sh

- run: |
if [ "${RUNNER_OS}" = 'Linux' ]; then
Expand Down
1 change: 1 addition & 0 deletions e2e/vite-isolation-context-sandbox/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default defineConfig({
vite: mergeConfig(commonConfig, {
resolve: {
browserField: false,
conditions: ['node', 'module', 'import', 'require', 'default'],
}
}),
},
Expand Down
Loading