@@ -3,17 +3,14 @@ import path from 'node:path'
3
3
4
4
import isNodeCoreModule from '@nolyfill/is-core-module'
5
5
import debug from 'debug'
6
- import type { FileSystem , ResolveOptions , Resolver } from 'enhanced-resolve'
7
- import enhancedResolve from 'enhanced-resolve'
8
- import { createPathsMatcher , getTsconfig } from 'get-tsconfig'
9
6
import type { TsConfigResult } from 'get-tsconfig'
7
+ import { createPathsMatcher , getTsconfig } from 'get-tsconfig'
10
8
import type { Version } from 'is-bun-module'
11
9
import { isBunModule } from 'is-bun-module'
12
- import stableHashExports from 'stable-hash'
10
+ import { type NapiResolveOptions , ResolverFactory } from 'oxc-resolver'
11
+ import { stableHash } from 'stable-hash'
13
12
import { globSync , isDynamicPattern } from 'tinyglobby'
14
-
15
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- esmodule interop
16
- const stableHash = stableHashExports . default || stableHashExports
13
+ import type { SetRequired } from 'type-fest'
17
14
18
15
const IMPORTER_NAME = 'eslint-import-resolver-typescript'
19
16
@@ -79,28 +76,17 @@ export const defaultMainFields = [
79
76
80
77
export const interfaceVersion = 2
81
78
82
- export interface TsResolverOptions
83
- extends Omit < ResolveOptions , 'fileSystem' | 'useSyncFileSystemCalls' > {
79
+ export interface TsResolverOptions extends NapiResolveOptions {
84
80
alwaysTryTypes ?: boolean
85
81
project ?: string [ ] | string
86
- extensions ?: string [ ]
87
82
}
88
83
89
- type InternalResolverOptions = Required <
90
- Pick <
91
- ResolveOptions ,
92
- | 'conditionNames'
93
- | 'extensionAlias'
94
- | 'extensions'
95
- | 'mainFields'
96
- | 'useSyncFileSystemCalls'
97
- >
84
+ type InternalResolverOptions = SetRequired <
85
+ NapiResolveOptions ,
86
+ 'conditionNames' | 'extensionAlias' | 'extensions' | 'mainFields'
98
87
> &
99
- ResolveOptions &
100
88
TsResolverOptions
101
89
102
- const fileSystem = fs as FileSystem
103
-
104
90
const JS_EXT_PATTERN = / \. (?: [ c m ] j s | j s x ? ) $ /
105
91
const RELATIVE_PATH_PATTERN = / ^ \. { 1 , 2 } (?: \/ .* ) ? $ /
106
92
@@ -118,7 +104,7 @@ let mappers: Array<{
118
104
} > = [ ]
119
105
120
106
let resolverCachedOptions : InternalResolverOptions
121
- let cachedResolver : Resolver | undefined
107
+ let cachedResolver : ResolverFactory | undefined
122
108
123
109
/**
124
110
* @param source the module to resolve; i.e './some-module'
@@ -130,7 +116,7 @@ export function resolve(
130
116
source : string ,
131
117
file : string ,
132
118
options ?: TsResolverOptions | null ,
133
- resolver : Resolver | null = null ,
119
+ resolver ?: ResolverFactory | null ,
134
120
) : {
135
121
found : boolean
136
122
path ?: string | null
@@ -146,18 +132,12 @@ export function resolve(
146
132
extensions : options ?. extensions ?? defaultExtensions ,
147
133
extensionAlias : options ?. extensionAlias ?? defaultExtensionAlias ,
148
134
mainFields : options ?. mainFields ?? defaultMainFields ,
149
- fileSystem : new enhancedResolve . CachedInputFileSystem (
150
- fileSystem ,
151
- 5 * 1000 ,
152
- ) ,
153
- useSyncFileSystemCalls : true ,
154
135
}
155
136
}
156
137
157
138
if ( ! resolver ) {
158
139
if ( ! cachedResolver || resolverCachedOptions !== cachedOptions ) {
159
- cachedResolver =
160
- enhancedResolve . ResolverFactory . createResolver ( cachedOptions )
140
+ cachedResolver = new ResolverFactory ( cachedOptions )
161
141
resolverCachedOptions = cachedOptions
162
142
}
163
143
resolver = cachedResolver
@@ -194,13 +174,12 @@ export function resolve(
194
174
let foundNodePath : string | undefined
195
175
for ( const mappedPath of mappedPaths ) {
196
176
try {
197
- const resolved = resolver . resolveSync (
198
- { } ,
177
+ const resolved = resolver . sync (
199
178
path . dirname ( path . resolve ( file ) ) ,
200
179
mappedPath ,
201
180
)
202
- if ( resolved ) {
203
- foundNodePath = resolved
181
+ if ( resolved . path ) {
182
+ foundNodePath = resolved . path
204
183
break
205
184
}
206
185
} catch {
@@ -246,14 +225,12 @@ export function resolve(
246
225
export function createTypeScriptImportResolver (
247
226
options ?: TsResolverOptions | null ,
248
227
) {
249
- const resolver = enhancedResolve . ResolverFactory . createResolver ( {
228
+ const resolver = new ResolverFactory ( {
250
229
...options ,
251
230
conditionNames : options ?. conditionNames ?? defaultConditionNames ,
252
231
extensions : options ?. extensions ?? defaultExtensions ,
253
232
extensionAlias : options ?. extensionAlias ?? defaultExtensionAlias ,
254
233
mainFields : options ?. mainFields ?? defaultMainFields ,
255
- fileSystem : new enhancedResolve . CachedInputFileSystem ( fileSystem , 5 * 1000 ) ,
256
- useSyncFileSystemCalls : true ,
257
234
} )
258
235
259
236
return {
0 commit comments