Skip to content
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

[cli] Core definitions #4255

Merged
merged 24 commits into from Mar 17, 2022
Merged

[cli] Core definitions #4255

merged 24 commits into from Mar 17, 2022

Conversation

Brianzchen
Copy link
Member

@Brianzchen Brianzchen commented Feb 8, 2022

Implements #4250

Test Plan

  • runTests work to find the initially added core defs
  • when ft-config.json exists in libdefDir (commonly flow-typed) it will install array of env
  • installs into flow-typed/core dir with code signature
  • update command works
  • outdated command will output if it's outdated
  • install command will not update if core def has been modified
  • docs updated with core definitions
  • contributing docs updated with core defs
  • test outdated
  • test install

Sample usage

  1. Create aflow-typed.config.json inside project root

Screen Shot 2022-02-20 at 6 40 03 pm

2. Run `flow-typed install`

Installing fresh or with overwrite or updating
Screen Shot 2022-02-20 at 6 43 49 pm
If it already exists and modified
Screen Shot 2022-02-20 at 6 45 06 pm
If a env is referenced that does not exist or not compatible with flow version
Screen Shot 2022-02-20 at 6 46 23 pm
3. Run flow-typed outdated

If there has been an update in the registry
Screen Shot 2022-02-20 at 6 48 09 pm
If nothing compatible
Screen Shot 2022-02-20 at 6 49 29 pm

@Brianzchen Brianzchen added work in progress cli Related to CLI tool labels Feb 8, 2022
@Brianzchen
Copy link
Member Author

I'm thinking that a solution like this is necessary regardless to solve some of flow's problems with missing core definitions and my use case is centred around jsx usage in particular.

I wonder how a library that ships flow or a libdef could take advantage of core definitions. It would be very useful if a libdef of a component library was able to type it's Input component with all the props that are natively supported by html and it would make sense if we said that a library like material-ui must run on a jsx environment.

This seems duplicative of the base definitions solution though with the major difference being that it doesn't import changes and I feel like they could co-exist solving different problems but equally could be consolidated to keep one solution for solving multiple problems.

@Brianzchen
Copy link
Member Author

Ok after having a day to think this through here are my thoughts.

Imo an environment served as a core definition and base definition are two different things, one runs globally the other is imported, redux types shouldn't be exposed globally as they are interfaced through a library for example and core definitions are a means to add more types that should be available as part of the tool depending on the application usage.

To support the lib defs and flow shipped libraries respectively,

I believe the first can be supported with libdefs owning a package.json just like for base definitions. If a libdef needs a core def installing it shouldn't cause conflict and won't overwrite any other core def since they are only versioned by flow version, we can pull all installed libdef's core defs and flatten the array with env var in ft-config.

The second I believe automation is not necessary and a requirement on a libraries readme should be sufficient imo.

@Brianzchen
Copy link
Member Author

I might rename everything to env instead of core. It just doesn't make sense during usage

Copy link
Contributor

@AndrewSouthpaw AndrewSouthpaw left a comment

Choose a reason for hiding this comment

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

Really excited to see this land, thanks for your hard work @Brianzchen!

I don't dig much into the implementation, overall it looks good, and the tests seem reasonable. I mostly focused on the docs and overall implementation strategy.

definitions/core/es5-1/README.md Outdated Show resolved Hide resolved
@@ -0,0 +1,84 @@
declare type jsx$HTMLElementProps = {|
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you link to the source here?


### jsx

Flow is built by Meta and ships with react definitions it does not type or provide a list of available jsx properties. These can live as a core definition instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence reads a little unclearly, try tweaking?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be worth clarify what we are lacking that we get when adding jsx as an env. Most people use Flow with React and think everything is fine, so it might be unclear why it's valuable to add it.

@@ -0,0 +1,17 @@
# ft-config.json
Copy link
Contributor

Choose a reason for hiding this comment

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

How about .flow-typed-config.json? I'm not sure ft would be meaningful to most people. I don't feel strongly here, but it even took me a second to realize ft mean "flow-typed".

Copy link
Member Author

Choose a reason for hiding this comment

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

What if we moved it to the root and named it flow-typed.config.json? That seems like a pretty normal standard for jest, babel, etc

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds perfect.

@Brianzchen
Copy link
Member Author

@gantoine 🙏

@AndrewSouthpaw
Copy link
Contributor

AndrewSouthpaw commented Mar 17, 2022

This looks fine I'll go ahead and merge, everything is green.

Edit scratch that I was reading the mobile ui wrong seems like we're still waiting on a review

Copy link
Member

@gantoine gantoine left a comment

Choose a reason for hiding this comment

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

Sorry it took so long to review! I'm really happy with this approach. 👍🏼

Before we merge this in, I'd like to do another minor deploy (if we have any pending cli changes).

And once it's merged and deployed, nothing will change for users until we write the first core definition right? In which case we can plan and deprecate accordingly.

const ftConfig = getFtConfig(cwd);
const {env} = ftConfig ?? {};

if (Array.isArray(env)) {
Copy link
Member

Choose a reason for hiding this comment

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

If there is no flow-typed.config.json file, none of this runs right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, Array.isArray(env) evaluates to false. I only wrote it in this way with spread for when we extend config file in the future

@Brianzchen
Copy link
Member Author

And once it's merged and deployed, nothing will change for users until we write the first core definition right? In which case we can plan and deprecate accordingly.

Nothing will change for users until we ship a new version which is also non-breaking. No users will get this new feature unless they also implement a config in their project also.

In terms of deprecation it's just that with es5-1, that we should remove from npm after we publish the latest version.

This PR also includes the beginnings of the first real env def I plan to use extensively though I didn't want this PR that builds the CLI to have that reviewed so I added a minimal version just to prove it's functionality.


Feel free to merge @gantoine when you're ready but it looks like we haven't done any more work on CLI since last 3.7.0 release.

@gantoine gantoine merged commit e645615 into flow-typed:master Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to CLI tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants