/
githubmirror
/
pixijs
Обзор
Документация
Войти
/
githubmirror
/
pixijs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
scripts/utils/spawn.mts
60 строк
2 KB
Zyie
chore: consolidate build and test scripts (#11910)
13 фев 2026, 19:52
Не верифицирован
13 фев 2026, 19:52
b44db4b
Код
Авторство
О чём код?
import childProcess from 'child_process'; import path from 'path'; export const spawn = (command: string, args: string[], options: childProcess.SpawnOptions & { signal?: AbortSignal } = {}) => new Promise<void>((resolve, reject) => { const { signal, ...spawnOptions } = options; const binPath = path.resolve(process.cwd(), 'node_modules/.bin'); const envPath = `${binPath}${path.delimiter}${process.env.PATH}`; const child = childProcess.spawn(command, args, { stdio: 'inherit', cwd: process.cwd(), shell: process.platform === 'win32', ...spawnOptions, env: { ...process.env, ...spawnOptions.env, PATH: envPath }, }); let settled = false; let aborted = false; const settle = (fn: () => void) => { if (!settled) { settled = true; fn(); } }; if (signal) { if (signal.aborted) { child.kill('SIGTERM'); settle(() => resolve()); return; } signal.addEventListener('abort', () => { aborted = true; child.kill('SIGTERM'); }, { once: true }); } child.on('close', (code) => { if (code === 0 || aborted) { settle(() => resolve()); } else { settle(() => reject(new Error(`"${command} ${args.join(' ')}" exited with code ${code}`))); } }); child.on('error', (err) => settle(() => reject(err))); });