"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 path = require("path");
const pFilter = require("p-filter");
const extendOptions_1 = require("./extendOptions");
const getContext_1 = require("./getContext");
const package_store_1 = require("package-store");
const dp = require("dependency-path");
const pnpm_logger_1 = require("pnpm-logger");
function default_1(maybeOpts) {
    return __awaiter(this, void 0, void 0, function* () {
        const reporter = maybeOpts && maybeOpts.reporter;
        if (reporter) {
            pnpm_logger_1.streamParser.on('data', reporter);
        }
        const opts = yield extendOptions_1.default(maybeOpts);
        const ctx = yield getContext_1.default(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 package_store_1.pkgIsUntouched(path.join(pkgPath, 'package'))); }));
        if (reporter) {
            pnpm_logger_1.streamParser.removeListener('data', reporter);
        }
        return modified;
    });
}
exports.default = default_1;
//# sourceMappingURL=storeStatus.js.map