vscode-dependency-cruiser
vscode-dependency-cruiser copied to clipboard
Respect Babel/TS/Webpack/whatever base paths, aliases and externals
I've configured my tsconfig.json
with a baseUrl
set to ./app/javascript
. So I write import { foo } from 'utility'
and it imports from ./app/javascript/utility
. Dependency Cruiser, however, sees utility
as a top-level import and shows me a graph like this:

It would be really great to see Dependency Cruiser follow Babel/TS/Webpack/whatever's config for base paths and show imports like utility
coming from the right place. Here's a non-exhaustive list of details that would need to be addressed:
- The import logic is intelligent enough to distinguish between
utility
, which is in./app/javascript/utility
, andreact
, which is in./node_modules/react
. -
tsconfig.json
supportsbaseUrl
as well as specific path aliases usingpaths
(e.g.,@utility
-->./app/javascript/utility
). -
jsconfig.json
has options similar totsconfig.json
but for VS Code (doesn't depend on TS). -
Babel's popular
module-resolver
plugin hasroot
andalias
config options. -
Webpack has its own
resolve
options. - There are all kinds of plugins for Babel/TS/Webpack/whatever that allow for "syncing" path settings from one tool to the other (here's a popular example)
- Edge case: handling externals
- Parcel, Rollup, etc.
Perhaps the easiest way to handle the myriad cases is to simply create baseUrl
, paths
and externals
settings in the plugin's config and allow users to manually specify the base path, aliases and any external module declarations.
One last consideration: if you let users declare the base path, they will probably need to give an absolute path since VS Code could be launched from whatever pwd. Not sure whether there's a way around that.
This is also a problem with just importing ts files, as the file-extension is not included
hope to implement,This is a massive problem during i use this。
I'm having this issue too with basepaths and aliases, but this is still a great extension :+1: