fix windows extensions (#1968)

This commit is contained in:
Max Novich
2025-04-08 10:07:37 -07:00
committed by GitHub
parent 48ac6a3925
commit 03c06c9bf6
23 changed files with 562 additions and 415 deletions

View File

@@ -4,18 +4,41 @@ import Electron from 'electron';
import log from './logger';
export const getBinaryPath = (app: Electron.App, binaryName: string): string => {
const isDev = process.env.NODE_ENV === 'development';
const isPackaged = app.isPackaged;
const isWindows = process.platform === 'win32';
const executableName = isWindows
? binaryName === 'npx'
? 'npx.cmd'
: `${binaryName}.exe`
: binaryName;
const possiblePaths = [];
if (isWindows) {
addPaths(isWindows, possiblePaths, `${binaryName}.exe`, app);
addPaths(isWindows, possiblePaths, `${binaryName}.cmd`, app);
} else {
addPaths(isWindows, possiblePaths, binaryName, app);
}
for (const binPath of possiblePaths) {
try {
if (fs.existsSync(binPath)) {
return binPath;
}
} catch (error) {
log.error(`Error checking path ${binPath}:`, error);
}
}
throw new Error(
`Could not find ${binaryName} binary in any of the expected locations: ${possiblePaths.join(
', '
)}`
);
};
const addPaths = (
isWindows: boolean,
possiblePaths: any[],
executableName: string,
app: Electron.App
): void => {
const isDev = process.env.NODE_ENV === 'development';
const isPackaged = app.isPackaged;
if (isDev && !isPackaged) {
possiblePaths.push(
path.join(process.cwd(), 'src', 'bin', executableName),
@@ -36,18 +59,4 @@ export const getBinaryPath = (app: Electron.App, binaryName: string): string =>
);
}
}
for (const binPath of possiblePaths) {
try {
if (fs.existsSync(binPath)) {
return binPath;
}
} catch (error) {
log.error(`Error checking path ${binPath}:`, error);
}
}
throw new Error(
`Could not find ${binaryName} binary in any of the expected locations: ${possiblePaths.join(', ')}`
);
};