1- import path from 'path'
1+ import path from 'node:path'
2+ import { fileURLToPath } from 'node:url'
23
34import debug from 'debug'
4- import { sync as globSync } from 'globby'
55import isGlob from 'is-glob'
6- import { isCore , sync , SyncOpts } from 'resolve'
6+ import * as _resolve from 'resolve'
7+ import { createSyncFn } from 'synckit'
78import {
89 ConfigLoaderSuccessResult ,
910 createMatchPath ,
@@ -16,6 +17,15 @@ const IMPORTER_NAME = 'eslint-import-resolver-typescript'
1617
1718const log = debug ( IMPORTER_NAME )
1819
20+ const _dirname =
21+ typeof __dirname === 'undefined'
22+ ? path . dirname ( fileURLToPath ( import . meta. url ) )
23+ : __dirname
24+
25+ const globSync = createSyncFn < typeof import ( 'globby' ) . globby > (
26+ path . resolve ( _dirname , 'worker.mjs' ) ,
27+ )
28+
1929/**
2030 * .mts, .cts, .d.mts, .d.cts, .mjs, .cjs are not included because .cjs and .mjs must be used explicitly.
2131 */
@@ -31,7 +41,7 @@ const defaultExtensions = [
3141
3242export const interfaceVersion = 2
3343
34- export type TsResolverOptions = SyncOpts & {
44+ export type TsResolverOptions = _resolve . SyncOpts & {
3545 alwaysTryTypes ?: boolean
3646 /**
3747 * @deprecated use `project` instead
@@ -62,7 +72,7 @@ export function resolve(
6272 source = removeQuerystring ( source )
6373
6474 // don't worry about core node modules
65- if ( isCore ( source ) ) {
75+ if ( _resolve . isCore ( source ) ) {
6676 log ( 'matched core:' , source )
6777
6878 return {
@@ -126,7 +136,7 @@ export function resolve(
126136 }
127137}
128138
129- function packageFilterDefault ( pkg : Record < string , string > ) {
139+ function packageFilterDefault ( pkg : _resolve . PackageJSON ) {
130140 pkg . main =
131141 pkg . types || pkg . typings || pkg . module || pkg [ 'jsnext:main' ] || pkg . main
132142 return pkg
@@ -162,13 +172,13 @@ function resolveExtension(id: string) {
162172 * Like `sync` from `resolve` package, but considers that the module id
163173 * could have a .js or .jsx extension.
164174 */
165- function tsResolve ( id : string , opts : SyncOpts ) : string {
175+ function tsResolve ( id : string , opts : _resolve . SyncOpts ) : string {
166176 try {
167- return sync ( id , opts )
177+ return _resolve . sync ( id , opts )
168178 } catch ( error ) {
169179 const resolved = resolveExtension ( id )
170180 if ( resolved ) {
171- return sync ( resolved . path , {
181+ return _resolve . sync ( resolved . path , {
172182 ...opts ,
173183 extensions : resolved . extensions ?? opts . extensions ,
174184 } )
0 commit comments