{"version":3,"file":"resolveConfigFilepath.mjs","names":[],"sources":["../../../src/config-dir/utils/resolveConfigFilepath.ts"],"sourcesContent":["import path from 'path';\nimport fs from 'fs';\n\n/**\n * Resolves a configuration filepath for dictionary files.\n *\n * @param {string} fileName - The base name of the config file to look for.\n * @param {string} [cwd] - An optional current working directory path.\n * @returns {string|undefined} - The path if found; otherwise undefined.\n */\nexport function resolveConfigFilepath(\n  fileName: string,\n  extensions: string[] = ['.ts', '.js'],\n  cwd?: string,\n  prefixes: string[] = ['.', './src']\n): string | undefined {\n  function resolvePath(pathname: string) {\n    const parts = [];\n    if (cwd) parts.push(cwd);\n    parts.push(pathname);\n    return path.resolve(...parts);\n  }\n\n  function pathExists(pathname: string) {\n    return fs.existsSync(resolvePath(pathname));\n  }\n\n  // Check for file existence in the root and src directories with supported extensions\n  for (const candidate of prefixes.flatMap(\n    (prefix) => extensions.map((ext) => `${prefix}/${fileName}${ext}`) // TOOD: is the / necessary after dot?\n  )) {\n    if (pathExists(candidate)) {\n      return candidate;\n    }\n  }\n\n  // Return undefined if no file is found\n  return undefined;\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,sBACd,UACA,aAAuB,CAAC,OAAO,MAAM,EACrC,KACA,WAAqB,CAAC,KAAK,QAAQ,EACf;CACpB,SAAS,YAAY,UAAkB;EACrC,MAAM,QAAQ,EAAE;AAChB,MAAI,IAAK,OAAM,KAAK,IAAI;AACxB,QAAM,KAAK,SAAS;AACpB,SAAO,KAAK,QAAQ,GAAG,MAAM;;CAG/B,SAAS,WAAW,UAAkB;AACpC,SAAO,GAAG,WAAW,YAAY,SAAS,CAAC;;AAI7C,MAAK,MAAM,aAAa,SAAS,SAC9B,WAAW,WAAW,KAAK,QAAQ,GAAG,OAAO,GAAG,WAAW,MAAM,CACnE,CACC,KAAI,WAAW,UAAU,CACvB,QAAO"}