import l from"node:path";import{createConfig as c,loadIgnoreConfig as m}from"@redocly/openapi-core";import{ExternalResolver as u}from"../../../fs/utils/external-ref-resolver.js";import{CONFIG_FILE_NAME as C}from"../../../../constants/common.js";import{getScorecardConfig as p}from"../get-scorecard-config.js";async function _(i,e){const r=await e.getConfig(),s=p(r),n=s.levels??[],o=l.join(e.fs.cwd,C),t=new u(e.fs),a=await m(o,t),f=await v(n,r.plugins,o,a),g=await d(s.targets,n,r.plugins,o,a);return{levelsConfig:n,configs:f,targets:g}}async function v(i,e=[],r,s){const n={};for(const o of i)n[o.name]=await c({...o,plugins:e},{configPath:r,ignore:s});return n}async function w(i,e,r=[],s,n){const o={};for(const t of i){const a=await c({...t,apis:{[t.name]:{root:"scorecard-target",rules:e}},plugins:r},{configPath:s,ignore:n});o[t.name]=a.forAlias(t.name)}return o}async function d(i,e,r=[],s,n){return i?Promise.all(i?.filter(o=>!!o.rules).map(async o=>({...o,configs:await w(e,o.rules,r,s,n)}))||[]):[]}export{_ as scorecardConfigLoader};
