"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
function workingDir(dir, cwd, checkExisting = true) {
    let finalDir = dir;
    if (cwd) {
        if (path_1.default.isAbsolute(cwd) && (!checkExisting || fs_extra_1.default.existsSync(cwd))) {
            finalDir = cwd;
        }
        else {
            const resolved = path_1.default.resolve(finalDir, cwd);
            if (!checkExisting || fs_extra_1.default.existsSync(resolved)) {
                finalDir = resolved;
            }
        }
    }
    return finalDir;
}
exports.default = workingDir;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ya2luZy1kaXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC93b3JraW5nLWRpci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLGdEQUF3QjtBQUV4Qix3REFBMEI7QUFFMUIsU0FBd0IsVUFBVSxDQUFDLEdBQVcsRUFBRSxHQUFXLEVBQUUsYUFBYSxHQUFHLElBQUk7SUFDL0UsSUFBSSxRQUFRLEdBQUcsR0FBRyxDQUFDO0lBQ25CLElBQUksR0FBRyxFQUFFO1FBQ1AsSUFBSSxjQUFJLENBQUMsVUFBVSxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQyxhQUFhLElBQUksa0JBQUUsQ0FBQyxVQUFVLENBQUMsR0FBRyxDQUFDLENBQUMsRUFBRTtZQUNsRSxRQUFRLEdBQUcsR0FBRyxDQUFDO1NBQ2hCO2FBQU07WUFDTCxNQUFNLFFBQVEsR0FBRyxjQUFJLENBQUMsT0FBTyxDQUFDLFFBQVEsRUFBRSxHQUFHLENBQUMsQ0FBQztZQUM3QyxJQUFJLENBQUMsYUFBYSxJQUFJLGtCQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxFQUFFO2dCQUM3QyxRQUFRLEdBQUcsUUFBUSxDQUFDO2FBQ3JCO1NBQ0Y7S0FDRjtJQUVELE9BQU8sUUFBUSxDQUFDO0FBQ2xCLENBQUM7QUFkRCw2QkFjQyJ9