/**
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import {resolve} from 'path';

const TOOL_ROOT = resolve(__dirname, "../");
const FLOW_ROOT = resolve(__dirname, "../../../");
export const defaultTestsDirName = "newtests";

// This is where we look for tests to run and where we put newly converted
// tests
export function getTestsDir(relative_to?: string): string {
  if (relative_to !== undefined) {
    return resolve(relative_to, defaultTestsDirName);
  } else {
    return resolve(FLOW_ROOT, defaultTestsDirName);
  }
}

export const binOptions: Array<string> = [
  resolve(FLOW_ROOT, "bin/flow"), // Open source build
  resolve(FLOW_ROOT, "bin/flow.exe"), // Open source windows build
  resolve(FLOW_ROOT, "../buck-out/gen/flow/flow/flow"), // Buck
];

export const defaultFlowConfigName = "_flowconfig";

@@ -196,86 +196,67 @@
 w%0A *
-/%0A%0Aimport %7Bresolve%7D from 'path';%0A%0Aconst TOOL_ROOT = resolve(__dirname, %22../%22);
+ @format%0A */%0A%0Aimport %7Bdirname, join, resolve%7D from 'path';%0A
 %0Acon
@@ -289,17 +289,17 @@
 irname, 
-%22
+'
 ../../..
@@ -299,17 +299,17 @@
 ./../../
-%22
+'
 );%0Aexpor
@@ -342,17 +342,17 @@
 e = 
-%22
+'
 newtests
 %22;%0A%0A
@@ -347,17 +347,17 @@
 newtests
-%22
+'
 ;%0A%0A// Th
@@ -606,35 +606,45 @@
  return 
-resolve(FLOW_ROOT, 
+dirname(require.resolve(join(
 defaultT
@@ -650,24 +650,42 @@
 TestsDirName
+, 'package.json'))
 );%0A  %7D%0A%7D%0A%0Aex
@@ -746,25 +746,25 @@
 W_ROOT, 
-%22
+'
 bin/flow
 %22), // O
@@ -751,25 +751,25 @@
 T, 'bin/flow
-%22
+'
 ), // Open s
@@ -801,17 +801,17 @@
 W_ROOT, 
-%22
+'
 bin/flow
@@ -814,17 +814,17 @@
 flow.exe
-%22
+'
 ), // Op
@@ -868,17 +868,17 @@
 W_ROOT, 
-%22
+'
 ../buck-
@@ -899,17 +899,17 @@
 low/flow
-%22
+'
 ), // Bu
@@ -952,17 +952,17 @@
 gName = 
-%22
+'
 _flowcon
@@ -968,7 +968,7 @@
 nfig
-%22
+'
 ;%0A

Allow workspaces outside of the workspace root