question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support tsconfig.json paths and baseUrl automatically

See original GitHub issue

It would be cool if the plugin could automatically detect tsconfig.json to see which first party imports you have, such as web/components/foo. Then those could be moved into the “absolute imports” group, instead of ending up in the (third party) “packages” group.

One idea is to use https://github.com/dividab/tsconfig-paths. Need to check that it actually supports baseUrl, though.

Another idea is to try to require("typescript"). If it’s there, use it to resolve the config.

The initial idea comes from: https://github.com/lydell/eslint-plugin-simple-import-sort/issues/18#issuecomment-532097832

Edit: This is a light-weight package that can do the hard work for us: https://github.com/privatenumber/get-tsconfig

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:15
  • Comments:25 (13 by maintainers)

github_iconTop GitHub Comments

14reactions
israelKusayevcommented, Jul 6, 2020

Yesss great idea, works perfect

const fs = require('fs');

const foldersUnderSrc = fs
  .readdirSync('src', { withFileTypes: true })
  .filter(dirent => dirent.isDirectory())
  .map(dirent => dirent.name);

and then

// Absolute imports and Relative imports.
[`^(${foldersUnderSrc.join('|')})(/.*|$)`, '^\\.'],

You can see here the config file https://github.com/reflexology/client-V2/blob/master/.eslintrc.js

3reactions
lydellcommented, Apr 2, 2020

Yes it does! By showing me how complex that would be, that would motivate adding the automatic tsconfig.json thing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
Default: The longest common path of all non-declaration input files. If composite is set, the default is instead the directory containing the tsconfig.json...
Read more >
Paths and baseUrl in tsconfig.json - Medhat Dawoud
The solution is very easy, just open your tsconfig.json in your application and add 2 more properties in case you did't find them...
Read more >
Angular 10 - baseUrl and paths aren't working - Stack Overflow
Essentially, I'd like to be able to do import { SomeService } from 'services/some.service' . However, no matter what I specify in my...
Read more >
Typescript: How to auto import with absolute paths if baseUrl ...
In my tsconfig.json I have set a base url: "baseUrl": "src/app", I want the IDE to auto import modules as...
Read more >
Typescript paths with ts-node, ts-node-dev and Jest | Medium
To achieve the non-relative import mentioned above, tsconfig.json could look like this: From the TypeScript docs: baseUrl: Specify the base directory to resolve ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found