"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBuildDeps = void 0;
const ramda_1 = require("ramda");
const upath_1 = require("upath");
const url_1 = require("url");
const urlJoin = require("url-join");
const fileProtocol = 'file:///';
function getBuildDeps(presentationPath, appCompilation) {
    const unixPresentationPath = upath_1.toUnix(presentationPath);
    const modules = appCompilation.modules.filter((module) => module.resource);
    const indirectDeps = modules
        .filter((module) => {
        const { pathname, searchParams } = new URL(urlJoin(fileProtocol, module.resource));
        return decodeURI(pathname).endsWith('.scss') || searchParams.get('lang') === 'scss';
    })
        .reduce((scssDeps, scssModule) => { var _a; return scssDeps.concat(Array.from(((_a = scssModule.buildInfo) === null || _a === void 0 ? void 0 : _a.fileDependencies) || [])); }, []);
    const directDeps = modules.map((module) => module.resource);
    const allDeps = ramda_1.uniq(directDeps.concat(indirectDeps)).reduce((deps, resource) => {
        const path = upath_1.toUnix(url_1.fileURLToPath(urlJoin(fileProtocol, resource)));
        return path.startsWith(unixPresentationPath)
            ? [...deps, upath_1.relative(unixPresentationPath, path)]
            : deps;
    }, []);
    return allDeps;
}
exports.getBuildDeps = getBuildDeps;
//# sourceMappingURL=getBuildDeps.js.map