Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: add more extension aliases for ts source/declaration files #442

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

Merged
merged 1 commit into from
Apr 21, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 .changeset/late-elephants-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": patch
---

fix: add more extension aliases for ts source/declaration files
10 changes: 10 additions & 0 deletions 10 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,19 @@ Default:
".d.ts",
".js",
],
".ts": [".ts", ".d.ts", ".js"],
".jsx": [".tsx", ".d.ts", ".jsx"],
".tsx": [
JounQin marked this conversation as resolved.
Show resolved Hide resolved
".tsx",
".d.ts",
".jsx",
// `.tsx` can also be compiled as `.js`
".js",
],
".cjs": [".cts", ".d.cts", ".cjs"],
".cts": [".cts", ".d.cts", ".cjs"],
".mjs": [".mts", ".d.mts", ".mjs"],
".mts": [".mts", ".d.mts", ".mjs"],
}
```

Expand Down
10 changes: 10 additions & 0 deletions 10 src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,19 @@ export const defaultExtensionAlias = {
'.d.ts',
'.js',
],
'.ts': ['.ts', '.d.ts', '.js'],
'.jsx': ['.tsx', '.d.ts', '.jsx'],
'.tsx': [
JounQin marked this conversation as resolved.
Show resolved Hide resolved
JounQin marked this conversation as resolved.
Show resolved Hide resolved
'.tsx',
'.d.ts',
'.jsx',
// `.tsx` can also be compiled as `.js`
'.js',
],
'.cjs': ['.cts', '.d.cts', '.cjs'],
'.cts': ['.cts', '.d.cts', '.cjs'],
'.mjs': ['.mts', '.d.mts', '.mjs'],
'.mts': ['.mts', '.d.mts', '.mjs'],
}

export const defaultMainFields = [
Expand Down
2 changes: 1 addition & 1 deletion 2 src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const unrsResolve = (
}
}
if (result.error) {
log('oxc resolve error:', result.error)
log('unrs-resolver error:', result.error)
if (TSCONFIG_NOT_FOUND_REGEXP.test(result.error)) {
throw new Error(result.error)
}
Expand Down
Empty file added 0 tests/unit/dts/foo.d.ts
Empty file.
33 changes: 23 additions & 10 deletions 33 tests/unit/unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import {
TSCONFIG_NOT_FOUND_REGEXP,
} from 'eslint-import-resolver-typescript'

describe('createTypeScriptImportResolver', async () => {
const { dirname } = import.meta

const pnpDir = path.resolve(dirname, 'pnp')
const { dirname } = import.meta

await exec('yarn', [], {
nodeOptions: {
cwd: pnpDir,
},
})
describe('createTypeScriptImportResolver', async () => {
const resolver = createTypeScriptImportResolver()

it('should work with pnp', async () => {
const resolver = createTypeScriptImportResolver()
const pnpDir = path.resolve(dirname, 'pnp')

await exec('yarn', [], {
nodeOptions: {
cwd: pnpDir,
},
})

const testfile = path.resolve(pnpDir, '__test__.js')

Expand All @@ -38,6 +38,19 @@ describe('createTypeScriptImportResolver', async () => {
`)
})

it('should resolve .d.ts with .ts extension', () => {
const dtsDir = path.resolve(dirname, 'dts')

const testfile = path.resolve(dtsDir, '__test__.js')

expect(resolver.resolve('./foo.ts', testfile)).toMatchInlineSnapshot(`
{
"found": true,
"path": "<ROOT>/tests/unit/dts/foo.d.ts",
}
`)
})

it('should error on malformed tsconfig reference', () => {
const project = path.resolve(dirname, 'malformed-reference')

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.