(configFile?: string, workingDir?: string)
| 70 | configureFetch(options => insomniaFetch({ ...options })); |
| 71 | |
| 72 | export const tryToReadInsoConfigFile = async (configFile?: string, workingDir?: string) => { |
| 73 | try { |
| 74 | const explorer = await cosmiconfig('inso'); |
| 75 | // set or detect .insorc in workingDir or cwd https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#explorersearch |
| 76 | const results = configFile ? await explorer.load(configFile) : await explorer.search(workingDir || process.cwd()); |
| 77 | |
| 78 | if (results && !results?.isEmpty) { |
| 79 | logger.debug(`Found config file at ${results?.filepath}.`); |
| 80 | const scripts = results.config?.scripts || {}; |
| 81 | const filePath = results.filepath; |
| 82 | const options = ['workingDir', 'ci', 'verbose', 'printOptions'].reduce((acc, key) => { |
| 83 | const value = results.config?.options?.[key]; |
| 84 | if (value) { |
| 85 | return { ...acc, [key]: value }; |
| 86 | } |
| 87 | return acc; |
| 88 | }, {}); |
| 89 | |
| 90 | return { options, scripts, filePath }; |
| 91 | } |
| 92 | } catch (error) { |
| 93 | // Report fatal error when loading from explicitly defined config file |
| 94 | if (configFile) { |
| 95 | console.log(`Could not find config file at ${configFile}.`); |
| 96 | console.error(error); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return {}; |
| 101 | }; |
| 102 | |
| 103 | const localAppDir = getAppDataDir(getDefaultProductName()); |
| 104 |
no test coverage detected