Skip to content

Commit 2657ed0

Browse files
committed
fix: handle Electron spawn in benchmark auto-run guard
The require.main === module check fails when Electron spawns the script via spawn(electronBinary, [scriptPath]) because Electron's module loader sets require.main differently. Added fallback check on process.argv[1] to handle both plain Node and Electron spawn.
1 parent 46fac0e commit 2657ed0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

skills/analysis/home-security-benchmark/scripts/run-benchmark.cjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,8 +1806,13 @@ async function main() {
18061806
process.exit(failed > 0 ? 1 : 0);
18071807
}
18081808

1809-
// Only run when executed directly (not when require()'d for syntax/import checks)
1810-
if (require.main === module) {
1809+
// Run when executed directly — supports both plain Node and Electron spawn.
1810+
// `require.main === module` works for `node script.cjs`.
1811+
// `process.argv[1]` check handles `spawn(electronBinary, [scriptPath])`.
1812+
const isDirectRun = require.main === module ||
1813+
(process.argv[1] && require('path').resolve(process.argv[1]) === __filename);
1814+
1815+
if (isDirectRun) {
18111816
main().catch(err => {
18121817
log(`Fatal: ${err.message}`);
18131818
emit({ event: 'error', message: err.message });

0 commit comments

Comments
 (0)