"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');
const path = require('path');
const linkBins_1 = require('./linkBins');
function linkBundledDeps(root) {
    const nodeModules = path.join(root, 'node_modules');
    return isDir(nodeModules, () => Promise.all(fs.readdirSync(nodeModules).map((mod) => isDir(path.join(nodeModules, mod), () => symlinkBundledDep(nodeModules, path.join(nodeModules, mod))))));
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = linkBundledDeps;
function symlinkBundledDep(nodeModules, submod) {
    return linkBins_1.default(nodeModules);
}
function isDir(path, fn) {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            const stat = yield fs.stat(path);
            if (!stat.isDirectory())
                return;
            return fn();
        }
        catch (err) {
            if (err.code !== 'ENOENT')
                throw err;
        }
    });
}
//# sourceMappingURL=linkBundledDeps.js.map