/*!
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
var __asyncValues = (this && this.__asyncValues) || function (o) {
    if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
    var m = o[Symbol.asyncIterator], i;
    return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
    function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
    function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
import { strict as assert } from "assert";
import path from "path";
import fs from "fs-extra";
describe("Check Dependencies", () => {
    it("verify no @fluid-internal packages in dependencies", async () => {
        await verifyNoFluidPackages(path.join(__dirname, "/../../node_modules"));
    });
});
// Store visited packages so we don't iterate them multiple times
const visitedPkgDirs = [];
const verifyNoFluidPackages = async (dir) => {
    var e_1, _a;
    const entries = await fs.promises.opendir(dir);
    const searches = [];
    try {
        for (var entries_1 = __asyncValues(entries), entries_1_1; entries_1_1 = await entries_1.next(), !entries_1_1.done;) {
            const entry = entries_1_1.value;
            // If there is a package.json we will look through it to extract information.
            if (entry.isFile() && entry.name === "package.json") {
                const fullPath = `${dir}/${entry.name}`;
                console.log(fullPath);
                const json = await fs.readJson(fullPath);
                if (json && json.dependencies) {
                    const dependencyKeys = Object.keys(json.dependencies);
                    if (dependencyKeys && dependencyKeys.includes("@fluid-internal")) {
                        assert.fail(fullPath);
                    }
                }
            }
            else if (entry.isDirectory() && !visitedPkgDirs.includes(entry.name)) {
                visitedPkgDirs.push(entry.name);
                searches.push(verifyNoFluidPackages(`${dir}/${entry.name}`));
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (entries_1_1 && !entries_1_1.done && (_a = entries_1.return)) await _a.call(entries_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    await Promise.all(searches);
};
//# sourceMappingURL=dependencies.spec.js.map