#How can I change the order for the auto-import functionality?

4 messages · Page 1 of 1 (latest)

thorn estuary
#

I'm working on a script to auto import missing imports for all files in my typescript project.

Therefore, I use "ts-morph", which detects missing imports and calls internally the typescript compiler for these to fix the imports.
That way, I can for instance define custom typescript preferences, which are sent to the compiler.
For the imports, e.g. importModuleSpecifierPreference to use relative imports instead of absolute ones.

But is there any preference to change the order for the imports?
It's the same function like in vscode for auto import all missing.
But I want my exports in the src folder to be considered before external packages.

I already tried the "Include Package JSON Auto Imports" setting with "off", but that didn't have any effect.

thorn estuary
#

I worked around it by executing the script twice. In the first run, I removed all packages from the package.json, so that the script only considers my local files. And for the second run, I added them again, so still missing imports would be imported from the packages.

digital turtle
#

you could also run your linter over the code in the second pass

thorn estuary
#

Which eslint rule would you recommend? I tried that approach in first place, but the eslint-plugin-auto-import rule works only for some cases, where the file name matches the missing import. E.g. if I'd miss the type Word from the file Hello, it won't find it. Only if I'd miss the type Hello.
But yeah, for the second run to add only the packages, there is an option in that rule to add specific ones.