"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.spawnCommand = spawnCommand;
const child_process_1 = require("child_process");
function shellQuote(value) {
    return `"${value.replace(/(["\\])/g, '\\$1')}"`;
}
function shellCommand(command, args) {
    return [command, ...args].map(shellQuote).join(' ');
}
function shouldRetryWithShell(error) {
    if (process.platform !== 'win32') {
        return false;
    }
    const code = error?.code;
    return code === 'EPERM' || code === 'ENOENT';
}
function spawnCommand(command, args, options) {
    const result = (0, child_process_1.spawnSync)(command, args, {
        ...options,
        shell: false
    });
    if (!result.error || !shouldRetryWithShell(result.error)) {
        return result;
    }
    return (0, child_process_1.spawnSync)(shellCommand(command, args), {
        ...options,
        shell: true
    });
}
//# sourceMappingURL=spawn.js.map