-
Notifications
You must be signed in to change notification settings - Fork 112
Support automatically checking for the node_modules version of Flow #53
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ function isOptional(param: string): boolean { | |
} | ||
|
||
async function isFlowInstalled(): Promise<boolean> { | ||
const flowPath = getPathToFlow(); | ||
const flowPath = await getPathToFlow(); | ||
if (!flowPathCache.has(flowPath)) { | ||
flowPathCache.set(flowPath, await canFindFlow(flowPath)); | ||
} | ||
|
@@ -144,12 +144,32 @@ async function canFindFlow(flowPath: string): Promise<boolean> { | |
} | ||
|
||
/** | ||
* @return The path to Flow on the user's machine. It is recommended not to cache the result of this | ||
* function in case the user updates his or her preferences in Atom, in which case the return | ||
* value will be stale. | ||
* @return The path to Flow on the user's machine. First using the the user's config, then looking into | ||
* the node_modules for the project. | ||
* It is recommended not to cache the result of this function in case the user updates his or her | ||
* preferences in Atom, in which case the return value will be stale. | ||
*/ | ||
function getPathToFlow(): string { | ||
return global.vscode.workspace.getConfiguration('flow').get('pathToFlow') | ||
async function getPathToFlow(): Promise<string> { | ||
const config = global.vscode.workspace.getConfiguration('flow') | ||
const userPath = config.get('pathToFlow') | ||
|
||
if (await canFindFlow(userPath)) { | ||
return userPath | ||
} | ||
|
||
const shouldUseNodeModule = config.get('useNPMPackagedFlow') | ||
if (shouldUseNodeModule && await canFindFlow(fallbackNodeModuleFlowLocation())){ | ||
return fallbackNodeModuleFlowLocation() | ||
} | ||
return userPath | ||
} | ||
|
||
/** | ||
* @return The potential path to Flow on the user's machine if they are using NPM/Yarn to manage | ||
* their installs of flow. | ||
*/ | ||
function fallbackNodeModuleFlowLocation(): string { | ||
return global.vscode.workspace.rootPath + "/node_modules/.bin/flow" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially thought that for windows support I would need to use path.join but Stack Overflow says it's not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested this on Windows? I think this would work, but not near a Windows computer so can't double check. I vaguely remember that there's a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah - this came up with my Jest work - I will need to do this |
||
} | ||
|
||
function getStopFlowOnExit(): boolean { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ export class FlowProcess { | |
|
||
/** Starts a Flow server in the current root */ | ||
async _startFlowServer(): Promise<void> { | ||
const pathToFlow = getPathToFlow(); | ||
const pathToFlow = await getPathToFlow(); | ||
// `flow server` will start a server in the foreground. asyncExecute | ||
// will not resolve the promise until the process exits, which in this | ||
// case is never. We need to use spawn directly to get access to the | ||
|
@@ -342,7 +342,7 @@ export class FlowProcess { | |
...args, | ||
'--from', 'nuclide', | ||
]; | ||
const pathToFlow = getPathToFlow(); | ||
const pathToFlow = await getPathToFlow(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How much slower do you think this call is? I mainly worry about things like autocomplete, where adding 100ms can really degrade performance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const ret = await asyncExecute(pathToFlow, args, options); | ||
if (ret.exitCode !== 0) { | ||
// TODO: bubble up the exit code via return value instead | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,11 @@ | |
|
||
import spawn from 'cross-spawn'; | ||
import {window, workspace} from 'vscode' | ||
import {getPathToFlow} from "../pkg/flow-base/lib/FlowHelpers" | ||
|
||
const NODE_NOT_FOUND = '[Flow] Cannot find node in PATH. The simpliest way to resolve it is install node globally' | ||
const FLOW_NOT_FOUND = '[Flow] Cannot find flow in PATH. Try to install it by npm install flow-bin -g' | ||
|
||
function getPathToFlow(): string { | ||
return workspace.getConfiguration('flow').get('pathToFlow') | ||
} | ||
|
||
export function isFlowEnabled() { | ||
return workspace.getConfiguration('flow').get('enabled') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this would have different behaviour now, I made them share the code instead |
||
} | ||
|
@@ -36,9 +33,10 @@ export function checkNode() { | |
} | ||
} | ||
|
||
export function checkFlow() { | ||
export async function checkFlow() { | ||
const path = await getPathToFlow() | ||
try { | ||
const check = spawn(process.platform === 'win32' ? 'where' : 'which', [getPathToFlow()]) | ||
const check = spawn(process.platform === 'win32' ? 'where' : 'which', [path]) | ||
let | ||
flowOutput = "", | ||
flowOutputError = "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this default to
flow
if not explicitly set? Does this mean that ifflow
is in the path, then theuseNPMPackagedFlow
option is ignored?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it does, maybe the logic should be switched around realistically