Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: rework async filter
  • Loading branch information
goosewobbler committed May 16, 2024
commit a09630d54c593f2873fee5a0bcc641a6785ab648
29 changes: 17 additions & 12 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,27 @@ export async function getBinaryPath(
const binaryPaths = outDirs.map((outDir) => path.join(outDir, electronBinaryPath));

// for each path, check if it exists and is executable
const executableBinaryPaths = binaryPaths.filter(async (binaryPath) => {
try {
await fs.access(binaryPath, fs.constants.X_OK);
return true;
} catch (e) {
log.debug(e);
return false;
}
});

// no binary case
const binaryPathsAccessResults = await Promise.all(
binaryPaths.map(async (binaryPath) => {
try {
await fs.access(binaryPath, fs.constants.X_OK);
return true;
} catch (e) {
log.debug(e);
return false;
}
}),
);

// get the list of executable paths
const executableBinaryPaths = binaryPaths.filter((_binaryPath, index) => binaryPathsAccessResults[index]);

// no executable binary case
if (executableBinaryPaths.length === 0) {
throw new Error(`No executable binary found, checked: \n[${binaryPaths.join(', \n')}]`);
}

// multiple binaries case
// multiple executable binaries case
if (executableBinaryPaths.length > 1) {
log.debug(`Detected multiple app binaries, using the first one: \n${executableBinaryPaths.join(', \n')}`);
}
Expand Down