"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const find_packages_1 = require("find-packages");
const loadYamlFile = require("load-yaml-file");
const path = require("path");
const constants_1 = require("./constants");
exports.default = (workspaceRoot) => __awaiter(this, void 0, void 0, function* () {
    const packagesManifest = yield requirePackagesManifest(workspaceRoot);
    const pkgs = yield find_packages_1.default(workspaceRoot, {
        ignore: [
            '**/node_modules/**',
            '**/bower_components/**',
        ],
        patterns: packagesManifest && packagesManifest.packages || undefined,
    });
    pkgs.sort((pkg1, pkg2) => pkg1.path.localeCompare(pkg2.path));
    return pkgs;
});
function requirePackagesManifest(dir) {
    return __awaiter(this, void 0, void 0, function* () {
        try {
            return yield loadYamlFile(path.join(dir, constants_1.WORKSPACE_MANIFEST_FILENAME));
        }
        catch (err) {
            if (err['code'] === 'ENOENT') { // tslint:disable-line
                return null;
            }
            throw err;
        }
    });
}
//# sourceMappingURL=findWorkspacePackages.js.map