import-js
import-js copied to clipboard
Auto import via NodeJS
Is it possible to use this module to auto import all undefined variables in a project?
I would like to add a feature to do something like a fix(path) passing the root path of my project in a CLI tool i am creating.
This feature would be very useful to my project migration situation, where we used TS modules, and want to migrate it all to the import {} from syntax.
Yes, you can run importjs from the command line to do this like so:
importjs fix --overwrite src/**/*.js
Or you can import it in a node script, though you might need to copy some boilerplate from the CLI: https://github.com/Galooshi/import-js/blob/dc8a158d15df50b2f15be3461f73706958df986d/lib/importjs.js#L59-L84
However, it's not perfect at finding the right import (especially when there are several with the same name, or your project contains build artifacts), and normally needs a level of human checking or intervention
I was not able to use the wildcard (**) as you said, can you help me? @coagmano
It doesn't seem to be supported.
The globstar (**) will only work on a bash-like shell, so if you're building it into a CLI, you'll need to shell out, or use a globbing package for file discovery. (Also, you can't easily shell out on Windows, so a package might be better regardless)
What approach are you using currently?
Closing this as stale. If you need more guidance please feel free to reopen it. Thanks.