{"version":3,"sources":["../src/fs/findUp.ts"],"names":["findUp","files","options","includeSelf","entry","assignObject","result","forEachUp","folder","file","filePath","path","fs","ABORT"],"mappings":";;;;AA2BO,SAASA,CAAAA,CAAOC,CAA0BC,CAAAA,CAAAA,CAAyB,CACtE,GAAM,CAAE,WAAAC,CAAAA,CAAAA,CAAc,KAAM,KAAAC,CAAAA,CAAAA,CAAQ,OAAQ,CAAA,GAAA,EAAM,CAAA,CAAIC,CAAa,CAAA,GAAIH,CAAO,CAAA,CACxEI,CAAmB,CAAA,GACzB,OAAI,OAAOL,CAAU,EAAA,QAAA,GACjBA,EAAQ,CAACA,CAAK,CAElBM,CAAAA,CAAAA,GAAAA,CACKC,CAAmB,EAAA,CAChB,IAASC,IAAAA,CAAAA,IAAQR,EAAO,CACpB,IAAMS,CAAWC,CAAAA,CAAAA,CAAK,KAAKH,CAAQC,CAAAA,CAAI,CACvC,CAAA,GAAIG,IAAG,UAAWF,CAAAA,CAAQ,CACtBJ,GAAAA,CAAAA,CAAO,KAAKI,CAAQ,CAAA,CAChBR,CAAS,EAAA,SAAA,CAAA,CAAW,OAAOW,GAEvC,CACJ,CACA,CAAA,CAAE,YAAAV,CAAa,CAAA,IAAA,CAAMC,CAAM,CAC/B,EACOE,CACX","file":"chunk-YR7QKWWY.mjs","sourcesContent":["/**\n * 向上查找指定的文件，并返回文件全路径\n *\n * findUpFiles(\"flex.config.json\")\n * findUpFiles([\n *    \"flex.config.json\",\n *    \"flex.config.yaml\",\n *    \"flex.config.ts\"\n * ])\n *\n * 如果没有发现，则返回[]\n *\n *\n */\n\nimport { forEachUp } from './forEachUp'\nimport path from 'node:path'\nimport fs from 'node:fs'\nimport { assignObject } from '../object/assignObject'\nimport { ABORT } from '../consts'\n\nexport interface FindUpOptions {\n    includeSelf?: boolean // 结果是否包含当前文件夹\n    entry?: string // 查找起点,默认为当前文件夹\n    onlyFirst?: boolean // 是否只查找第一个文件\n}\n\nexport function findUp(files: string | string[], options?: FindUpOptions) {\n    const { includeSelf = true, entry = process.cwd() } = assignObject({}, options)\n    const result: string[] = []\n    if (typeof files === 'string') {\n        files = [files]\n    }\n    forEachUp(\n        (folder: string) => {\n            for (let file of files) {\n                const filePath = path.join(folder, file)\n                if (fs.existsSync(filePath)) {\n                    result.push(filePath)\n                    if (options?.onlyFirst) return ABORT\n                }\n            }\n        },\n        { includeSelf, base: entry },\n    )\n    return result\n}\n"]}