import-sort
import-sort copied to clipboard
import-sort-parser-babylon fails to load babel config in vscode
I have a project with both typescript and js in it, and I've set up import-sorter to use the babylon parser for both of them, with babel configured in such a way that this just works. The import-sort-cli works just fine, but doing sort imports from VS code fails with syntax errors in my file. To figure out why, I debugged into the VS code extension, and found that babel settings get's loaded for the wrong directory. Instead of loading babel settings for my project, it tries to find babel settings based on the executable path of vs code itself.
As far as I can tell, the issue stems from this line: https://github.com/renke/import-sort/blob/master/packages/import-sort-parser-babylon/src/index.ts#L78. Instead of just passing in the file name, the directory also needs to be provided to babel, else it defaults to CWD. I would suggest either passing in path.dirname(options.file), or allowing passing in options.dir or options.cwd, then having the downstream extensions ensure the correct values are passed in (like workspace, or similar), though using the dirname of the file is likely going to be the most correct option.
Since I originally proposed this, i've more than realized that yeah babel may need a ton of additional config to properly find the config file. I think what we need to do is allow passing through parser implementation specific options from the cli or node api e.g. an entire babel config. This is waht react-docgen now allows as well as other tools that consumer babel like gatsby. I'd be happy to work on it.