1
- import { ResolverFactory , CachedInputFileSystem , type ResolveOptions } from 'enhanced-resolve' ;
2
- import fs from 'node:fs' ;
3
- import type { NewResolver } from './types' ;
4
- import { isBuiltin } from 'node:module' ;
5
- import { dirname } from 'node:path' ;
1
+ import fs from 'node:fs'
2
+ import { isBuiltin } from 'node:module'
3
+ import path from 'node:path'
6
4
7
- interface NodeResolverOptions extends Omit < ResolveOptions , 'useSyncFileSystemCalls' > {
5
+ import { ResolverFactory , CachedInputFileSystem } from 'enhanced-resolve'
6
+ import type { ResolveOptions } from 'enhanced-resolve'
7
+
8
+ import type { NewResolver } from './types'
9
+
10
+ type NodeResolverOptions = {
8
11
/**
9
12
* The allowed extensions the resolver will attempt to find when resolving a module
10
13
* @type {string[] | undefined }
11
14
* @default ['.mjs', '.cjs', '.js', '.json', '.node']
12
15
*/
13
- extensions ?: string [ ] ;
16
+ extensions ?: string [ ]
14
17
/**
15
18
* The import conditions the resolver will used when reading the exports map from "package.json"
16
19
* @type {string[] | undefined }
17
20
* @default ['default', 'module', 'import', 'require']
18
21
*/
19
- conditionNames ?: string [ ] ;
20
- }
22
+ conditionNames ?: string [ ]
23
+ } & Omit < ResolveOptions , 'useSyncFileSystemCalls' >
21
24
22
25
export function createNodeResolver ( {
23
26
extensions = [ '.mjs' , '.cjs' , '.js' , '.json' , '.node' ] ,
24
27
conditionNames = [ 'default' , 'module' , 'import' , 'require' ] ,
25
- mainFields = [ 'main' ] ,
26
- exportsFields = [ 'exports' ] ,
27
- mainFiles = [ 'index' ] ,
28
+ mainFields : _mainFields = [ 'main' ] ,
29
+ exportsFields : _exportsFields = [ 'exports' ] ,
30
+ mainFiles : _mainFiles = [ 'index' ] ,
28
31
fileSystem = new CachedInputFileSystem ( fs , 4 * 1000 ) ,
29
32
...restOptions
30
33
} : Partial < NodeResolverOptions > = { } ) : NewResolver {
@@ -34,7 +37,7 @@ export function createNodeResolver({
34
37
conditionNames,
35
38
useSyncFileSystemCalls : true ,
36
39
...restOptions ,
37
- } ) ;
40
+ } )
38
41
39
42
// shared context across all resolve calls
40
43
@@ -43,26 +46,26 @@ export function createNodeResolver({
43
46
name : 'eslint-plugin-import-x built-in node resolver' ,
44
47
resolve : ( modulePath , sourceFile ) => {
45
48
if ( isBuiltin ( modulePath ) ) {
46
- return { found : true , path : null } ;
49
+ return { found : true , path : null }
47
50
}
48
51
49
52
if ( modulePath . startsWith ( 'data:' ) ) {
50
- return { found : true , path : null } ;
53
+ return { found : true , path : null }
51
54
}
52
55
53
56
try {
54
- const path = resolver . resolveSync (
57
+ const resolved = resolver . resolveSync (
55
58
{ } ,
56
- dirname ( sourceFile ) ,
57
- modulePath
58
- ) ;
59
- if ( path ) {
60
- return { found : true , path } ;
59
+ path . dirname ( sourceFile ) ,
60
+ modulePath ,
61
+ )
62
+ if ( resolved ) {
63
+ return { found : true , path : resolved }
61
64
}
62
- return { found : false } ;
65
+ return { found : false }
63
66
} catch {
64
- return { found : false } ;
67
+ return { found : false }
65
68
}
66
- }
69
+ } ,
67
70
}
68
71
}
0 commit comments