Macil / flow-copy-source

Script to copy javascript files and append ".flow" to the filename
MIT License
173 stars 13 forks source link

Unnecessary copies #16

Open rhoskal opened 6 years ago

rhoskal commented 6 years ago

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.

Macil commented 6 years ago

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.

rhoskal commented 6 years ago

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.

ilyalesik commented 5 years ago

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