({ getHomeDir = os.homedir } = {})
| 182 | } |
| 183 | |
| 184 | export async function discoverConfigFiles({ getHomeDir = os.homedir } = {}) { |
| 185 | const magicConfigName = 'web-ext-config'; |
| 186 | |
| 187 | // Config files will be loaded in this order. |
| 188 | const possibleConfigs = [ |
| 189 | // Look for a magic hidden config (preceded by dot) in home dir. |
| 190 | path.join(getHomeDir(), `.${magicConfigName}.mjs`), |
| 191 | path.join(getHomeDir(), `.${magicConfigName}.cjs`), |
| 192 | path.join(getHomeDir(), `.${magicConfigName}.js`), |
| 193 | // Look for webExt key inside package.json file |
| 194 | path.join(process.cwd(), 'package.json'), |
| 195 | // Look for a magic config in the current working directory. |
| 196 | path.join(process.cwd(), `${magicConfigName}.mjs`), |
| 197 | path.join(process.cwd(), `${magicConfigName}.cjs`), |
| 198 | path.join(process.cwd(), `${magicConfigName}.js`), |
| 199 | // Look for a magic hidden config (preceded by dot) the current working directory. |
| 200 | path.join(process.cwd(), `.${magicConfigName}.mjs`), |
| 201 | path.join(process.cwd(), `.${magicConfigName}.cjs`), |
| 202 | path.join(process.cwd(), `.${magicConfigName}.js`), |
| 203 | ]; |
| 204 | |
| 205 | const configs = await Promise.all( |
| 206 | possibleConfigs.map(async (fileName) => { |
| 207 | const resolvedFileName = path.resolve(fileName); |
| 208 | if (await fileExists(resolvedFileName)) { |
| 209 | return resolvedFileName; |
| 210 | } else { |
| 211 | log.debug( |
| 212 | `Discovered config "${resolvedFileName}" does not ` + |
| 213 | 'exist or is not readable', |
| 214 | ); |
| 215 | return undefined; |
| 216 | } |
| 217 | }), |
| 218 | ); |
| 219 | |
| 220 | const existingConfigs = []; |
| 221 | configs.forEach((f) => { |
| 222 | if (typeof f === 'string') { |
| 223 | existingConfigs.push(f); |
| 224 | } |
| 225 | }); |
| 226 | return existingConfigs; |
| 227 | } |
no test coverage detected
searching dependent graphs…