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 pathFile = path.join(electronModulePath, 'path.txt')
let executablePath
@ -28,11 +30,14 @@ const getElectronPath = (): string => {
executablePath = fs.readFileSync(pathFile, 'utf-8')
}
if (executablePath) {
return path.join(electronModulePath, 'dist', executablePath)
electronExecPath = path.join(electronModulePath, 'dist', executablePath)
process.env.ELECTRON_EXEC_PATH = electronExecPath
} else {
throw new Error('Electron uninstall')
}
}
return electronExecPath
}
export function startElectron(root: string | undefined, logger: Logger): ChildProcessWithoutNullStreams {
ensureElectronEntryFile(root)