perf: cache electron executable path

This commit is contained in:
alex8088 2022-09-18 01:46:02 +08:00
parent c6bade23b5
commit cd0bbb6cfb

View file

@ -20,7 +20,9 @@ const ensureElectronEntryFile = (root = process.cwd()): void => {
} }
} }
const getElectronPath = (): string => { export const getElectronPath = (): string => {
let electronExecPath = process.env.ELECTRON_EXEC_PATH || ''
if (!electronExecPath) {
const electronModulePath = path.resolve(process.cwd(), 'node_modules', 'electron') const electronModulePath = path.resolve(process.cwd(), 'node_modules', 'electron')
const pathFile = path.join(electronModulePath, 'path.txt') const pathFile = path.join(electronModulePath, 'path.txt')
let executablePath let executablePath
@ -28,10 +30,13 @@ const getElectronPath = (): string => {
executablePath = fs.readFileSync(pathFile, 'utf-8') executablePath = fs.readFileSync(pathFile, 'utf-8')
} }
if (executablePath) { if (executablePath) {
return path.join(electronModulePath, 'dist', executablePath) electronExecPath = path.join(electronModulePath, 'dist', executablePath)
process.env.ELECTRON_EXEC_PATH = electronExecPath
} else { } else {
throw new Error('Electron uninstall') throw new Error('Electron uninstall')
} }
}
return electronExecPath
} }
export function startElectron(root: string | undefined, logger: Logger): ChildProcessWithoutNullStreams { export function startElectron(root: string | undefined, logger: Logger): ChildProcessWithoutNullStreams {