"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 forceSymlink_1 = require('./forceSymlink');
const path = require('path');
const os = require('os');
const mkdirp = require('mkdirp-promise/lib/node4');
// Always use "junctions" on Windows. Even though support for "symbolic links" was added in Vista+, users by default
// lack permission to create them
const symlinkType = os.platform() === 'win32' ? 'junction' : 'dir';
/**
 * Relative symlink
 */
function relSymlink(src, dest) {
    return __awaiter(this, void 0, void 0, function* () {
        // Junction points can't be relative
        const rel = symlinkType !== 'junction' ? path.relative(path.dirname(dest), src) : src;
        try {
            yield forceSymlink_1.default(rel, dest, symlinkType);
        }
        catch (err) {
            if (err.code === 'ENOENT') {
                yield mkdirp(path.dirname(dest));
                yield forceSymlink_1.default(rel, dest, symlinkType);
                return;
            }
            throw err;
        }
    });
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = relSymlink;
//# sourceMappingURL=index.js.map