@@ -3,17 +3,14 @@ import path from 'node:path'
33
44import isNodeCoreModule from '@nolyfill/is-core-module'
55import 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'
96import type { TsConfigResult } from 'get-tsconfig'
7+ import { createPathsMatcher , getTsconfig } from 'get-tsconfig'
108import type { Version } from 'is-bun-module'
119import { 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'
1312import { 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'
1714
1815const IMPORTER_NAME = 'eslint-import-resolver-typescript'
1916
@@ -79,28 +76,17 @@ export const defaultMainFields = [
7976
8077export const interfaceVersion = 2
8178
82- export interface TsResolverOptions
83- extends Omit < ResolveOptions , 'fileSystem' | 'useSyncFileSystemCalls' > {
79+ export interface TsResolverOptions extends NapiResolveOptions {
8480 alwaysTryTypes ?: boolean
8581 project ?: string [ ] | string
86- extensions ?: string [ ]
8782}
8883
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'
9887> &
99- ResolveOptions &
10088 TsResolverOptions
10189
102- const fileSystem = fs as FileSystem
103-
10490const JS_EXT_PATTERN = / \. (?: [ c m ] j s | j s x ? ) $ /
10591const RELATIVE_PATH_PATTERN = / ^ \. { 1 , 2 } (?: \/ .* ) ? $ /
10692
@@ -118,7 +104,7 @@ let mappers: Array<{
118104} > = [ ]
119105
120106let resolverCachedOptions : InternalResolverOptions
121- let cachedResolver : Resolver | undefined
107+ let cachedResolver : ResolverFactory | undefined
122108
123109/**
124110 * @param source the module to resolve; i.e './some-module'
@@ -130,7 +116,7 @@ export function resolve(
130116 source : string ,
131117 file : string ,
132118 options ?: TsResolverOptions | null ,
133- resolver : Resolver | null = null ,
119+ resolver ?: ResolverFactory | null ,
134120) : {
135121 found : boolean
136122 path ?: string | null
@@ -146,18 +132,12 @@ export function resolve(
146132 extensions : options ?. extensions ?? defaultExtensions ,
147133 extensionAlias : options ?. extensionAlias ?? defaultExtensionAlias ,
148134 mainFields : options ?. mainFields ?? defaultMainFields ,
149- fileSystem : new enhancedResolve . CachedInputFileSystem (
150- fileSystem ,
151- 5 * 1000 ,
152- ) ,
153- useSyncFileSystemCalls : true ,
154135 }
155136 }
156137
157138 if ( ! resolver ) {
158139 if ( ! cachedResolver || resolverCachedOptions !== cachedOptions ) {
159- cachedResolver =
160- enhancedResolve . ResolverFactory . createResolver ( cachedOptions )
140+ cachedResolver = new ResolverFactory ( cachedOptions )
161141 resolverCachedOptions = cachedOptions
162142 }
163143 resolver = cachedResolver
@@ -194,13 +174,12 @@ export function resolve(
194174 let foundNodePath : string | undefined
195175 for ( const mappedPath of mappedPaths ) {
196176 try {
197- const resolved = resolver . resolveSync (
198- { } ,
177+ const resolved = resolver . sync (
199178 path . dirname ( path . resolve ( file ) ) ,
200179 mappedPath ,
201180 )
202- if ( resolved ) {
203- foundNodePath = resolved
181+ if ( resolved . path ) {
182+ foundNodePath = resolved . path
204183 break
205184 }
206185 } catch {
@@ -246,14 +225,12 @@ export function resolve(
246225export function createTypeScriptImportResolver (
247226 options ?: TsResolverOptions | null ,
248227) {
249- const resolver = enhancedResolve . ResolverFactory . createResolver ( {
228+ const resolver = new ResolverFactory ( {
250229 ...options ,
251230 conditionNames : options ?. conditionNames ?? defaultConditionNames ,
252231 extensions : options ?. extensions ?? defaultExtensions ,
253232 extensionAlias : options ?. extensionAlias ?? defaultExtensionAlias ,
254233 mainFields : options ?. mainFields ?? defaultMainFields ,
255- fileSystem : new enhancedResolve . CachedInputFileSystem ( fileSystem , 5 * 1000 ) ,
256- useSyncFileSystemCalls : true ,
257234 } )
258235
259236 return {
0 commit comments