@@ -18,6 +18,7 @@ import {checkOutput} from '../../commons-node/process';
1818import fsPromise from '../../commons-node/fsPromise' ;
1919import LRU from 'lru-cache' ;
2020import invariant from 'assert' ;
21+ import path from 'path' ;
2122
2223import { getLogger } from '../../nuclide-logging/lib/main' ;
2324const logger = getLogger ( ) ;
@@ -166,13 +167,17 @@ async function getPathToFlow(): Promise<string> {
166167 const config = global . vscode . workspace . getConfiguration ( 'flow' ) ;
167168 const shouldUseNodeModule = config . get ( 'useNPMPackagedFlow' ) ;
168169 const userPath = config . get ( 'pathToFlow' ) ;
170+ const nodeModuleFlowPath = nodeModuleFlowLocation ( global . vscode . workspace . rootPath )
169171
170- if ( shouldUseNodeModule && await canFindFlow ( nodeModuleFlowLocation ( ) ) ) {
171- global . cachedPathToFlowBin = nodeModuleFlowLocation ( ) ;
172+ if ( shouldUseNodeModule && await canFindFlow ( nodeModuleFlowPath ) ) {
173+ global . cachedPathToFlowBin = nodeModuleFlowPath ;
172174 } else if ( await canFindFlow ( userPath ) ) {
173175 global . cachedPathToFlowBin = userPath ;
176+ } else if ( await canFindFlow ( 'flow' ) ) {
177+ global . cachedPathToFlowBin = 'flow' ;
174178 } else {
175- global . cachedPathToFlowBin = "flow" ;
179+ const extensionRoot = path . resolve ( __dirname , '../../../../' ) ;
180+ global . cachedPathToFlowBin = nodeModuleFlowLocation ( extensionRoot )
176181 }
177182
178183 logger . info ( "Path to Flow: " + global . cachedPathToFlowBin ) ;
@@ -185,11 +190,11 @@ async function getPathToFlow(): Promise<string> {
185190 * @return The potential path to Flow on the user's machine if they are using NPM/Yarn to manage
186191 * their installs of flow.
187192 */
188- function nodeModuleFlowLocation ( ) : string {
193+ function nodeModuleFlowLocation ( rootPath : string ) : string {
189194 if ( process . platform === 'win32' ) {
190- return `${global . vscode . workspace . rootPath } \\node_modules \\. bin \\flow . cmd `
195+ return `${rootPath } \\node_modules \\. bin \\flow . cmd `
191196 } else {
192- return `${global . vscode . workspace . rootPath } / node_modules / . bin / flow `
197+ return ` $ { rootPath } / node_modules / . bin / flow `
193198 }
194199}
195200
0 commit comments