diff --git a/.github/scripts/install-electron.sh b/.github/scripts/install-electron.sh new file mode 100755 index 0000000..438f911 --- /dev/null +++ b/.github/scripts/install-electron.sh @@ -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; } diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 894864d..2086dee 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/e2e/vite-isolation-context-sandbox/vite.config.ts b/e2e/vite-isolation-context-sandbox/vite.config.ts index 90eaf1a..e0037d4 100644 --- a/e2e/vite-isolation-context-sandbox/vite.config.ts +++ b/e2e/vite-isolation-context-sandbox/vite.config.ts @@ -31,6 +31,7 @@ export default defineConfig({ vite: mergeConfig(commonConfig, { resolve: { browserField: false, + conditions: ['node', 'module', 'import', 'require', 'default'], } }), },