Skip to content

Commit 7f6f4b5

Browse files
authored
Merge pull request #41 from vitonsky/38-paths-from-jsconfig-are-not-includes
feat: use jsconfig if no tsconfig found
2 parents d5a3078 + cae7469 commit 7f6f4b5

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"ignoreRequire": true,
3737
"lang": "en_US",
3838
"skipWords": [
39-
"tsconfig"
39+
"tsconfig",
40+
"jsconfig"
4041
],
4142
// Check if word contains numbers
4243
"skipIfMatch": [

jsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": {
5+
"@foo/*": ["src/foo/*"],
6+
"@bar/*": ["src/bar/*"]
7+
}
8+
}
9+
}

src/rules/alias.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ function findAlias(
2424
filePath: string,
2525
ignoredPaths: string[] = [],
2626
) {
27-
if (fs.existsSync(path.join(baseDir, 'tsconfig.json'))) {
27+
const isTsconfigExists = fs.existsSync(path.join(baseDir, 'tsconfig.json'));
28+
const isJsconfigExists = fs.existsSync(path.join(baseDir, 'jsconfig.json'));
29+
30+
const configFile = isTsconfigExists
31+
? 'tsconfig.json'
32+
: isJsconfigExists
33+
? 'jsconfig.json'
34+
: null;
35+
36+
if (configFile) {
2837
const tsconfig = JSON.parse(
29-
fs.readFileSync(path.join(baseDir, 'tsconfig.json')).toString('utf8'),
38+
fs.readFileSync(path.join(baseDir, configFile)).toString('utf8'),
3039
);
3140

3241
const paths: Record<string, string[]> = tsconfig?.compilerOptions?.paths ?? {};

0 commit comments

Comments
 (0)