flow-copy-source icon indicating copy to clipboard operation
flow-copy-source copied to clipboard

Unnecessary copies

Open rhoskal opened this issue 7 years ago • 3 comments

I came across this on my journey learning how to export my own npm module's flow types. While this module does save a lot of "hand jamming", it also copies EVERY *.{js,mjs,jsx} even if they don't have the Flow Type annotation comment (e.g. // @flow or /* @flow */) thus "bloating" the lib/ or dist/ folders. The most simplistic and elegant approach I came up with was to use a simple one-liner script in my package.json

  "scripts": {
    "build": "babel src/ -d lib/ && yarn copy-flow-source",
    "copy-flow-source": "for f in `grep --include=\\*.js -rlw src/ -e '^//\\s*@flow'`; do cp ${f} lib/${f#*/}.flow; done;",
    ...
  }

This would be a nice feature to add to your module, however I'm not sure kefir read contents of files like grep can. This way we follow the philosophy of keeping modules as lean as possible.

rhoskal avatar Aug 27 '18 19:08 rhoskal

Do you have many javascript files that don't use Flow? (Do you think it might be common to have many non-Flow .js files in projects using flow-copy-source?) This feature wouldn't be too hard to implement, but I'm not sure I want to add the performance or conceptual overhead for what might be a rare case.

Macil avatar Aug 28 '18 21:08 Macil

Probably not if you are starting a project from scratch. However, I could definitely see how this "enhancement" would be beneficial if you are transitioning legacy code--especially on a large code base. You definitely don't have to commit the work since both of we both have working solutions to solve each of our point of views. Just my 2 cents.

rhoskal avatar Aug 28 '18 21:08 rhoskal

@hansjhoffman you can try to use https://github.com/ilyalesik/gen-flow-files

ilyalesik avatar Jan 20 '19 18:01 ilyalesik