facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.09k stars 1.85k forks source link

Ability to copy all files and not only JS files when stripping types using `flow-remove-types` #9148

Open bacloud23 opened 1 month ago

bacloud23 commented 1 month ago

Proposal

I think it is useful to have all files copied by default when using flow-remove-types. I for instance use .proto files inside code, you can imagine other useful extensions that generally go hand in hand with JS (like JSON, HTML..)

Use case

My build step is like "build": "flow-remove-types src/ -d dist/",, source folder contains files other than .js so the ./dist is not self contained anymore.

SamChou19815 commented 1 month ago

Note that we probably won't do it ourselves, since we don't really recommend using it. The implementation of flow-remove-types is quite hacky, and you will be better off using babel directly. We do accept community contribution.

bacloud23 commented 1 month ago

I would like to work on this. Please assign @SamChou19815 🙏

bacloud23 commented 1 month ago

OK understood about recommendation. But won't babel approach use the same whatever algorithm to remove types ? I would like not to add babel at all, since I've never used it, and I don't need it.

Do you mean using flow-remove-types is not recommended at all ? For me it seems to build JS without types just fine. I've added a hacky way to preserve all files: "build": "rm -rf dist/ && cp -a src/ dist/ && flow-remove-types src/ -d dist/" first it copies all files and folders (including JS, not the best) then it ovewrites JS with the ones from flow-remove-types

SamChou19815 commented 1 month ago

But won't babel approach use the same whatever algorithm to remove types

No, babel will remove the types from the AST, and then print the result API back to code. That approach is much less fragile then the string manipulation approach based on ranges that's currently in flow-remove-types.

The only thing preventing us from deleting it from the repo is that we have not find an easy way to use the babel infra so that flow-remove-types powered flow-node, which can directly run flow code with the correct line number in stacktraces, still works.

The energy would be better spent on making the babel-based approach work by connecting it to the source map. That being said, we will still accept bug fixes and improvements to flow-remove-types before we work out the babel stuff.

bacloud23 commented 1 month ago

Hi @SamChou19815 Understood! And thank you for explanations.

I still can work on this like you said, but it might take time for me to put my hands on code..