You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
722 B

  1. // Verifica disponibilità di binari di sistema invocati via child_process.
  2. // Cache in-memory per processo: i binari non vengono installati/disinstallati durante un run.
  3. import { spawn } from 'node:child_process';
  4. const cache = new Map<string, boolean>();
  5. export async function checkSystemBin(name: string, versionArg = '-version'): Promise<boolean> {
  6. const hit = cache.get(name);
  7. if (hit !== undefined) return hit;
  8. const ok = await new Promise<boolean>(resolve => {
  9. const p = spawn(name, [versionArg]);
  10. p.on('error', () => resolve(false));
  11. p.on('exit', code => resolve(code === 0));
  12. });
  13. if (!ok) console.warn(`[system-bins] '${name}' non trovato su PATH`);
  14. cache.set(name, ok);
  15. return ok;
  16. }