"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
const fs = require("mz/fs");
/**
 * Creates a symlink. Re-link if a symlink already exists at the supplied
 * srcPath. API compatible with [`fs#symlink`](https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback).
 */
function forceSymlink(srcPath, dstPath, type) {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            yield fs.symlink(srcPath, dstPath, type);
        }
        catch (err) {
            if (err.code !== 'EEXIST')
                throw err;
            const linkString = yield fs.readlink(dstPath);
            if (srcPath === linkString) {
                return;
            }
            yield fs.unlink(dstPath);
            yield forceSymlink(srcPath, dstPath, type);
        }
    });
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = forceSymlink;
//# sourceMappingURL=forceSymlink.js.map