All files / util resolve-dir.js

88.24% Statements 15/17
75% Branches 9/12
100% Functions 1/1
88.24% Lines 15/17
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          1x     10x   10x 15x 15x 15x 15x 9x   9x 9x                 9x 9x 9x     6x   1x    
import debug from 'debug';
import fs from 'fs-promise';
import path from 'path';
import readPackageJSON from './read-package-json';
 
const d = debug('electron-forge:project-resolver');
 
export default async (dir) => {
  let mDir = dir;
  let prevDir;
  while (prevDir !== mDir) {
    prevDir = mDir;
    const testPath = path.resolve(mDir, 'package.json');
    d('searching for project in:', mDir);
    if (await fs.exists(testPath)) {
      const packageJSON = await readPackageJSON(mDir);
 
      Eif (packageJSON.devDependencies && packageJSON.devDependencies['electron-prebuilt-compile']) {
        Iif (!/[0-9]/.test(packageJSON.devDependencies['electron-prebuilt-compile'][0])) {
          // eslint-disable-next-line no-throw-literal
          throw 'You must depend on an EXACT version of "electron-prebuilt-compile" not a range';
        }
      } else {
        // eslint-disable-next-line no-throw-literal
        throw 'You must depend on "electron-prebuilt-compile" in your devDependencies';
      }
 
      Eif (packageJSON.config && packageJSON.config.forge) {
        d('electron-forge compatible package.json found in', testPath);
        return mDir;
      }
    }
    mDir = path.dirname(mDir);
  }
  return null;
};