Check if `tw` is used before importing
I have a babel preset I use across many packages. Some use twin and others don't.
Currently, when this plugin imports twin.macro even if you are in a file or package that doesn't use it.
A workaround is to conditionally include the plugin in overrides, but this becomes an unmaintainable mess.
I wonder if it could search the AST for uses of tw...or maybe this wouldn't be very performant.
Another idea would be to use read-pkg-up to find the package.json and check if twin.macro is declared. If so, then include it. This comes with its own fs performance issues.
Great idea - this plugin should really check before adding the imports. I'd opt for visiting the tw nodes to determine whether to add the imports or not.
Regarding performance: From what I've seen with similar checks - it shouldn't be a worry.