Skip to content

Commit 9cf60cb

Browse files
authored
fix: auto try extensions (#126)
1 parent 5f828eb commit 9cf60cb

File tree

8 files changed

+210
-147
lines changed

8 files changed

+210
-147
lines changed

.changeset/strong-beans-allow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-import-resolver-typescript": patch
3+
---
4+
5+
fix: auto try extensions

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist
12
lib
23
CHANGELOG.md
34
!/.*.cjs

.github/workflows/pkg-size.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup Node.js
1818
uses: actions/setup-node@v3
1919
with:
20-
node-version: 16.x
20+
node-version: 16
2121
cache: yarn
2222

2323
- name: Package Size Report

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
1717
fetch-depth: 0
1818

19-
- name: Setup Node.js 16.x
19+
- name: Setup Node.js 16
2020
uses: actions/setup-node@v3
2121
with:
22-
node-version: 16.x
22+
node-version: 16
2323
cache: yarn
2424

2525
- name: Install Dependencies

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ This means you can:
3030
- [Installation](#installation)
3131
- [Configuration](#configuration)
3232
- [Contributing](#contributing)
33+
- [Sponsors](#sponsors)
34+
- [Backers](#backers)
3335
- [Changelog](#changelog)
3436
- [License](#license)
3537

@@ -109,6 +111,18 @@ We have [GitHub Actions](https://github.com/import-js/eslint-import-resolver-typ
109111

110112
If either fails, we won't be able to merge your PR until it's fixed.
111113

114+
## Sponsors
115+
116+
| 1stG | RxTS | UnTS |
117+
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
118+
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/organizations.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/organizations.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/organizations.svg)](https://opencollective.com/unts) |
119+
120+
## Backers
121+
122+
| 1stG | RxTS | UnTS |
123+
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
124+
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |
125+
112126
## Changelog
113127

114128
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).

package.json

+33-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@
88
"contributors": [
99
"JounQin (https://www.1stG.me) <admin@1stg.me>"
1010
],
11+
"donate": {
12+
"recipients": [
13+
{
14+
"name": "unts",
15+
"platform": "opencollective",
16+
"address": "https://opencollective.com/unts",
17+
"weight": 60
18+
},
19+
{
20+
"name": "rxts",
21+
"platform": "opencollective",
22+
"address": "https://opencollective.com/rxts",
23+
"weight": 20
24+
},
25+
{
26+
"name": "1stG",
27+
"email": "i@1stg.me",
28+
"weight": 20,
29+
"platforms": [
30+
{
31+
"platform": "opencollective",
32+
"address": "https://opencollective.com/1stG"
33+
},
34+
{
35+
"platform": "patreon",
36+
"address": "https://www.patreon.com/1stG"
37+
}
38+
]
39+
}
40+
]
41+
},
42+
"funding": "https://opencollective.com/unts",
1143
"license": "ISC",
1244
"packageManager": "yarn@1.22.19",
1345
"engines": {
@@ -71,7 +103,7 @@
71103
"synckit": "^0.7.1"
72104
},
73105
"devDependencies": {
74-
"@1stg/lib-config": "^7.2.0",
106+
"@1stg/lib-config": "^7.2.3",
75107
"@changesets/changelog-github": "^0.4.5",
76108
"@changesets/cli": "^2.23.0",
77109
"@mozilla/glean": "^1.0.0",

src/index.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ const isFile = (path?: string | undefined): path is string => {
252252
* @param {string} file the importing file's full path; i.e. '/usr/local/bin/file.js'
253253
* @returns The mapped path of the module or undefined
254254
*/
255+
// eslint-disable-next-line sonarjs/cognitive-complexity
255256
function getMappedPath(
256257
source: string,
257258
file: string,
@@ -265,7 +266,16 @@ function getMappedPath(
265266
paths = [resolved]
266267
}
267268
} else {
268-
paths = mappers!.flatMap(mapper => mapper?.(source)).filter(isFile)
269+
paths = mappers!
270+
.map(mapper =>
271+
mapper?.(source).map(item =>
272+
path.extname(item)
273+
? item
274+
: ['ts', 'tsx', '.d.ts', 'js'].map(ext => `${item}.${ext}`),
275+
),
276+
)
277+
.flat(2)
278+
.filter(isFile)
269279
}
270280

271281
if (retry && paths.length === 0) {

0 commit comments

Comments
 (0)