"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 tape = require('tape');
const promisifyTape = require('tape-promise');
const test = promisifyTape(tape);
const path = require('path');
const isExecutable_1 = require('./support/isExecutable');
const prepare_1 = require('./support/prepare');
const mkdirp = require('mkdirp');
const thenify = require('thenify');
const ncpCB = require('ncp');
const ncp = thenify(ncpCB.ncp);
const src_1 = require('../src');
const localPkg_1 = require('./support/localPkg');
const testDefaults_1 = require('./support/testDefaults');
test('relative link', function (t) {
    return __awaiter(this, void 0, void 0, function* () {
        prepare_1.default();
        const tmpDir = path.resolve(__dirname, '..', '.tmp');
        const linkedPkgName = 'hello-world-js-bin';
        const linkedPkgDirName = linkedPkgName + Math.random().toString();
        const linkedPkgPath = path.resolve(tmpDir, linkedPkgDirName);
        yield ncp(localPkg_1.pathToLocalPkg(linkedPkgName), linkedPkgPath);
        yield src_1.linkFromRelative(`../${linkedPkgDirName}`, testDefaults_1.default());
        isExecutable_1.default(t, path.join(process.cwd(), 'node_modules', '.bin', 'hello-world-js-bin'));
    });
});
test('global link', function (t) {
    return __awaiter(this, void 0, void 0, function* () {
        const tmpDir = path.resolve(__dirname, '..', '.tmp');
        mkdirp.sync(tmpDir);
        const linkedPkgName = 'hello-world-js-bin';
        const linkedPkgPath = path.resolve(tmpDir, linkedPkgName + Math.random().toString());
        yield ncp(localPkg_1.pathToLocalPkg(linkedPkgName), linkedPkgPath);
        process.chdir(linkedPkgPath);
        yield src_1.linkToGlobal(testDefaults_1.default());
        prepare_1.default();
        yield src_1.linkFromGlobal(linkedPkgName, testDefaults_1.default());
        isExecutable_1.default(t, path.join(process.cwd(), 'node_modules', '.bin', 'hello-world-js-bin'));
    });
});
test('link local package if link-local = true', function (t) {
    return __awaiter(this, void 0, void 0, function* () {
        prepare_1.default();
        const tmpDir = path.resolve(__dirname, '..', '.tmp');
        const linkedPkgName = 'hello-world-js-bin';
        const linkedPkgDirName = linkedPkgName + Math.random().toString();
        const linkedPkgPath = path.resolve(tmpDir, linkedPkgDirName);
        yield ncp(localPkg_1.pathToLocalPkg(linkedPkgName), linkedPkgPath);
        yield src_1.installPkgs([`file:../${linkedPkgDirName}`], testDefaults_1.default({ linkLocal: true }));
        isExecutable_1.default(t, path.join(process.cwd(), 'node_modules', '.bin', 'hello-world-js-bin'));
    });
});
//# sourceMappingURL=link.js.map