import { execFile } from 'child_process';
import { dirname, resolve as resolvePath } from 'path';
export default async function executeScript(scriptPath) {
    const resolvedScriptPath = resolvePath(scriptPath);
    return new Promise((resolve, reject) => {
        execFile(process.execPath, [resolvedScriptPath], {
            cwd: dirname(resolvedScriptPath),
            encoding: 'utf8',
        }, (error, stdout, stderr) => {
            if (error) {
                const output = stderr.trim() || error.message;
                return reject(new Error(`Unable to execute hook script "${resolvedScriptPath}": ${output}`));
            }
            resolve(stdout || stderr || '');
        });
    });
}
