function buildRegExps(basePath, dirPaths) {
  return dirPaths.map(
    folderPath =>
      // Babel `only` option works with forward slashes in the RegExp so replace
      // backslashes for Windows.
      folderPath instanceof RegExp
        ? new RegExp(
            `^${escapeRegExp(
              path.resolve(basePath, '.').replace(/\\/g, '/')
            )}/${folderPath.source}`,
            folderPath.flags
          )
        : new RegExp(
            `^${escapeRegExp(
              path.resolve(basePath, folderPath).replace(/\\/g, '/')
            )}`
          )
  );
}
We use absolute paths for matching only the top-level folders reliably. For
example, we would not want to match some deeply nested forder that happens to
have the same name as one of `BABEL_ENABLED_PATHS`.