import*as f from"path";import{bold as i}from"colorette";import{existsSync as m}from"node:fs";import{USER_THEME_ALIAS as u}from"../../constants/common.js";import{reporter as a}from"../../server/tools/notifiers/reporter.js";import{resolveExternalPlugins as l}from"../../server/external-plugins/resolve-external-plugins.js";const d=[".tsx",".ts",".mjsx",".mjs",".jsx",".js"];async function T(t,s,e,n){const o=(await l(t,s)).find(r=>e?r.name===e:h(r,n));if(!o){const r=e?`The requested theme ${i(e)} does not exist`:n?`The requested component ${i(n)} does not exist in any theme`:void 0;r&&await a.panicOnBuildContentError(r)}return o}function h(t,s){if(t.name===u||!s)return!1;for(const e of d)if(m(f.join(t.pluginDirAbsolutePath,s+e)))return!0;return!1}export{T as resolveTheme};
