{"version":3,"sources":["../source/merge/merge.ts","../source/read/read.ts"],"names":["mergeDeepObjects","createMergedConfig","dirtyConfigsList","cleanConfigsList","existsSync","join","RuntimeError","getRuntimeEnvironmentName","IN_BROWSER","packageDirectorySync","isCWD","path","getCurrentWorkingDirectory","runtimeName","cwd","joinPaths","paths","joined","getNearestPackageRootPath","packageDirectoryPath","getNearestConfigPath","fileName","packageRootPath","configPath"],"mappings":"AAAA,OAAS,oBAAAA,MAAwB,wCAI1B,SAASC,EACfC,EACkB,CAClB,IAAMC,EAAmBD,EAAiB,OAAO,OAAO,EAExD,OAAOF,EAAiBG,CAAgB,CACzC,CCVA,OAAS,cAAAC,MAAkB,KAC3B,OAAS,QAAAC,MAAY,OAErB,OAAS,gBAAAC,MAAoB,gDAC7B,OAAS,6BAAAC,EAA2B,cAAAC,MAAkB,+CACtD,OAAS,wBAAAC,MAA4B,UAQ9B,SAASC,EAAMC,EAA2B,CAChD,OAAOA,EAAK,WAAW,GAAG,CAC3B,CAGO,SAASC,GAAkC,CACjD,GAAIJ,EAAY,MAAM,IAAIF,EAAa,0DAA0D,EAEjG,IAAMO,EAAcN,EAA0B,EAE1CO,EAEJ,OAAQD,EAAa,CACpB,IAAK,MACL,IAAK,OAAQ,CACZC,EAAM,QAAQ,IAAI,EAClB,KACD,CACA,IAAK,OAAQ,CACZA,EAAM,KAAK,IAAI,EACf,KACD,CACA,QACC,MAAM,IAAIR,EACT,uFAAuFO,IACxF,CAEF,CAEA,GAAIH,EAAMI,CAAG,EACZ,OAAOA,EAEP,MAAM,IAAI,UACT,uBAAuBD,0DAAoEC,IAC5F,CAEF,CAGO,SAASC,EAAuCC,EAAwB,CAC9E,IAAMC,EAASZ,EAAK,GAAGW,CAAK,EAE5B,GAAIN,EAAMO,CAAM,EACf,OAAOA,EAEP,MAAM,IAAI,UAAU,8CAA8C,CAEpE,CAEO,SAASC,EAA0BJ,EAA4B,CACrE,GAAIN,EAAY,MAAM,IAAIF,EAAa,uDAAuD,EAE9F,IAAMa,EAAuBV,EAAqB,CAAE,IAAKK,GAAOF,EAA2B,CAAE,CAAC,EAE9F,GAAIO,GAAwBT,EAAMS,CAAoB,EACrD,OAAOA,EAEP,MAAM,IAAIb,EAAa,kEAAkEQ,IAAM,CAEjG,CAKO,SAASM,EACfC,EACAP,EACmB,CACnB,IAAMQ,EAAkBJ,EAA0BJ,CAAG,EAC/CS,EAAaR,EAAkB,CAACO,EAAsBD,CAAQ,CAAC,EAErE,GAAIjB,EAAWmB,CAAU,EACxB,OAAOA,EAEP,MAAM,IAAIjB,EAAa,0BAA0Be,UAAiB,CAEpE","sourcesContent":["import { mergeDeepObjects } from \"@terminal-nerds/snippets-object/merge\";\n\nexport type MergedConfig<T extends Record<string, unknown> = Record<string, unknown>> = T;\n\nexport function createMergedConfig<T extends Record<string, unknown> = Record<string, unknown>>(\n\tdirtyConfigsList: Array<unknown>,\n): MergedConfig<T> {\n\tconst cleanConfigsList = dirtyConfigsList.filter(Boolean) as Array<Record<string, object>>;\n\n\treturn mergeDeepObjects(cleanConfigsList) as MergedConfig<T>;\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nimport { RuntimeError } from \"@terminal-nerds/snippets-error/custom/runtime\";\nimport { getRuntimeEnvironmentName, IN_BROWSER } from \"@terminal-nerds/snippets-runtime/environment\";\nimport { packageDirectorySync } from \"pkg-dir\";\nimport type { Join } from \"type-fest\";\n\n// TODO: Move it to a separate package\nexport type AbsolutePath = `/${string}`;\nexport type CWD = AbsolutePath;\n\n// TODO: Move it to a separate package\nexport function isCWD(path: string): path is CWD {\n\treturn path.startsWith(\"/\");\n}\n\n// TODO: Move it to a separate package\nexport function getCurrentWorkingDirectory(): CWD {\n\tif (IN_BROWSER) throw new RuntimeError(`You cannot get current working directory in the browser.`);\n\n\tconst runtimeName = getRuntimeEnvironmentName();\n\n\tlet cwd;\n\n\tswitch (runtimeName) {\n\t\tcase \"bun\":\n\t\tcase \"node\": {\n\t\t\tcwd = process.cwd();\n\t\t\tbreak;\n\t\t}\n\t\tcase \"deno\": {\n\t\t\tcwd = Deno.cwd();\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new RuntimeError(\n\t\t\t\t`Cannot determine the current working directory in the current runtime environment - ${runtimeName}.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (isCWD(cwd)) {\n\t\treturn cwd;\n\t} else {\n\t\tthrow new TypeError(\n\t\t\t`The current runtime ${runtimeName} provived an invalid current working directory path - ${cwd}.`,\n\t\t);\n\t}\n}\n\n// TODO: Move it to a separate package\nexport function joinPaths<T extends readonly string[]>(paths: T): Join<T, \"/\"> {\n\tconst joined = join(...paths);\n\n\tif (isCWD(joined)) {\n\t\treturn joined as Join<T, \"/\">;\n\t} else {\n\t\tthrow new TypeError(`Joined path did not return an absolute path.`);\n\t}\n}\n\nexport function getNearestPackageRootPath(cwd?: string): AbsolutePath {\n\tif (IN_BROWSER) throw new RuntimeError(`You cannot get root path of a package in the browser.`);\n\n\tconst packageDirectoryPath = packageDirectorySync({ cwd: cwd ?? getCurrentWorkingDirectory() });\n\n\tif (packageDirectoryPath && isCWD(packageDirectoryPath)) {\n\t\treturn packageDirectoryPath;\n\t} else {\n\t\tthrow new RuntimeError(`Cannot determine the nearest root of the package for the file: ${cwd}!`);\n\t}\n}\n\nexport type ConfigFileName = string;\nexport type ConfigPath<A extends CWD, N extends ConfigFileName> = Join<[A, N], \"/\">;\n\nexport function getNearestConfigPath<N extends ConfigFileName, A extends AbsolutePath = AbsolutePath>(\n\tfileName: N,\n\tcwd?: A,\n): ConfigPath<A, N> {\n\tconst packageRootPath = getNearestPackageRootPath(cwd);\n\tconst configPath = joinPaths<[A, N]>([packageRootPath as A, fileName]);\n\n\tif (existsSync(configPath)) {\n\t\treturn configPath;\n\t} else {\n\t\tthrow new RuntimeError(`Cannot locate nearest \"${fileName}\" file!`);\n\t}\n}\n"]}