-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for flow:main in package.json #6504
Add support for flow:main in package.json #6504
Conversation
This is so wonderful, thank you for going after it.
Agreed. |
Glad you agree @rgbkrk Note to reviewers: CI failure of |
@steelbrain thanks for doing this! It definitely addresses many issues. Would you consider |
@Gozala The issue you have stated is very valid. I would like to point out that resolutions such as the one you recommended have been tried before by other movements, most notably the It ended up being so complicated that there's only one package on npm that supports it and hasn't been updated in forever because of how complex it's become. Further I'd like to point out that this limitation is also shared by Typescript with their For the time being, I think this fix should make lives of people working with flow in monorepo and other setups easier while maintaining simplicity and obtaining parity with Typescript. You can work the stated issue around with the non-ideal |
Within our monorepo we used to have import paths like this then realized that it made our module name mappers excessively complex. In fact, we kept running into issues because of how |
The problem with sharing flow types directly in published library is that Flow is still So I would say that until Flow becomes stable, flow-typed should be the recommended way to share library packages |
@Hypnosphi We cannot publish the sources of our private mono-repo modules just to get support for flow typings among them. The "sharing" part is entirely optional, if someone is afraid their typings would break, they can of course choose not to publish them and still use |
I'm sure it's a valuable feature, I just doubt that it fixes #1996 |
I would disagree with you there, It does fix it. It does add a way, just like Typescript for packages to publish their types. Whether flow has matured enough itself to not break compat is a different question. I don't see why this particular option would have to be changed when flow hits 1.x. The types? Yes. The exposing interface? Shouldn't need changes. |
If it was true, there wouldn't be version ranges in definitions from Maybe
|
@Hypnosphi If you disagree with the fix that I've put up, please feel free to open a new PR that does it better and I'd be more than glad to close this one in favor of it :) There are currently npm modules that are published that already have types with Again I'd like to reiterate that nobody has to specify this new manifest while publishing to npm, it's like the typing sugar. You can keep things as they are in your npm module or you can specify if you want to. It's just like adding an |
Agree with @Hypnosphi. Different flow versions easily can break non-trivial type definitions from my experience. Ability to specify this in Also, @Gozala raises a good point: #6504 (comment), libraries like lodash follow this pattern, so will be useful to address them too. Even if it wasn't implemented in this PR, maybe the property value could be an object instead of string to support extending t in future? |
+1 on having multi-flow versions being done in a different PR, and having this one merged in as-is. @steelbrain is right in that this PR is consistent with the current behavior with including flow types in your module – you currently cannot specify any flow versioning for your published types. Also he makes a good point that using this property in your |
I'm also in agreement with @steelbrain and @saadq. This PR is immediately useful for those of us who make use of Versioning is def an issue, but it's one you'd still have if you take the |
@mrkev can u comment on this? how Facebook handle external packages with flow? |
@sibelius I think we just use library definitions. This looks like a good idea tbh, but I'm worried about versioning. I want to look at the discussion from the previous one. Unfortunately don't have much time to look deeply into this now, sorry. I'll keep it in my backlog. |
Would this work as a workaround for: #6134 ? |
Also to consolidate the tooling for |
Tooling like that is only fixing the symptoms and not the problem. Typescript just released v3 and they still have not renamed their manifest key ( This PR has been stalled for so long. I have started building/publishing my Flow forks to use in my projects, npm users can install I intend to publish future updates with this PR applied for OSX and Linux. Hopefully not for long :( |
due to limitations in flow (check facebook/flow#6504) this is required for now
This was the PR I held out for, in hopes this would help drive community adoption and interoperability. Our favorite libraries all have either been re-written in typescript or provide up to date definitions. The same can't be said for flow. I've loved flow too, so it saddens me quite a bit. Thanks for the good efforts @steelbrain. It was worth a shot. We're moving on to typescript since babel 7 makes the transition easy. nteract/nteract#3462 |
@samwgoldman can you check this? |
Love that this issue is finally being addressed! One question though - doesn't this mean that modules will need to publish both the whole flow-typed and non-flow-typed versions of the codebase? (meaning twice the size the module actually needs to be). imo the ideal solution would be just having an easy way to create/flow to recognize the libdef for that module - indeed that's how typescript enables this functionality. |
Will it really be analogous to the TS |
Any progress? |
Any news? |
@goodmind @Bannerets please hit "Subscribe" button in the right sidebar instead of giving false alarms to those who already did. |
I already subscribed before commenting. My comment was to attract attention to stale PR, and to get status of the PR (it was a question), not for subscribing. Flow team just fully ignores this small PR for a year. |
There's a problem with the PR though. e.g. |
I'm giving up on this because of lack of interest/support from maintainers. Moving to Typescript. Apologies to all the subscribed ones that this didn't work out :) |
This PR is a resurrection of #1459
Situation
Flow syntax is not natively supported by JS Engines so flow users use tools like
babel
to strip types from flow to ship it innpm
. This means that people that import those packages into their projects don't have typing support and have to in turn again useflow-typed
to add support for packages that were originally written in flow.There are of course workarounds for this, the most popular one being to mirror sources of files in the same folder as dist as
[file].js.flow
. It has it's own sets of quirks and limitations.As things are, it's nearly impossible to use Flowtype in a monorepo setup without having to rely on third party tooling.
Why current alternatives aren't enough
The flow community has had this problem for a while and as such demand has given birth to a supply of "fixes" for this including but not limited to
All of them are unreliable and easily break as they all use
.js.flow
way of working this issue aroundProposed solution
The path this PR tries to take is to add a new field to
package.json
calledflow:main
. When available, it'll be used instead ofmain
. It's resolution and handling is no different than that of amain
field.This change is non API breaking and no existing packages running flow would break with this. Furthermore those packages that already are using
lib/index.js.flow
or similar ways would also be unaffected by this. This change would only affect the packages that explicitly specify the new key.This PR enables package authors to allow package authors to specify
main
tolib/index.js
(example value) andflow:main
tosrc/index.js
(example value). This change when combined with un-ignoringsrc
directory in.npmignore
would give flow typings for modules out of the box.Furthermore, with this change, no special changes have to be done to make typings in mono repo modules work. They should work OOB.
Why flow:main
It's just a proposed solution. Typescript uses
types
/typings
. We could do something similar. I'm open to suggestion for names but I thinkflow:main
is simple, straight forward and gets the job done :)