All files resolve-dir.js

5.88% Statements 1/17
0% Branches 0/12
0% Functions 0/1
5.88% Lines 1/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                                                              
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);
 
      if (packageJSON.devDependencies && packageJSON.devDependencies['electron-prebuilt-compile']) {
        if (!/[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';
      }
 
      if (packageJSON.config && packageJSON.config.forge) {
        d('electron-forge compatible package.json found in', testPath);
        return mDir;
      }
    }
    mDir = path.dirname(mDir);
  }
  return null;
};