"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 check_package_1 = require("@pnpm/check-package");
const logger_1 = require("@pnpm/logger");
const dp = require("dependency-path");
const pFilter = require("p-filter");
const path = require("path");
const getContext_1 = require("../getContext");
const extendStoreStatusOptions_1 = require("./extendStoreStatusOptions");
function default_1(maybeOpts) {
    return __awaiter(this, void 0, void 0, function* () {
        const reporter = maybeOpts && maybeOpts.reporter;
        if (reporter) {
            logger_1.streamParser.on('data', reporter);
        }
        const opts = yield extendStoreStatusOptions_1.default(maybeOpts);
        const ctx = yield getContext_1.getContextForSingleImporter(opts);
        if (!ctx.wantedShrinkwrap)
            return [];
        const pkgPaths = Object.keys(ctx.wantedShrinkwrap.packages || {})
            .map((id) => {
            if (id === '/')
                return null;
            return dp.resolve(ctx.wantedShrinkwrap.registry, id);
        })
            .filter((pkgId) => pkgId && !ctx.skipped.has(pkgId))
            .map((pkgPath) => path.join(ctx.storePath, pkgPath));
        const modified = yield pFilter(pkgPaths, (pkgPath) => __awaiter(this, void 0, void 0, function* () { return !(yield check_package_1.default(path.join(pkgPath, 'package'))); }));
        if (reporter) {
            logger_1.streamParser.removeListener('data', reporter);
        }
        return modified;
    });
}
exports.default = default_1;
//# sourceMappingURL=index.js.map