All files / src utils.ts

100% Statements 6/6
66.66% Branches 2/3
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45        41x                                                             41x 615x 615x 35x       6x    
import path from 'path';
import fs from 'fs';
 
export function findConfigFile(moduleName: string, root: string, searchPlaces: string[] = []) {
  const data = [
    ...searchPlaces,
    `.${moduleName}rc`,
    `.${moduleName}rc.json`,
    `.${moduleName}rc.json5`,
    `.${moduleName}rc.jsonc`,
    `.${moduleName}rc.yaml`,
    `.${moduleName}rc.yml`,
    `.${moduleName}rc.toml`,
    `.${moduleName}rc.ini`,
    `.${moduleName}rc.js`,
    `.${moduleName}rc.ts`,
    `.${moduleName}rc.cjs`,
    `.${moduleName}rc.mjs`,
    `.config/${moduleName}rc`,
    `.config/${moduleName}rc.json`,
    `.config/${moduleName}rc.json5`,
    `.config/${moduleName}rc.jsonc`,
    `.config/${moduleName}rc.yaml`,
    `.config/${moduleName}rc.yml`,
    `.config/${moduleName}rc.toml`,
    `.config/${moduleName}rc.ini`,
    `.config/${moduleName}rc.js`,
    `.config/${moduleName}rc.ts`,
    `.config/${moduleName}rc.cjs`,
    `.config/${moduleName}rc.mjs`,
    `${moduleName}.config.js`,
    `${moduleName}.config.ts`,
    `${moduleName}.config.cjs`,
    `${moduleName}.config.mjs`,
  ];
  for (const file of data) {
    const filePath = path.resolve(root, file);
    if (fs.existsSync(filePath)) {
      return filePath;
    }
  }
 
  return null;
}