[READ-ONLY] Mirror of https://github.com/probablykasper/vite-plugin-electron-x. A Vite plugin for bundling main.ts, preload.ts and running Electron in development
0

Configure Feed

Select the types of activity you want to include in your feed.

Fix electron binary detection

Kasper (Aug 30, 2022, 9:15 AM +0200) 8c01ac65 55ccbf8b

+24 -7
+24 -7
src/index.ts
··· 1 1 import { spawn } from 'child_process' 2 - import { resolve } from 'path' 2 + import { resolve, join } from 'path' 3 3 import { default as esbuild, type BuildOptions as EsbuildOptions } from 'esbuild' 4 4 import { BuildOptions as ViteBuildOptions, Plugin, ResolvedConfig } from 'vite' 5 - import { default as electronPath } from 'electron' 6 5 import fs from 'fs' 7 6 8 - // Spawn electron the same way as electron cli 7 + const electronDir = resolve(process.cwd(), 'node_modules', 'electron') 8 + 9 + // imitates `electron/index.js` 10 + function getElectronPath() { 11 + const pathFile = join(electronDir, 'path.txt') 12 + console.log(pathFile) 13 + 14 + let executablePath: string | undefined 15 + if (fs.existsSync(pathFile)) { 16 + executablePath = fs.readFileSync(pathFile, 'utf-8') 17 + } 18 + if (process.env.ELECTRON_OVERRIDE_DIST_PATH) { 19 + return join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath || 'electron') 20 + } 21 + if (executablePath) { 22 + return join(electronDir, 'dist', executablePath) 23 + } 24 + console.error('Could not get Electron path') 25 + process.exit(1) 26 + } 27 + 28 + // Spawn electron, imitates `electron/cli.js` 9 29 async function spawnElectron(args: string[], env: NodeJS.ProcessEnv) { 10 - if (typeof electronPath !== 'string') { 11 - console.error('Could not get Electron path') 12 - process.exit(1) 13 - } 30 + const electronPath = getElectronPath() 14 31 const child = spawn(electronPath, args, { stdio: 'ignore', env, windowsHide: false }) 15 32 child.on('close', (code, signal) => { 16 33 if (code === null) {