Skip to content

Commit

Permalink
fix: auto try extensions (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jul 2, 2022
1 parent 5f828eb commit 9cf60cb
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 147 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-beans-allow.md
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

fix: auto try extensions
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,3 +1,4 @@
dist
lib
CHANGELOG.md
!/.*.cjs
2 changes: 1 addition & 1 deletion .github/workflows/pkg-size.yml
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
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
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
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
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

0 comments on commit 9cf60cb

Please sign in to comment.