(opts: {
cwd: string;
configPath?: string;
})
| 11 | ]; |
| 12 | |
| 13 | export const getConfig = async (opts: { |
| 14 | cwd: string; |
| 15 | configPath?: string; |
| 16 | }): Promise<ExecutorCliConfig | null> => { |
| 17 | const { cwd, configPath } = opts; |
| 18 | |
| 19 | let resolvedPath: string | undefined; |
| 20 | |
| 21 | if (configPath) { |
| 22 | resolvedPath = path.resolve(cwd, configPath); |
| 23 | if (!existsSync(resolvedPath)) { |
| 24 | console.error(`Config file not found: ${resolvedPath}`); |
| 25 | return null; |
| 26 | } |
| 27 | } else { |
| 28 | for (const p of defaultPaths) { |
| 29 | const candidate = path.resolve(cwd, p); |
| 30 | if (existsSync(candidate)) { |
| 31 | resolvedPath = candidate; |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if (!resolvedPath) return null; |
| 38 | |
| 39 | const jiti = createJiti(cwd, { |
| 40 | interopDefault: true, |
| 41 | moduleCache: false, |
| 42 | }); |
| 43 | |
| 44 | const mod = await jiti.import(resolvedPath); |
| 45 | const config = (mod as { default?: ExecutorCliConfig }).default ?? mod; |
| 46 | return config as ExecutorCliConfig; |
| 47 | }; |
no test coverage detected