Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto try extensions #126

Merged
merged 2 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/strong-beans-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

fix: auto try extensions
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
lib
CHANGELOG.md
!/.*.cjs
2 changes: 1 addition & 1 deletion .github/workflows/pkg-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16
cache: yarn

- name: Package Size Report
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 16.x
- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16
cache: yarn

- name: Install Dependencies
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This means you can:
- [Installation](#installation)
- [Configuration](#configuration)
- [Contributing](#contributing)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Changelog](#changelog)
- [License](#license)

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

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

## Sponsors

| 1stG | RxTS | UnTS |
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [![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) |

## Backers

| 1stG | RxTS | UnTS |
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| [![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) |

## Changelog

Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
Expand Down
34 changes: 33 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@
"contributors": [
"JounQin (https://www.1stG.me) <admin@1stg.me>"
],
"donate": {
"recipients": [
{
"name": "unts",
"platform": "opencollective",
"address": "https://opencollective.com/unts",
"weight": 60
},
{
"name": "rxts",
"platform": "opencollective",
"address": "https://opencollective.com/rxts",
"weight": 20
},
{
"name": "1stG",
"email": "i@1stg.me",
"weight": 20,
"platforms": [
{
"platform": "opencollective",
"address": "https://opencollective.com/1stG"
},
{
"platform": "patreon",
"address": "https://www.patreon.com/1stG"
}
]
}
]
},
"funding": "https://opencollective.com/unts",
"license": "ISC",
"packageManager": "yarn@1.22.19",
"engines": {
Expand Down Expand Up @@ -71,7 +103,7 @@
"synckit": "^0.7.1"
},
"devDependencies": {
"@1stg/lib-config": "^7.2.0",
"@1stg/lib-config": "^7.2.3",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.0",
"@mozilla/glean": "^1.0.0",
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const isFile = (path?: string | undefined): path is string => {
* @param {string} file the importing file's full path; i.e. '/usr/local/bin/file.js'
* @returns The mapped path of the module or undefined
*/
// eslint-disable-next-line sonarjs/cognitive-complexity
function getMappedPath(
source: string,
file: string,
Expand All @@ -265,7 +266,16 @@ function getMappedPath(
paths = [resolved]
}
} else {
paths = mappers!.flatMap(mapper => mapper?.(source)).filter(isFile)
paths = mappers!
.map(mapper =>
mapper?.(source).map(item =>
path.extname(item)
? item
: ['ts', 'tsx', '.d.ts', 'js'].map(ext => `${item}.${ext}`),
),
)
.flat(2)
.filter(isFile)
}

if (retry && paths.length === 0) {
Expand Down