fix: use existsSync instead of require(fs) in ESM module

This commit is contained in:
Michess
2026-04-13 14:25:31 +02:00
parent 4bc6ea58e6
commit f7b87f2941

View File

@@ -1,4 +1,5 @@
import { spawn, ChildProcess } from "child_process"; import { spawn, ChildProcess } from "child_process";
import { existsSync } from "fs";
export interface StockfishLevel { export interface StockfishLevel {
level: number; level: number;
@@ -32,8 +33,7 @@ export class StockfishEngine {
try { try {
// Debian installs stockfish to /usr/games/stockfish // Debian installs stockfish to /usr/games/stockfish
const sfBin = ["/usr/games/stockfish", "/usr/bin/stockfish", "stockfish"] const sfBin = ["/usr/games/stockfish", "/usr/bin/stockfish", "stockfish"]
.find(p => { try { require("fs").accessSync(p); return true; } catch { return false; } }) .find(p => existsSync(p)) ?? "stockfish";
?? "stockfish";
this.process = spawn(sfBin, [], { this.process = spawn(sfBin, [], {
stdio: ["pipe", "pipe", "pipe"], stdio: ["pipe", "pipe", "pipe"],