Skip to content

Commit 06c2d63

Browse files
committed
fix: add more extension aliases for ts source/declaration files
close #429
1 parent 151fa11 commit 06c2d63

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,18 @@ Default:
282282
".d.ts",
283283
".js",
284284
],
285+
".ts": [".ts", ".d.ts", ".js"],
285286
".jsx": [".tsx", ".d.ts", ".jsx"],
287+
".tsx": [
288+
".tsx",
289+
".d.ts",
290+
".jsx",
291+
// `.tsx` can also be compiled as `.js`
292+
],
286293
".cjs": [".cts", ".d.cts", ".cjs"],
294+
".cts": [".cts", ".d.cts", ".cjs"],
287295
".mjs": [".mts", ".d.mts", ".mjs"],
296+
".mts": [".mts", ".d.mts", ".mjs"],
288297
}
289298
```
290299

Diff for: src/constants.ts

+9
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@ export const defaultExtensionAlias = {
3636
'.d.ts',
3737
'.js',
3838
],
39+
'.ts': ['.ts', '.d.ts', '.js'],
3940
'.jsx': ['.tsx', '.d.ts', '.jsx'],
41+
'.tsx': [
42+
'.tsx',
43+
'.d.ts',
44+
'.jsx',
45+
// `.tsx` can also be compiled as `.js`
46+
],
4047
'.cjs': ['.cts', '.d.cts', '.cjs'],
48+
'.cts': ['.cts', '.d.cts', '.cjs'],
4149
'.mjs': ['.mts', '.d.mts', '.mjs'],
50+
'.mts': ['.mts', '.d.mts', '.mjs'],
4251
}
4352

4453
export const defaultMainFields = [

Diff for: src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const unrsResolve = (
5050
}
5151
}
5252
if (result.error) {
53-
log('oxc resolve error:', result.error)
53+
log('unrs-resolver error:', result.error)
5454
if (TSCONFIG_NOT_FOUND_REGEXP.test(result.error)) {
5555
throw new Error(result.error)
5656
}

Diff for: tests/unit/dts/foo.d.ts

Whitespace-only changes.

Diff for: tests/unit/unit.spec.ts

+23-10
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import {
77
TSCONFIG_NOT_FOUND_REGEXP,
88
} from 'eslint-import-resolver-typescript'
99

10-
describe('createTypeScriptImportResolver', async () => {
11-
const { dirname } = import.meta
12-
13-
const pnpDir = path.resolve(dirname, 'pnp')
10+
const { dirname } = import.meta
1411

15-
await exec('yarn', [], {
16-
nodeOptions: {
17-
cwd: pnpDir,
18-
},
19-
})
12+
describe('createTypeScriptImportResolver', async () => {
13+
const resolver = createTypeScriptImportResolver()
2014

2115
it('should work with pnp', async () => {
22-
const resolver = createTypeScriptImportResolver()
16+
const pnpDir = path.resolve(dirname, 'pnp')
17+
18+
await exec('yarn', [], {
19+
nodeOptions: {
20+
cwd: pnpDir,
21+
},
22+
})
2323

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

@@ -38,6 +38,19 @@ describe('createTypeScriptImportResolver', async () => {
3838
`)
3939
})
4040

41+
it('should resolve .d.ts with .ts extension', () => {
42+
const dtsDir = path.resolve(dirname, 'dts')
43+
44+
const testfile = path.resolve(dtsDir, '__test__.js')
45+
46+
expect(resolver.resolve('./foo.ts', testfile)).toMatchInlineSnapshot(`
47+
{
48+
"found": true,
49+
"path": "<ROOT>/tests/unit/dts/foo.d.ts",
50+
}
51+
`)
52+
})
53+
4154
it('should error on malformed tsconfig reference', () => {
4255
const project = path.resolve(dirname, 'malformed-reference')
4356

0 commit comments

Comments
 (0)