text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = resolveProjectRoot;
  
  var _path = _interopRequireDefault(require("path"));
  
  var _readManifest = _interopRequireDefault(require("./readManifest"));
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  /* eslint-disable no-sync */
  function resolveProjectRoot() {
    var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var options = Object.assign({
      basePath: process.cwd()
    }, opts);
    return options.sync ? resolveProjectRootSync(options) : resolveProjectRootAsync(options);
  }
  
  function resolveProjectRootAsync(options) {
    // @todo implement actual async version
    return Promise.resolve(resolveProjectRootSync(options));
  }
  
  function resolveProjectRootSync(options) {
    var manifestDir = options.basePath;
    var isProjectRoot = isRoot(manifestDir, options);
  
    while (!isProjectRoot && _path.default.dirname(manifestDir) !== manifestDir) {
      manifestDir = _path.default.dirname(manifestDir);
      isProjectRoot = isRoot(manifestDir, options);
    }
  
    return isProjectRoot ? manifestDir : false;
  }
  
  function isRoot(manifestDir, options) {
    try {
      var manifest = (0, _readManifest.default)(Object.assign({}, options, {
        manifestDir,
        sync: true
      }));
      return manifest.root || false;
    } catch (err) {
      if (err.code === 'ENOENT') {
        return false;
      } // On any error that is not "file not found", rethrow
  
  
      throw err;
    }
  }