flow-typed/flow-typed

Support Yarn Workspaces

k15a opened this issue ยท 14 comments

k15a commented

Yarn has a feature called workspaces which is quite good for monorepos.

The problem is that they are not working good with flow and flow-typed. There are two options to use flow in a monorepo:

Use a single flow in the root

The problem is that flow will only use the flow-typed folder in the root so all typings installed in the individual package folders are ignored.

Flow-typed could install all typings into the root and check for the workspaces key in the package.json for individual packages. (This will probably be an issue when package A depends on a different version of an npm package than package B)

Use one flow per package

The problem here is that yarn will hoist some packages into the root of the project and flow can't find them there. This is a problem with flow because it seems that they use a different module resolution algorithm then node does. facebook/flow#5107

@k15a FYI there is a CLI called flow-mono-cli which solves most of the issues when working with flow in a mono-repo. Check it out, if you have any additional feature requests or feedback I am more than happy to hear from you! :)

k15a commented

@Inkdpixels I've already seen that and tried it at work. Unfortunately, it's only working with node 8 and if you use yarn will not even install because of some dependency.

@k15a That is unfortunate! We do require Node 8 of course since it is the current LTS and advise anyone to upgrade as soon as possible, but the dependency error sounds a bit weird, can you elaborate what exactly is causing an error there so I can reproduce it / fix it? That would be super cool! Thanks in advance :)

@Inkdpixels and what suggestion do you have when using a single flow at the root? That's the approach I took, but flow-typed now doesn't know how to install the definitions :/

@AugustinLF We embrace having flow setup for each package, while it sounds like overhead in the first place we found that flow just works better, faster and leads to less headaches if you extract packages from your mono-repo in the future.

The CLI we built guides you on how to properly set up a mono-repo without much hassle and support's you as much as possible, if you have any feedback we are more than open for suggestions!

FYI we also support root flow-typed definitions, but, as stated before, we need flow-typed and flow in each package. :-)

Is any action to be taken regarding this?

I haven't seen anything in the past couple months to my recollection.

+1

flow-mono-cli is a good option, but an official support would be better !

Here is small article I wrote on the topic : https://medium.com/inato/how-to-use-flow-in-a-mono-repo-8947d43d50fb ๐Ÿ˜‰

any progress here?

@11111000000 this stackoverflow answer might be helpful: https://stackoverflow.com/a/57017179/2150422

To fix it need update .flowconfig:

[include]
../../node_modules/

FS struct:

/project_root
--/node_modules
--/packages
----/module1
------.flowconfig>

Thanks for sharing @jeremyblalock ! If anyone is feeling motivated, I'm sure an addition to the README for this repo would be welcome to explain how to add support for yarn workspaces.

This seems solved from #4140.

@AndrewSouthpaw or anyone else, do you see any reason to keep this issue open? Are there anymore challenges that should be solved by flow-typed? I believe if you choose to run a different .flowconfig in each package in a monorepo that has no extra functionality need from flow-typed

Seems reasonable to me! I think a note in the README would still be a valid addition, but I think this is fine to close. Thanks @Brianzchen!