Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Support automatically checking for the node_modules version of Flow #53

Merged
merged 4 commits into from
Dec 6, 2016

Conversation

orta
Copy link
Contributor

@orta orta commented Nov 23, 2016

Addresses #41 by proxy too.

We have multiple apps that use different versions of Flow, which makes it tough to keep VS Code in a good state. We couldn't use an absolute path, or per-project settings (as they wouldn't work per user) and so I think this is a good fallback.

* their installs of flow.
*/
function fallbackNodeModuleFlowLocation(): string {
return global.vscode.workspace.rootPath + "/node_modules/.bin/flow"
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 node_modules/.bin/flow.cmd which is what you can use from the commandline, but I wonder if there is a .bin/flow or if the flow.cmd just references a binary inside of node_modules/flow

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

if (await canFindFlow(fallbackNodeModuleFlowLocation())){
return fallbackNodeModuleFlowLocation()
}
return config
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opted to return the config value here just in case ( and because the type is not optional )


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')
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@orta
Copy link
Contributor Author

orta commented Nov 28, 2016

poke?

@orta
Copy link
Contributor Author

orta commented Nov 30, 2016

Looks like this was discussed here: facebookarchive/nuclide#570

I can move this behind a flag?

@orta
Copy link
Contributor Author

orta commented Dec 2, 2016

Alright, I've added it behind a flag - and offered the same warning as Nuclides 👍

Copy link
Contributor

@gabelevi gabelevi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay! This generally looks good to me, but I have a few inline questions. Thanks for putting this together!

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')
Copy link
Contributor

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 if flow is in the path, then the useNPMPackagedFlow option is ignored?

Copy link
Contributor Author

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

@@ -342,7 +342,7 @@ export class FlowProcess {
...args,
'--from', 'nuclide',
];
const pathToFlow = getPathToFlow();
const pathToFlow = await getPathToFlow();
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

@orta orta Dec 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the difference is a fileExists check for which I don't expect to be a slow it's a which lookup, so it would be - however, I can instead opt to cache the values, I think it's pretty easy to get a callback from VS Code when your settings changes and so the stored path can be reset then - will take a look

* their installs of flow.
*/
function fallbackNodeModuleFlowLocation(): string {
return global.vscode.workspace.rootPath + "/node_modules/.bin/flow"
Copy link
Contributor

Choose a reason for hiding this comment

The 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 node_modules/.bin/flow.cmd which is what you can use from the commandline, but I wonder if there is a .bin/flow or if the flow.cmd just references a binary inside of node_modules/flow

@orta
Copy link
Contributor Author

orta commented Dec 4, 2016

Alright - I've got it caching the path for flow, so you'll only get the hit of checking for which flow the first time the extension loads, changing your user settings will trigger a cache clean, resetting all user state.

I've also fixed the windows support I think

@orta
Copy link
Contributor Author

orta commented Dec 4, 2016

And, well, I remembered to push to my fork too 💃

@@ -1,50 +1,56 @@
/* @flow */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, bah, git was complaining about line ends - didn't think it would do this

@orta
Copy link
Contributor Author

orta commented Dec 5, 2016

This is rebased etc, and should be 👍 for review

@gabelevi
Copy link
Contributor

gabelevi commented Dec 6, 2016

Sweet! This looks good to me! In the future we might need to be more aggressive with clearing the cache, but this looks good for now! Thanks for bearing with me!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants