I think relieing on a regexp to find imports in source code is not a good idea.
Using something like npm:acorn (with a plugin to parse typescript) and iterating over all the ImportDeclarations and ImportExpressions (both node types from estree spec) is a much better idea.
Though finding the module specifiers in the case of dynamic imports (the ImportExpressions) might be quite tricky.
Fully agree that this is not the ideal way. Was mainly a quick way to get a 90% solution. If you want to try a better method please feel free to do a PR and I can merge it!
I think relieing on a regexp to find imports in source code is not a good idea.
Using something like
npm:acorn
(with a plugin to parse typescript) and iterating over all the ImportDeclarations and ImportExpressions (both node types from estree spec) is a much better idea.Though finding the module specifiers in the case of dynamic imports (the ImportExpressions) might be quite tricky.
Fully agree that this is not the ideal way. Was mainly a quick way to get a 90% solution. If you want to try a better method please feel free to do a PR and I can merge it!